diff --git a/.codespellrc b/.codespellrc index 16cda4a4..3654513b 100644 --- a/.codespellrc +++ b/.codespellrc @@ -2,8 +2,8 @@ # See: https://github.com/codespell-project/codespell#using-a-config-file [codespell] # In the event of a false positive, add the problematic word, in all lowercase, to a comma-separated list here: -ignore-words-list = licence,ot -skip = ./.git,./.licenses,__pycache__,node_modules,./go.mod,./go.sum,./package-lock.json,./poetry.lock,./yarn.lock +ignore-words-list = ba,licence,ot +skip = ./.git,./.licenses,__pycache__,node_modules,./other/clang-format-configuration/testdata/input/samples,./other/clang-format-configuration/testdata/golden,./other/clang-format-configuration/.clang-format,./go.mod,./go.sum,./package-lock.json,./poetry.lock,./yarn.lock builtin = clear,informal,en-GB_to_en-US check-filenames = check-hidden = diff --git a/.ecrc b/.ecrc index fd3d1617..8331478d 100644 --- a/.ecrc +++ b/.ecrc @@ -4,6 +4,8 @@ "^\\.licenses[/\\\\]", "__pycache__[/\\\\]", "node_modules[/\\\\]", + "^other[/\\\\]clang-format-configuration[/\\\\]testdata[/\\\\]", + "^other[/\\\\]clang-format-configuration[/\\\\]\\.clang-format", "^LICENSE\\.txt$", "^poetry\\.lock$" ] diff --git a/.eslintrc.yml b/.eslintrc.yml new file mode 100644 index 00000000..3e0be6c9 --- /dev/null +++ b/.eslintrc.yml @@ -0,0 +1,14 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-javascript/.eslintrc.yml +# See: https://eslint.org/docs/user-guide/configuring/ +# The code style defined in this file is the official standardized style to be used in all Arduino projects and should +# not be modified. + +extends: + - airbnb-base + - prettier +rules: + max-len: + - error + - code: 180 + no-console: "off" + no-underscore-dangle: "off" diff --git a/.github/workflows/check-clang-format.yml b/.github/workflows/check-clang-format.yml new file mode 100644 index 00000000..d1c0b7cb --- /dev/null +++ b/.github/workflows/check-clang-format.yml @@ -0,0 +1,230 @@ +name: Check ClangFormat Configuration + +env: + # See: https://github.com/actions/setup-node/#readme + NODE_VERSION: 16.x + +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/check-clang-format.yml" + - "other/clang-format-configuration/scripts/convert-clang-format-configuration.js" + - "other/clang-format-configuration/testdata/**" + - "other/clang-format-configuration/.clang-format" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + pull_request: + paths: + - ".github/workflows/check-clang-format.yml" + - "other/clang-format-configuration/scripts/convert-clang-format-configuration.js" + - "other/clang-format-configuration/testdata/**" + - "other/clang-format-configuration/.clang-format" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + schedule: + # Run periodically to catch breakage caused by external changes. + - cron: "0 17 * * WED" + workflow_dispatch: + inputs: + clang-format-version: + description: ClangFormat version (leave empty for standard version) + type: string + default: "" + required: false + repository_dispatch: + +jobs: + validate: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Validate ClangFormat configuration files + run: task --silent clang-format:validate + + check-config: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Set environment variables + run: | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable + if [[ "${{ github.event.inputs.clang-format-version }}" == "" ]]; then + echo "CLANG_FORMAT_VERSION=$(task clang-format:get-version)" >> "$GITHUB_ENV" + else + echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV" + fi + echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV" + echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV" + + - name: Download ClangFormat + id: download + uses: MrOctopus/download-asset-action@1.0 + with: + repository: arduino/clang-static-binaries + tag: ${{ env.CLANG_FORMAT_VERSION }} + asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2 + target: ${{ env.CLANG_FORMAT_INSTALL_PATH }} + + - name: Install ClangFormat + run: | + cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}" + tar --extract --file="${{ steps.download.outputs.name }}" + # Add installation to PATH: + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path + echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH" + + - name: Check ClangFormat configuration file + id: check + run: | + task \ + --silent \ + clang-format:check-config \ + CLANG_FORMAT_VERSION="${{ env.CLANG_FORMAT_VERSION }}" + + - name: Save effective configuration file to a workflow artifact + if: > + always() && + steps.check.outcome == 'failure' + uses: actions/upload-artifact@v3 + with: + path: ${{ env.WORKING_FOLDER }}/expected/.clang-format + if-no-files-found: error + name: config-output + + check-output: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Set environment variables + run: | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable + if [[ "${{ github.event.inputs.clang-format-version }}" == "" ]]; then + echo "CLANG_FORMAT_VERSION=$(task clang-format:get-version)" >> "$GITHUB_ENV" + else + echo "CLANG_FORMAT_VERSION=${{ github.event.inputs.clang-format-version }}" >> "$GITHUB_ENV" + fi + echo "CLANG_FORMAT_INSTALL_PATH=${{ runner.temp }}/clang-format" >> "$GITHUB_ENV" + echo "WORKING_FOLDER=${{ runner.temp }}" >> "$GITHUB_ENV" + + - name: Download ClangFormat + id: download + uses: MrOctopus/download-asset-action@1.0 + with: + repository: arduino/clang-static-binaries + tag: ${{ env.CLANG_FORMAT_VERSION }} + asset: clang-format_${{ env.CLANG_FORMAT_VERSION }}_Linux_64bit.tar.bz2 + target: ${{ env.CLANG_FORMAT_INSTALL_PATH }} + + - name: Install ClangFormat + run: | + cd "${{ env.CLANG_FORMAT_INSTALL_PATH }}" + tar --extract --file="${{ steps.download.outputs.name }}" + # Add installation to PATH: + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-system-path + echo "${{ env.CLANG_FORMAT_INSTALL_PATH }}/clang_Linux_64bit" >> "$GITHUB_PATH" + + - name: Check ClangFormat output + id: check + run: | + task \ + clang-format:check-output \ + CLANG_FORMAT_VERSION="${{ env.CLANG_FORMAT_VERSION }}" \ + WORKING_FOLDER="${{ env.WORKING_FOLDER }}" + + - name: Save formatted test data to a workflow artifact + if: > + always() && + steps.check.outcome == 'failure' + uses: actions/upload-artifact@v3 + with: + path: ${{ env.WORKING_FOLDER }}/output + if-no-files-found: error + name: testdata-output + + check-testdata: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Check ClangFormat test data + run: task --silent clang-format:check-testdata + + convert: + runs-on: ubuntu-latest + + steps: + - name: Set environment variables + run: | + # See: https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-an-environment-variable + echo "CONVERSION_OUTPUT_PATH=${{ runner.temp }}/clang-format-js-object.txt" >> "$GITHUB_ENV" + + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Convert the ClangFormat configuration + run: | + task \ + --silent \ + clang-format:convert \ + OUTPUT_PATH="${{ env.CONVERSION_OUTPUT_PATH }}" + + - name: Save conversion to a workflow artifact + uses: actions/upload-artifact@v3 + with: + path: ${{ env.CONVERSION_OUTPUT_PATH }} + if-no-files-found: error + name: javascript-configuration-object diff --git a/.github/workflows/check-eslint.yml b/.github/workflows/check-eslint.yml new file mode 100644 index 00000000..14054e2a --- /dev/null +++ b/.github/workflows/check-eslint.yml @@ -0,0 +1,49 @@ +name: Check ESLint Configuration + +env: + # See: https://github.com/actions/setup-node/#readme + NODE_VERSION: 16.x + +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/check-eslint.yml" + - "workflow-templates/assets/check-javascript/.eslintrc.yml" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + pull_request: + paths: + - ".github/workflows/check-eslint.yml" + - "workflow-templates/assets/check-javascript/.eslintrc.yml" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + schedule: + # Run every Tuesday at 8 AM UTC to catch breakage resulting from changes to the JSON schema. + - cron: "0 8 * * TUE" + workflow_dispatch: + repository_dispatch: + +jobs: + validate: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Validate workflows + run: task --silent eslint:validate diff --git a/.github/workflows/check-javascript-task.yml b/.github/workflows/check-javascript-task.yml new file mode 100644 index 00000000..851259a5 --- /dev/null +++ b/.github/workflows/check-javascript-task.yml @@ -0,0 +1,54 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-javascript-task.md +name: Check JavaScript + +env: + # See: https://github.com/actions/setup-node/#readme + NODE_VERSION: 16.x + +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/check-javascript-task.ya?ml" + - ".eslintignore" + - "**/.eslintrc*" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + - "**.jsx?" + pull_request: + paths: + - ".github/workflows/check-javascript-task.ya?ml" + - ".eslintignore" + - "**/.eslintrc*" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + - "**.jsx?" + workflow_dispatch: + repository_dispatch: + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Lint + run: task js:lint diff --git a/.markdownlintignore b/.markdownlintignore index 0022748d..b764cf02 100644 --- a/.markdownlintignore +++ b/.markdownlintignore @@ -2,3 +2,5 @@ .licenses/ __pycache__/ node_modules/ +/other/clang-format-configuration/testdata/golden/samples/ +/other/clang-format-configuration/testdata/input/samples/ diff --git a/.prettierignore b/.prettierignore index e1f03f10..99d17548 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,6 @@ .licenses/ __pycache__/ node_modules/ +/other/clang-format-configuration/testdata/golden/samples/ +/other/clang-format-configuration/testdata/input/samples/ +/other/clang-format-configuration/.clang-format diff --git a/.yamllint.yml b/.yamllint.yml index 67630dcc..1a36cbaf 100644 --- a/.yamllint.yml +++ b/.yamllint.yml @@ -72,5 +72,6 @@ yaml-files: ignore: | /.git/ + /other/clang-format-configuration/.clang-format __pycache__/ node_modules/ diff --git a/README.md b/README.md index 27144860..3d828014 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ # Tooling Project Assets +[![Check ClangFormat Configuration status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-clang-format.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-clang-format.yml) [![Check Dependabot Configuration status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-dependabot.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-dependabot.yml) +[![Check ESLint Configuration status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-eslint.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-eslint.yml) [![Check Issue Templates status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-issue-templates.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-issue-templates.yml) +[![Check JavaScript status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-javascript-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-javascript-task.yml) [![Check Label Configuration status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-labels.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-labels.yml) [![Check markdownlint Configuration status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-markdownlint.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-markdownlint.yml) [![Check npm status](https://github.com/arduino/tooling-project-assets/actions/workflows/check-npm-task.yml/badge.svg)](https://github.com/arduino/tooling-project-assets/actions/workflows/check-npm-task.yml) diff --git a/Taskfile.yml b/Taskfile.yml index 01378209..1879c2f6 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -1,6 +1,14 @@ version: "3" vars: + CLANG_FORMAT_CONFIGURATION_FOLDER: other/clang-format-configuration + CLANG_FORMAT_CONFIGURATION_PATH: "{{.CLANG_FORMAT_CONFIGURATION_FOLDER}}/.clang-format" + CLANG_FORMAT_TEST_DATA_FOLDER: "{{.CLANG_FORMAT_CONFIGURATION_FOLDER}}/testdata" + CLANG_FORMAT_INPUT_TEST_DATA_FOLDER: "{{.CLANG_FORMAT_TEST_DATA_FOLDER}}/input" + CLANG_FORMAT_TARGETED_INPUT_TEST_DATA_FOLDER: "{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/targeted" + CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER: "{{.CLANG_FORMAT_TEST_DATA_FOLDER}}/golden" + # See: https://github.com/arduino/arduino-ide/blob/main/arduino-ide-extension/package.json + DEFAULT_CLANG_FORMAT_VERSION: 14.0.0 # Last version of ajv-cli with support for the JSON schema "Draft 4" specification SCHEMA_DRAFT_4_AJV_CLI_VERSION: 3.3.0 @@ -9,10 +17,16 @@ tasks: desc: Check for problems with the project deps: - task: ci:validate + - task: clang-format:check-config + - task: clang-format:check-output + - task: clang-format:check-testdata + - task: clang-format:validate - task: dependabot:validate + - task: eslint:validate - task: general:check-formatting - task: general:check-spelling - task: issue-form:validate + - task: js:lint - task: labels:validate - task: markdown:check-links - task: markdown:lint @@ -32,6 +46,7 @@ tasks: - task: general:correct-spelling - task: general:format-prettier - task: github:sync + - task: js:fix - task: markdown:fix - task: python:format - task: shell:format @@ -45,6 +60,7 @@ tasks: - | cp \ "{{.WORKFLOW_TEMPLATES_PATH}}/check-general-formatting-task.yml" \ + "{{.WORKFLOW_TEMPLATES_PATH}}/check-javascript-task.yml" \ "{{.WORKFLOW_TEMPLATES_PATH}}/check-markdown-task.yml" \ "{{.WORKFLOW_TEMPLATES_PATH}}/check-npm-task.yml" \ "{{.WORKFLOW_TEMPLATES_PATH}}/check-prettier-formatting-task.yml" \ @@ -96,6 +112,209 @@ tasks: -s "{{.WORKFLOW_SCHEMA_PATH}}" \ -d "{{.TEMPLATE_WORKFLOWS_DATA_PATH}}" + clang-format:check-config: + desc: Check that ClangFormat configuration file matches effective tool configuration + vars: + WORKING_FOLDER: + sh: | + if [[ "{{.WORKING_FOLDER}}" == "" ]]; then + # Generate a path + task utility:mktemp-folder TEMPLATE="clang-format-check-config-XXXXXXXXXX" + else + # A path was specified via the command line + echo "{{.WORKING_FOLDER}}" + fi + ACTUAL_CONFIGURATION_PATH: "{{.WORKING_FOLDER}}/actual/.clang-format" + EXPECTED_CONFIGURATION_PATH: "{{.WORKING_FOLDER}}/expected/.clang-format" + cmds: + - | + mkdir "{{.WORKING_FOLDER}}/actual" + mkdir "{{.WORKING_FOLDER}}/expected" + cp "{{.CLANG_FORMAT_CONFIGURATION_PATH}}" "{{.WORKING_FOLDER}}/actual/" + - task: clang-format:dump-config + vars: + TARGET_PATH: "{{.WORKING_FOLDER}}/expected/.clang-format" + - | + cd "{{.WORKING_FOLDER}}" + diff --color=always --unified "actual/.clang-format" "expected/.clang-format" + + # Check if ClangFormat is installed and the expected version + clang-format:check-installed: + vars: + EXPECTED_CLANG_FORMAT_VERSION: "{{default .DEFAULT_CLANG_FORMAT_VERSION .CLANG_FORMAT_VERSION}}" + cmds: + - | + if ! which clang-format &>/dev/null; then + echo "clang-format not found or not in PATH. Please install: https://github.com/arduino/clang-static-binaries/releases" + exit 1 + fi + - | + INSTALLED_CLANG_FORMAT_VERSION_ARRAY=($(clang-format --version)) + INSTALLED_CLANG_FORMAT_VERSION="${INSTALLED_CLANG_FORMAT_VERSION_ARRAY[${#INSTALLED_CLANG_FORMAT_VERSION_ARRAY[@]}-1]}" + if [[ "$INSTALLED_CLANG_FORMAT_VERSION" != "{{.EXPECTED_CLANG_FORMAT_VERSION}}" ]]; then + echo "Installed version of clang-format $INSTALLED_CLANG_FORMAT_VERSION (at $(which clang-format)) does not match expected {{.EXPECTED_CLANG_FORMAT_VERSION}}" + exit 1 + fi + + clang-format:check-output: + desc: Compare actual vs expected output of ClangFormat + vars: + WORKING_FOLDER: + sh: | + if [[ "{{.WORKING_FOLDER}}" == "" ]]; then + # Generate a path + task utility:mktemp-folder TEMPLATE="clang-format-check-XXXXXXXXXX" + else + # A path was specified via the command line + echo "{{.WORKING_FOLDER}}" + fi + deps: + - task: clang-format:check-installed + cmds: + - | + cp \ + --recursive \ + --target-directory="{{.WORKING_FOLDER}}" \ + "{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}" \ + "{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}" + - task: clang-format:format + vars: + TARGET_FOLDER: "{{.WORKING_FOLDER}}/input/" + - | + # Give the folder an appropriate name to make the diff easier to understand + mv "{{.WORKING_FOLDER}}/input/" "{{.WORKING_FOLDER}}/output/" + - | + cd "{{.WORKING_FOLDER}}" + diff --color=always --recursive --unified "golden/" "output/" + + clang-format:check-testdata: + desc: Check whether the targeted test data C++ code for the ClangFormat configuration is valid and correct + cmds: + - | + if ! which g++ &>/dev/null; then + echo "GCC not found or not in PATH." + exit 1 + fi + - | + # Only the "targeted" test data is checked because the "samples" test data is not maintained in this repo. + g++ \ + -fconcepts \ + -fsyntax-only \ + -I "{{.CLANG_FORMAT_TARGETED_INPUT_TEST_DATA_FOLDER}}/include" \ + -Wall \ + -Werror \ + -Wextra \ + "{{.CLANG_FORMAT_TARGETED_INPUT_TEST_DATA_FOLDER}}"/*.cpp + + clang-format:convert: + desc: Convert the ClangFormat configuration file into the JavaScript object used by Arduino IDE 2.x + vars: + OUTPUT_PATH: + sh: | + if [[ "{{.OUTPUT_PATH}}" == "" ]]; then + task utility:mktemp-file TEMPLATE="clang-format-js-object-XXXXXXXXXX.txt" + else + echo "{{.OUTPUT_PATH}}" + fi + deps: + - task: npm:install-deps + cmds: + - | + node \ + "{{.CLANG_FORMAT_CONFIGURATION_FOLDER}}/scripts/convert-clang-format-configuration.js" \ + "{{.CLANG_FORMAT_CONFIGURATION_PATH}}" \ + "{{.OUTPUT_PATH}}" + + # Write the effective ClangFormat configuration to the path specified by the TARGET_PATH variable + clang-format:dump-config: + deps: + - task: clang-format:check-installed + cmds: + - | + # Add source comment + echo \ + "# Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration" > \ + "{{.TARGET_PATH}}" + + # Dump the effective configuration to the target file + clang-format \ + --dump-config \ + --style=file:"{{.CLANG_FORMAT_CONFIGURATION_PATH}}" >> \ + "{{.TARGET_PATH}}" + + # Use ClangFormat to format the files under the path specified by TARGET_FOLDER recursively + clang-format:format: + cmds: + - | + find \ + "{{.TARGET_FOLDER}}" \ + \( \ + -name '*.c' -or \ + -name '*.cpp' -or \ + -name '*.h' -or \ + -name '*.ino' -or \ + -name '*.inot' -or \ + -name '*.ipp' -or \ + -name '*.tpp' -and \ + -type f \ + \) \ + -exec \ + clang-format \ + --assume-filename=foo.cpp \ + -i \ + --style=file:"{{.CLANG_FORMAT_CONFIGURATION_PATH}}" \ + {} \; + + # Print the standard version of ClangFormat for current use + clang-format:get-version: + cmds: + - echo "{{.DEFAULT_CLANG_FORMAT_VERSION}}" + + clang-format:update-config: + desc: Update ClangFormat configuration file to match effective tool configuration + cmds: + - task: clang-format:dump-config + vars: + TARGET_PATH: "{{.CLANG_FORMAT_CONFIGURATION_PATH}}" + + clang-format:update-golden: + desc: Update golden master test data for current configuration + deps: + - task: clang-format:check-installed + cmds: + - rm --recursive "{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/" + - cp --recursive "{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/" "{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/" + - task: clang-format:format + vars: + TARGET_FOLDER: "{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/" + + clang-format:validate: + desc: Validate ClangFormat configuration file against its JSON schema + vars: + # Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/clang-format.json + SCHEMA_URL: https://json.schemastore.org/clang-format.json + SCHEMA_PATH: + sh: task utility:mktemp-file TEMPLATE="clang-format-configuration-schema-XXXXXXXXXX.json" + DATA_SOURCE_PATH: "{{.CLANG_FORMAT_CONFIGURATION_PATH}}" + # ajv-cli identifies YAML-format data files by their file extension, so renaming is required: + # https://github.com/ajv-validator/ajv-cli/issues/117 + DATA_PATH: + sh: task utility:mktemp-file TEMPLATE=".clang-format-XXXXXXXXXX.yml" + deps: + - task: npm:install-deps + cmds: + - wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}} + - cp "{{.DATA_SOURCE_PATH}}" "{{.DATA_PATH}}" + - | + npx \ + --package=ajv-cli \ + --package=ajv-formats \ + ajv validate \ + --all-errors \ + -c ajv-formats \ + -s "{{.SCHEMA_PATH}}" \ + -d "{{.DATA_PATH}}" + config:sync: desc: Sync configuration files from templates vars: @@ -104,11 +323,10 @@ tasks: cmds: - | cp \ - "{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-general-formatting/.ecrc" \ + "{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-javascript/.eslintrc.yml" \ "{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/general/.editorconfig" \ "{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-python/.flake8" \ "{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-markdown/.markdownlint.yml" \ - "{{.WORKFLOW_TEMPLATE_ASSETS_PATH}}/check-yaml/.yamllint.yml" \ "{{.REPOSITORY_ROOT_PATH}}" dependabot:validate: @@ -153,6 +371,29 @@ tasks: # This is an "umbrella" task used to call any documentation generation processes the project has. # It can be left empty if there are none. + eslint:validate: + desc: Validate ESLint configuration file against its JSON schema + vars: + # Source: https://github.com/SchemaStore/schemastore/blob/master/src/schemas/json/eslintrc.json + SCHEMA_URL: https://json.schemastore.org/eslintrc.json + SCHEMA_PATH: + sh: task utility:mktemp-file TEMPLATE="eslintrc-schema-XXXXXXXXXX.json" + DATA_PATH: workflow-templates/assets/check-javascript/.eslintrc.yml + # ajv-cli identifies YAML-format data files by their file extension, so renaming is required: + # https://github.com/ajv-validator/ajv-cli/issues/117 + PROJECT_FOLDER: + sh: pwd + WORKING_FOLDER: + sh: task utility:mktemp-folder TEMPLATE="eslintrc-validate-XXXXXXXXXX" + cmds: + - wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}} + - | + cd "{{.WORKING_FOLDER}}" # Workaround for https://github.com/npm/cli/issues/3210 + npx ajv-cli@{{.SCHEMA_DRAFT_4_AJV_CLI_VERSION}} validate \ + --all-errors \ + -s "{{.SCHEMA_PATH}}" \ + -d "{{.PROJECT_FOLDER}}/{{.DATA_PATH}}" + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-general-formatting-task/Taskfile.yml general:check-formatting: desc: Check basic formatting style of all files @@ -222,6 +463,20 @@ tasks: -s "{{.SCHEMA_PATH}}" \ -d "{{.DATA_PATH}}" + js:fix: + desc: Fix JavaScript code linting violations + deps: + - task: npm:install-deps + cmds: + - npx eslint --ext .js,.jsx --fix . + + js:lint: + desc: Lint JavaScript code + deps: + - task: npm:install-deps + cmds: + - npx eslint --ext .js,.jsx . + labels:validate: desc: Validate GitHub repository label configuration files against their JSON schema vars: @@ -269,6 +524,8 @@ tasks: -type d -name '.licenses' -prune -o \ -type d -name '__pycache__' -prune -o \ -type d -name 'node_modules' -prune -o \ + -path './{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/samples' -prune -o \ + -path './{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/samples' -prune -o \ -regex ".*[.]md" -print ); do markdown-link-check \ @@ -287,6 +544,8 @@ tasks: -type d -name '.licenses' -prune -o \ -type d -name '__pycache__' -prune -o \ -type d -name 'node_modules' -prune -o \ + -path './{{.CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER}}/samples' -prune -o \ + -path './{{.CLANG_FORMAT_INPUT_TEST_DATA_FOLDER}}/samples' -prune -o \ -regex ".*[.]md" -print ); do markdown-link-check \ diff --git a/other/clang-format-configuration/.clang-format b/other/clang-format-configuration/.clang-format new file mode 100644 index 00000000..efbc0c0b --- /dev/null +++ b/other/clang-format-configuration/.clang-format @@ -0,0 +1,149 @@ +# Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignConsecutiveMacros: false +AlignConsecutiveAssignments: false +AlignConsecutiveBitFields: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlines: DontAlign +AlignOperands: Align +AlignTrailingComments: true +AllowAllArgumentsOnNextLine: true +AllowAllConstructorInitializersOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowShortEnumsOnASingleLine: true +AllowShortBlocksOnASingleLine: Always +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: Empty +AllowShortLambdasOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: Always +AllowShortLoopsOnASingleLine: true +AlwaysBreakAfterDefinitionReturnType: None +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: No +BinPackArguments: true +BinPackParameters: true +BraceWrapping: + AfterCaseLabel: false + AfterClass: false + AfterControlStatement: Never + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + AfterExternBlock: false + BeforeCatch: false + BeforeElse: false + BeforeLambdaBody: false + BeforeWhile: false + IndentBraces: false + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakBeforeBinaryOperators: NonAssignment +BreakBeforeBraces: Attach +BreakBeforeInheritanceComma: false +BreakInheritanceList: BeforeColon +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakConstructorInitializers: BeforeColon +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: false +ColumnLimit: 0 +CommentPragmas: '' +CompactNamespaces: false +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 2 +ContinuationIndentWidth: 2 +Cpp11BracedListStyle: false +DeriveLineEnding: true +DerivePointerAlignment: true +DisableFormat: false +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IncludeBlocks: Preserve +IncludeCategories: + - Regex: '^"(llvm|llvm-c|clang|clang-c)/' + Priority: 2 + SortPriority: 0 + - Regex: '^(<|"(gtest|gmock|isl|json)/)' + Priority: 3 + SortPriority: 0 + - Regex: '.*' + Priority: 1 + SortPriority: 0 +IncludeIsMainRegex: '' +IncludeIsMainSourceRegex: '' +IndentCaseLabels: true +IndentCaseBlocks: true +IndentGotoLabels: false +IndentPPDirectives: None +IndentExternBlock: Indent +IndentWidth: 2 +IndentWrappedFunctionNames: false +InsertTrailingCommas: None +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 100000 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PenaltyBreakAssignment: 1 +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 1 +PenaltyBreakFirstLessLess: 1 +PenaltyBreakString: 1 +PenaltyBreakTemplateDeclaration: 1 +PenaltyExcessCharacter: 1 +PenaltyReturnTypeOnItsOwnLine: 1 +PointerAlignment: Right +ReflowComments: false +SortIncludes: false +SortUsingDeclarations: false +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeParens: ControlStatements +SpaceBeforeRangeBasedForLoopColon: true +SpaceInEmptyBlock: false +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 2 +SpacesInAngles: false +SpacesInConditionalStatement: false +SpacesInContainerLiterals: false +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +SpaceBeforeSquareBrackets: false +Standard: Auto +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 2 +UseCRLF: false +UseTab: Never +WhitespaceSensitiveMacros: + - STRINGIZE + - PP_STRINGIZE + - BOOST_PP_STRINGIZE +... + diff --git a/other/clang-format-configuration/README.md b/other/clang-format-configuration/README.md new file mode 100644 index 00000000..fd27bef0 --- /dev/null +++ b/other/clang-format-configuration/README.md @@ -0,0 +1,104 @@ +# ClangFormat configuration file for official Arduino code style + +This is a configuration file for [the **ClangFormat** code formatting tool](https://clang.llvm.org/docs/ClangFormat.html). + +The code style defined in this file is the standardized [Arduino language](https://www.arduino.cc/reference/en/)/C++/C style to be used in all official Arduino projects. + +## Validation + +The configuration is designed to produce the Arduino code style as established by the Arduino IDE's "**Auto Format**" feature and the code of the sketches and libraries written by Arduino. + +It is used by multiple official Arduino projects as well as by the community. Any changes to the formatter output can be disruptive and so should only be made deliberately after proper evaluation and review of the impact. + +**ClangFormat** is a very complex tool which is under active development. This means that unintended changes to the formatter output might result from: + +- Side effects of intentional configuration changes. +- Differences in **ClangFormat**'s handling of existing configuration options after updating to a new version. +- Introduction of new configuration options after updating to a new version. + +For this reason, it is necessary to carefully validate the configuration in preparation for: + +- Changes to the configuration file +- Updating the version of **ClangFormat** used in Arduino's projects + +Validation is done by formatting a collection of test data files and then comparing the result against "golden masters" which have the intended formatting. The repository's continuous integration system does this check after every change to relevant files. It can also be run locally using [the **Task** task runner tool](https://taskfile.dev/): + +```text +task clang-format:check-configuration +``` + +### ClangFormat version updates + +The validation is done using Arduino's current standard version of **ClangFormat** by default. When an update to a different version of **ClangFormat** is planned, configuration validation must be done against the candidate version. + +#### Running the check locally + +1. Install the candidate **ClangFormat** version on your machine. + **ⓘ** In addition to the standard sources, Arduino provides builds [here](https://github.com/arduino/clang-static-binaries/releases) +1. Add the location of the **ClangFormat** installation to your `PATH`. +1. Run the Task command, specifying the version via an argument: + ```text + task clang-format:check-configuration CLANG_FORMAT_VERSION= + ``` + **ⓘ**Replace `` in the command with the version of the **ClangFormat** candidate. + +#### Running the check via GitHub Actions + +The GitHub Actions workflow can be triggered manually, with the option to specify an arbitrary version of **ClangFormat** to run the validation against. + +1. Check whether a build of the candidate version is available [here](https://github.com/arduino/clang-static-binaries/releases). + If not, submit an issue in that repository requesting a build. +1. Open https://github.com/arduino/tooling-project-assets/actions/workflows/check-clang-format.yml +1. Click the **Run Workflow** button. +1. Enter the **ClangFormat** candidate version in the "**ClangFormat version**" input field. +1. Click the **Run Workflow** button. +1. Wait for the workflow run to finish. +1. Check the results. + +#### Updating the default ClangFormat version + +Once a new version of **ClangFormat** has been adopted as the standard for use in Arduino projects, it must be set as the default for use in the validations. This default version is defined by the `vars.DEFAULT_CLANG_FORMAT_VERSION` field of [`Taskfile.yml`](../../Taskfile.yml). + +### Updating the "golden masters" + +The goal is for the configuration to produce output compliant with the established official Arduino code style. For this reason, differences in output resulting from a configuration change or **ClangFormat** update should not be taken lightly. + +When changes are unavoidable, the test data "golden masters" must be updated accordingly: + +#### Via local operation + +Run the following command + +```text +task clang-format:update-golden +``` + +#### Via GitHub Actions + +As an alternative to running the update command locally, you can download the files from a workflow artifact named "**testdata-output**" which is available in the "**Summary**" page of each workflow run where the `check-output` job of the "**Check ClangFormat Configuration**" workflow failed due to the current golden masters not matching the output. + +Save the contents of the downloaded ZIP file to [the `testdata/golden/` folder](testdata/golden/). + +### Updating the configuration file + +In order to detect added keys, removed keys, or changes to the type of existing keys resulting from a **ClangFormat** version update, the configuration file is used as a "golden master" which the output of `clang-format --dump-config` is compared against. + +At the conclusion of the investigation of any output, the configuration file may need to be updated to match the new output: + +#### Via local operation + +Run the following command + +```text +task clang-format:update-config +``` + +#### Via GitHub Actions + +As an alternative to running the update command locally, you can download the files from a workflow artifact named "**config-output**" which is available in the "**Summary**" page of each workflow run where the `check-config` job of the "**Check ClangFormat Configuration**" workflow failed due to the current configuration file not matching the `--dump-config` output. + +Replace [`.clang-format`](.clang-format) with the one from the downloaded ZIP file. + +## Configuration notes + +Notes about the **ClangFormat** configuration are recorded [here](notes.md). diff --git a/other/clang-format-configuration/notes.md b/other/clang-format-configuration/notes.md new file mode 100644 index 00000000..b6e34b0c --- /dev/null +++ b/other/clang-format-configuration/notes.md @@ -0,0 +1,123 @@ +# ClangFormat configuration notes + +## `AccessModifierOffset` + +This is the additional indent beyond the standard code indentation level. + +The Arduino IDE 1.x formatting style indented access modifiers (equivalent to `AccessModifierOffset: 0`), but also added an extra indent for the members. So non-indented access modifiers (`AccessModifierOffset: -2`) is actually closest to the previous formatting style. + +## `BasedOnStyle` + +This key is irrelevant because we define all configuration keys. + +**ClangFormat** uses the `LLVM` style as a base by default. + +## `BraceWrapping` + +This key is ignored when `BreakBeforeBraces` is set to anything other than `Custom`. + +## `BreakBeforeInheritanceComma` + +Seems to be a backwards compatibility name for `BreakInheritanceList: BeforeComma`: + +https://releases.llvm.org/6.0.0/tools/clang/docs/ClangFormatStyleOptions.html#configurable-format-style-options:~:text=BreakBeforeInheritanceComma + +## `BreakConstructorInitializersBeforeComma` + +Seems to be a backwards compatibility name for `BreakConstructorInitializers: BeforeComma`: + +https://releases.llvm.org/3.8.0/tools/clang/docs/ClangFormatStyleOptions.html#configurable-format-style-options:~:text=BreakConstructorInitializersBeforeComma + +## `CommentPragmas` + +Setting this to an empty string (e.g., `""`) prevents any comments from being matched. + +## `ForEachMacros` + +The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `ForEachMacros: []`. + +## `IncludeCategories` + +The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `IncludeCategories: []`. + +## `IncludeIsMainRegex` + +Setting this to an empty string (e.g., `""`) prevents any `#include` directives from being matched. + +## `KeepEmptyLinesAtTheStartOfBlocks` + +Note that empty lines at the ends of blocks are always removed. + +## `MaxEmptyLinesToKeep` + +Since the established behavior of the "Auto Format" feature from Arduino IDE 1.x is to allow any number of empty lines, this is set to a very large number to effectively reproduce the same. + +Note that empty lines at the ends of blocks are always removed. + +## `NamespaceMacros` + +This key is omitted from the `clang-format --dump-config` output when it is set to an empty array. Since Arduino's configuration does not have any need to define such macros, it is expected that this key will be absent from the configuration file even though present in the **ClangFormat** documentation. + +## `PointerAlignment` + +The `DerivePointerAlignment: true` configuration causes whatever pointer alignment style is predominant in the code to be used by **ClangFormat**. In the event no prevailing style can be can't be detected from code, this value is used as a fallback. + +## `RawStringFormats` + +This key is omitted from the `clang-format --dump-config` output when it is set to an empty array. Since Arduino's configuration does not have any need to define such formats, it is expected that this key will be absent from the configuration file even though present in the **ClangFormat** documentation. + +## `StatementMacros` + +The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `StatementMacros: []`. + +## `TabWidth` + +During the formatting process, **ClangFormat** always uses spaces initially for indentation and alignment, according to the `IndentWidth` configuration setting value. + +If use of tabs for the final indents or alignment is indicated by the `UseTab` configuration setting, those spaces are then converted to tabs according to the value of `TabWidth`. For example, if `TabWidth` is set to `4`, then every occurrence of four spaces within the scope of the `UseTab` setting is converted to a tab. + +This means there is a complex interaction between the `IndentWidth` and `TabWidth` values, which can produce unexpected results. For example, if `IndentWidth` is set to `2` and `TabWidth` to 4, every two indent levels is converted to a single tab, leaving two spaces for the final indentation of each odd level. + +For this reason, `TabWidth` must always be set to the same value as `IndentWidth`. + +## `TypenameMacros` + +This key is omitted from the `clang-format --dump-config` output when it is set to an empty array. Since Arduino's configuration does not have any need to define such macros, it is expected that this key will be absent from the configuration file even though present in the **ClangFormat** documentation. + +## `UseCRLF` + +The `DeriveLineEnding: true` configuration causes whatever line endings are predominant in the code to be used by **ClangFormat**. In the event no prevailing style can be can't be detected from code, this value is used as a fallback. + +## `WhitespaceSensitiveMacros` + +The items specified via this key are added to the base set hardcoded into **ClangFormat**, even if you set it to `WhitespaceSensitiveMacros: []`. + +## "Penalty" keys + +These keys (e.g., `PenaltyBreakAssignment`) are not applicable when wrapping is disabled by setting `ColumnLimit` to `0`, as is done in Arduino's configuration. They are all arbitrarily set to `1`. + +## Keys specific to irrelevant languages + +The following keys are specific to languages other than the Arduino/C++/C targeted by this configuration. For this reason, their values are inconsequential. + +They should be set to **ClangFormat**'s default values. + +### Java + +- `BreakAfterJavaFieldAnnotations` +- `JavaImportGroups` + +### JavaScript + +- `InsertTrailingCommas` +- `JavaScriptQuotes` +- `JavaScriptWrapImports` + +### Objective C-specific keys + +- `AfterObjCDeclaration` +- `ObjCBinPackProtocolList` +- `ObjCBlockIndentWidth` +- `ObjCBreakBeforeNestedBlockParam` +- `ObjCSpaceAfterProperty` +- `ObjCSpaceBeforeProtocolList` diff --git a/other/clang-format-configuration/scripts/convert-clang-format-configuration.js b/other/clang-format-configuration/scripts/convert-clang-format-configuration.js new file mode 100644 index 00000000..f6b40ae7 --- /dev/null +++ b/other/clang-format-configuration/scripts/convert-clang-format-configuration.js @@ -0,0 +1,17 @@ +// Convert the YAML ClangFormat configuration file to the JavaScript object source code for use by Arduino IDE 2.x +// https://github.com/arduino/arduino-ide/blob/main/arduino-ide-extension/src/node/clang-formatter.ts + +const fs = require("fs"); +const yaml = require("js-yaml"); +const util = require("util"); + +try { + const inputPath = process.argv[2]; + const conversionPath = process.argv[3]; + const configurationData = yaml.load(fs.readFileSync(inputPath, "utf8")); + fs.writeFileSync(conversionPath, util.format("%O", configurationData)); + console.log("Conversion written to", conversionPath); +} catch (e) { + console.error(e); + process.exitCode = 1; +} diff --git a/other/clang-format-configuration/testdata/.editorconfig b/other/clang-format-configuration/testdata/.editorconfig new file mode 100644 index 00000000..82532079 --- /dev/null +++ b/other/clang-format-configuration/testdata/.editorconfig @@ -0,0 +1,7 @@ +[*.cpp] +end_of_line = unset +indent_size = unset +indent_style = unset +# insert_final_newline must be unset to avoid general:check-formatting failure on files w/ CRLF EOL. +# (A bug in editorconfig-checker?) +insert_final_newline = unset diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/LICENSE new file mode 100644 index 00000000..19e30718 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +(This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.) + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + {signature of Ty Coon}, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/README.md new file mode 100644 index 00000000..9ec934a3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/README.md @@ -0,0 +1,33 @@ +# ArduinoBLE + +[![Compile Examples Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [![Spell Check Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) + +Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE. + +This library supports creating a Bluetooth® Low Energy peripheral & central mode. + +For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. + + +For more information about this library please visit us at: +https://www.arduino.cc/en/Reference/ArduinoBLE + +## License + +``` +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +``` diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/LedControl/LedControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/LedControl/LedControl.ino new file mode 100644 index 00000000..abdda7b1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/LedControl/LedControl.ino @@ -0,0 +1,129 @@ +/* + LED Control + + This example scans for Bluetooth® Low Energy peripherals until one with the advertised service + "19b10000-e8f2-537e-4f6c-d104768a1214" UUID is found. Once discovered and connected, + it will remotely control the Bluetooth® Low Energy peripheral's LED, when the button is pressed or released. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Button with pull-up resistor connected to pin 2. + + You can use it with another board that is compatible with this library and the + Peripherals -> LED example. + + This example code is in the public domain. +*/ + +#include + +// variables for button +const int buttonPin = 2; +int oldButtonState = LOW; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // configure the button pin as input + pinMode(buttonPin, INPUT); + + // initialize the Bluetooth® Low Energy hardware + BLE.begin(); + + Serial.println("Bluetooth® Low Energy Central - LED control"); + + // start scanning for peripherals + BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); +} + +void loop() { + // check if a peripheral has been discovered + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // discovered a peripheral, print out address, local name, and advertised service + Serial.print("Found "); + Serial.print(peripheral.address()); + Serial.print(" '"); + Serial.print(peripheral.localName()); + Serial.print("' "); + Serial.print(peripheral.advertisedServiceUuid()); + Serial.println(); + + if (peripheral.localName() != "LED") { + return; + } + + // stop scanning + BLE.stopScan(); + + controlLed(peripheral); + + // peripheral disconnected, start scanning again + BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + } +} + +void controlLed(BLEDevice peripheral) { + // connect to the peripheral + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + // retrieve the LED characteristic + BLECharacteristic ledCharacteristic = peripheral.characteristic("19b10001-e8f2-537e-4f6c-d104768a1214"); + + if (!ledCharacteristic) { + Serial.println("Peripheral does not have LED characteristic!"); + peripheral.disconnect(); + return; + } else if (!ledCharacteristic.canWrite()) { + Serial.println("Peripheral does not have a writable LED characteristic!"); + peripheral.disconnect(); + return; + } + + while (peripheral.connected()) { + // while the peripheral is connected + + // read the button pin + int buttonState = digitalRead(buttonPin); + + if (oldButtonState != buttonState) { + // button changed + oldButtonState = buttonState; + + if (buttonState) { + Serial.println("button pressed"); + + // button is pressed, write 0x01 to turn the LED on + ledCharacteristic.writeValue((byte)0x01); + } else { + Serial.println("button released"); + + // button is released, write 0x00 to turn the LED off + ledCharacteristic.writeValue((byte)0x00); + } + } + } + + Serial.println("Peripheral disconnected"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/PeripheralExplorer/PeripheralExplorer.ino new file mode 100644 index 00000000..e90e6b55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -0,0 +1,177 @@ +/* + Peripheral Explorer + + This example scans for Bluetooth® Low Energy peripherals until one with a particular name ("LED") + is found. Then connects, and discovers + prints all the peripheral's attributes. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use it with another board that is compatible with this library and the + Peripherals -> LED example. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1) + ; + } + + Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer"); + + // start scanning for peripherals + BLE.scan(); +} + +void loop() { + // check if a peripheral has been discovered + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // discovered a peripheral, print out address, local name, and advertised service + Serial.print("Found "); + Serial.print(peripheral.address()); + Serial.print(" '"); + Serial.print(peripheral.localName()); + Serial.print("' "); + Serial.print(peripheral.advertisedServiceUuid()); + Serial.println(); + + // see if peripheral is a LED + if (peripheral.localName() == "LED") { + // stop scanning + BLE.stopScan(); + + explorerPeripheral(peripheral); + + // peripheral disconnected, we are done + while (1) { + // do nothing + } + } + } +} + +void explorerPeripheral(BLEDevice peripheral) { + // connect to the peripheral + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + // read and print device name of peripheral + Serial.println(); + Serial.print("Device name: "); + Serial.println(peripheral.deviceName()); + Serial.print("Appearance: 0x"); + Serial.println(peripheral.appearance(), HEX); + Serial.println(); + + // loop the services of the peripheral and explore each + for (int i = 0; i < peripheral.serviceCount(); i++) { + BLEService service = peripheral.service(i); + + exploreService(service); + } + + Serial.println(); + + // we are done exploring, disconnect + Serial.println("Disconnecting ..."); + peripheral.disconnect(); + Serial.println("Disconnected"); +} + +void exploreService(BLEService service) { + // print the UUID of the service + Serial.print("Service "); + Serial.println(service.uuid()); + + // loop the characteristics of the service and explore each + for (int i = 0; i < service.characteristicCount(); i++) { + BLECharacteristic characteristic = service.characteristic(i); + + exploreCharacteristic(characteristic); + } +} + +void exploreCharacteristic(BLECharacteristic characteristic) { + // print the UUID and properties of the characteristic + Serial.print("\tCharacteristic "); + Serial.print(characteristic.uuid()); + Serial.print(", properties 0x"); + Serial.print(characteristic.properties(), HEX); + + // check if the characteristic is readable + if (characteristic.canRead()) { + // read the characteristic value + characteristic.read(); + + if (characteristic.valueLength() > 0) { + // print out the value of the characteristic + Serial.print(", value 0x"); + printData(characteristic.value(), characteristic.valueLength()); + } + } + Serial.println(); + + // loop the descriptors of the characteristic and explore each + for (int i = 0; i < characteristic.descriptorCount(); i++) { + BLEDescriptor descriptor = characteristic.descriptor(i); + + exploreDescriptor(descriptor); + } +} + +void exploreDescriptor(BLEDescriptor descriptor) { + // print the UUID of the descriptor + Serial.print("\t\tDescriptor "); + Serial.print(descriptor.uuid()); + + // read the descriptor value + descriptor.read(); + + // print out the value of the descriptor + Serial.print(", value 0x"); + printData(descriptor.value(), descriptor.valueLength()); + + Serial.println(); +} + +void printData(const unsigned char data[], int length) { + for (int i = 0; i < length; i++) { + unsigned char b = data[i]; + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/Scan/Scan.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/Scan/Scan.ino new file mode 100644 index 00000000..872ba4d7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/Scan/Scan.ino @@ -0,0 +1,70 @@ +/* + Scan + + This example scans for Bluetooth® Low Energy peripherals and prints out their advertising details: + address, local name, advertised service UUID's. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1) + ; + } + + Serial.println("Bluetooth® Low Energy Central scan"); + + // start scanning for peripheral + BLE.scan(); +} + +void loop() { + // check if a peripheral has been discovered + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // discovered a peripheral + Serial.println("Discovered a peripheral"); + Serial.println("-----------------------"); + + // print address + Serial.print("Address: "); + Serial.println(peripheral.address()); + + // print the local name, if present + if (peripheral.hasLocalName()) { + Serial.print("Local Name: "); + Serial.println(peripheral.localName()); + } + + // print the advertised service UUIDs, if present + if (peripheral.hasAdvertisedServiceUuid()) { + Serial.print("Service UUIDs: "); + for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { + Serial.print(peripheral.advertisedServiceUuid(i)); + Serial.print(" "); + } + Serial.println(); + } + + // print the RSSI + Serial.print("RSSI: "); + Serial.println(peripheral.rssi()); + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/ScanCallback/ScanCallback.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/ScanCallback/ScanCallback.ino new file mode 100644 index 00000000..483bc3f5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/ScanCallback/ScanCallback.ino @@ -0,0 +1,75 @@ +/* + Scan Callback + + This example scans for Bluetooth® Low Energy peripherals and prints out their advertising details: + address, local name, advertised service UUIDs. Unlike the Scan example, it uses + the callback style APIs and disables filtering so the peripheral discovery is + reported for every single advertisement it makes. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1) + ; + } + + Serial.println("Bluetooth® Low Energy Central scan callback"); + + // set the discovered event handle + BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler); + + // start scanning for peripherals with duplicates + BLE.scan(true); +} + +void loop() { + // poll the central for events + BLE.poll(); +} + +void bleCentralDiscoverHandler(BLEDevice peripheral) { + // discovered a peripheral + Serial.println("Discovered a peripheral"); + Serial.println("-----------------------"); + + // print address + Serial.print("Address: "); + Serial.println(peripheral.address()); + + // print the local name, if present + if (peripheral.hasLocalName()) { + Serial.print("Local Name: "); + Serial.println(peripheral.localName()); + } + + // print the advertised service UUIDs, if present + if (peripheral.hasAdvertisedServiceUuid()) { + Serial.print("Service UUIDs: "); + for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { + Serial.print(peripheral.advertisedServiceUuid(i)); + Serial.print(" "); + } + Serial.println(); + } + + // print the RSSI + Serial.print("RSSI: "); + Serial.println(peripheral.rssi()); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/SensorTagButton/SensorTagButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/SensorTagButton/SensorTagButton.ino new file mode 100644 index 00000000..c8f5c88e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Central/SensorTagButton/SensorTagButton.ino @@ -0,0 +1,136 @@ +/* + SensorTag Button + + This example scans for Bluetooth® Low Energy peripherals until a TI SensorTag is discovered. + It then connects to it, discovers the attributes of the 0xffe0 service, + subscribes to the Simple Key Characteristic (UUID 0xffe1). When a button is + pressed on the SensorTag a notification is received and the button state is + outputted to the Serial Monitor when one is pressed. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - TI SensorTag + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1) + ; + } + + Serial.println("Bluetooth® Low Energy Central - SensorTag button"); + Serial.println("Make sure to turn on the device."); + + // start scanning for peripheral + BLE.scan(); +} + +void loop() { + // check if a peripheral has been discovered + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // discovered a peripheral, print out address, local name, and advertised service + Serial.print("Found "); + Serial.print(peripheral.address()); + Serial.print(" '"); + Serial.print(peripheral.localName()); + Serial.print("' "); + Serial.print(peripheral.advertisedServiceUuid()); + Serial.println(); + + // Check if the peripheral is a SensorTag, the local name will be: + // "CC2650 SensorTag" + if (peripheral.localName() == "CC2650 SensorTag") { + // stop scanning + BLE.stopScan(); + + monitorSensorTagButtons(peripheral); + + // peripheral disconnected, start scanning again + BLE.scan(); + } + } +} + +void monitorSensorTagButtons(BLEDevice peripheral) { + // connect to the peripheral + Serial.println("Connecting ..."); + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering service 0xffe0 ..."); + if (peripheral.discoverService("ffe0")) { + Serial.println("Service discovered"); + } else { + Serial.println("Attribute discovery failed."); + peripheral.disconnect(); + + while (1) + ; + return; + } + + // retrieve the simple key characteristic + BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); + + // subscribe to the simple key characteristic + Serial.println("Subscribing to simple key characteristic ..."); + if (!simpleKeyCharacteristic) { + Serial.println("no simple key characteristic found!"); + peripheral.disconnect(); + return; + } else if (!simpleKeyCharacteristic.canSubscribe()) { + Serial.println("simple key characteristic is not subscribable!"); + peripheral.disconnect(); + return; + } else if (!simpleKeyCharacteristic.subscribe()) { + Serial.println("subscription failed!"); + peripheral.disconnect(); + return; + } else { + Serial.println("Subscribed"); + Serial.println("Press the right and left buttons on your SensorTag."); + } + + while (peripheral.connected()) { + // while the peripheral is connected + + // check if the value of the simple key characteristic has been updated + if (simpleKeyCharacteristic.valueUpdated()) { + // yes, get the value, characteristic is 1 byte so use byte value + byte value = 0; + + simpleKeyCharacteristic.readValue(value); + + if (value & 0x01) { + // first bit corresponds to the right button + Serial.println("Right button pressed"); + } + + if (value & 0x02) { + // second bit corresponds to the left button + Serial.println("Left button pressed"); + } + } + } + + Serial.println("SensorTag disconnected!"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino new file mode 100644 index 00000000..66c73de0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino @@ -0,0 +1,46 @@ +#include + +BLEService myService("fff0"); +BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); + +// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop' +const uint8_t manufactData[4] = { 0x01, 0x02, 0x03, 0x04 }; +const uint8_t serviceData[3] = { 0x00, 0x01, 0x02 }; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!BLE.begin()) { + Serial.println("failed to initialize BLE!"); + while (1) + ; + } + + myService.addCharacteristic(myCharacteristic); + BLE.addService(myService); + + // Build scan response data packet + BLEAdvertisingData scanData; + // Set parameters for scan response packet + scanData.setLocalName("Test enhanced advertising"); + // Copy set parameters in the actual scan response packet + BLE.setScanResponseData(scanData); + + // Build advertising data packet + BLEAdvertisingData advData; + // Set parameters for advertising packet + advData.setManufacturerData(0x004C, manufactData, sizeof(manufactData)); + advData.setAdvertisedService(myService); + advData.setAdvertisedServiceData(0xfff0, serviceData, sizeof(serviceData)); + // Copy set parameters in the actual advertising packet + BLE.setAdvertisingData(advData); + + BLE.advertise(); + Serial.println("advertising ..."); +} + +void loop() { + BLE.poll(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino new file mode 100644 index 00000000..f09ba87f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino @@ -0,0 +1,43 @@ +#include + +BLEService myService("fff0"); +BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); + +// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop' +const uint8_t completeRawAdvertisingData[] = { 0x02, 0x01, 0x06, 0x09, 0xff, 0x01, 0x01, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05 }; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!BLE.begin()) { + Serial.println("failed to initialize BLE!"); + while (1) + ; + } + + myService.addCharacteristic(myCharacteristic); + BLE.addService(myService); + + // Build advertising data packet + BLEAdvertisingData advData; + // If a packet has a raw data parameter, then all the other parameters of the packet will be ignored + advData.setRawData(completeRawAdvertisingData, sizeof(completeRawAdvertisingData)); + // Copy set parameters in the actual advertising packet + BLE.setAdvertisingData(advData); + + // Build scan response data packet + BLEAdvertisingData scanData; + scanData.setLocalName("Test advertising raw data"); + // Copy set parameters in the actual scan response packet + BLE.setScanResponseData(scanData); + + BLE.advertise(); + + Serial.println("advertising ..."); +} + +void loop() { + BLE.poll(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino new file mode 100644 index 00000000..6930cc94 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino @@ -0,0 +1,108 @@ +/* + Battery Monitor + + This example creates a Bluetooth® Low Energy peripheral with the standard battery service and + level characteristic. The A0 pin is used to calculate the battery level. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + +// Bluetooth® Low Energy Battery Service +BLEService batteryService("180F"); + +// Bluetooth® Low Energy Battery Level Characteristic +BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID + BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes + +int oldBatteryLevel = 0; // last battery level reading from analog input +long previousMillis = 0; // last time the battery level was checked, in ms + +void setup() { + Serial.begin(9600); // initialize serial communication + while (!Serial) + ; + + pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1) + ; + } + + /* Set a local name for the Bluetooth® Low Energy device + This name will appear in advertising packets + and can be used by remote devices to identify this Bluetooth® Low Energy device + The name can be changed but maybe be truncated based on space left in advertisement packet + */ + BLE.setLocalName("BatteryMonitor"); + BLE.setAdvertisedService(batteryService); // add the service UUID + batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic + BLE.addService(batteryService); // Add the battery service + batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic + + /* Start advertising Bluetooth® Low Energy. It will start continuously transmitting Bluetooth® Low Energy + advertising packets and will be visible to remote Bluetooth® Low Energy central devices + until it receives a new connection */ + + // start advertising + BLE.advertise(); + + Serial.println("Bluetooth® device active, waiting for connections..."); +} + +void loop() { + // wait for a Bluetooth® Low Energy central + BLEDevice central = BLE.central(); + + // if a central is connected to the peripheral: + if (central) { + Serial.print("Connected to central: "); + // print the central's BT address: + Serial.println(central.address()); + // turn on the LED to indicate the connection: + digitalWrite(LED_BUILTIN, HIGH); + + // check the battery level every 200ms + // while the central is connected: + while (central.connected()) { + long currentMillis = millis(); + // if 200ms have passed, check the battery level: + if (currentMillis - previousMillis >= 200) { + previousMillis = currentMillis; + updateBatteryLevel(); + } + } + // when the central disconnects, turn off the LED: + digitalWrite(LED_BUILTIN, LOW); + Serial.print("Disconnected from central: "); + Serial.println(central.address()); + } +} + +void updateBatteryLevel() { + /* Read the current voltage level on the A0 analog input pin. + This is used here to simulate the charge level of a battery. + */ + int battery = analogRead(A0); + int batteryLevel = map(battery, 0, 1023, 0, 100); + + if (batteryLevel != oldBatteryLevel) { // if the battery level has changed + Serial.print("Battery Level % is now: "); // print it + Serial.println(batteryLevel); + batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic + oldBatteryLevel = batteryLevel; // save the level for next comparison + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/ButtonLED/ButtonLED.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/ButtonLED/ButtonLED.ino new file mode 100644 index 00000000..12b6e1da --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -0,0 +1,95 @@ +/* + Button LED + + This example creates a Bluetooth® Low Energy peripheral with service that contains a + characteristic to control an LED and another characteristic that + represents the state of the button. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Button connected to pin 4 + + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + +const int ledPin = LED_BUILTIN; // set ledPin to on-board LED +const int buttonPin = 4; // set buttonPin to digital pin 4 + +BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service + +// create switch characteristic and allow remote device to read and write +BLEByteCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); +// create button characteristic and allow remote device to get notifications +BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + pinMode(ledPin, OUTPUT); // use the LED as an output + pinMode(buttonPin, INPUT); // use button pin as an input + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1) + ; + } + + // set the local name peripheral advertises + BLE.setLocalName("ButtonLED"); + // set the UUID for the service this peripheral advertises: + BLE.setAdvertisedService(ledService); + + // add the characteristics to the service + ledService.addCharacteristic(ledCharacteristic); + ledService.addCharacteristic(buttonCharacteristic); + + // add the service + BLE.addService(ledService); + + ledCharacteristic.writeValue(0); + buttonCharacteristic.writeValue(0); + + // start advertising + BLE.advertise(); + + Serial.println("Bluetooth® device active, waiting for connections..."); +} + +void loop() { + // poll for Bluetooth® Low Energy events + BLE.poll(); + + // read the current button pin state + char buttonValue = digitalRead(buttonPin); + + // has the value changed since the last read + bool buttonChanged = (buttonCharacteristic.value() != buttonValue); + + if (buttonChanged) { + // button state changed, update characteristics + ledCharacteristic.writeValue(buttonValue); + buttonCharacteristic.writeValue(buttonValue); + } + + if (ledCharacteristic.written() || buttonChanged) { + // update LED, either central has written to characteristic or button state has changed + if (ledCharacteristic.value()) { + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); + } else { + Serial.println("LED off"); + digitalWrite(ledPin, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/CallbackLED/CallbackLED.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/CallbackLED/CallbackLED.ino new file mode 100644 index 00000000..fbd18a34 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -0,0 +1,97 @@ +/* + Callback LED + + This example creates a Bluetooth® Low Energy peripheral with service that contains a + characteristic to control an LED. The callback features of the + library are used. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service + +// create switch characteristic and allow remote device to read and write +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +const int ledPin = LED_BUILTIN; // pin to use for the LED + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + pinMode(ledPin, OUTPUT); // use the LED pin as an output + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1) + ; + } + + // set the local name peripheral advertises + BLE.setLocalName("LEDCallback"); + // set the UUID for the service this peripheral advertises + BLE.setAdvertisedService(ledService); + + // add the characteristic to the service + ledService.addCharacteristic(switchCharacteristic); + + // add service + BLE.addService(ledService); + + // assign event handlers for connected, disconnected to peripheral + BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); + BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); + + // assign event handlers for characteristic + switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); + // set an initial value for the characteristic + switchCharacteristic.setValue(0); + + // start advertising + BLE.advertise(); + + Serial.println(("Bluetooth® device active, waiting for connections...")); +} + +void loop() { + // poll for Bluetooth® Low Energy events + BLE.poll(); +} + +void blePeripheralConnectHandler(BLEDevice central) { + // central connected event handler + Serial.print("Connected event, central: "); + Serial.println(central.address()); +} + +void blePeripheralDisconnectHandler(BLEDevice central) { + // central disconnected event handler + Serial.print("Disconnected event, central: "); + Serial.println(central.address()); +} + +void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { + // central wrote new value to characteristic, update LED + Serial.print("Characteristic event, written: "); + + if (switchCharacteristic.value()) { + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); + } else { + Serial.println("LED off"); + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino new file mode 100644 index 00000000..b4a82cf4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino @@ -0,0 +1,265 @@ +/* + Battery Monitor + + This example creates a BLE peripheral with the standard battery service and + level characteristic. The A0 pin is used to calculate the battery level. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic BLE central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + + +#define PAIR_BUTTON 3 // button for pairing +#define PAIR_LED 24 // LED used to signal pairing +#define PAIR_LED_ON LOW // Blue LED on Nano BLE has inverted logic +#define PAIR_INTERVAL 30000 // interval for pairing after button press in ms + +#define CTRL_LED LED_BUILTIN + + +// BLE Battery Service +BLEService batteryService("180F"); + +// BLE Battery Level Characteristic +BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID + BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes +BLEStringCharacteristic stringcharacteristic("183E", BLERead | BLEWrite, 31); + + +// Add BLEEncryption tag to require pairing. This controls the LED. +BLEUnsignedCharCharacteristic secretValue("2a3F", BLERead | BLEWrite | BLEEncryption); + +int oldBatteryLevel = 0; // last battery level reading from analog input +unsigned long previousMillis = 0; // last time the battery level was checked, in ms +unsigned long pairingStarted = 0; // pairing start time when button is pressed +bool wasConnected = 0; +bool acceptOrReject = true; + +void setup() { + Serial.begin(9600); // initialize serial communication + while (!Serial) + ; + + pinMode(CTRL_LED, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected + pinMode(PAIR_LED, OUTPUT); + pinMode(PAIR_BUTTON, INPUT_PULLUP); + + + Serial.println("Serial connected"); + + // Callback function with confirmation code when new device is pairing. + BLE.setDisplayCode([](uint32_t confirmCode) { + Serial.println("New device pairing request."); + Serial.print("Confirm code matches pairing device: "); + char code[6]; + sprintf(code, "%06d", confirmCode); + Serial.println(code); + }); + + // Callback to allow accepting or rejecting pairing + BLE.setBinaryConfirmPairing([&acceptOrReject]() { + Serial.print("Should we confirm pairing? "); + delay(5000); + if (acceptOrReject) { + acceptOrReject = false; + Serial.println("yes"); + return true; + } else { + acceptOrReject = true; + Serial.println("no"); + return false; + } + }); + + // IRKs are keys that identify the true owner of a random mac address. + // Add IRKs of devices you are bonded with. + BLE.setGetIRKs([](uint8_t* nIRKs, uint8_t** BDaddrTypes, uint8_t*** BDAddrs, uint8_t*** IRKs) { + // Set to number of devices + *nIRKs = 2; + + *BDAddrs = new uint8_t*[*nIRKs]; + *IRKs = new uint8_t*[*nIRKs]; + *BDaddrTypes = new uint8_t[*nIRKs]; + + // Set these to the mac and IRK for your bonded devices as printed in the serial console after bonding. + uint8_t device1Mac[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t device1IRK[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + uint8_t device2Mac[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t device2IRK[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + + (*BDaddrTypes)[0] = 0; // Type 0 is for pubc address, type 1 is for static random + (*BDAddrs)[0] = new uint8_t[6]; + (*IRKs)[0] = new uint8_t[16]; + memcpy((*IRKs)[0], device1IRK, 16); + memcpy((*BDAddrs)[0], device1Mac, 6); + + + (*BDaddrTypes)[1] = 0; + (*BDAddrs)[1] = new uint8_t[6]; + (*IRKs)[1] = new uint8_t[16]; + memcpy((*IRKs)[1], device2IRK, 16); + memcpy((*BDAddrs)[1], device2Mac, 6); + + + return 1; + }); + // The LTK is the secret key which is used to encrypt bluetooth traffic + BLE.setGetLTK([](uint8_t* address, uint8_t* LTK) { + // address is input + Serial.print("Received request for address: "); + btct.printBytes(address, 6); + + // Set these to the MAC and LTK of your devices after bonding. + uint8_t device1Mac[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t device1LTK[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t device2Mac[6] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + uint8_t device2LTK[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + + + if (memcmp(device1Mac, address, 6) == 0) { + memcpy(LTK, device1LTK, 16); + return 1; + } else if (memcmp(device2Mac, address, 6) == 0) { + memcpy(LTK, device2LTK, 16); + return 1; + } + return 0; + }); + BLE.setStoreIRK([](uint8_t* address, uint8_t* IRK) { + Serial.print(F("New device with MAC : ")); + btct.printBytes(address, 6); + Serial.print(F("Need to store IRK : ")); + btct.printBytes(IRK, 16); + return 1; + }); + BLE.setStoreLTK([](uint8_t* address, uint8_t* LTK) { + Serial.print(F("New device with MAC : ")); + btct.printBytes(address, 6); + Serial.print(F("Need to store LTK : ")); + btct.printBytes(LTK, 16); + return 1; + }); + + while (1) { + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + delay(200); + continue; + } + Serial.println("BT init"); + delay(200); + + /* Set a local name for the BLE device + This name will appear in advertising packets + and can be used by remote devices to identify this BLE device + The name can be changed but maybe be truncated based on space left in advertisement packet + */ + + BLE.setDeviceName("Arduino"); + BLE.setLocalName("BatteryMonitor"); + + BLE.setAdvertisedService(batteryService); // add the service UUID + batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic + batteryService.addCharacteristic(stringcharacteristic); + batteryService.addCharacteristic(secretValue); + + BLE.addService(batteryService); // Add the battery service + batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic + char* stringCharValue = new char[32]; + stringCharValue = "string"; + stringcharacteristic.writeValue(stringCharValue); + secretValue.writeValue(0); + + delay(1000); + + // prevent pairing until button is pressed (will show a pairing rejected message) + BLE.setPairable(false); + + /* Start advertising BLE. It will start continuously transmitting BLE + advertising packets and will be visible to remote BLE central devices + until it receives a new connection */ + + // start advertising + if (!BLE.advertise()) { + Serial.println("failed to advertise bluetooth."); + BLE.stopAdvertise(); + delay(500); + } else { + Serial.println("advertising..."); + break; + } + BLE.end(); + delay(100); + } +} + + +void loop() { + // wait for a BLE central + BLEDevice central = BLE.central(); + + + // If button is pressed, allow pairing for 30 sec + if (!BLE.pairable() && digitalRead(PAIR_BUTTON) == LOW) { + pairingStarted = millis(); + BLE.setPairable(Pairable::ONCE); + Serial.println("Accepting pairing for 30s"); + } else if (BLE.pairable() && millis() > pairingStarted + PAIR_INTERVAL) { + BLE.setPairable(false); + Serial.println("No longer accepting pairing"); + } + // Make LED blink while pairing is allowed + digitalWrite(PAIR_LED, (BLE.pairable() ? (millis() % 400) < 200 : BLE.paired()) ? PAIR_LED_ON : !PAIR_LED_ON); + + + // if a central is connected to the peripheral: + if (central && central.connected()) { + if (!wasConnected) { + wasConnected = true; + Serial.print("Connected to central: "); + // print the central's BT address: + Serial.println(central.address()); + } + + // check the battery level every 200ms + // while the central is connected: + long currentMillis = millis(); + // if 200ms have passed, check the battery level: + if (currentMillis - previousMillis >= 1000) { + previousMillis = currentMillis; + updateBatteryLevel(); + digitalWrite(CTRL_LED, secretValue.value() > 0 ? HIGH : LOW); + } + } else if (wasConnected) { + wasConnected = false; + Serial.print("Disconnected from central: "); + Serial.println(central.address()); + } +} + +void updateBatteryLevel() { + /* Read the current voltage level on the A0 analog input pin. + This is used here to simulate the charge level of a battery. + */ + int battery = analogRead(A0); + int batteryLevel = map(battery, 0, 1023, 0, 100); + + if (batteryLevel != oldBatteryLevel) { // if the battery level has changed + // Serial.print("Battery Level % is now: "); // print it + // Serial.println(batteryLevel); + batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic + oldBatteryLevel = batteryLevel; // save the level for next comparison + } +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/LED/LED.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/LED/LED.ino new file mode 100644 index 00000000..15b53e34 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/LED/LED.ino @@ -0,0 +1,91 @@ +/* + LED + + This example creates a Bluetooth® Low Energy peripheral with service that contains a + characteristic to control an LED. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service + +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +const int ledPin = LED_BUILTIN; // pin to use for the LED + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // set LED pin to output mode + pinMode(ledPin, OUTPUT); + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1) + ; + } + + // set advertised local name and service UUID: + BLE.setLocalName("LED"); + BLE.setAdvertisedService(ledService); + + // add the characteristic to the service + ledService.addCharacteristic(switchCharacteristic); + + // add service + BLE.addService(ledService); + + // set the initial value for the characeristic: + switchCharacteristic.writeValue(0); + + // start advertising + BLE.advertise(); + + Serial.println("BLE LED Peripheral"); +} + +void loop() { + // listen for Bluetooth® Low Energy peripherals to connect: + BLEDevice central = BLE.central(); + + // if a central is connected to peripheral: + if (central) { + Serial.print("Connected to central: "); + // print the central's MAC address: + Serial.println(central.address()); + + // while the central is still connected to peripheral: + while (central.connected()) { + // if the remote device wrote to the characteristic, + // use the value to control the LED: + if (switchCharacteristic.written()) { + if (switchCharacteristic.value()) { // any value other than 0 + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); // will turn the LED on + } else { // a 0 value + Serial.println(F("LED off")); + digitalWrite(ledPin, LOW); // will turn the LED off + } + } + } + + // when the central disconnects, print it out: + Serial.print(F("Disconnected from central: ")); + Serial.println(central.address()); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/LICENSE new file mode 100644 index 00000000..9b925602 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/LICENSE @@ -0,0 +1,21 @@ +Copyright (c) 2018 Arduino SA. All rights reserved. + +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/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/README.adoc new file mode 100644 index 00000000..965379c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/README.adoc @@ -0,0 +1,38 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoBearSSL + += {repository-name} = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Port of https://bearssl.org[BearSSL] to Arduino. + +This library depends on ArduinoECCX08. This dependency could be +disabled by defining ARDUINO_DISABLE_ECCX08 in ArduinoBearSSLConfig.h +(see examples). + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +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/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/AES128.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/AES128.ino new file mode 100644 index 00000000..876e8ec7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/AES128.ino @@ -0,0 +1,72 @@ +/* + ArduinoCrypto AES128 Example + + This sketch demonstrates how to run AES128 encryption and decryption for an input string. + + Circuit: + - Nano 33 IoT board + + created 13 July 2020 + by Luigi Gubello + + This example code is in the public domain. +*/ + +#include +#include "AES128.h" + +#ifdef ARDUINO_ARCH_MEGAAVR +// Create the object +AES128Class AES128; +#endif + +uint8_t key[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02 }; +uint8_t enc_iv[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 }; +uint8_t dec_iv[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 }; +uint8_t input[16] = "ArduinoArduino"; // {0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x00,0x00} + +void setup() { + Serial.begin(9600); + while (!Serial) + ; +} + +void loop() { + + Serial.print("Key: "); + printHex(key, 16); + Serial.println(" "); + Serial.print("IV: "); + printHex(enc_iv, 16); + Serial.println(" "); + Serial.print("AES128 Encryption of '"); + printHex(input, 16); + Serial.print("' is 0x"); + AES128.runEnc(key, 16, input, 16, enc_iv); // expect 0x65D0F7758B094114AFA6D33A5EA0716A + printHex(input, 16); + Serial.println(" "); + Serial.println(" "); + Serial.print("Key: "); + printHex(key, 16); + Serial.println(" "); + Serial.print("IV: "); + printHex(dec_iv, 16); + Serial.println(" "); + Serial.print("AES128 Decryption of '"); + printHex(input, 16); + Serial.print("' is 0x"); + AES128.runDec(key, 16, input, 16, dec_iv); + printHex(input, 16); + Serial.println(" "); + while (1) + ; +} + +void printHex(uint8_t *text, size_t size) { + for (byte i = 0; i < size; i = i + 1) { + if (text[i] < 16) { + Serial.print("0"); + } + Serial.print(text[i], HEX); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/DES/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/DES/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/DES/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/DES/DES.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/DES/DES.ino new file mode 100644 index 00000000..d9973103 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/DES/DES.ino @@ -0,0 +1,72 @@ +/* + ArduinoCrypto DES Example + + This sketch demonstrates how to run DES encryption and decryption for an input string. + + Circuit: + - Nano 33 IoT board + + created 13 July 2020 + by Luigi Gubello + + This example code is in the public domain. +*/ + +#include +#include "DES.h" + +#ifdef ARDUINO_ARCH_MEGAAVR +// Create the object +DESClass DES; +#endif + +uint8_t key[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02 }; +uint8_t enc_iv[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 }; +uint8_t dec_iv[8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x01 }; +uint8_t input[8] = "Arduino"; // {0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x00} + +void setup() { + Serial.begin(9600); + while (!Serial) + ; +} + +void loop() { + + Serial.print("Key: "); + printHex(key, 8); + Serial.println(" "); + Serial.print("IV: "); + printHex(enc_iv, 8); + Serial.println(" "); + Serial.print("DES Encryption of '"); + printHex(input, 8); + Serial.print("' is 0x"); + DES.runEnc(key, 8, input, 8, enc_iv); // expect 0x3C21EB6A62D372DB + printHex(input, 8); + Serial.println(" "); + Serial.println(" "); + Serial.print("Key: "); + printHex(key, 8); + Serial.println(" "); + Serial.print("IV: "); + printHex(dec_iv, 8); + Serial.println(" "); + Serial.print("DES Decryption of '"); + printHex(input, 8); + Serial.print("' is 0x"); + DES.runDec(key, 8, input, 8, dec_iv); + printHex(input, 8); + Serial.println(" "); + while (1) + ; +} + +void printHex(uint8_t *text, size_t size) { + for (byte i = 0; i < size; i = i + 1) { + if (text[i] < 16) { + Serial.print("0"); + } + Serial.print(text[i], HEX); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/MD5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/MD5.ino new file mode 100644 index 00000000..bf686ac5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/MD5.ino @@ -0,0 +1,70 @@ +/* + ArduinoBearSSL MD5 + + This sketch demonstrates how to create a MD5 hash + for an input string. + + This example code is in the public domain. +*/ + +#include +#include "MD5.h" + +#ifdef ARDUINO_ARCH_MEGAAVR +// Create the object +MD5Class MD5; +#endif + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // expect 9e107d9d372bb6826bd81d3542a419d6 + printMD5("The quick brown fox jumps over the lazy dog"); + + // expect 80070713463e7749b90c2dc24911e275 + printHMACMD5("key", "The quick brown fox jumps over the lazy dog"); +} + +void loop() { +} + +void printMD5(const char* str) { + Serial.print("MD5 of '"); + Serial.print(str); + Serial.print("' is 0x"); + + MD5.beginHash(); + MD5.print(str); + MD5.endHash(); + + printResult(); +} + +void printHMACMD5(const char* secret, const char* str) { + Serial.print("HMAC-MD5 of '"); + Serial.print(str); + Serial.print("' with secret '"); + Serial.print(secret); + Serial.print("' is 0x"); + + MD5.beginHmac(secret); + MD5.print(str); + MD5.endHmac(); + + printResult(); +} + +void printResult() { + while (MD5.available()) { + byte b = MD5.read(); + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/MKRGSMSSLClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/MKRGSMSSLClient.ino new file mode 100644 index 00000000..a9ebd3e7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/MKRGSMSSLClient.ino @@ -0,0 +1,94 @@ +/* + This example creates a client object that connects and transfers + data using always SSL. + + It is compatible with the methods normally related to plain + connections, like client.connect(host, port). + + Written by Arturo Guadalupi + last revision November 2015 + +*/ + +#include +#include + +const char pin[] = ""; +const char apn[] = "apn"; +const char login[] = "login"; +const char password[] = "pass"; + +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +GPRS gprs; +GSM gsmAccess; + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +GSMClient client; +BearSSLClient sslClient(client); + +unsigned long getTime() { + return gsmAccess.getTime(); +} + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // connection state + boolean notConnected = true; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (notConnected) { + if ((gsmAccess.begin(pin) == GSM_READY) & (gprs.attachGPRS(apn, login, password) == GPRS_READY)) { + notConnected = false; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected to GPRS"); + + ArduinoBearSSL.onGetTime(getTime); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (sslClient.connect(server, 443)) { + Serial.println("connected to server"); + // Make a HTTP request: + sslClient.println("GET /search?q=arduino HTTP/1.1"); + sslClient.println("Host: www.google.com"); + sslClient.println("Connection: close"); + sslClient.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (sslClient.available()) { + char c = sslClient.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!sslClient.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + sslClient.stop(); + + // do nothing forevermore: + while (true) + ; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/SHA1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/SHA1.ino new file mode 100644 index 00000000..45978296 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/SHA1.ino @@ -0,0 +1,70 @@ +/* + ArduinoBearSSL SHA1 + + This sketch demonstrates how to create a SHA1 hash and HMAC + for an input string. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // expect 0xDA39A3EE5E6B4B0D3255BFEF95601890AFD80709 + printSHA1(""); + + // expect 0x2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12 + printSHA1("The quick brown fox jumps over the lazy dog"); + + // expect 0xFBDB1D1B18AA6C08324B7D64B71FB76370690E1D + printHMACSHA1("", ""); + + // expect 0xDE7C9B85B8B78AA6BC8A7A36F70A90701C9DB4D9 + printHMACSHA1("key", "The quick brown fox jumps over the lazy dog"); +} + +void loop() { +} + +void printSHA1(const char* str) { + Serial.print("SHA1 of '"); + Serial.print(str); + Serial.print("' is 0x"); + + SHA1.beginHash(); + SHA1.print(str); + SHA1.endHash(); + + printResult(); +} + +void printHMACSHA1(const char* secret, const char* str) { + Serial.print("HMAC-SHA1 of '"); + Serial.print(str); + Serial.print("' with secret '"); + Serial.print(secret); + Serial.print("' is 0x"); + + SHA1.beginHmac(secret); + SHA1.print(str); + SHA1.endHmac(); + + printResult(); +} + +void printResult() { + while (SHA1.available()) { + byte b = SHA1.read(); + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/SHA256.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/SHA256.ino new file mode 100644 index 00000000..8a32c576 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/SHA256.ino @@ -0,0 +1,76 @@ +/* + ArduinoBearSSL SHA256 + + This sketch demonstrates how to create a SHA256 hash and HMAC + for an input string. + + This example code is in the public domain. +*/ + +#include +#include "SHA256.h" + +#ifdef ARDUINO_ARCH_MEGAAVR +// Create the object +SHA256Class SHA256; +#endif + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // expect 0xE3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 + printSHA256(""); + + // expect 0xD7A8FBB307D7809469CA9ABCB0082E4F8D5651E46D3CDB762D02D0BF37C9E592 + printSHA256("The quick brown fox jumps over the lazy dog"); + + // expect 0xB613679A0814D9EC772F95D778C35FC5FF1697C493715653C6C712144292C5AD + printHMACSHA256("", ""); + + // expect 0xF7BC83F430538424B13298E6AA6FB143EF4D59A14946175997479DBC2D1A3CD8 + printHMACSHA256("key", "The quick brown fox jumps over the lazy dog"); +} + +void loop() { +} + +void printSHA256(const char* str) { + Serial.print("SHA256 of '"); + Serial.print(str); + Serial.print("' is 0x"); + + SHA256.beginHash(); + SHA256.print(str); + SHA256.endHash(); + + printResult(); +} + +void printHMACSHA256(const char* secret, const char* str) { + Serial.print("HMAC-SHA256 of '"); + Serial.print(str); + Serial.print("' with secret '"); + Serial.print(secret); + Serial.print("' is 0x"); + + SHA256.beginHmac(secret); + SHA256.print(str); + SHA256.endHmac(); + + printResult(); +} + +void printResult() { + while (SHA256.available()) { + byte b = SHA256.read(); + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/WiFiSSLClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/WiFiSSLClient.ino new file mode 100644 index 00000000..7e18c534 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/WiFiSSLClient.ino @@ -0,0 +1,115 @@ +/* + This example creates a client object that connects and transfers + data using always SSL. + + It is compatible with the methods normally related to plain + connections, like client.connect(host, port). + + Written by Arturo Guadalupi + last revision November 2015 + +*/ + +#include +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; +BearSSLClient sslClient(client); + +unsigned long getTime() { + return WiFi.getTime(); +} + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to wifi"); + printWiFiStatus(); + + ArduinoBearSSL.onGetTime(getTime); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (sslClient.connect(server, 443)) { + Serial.println("connected to server"); + // Make a HTTP request: + sslClient.println("GET /search?q=arduino HTTP/1.1"); + sslClient.println("Host: www.google.com"); + sslClient.println("Connection: close"); + sslClient.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (sslClient.available()) { + char c = sslClient.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!sslClient.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + sslClient.stop(); + + // do nothing forevermore: + while (true) + ; + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/README.adoc new file mode 100644 index 00000000..56d14c8f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoDMX + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Control DMX lights with your Arduino. + +Using RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library. + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/examples/DMXBlink/DMXBlink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/examples/DMXBlink/DMXBlink.ino new file mode 100644 index 00000000..e1b172d5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/examples/DMXBlink/DMXBlink.ino @@ -0,0 +1,52 @@ +/* + DMX Blink + + This sketch toggles the value of DMX channel 1 between 255 and 0. + + Circuit: + - DMX light + - MKR board + - MKR 485 shield + - ISO GND connected to DMX light GND (pin 1) + - Y connected to DMX light Data + (pin 2) + - Z connected to DMX light Data - (pin 3) + - Jumper positions + - Z \/\/ Y set to ON + + created 5 July 2018 + by Sandeep Mistry +*/ + +#include // the ArduinoDMX library depends on ArduinoRS485 +#include + +const int universeSize = 16; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // initialize the DMX library with the universe size + if (!DMX.begin(universeSize)) { + Serial.println("Failed to initialize DMX!"); + while (1) + ; // wait for ever + } +} + +void loop() { + // set channel 1 value to 255 + DMX.beginTransmission(); + DMX.write(1, 255); + DMX.endTransmission(); + + delay(1000); + + // set channel 1 value to 0 + DMX.beginTransmission(); + DMX.write(1, 0); + DMX.endTransmission(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/examples/DMXFade/DMXFade.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/examples/DMXFade/DMXFade.ino new file mode 100644 index 00000000..61f2b9da --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoDMX/examples/DMXFade/DMXFade.ino @@ -0,0 +1,58 @@ +/* + DMX Fade + + This sketch fades the value of DMX channel 1 between 0 and 255 in steps to create a fade effect. + All other slots are set to a value of 0. + + Circuit: + - DMX light + - MKR board + - MKR 485 shield + - ISO GND connected to DMX light GND (pin 1) + - Y connected to DMX light Data + (pin 2) + - Z connected to DMX light Data - (pin 3) + - Jumper positions + - Z \/\/ Y set to ON + + created 5 July 2018 + by Sandeep Mistry +*/ + +#include // the ArduinoDMX library depends on ArduinoRS485 +#include + +const int universeSize = 16; + +int brightness = 0; +int fadeAmount = 5; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // initialize the DMX library with the universe size + if (!DMX.begin(universeSize)) { + Serial.println("Failed to initialize DMX!"); + while (1) + ; // wait for ever + } +} + +void loop() { + // set the value of channel 1 + DMX.beginTransmission(); + DMX.write(1, brightness); + DMX.endTransmission(); + + // change the brightness for the next round + brightness += fadeAmount; + + // reverse fade direction when on edge of range + if (brightness <= 0 || brightness >= 255) { + fadeAmount = -fadeAmount; + } + + // delay for dimming effect + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/README.adoc new file mode 100644 index 00000000..182880a7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/README.adoc @@ -0,0 +1,29 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: ArduinoECCX08 + += {repository-name} = + +image:https://github.com/{repository-owner}/{repository-name}/workflows/Compile%20Examples/badge.svg["Compile Examples Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Compile+Examples"] +image:https://github.com/{repository-owner}/{repository-name}/workflows/Arduino%20Lint/badge.svg["Arduino Lint Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Arduino+Lint"] +image:https://github.com/{repository-owner}/{repository-name}/workflows/Spell%20Check/badge.svg["Spell Check Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Spell+Check"] + +Arduino Library for the Atmel/Microchip ECC508 and ECC608 crypto chips + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/ECCX08RandomNumber/ECCX08RandomNumber.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/ECCX08RandomNumber/ECCX08RandomNumber.ino new file mode 100644 index 00000000..5890207a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/ECCX08RandomNumber/ECCX08RandomNumber.ino @@ -0,0 +1,39 @@ +/* + ECCX08 Random Number + + This sketch uses the ECC508 or ECC608 to generate a random number + every second and print it to the Serial monitor + + Circuit: + - MKR board with ECC508 or ECC608 on board + + created 19 July 2018 + by Sandeep Mistry +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("Failed to communicate with ECC508/ECC608!"); + while (1) + ; + } + + if (!ECCX08.locked()) { + Serial.println("The ECC508/ECC608 is not locked!"); + while (1) + ; + } +} + +void loop() { + Serial.print("Random number = "); + Serial.println(ECCX08.random(65535)); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08CSR/ECCX08CSR.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08CSR/ECCX08CSR.ino new file mode 100644 index 00000000..ad2a5f79 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08CSR/ECCX08CSR.ino @@ -0,0 +1,158 @@ +/* + ArduinoECCX08 - CSR (Certificate Signing Request) + + This sketch can be used to generate a CSR for a private key + generated in an ECC508/ECC608 crypto chip slot. + + If the ECC508/ECC608 is not configured and locked it prompts + the user to configure and lock the chip with a default TLS + configuration. + + The user is prompted for the following information that is contained + in the generated CSR: + - country + - state or province + - locality + - organization + - organizational unit + - common name + + The user can also select a slot number to use for the private key + A new private key can also be generated in this slot. + + The circuit: + - Arduino MKR board equipped with ECC508 or ECC608 chip + + This example code is in the public domain. +*/ + +#include +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + String serialNumber = ECCX08.serialNumber(); + + Serial.print("ECCX08 Serial Number = "); + Serial.println(serialNumber); + Serial.println(); + + if (!ECCX08.locked()) { + String lock = promptAndReadLine("The ECCX08 on your board is not locked, would you like to PERMANENTLY configure and lock it now? (y/N)", "N"); + lock.toLowerCase(); + + if (!lock.startsWith("y")) { + Serial.println("Unfortunately you can't proceed without locking it :("); + while (1) + ; + } + + if (!ECCX08.writeConfiguration(ECCX08_DEFAULT_TLS_CONFIG)) { + Serial.println("Writing ECCX08 configuration failed!"); + while (1) + ; + } + + if (!ECCX08.lock()) { + Serial.println("Locking ECCX08 configuration failed!"); + while (1) + ; + } + + Serial.println("ECCX08 locked successfully"); + Serial.println(); + } + + Serial.println("Hi there, in order to generate a new CSR for your board, we'll need the following information ..."); + Serial.println(); + + String country = promptAndReadLine("Country Name (2 letter code)", ""); + String stateOrProvince = promptAndReadLine("State or Province Name (full name)", ""); + String locality = promptAndReadLine("Locality Name (eg, city)", ""); + String organization = promptAndReadLine("Organization Name (eg, company)", ""); + String organizationalUnit = promptAndReadLine("Organizational Unit Name (eg, section)", ""); + String common = promptAndReadLine("Common Name (e.g. server FQDN or YOUR name)", serialNumber.c_str()); + String slot = promptAndReadLine("What slot would you like to use? (0 - 4)", "0"); + String generateNewKey = promptAndReadLine("Would you like to generate a new private key? (Y/n)", "Y"); + + Serial.println(); + + generateNewKey.toLowerCase(); + + if (!ECCX08CSR.begin(slot.toInt(), generateNewKey.startsWith("y"))) { + Serial.println("Error starting CSR generation!"); + while (1) + ; + } + + ECCX08CSR.setCountryName(country); + ECCX08CSR.setStateProvinceName(stateOrProvince); + ECCX08CSR.setLocalityName(locality); + ECCX08CSR.setOrganizationName(organization); + ECCX08CSR.setOrganizationalUnitName(organizationalUnit); + ECCX08CSR.setCommonName(common); + + String csr = ECCX08CSR.end(); + + if (!csr) { + Serial.println("Error generating CSR!"); + while (1) + ; + } + + Serial.println("Here's your CSR, enjoy!"); + Serial.println(); + Serial.println(csr); +} + +void loop() { + // do nothing +} + +String promptAndReadLine(const char* prompt, const char* defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + + if (s.length() == 0) { + s = defaultValue; + } + + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + continue; + } else if (c == '\n') { + break; + } + + line += c; + } + } + + return line; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08JWSPublicKey/ECCX08JWSPublicKey.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08JWSPublicKey/ECCX08JWSPublicKey.ino new file mode 100644 index 00000000..03860626 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08JWSPublicKey/ECCX08JWSPublicKey.ino @@ -0,0 +1,124 @@ +/* + ArduinoECCX08 - JWS Public Key + + This sketch can be used to generate a PEM public key for a private key + generated in an ECC508/ECC608 crypto chip slot. + + If the ECC508/ECC608 is not configured and locked it prompts + the user to configure and lock the chip with a default TLS + configuration. + + The user can also select a slot number to use for the private key + A new private key can also be generated in this slot. + + The circuit: + - Arduino MKR board equipped with ECC508 or ECC608 chip + + This example code is in the public domain. +*/ + +#include +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + if (!ECCX08.locked()) { + String lock = promptAndReadLine("The ECCX08 on your board is not locked, would you like to PERMANENTLY configure and lock it now? (y/N)", "N"); + lock.toLowerCase(); + + if (!lock.startsWith("y")) { + Serial.println("Unfortunately you can't proceed without locking it :("); + while (1) + ; + } + + if (!ECCX08.writeConfiguration(ECCX08_DEFAULT_TLS_CONFIG)) { + Serial.println("Writing ECCX08 configuration failed!"); + while (1) + ; + } + + if (!ECCX08.lock()) { + Serial.println("Locking ECCX08 configuration failed!"); + while (1) + ; + } + + Serial.println("ECCX08 locked successfully"); + Serial.println(); + } + + Serial.println("Hi there, in order to generate a PEM public key for your board, we'll need the following information ..."); + Serial.println(); + + String slot = promptAndReadLine("What slot would you like to use? (0 - 4)", "0"); + String generateNewKey = promptAndReadLine("Would you like to generate a new private key? (Y/n)", "Y"); + + Serial.println(); + + generateNewKey.toLowerCase(); + + String publicKeyPem = ECCX08JWS.publicKey(slot.toInt(), generateNewKey.startsWith("y")); + + if (!publicKeyPem || publicKeyPem == "") { + Serial.println("Error generating public key!"); + while (1) + ; + } + + Serial.println("Here's your public key PEM, enjoy!"); + Serial.println(); + Serial.println(publicKeyPem); +} + +void loop() { + // do nothing +} + +String promptAndReadLine(const char* prompt, const char* defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + + if (s.length() == 0) { + s = defaultValue; + } + + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + continue; + } else if (c == '\n') { + break; + } + + line += c; + } + } + + return line; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08SelfSignedCert/ECCX08SelfSignedCert.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08SelfSignedCert/ECCX08SelfSignedCert.ino new file mode 100644 index 00000000..0dbde247 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08SelfSignedCert/ECCX08SelfSignedCert.ino @@ -0,0 +1,156 @@ +/* + ArduinoECCX08 - Self Signed Cert + + This sketch can be used to generate a self signed certificate + for a private key generated in an ECC508/ECC608 crypto chip slot. + The issue and expired date, and signature are stored in another + slot for reconstrution. + + If the ECC508/ECC608 is not configured and locked it prompts + the user to configure and lock the chip with a default TLS + configuration. + + The user can also select the slot number to use for the private key + and storage. + A new private key can also be generated in this slot. + + The circuit: + - Arduino MKR board equipped with ECC508 or ECC608 chip + + This example code is in the public domain. +*/ + +#include +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + String serialNumber = ECCX08.serialNumber(); + + Serial.print("ECCX08 Serial Number = "); + Serial.println(serialNumber); + Serial.println(); + + if (!ECCX08.locked()) { + String lock = promptAndReadLine("The ECCX08 on your board is not locked, would you like to PERMANENTLY configure and lock it now? (y/N)", "N"); + lock.toLowerCase(); + + if (!lock.startsWith("y")) { + Serial.println("Unfortunately you can't proceed without locking it :("); + while (1) + ; + } + + if (!ECCX08.writeConfiguration(ECCX08_DEFAULT_TLS_CONFIG)) { + Serial.println("Writing ECCX08 configuration failed!"); + while (1) + ; + } + + if (!ECCX08.lock()) { + Serial.println("Locking ECCX08 configuration failed!"); + while (1) + ; + } + + Serial.println("ECCX08 locked successfully"); + Serial.println(); + } + + Serial.println("Hi there, in order to generate a new self signed cert for your board, we'll need the following information ..."); + Serial.println(); + + String issueYear = promptAndReadLine("Please enter the issue year of the certificate? (2000 - 2031)", "2019"); + String issueMonth = promptAndReadLine("Please enter the issue month of the certificate? (1 - 12)", "1"); + String issueDay = promptAndReadLine("Please enter the issue day of the certificate? (1 - 31)", "1"); + String issueHour = promptAndReadLine("Please enter the issue hour of the certificate? (0 - 23)", "0"); + String expireYears = promptAndReadLine("Please enter how many years the certificate is valid for? (1 - 31)", "31"); + String privateKeySlot = promptAndReadLine("What slot would you like to use for the private key? (0 - 4)", "0"); + String storageSlot = promptAndReadLine("What slot would you like to use for storage? (8 - 15)", "8"); + String generateNewKey = promptAndReadLine("Would you like to generate a new private key? (Y/n)", "Y"); + + Serial.println(); + + generateNewKey.toLowerCase(); + + if (!ECCX08SelfSignedCert.beginStorage(privateKeySlot.toInt(), storageSlot.toInt(), generateNewKey.startsWith("y"))) { + Serial.println("Error starting self signed cert generation!"); + while (1) + ; + } + + ECCX08SelfSignedCert.setCommonName(ECCX08.serialNumber()); + ECCX08SelfSignedCert.setIssueYear(issueYear.toInt()); + ECCX08SelfSignedCert.setIssueMonth(issueMonth.toInt()); + ECCX08SelfSignedCert.setIssueDay(issueDay.toInt()); + ECCX08SelfSignedCert.setIssueHour(issueHour.toInt()); + ECCX08SelfSignedCert.setExpireYears(expireYears.toInt()); + + String cert = ECCX08SelfSignedCert.endStorage(); + + if (!cert) { + Serial.println("Error generating self signed cert!"); + while (1) + ; + } + + Serial.println("Here's your self signed cert, enjoy!"); + Serial.println(); + Serial.println(cert); + Serial.println(); + + Serial.print("SHA1: "); + Serial.println(ECCX08SelfSignedCert.sha1()); +} + +void loop() { + // do nothing +} + +String promptAndReadLine(const char* prompt, const char* defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + + if (s.length() == 0) { + s = defaultValue; + } + + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + continue; + } else if (c == '\n') { + break; + } + + line += c; + } + } + + return line; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoGraphics/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoGraphics/README.adoc new file mode 100644 index 00000000..a77a80e7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoGraphics/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoGraphics + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Core graphics library for Arduino. Based on the Processing API. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/ArduinoGraphics + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoGraphics/examples/ASCIIDraw/ASCIIDraw.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoGraphics/examples/ASCIIDraw/ASCIIDraw.ino new file mode 100644 index 00000000..879b2fcb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoGraphics/examples/ASCIIDraw/ASCIIDraw.ino @@ -0,0 +1,107 @@ +/* + ASCIIDraw + + Use the ArduinoGraphics library to draw ASCII art on the Serial Monitor. + + This is intended primarily to allow testing of the library. + See the Arduino_MKRRGB library for a more useful demonstration of the ArduinoGraphics library. + + The circuit: + - Arduino board + + This example code is in the public domain. +*/ + +#include + +const byte canvasWidth = 61; +const byte canvasHeight = 27; + +class ASCIIDrawClass : public ArduinoGraphics { +public: + // can be used with an object of any class that inherits from the Print class + ASCIIDrawClass(Print &printObject = (Print &)Serial) + : ArduinoGraphics(canvasWidth, canvasHeight), + _printObject(&printObject) {} + + // this function is called by the ArduinoGraphics library's functions + virtual void set(int x, int y, uint8_t r, uint8_t g, uint8_t b) { + // the r parameter is (mis)used to set the character to draw with + _canvasBuffer[x][y] = r; + // cast unused parameters to void to fix "unused parameter" warning + (void)g; + (void)b; + } + + // display the drawing + void endDraw() { + ArduinoGraphics::endDraw(); + + for (byte row = 0; row < canvasHeight; row++) { + for (byte column = 0; column < canvasWidth; column++) { + // handle unset parts of buffer + if (_canvasBuffer[column][row] == 0) { + _canvasBuffer[column][row] = ' '; + } + _printObject->print(_canvasBuffer[column][row]); + } + _printObject->println(); + } + } + +private: + Print *_printObject; + char _canvasBuffer[canvasWidth][canvasHeight] = { { 0 } }; +}; + +ASCIIDrawClass ASCIIDraw; + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + ASCIIDraw.beginDraw(); + + // configure the character used to fill the background. The second and third parameters are ignored + ASCIIDraw.background('+', 0, 0); + ASCIIDraw.clear(); + + // add the outer border + ASCIIDraw.stroke('-', 0, 0); + ASCIIDraw.fill('*', 0, 0); + const byte outerBorderThickness = 1; + ASCIIDraw.rect(outerBorderThickness, outerBorderThickness, canvasWidth - outerBorderThickness * 2, canvasHeight - outerBorderThickness * 2); + + // add the inner border + ASCIIDraw.stroke('+', 0, 0); + ASCIIDraw.fill('O', 0, 0); + const byte borderThickness = outerBorderThickness + 6; + ASCIIDraw.rect(borderThickness, borderThickness, canvasWidth - borderThickness * 2, canvasHeight - borderThickness * 2); + + // add the text + ASCIIDraw.background(' ', 0, 0); + ASCIIDraw.stroke('@', 0, 0); + const char text[] = "ARDUINO"; + ASCIIDraw.textFont(Font_5x7); + const byte textWidth = strlen(text) * ASCIIDraw.textFontWidth(); + const byte textHeight = ASCIIDraw.textFontHeight(); + const byte textX = (canvasWidth - textWidth) / 2; + const byte textY = (canvasHeight - textHeight) / 2; + ASCIIDraw.text(text, textX, textY); + + // underline the text + ASCIIDraw.stroke('-', 0, 0); + ASCIIDraw.line(textX, textY + textHeight - 1, textX + textWidth - 1, textY + textHeight - 1); + + // add some accents to the underline + ASCIIDraw.stroke('+', 0, 0); + ASCIIDraw.point(textX + 4, textY + textHeight - 1); + ASCIIDraw.point(textX + textWidth - 1 - 4, textY + textHeight - 1); + + // print the drawing to the Serial Monitor + ASCIIDraw.endDraw(); +} + +void loop() {} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/LICENSE new file mode 100644 index 00000000..4a1b324f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/LICENSE @@ -0,0 +1,688 @@ +This file includes licensing information for ArduinoIoTCloud + +Copyright (c) 2019 ARDUINO SA (www.arduino.cc) + +The software is released under the GNU General Public License, which covers the main body +of the ArduinoIoTCloud code. The terms of this license can be found at: +https://www.gnu.org/licenses/gpl-3.0.en.html + +You can be released from the requirements of the above licenses by purchasing +a commercial license. Buying such a license is mandatory if you want to modify or +otherwise use the software for commercial activities involving the Arduino +software without disclosing the source code of your own applications. To purchase +a commercial license, send an email to license@arduino.cc + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/README.md new file mode 100644 index 00000000..c18fd280 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/README.md @@ -0,0 +1,88 @@ +`ArduinoIoTCloud` +================= + +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoIoTCloud/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoIoTCloud/actions/workflows/check-arduino.yml) +[![Compile Examples](https://github.com/arduino-libraries/ArduinoIoTCloud/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoIoTCloud/actions?workflow=Compile+Examples) +[![Spell Check](https://github.com/arduino-libraries/ArduinoIoTCloud/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoIoTCloud/actions?workflow=Spell+Check) +[![Unit Tests](https://github.com/arduino-libraries/ArduinoIoTCloud/workflows/Unit%20Tests/badge.svg)](https://github.com/arduino-libraries/ArduinoIoTCloud/actions?workflow=Unit+Tests) +[![codecov](https://codecov.io/gh/arduino-libraries/ArduinoIoTCloud/branch/master/graph/badge.svg)](https://codecov.io/gh/arduino-libraries/ArduinoIoTCloud) + +### What? +The `ArduinoIoTCloud` library is the central element of the firmware enabling certain Arduino boards to connect to the [Arduino IoT Cloud](https://www.arduino.cc/en/IoT/HomePage). The following boards are supported: + +* **WiFi**: [`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), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/1.0.6) +* **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) +* **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) +* **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) + +### How? +1) Register your Arduino IoT Cloud capable board via [Arduino IoT Cloud](https://create.arduino.cc/iot) (Devices Section). +2) Create a new logical representation known as a [Thing](https://create.arduino.cc/iot/things). + +### Arduino IoT Cloud Components + +- **Devices**: Physical objects built around a board (e.g. `MKR WiFi 1010`). This is the hardware which runs the sketch, reads sensors, controls actuators and communicates with the Arduino IoT Cloud. + +- **Things**: Logical representation of a connected object. They embody inherent properties of the object, with as little reference to the actual hardware or code used to implement them. Each Thing is represented by a collection of _Properties_ (e.g., temperature, light, pressure...). + +- **Properties**: Qualities defining the characteristics of a system. A _Property_ can be defined as *read-only* (`READ`) to indicate that Arduino IoT Cloud can read the data, but cannot change the value of such _Property_. On the other end, it may be designated to be **read-and-write** (`READWRITE`), allowing Arduino IoT Cloud to remotely change the property’s value and trigger an event notification on the device. It is also possible to mark properties as *write-only* (`WRITE`) which means the cloud can write to this property but not read its value (this limits data transmission for properties which are used to trigger events only). + +### How-to-use +* `thingProperties.h` +```C++ +void onLedChange(); +/* ... */ +bool led; +int seconds; +/* ... */ +void initProperties() { + ArduinoCloud.setThingId("ARDUINO-THING-ID"); + ArduinoCloud.addProperty(led, WRITE, ON_CHANGE, onLedChange); + ArduinoCloud.addProperty(seconds, READ, ON_CHANGE); +} +/* ... */ +WiFiConnectionHandler ArduinoIoTPreferredConnection("SECRET_SSID", "SECRET_PASS"); +``` + +* `MyCloudApplication.ino` +```C++ +#include "thingProperties.h" + +void setup() { + Serial.begin(9600); + while(!Serial) { } + pinMode(LED_BUILTIN, OUTPUT); + + initProperties(); + ArduinoCloud.begin(ArduinoIoTPreferredConnection); +} + +void loop() { + ArduinoCloud.update(); + seconds = millis() / 1000; +} + +void onLedChange() { + digitalWrite(LED_BUILTIN, led); +} +``` + +### FAQ +#### Watchdog +This [1.0.0](https://github.com/arduino-libraries/ArduinoIoTCloud/releases/tag/1.0.0) release of this library adds watchdog functionality to all ATSAMD21G18 based cloud connected boards. A watchdog is simply an electronic timer counting down from a preset start value which, upon reaching zero, triggers a reset of the microcontroller. It can be used to automatically recover from temporary hardware faults or unrecoverable software errors. In order to avoid the watchdog from reaching zero the countdown timer needs to be regularly re-set to its start value. This is happening within `ArduinoCloud.update()` which is periodically called at the start of the `loop()` function. Although the watchdog is automatically enabled it can be disabled by setting the second parameter of `ArduinoCloud.begin(...)` to `false`: +```C++ +ArduinoCloud.begin(ArduinoIoTPreferredConnection, false). +``` + +#### Device can not subscribe to `THING_ID` +``` +ArduinoIoTCloudTCP::handle_SubscribeMqttTopics could not subscribe to /a/t/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/e/i +``` +In this case either the device has not been associated with the thing within the Arduino IoT Cloud GUI configuration or there's a typo in the thing id. + +#### ESP Boards +Support for ESP boards is obtained through third-party core with some differences and limitations compared to Arduino boards. + +- **Authentication scheme**: Board authentication is done through `DEVICE_LOGIN_NAME` and `DEVICE_KEY`, both values are included in the `thingProperties.h` file. +- **RTC**: RTC support is not included thus each `ArduinoCould.update()` call will lead to an NTP request introducing delay in your `loop()` function. The scheduler widget will not work correctly if connection is lost after configuration. +- **Watchdog**: Watchdog support is not included. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino new file mode 100644 index 00000000..a8dcdc55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino @@ -0,0 +1,59 @@ +/* + This sketch demonstrates how to use more complex cloud data types such as a colour or coordinates. + + This sketch is compatible with: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR NB 1500 + - MKR WAN 1300/1310 + - Nano 33 IoT + - ESP 8266 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for (unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000);) {} + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +float latMov = 45.5058224, lonMov = 9.1628673; +float latArd = 45.0502078, lonArd = 7.6674765; + +float hueRed = 0.0, satRed = 100.0, briRed = 100.0; +float hueGreen = 80.0, satGreen = 100.0, briGreen = 100.0; + +void loop() { + ArduinoCloud.update(); +} + +void onSwitchButtonChange() { + if (switchButton) { + location = Location(latMov, lonMov); + color = Color(hueRed, satRed, briRed); + } else { + location = Location(latArd, lonArd); + color = Color(hueGreen, satGreen, briGreen); + } +} + +void onColorChange() { + Serial.print("Hue = "); + Serial.println(color.getValue().hue); + Serial.print("Sat = "); + Serial.println(color.getValue().sat); + Serial.print("Bri = "); + Serial.println(color.getValue().bri); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h new file mode 100644 index 00000000..bd82601f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) +#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" +#define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) +#define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) +#define SECRET_APP_EUI "" +#define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/thingProperties.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/thingProperties.h new file mode 100644 index 00000000..72ef897f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/thingProperties.h @@ -0,0 +1,39 @@ +#include +#include + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void onSwitchButtonChange(); +void onColorChange(); + +bool switchButton; +CloudLocation location; +CloudColor color; + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE, onSwitchButtonChange); + ArduinoCloud.addProperty(location, READ, ON_CHANGE); + ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE, onSwitchButtonChange); + ArduinoCloud.addProperty(location, 2, READ, ON_CHANGE); + ArduinoCloud.addProperty(color, 3, READWRITE, ON_CHANGE, onColorChange); +#endif +} + +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino new file mode 100644 index 00000000..a2e90f69 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino @@ -0,0 +1,61 @@ +/* + This sketch demonstrates how to exchange data between your board and the Arduino IoT Cloud. + + * Connect a potentiometer (or other analog sensor) to A0. + * When the potentiometer (or sensor) value changes the data is sent to the Cloud. + * When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF. + + IMPORTANT: + This sketch works with WiFi, GSM, NB and Lora enabled boards supported by Arduino IoT Cloud. + On a LoRa board, if it is configuered as a class A device (default and preferred option), values from Cloud dashboard are received + only after a value is sent to Cloud. + + This sketch is compatible with: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR NB 1500 + - MKR WAN 1300/1310 + - Nano 33 IoT + - ESP 8266 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +#if defined(ESP32) +static int const LED_BUILTIN = 2; +#endif + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for (unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000);) {} + + /* Configure LED pin as an output */ + pinMode(LED_BUILTIN, OUTPUT); + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); + potentiometer = analogRead(A0); + seconds = millis() / 1000; +} + +/* + * 'onLedChange' is called when the "led" property of your Thing changes + */ +void onLedChange() { + Serial.print("LED set to "); + Serial.println(led); + digitalWrite(LED_BUILTIN, led); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/arduino_secrets.h new file mode 100644 index 00000000..bd82601f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) +#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" +#define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) +#define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) +#define SECRET_APP_EUI "" +#define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/thingProperties.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/thingProperties.h new file mode 100644 index 00000000..4744276b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/thingProperties.h @@ -0,0 +1,46 @@ +#include +#include + +#if defined(BOARD_HAS_WIFI) +#elif defined(BOARD_HAS_GSM) +#elif defined(BOARD_HAS_LORA) +#elif defined(BOARD_HAS_NB) +#else +#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400" +#endif + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void onLedChange(); + +bool led; +int potentiometer; +int seconds; + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange); + ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10); + ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange); + ArduinoCloud.addProperty(potentiometer, 2, READ, ON_CHANGE); + ArduinoCloud.addProperty(seconds, 3, READ, 5 * MINUTES); +#endif +} + +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino new file mode 100644 index 00000000..ba22d7b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino @@ -0,0 +1,80 @@ +/* + This sketch demonstrates how to subscribe to IoT Cloud events and perform actions + The available events are + + CONNECT : Board successfully connects to IoT Cloud + SYNC : Data is successfully synced between Board and IoT Cloud + DISCONNECT : Board has lost connection to IoT Cloud + + You don't need any specific Properties to be created in order to demonstrate these functionalities. + Simply create a new Thing and give it 1 arbitrary Property. + Remember that the Thing ID needs to be configured in thingProperties.h + These events can be very useful in particular cases, for instance to disable a peripheral + or a connected sensor/actuator when no data connection is available, as well as to perform + specific operations on connection or right after properties values are synchronised. + + To subscribe to an event you can use the `addCallback` method and specify + which event will trigger which custom function. + One function per event can be assigned. + + IMPORTANT: + This sketch works with WiFi, GSM, NB and Lora enabled boards supported by Arduino IoT Cloud. + On a LoRa board, if it is configuered as a class A device (default and preferred option), values from Cloud dashboard are received + only after a value is sent to Cloud. + + This sketch is compatible with: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR NB 1500 + - MKR WAN 1300/1310 + - Nano 33 IoT + - ESP 8266 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for (unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000);) {} + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + /* + Invoking `addCallback` on the ArduinoCloud object allows you to subscribe + to any of the available events and decide which functions to call when they are fired. + + The functions `doThisOnConnect`, `doThisOnSync`, `doThisOnDisconnect` + are custom functions and can be named to your likings and for this example + they are defined/implemented at the bottom of the Sketch + */ + ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect); + ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, doThisOnSync); + ArduinoCloud.addCallback(ArduinoIoTCloudEvent::DISCONNECT, doThisOnDisconnect); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); +} + +void doThisOnConnect() { + /* add your custom code here */ + Serial.println("Board successfully connected to Arduino IoT Cloud"); +} +void doThisOnSync() { + /* add your custom code here */ + Serial.println("Thing Properties synchronised"); +} +void doThisOnDisconnect() { + /* add your custom code here */ + Serial.println("Board disconnected from Arduino IoT Cloud"); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h new file mode 100644 index 00000000..bd82601f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) +#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" +#define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) +#define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) +#define SECRET_APP_EUI "" +#define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/thingProperties.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/thingProperties.h new file mode 100644 index 00000000..644c00ff --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/thingProperties.h @@ -0,0 +1,33 @@ +#include +#include + +#if defined(BOARD_HAS_WIFI) +#elif defined(BOARD_HAS_GSM) +#elif defined(BOARD_HAS_LORA) +#elif defined(BOARD_HAS_NB) +#else +#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400" +#endif + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +/* BOARD_ID is only required if you are using an ESP8266 */ +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +} + +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino new file mode 100644 index 00000000..e154f1c5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino @@ -0,0 +1,88 @@ +/* + This sketch demonstrates how to handle deferred OTA from Arduino IoT Cloud. + + Deferred OTA can be triggered using the arduino-cloud-cli with the following command: + ./arduino-cloud-cli ota upload --device-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --file filename.ino.bin --deferred + The update file and the download link will be available to be used within one week. + + * always_deny callback will always postpone the OTA update + * always_allow callback will immediately apply the OTA update + * ask_user_via_serial callback will read user input from serial to apply or postpone OTA update + + This sketch is compatible with: + - MKR WIFI 1010 + - Nano 33 IoT + - Portenta + - Nano RP2040 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +#if defined(ESP32) +static int const LED_BUILTIN = 2; +#endif + +bool always_deny() { + return false; +} + +bool always_allow() { + return true; +} + +static bool ask_user_via_serial_first_run = true; +bool ask_user_via_serial() { + if (ask_user_via_serial_first_run) { + Serial.println("Apply OTA? y / [n]"); + ask_user_via_serial_first_run = false; + } + if (Serial.available()) { + char c = Serial.read(); + if (c == 'y' || c == 'Y') { + return true; + } + } + return false; +} + +bool onOTARequestCallback() { + /* Select the preferred behaviour changing the called function */ + //return always_deny(); + //return always_allow(); + return ask_user_via_serial(); +} + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for (unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000);) {} + + /* Configure LED pin as an output */ + pinMode(LED_BUILTIN, OUTPUT); + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + /* Setup OTA callback */ + ArduinoCloud.onOTARequestCb(onOTARequestCallback); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); +} + +/* + * 'onLedChange' is called when the "led" property of your Thing changes + */ +void onLedChange() { + Serial.print("LED set to "); + Serial.println(led); + digitalWrite(LED_BUILTIN, led); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h new file mode 100644 index 00000000..bd82601f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) +#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" +#define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) +#define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) +#define SECRET_APP_EUI "" +#define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h new file mode 100644 index 00000000..549d632c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h @@ -0,0 +1,40 @@ +#include +#include + +#if defined(BOARD_HAS_WIFI) +#elif defined(BOARD_HAS_GSM) +#elif defined(BOARD_HAS_LORA) +#elif defined(BOARD_HAS_NB) +#else +#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400" +#endif + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void onLedChange(); + +bool led; + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange); +#endif +} + +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino new file mode 100644 index 00000000..8f2cb8a7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino @@ -0,0 +1,227 @@ +/* + This sketch demonstrates how to use the cloud schedule variable type. + + This sketch is compatible with the following boards: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR NB 1500 + - Nano 33 IoT + - ESP 8266 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +#if defined(ESP32) +static int const LED_BUILTIN = 2; +#endif + +void setup() { + /* Initialize the serial port and wait up to 5 seconds for a connection */ + Serial.begin(9600); + for (unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000);) {} + + /* Configure LED pin as an output */ + pinMode(LED_BUILTIN, OUTPUT); + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); + + /* Setup one shot schedule example */ + setupOneShotSchedule(); + + /* Setup per minute schedule example */ + setupMinuteSchedule(); + + /* Setup hourly schedule example */ + setupHourlySchedule(); + + /* Setup daily schedule example */ + setupDailySchedule(); + + /* Setup weekly schedule example */ + setupWeeklySchedule(); + + /* Setup monthly schedule example */ + setupMonthlySchedule(); + + /* Setup yearly schedule example */ + setupYearlySchedule(); +} + +/* Setup a schedule with an active period of 5 minutes that doesn't repeat + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 02 17:00:00 + */ +void setupOneShotSchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = startingFrom + (DAYS * 1); + ScheduleTimeType activePeriod = MINUTES * 5; + + /* Warning: there is no cross check between until and activePeriod */ + ScheduleConfigurationType scheduleConfiguration = Schedule::createOneShotScheduleConfiguration(); + + oneShot = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 15 seconds that repeats each minute + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 02 17:00:00 + */ +void setupMinuteSchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = startingFrom + (DAYS * 1); + ScheduleTimeType activePeriod = SECONDS * 15; + unsigned int repetitionPeriod = 1; + + /* Warning: there is no cross check between repetitionPeriod and activePeriod */ + ScheduleConfigurationType scheduleConfiguration = Schedule::createFixedDeltaScheduleConfiguration(ScheduleUnit::Minutes, repetitionPeriod); + + minute = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 20 minutes that repeats each hour + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 15 13:00:00 + */ +void setupHourlySchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00"); + ScheduleTimeType activePeriod = MINUTES * 20; + unsigned int repetitionPeriod = 1; + + /* Warning: there is no cross check between repetitionPeriod and activePeriod */ + ScheduleConfigurationType scheduleConfiguration = Schedule::createFixedDeltaScheduleConfiguration(ScheduleUnit::Hours, repetitionPeriod); + + hourly = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 2 hours that repeats each day + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 15 13:00:00 + */ +void setupDailySchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00"); + ScheduleTimeType activePeriod = HOURS * 2; + unsigned int repetitionPeriod = 1; + + /* Warning: there is no cross check between repetitionPeriod and activePeriod */ + ScheduleConfigurationType scheduleConfiguration = Schedule::createFixedDeltaScheduleConfiguration(ScheduleUnit::Days, repetitionPeriod); + + daily = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 3 minutes with a weekly configuration + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 31 17:00:00 + * Weekly configuration + * Sunday -> Inactive + * Monday -> Active + * Tuesday -> Inactive + * Wednesday -> Active + * Thursday -> Inactive + * Friday -> Active + * Saturday -> Inactive + */ +void setupWeeklySchedule() { + + unsigned int startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + unsigned int until = startingFrom + (DAYS * 30); + unsigned int executionPeriod = MINUTES * 3; + + ScheduleWeeklyMask WeeklyMask = { + ScheduleState::Inactive, /* Sunday */ + ScheduleState::Active, /* Monday */ + ScheduleState::Inactive, /* Tuesday */ + ScheduleState::Active, /* Wednesday */ + ScheduleState::Inactive, /* Thursday */ + ScheduleState::Active, /* Friday */ + ScheduleState::Inactive, /* Saturday */ + }; + + ScheduleConfigurationType scheduleConfiguration = Schedule::createWeeklyScheduleConfiguration(WeeklyMask); + + weekly = Schedule(startingFrom, until, executionPeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 1 day that repeats each third day of the month + * Starting from 2021 11 01 17:00:00 + * Until 2022 11 15 13:00:00 + */ +void setupMonthlySchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00"); + ScheduleTimeType activePeriod = DAYS * 1; + int dayOfMonth = 3; + + ScheduleConfigurationType scheduleConfiguration = Schedule::createMonthlyScheduleConfiguration(dayOfMonth); + + monthly = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + + +/* Setup a schedule with an active period of 2 days that repeats each year on November 6th + * Starting from 2021 11 06 17:00:00 + * Until 2041 11 15 13:00:00 + */ +void setupYearlySchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 06 17:00:00"); + ScheduleTimeType until = TimeService::getTimeFromString("2041 Nov 06 13:00:00"); + ScheduleTimeType activePeriod = DAYS * 2; + int dayOfMonth = 6; + + ScheduleConfigurationType scheduleConfiguration = Schedule::createYearlyScheduleConfiguration(ScheduleMonth::Nov, dayOfMonth); + + yearly = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +void loop() { + ArduinoCloud.update(); + + /* Print a message when the oneShot schedule is active */ + if (oneShot.isActive()) { + Serial.println("One shot schedule is active"); + } + + /* Print a message when the per minute schedule is active */ + if (minute.isActive()) { + Serial.println("Per minute schedule is active"); + } + + /* Print a message when the hourly schedule is active */ + if (hourly.isActive()) { + Serial.println("Hourly schedule is active"); + } + + /* Print a message when the daily schedule is active */ + if (daily.isActive()) { + Serial.println("Daily schedule is active"); + } + + /* Activate LED when the weekly schedule is active */ + digitalWrite(LED_BUILTIN, weekly.isActive()); + + /* Print a message when the monthly schedule is active */ + if (monthly.isActive()) { + Serial.println("Monthly schedule is active"); + } + + /* Print a message when the yearly schedule is active */ + if (yearly.isActive()) { + Serial.println("Yearly schedule is active"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h new file mode 100644 index 00000000..bd82601f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) +#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" +#define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) +#define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) +#define SECRET_APP_EUI "" +#define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/thingProperties.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/thingProperties.h new file mode 100644 index 00000000..d4bbf968 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/thingProperties.h @@ -0,0 +1,46 @@ +#include +#include + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void onSwitchButtonChange(); + +bool switchButton; +CloudSchedule oneShot; +CloudSchedule minute; +CloudSchedule hourly; +CloudSchedule daily; +CloudSchedule weekly; +CloudSchedule monthly; +CloudSchedule yearly; + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE); + ArduinoCloud.addProperty(oneShot, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(minute, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(hourly, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(daily, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(weekly, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(monthly, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(yearly, READWRITE, ON_CHANGE); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE; +#endif +} + +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino new file mode 100644 index 00000000..0f4b5f3e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino @@ -0,0 +1,49 @@ +/* + This sketch is used in combination with Travis CI to check if + unintentional breaking changes are made to the used facing + Arduino IoT Cloud API. + + This sketch is compatible with: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR WAN 1300/1310 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +void setup() { + + Serial.begin(9600); + unsigned long serialBeginTime = millis(); + while (!Serial && (millis() - serialBeginTime > 5000)) + ; + + Serial.println("Starting Arduino IoT Cloud Example"); + + initProperties(); + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); +} + +void onBoolPropertyChange() { + Serial.println("'onBoolPropertyChange'"); +} + +void onIntPropertyChange() { + Serial.println("'onIntPropertyChange'"); +} + +void onFloatPropertyChange() { + Serial.println("'onFloatPropertyChange'"); +} + +void onStringPropertyChange() { + Serial.println("'onStringPropertyChange'"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h new file mode 100644 index 00000000..9250a358 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h @@ -0,0 +1,29 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) +#define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" +#define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) +#define SECRET_APP_EUI "" +#define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_LOGIN "" +#define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h new file mode 100644 index 00000000..c5a36203 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h @@ -0,0 +1,140 @@ +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include +#include + +#if defined(BOARD_HAS_WIFI) +#elif defined(BOARD_HAS_GSM) +#elif defined(BOARD_HAS_LORA) +#elif defined(BOARD_HAS_NB) +#else +#error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400" +#endif + +/****************************************************************************** + DEFINES + ******************************************************************************/ + +#define THING_ID "ARDUINO_IOT_CLOUD_THING_ID" + +/****************************************************************************** + GLOBAL CONSTANTS + ******************************************************************************/ + +int const MIN_DELTA_INT_PROPERTY = 5; +float const MIN_DELTA_FLOAT_PROPERTY = 10.0f; + +/****************************************************************************** + GLOBAL VARIABLES + ******************************************************************************/ + +bool bool_property_1; +bool bool_property_2; + +int int_property_1; +int int_property_2; +int int_property_3; +int int_property_4; +int int_property_5; +int int_property_6; + +float float_property_1; +float float_property_2; +float float_property_3; +float float_property_4; + +String str_property_1; +String str_property_2; +String str_property_3; +String str_property_4; +String str_property_5; +String str_property_6; +String str_property_7; +String str_property_8; + +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, EU868); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif + +/****************************************************************************** + PROTOTYPES + ******************************************************************************/ + +void onBoolPropertyChange(); +void onIntPropertyChange(); +void onFloatPropertyChange(); +void onStringPropertyChange(); + +/****************************************************************************** + FUNCTIONS + ******************************************************************************/ +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) +void initProperties() { + ArduinoCloud.setThingId(THING_ID); + + ArduinoCloud.addProperty(bool_property_1, READWRITE, 1 * SECONDS); + ArduinoCloud.addProperty(int_property_1, READ, 2 * MINUTES); + ArduinoCloud.addProperty(float_property_1, WRITE, 3 * HOURS); + ArduinoCloud.addProperty(str_property_1, READWRITE, 4 * DAYS); + + ArduinoCloud.addProperty(bool_property_2, Permission::ReadWrite).publishEvery(1 * SECONDS); + ArduinoCloud.addProperty(int_property_2, Permission::Read).publishEvery(1 * MINUTES); + ArduinoCloud.addProperty(float_property_2, Permission::Write).publishEvery(3 * HOURS); + ArduinoCloud.addProperty(str_property_2, Permission::ReadWrite).publishEvery(4 * DAYS); + + ArduinoCloud.addProperty(int_property_3, READWRITE, ON_CHANGE); /* Default 'minDelta' = 0 */ + ArduinoCloud.addProperty(int_property_4, READWRITE, ON_CHANGE, onIntPropertyChange); /* Default 'minDelta' = 0 */ + ArduinoCloud.addProperty(int_property_5, READWRITE, ON_CHANGE, 0 /* onIntPropertyChange */, MIN_DELTA_INT_PROPERTY); + ArduinoCloud.addProperty(int_property_6, READWRITE, ON_CHANGE, onIntPropertyChange, MIN_DELTA_INT_PROPERTY); + + ArduinoCloud.addProperty(float_property_3, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY); + ArduinoCloud.addProperty(float_property_4, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY).onUpdate(onFloatPropertyChange); + + ArduinoCloud.addProperty(str_property_3, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, MOST_RECENT_WINS); + ArduinoCloud.addProperty(str_property_4, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, CLOUD_WINS); + ArduinoCloud.addProperty(str_property_5, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, DEVICE_WINS); + + ArduinoCloud.addProperty(str_property_6, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(MOST_RECENT_WINS); + ArduinoCloud.addProperty(str_property_7, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(CLOUD_WINS); + ArduinoCloud.addProperty(str_property_8, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(DEVICE_WINS); +} + +#elif defined(BOARD_HAS_LORA) +void initProperties() { + ArduinoCloud.setThingId(THING_ID); + + ArduinoCloud.addProperty(bool_property_1, 1, READWRITE, 1 * SECONDS); + ArduinoCloud.addProperty(int_property_1, 2, READ, 2 * MINUTES); + ArduinoCloud.addProperty(float_property_1, 3, WRITE, 3 * HOURS); + ArduinoCloud.addProperty(str_property_1, 4, READWRITE, 4 * DAYS); + + ArduinoCloud.addProperty(bool_property_2, 5, Permission::ReadWrite).publishEvery(1 * SECONDS); + ArduinoCloud.addProperty(int_property_2, 6, Permission::Read).publishEvery(1 * MINUTES); + ArduinoCloud.addProperty(float_property_2, 7, Permission::Write).publishEvery(3 * HOURS); + ArduinoCloud.addProperty(str_property_2, 8, Permission::ReadWrite).publishEvery(4 * DAYS); + + ArduinoCloud.addProperty(int_property_3, 9, READWRITE, ON_CHANGE); /* Default 'minDelta' = 0 */ + ArduinoCloud.addProperty(int_property_4, 10, READWRITE, ON_CHANGE, onIntPropertyChange); /* Default 'minDelta' = 0 */ + ArduinoCloud.addProperty(int_property_5, 11, READWRITE, ON_CHANGE, 0 /* onIntPropertyChange */, MIN_DELTA_INT_PROPERTY); + ArduinoCloud.addProperty(int_property_6, 12, READWRITE, ON_CHANGE, onIntPropertyChange, MIN_DELTA_INT_PROPERTY); + + ArduinoCloud.addProperty(float_property_3, 13, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY); + ArduinoCloud.addProperty(float_property_4, 14, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY).onUpdate(onFloatPropertyChange); + + ArduinoCloud.addProperty(str_property_3, 15, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, MOST_RECENT_WINS); + ArduinoCloud.addProperty(str_property_4, 16, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, CLOUD_WINS); + ArduinoCloud.addProperty(str_property_5, 17, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, DEVICE_WINS); + + ArduinoCloud.addProperty(str_property_6, 18, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(MOST_RECENT_WINS); + ArduinoCloud.addProperty(str_property_7, 19, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(CLOUD_WINS); + ArduinoCloud.addProperty(str_property_8, 20, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(DEVICE_WINS); +} +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/ECCX08TLSConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/ECCX08TLSConfig.h new file mode 100644 index 00000000..a7f2c1d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/ECCX08TLSConfig.h @@ -0,0 +1,105 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef _ECCX08_TLS_CONFIG_H_ +#define _ECCX08_TLS_CONFIG_H_ + +const byte DEFAULT_ECCX08_TLS_CONFIG[128] = { + // Read only - start + // SN[0:3] + 0x01, 0x23, 0x00, 0x00, + // RevNum + 0x00, 0x00, 0x50, 0x00, + // SN[4:8] + 0x00, 0x00, 0x00, 0x00, 0x00, + // Reserved + 0xC0, + // I2C_Enable + 0x71, + // Reserved + 0x00, + // Read only - end + // I2C_Address + 0xC0, + // Reserved + 0x00, + // OTPmode + 0x55, + // ChipMode + 0x00, + // SlotConfig + 0x83, 0x20, // External Signatures | Internal Signatures | IsSecret | Write Configure Never, Default: 0x83, 0x20, + 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x87, 0x20, + 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x8F, 0x20, + 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0xC4, 0x8F, + 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0x8F, 0x8F, + 0x8F, 0x8F, + 0x9F, 0x8F, + 0xAF, 0x8F, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0xAF, 0x8F, + // Counter[0] + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + // Counter[1] + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + // LastKeyUse + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + // Write via commands only - start + // UserExtra + 0x00, + // Selector + 0x00, + // LockValue + 0x55, + // LockConfig + 0x55, + // SlotLocked + 0xFF, 0xFF, + // Write via commands only - end + // RFU + 0x00, 0x00, + // X509format + 0x00, 0x00, 0x00, 0x00, + // KeyConfig + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00, + 0x1C, 0x00, + 0x1C, 0x00, + 0x1C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x1C, 0x00 +}; + +#endif /* _ECCX08_TLS_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/Provisioning.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/Provisioning.ino new file mode 100644 index 00000000..bfa82167 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/Provisioning.ino @@ -0,0 +1,204 @@ +#include +#include "ECCX08TLSConfig.h" + +const bool DEBUG = true; + +ArduinoIoTCloudCertClass Certificate; +CryptoUtil Crypto; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!Crypto.begin()) { + Serial.println("No crypto present!"); + while (1) + ; + } + + if (!Crypto.locked()) { + String lockConfirm = promptAndReadLine("Your crypto is unlocked, would you like to lock it (y/N): "); + lockConfirm.toLowerCase(); + + if (lockConfirm != "y") { + Serial.println("That's all folks"); + while (1) + ; + } + + if (!Crypto.writeConfiguration(DEFAULT_ECCX08_TLS_CONFIG)) { + Serial.println("Writing crypto configuration failed!"); + while (1) + ; + } + + if (!Crypto.lock()) { + Serial.println("Locking crypto configuration failed!"); + while (1) + ; + } + + Serial.println("crypto locked successfully"); + Serial.println(); + } + + String csrConfirm = promptAndReadLine("Would you like to generate a new private key and CSR (y/N): "); + csrConfirm.toLowerCase(); + + if (csrConfirm != "y") { + Serial.println("That's all folks"); + while (1) + ; + } + + if (!Certificate.begin()) { + Serial.println("Error starting CSR generation!"); + while (1) + ; + } + + String deviceId = promptAndReadLine("Please enter the device id: "); + Certificate.setSubjectCommonName(deviceId); + + if (!Crypto.buildCSR(Certificate, CryptoSlot::Key, true)) { + Serial.println("Error generating CSR!"); + while (1) + ; + } + + String csr = Certificate.getCSRPEM(); + + if (!csr) { + Serial.println("Error generating CSR!"); + while (1) + ; + } + + Serial.println("Generated CSR is:"); + Serial.println(); + Serial.println(csr); + + String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): "); + String issueMonth = promptAndReadLine("Please enter the issue month of the certificate (1 - 12): "); + String issueDay = promptAndReadLine("Please enter the issue day of the certificate (1 - 31): "); + String issueHour = promptAndReadLine("Please enter the issue hour of the certificate (0 - 23): "); + String expireYears = promptAndReadLine("Please enter how many years the certificate is valid for (0 - 31): "); + String serialNumber = promptAndReadLine("Please enter the certificates serial number: "); + String authorityKeyIdentifier = promptAndReadLine("Please enter the certificates authority key identifier: "); + String signature = promptAndReadLine("Please enter the certificates signature: "); + + byte serialNumberBytes[CERT_SERIAL_NUMBER_LENGTH]; + byte authorityKeyIdentifierBytes[CERT_AUTHORITY_KEY_ID_LENGTH]; + byte signatureBytes[CERT_SIGNATURE_LENGTH]; + + hexStringToBytes(serialNumber, serialNumberBytes, sizeof(serialNumberBytes)); + hexStringToBytes(authorityKeyIdentifier, authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes)); + hexStringToBytes(signature, signatureBytes, sizeof(signatureBytes)); + + if (!Crypto.writeDeviceId(deviceId, CryptoSlot::DeviceId)) { + Serial.println("Error storing device id!"); + while (1) + ; + } + + if (!Certificate.begin()) { + Serial.println("Error starting crypto storage!"); + while (1) + ; + } + + Certificate.setSubjectCommonName(deviceId); + Certificate.setIssuerCountryName("US"); + Certificate.setIssuerOrganizationName("Arduino LLC US"); + Certificate.setIssuerOrganizationalUnitName("IT"); + Certificate.setIssuerCommonName("Arduino"); + Certificate.setSignature(signatureBytes, sizeof(signatureBytes)); + Certificate.setAuthorityKeyId(authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes)); + Certificate.setSerialNumber(serialNumberBytes, sizeof(serialNumberBytes)); + Certificate.setIssueYear(issueYear.toInt()); + Certificate.setIssueMonth(issueMonth.toInt()); + Certificate.setIssueDay(issueDay.toInt()); + Certificate.setIssueHour(issueHour.toInt()); + Certificate.setExpireYears(expireYears.toInt()); + + if (!Crypto.buildCert(Certificate, CryptoSlot::Key)) { + Serial.println("Error building cert!"); + while (1) + ; + } + + if (!Crypto.writeCert(Certificate, CryptoSlot::CompressedCertificate)) { + Serial.println("Error storing cert!"); + while (1) + ; + } + + if (!DEBUG) { + return; + } + + Serial.println("Compressed cert = "); + + const byte* certData = Certificate.bytes(); + int certLength = Certificate.length(); + + for (int i = 0; i < certLength; i++) { + byte b = certData[i]; + + if (b < 16) { + Serial.print('0'); + } + Serial.print(b, HEX); + } + Serial.println(); +} + +void loop() { +} + +String promptAndReadLine(const char* prompt) { + Serial.print(prompt); + String s = readLine(); + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + } else if (c == '\n') { + break; + } + + line += c; + } + } + + line.trim(); + + return line; +} + +void hexStringToBytes(String& in, byte out[], int length) { + int inLength = in.length(); + in.toUpperCase(); + int outLength = 0; + + for (int i = 0; i < inLength && outLength < length; i += 2) { + char highChar = in[i]; + char lowChar = in[i + 1]; + + byte highByte = (highChar <= '9') ? (highChar - '0') : (highChar + 10 - 'A'); + byte lowByte = (lowChar <= '9') ? (lowChar - '0') : (lowChar + 10 - 'A'); + + out[outLength++] = (highByte << 4) | (lowByte & 0xF); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08Cert.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08Cert.h new file mode 100644 index 00000000..03eea0b1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08Cert.h @@ -0,0 +1,141 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef _ECCX08_CERT_H_ +#define _ECCX08_CERT_H_ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + +/****************************************************************************** + * CLASS DECLARATION + ******************************************************************************/ + +class ECCX08CertClass { + +public: + ECCX08CertClass(); + virtual ~ECCX08CertClass(); + + int beginCSR(int keySlot, bool newPrivateKey = true); + String endCSR(); + + int beginStorage(int compressedCertSlot, int serialNumberAndAuthorityKeyIdentifierSlot); + void setSignature(byte signature[]); + void setIssueYear(int issueYear); + void setIssueMonth(int issueMonth); + void setIssueDay(int issueDay); + void setIssueHour(int issueHour); + void setExpireYears(int expireYears); + void setSerialNumber(const byte serialNumber[]); + void setAuthorityKeyIdentifier(const byte authorityKeyIdentifier[]); + int endStorage(); + + int beginReconstruction(int keySlot, int compressedCertSlot, int serialNumberAndAuthorityKeyIdentifierSlot); + int endReconstruction(); + + byte* bytes(); + int length(); + + void setIssuerCountryName(const String& countryName); + void setIssuerStateProvinceName(const String& stateProvinceName); + void setIssuerLocalityName(const String& localityName); + void setIssuerOrganizationName(const String& organizationName); + void setIssuerOrganizationalUnitName(const String& organizationalUnitName); + void setIssuerCommonName(const String& commonName); + + void setSubjectCountryName(const String& countryName); + void setSubjectStateProvinceName(const String& stateProvinceName); + void setSubjectLocalityName(const String& localityName); + void setSubjectOrganizationName(const String& organizationName); + void setSubjectOrganizationalUnitName(const String& organizationalUnitName); + void setSubjectCommonName(const String& commonName); + +private: + int versionLength(); + + int issuerOrSubjectLength(const String& countryName, + const String& stateProvinceName, + const String& localityName, + const String& organizationName, + const String& organizationalUnitName, + const String& commonName); + + int publicKeyLength(); + + int authorityKeyIdentifierLength(const byte authorityKeyIdentifier[]); + + int signatureLength(const byte signature[]); + + int serialNumberLength(const byte serialNumber[]); + + int sequenceHeaderLength(int length); + + void appendVersion(int version, byte out[]); + + void appendIssuerOrSubject(const String& countryName, + const String& stateProvinceName, + const String& localityName, + const String& organizationName, + const String& organizationalUnitName, + const String& commonName, + byte out[]); + + void appendPublicKey(const byte publicKey[], byte out[]); + + void appendAuthorityKeyIdentifier(const byte authorityKeyIdentifier[], byte out[]); + + void appendSignature(const byte signature[], byte out[]); + + void appendSerialNumber(const byte serialNumber[], byte out[]); + + int appendName(const String& name, int type, byte out[]); + + void appendSequenceHeader(int length, byte out[]); + + int appendDate(int year, int month, int day, int hour, int minute, int second, byte out[]); + + int appendEcdsaWithSHA256(byte out[]); + +private: + int _keySlot; + int _compressedCertSlot; + int _serialNumberAndAuthorityKeyIdentifierSlot; + + String _issuerCountryName; + String _issuerStateProvinceName; + String _issuerLocalityName; + String _issuerOrganizationName; + String _issuerOrganizationalUnitName; + String _issuerCommonName; + + String _subjectCountryName; + String _subjectStateProvinceName; + String _subjectLocalityName; + String _subjectOrganizationName; + String _subjectOrganizationalUnitName; + String _subjectCommonName; + + byte _temp[108]; + byte* _bytes; + int _length; +}; + +#endif /* _ECCX08_CERT_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08TLSConfig.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08TLSConfig.h new file mode 100644 index 00000000..a7f2c1d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08TLSConfig.h @@ -0,0 +1,105 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef _ECCX08_TLS_CONFIG_H_ +#define _ECCX08_TLS_CONFIG_H_ + +const byte DEFAULT_ECCX08_TLS_CONFIG[128] = { + // Read only - start + // SN[0:3] + 0x01, 0x23, 0x00, 0x00, + // RevNum + 0x00, 0x00, 0x50, 0x00, + // SN[4:8] + 0x00, 0x00, 0x00, 0x00, 0x00, + // Reserved + 0xC0, + // I2C_Enable + 0x71, + // Reserved + 0x00, + // Read only - end + // I2C_Address + 0xC0, + // Reserved + 0x00, + // OTPmode + 0x55, + // ChipMode + 0x00, + // SlotConfig + 0x83, 0x20, // External Signatures | Internal Signatures | IsSecret | Write Configure Never, Default: 0x83, 0x20, + 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x87, 0x20, + 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x8F, 0x20, + 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0xC4, 0x8F, + 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0x8F, 0x8F, + 0x8F, 0x8F, + 0x9F, 0x8F, + 0xAF, 0x8F, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0xAF, 0x8F, + // Counter[0] + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + // Counter[1] + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + // LastKeyUse + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + // Write via commands only - start + // UserExtra + 0x00, + // Selector + 0x00, + // LockValue + 0x55, + // LockConfig + 0x55, + // SlotLocked + 0xFF, 0xFF, + // Write via commands only - end + // RFU + 0x00, 0x00, + // X509format + 0x00, 0x00, 0x00, 0x00, + // KeyConfig + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00, + 0x1C, 0x00, + 0x1C, 0x00, + 0x1C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x1C, 0x00 +}; + +#endif /* _ECCX08_TLS_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/SelfProvisioning.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/SelfProvisioning.ino new file mode 100644 index 00000000..63039134 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/SelfProvisioning.ino @@ -0,0 +1,491 @@ +/* + Self Provisioning on Arduino IoT Cloud + + This sketch demonstrates how to automate the provisioning + of the Arduino boards MKR WiFi 1010 and Nano 33 IoT to + the Arduino IoT Cloud, using the Arduino Cloud API. + + Circuit: + - MKR WiFi 1010 board + - Nano 33 IoT board + + created 14 August 2020 + by Luigi Gubello + + This example code is in the public domain. +*/ + +#include "arduino_secrets.h" +#include "ECCX08TLSConfig.h" +#include "ECCX08Cert.h" +#include +#include +#include + +// from section 10.3.3 of the SAMD datasheet +#define SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x0080A00C) +#define SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x0080A040) +#define SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x0080A044) +#define SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048) + +const bool DEBUG = true; +const int keySlot = 0; +const int compressedCertSlot = 10; +const int serialNumberAndAuthorityKeyIdentifierSlot = 11; +const int deviceIdSlot = 12; + +char ssid[] = SECRET_SSID; +char pass[] = SECRET_PASS; +char client_id[] = SECRET_CLIENT_ID; +char secret_id[] = SECRET_SECRET_ID; + +#if defined(ARDUINO_SAMD_NANO_33_IOT) +char board_type[] = "nano_33_iot"; // Nano 33 IoT +char board_fqbn[] = "arduino:samd:nano_33_iot"; // Nano 33 IoT +#elif defined(ARDUINO_SAMD_MKRWIFI1010) +char board_type[] = "mkrwifi1010"; // MKR WiFi 1010 +char board_fqbn[] = "arduino:samd:mkrwifi1010"; // MKR WiFi 1010 +#else +char board_type[] = "nonina"; // Not supported boards +char board_fqbn[] = ""; +#endif + +/// Board Info +String board_name = "NewDevice_"; +String ArduinoID; + +String Arduino_Token; +String deviceId; + +String not_before; +String serialNumber; +String authorityKeyIdentifier; +String signature; + +char server[] = "api2.arduino.cc"; // server address + +WiFiSSLClient client; +int status = WL_IDLE_STATUS; + +ECCX08CertClass ECCX08Cert; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (board_type == "nonina") { + Serial.println("Sorry, this sketch only works on Nano 33 IoT and MKR 1010 WiFi"); + while (1) { ; } + } + + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + delay(10000); + } + + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + while (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + delay(100); + } + + if (!ECCX08.locked()) { + + if (!ECCX08.writeConfiguration(DEFAULT_ECCX08_TLS_CONFIG)) { + Serial.println("Writing ECCX08 configuration failed!"); + Serial.println("Stopping Provisioning"); + while (1) + ; + } + + if (!ECCX08.lock()) { + Serial.println("Locking ECCX08 configuration failed!"); + Serial.println("Stopping Provisioning"); + while (1) + ; + } + + Serial.println("ECCX08 locked successfully"); + Serial.println(); + } + + //Random number for device name + board_name += String(ECCX08.random(65535)); + + uint32_t BoardUniqueID[4]; + BoardUniqueID[0] = SERIAL_NUMBER_WORD_0; + BoardUniqueID[1] = SERIAL_NUMBER_WORD_1; + BoardUniqueID[2] = SERIAL_NUMBER_WORD_2; + BoardUniqueID[3] = SERIAL_NUMBER_WORD_3; + uint8_t bid[32]; + for (int i = 0; i < 4; i++) { + bid[i * 4 + 0] = (uint8_t)(BoardUniqueID[i] >> 24); + bid[i * 4 + 1] = (uint8_t)(BoardUniqueID[i] >> 16); + bid[i * 4 + 2] = (uint8_t)(BoardUniqueID[i] >> 8); + bid[i * 4 + 3] = (uint8_t)(BoardUniqueID[i] >> 0); + } + + for (size_t i = 0; i < 16; i++) { + if (bid[i] < 16) { + ArduinoID += String(0, HEX); + } + ArduinoID += String(bid[i], HEX); + } + ArduinoID.toUpperCase(); + + Serial.print("Device Name: "); + Serial.println(board_name); + // Create Arduino Token + ArduinoToken(client_id, secret_id); + Serial.print("Bearer Token: "); + Serial.println(Arduino_Token); + // Generating Device UUID + BoardUuid(board_name, board_type, board_fqbn, ArduinoID, Arduino_Token); + Serial.print("Device UUID:"); + Serial.println(deviceId); + + delay(2000); + + while (!ECCX08Cert.beginCSR(keySlot, true)) { + Serial.println("Error starting CSR generation!"); + delay(2000); + } + + ECCX08Cert.setSubjectCommonName(deviceId); + + String csr = ECCX08Cert.endCSR(); + + while (!csr) { + Serial.println("Error generating CSR!"); + delay(2000); + } + + Serial.println("Generated CSR is:"); + Serial.println(); + Serial.println(csr); + + // Downloading Arduino cert + ArduinoCertificate(Arduino_Token, deviceId, csr); + + String issueYear = not_before.substring(0, 4); + Serial.print("Year: "); + Serial.println(issueYear); + String issueMonth = not_before.substring(5, 7); + Serial.print("Month: "); + Serial.println(issueMonth); + String issueDay = not_before.substring(8, 10); + Serial.print("Day: "); + Serial.println(issueDay); + String issueHour = not_before.substring(11, 13); + Serial.print("Hour: "); + Serial.println(issueHour); + String expireYears = "31"; + Serial.print("Certificate Serial: "); + Serial.println(serialNumber); + Serial.print("Certificate Authority Key: "); + Serial.println(authorityKeyIdentifier); + Serial.print("Certificate Signature: "); + Serial.println(signature); + + byte deviceIdBytes[72]; + byte serialNumberBytes[16]; + byte authorityKeyIdentifierBytes[20]; + byte signatureBytes[64]; + + deviceId.getBytes(deviceIdBytes, sizeof(deviceIdBytes)); + hexStringToBytes(serialNumber, serialNumberBytes, sizeof(serialNumberBytes)); + hexStringToBytes(authorityKeyIdentifier, authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes)); + hexStringToBytes(signature, signatureBytes, sizeof(signatureBytes)); + + if (!ECCX08.writeSlot(deviceIdSlot, deviceIdBytes, sizeof(deviceIdBytes))) { + Serial.println("Error storing device id!"); + while (1) + ; + } + + if (!ECCX08Cert.beginStorage(compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) { + Serial.println("Error starting ECCX08 storage!"); + while (1) + ; + } + + ECCX08Cert.setSignature(signatureBytes); + ECCX08Cert.setAuthorityKeyIdentifier(authorityKeyIdentifierBytes); + ECCX08Cert.setSerialNumber(serialNumberBytes); + ECCX08Cert.setIssueYear(issueYear.toInt()); + ECCX08Cert.setIssueMonth(issueMonth.toInt()); + ECCX08Cert.setIssueDay(issueDay.toInt()); + ECCX08Cert.setIssueHour(issueHour.toInt()); + ECCX08Cert.setExpireYears(expireYears.toInt()); + + if (!ECCX08Cert.endStorage()) { + Serial.println("Error storing ECCX08 compressed cert!"); + while (1) + ; + } + + if (!ECCX08Cert.beginReconstruction(keySlot, compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) { + Serial.println("Error starting ECCX08 cert reconstruction!"); + while (1) + ; + } + + ECCX08Cert.setIssuerCountryName("US"); + ECCX08Cert.setIssuerOrganizationName("Arduino LLC US"); + ECCX08Cert.setIssuerOrganizationalUnitName("IT"); + ECCX08Cert.setIssuerCommonName("Arduino"); + + if (!ECCX08Cert.endReconstruction()) { + Serial.println("Error reconstructing ECCX08 compressed cert!"); + while (1) + ; + } + + if (!DEBUG) { + return; + } + + Serial.println("Compressed cert = "); + + const byte* certData = ECCX08Cert.bytes(); + int certLength = ECCX08Cert.length(); + + for (int i = 0; i < certLength; i++) { + byte b = certData[i]; + + if (b < 16) { + Serial.print('0'); + } + Serial.print(b, HEX); + } + Serial.println(); +} + +void loop() { +} + +String promptAndReadLine(const char* prompt) { + Serial.print(prompt); + String s = readLine(); + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + } else if (c == '\n') { + break; + } + + line += c; + } + } + + line.trim(); + + return line; +} + +void hexStringToBytes(String& in, byte out[], int length) { + int inLength = in.length(); + in.toUpperCase(); + int outLength = 0; + + for (int i = 0; i < inLength && outLength < length; i += 2) { + char highChar = in[i]; + char lowChar = in[i + 1]; + + byte highByte = (highChar <= '9') ? (highChar - '0') : (highChar + 10 - 'A'); + byte lowByte = (lowChar <= '9') ? (lowChar - '0') : (lowChar + 10 - 'A'); + + out[outLength++] = (highByte << 4) | (lowByte & 0xF); + } +} + +void ArduinoToken(String client_id, String client_secret) { + Serial.println("Creating Bearer Token..."); + String PostData = "grant_type=client_credentials&client_id="; + PostData += client_id; + PostData += "&client_secret="; + PostData += secret_id; + PostData += "&audience=https://api2.arduino.cc/iot"; + + if (client.connect(server, 443)) { + client.println("POST /iot/v1/clients/token HTTP/1.1"); + client.println("Host: api2.arduino.cc"); + client.println("Connection: close"); + client.println("Content-Type: application/x-www-form-urlencoded"); + client.print("Content-Length: "); + client.println(PostData.length()); + client.println(); + client.println(PostData); + } + + while (!client.available()) { + Serial.println("No client"); + delay(2000); + } + + char endOfHeaders[] = "\r\n\r\n"; + if (!client.find(endOfHeaders)) { + Serial.println("Invalid response"); + Serial.println("Error during token generation"); + while (1) { + ; + } + } + + char tokenResponse[1024]; + int intIndex = 0; + while (client.available()) { + tokenResponse[intIndex] = client.read(); + if (tokenResponse[intIndex] == -1) { + break; + } + intIndex++; + } + JSONVar myObject = JSON.parse(tokenResponse); + if (myObject.hasOwnProperty("access_token")) { + Arduino_Token += (const char*)myObject["access_token"]; + } +} + +void BoardUuid(String board_name, String board_type, String board_fqbn, String board_serial, String user_token) { + Serial.println("Adding board to IoT Cloud..."); + String PostData = "{\"fqbn\":\""; + PostData += board_fqbn; + PostData += "\",\"name\":\""; + PostData += board_name; + PostData += "\",\"type\":\""; + PostData += board_type; + PostData += "\",\"serial\":\""; + PostData += board_serial; + PostData += "\"}"; + + if (client.connect(server, 443)) { + client.println("PUT /iot/v2/devices HTTP/1.1"); + client.println("Host: api2.arduino.cc"); + client.println("Connection: close"); + client.println("Content-Type: application/json;charset=UTF-8"); + client.print("Authorization: Bearer "); + client.println(user_token); + client.print("Content-Length: "); + client.println(PostData.length()); + client.println(); + client.println(PostData); + } + + while (!client.available()) { + ; + } + + char endOfHeaders[] = "\r\n\r\n"; + if (!client.find(endOfHeaders)) { + Serial.println("Invalid response"); + Serial.println("Error during Device UUID generation"); + while (1) { + ; + } + } + + char deviceResponse[512]; + int intIndex = 0; + while (client.available()) { + deviceResponse[intIndex] = client.read(); + if (deviceResponse[intIndex] == -1) { + break; + } + intIndex++; + } + JSONVar myObject = JSON.parse(deviceResponse); + if (myObject.hasOwnProperty("id")) { + deviceId += (const char*)myObject["id"]; + } +} + +void ArduinoCertificate(String user_token, String DeviceUuid, String csr) { + Serial.println("Downloading certificate..."); + String url = "/iot/v2/devices/"; + url += DeviceUuid; + url += "/certs"; + + csr.replace("\n", "\\n"); + String PostData = "{\"ca\":\"Arduino\",\"csr\":\""; + PostData += csr; + PostData += "\",\"enabled\":true}"; + + if (client.connect(server, 443)) { + client.print("PUT "); + client.print(url); + client.println(" HTTP/1.1"); + client.println("Host: api2.arduino.cc"); + client.println("Connection: close"); + client.println("Content-Type: application/json;charset=UTF-8"); + client.print("Authorization: Bearer "); + client.println(user_token); + client.print("Content-Length: "); + client.println(PostData.length()); + client.println(); + client.println(PostData); + } + + while (!client.available()) { + ; + } + + char endOfHeaders[] = "\r\n\r\n"; + if (!client.find(endOfHeaders)) { + Serial.println("Invalid response"); + Serial.println("Error during certificate generation"); + while (1) { + ; + } + } + + char certResponse[4096]; + int intIndex = 0; + while (client.available()) { + certResponse[intIndex] = client.read(); + if (certResponse[intIndex] == -1) { + break; + } + intIndex++; + } + JSONVar myObject = JSON.parse(certResponse); + String certZip = JSON.stringify(myObject["compressed"]); + JSONVar myCert = JSON.parse(certZip); + if (myCert.hasOwnProperty("not_before")) { + not_before += (const char*)myCert["not_before"]; + } + if (myCert.hasOwnProperty("serial")) { + serialNumber += (const char*)myCert["serial"]; + } + if (myCert.hasOwnProperty("authority_key_identifier")) { + authorityKeyIdentifier += (const char*)myCert["authority_key_identifier"]; + } + if (myCert.hasOwnProperty("signature_asn1_x")) { + signature += (const char*)myCert["signature_asn1_x"]; + } + if (myCert.hasOwnProperty("signature_asn1_y")) { + signature += (const char*)myCert["signature_asn1_y"]; + } +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/arduino_secrets.h new file mode 100644 index 00000000..cf14c1e1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" +#define SECRET_CLIENT_ID "" +#define SECRET_SECRET_ID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/LICENSE new file mode 100644 index 00000000..19e30718 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +(This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.) + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + {signature of Ty Coon}, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/README.md new file mode 100644 index 00000000..55bf63eb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/README.md @@ -0,0 +1,19 @@ +# Arduino Low Power library + +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml) + +This library allows the use of the low power features of the SAMD21 MCU. This means your battery powered projects will have a longer battery life on boards like [MKRZero](https://store.arduino.cc/usa/arduino-mkrzero), [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) and [MKRFox1200](https://www.arduino.cc/en/Main/ArduinoBoardMKRFox1200). + +For more information about this library please visit us at + + +# License +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/AdcWakeup/AdcWakeup.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/AdcWakeup/AdcWakeup.ino new file mode 100644 index 00000000..0501ee98 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/AdcWakeup/AdcWakeup.ino @@ -0,0 +1,61 @@ +/* + AdcWakeup + + This sketch demonstrates the usage of the ADC to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, changing the voltage on pin A0 will wake up the board. You can test this by connecting a potentiometer between VCC, A0, and GND. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +// Blink sequence number +// Declare it volatile since it's incremented inside an interrupt +volatile int repetitions = 1; + +// Pin used to trigger a wakeup +const int pin = A0; +// How sensitive to be to changes in voltage +const int margin = 10; + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + pinMode(pin, INPUT); +} + +void loop() { + for (int i = 0; i < repetitions; i++) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } + + // Read the voltage at the ADC pin + int value = analogRead(pin); + + // Define a window around that value + uint16_t lo = max(value - margin, 0); + uint16_t hi = min(value + margin, UINT16_MAX); + + // Attach an ADC interrupt on pin A0, calling repetitionsIncrease when the voltage is outside the given range. + // This should be called immediately before LowPower.sleep() because it reconfigures the ADC internally. + LowPower.attachAdcInterrupt(pin, repetitionsIncrease, ADC_INT_OUTSIDE, lo, hi); + + // Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources) + // The power consumption of the chip will drop consistently + LowPower.sleep(); + + // Detach the ADC interrupt. This should be called immediately after LowPower.sleep() because it restores the ADC configuration after waking up. + LowPower.detachAdcInterrupt(); +} + +void repetitionsIncrease() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context + repetitions++; +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/ExternalWakeup/ExternalWakeup.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/ExternalWakeup/ExternalWakeup.ino new file mode 100644 index 00000000..e756a936 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/ExternalWakeup/ExternalWakeup.ino @@ -0,0 +1,47 @@ +/* + ExternalWakeup + + This sketch demonstrates the usage of External Interrupts (on pins) to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, shorting pin 8 to a GND will wake up the board. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +// Blink sequence number +// Declare it volatile since it's incremented inside an interrupt +volatile int repetitions = 1; + +// Pin used to trigger a wakeup +const int pin = 8; + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + // Set pin 8 as INPUT_PULLUP to avoid spurious wakeup + pinMode(pin, INPUT_PULLUP); + // Attach a wakeup interrupt on pin 8, calling repetitionsIncrease when the device is woken up + LowPower.attachInterruptWakeup(pin, repetitionsIncrease, CHANGE); +} + +void loop() { + for (int i = 0; i < repetitions; i++) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } + // Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources) + // The power consumption of the chip will drop consistently + LowPower.sleep(); +} + +void repetitionsIncrease() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context + repetitions++; +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/PrimoDeepSleep/PrimoDeepSleep.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/PrimoDeepSleep/PrimoDeepSleep.ino new file mode 100644 index 00000000..991a4459 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/PrimoDeepSleep/PrimoDeepSleep.ino @@ -0,0 +1,90 @@ +/* + PrimoDeepSleep.ino + + Written by Chiara Ruggeri (chiara@arduino.org) + + This example for the Arduino Primo board shows how to use + Arduino Low Power library to enter in power off mode and save power. + This mode ensures the deepest power saving mode. If you need + a faster response from the board use standby function instead. + + Please note that once exited from the deepest sleep mode the + board will reset (so setup will be run again). + + The functions enableWakeupFrom set the peripheral that will wake up + the board. By calling it more than once you can choose multiple + wakeup sources. + The board will be reset when it wakes up from power off. + You can use wakeUpCause() function to find out what signals woke up + the board if you use more than one wakeUpBy.. function. + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + + +// Pin used to wakeup the board +const int digitalPin = 10; + +// Pin used in Comparator module to wake up the board +const int analogPin = A0; + + +void StmEspPM(bool sleep) { + // enable USER1_BUTTON to turn STM32 off and on when pressed. + // note that when STM32 is off you cannot load any new sketch. + pinMode(USER1_BUTTON, STM32_IT); + + // turn ESP8266 off or on + digitalWrite(GPIO_ESP_PW, sleep ? LOW : HIGH); +} + +void setup() { + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + + //look for what peripheral woke up the board + //reason is 0 at the first execution + wakeup_reason reason = LowPower.wakeupReason(); + if (reason == GPIO_WAKEUP) //GPIO caused the wake up + doMyStuff(); + else if (reason == NFC_WAKEUP) //NFC caused the wake up + doMyStuffWithNFC(); + else if (reason == ANALOG_COMPARATOR_WAKEUP) //Comparator caused the wake up + doOtherStuff(); + + Serial.println("Hi all, I return to sleep"); + + LowPower.companionLowPowerCallback(StmEspPM); + // Send sleep command to ESP and enable USER1_BUTTON to turn STM off + LowPower.companionSleep(); + + //set digital pin 10 to wake up the board when LOW level is detected + LowPower.enableWakeupFrom(GPIO_WAKEUP, digitalPin, LOW); + //let the board be woken up by any NFC field + LowPower.enableWakeupFrom(NFC_WAKEUP); + //wake up the board when the voltage on pin A0 goes below the voltage on pin AREF + LowPower.enableWakeupFrom(ANALOG_COMPARATOR_WAKEUP, analogPin, AREF, UP); + //go in low power mode. Note that the board will reset once it is woken up + LowPower.deepSleep(); +} + + +void loop() {} + +void doMyStuff() { + //insert your code here +} + +void doMyStuffWithNFC() { + //insert your code here +} + +void doOtherStuff() { + //insert your code here +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/TianStandby/TianStandby.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/TianStandby/TianStandby.ino new file mode 100644 index 00000000..73772210 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/TianStandby/TianStandby.ino @@ -0,0 +1,51 @@ +/* + TianStandby + + This sketch demonstrates the usage of SAMD chip to further reduce the power usage of the Tian + board. This method can be applied to any board with companion chips which expose a method + (via direct pin interrupt or via a command) to enter and exit standby. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered applications can take advantage of these modes to enhance battery life significantly. + + In this sketch, the internal RTC of the SAMD chip will wake up the processor every 20 seconds. + Before going to sleep, the SAMD chip tells the MIPS CPU to standby too. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +#define MIPS_PIN 32 + +void MipsPM(bool sleep) { + pinMode(MIPS_PIN, OUTPUT); + digitalWrite(MIPS_PIN, sleep ? LOW : HIGH); +} + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + LowPower.companionLowPowerCallback(MipsPM); + // Uncomment this function if you wish to attach function dummy when RTC wakes up the chip + LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, onWakeup, CHANGE); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + // Triggers a 2000 ms sleep (the device will be woken up only by the registered wakeup sources and by internal RTC) + // The power consumption of the chip will drop consistently + // Send sleep command to MIPS CPU and then go to sleep + LowPower.companionSleep(); + LowPower.sleep(20000); +} + +void onWakeup() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context + + // Wakeup the companion chip, too + LowPower.companionWakeup(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/TimedWakeup/TimedWakeup.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/TimedWakeup/TimedWakeup.ino new file mode 100644 index 00000000..87075a10 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoLowPower/examples/TimedWakeup/TimedWakeup.ino @@ -0,0 +1,35 @@ +/* + TimedWakeup + + This sketch demonstrates the usage of Internal Interrupts to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, the internal RTC will wake up the processor every 2 seconds. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + // Uncomment this function if you wish to attach function dummy when RTC wakes up the chip + // LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + // Triggers a 2000 ms sleep (the device will be woken up only by the registered wakeup sources and by internal RTC) + // The power consumption of the chip will drop consistently + LowPower.sleep(2000); +} + +void dummy() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/README.adoc new file mode 100644 index 00000000..7221642e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/README.adoc @@ -0,0 +1,41 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: ArduinoModbus + += Modbus Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Use http://www.modbus.org/[Modbus] with your Arduino. + +Using TCP or RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library. + +This library is based on https://github.com/stephane/libmodbus[libmodbus], modifications were made to the lower level RS485 and TCP layers to use Arduino Serial/RS485 and Client API's. Then an Arduino friendly API was added on top. + +For more information about this library please visit us at +https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus + +== Useful resources == + +* https://en.wikipedia.org/wiki/Modbus[Modbus - Wikipedia] +* http://www.modbus.org/faq.php[Modbus FAQ] + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientKitchenSink/ModbusRTUClientKitchenSink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientKitchenSink/ModbusRTUClientKitchenSink.ino new file mode 100644 index 00000000..50008b58 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientKitchenSink/ModbusRTUClientKitchenSink.ino @@ -0,0 +1,185 @@ +/* + Modbus RTU Client Kitchen Sink + + This sketch creates a Modbus RTU Client and demonstrates + how to use various Modbus Client APIs. + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU server + - Y connected to A/Y of the Modbus RTU server + - Z connected to B/Z of the Modbus RTU server + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to ON + + created 18 July 2018 + by Sandeep Mistry +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +int counter = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + Serial.println("Modbus RTU Client Kitchen Sink"); + + // start the Modbus RTU client + if (!ModbusRTUClient.begin(9600)) { + Serial.println("Failed to start Modbus RTU Client!"); + while (1) + ; + } +} + +void loop() { + writeCoilValues(); + + readCoilValues(); + + readDiscreteInputValues(); + + writeHoldingRegisterValues(); + + readHoldingRegisterValues(); + + readInputRegisterValues(); + + counter++; + + delay(5000); + Serial.println(); +} + +void writeCoilValues() { + // set the coils to 1 when counter is odd + byte coilValue = ((counter % 2) == 0) ? 0x00 : 0x01; + + Serial.print("Writing Coil values ... "); + + // write 10 Coil values to (slave) id 42, address 0x00 + ModbusRTUClient.beginTransmission(42, COILS, 0x00, 10); + for (int i = 0; i < 10; i++) { + ModbusRTUClient.write(coilValue); + } + if (!ModbusRTUClient.endTransmission()) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + } + + // Alternatively, to write a single Coil value use: + // ModbusRTUClient.coilWrite(...) +} + +void readCoilValues() { + Serial.print("Reading Coil values ... "); + + // read 10 Coil values from (slave) id 42, address 0x00 + if (!ModbusRTUClient.requestFrom(42, COILS, 0x00, 10)) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + + while (ModbusRTUClient.available()) { + Serial.print(ModbusRTUClient.read()); + Serial.print(' '); + } + Serial.println(); + } + + // Alternatively, to read a single Coil value use: + // ModbusRTUClient.coilRead(...) +} + +void readDiscreteInputValues() { + Serial.print("Reading Discrete Input values ... "); + + // read 10 Discrete Input values from (slave) id 42, address 0x00 + if (!ModbusRTUClient.requestFrom(42, DISCRETE_INPUTS, 0x00, 10)) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + + while (ModbusRTUClient.available()) { + Serial.print(ModbusRTUClient.read()); + Serial.print(' '); + } + Serial.println(); + } + + // Alternatively, to read a single Discrete Input value use: + // ModbusRTUClient.discreteInputRead(...) +} + +void writeHoldingRegisterValues() { + // set the Holding Register values to counter + + Serial.print("Writing Holding Registers values ... "); + + // write 10 coil values to (slave) id 42, address 0x00 + ModbusRTUClient.beginTransmission(42, HOLDING_REGISTERS, 0x00, 10); + for (int i = 0; i < 10; i++) { + ModbusRTUClient.write(counter); + } + if (!ModbusRTUClient.endTransmission()) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + } + + // Alternatively, to write a single Holding Register value use: + // ModbusRTUClient.holdingRegisterWrite(...) +} + +void readHoldingRegisterValues() { + Serial.print("Reading Input Register values ... "); + + // read 10 Input Register values from (slave) id 42, address 0x00 + if (!ModbusRTUClient.requestFrom(42, HOLDING_REGISTERS, 0x00, 10)) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + + while (ModbusRTUClient.available()) { + Serial.print(ModbusRTUClient.read()); + Serial.print(' '); + } + Serial.println(); + } + + // Alternatively, to read a single Holding Register value use: + // ModbusRTUClient.holdingRegisterRead(...) +} + +void readInputRegisterValues() { + Serial.print("Reading input register values ... "); + + // read 10 discrete input values from (slave) id 42, + if (!ModbusRTUClient.requestFrom(42, INPUT_REGISTERS, 0x00, 10)) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + + while (ModbusRTUClient.available()) { + Serial.print(ModbusRTUClient.read()); + Serial.print(' '); + } + Serial.println(); + } + + // Alternatively, to read a single Input Register value use: + // ModbusRTUClient.inputRegisterRead(...) +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientToggle/ModbusRTUClientToggle.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientToggle/ModbusRTUClientToggle.ino new file mode 100644 index 00000000..c3b2fda0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientToggle/ModbusRTUClientToggle.ino @@ -0,0 +1,57 @@ +/* + Modbus RTU Client Toggle + + This sketch toggles the coil of a Modbus RTU server connected via RS485 + on and off every second. + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU server + - Y connected to A/Y of the Modbus RTU server + - Z connected to B/Z of the Modbus RTU server + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to ON + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + Serial.println("Modbus RTU Client Toggle"); + + // start the Modbus RTU client + if (!ModbusRTUClient.begin(9600)) { + Serial.println("Failed to start Modbus RTU Client!"); + while (1) + ; + } +} + +void loop() { + // for (slave) id 1: write the value of 0x01, to the coil at address 0x00 + if (!ModbusRTUClient.coilWrite(1, 0x00, 0x01)) { + Serial.print("Failed to write coil! "); + Serial.println(ModbusRTUClient.lastError()); + } + + // wait for 1 second + delay(1000); + + // for (slave) id 1: write the value of 0x00, to the coil at address 0x00 + if (!ModbusRTUClient.coilWrite(1, 0x00, 0x00)) { + Serial.print("Failed to write coil! "); + Serial.println(ModbusRTUClient.lastError()); + } + + // wait for 1 second + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerKitchenSink/ModbusRTUServerKitchenSink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerKitchenSink/ModbusRTUServerKitchenSink.ino new file mode 100644 index 00000000..7928423b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerKitchenSink/ModbusRTUServerKitchenSink.ino @@ -0,0 +1,73 @@ +/* + Modbus RTU Server Kitchen Sink + + This sketch creates a Modbus RTU Server and demonstrates + how to use various Modbus Server APIs. + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU server + - Y connected to A/Y of the Modbus RTU client + - Z connected to B/Z of the Modbus RTU client + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to OFF + + created 18 July 2018 + by Sandeep Mistry +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +const int numCoils = 10; +const int numDiscreteInputs = 10; +const int numHoldingRegisters = 10; +const int numInputRegisters = 10; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + Serial.println("Modbus RTU Server Kitchen Sink"); + + // start the Modbus RTU server, with (slave) id 42 + if (!ModbusRTUServer.begin(42, 9600)) { + Serial.println("Failed to start Modbus RTU Server!"); + while (1) + ; + } + + // configure coils at address 0x00 + ModbusRTUServer.configureCoils(0x00, numCoils); + + // configure discrete inputs at address 0x00 + ModbusRTUServer.configureDiscreteInputs(0x00, numDiscreteInputs); + + // configure holding registers at address 0x00 + ModbusRTUServer.configureHoldingRegisters(0x00, numHoldingRegisters); + + // configure input registers at address 0x00 + ModbusRTUServer.configureInputRegisters(0x00, numInputRegisters); +} + +void loop() { + // poll for Modbus RTU requests + ModbusRTUServer.poll(); + + // map the coil values to the discrete input values + for (int i = 0; i < numCoils; i++) { + int coilValue = ModbusRTUServer.coilRead(i); + + ModbusRTUServer.discreteInputWrite(i, coilValue); + } + + // map the holding register values to the input register values + for (int i = 0; i < numHoldingRegisters; i++) { + long holdingRegisterValue = ModbusRTUServer.holdingRegisterRead(i); + + ModbusRTUServer.inputRegisterWrite(i, holdingRegisterValue); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerLED/ModbusRTUServerLED.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerLED/ModbusRTUServerLED.ino new file mode 100644 index 00000000..5ff119dd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerLED/ModbusRTUServerLED.ino @@ -0,0 +1,62 @@ +/* + Modbus RTU Server LED + + This sketch creates a Modbus RTU Server with a simulated coil. + The value of the simulated coil is set on the LED + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU server + - Y connected to A/Y of the Modbus RTU client + - Z connected to B/Z of the Modbus RTU client + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to OFF + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +const int ledPin = LED_BUILTIN; + +void setup() { + Serial.begin(9600); + + Serial.println("Modbus RTU Server LED"); + + // start the Modbus RTU server, with (slave) id 1 + if (!ModbusRTUServer.begin(1, 9600)) { + Serial.println("Failed to start Modbus RTU Server!"); + while (1) + ; + } + + // configure the LED + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, LOW); + + // configure a single coil at address 0x00 + ModbusRTUServer.configureCoils(0x00, 1); +} + +void loop() { + // poll for Modbus RTU requests + int packetReceived = ModbusRTUServer.poll(); + + if (packetReceived) { + // read the current value of the coil + int coilValue = ModbusRTUServer.coilRead(0x00); + + if (coilValue) { + // coil value set, turn LED on + digitalWrite(ledPin, HIGH); + } else { + // coil value clear, turn LED off + digitalWrite(ledPin, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUTemperatureSensor/ModbusRTUTemperatureSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUTemperatureSensor/ModbusRTUTemperatureSensor.ino new file mode 100644 index 00000000..cc31b502 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUTemperatureSensor/ModbusRTUTemperatureSensor.ino @@ -0,0 +1,67 @@ +/* + Modbus RTU Temperature Sensor + + This sketch shows you how to interact with a Modbus RTU temperature and humidity sensor. + It reads the temperature and humidity values every 5 seconds and outputs them to the + serial monitor. + + Circuit: + - MKR board + - Winners® Modbus RS485 Temperature and Humidity: + https://www.banggood.com/Modbus-RS485-Temperature-and-Humidity-Transmitter-Sensor-High-Precision-Monitoring-p-1159961.html?cur_warehouse=CN + - External 9-36 V power Supply + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU sensor and the Power supply V- + - Power supply V+ connected to V+ sensor + - Y connected to A/Y of the Modbus RTU sensor + - Z connected to B/Z of the Modbus RTU sensor + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to ON + + created 8 August 2018 + by Riccardo Rizzo +*/ + +#include + +float temperature; +float humidity; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + Serial.println("Modbus Temperature Humidity Sensor"); + // start the Modbus RTU client + if (!ModbusRTUClient.begin(9600)) { + Serial.println("Failed to start Modbus RTU Client!"); + while (1) + ; + } +} + +void loop() { + + // send a Holding registers read request to (slave) id 1, for 2 registers + if (!ModbusRTUClient.requestFrom(1, HOLDING_REGISTERS, 0x00, 2)) { + Serial.print("failed to read registers! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + // If the request succeeds, the sensor sends the readings, that are + // stored in the holding registers. The read() method can be used to + // get the raw temperature and the humidity values. + short rawtemperature = ModbusRTUClient.read(); + short rawhumidity = ModbusRTUClient.read(); + + // To get the temperature in Celsius and the humidity reading as + // a percentage, divide the raw value by 10.0. + temperature = rawtemperature / 10.0; + humidity = rawhumidity / 10.0; + Serial.println(temperature); + Serial.println(humidity); + } + + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusClientToggle/EthernetModbusClientToggle.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusClientToggle/EthernetModbusClientToggle.ino new file mode 100644 index 00000000..39c1bef2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusClientToggle/EthernetModbusClientToggle.ino @@ -0,0 +1,87 @@ +/* + Ethernet Modbus TCP Client Toggle + + This sketch toggles the coil of a Modbus TCP server connected + on and off every second. + + Circuit: + - Any Arduino MKR Board + - MKR ETH Shield + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include +#include + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +EthernetClient ethClient; +ModbusTCPClient modbusTCPClient(ethClient); + +IPAddress server(192, 168, 1, 10); // update with the IP Address of your Modbus server + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection and the server: + Ethernet.begin(mac, ip); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } +} + +void loop() { + if (!modbusTCPClient.connected()) { + // client not connected, start the Modbus TCP client + Serial.println("Attempting to connect to Modbus TCP server"); + + if (!modbusTCPClient.begin(server, 502)) { + Serial.println("Modbus TCP Client failed to connect!"); + } else { + Serial.println("Modbus TCP Client connected"); + } + } else { + // client connected + + // write the value of 0x01, to the coil at address 0x00 + if (!modbusTCPClient.coilWrite(0x00, 0x01)) { + Serial.print("Failed to write coil! "); + Serial.println(modbusTCPClient.lastError()); + } + + // wait for 1 second + delay(1000); + + // write the value of 0x00, to the coil at address 0x00 + if (!modbusTCPClient.coilWrite(0x00, 0x00)) { + Serial.print("Failed to write coil! "); + Serial.println(modbusTCPClient.lastError()); + } + + // wait for 1 second + delay(1000); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino new file mode 100644 index 00000000..bc75e947 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino @@ -0,0 +1,117 @@ +/* + Ethernet Modbus TCP Server LED + + This sketch creates a Modbus TCP Server with a simulated coil. + The value of the simulated coil is set on the LED + + Circuit: + - Any Arduino MKR Board + - MKR ETH Shield + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include +#include + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +EthernetServer ethServer(502); + +ModbusTCPServer modbusTCPServer; + +const int ledPin = LED_BUILTIN; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.println("Ethernet Modbus TCP Example"); + + // start the Ethernet connection and the server: + Ethernet.begin(mac, ip); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start the server + ethServer.begin(); + + // start the Modbus TCP server + if (!modbusTCPServer.begin()) { + Serial.println("Failed to start Modbus TCP Server!"); + while (1) + ; + } + + // configure the LED + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, LOW); + + // configure a single coil at address 0x00 + modbusTCPServer.configureCoils(0x00, 1); +} + +void loop() { + // listen for incoming clients + EthernetClient client = ethServer.available(); + + if (client) { + // a new client connected + Serial.println("new client"); + + // let the Modbus TCP accept the connection + modbusTCPServer.accept(client); + + while (client.connected()) { + // poll for Modbus TCP requests, while client connected + modbusTCPServer.poll(); + + // update the LED + updateLED(); + } + + Serial.println("client disconnected"); + } +} + +void updateLED() { + // read the current value of the coil + int coilValue = modbusTCPServer.coilRead(0x00); + + if (coilValue) { + // coil value set, turn LED on + digitalWrite(ledPin, HIGH); + } else { + // coild value clear, turn LED off + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino new file mode 100644 index 00000000..11684ce2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino @@ -0,0 +1,106 @@ +/* + WiFi Modbus TCP Client Toggle + + This sketch toggles the coil of a Modbus TCP server connected + on and off every second. + + Circuit: + - MKR1000 or MKR WiFi 1010 board + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include +#include // for MKR WiFi 1010 +// #include // for MKR1000 + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiClient wifiClient; +ModbusTCPClient modbusTCPClient(wifiClient); + +IPAddress server(192, 168, 1, 10); // update with the IP Address of your Modbus server + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Modbus TCP Client Toggle"); + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + if (!modbusTCPClient.connected()) { + // client not connected, start the Modbus TCP client + Serial.println("Attempting to connect to Modbus TCP server"); + + if (!modbusTCPClient.begin(server)) { + Serial.println("Modbus TCP Client failed to connect!"); + } else { + Serial.println("Modbus TCP Client connected"); + } + } else { + // client connected + + // write the value of 0x01, to the coil at address 0x00 + if (!modbusTCPClient.coilWrite(0x00, 0x01)) { + Serial.print("Failed to write coil! "); + Serial.println(modbusTCPClient.lastError()); + } + + // wait for 1 second + delay(1000); + + // write the value of 0x00, to the coil at address 0x00 + if (!modbusTCPClient.coilWrite(0x00, 0x00)) { + Serial.print("Failed to write coil! "); + Serial.println(modbusTCPClient.lastError()); + } + + // wait for 1 second + delay(1000); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino new file mode 100644 index 00000000..8c59a4b7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino @@ -0,0 +1,127 @@ +/* + WiFi Modbus TCP Server LED + + This sketch creates a Modbus TCP Server with a simulated coil. + The value of the simulated coil is set on the LED + + Circuit: + - MKR1000 or MKR WiFi 1010 board + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include +#include // for MKR WiFi 1010 +// #include // for MKR1000 + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +const int ledPin = LED_BUILTIN; + +int status = WL_IDLE_STATUS; + +WiFiServer wifiServer(502); + +ModbusTCPServer modbusTCPServer; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Modbus TCP Server LED"); + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the status: + printWifiStatus(); + + // start the server + wifiServer.begin(); + + // start the Modbus TCP server + if (!modbusTCPServer.begin()) { + Serial.println("Failed to start Modbus TCP Server!"); + while (1) + ; + } + + // configure the LED + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, LOW); + + // configure a single coil at address 0x00 + modbusTCPServer.configureCoils(0x00, 1); +} + +void loop() { + // listen for incoming clients + WiFiClient client = wifiServer.available(); + + if (client) { + // a new client connected + Serial.println("new client"); + + // let the Modbus TCP accept the connection + modbusTCPServer.accept(client); + + while (client.connected()) { + // poll for Modbus TCP requests, while client connected + modbusTCPServer.poll(); + + // update the LED + updateLED(); + } + + Serial.println("client disconnected"); + } +} + +void updateLED() { + // read the current value of the coil + int coilValue = modbusTCPServer.coilRead(0x00); + + if (coilValue) { + // coil value set, turn LED on + digitalWrite(ledPin, HIGH); + } else { + // coild value clear, turn LED off + digitalWrite(ledPin, LOW); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/LICENSE new file mode 100644 index 00000000..65c5ca88 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/README.md new file mode 100644 index 00000000..3ae26f16 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/README.md @@ -0,0 +1,19 @@ +# ArduinoMotorCarrier library + +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/spell-check.yml) + +This library is designed to use the MKR Motor Carrier. The shield supports micro servo motors, DC motors and DC motors with encoder. This library, therefore, has functions and creates objects to support such hardware. Objects are automatically created when "ArduinoMotorCarrier.h" is included, hence no need to initiate objects manually. + +For more information about this library please visit us at + + +# License +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Flasher/Flasher.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Flasher/Flasher.ino new file mode 100644 index 00000000..9c16fe08 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Flasher/Flasher.ino @@ -0,0 +1,130 @@ +/* + STANDALONE FIRMWARE UPDATE FOR Arduino Motor Carrier + + To generate a new firmware, compile D11-Firmware with target MKRMotorShield, 4KB bootloader, LTO enabled, pinmap complete + and execute + + echo -n "const " > fw.h && xxd -i D11-Firmware.ino.bin >> fw.h +*/ + +#include "Wire.h" +#include "ArduinoMotorCarrier.h" + +#ifdef ARDUINO_SAMD_NANO_33_IOT +#include "fw_nano.h" +#else +#include "fw_mkr.h" +#endif + +#define I2C_ADDRESS 0x09 + +void setDataRunning(int cmd, uint8_t target, int data) { + Wire.beginTransmission(0x66); + Wire.write((uint8_t)cmd); + Wire.write((uint8_t)target); + Wire.write(data); + Wire.endTransmission(); +} + + +void setup() { + // put your setup code here, to run once: + Wire.begin(); + Wire.setClock(1000000); + + Serial.begin(115200); + while (!Serial) + ; + pinMode(6, OUTPUT); + digitalWrite(6, HIGH); + + int prev_address = -1; + + Wire.beginTransmission(0x66); + Wire.write((uint8_t)GET_VERSION); + Wire.write((uint8_t)0); + Wire.endTransmission(); + + Wire.requestFrom(0x66, 5); + Wire.read(); + + String version = ""; + + while (Wire.available()) { + version += (char)Wire.read(); + } + + if (version.c_str()[0] == '0') { + Serial.println("Reset D11"); + setDataRunning(RESET, 0, 0); + delay(10); + } else { + // TODO: on NanoMotorCarrier we have the change to forcefully reset the D11; do it now if it is unresponsive + } + + // reset running D11 + Serial.println("Erase flash"); + + Wire.beginTransmission(I2C_ADDRESS); + Wire.write('r'); + Wire.endTransmission(); + + delay(500); + + Serial.println("Starting flash"); + + int address = 0; + while (address < (D11_Firmware_ino_bin_len + 0x1000)) { + int retry = 0; + do { + Wire.requestFrom(I2C_ADDRESS, 4); + uint8_t buf[4]; + int k = 0; + while (Wire.available()) { + buf[k++] = Wire.read(); + } + address = *(uint32_t*)buf; + delay(10); + } while (prev_address == address && retry++ < 5); + prev_address = address; + Serial.println(address); + + uint8_t crc = 0; + for (int j = 0; j < 64; j++) { + crc ^= D11_Firmware_ino_bin[address - 0x1000 + j]; + } + + Serial.println(crc, HEX); + + Wire.beginTransmission(I2C_ADDRESS); + Wire.write('w'); + Wire.write(crc); + Wire.write(&D11_Firmware_ino_bin[address - 0x1000], 64); + Wire.endTransmission(); + } + + Serial.println("Booting FW"); + Wire.beginTransmission(I2C_ADDRESS); + Wire.write('x'); + Wire.endTransmission(); + + delay(1000); + + Wire.beginTransmission(0x66); + Wire.write((uint8_t)GET_VERSION); + Wire.write((uint32_t)0); + Wire.endTransmission(); + + Wire.requestFrom(0x66, 5); + Wire.read(); + + Serial.print("New version: "); + while (Wire.available()) { + Serial.print((char)Wire.read()); + } + Serial.println(); +} + +void loop() { + // put your main code here, to run repeatedly: +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test/Motor_test.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test/Motor_test.ino new file mode 100644 index 00000000..7f5a42c9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test/Motor_test.ino @@ -0,0 +1,84 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = 0; + +void setup() { + //Serial port initialization + Serial.begin(115200); + while (!Serial) + ; + + //Establishing the communication with the Motor Carrier + if (controller.begin()) { + Serial.print("MKR Motor Connected connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); +} + + +void loop() { + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + + //Reset to the default values if the battery level is lower than 11 V + if (batteryVoltage < 11) { + Serial.println(" "); + Serial.println("WARNING: LOW BATTERY"); + Serial.println("ALL SYSTEMS DOWN"); + M1.setDuty(0); + M2.setDuty(0); + M3.setDuty(0); + M4.setDuty(0); + while (batteryVoltage < 11) { + batteryVoltage = (float)battery.getConverted(); + } + } else { + //Motor test + for (duty = -100; duty < 100; duty += 5) { + Serial.print("Motor Duty: "); + Serial.println(duty); + M1.setDuty(duty); + M2.setDuty(duty); + M3.setDuty(duty); + M4.setDuty(duty); + delay(50); + } + for (duty = 100; duty > -100; duty -= 5) { + Serial.print("Motor Duty: "); + Serial.println(duty); + M1.setDuty(duty); + M2.setDuty(duty); + M3.setDuty(duty); + M4.setDuty(duty); + delay(50); + } + + //Keep active the communication between MKR board & MKR Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test_encoder/Motor_test_encoder.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test_encoder/Motor_test_encoder.ino new file mode 100644 index 00000000..f313247c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test_encoder/Motor_test_encoder.ino @@ -0,0 +1,80 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = -20; + +void setup() { + //Serial port initialization + Serial.begin(115200); + while (!Serial) + ; + + //Establishing the communication with the Motor Carrier + if (controller.begin()) { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + // Reset the encoder internal counter to zero (can be set to any initial value) + Serial.println("reset counters"); + encoder1.resetCounter(0); + encoder2.resetCounter(0); + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); +} + + +void loop() { + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + + //Reset to the default values if the battery level is lower than 11 V + if (batteryVoltage < 11) { + Serial.println(" "); + Serial.println("WARNING: LOW BATTERY"); + Serial.println("ALL SYSTEMS DOWN"); + M1.setDuty(0); + M2.setDuty(0); + M3.setDuty(0); + M4.setDuty(0); + while (batteryVoltage < 11) { + batteryVoltage = (float)battery.getConverted(); + } + } else { + //Chose the motor to use:M1(default), M2, M3 or M4 + Serial.print("M1 Duty: "); + Serial.println(duty); + M1.setDuty(duty); + + //Chose the encoder to use:encoder1(default) or encoder2 + Serial.print("Encoder1 Pos [counts]: "); + Serial.println(encoder1.getRawCount()); + Serial.print("Encoder1 vel [counts/sec]: "); + Serial.println(encoder1.getCountPerSecond()); + } + + //Keep active the communication between MKR board & MKR Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Servo_test/Servo_test.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Servo_test/Servo_test.ino new file mode 100644 index 00000000..8d02d755 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Servo_test/Servo_test.ino @@ -0,0 +1,77 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +int batteryVoltage; + +void setup() { + //Serial port initialization + Serial.begin(115200); + while (!Serial) + ; + + //Establishing the communication with the Motor Carrier + if (controller.begin()) { + Serial.print("MKR Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); +} + + +void loop() { + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + + //Reset to the default values if the battery level is lower than 11 V + if (batteryVoltage < 11) { + Serial.println(" "); + Serial.println("WARNING: LOW BATTERY"); + Serial.println("ALL SYSTEMS DOWN"); + while (batteryVoltage < 11) { + batteryVoltage = (float)battery.getConverted(); + } + } else { + //Servo sweep from 0 position to 180 + for (int i = 0; i < 180; i += 5) { + //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + servo1.setAngle(i); + Serial.print("Servo position"); + Serial.println(i); + delay(50); + } + + delay(200); + + //Servo sweep from 180 position to 0 + for (int i = 180; i > 0; i -= 5) { + //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + servo1.setAngle(i); + Serial.print("Servo position"); + Serial.println(i); + delay(50); + } + } + + //Keep active the communication between MKR board & MKR Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Test/Test.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Test/Test.ino new file mode 100644 index 00000000..18fb0725 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Test/Test.ino @@ -0,0 +1,61 @@ +/* + MKR Motor Carrier Test sketch + This sketch demonstrates some APIs exposed by the ArduinoMotorCarrier library. + For the complete list, visit the reference page on https://www.arduino.cc/en/Reference/MKRMotorCarrier + This example code is in the public domain. +*/ + +#include "ArduinoMotorCarrier.h" + +void setup() { + + Serial.begin(115200); + while (!Serial) + ; + + // Start communication with the Motor Carrier + if (controller.begin()) { + Serial.print("MKR Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } + + // Reboot the motor controller; brings every value back to default + controller.reboot(); + + Serial.println(controller.getFreeRam()); + + // Reset the encoder internal counter to zero (can be set to any initial value) + encoder1.resetCounter(0); + + // Start DC Motor 1 (labeled M1) with 90% of maximum speed, clockwise + M1.setDuty(90); + + // Read the encoder connected to Motor1 until it reaches 36000 counts + int motor1Pos = 0; + while (motor1Pos < 36000) { + motor1Pos = encoder1.getRawCount(); + // Remember to call ping() here and there! + // If you forget to do so the controller will think that the user sketch is not running and will freeze. + // You can wait up to 3 seconds between pings before the reset kicks in + controller.ping(); + } + + // Switch motor control from DIRECT to PID-driven. + // This way, you can program the motor to reach a certain position or velocity without any further intervention. + // The PID can be carefully tuned if a particular profile is needed. + pid1.setControlMode(CL_POSITION); + pid1.setGains(25, 0, 3); + pid1.setMaxAcceleration(4000); + pid1.setSetpoint(TARGET_POSITION, 5000); +} + +void loop() { + // Simply print the actual position while the PID is running, pinging the controller every loop() + Serial.println(encoder1.getRawCount()); + controller.ping(); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/Battery_Charging/Battery_Charging.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/Battery_Charging/Battery_Charging.ino new file mode 100644 index 00000000..36decbc5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/Battery_Charging/Battery_Charging.ino @@ -0,0 +1,32 @@ + +#include + +//Variable to store the battery voltage +float batteryVoltage; + +// the setup function runs once when you press reset or power the board +void setup() { + Serial.begin(115200); + //while (!Serial); + + if (controller.begin()) { + Serial.print("Nano Motor Shield connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red led blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } +} + +// the loop function runs over and over again forever +void loop() { + + batteryVoltage = battery.getRaw() / 236.0; + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage, 3); + //Serial.println("V"); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); + delay(5000); //wait for a few seconds +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/DCMotorTest/DCMotorTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/DCMotorTest/DCMotorTest.ino new file mode 100644 index 00000000..d4eeb369 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/DCMotorTest/DCMotorTest.ino @@ -0,0 +1,92 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = 0; + +void setup() { + //Serial port initialization + Serial.begin(115200); + //while (!Serial); + + //Establishing the communication with the Motor Carrier + if (controller.begin()) { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + int dutyInit = 0; // at 50 it works as expected, at 60 shift sides and is too small duty to move, at 70 is very big duty. + M1.setDuty(dutyInit); + M2.setDuty(dutyInit); + M3.setDuty(dutyInit); + M4.setDuty(dutyInit); + Serial.print("Duty init: "); + Serial.println(dutyInit); + // int duty2 = dutyInit * 16777215 / 100; + // Serial.print("Conversion formula: "); + // Serial.println(duty2); + //while (1); //WHILE 1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REMOVE!!!! +} + + +void loop() { + + //Take the battery status + //float batteryVoltage = (float)battery.getConverted(); + + //Reset to the default values if the battery level is lower than 11 V + // if (batteryVoltage < 11) + // { + // Serial.println(" "); + // Serial.println("WARNING: LOW BATTERY"); + // Serial.println("ALL SYSTEMS DOWN"); + // M1.setDuty(0); + // M2.setDuty(0); + // M3.setDuty(0); + // M4.setDuty(0); + // while (batteryVoltage < 11) + // { + // batteryVoltage = (float)battery.getConverted(); + // } + // } + // else + // { + + //Motor test + for (duty = -100; duty < 100; duty += 1) { + Serial.print("Motor Duty: "); + Serial.println(duty); + M1.setDuty(duty); + M2.setDuty(duty); + M3.setDuty(duty); + M4.setDuty(duty); + delay(10); + } + for (duty = 100; duty > -100; duty -= 1) { + Serial.print("Motor Duty: "); + Serial.println(duty); + M1.setDuty(duty); + M2.setDuty(duty); + M3.setDuty(duty); + M4.setDuty(duty); + delay(10); + } + + //Keep active the communication between Nano & Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/EncoderTest/EncoderTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/EncoderTest/EncoderTest.ino new file mode 100644 index 00000000..b0cc280f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/EncoderTest/EncoderTest.ino @@ -0,0 +1,61 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = 0; + +void setup() { + //Establishing the communication with the Motor Carrier + if (controller.begin()) { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } + + //Serial port initialization + Serial.begin(115200); + while (!Serial) + ; + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + // Reset the encoder internal counter to zero (can be set to any initial value) + Serial.println("reset counters"); + encoder1.resetCounter(0); + encoder2.resetCounter(0); + + M1.setDuty(30); + M2.setDuty(30); + M3.setDuty(30); + M4.setDuty(30); +} + + +void loop() { + + //Chose the encoder to use:encoder1(default) or encoder2 + Serial.print("Encoder1 Pos [counts]: "); + Serial.print(encoder1.getRawCount()); + Serial.print(" Encoder1 vel [counts/sec]: "); + Serial.println(encoder1.getCountPerSecond()); + Serial.print("Encoder2 Pos [counts]: "); + Serial.print(encoder2.getRawCount()); + Serial.print(" Encoder2 vel [counts/sec]: "); + Serial.println(encoder2.getCountPerSecond()); + Serial.println(""); + + //Keep active the communication between Nano & Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/IMU_Test/IMU_Test.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/IMU_Test/IMU_Test.ino new file mode 100644 index 00000000..5b9bc440 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/IMU_Test/IMU_Test.ino @@ -0,0 +1,89 @@ +/* + *************************************************************************** + + Euler_Streaming.pde - part of sample SW for using BNO055 with Arduino + + (C) All rights reserved by ROBERT BOSCH GMBH + + Copyright (C) 2014 Bosch Sensortec GmbH + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + **************************************************************************/ +/* Date: 2014/01/07 + Revision: 1.2 + +*/ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* bno055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if ((millis() - lastTime) >= 100) //To stream at 10 Hz without using additional timers + { + lastTime = millis(); + + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p) / 16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/PID_Position_test/PID_Position_test.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/PID_Position_test/PID_Position_test.ino new file mode 100644 index 00000000..0c72da3d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/PID_Position_test/PID_Position_test.ino @@ -0,0 +1,124 @@ +#include +//#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = 0; + +int target; + +void setup() { + //Serial port initialization + Serial.begin(115200); + while (!Serial) + ; + + //Establishing the communication with the Motor Carrier + if (controller.begin()) { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); + + int dutyInit = 0; // at 50 it works as expected, at 60 shift sides and is too small duty to move, at 70 is very big duty. + M1.setDuty(dutyInit); + M2.setDuty(dutyInit); + M3.setDuty(dutyInit); + M4.setDuty(dutyInit); + Serial.print("Duty: "); + Serial.println(dutyInit); + + /************* PID 1 ***********************/ + + // pid1.setControlMode(CL_POSITION); + // + // //pid1.resetGains(); + // //pid1.setLimits(-100,100); + // pid1.setGains(0.01f, 0.017f, 0.0f); //Proportional(change) Integral(change) Derivative + // Serial.print("P Gain: "); + // Serial.println((float)pid1.getPgain()); + // Serial.print("I Gain: "); + // Serial.println((float)pid1.getIgain()); + // Serial.print("D Gain: "); + // Serial.println((float)pid1.getDgain(), 7); + // Serial.println(""); + // + // encoder1.resetCounter(0); + // Serial.print("encoder1: "); + // Serial.println(encoder1.getRawCount()); + // target = 1000; + // pid1.setSetpoint(TARGET_POSITION, target); + + /************* PID 2 ***********************/ + + pid2.setControlMode(CL_POSITION); + + //pid1.resetGains(); + //pid1.setLimits(-100,100); + pid2.setGains(0.1f, 0.0f, 0.0f); //Proportional(change) Integral(change) Derivative + Serial.print("P Gain: "); + Serial.println((float)pid2.getPgain()); + Serial.print("I Gain: "); + Serial.println((float)pid2.getIgain()); + Serial.print("D Gain: "); + Serial.println((float)pid2.getDgain(), 7); + Serial.println(""); + + encoder2.resetCounter(0); + Serial.print("encoder2: "); + Serial.println(encoder2.getRawCount()); + target = 1000; + pid2.setSetpoint(TARGET_POSITION, target); +} + +void loop() { + + /************* PID 1 ***********************/ + + // Serial.print("encoder1: "); + // Serial.print(encoder1.getRawCount()); + // Serial.print(" target: "); + // Serial.println(target); + // if (encoder1.getRawCount() == target) { + // target += 1000; + // Serial.print("Target reached: Setting new target.."); + // pid1.setSetpoint(TARGET_POSITION, target); + // //delay(5000); + // } + + /************* PID 2 ***********************/ + + Serial.print("encoder2: "); + Serial.print(encoder2.getRawCount()); + Serial.print(" target: "); + Serial.println(target); + if (encoder2.getRawCount() == target) { + target += 1000; + Serial.print("Target reached: Setting new target.."); + pid2.setSetpoint(TARGET_POSITION, target); + //delay(5000); + } + + //--------------------------------------- + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/ServoTest/ServoTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/ServoTest/ServoTest.ino new file mode 100644 index 00000000..4cf64952 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/ServoTest/ServoTest.ino @@ -0,0 +1,72 @@ +#include +#include +//#include +//#include +#define INTERRUPT_PIN 6 + + +void setup() { + //Serial port initialization + Serial.begin(115200); + //while (!Serial); + + //Establishing the communication with the Motor Carrier + if (controller.begin()) { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1) + ; + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + M1.setDuty(0); + M2.setDuty(0); + M3.setDuty(0); + M4.setDuty(0); + + if (!PMIC.enableBoostMode()) { + Serial.println("Error enabling Boost Mode"); + } +} + +void loop() { + + //Servo sweep from 0 position to 180 + for (int i = 0; i < 180; i += 1) { + //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + servo1.setAngle(i); + servo2.setAngle(i); + servo3.setAngle(i); + servo4.setAngle(i); + Serial.print("Servos position"); + Serial.println(i); + delay(20); + } + + delay(200); + + //Servo sweep from 180 position to 0 + for (int i = 180; i > 0; i -= 1) { + //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + servo1.setAngle(i); + servo2.setAngle(i); + servo3.setAngle(i); + servo4.setAngle(i); + Serial.print("Servos position: "); + Serial.println(i); + delay(20); + } + + + //Keep active the communication between MKR board & MKR Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/README.adoc new file mode 100644 index 00000000..050bacaf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/README.adoc @@ -0,0 +1,10 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoMqttClient + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to send and receive MQTT messages using Arduino. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/WiFiAdvancedCallback.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/WiFiAdvancedCallback.ino new file mode 100644 index 00000000..82b44178 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/WiFiAdvancedCallback.ino @@ -0,0 +1,191 @@ +/* + ArduinoMqttClient - WiFi Advanced Callback + + This example connects to a MQTT broker and subscribes to a single topic, + it also publishes a message to another topic every 10 seconds. + When a message is received it prints the message to the Serial Monitor, + it uses the callback functionality of the library. + + It also demonstrates how to set the will message, get/set QoS, + duplicate and retain values of messages. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) +#include +#elif defined(ARDUINO_SAMD_MKR1000) +#include +#elif defined(ARDUINO_ARCH_ESP8266) +#include +#elif defined(ARDUINO_ARCH_ESP32) +#include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char willTopic[] = "arduino/will"; +const char inTopic[] = "arduino/in"; +const char outTopic[] = "arduino/out"; + +const long interval = 10000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + // By default the library connects with the "clean session" flag set, + // you can disable this behaviour by using + // mqttClient.setCleanSession(false); + + // set a will message, used by the broker when the connection dies unexpectedly + // you must know the size of the message beforehand, and it must be set before connecting + String willPayload = "oh no!"; + bool willRetain = true; + int willQos = 1; + + mqttClient.beginWill(willTopic, willPayload.length(), willRetain, willQos); + mqttClient.print(willPayload); + mqttClient.endWill(); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1) + ; + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + // set the message receive callback + mqttClient.onMessage(onMqttMessage); + + Serial.print("Subscribing to topic: "); + Serial.println(inTopic); + Serial.println(); + + // subscribe to a topic + // the second parameter sets the QoS of the subscription, + // the the library supports subscribing at QoS 0, 1, or 2 + int subscribeQos = 1; + + mqttClient.subscribe(inTopic, subscribeQos); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(inTopic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(inTopic); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to receive MQTT messages and + // send MQTT keep alives which avoids being disconnected by the broker + mqttClient.poll(); + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + String payload; + + payload += "hello world!"; + payload += " "; + payload += count; + + Serial.print("Sending message to topic: "); + Serial.println(outTopic); + Serial.println(payload); + + // send message, the Print interface can be used to set the message contents + // in this case we know the size ahead of time, so the message payload can be streamed + + bool retained = false; + int qos = 1; + bool dup = false; + + mqttClient.beginMessage(outTopic, payload.length(), retained, qos, dup); + mqttClient.print(payload); + mqttClient.endMessage(); + + Serial.println(); + + count++; + } +} + +void onMqttMessage(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', duplicate = "); + Serial.print(mqttClient.messageDup() ? "true" : "false"); + Serial.print(", QoS = "); + Serial.print(mqttClient.messageQoS()); + Serial.print(", retained = "); + Serial.print(mqttClient.messageRetain() ? "true" : "false"); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/WiFiEcho.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/WiFiEcho.ino new file mode 100644 index 00000000..5a6516c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/WiFiEcho.ino @@ -0,0 +1,147 @@ +/* + ArduinoMqttClient - WiFi Echo + + This example connects to a MQTT broker and subscribes to a single topic, + it also publishes a message to the same topic once a second. + When a message is received it prints the message to the Serial Monitor. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) +#include +#elif defined(ARDUINO_SAMD_MKR1000) +#include +#elif defined(ARDUINO_ARCH_ESP8266) +#include +#elif defined(ARDUINO_ARCH_ESP32) +#include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; + +const char topic[] = "arduino/echo"; + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1) + ; + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + Serial.print("Subscribing to topic: "); + Serial.println(topic); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe(topic); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(topic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(topic); + Serial.println(); +} + +void loop() { + // check for incoming messages + int messageSize = mqttClient.parseMessage(); + if (messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); + } + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + Serial.print("Sending message to topic: "); + Serial.println(topic); + Serial.print("echo "); + Serial.println(count); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage(topic); + mqttClient.print("echo "); + mqttClient.print(count); + mqttClient.endMessage(); + + Serial.println(); + + count++; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/WiFiEchoCallback.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/WiFiEchoCallback.ino new file mode 100644 index 00000000..1f03d6fd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/WiFiEchoCallback.ino @@ -0,0 +1,152 @@ +/* + ArduinoMqttClient - WiFi Echo + + This example connects to a MQTT broker and subscribes to a single topic, + it also publishes a message to the same topic once a second. + When a message is received it prints the message to the Serial Monitor, + it uses the callback functionality of the library. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) +#include +#elif defined(ARDUINO_SAMD_MKR1000) +#include +#elif defined(ARDUINO_ARCH_ESP8266) +#include +#elif defined(ARDUINO_ARCH_ESP32) +#include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char topic[] = "arduino/echo"; + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1) + ; + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + // set the message receive callback + mqttClient.onMessage(onMqttMessage); + + Serial.print("Subscribing to topic: "); + Serial.println(topic); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe(topic); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(topic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(topic); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to receive MQTT messages and + // send MQTT keep alives which avoids being disconnected by the broker + mqttClient.poll(); + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + Serial.print("Sending message to topic: "); + Serial.println(topic); + Serial.print("echo "); + Serial.println(count); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage(topic); + mqttClient.print("echo "); + mqttClient.print(count); + mqttClient.endMessage(); + + Serial.println(); + + count++; + } +} + +void onMqttMessage(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/WiFiSimpleReceive.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/WiFiSimpleReceive.ino new file mode 100644 index 00000000..d0c04c61 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/WiFiSimpleReceive.ino @@ -0,0 +1,115 @@ +/* + ArduinoMqttClient - WiFi Simple Receive + + This example connects to a MQTT broker and subscribes to a single topic. + When a message is received it prints the message to the Serial Monitor. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) +#include +#elif defined(ARDUINO_SAMD_MKR1000) +#include +#elif defined(ARDUINO_ARCH_ESP8266) +#include +#elif defined(ARDUINO_ARCH_ESP32) +#include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char topic[] = "arduino/simple"; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1) + ; + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + Serial.print("Subscribing to topic: "); + Serial.println(topic); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe(topic); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(topic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(topic); + Serial.println(); +} + +void loop() { + int messageSize = mqttClient.parseMessage(); + if (messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/WiFiSimpleReceiveCallback.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/WiFiSimpleReceiveCallback.ino new file mode 100644 index 00000000..ab7a5aa0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/WiFiSimpleReceiveCallback.ino @@ -0,0 +1,122 @@ +/* + ArduinoMqttClient - WiFi Simple Receive Callback + + This example connects to a MQTT broker and subscribes to a single topic. + When a message is received it prints the message to the Serial Monitor, + it uses the callback functionality of the library. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) +#include +#elif defined(ARDUINO_SAMD_MKR1000) +#include +#elif defined(ARDUINO_ARCH_ESP8266) +#include +#elif defined(ARDUINO_ARCH_ESP32) +#include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char topic[] = "arduino/simple"; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1) + ; + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + // set the message receive callback + mqttClient.onMessage(onMqttMessage); + + Serial.print("Subscribing to topic: "); + Serial.println(topic); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe(topic); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(topic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(topic); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to receive MQTT messages and + // send MQTT keep alives which avoids being disconnected by the broker + mqttClient.poll(); +} + +void onMqttMessage(int messageSize) { + // we received a message, print out the topic and contents + Serial.println("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/WiFiSimpleSender.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/WiFiSimpleSender.ino new file mode 100644 index 00000000..fb35dbb4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/WiFiSimpleSender.ino @@ -0,0 +1,116 @@ +/* + ArduinoMqttClient - WiFi Simple Sender + + This example connects to a MQTT broker and publishes a message to + a topic once a second. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) +#include +#elif defined(ARDUINO_SAMD_MKR1000) +#include +#elif defined(ARDUINO_ARCH_ESP8266) +#include +#elif defined(ARDUINO_ARCH_ESP32) +#include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char topic[] = "arduino/simple"; + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1) + ; + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to send MQTT keep alives which + // avoids being disconnected by the broker + mqttClient.poll(); + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + Serial.print("Sending message to topic: "); + Serial.println(topic); + Serial.print("hello "); + Serial.println(count); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage(topic); + mqttClient.print("hello "); + mqttClient.print(count); + mqttClient.endMessage(); + + Serial.println(); + + count++; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/README.adoc new file mode 100644 index 00000000..b1be50e8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/README.adoc @@ -0,0 +1,15 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoRS485 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield. + +This library supports the Maxim Integrated MAX3157 and equivalent chipsets. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Passthrough/RS485Passthrough.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Passthrough/RS485Passthrough.ino new file mode 100644 index 00000000..f86249f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Passthrough/RS485Passthrough.ino @@ -0,0 +1,44 @@ +/* + RS-485 Passthrough + + This sketch relays data sent and received between the Serial port and the RS-485 interface + + Circuit: + - MKR board + - MKR 485 Shield + - ISO GND connected to GND of the RS-485 device + - Y connected to A of the RS-485 device + - Z connected to B of the RS-485 device + - A connected to Y of the RS-485 device + - B connected to Z of the RS-485 device + - Jumper positions + - FULL set to ON + - Z \/\/ Y set to ON, if the RS-485 device doesn't provide termination + - B \/\/ A set to ON, if the RS-485 device doesn't provide termination + + created 4 July 2018 + by Sandeep Mistry +*/ + +#include + +void setup() { + Serial.begin(9600); + RS485.begin(9600); + + // enable transmission, can be disabled with: RS485.endTransmission(); + RS485.beginTransmission(); + + // enable reception, can be disabled with: RS485.noReceive(); + RS485.receive(); +} + +void loop() { + if (Serial.available()) { + RS485.write(Serial.read()); + } + + if (RS485.available()) { + Serial.write(RS485.read()); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Receiver/RS485Receiver.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Receiver/RS485Receiver.ino new file mode 100644 index 00000000..706840d1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Receiver/RS485Receiver.ino @@ -0,0 +1,37 @@ +/* + RS-485 Receiver + + This sketch receives data over RS-485 interface and outputs the data to the Serial interface + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the RS-485 device + - A connected to A/Y of the RS-485 device + - B connected to B/Z of the RS-485 device + - Jumper positions + - FULL set to ON + - A \/\/ B set to OFF + + created 4 July 2018 + by Sandeep Mistry +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + RS485.begin(9600); + + // enable reception, can be disabled with: RS485.noReceive(); + RS485.receive(); +} + +void loop() { + if (RS485.available()) { + Serial.write(RS485.read()); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Sender/RS485Sender.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Sender/RS485Sender.ino new file mode 100644 index 00000000..c40f0169 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoRS485/examples/RS485Sender/RS485Sender.ino @@ -0,0 +1,37 @@ +/* + RS-485 Sender + + This sketch periodically sends a string over the RS-485 interface + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the RS-485 device + - Y connected to A of the RS-485 device + - Z connected to B of the RS-485 device + - Jumper positions + - FULL set to ON + - Z \/\/ Y set to ON + + created 4 July 2018 + by Sandeep Mistry +*/ + +#include + +int counter = 0; + +void setup() { + RS485.begin(9600); +} + +void loop() { + RS485.beginTransmission(); + RS485.print("hello "); + RS485.println(counter); + RS485.endTransmission(); + + counter++; + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/README.md new file mode 100644 index 00000000..5e8b15bb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/README.md @@ -0,0 +1,28 @@ +# ArduinoSound + +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/spell-check.yml) + +A simple way to play and analyze audio data using Arduino. Currently only supports SAMD21 boards and I2S audio devices. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/ArduinoSound + +## License + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/AmplitudeSerialPlotter/AmplitudeSerialPlotter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/AmplitudeSerialPlotter/AmplitudeSerialPlotter.ino new file mode 100644 index 00000000..5ed9070a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/AmplitudeSerialPlotter/AmplitudeSerialPlotter.ino @@ -0,0 +1,59 @@ +/* + This example reads audio data from an InvenSense ICS-43432 I2S microphone + breakout board, and prints out the amplitude to the Serial Monitor. The + Serial Plotter built into the Arduino IDE (Tools -> Serial Plotter) can be + used to plot the audio amplitude data. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * ICS-43432: + * GND connected GND + * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKR Zero) + * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 23 November 2016 + by Sandeep Mistry + */ + +#include + +// create an amplitude analyzer to be used with the I2S input +AmplitudeAnalyzer amplitudeAnalyzer; + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // setup the I2S audio input for 44.1 kHz with 32-bits per sample + if (!AudioInI2S.begin(44100, 32)) { + Serial.println("Failed to initialize I2S input!"); + while (1) + ; // do nothing + } + + // configure the I2S input as the input for the amplitude analyzer + if (!amplitudeAnalyzer.input(AudioInI2S)) { + Serial.println("Failed to set amplitude analyzer input!"); + while (1) + ; // do nothing + } +} + +void loop() { + // check if a new analysis is available + if (amplitudeAnalyzer.available()) { + // read the new amplitude + int amplitude = amplitudeAnalyzer.read(); + //dB relative to full scale + int dpFS = 20 * log10(abs(amplitude)); + // print out the decibel to the serial monitor + Serial.println(dpFS); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/ClapDetector/ClapDetector.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/ClapDetector/ClapDetector.ino new file mode 100644 index 00000000..83cfcdaf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/ClapDetector/ClapDetector.ino @@ -0,0 +1,79 @@ +/* + This example reads audio data from an InvenSense ICS-43432 I2S microphone + breakout board, and uses the input to detect clapping sounds. An LED is + toggled when a clap is detected. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * ICS-43432: + * GND connected GND + * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKR Zero) + * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 18 November 2016 + by Sandeep Mistry + */ + +#include + +// the LED pin to use as output +const int ledPin = LED_BUILTIN; + +// the amplitude threshold for a clap to be detected +const int amplitudeDeltaThreshold = 100000000; + +// create an amplitude analyzer to be used with the I2S input +AmplitudeAnalyzer amplitudeAnalyzer; + +// variable to keep track of last amplitude +int lastAmplitude = 0; + +void setup() { + // setup the serial + Serial.begin(9600); + + // configure the LED pin as an output + pinMode(ledPin, OUTPUT); + + // setup the I2S audio input for 44.1 kHz with 32-bits per sample + if (!AudioInI2S.begin(44100, 32)) { + Serial.println("Failed to initialize I2S input!"); + while (1) + ; // do nothing + } + + // configure the I2S input as the input for the amplitude analyzer + if (!amplitudeAnalyzer.input(AudioInI2S)) { + Serial.println("Failed to set amplitude analyzer input!"); + while (1) + ; // do nothing + } +} + +void loop() { + // check if a new analysis is available + if (amplitudeAnalyzer.available()) { + // read the new amplitude + int amplitude = amplitudeAnalyzer.read(); + + // find the difference between the new amplitude and the last + int delta = amplitude - lastAmplitude; + + // check if the difference is larger than the threshold + if (delta > amplitudeDeltaThreshold) { + // a clap was detected + Serial.println("clap detected"); + + // toggle the LED + digitalWrite(ledPin, !digitalRead(ledPin)); + + // delay a bit to debounce + delay(100); + } + + // update the last amplitude with the new amplitude + lastAmplitude = amplitude; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/SpectrumSerialPlotter/SpectrumSerialPlotter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/SpectrumSerialPlotter/SpectrumSerialPlotter.ino new file mode 100644 index 00000000..3150a841 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/SpectrumSerialPlotter/SpectrumSerialPlotter.ino @@ -0,0 +1,74 @@ +/* + This example reads audio data from an InvenSense ICS-43432 I2S microphone + breakout board, and prints out the spectrum to the Serial Monitor. The + Serial Plotter built into the Arduino IDE (Tools -> Serial Plotter) can be + used to plot the audio amplitude data. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * ICS-43432: + * GND connected GND + * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKR Zero) + * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 21 November 2016 + by Sandeep Mistry + */ + +#include + +// sample rate for the input +const int sampleRate = 8000; + +// size of the FFT to compute +const int fftSize = 128; + +// size of the spectrum output, half of FFT size +const int spectrumSize = fftSize / 2; + +// array to store spectrum output +int spectrum[spectrumSize]; + +// create an FFT analyzer to be used with the I2S input +FFTAnalyzer fftAnalyzer(fftSize); + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // setup the I2S audio input for the sample rate with 32-bits per sample + if (!AudioInI2S.begin(sampleRate, 32)) { + Serial.println("Failed to initialize I2S input!"); + while (1) + ; // do nothing + } + + // configure the I2S input as the input for the FFT analyzer + if (!fftAnalyzer.input(AudioInI2S)) { + Serial.println("Failed to set FFT analyzer input!"); + while (1) + ; // do nothing + } +} + +void loop() { + // check if a new analysis is available + if (fftAnalyzer.available()) { + // read the new spectrum + fftAnalyzer.read(spectrum, spectrumSize); + + // print out the spectrum + for (int i = 0; i < spectrumSize; i++) { + Serial.print((i * sampleRate) / fftSize); // the starting frequency + Serial.print("\t"); // + Serial.println(spectrum[i]); // the spectrum value + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/WavePlayback/WavePlayback.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/WavePlayback/WavePlayback.ino new file mode 100644 index 00000000..7587b7bd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/WavePlayback/WavePlayback.ino @@ -0,0 +1,96 @@ +/* + This reads a wave file from an SD card and plays it using the I2S interface to + a MAX98357 I2S Amp Breakout board. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * SD breakout or shield connected + * MAX98357: + * GND connected GND + * VIN connected 5V + * LRC connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * BCLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * DIN connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 15 November 2016 + by Sandeep Mistry + */ + +#include +#include + +// filename of wave file to play +const char filename[] = "MUSIC.WAV"; + +// variable representing the Wave File +SDWaveFile waveFile; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // setup the SD card, depending on your shield of breakout board + // you may need to pass a pin number in begin for SS + Serial.print("Initializing SD card..."); + if (!SD.begin()) { + Serial.println("initialization failed!"); + return; + } + Serial.println("initialization done."); + + // create a SDWaveFile + waveFile = SDWaveFile(filename); + + // check if the WaveFile is valid + if (!waveFile) { + Serial.println("wave file is invalid!"); + while (1) + ; // do nothing + } + + // print out some info. about the wave file + Serial.print("Bits per sample = "); + Serial.println(waveFile.bitsPerSample()); + + long channels = waveFile.channels(); + Serial.print("Channels = "); + Serial.println(channels); + + long sampleRate = waveFile.sampleRate(); + Serial.print("Sample rate = "); + Serial.print(sampleRate); + Serial.println(" Hz"); + + long duration = waveFile.duration(); + Serial.print("Duration = "); + Serial.print(duration); + Serial.println(" seconds"); + + // adjust the playback volume + AudioOutI2S.volume(5); + + // check if the I2S output can play the wave file + if (!AudioOutI2S.canPlay(waveFile)) { + Serial.println("unable to play wave file using I2S!"); + while (1) + ; // do nothing + } + + // start playback + Serial.println("starting playback"); + AudioOutI2S.play(waveFile); +} + +void loop() { + // check if playback is still going on + if (!AudioOutI2S.isPlaying()) { + // playback has stopped + + Serial.println("playback stopped"); + while (1) + ; // do nothing + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/WhistleDetector/WhistleDetector.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/WhistleDetector/WhistleDetector.ino new file mode 100644 index 00000000..cef7337c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/ArduinoSound/examples/WhistleDetector/WhistleDetector.ino @@ -0,0 +1,86 @@ +/* + This example reads audio data from an InvenSense ICS-43432 I2S microphone + breakout board, and uses the input to detect whistling sounds at a particular + frequency. When a whistle is detected, its level is used to control the + brightness of an LED. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * ICS-43432: + * GND connected GND + * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKR Zero) + * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 30 November 2016 + by Sandeep Mistry + */ + +#include + +// the LED pin to use as output +const int ledPin = LED_BUILTIN; + +// sample rate for the input +const int sampleRate = 8000; + +// size of the FFT to compute +const int fftSize = 128; + +// size of the spectrum output, half of FFT size +const int spectrumSize = fftSize / 2; + +// frequency of whistle to detect +const int whistleFrequency = 1250; + +// map whistle frequency to FFT bin +const int whistleBin = (whistleFrequency * fftSize / sampleRate); + +// array to store spectrum output +int spectrum[spectrumSize]; + +// create an FFT analyzer to be used with the I2S input +FFTAnalyzer fftAnalyzer(fftSize); + +void setup() { + // setup the serial + Serial.begin(9600); + + // configure the pin for output mode + pinMode(ledPin, OUTPUT); + + // setup the I2S audio input for the sample rate with 32-bits per sample + if (!AudioInI2S.begin(sampleRate, 32)) { + Serial.println("Failed to initialize I2S input!"); + while (1) + ; // do nothing + } + + // configure the I2S input as the input for the FFT analyzer + if (!fftAnalyzer.input(AudioInI2S)) { + Serial.println("Failed to set FFT analyzer input!"); + while (1) + ; // do nothing + } +} + +void loop() { + if (fftAnalyzer.available()) { + // analysis available, read in the spectrum + fftAnalyzer.read(spectrum, spectrumSize); + + // map the value of the whistle bin magnitude between 0 and 255 + int ledValue = map(spectrum[whistleBin], 50000, 60000, 0, 255); + + // cap the values + if (ledValue < 0) { + ledValue = 0; + } else if (ledValue > 255) { + ledValue = 255; + } + + // set LED brightness based on whistle bin magnitude + analogWrite(ledPin, ledValue); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/README.adoc new file mode 100644 index 00000000..e7b720f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/README.adoc @@ -0,0 +1,12 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_APDS9960 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +A library for the APDS-9960 sensor, allows you to read gestures, color, and proximity on your Arduino Nano 33 BLE Sense board and other boards with sensor attached via I2C. + +For more information about this library please visit us at https://www.arduino.cc/reference/en/libraries/arduino_apds9960/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/ColorSensor/ColorSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/ColorSensor/ColorSensor.ino new file mode 100644 index 00000000..162c5bac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/ColorSensor/ColorSensor.ino @@ -0,0 +1,47 @@ +/* + APDS-9960 - Color Sensor + + This example reads color data from the on-board APDS-9960 sensor of the + Nano 33 BLE Sense and prints the color RGB (red, green, blue) values + to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!APDS.begin()) { + Serial.println("Error initializing APDS-9960 sensor."); + } +} + +void loop() { + // check if a color reading is available + while (!APDS.colorAvailable()) { + delay(5); + } + int r, g, b; + + // read the color + APDS.readColor(r, g, b); + + // print the values + Serial.print("r = "); + Serial.println(r); + Serial.print("g = "); + Serial.println(g); + Serial.print("b = "); + Serial.println(b); + Serial.println(); + + // wait a bit before reading again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/FullExample/FullExample.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/FullExample/FullExample.ino new file mode 100644 index 00000000..be613bfb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/FullExample/FullExample.ino @@ -0,0 +1,85 @@ +/* + APDS-9960 - All sensor data from APDS-9960 + + This example reads all data from the on-board APDS-9960 sensor of the + Nano 33 BLE Sense: + - color RGB (red, green, blue) + - proximity + - gesture + and prints updates to the Serial Monitor every 100 ms. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; // Wait for Serial Monitor to open + + if (!APDS.begin()) { + Serial.println("Error initializing APDS-9960 sensor."); + while (true) + ; // Stop forever + } +} + +int proximity = 0; +int r = 0, g = 0, b = 0; +unsigned long lastUpdate = 0; + +void loop() { + + // Check if a proximity reading is available. + if (APDS.proximityAvailable()) { + proximity = APDS.readProximity(); + } + + // Check if a gesture reading is available + if (APDS.gestureAvailable()) { + int gesture = APDS.readGesture(); + switch (gesture) { + case GESTURE_UP: + Serial.println("Detected UP gesture"); + break; + + case GESTURE_DOWN: + Serial.println("Detected DOWN gesture"); + break; + + case GESTURE_LEFT: + Serial.println("Detected LEFT gesture"); + break; + + case GESTURE_RIGHT: + Serial.println("Detected RIGHT gesture"); + break; + + default: + // Ignore + break; + } + } + + // Check if a color reading is available + if (APDS.colorAvailable()) { + APDS.readColor(r, g, b); + } + + // Print updates every 100 ms + if (millis() - lastUpdate > 100) { + lastUpdate = millis(); + Serial.print("PR="); + Serial.print(proximity); + Serial.print(" RGB="); + Serial.print(r); + Serial.print(","); + Serial.print(g); + Serial.print(","); + Serial.println(b); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/GestureSensor/GestureSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/GestureSensor/GestureSensor.ino new file mode 100644 index 00000000..397bb2f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/GestureSensor/GestureSensor.ino @@ -0,0 +1,66 @@ +/* + APDS-9960 - Gesture Sensor + + This example reads gesture data from the on-board APDS-9960 sensor of the + Nano 33 BLE Sense and prints any detected gestures to the Serial Monitor. + + Gesture directions are as follows: + - UP: from USB connector towards antenna + - DOWN: from antenna towards USB connector + - LEFT: from analog pins side towards digital pins side + - RIGHT: from digital pins side towards analog pins side + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!APDS.begin()) { + Serial.println("Error initializing APDS-9960 sensor!"); + } + + // for setGestureSensitivity(..) a value between 1 and 100 is required. + // Higher values make the gesture recognition more sensitive but less accurate + // (a wrong gesture may be detected). Lower values makes the gesture recognition + // more accurate but less sensitive (some gestures may be missed). + // Default is 80 + //APDS.setGestureSensitivity(80); + + Serial.println("Detecting gestures ..."); +} +void loop() { + if (APDS.gestureAvailable()) { + // a gesture was detected, read and print to Serial Monitor + int gesture = APDS.readGesture(); + + switch (gesture) { + case GESTURE_UP: + Serial.println("Detected UP gesture"); + break; + + case GESTURE_DOWN: + Serial.println("Detected DOWN gesture"); + break; + + case GESTURE_LEFT: + Serial.println("Detected LEFT gesture"); + break; + + case GESTURE_RIGHT: + Serial.println("Detected RIGHT gesture"); + break; + + default: + // ignore + break; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/ProximitySensor/ProximitySensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/ProximitySensor/ProximitySensor.ino new file mode 100644 index 00000000..4418bd51 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_APDS9960/examples/ProximitySensor/ProximitySensor.ino @@ -0,0 +1,41 @@ +/* + APDS-9960 - Proximity Sensor + + This example reads proximity data from the on-board APDS-9960 sensor of the + Nano 33 BLE Sense and prints the proximity value to the Serial Monitor + every 100 ms. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!APDS.begin()) { + Serial.println("Error initializing APDS-9960 sensor!"); + } +} + +void loop() { + // check if a proximity reading is available + if (APDS.proximityAvailable()) { + // read the proximity + // - 0 => close + // - 255 => far + // - -1 => error + int proximity = APDS.readProximity(); + + // print value to the Serial Monitor + Serial.println(proximity); + } + + // wait a bit before reading again + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/README.adoc new file mode 100644 index 00000000..21601bbc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_BQ24195 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows the control and configuration of the BQ24195 PMIC used on various Arduino boards. + +The library is in beta and its APIs are not stable yet. + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryCharger/BatteryCharger.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryCharger/BatteryCharger.ino new file mode 100644 index 00000000..ee1799ce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryCharger/BatteryCharger.ino @@ -0,0 +1,82 @@ +/* + Battery Charge Example + + This example shows how to configure and enable charge mode on Arduino MKR boards + + Circuit: + - Arduino MKR board + - 750 mAh LiPo battery + + created 21 Aug 2019 + by Riccardo Rizzo + + This sample code is part of the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + if (!PMIC.begin()) { + Serial.println("Failed to initialize PMIC!"); + while (1) + ; + } + + // Set the input current limit to 2 A and the overload input voltage to 3.88 V + if (!PMIC.setInputCurrentLimit(2.0)) { + Serial.println("Error in set input current limit"); + } + + if (!PMIC.setInputVoltageLimit(3.88)) { + Serial.println("Error in set input voltage limit"); + } + + // set the minimum voltage used to feeding the module embed on Board + if (!PMIC.setMinimumSystemVoltage(3.5)) { + Serial.println("Error in set minimum system volage"); + } + + // Set the desired charge voltage to 4.11 V + if (!PMIC.setChargeVoltage(4.2)) { + Serial.println("Error in set charge volage"); + } + + // Set the charge current to 375 mA + // the charge current should be defined as maximum at (C for hour)/2h + // to avoid battery explosion (for example for a 750 mAh battery set to 0.375 A) + if (!PMIC.setChargeCurrent(0.375)) { + Serial.println("Error in set charge current"); + } + Serial.println("Initialization done!"); +} + +void loop() { + // Enable the Charger + if (!PMIC.enableCharge()) { + Serial.println("Error enabling Charge mode"); + } + // canRunOnBattery() returns true if the battery voltage is < the minimum + // systems voltage + if (PMIC.canRunOnBattery()) { + // loop until charge is done + while (PMIC.chargeStatus() != CHARGE_TERMINATION_DONE) { + delay(1000); + } + // Disable the charger and loop forever + Serial.println("Disable Charge mode"); + if (!PMIC.disableCharge()) { + Serial.println("Error disabling Charge mode"); + } + while (1) + ; + // if you really want to detach the battery call + // PMIC.disableBATFET(); + //isbatteryconnected = false; + } + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryChargerInterrupt/BatteryChargerInterrupt.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryChargerInterrupt/BatteryChargerInterrupt.ino new file mode 100644 index 00000000..ce91558f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryChargerInterrupt/BatteryChargerInterrupt.ino @@ -0,0 +1,97 @@ +/* + Battery Charge Interrupt Example + + This example shows how to configure and enable charge mode on Arduino MKR boards + + Circuit: + - Arduino MKR board + - 750 mAh LiPo battery + + created 21 Aug 2019 + by Riccardo Rizzo + + This sample code is part of the public domain. +*/ + +#include + +volatile unsigned long time_last_interrupt = millis(); + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + +// Available only for MKRGSM1400 and MKRNB1500 +#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) + // Attach the PMIC IRQ pin + attachInterrupt(digitalPinToInterrupt(PMIC_IRQ_PIN), batteryConnected, FALLING); +#endif + + if (!PMIC.begin()) { + Serial.println("Failed to initialize PMIC!"); + while (1) + ; + } + + // Set the input current limit to 2 A and the overload input voltage to 3.88 V + if (!PMIC.setInputCurrentLimit(2.0)) { + Serial.println("Error in set input current limit"); + } + + if (!PMIC.setInputVoltageLimit(3.88)) { + Serial.println("Error in set input voltage limit"); + } + + // set the minimum voltage used to feeding the module embed on Board + if (!PMIC.setMinimumSystemVoltage(3.5)) { + Serial.println("Error in set minimum system volage"); + } + + // Set the desired charge voltage to 4.11 V + if (!PMIC.setChargeVoltage(4.2)) { + Serial.println("Error in set charge volage"); + } + + // Set the charge current to 375 mA + // the charge current should be defined as maximum at (C for hour)/2h + // to avoid battery explosion (for example for a 750mAh battery set to 0.375 A) + if (!PMIC.setChargeCurrent(0.375)) { + Serial.println("Error in set charge current"); + } + Serial.println("Initialization done!"); +} + +void loop() { + if (millis() - time_last_interrupt > 100) { + // Enable the Charger + if (!PMIC.enableCharge()) { + Serial.println("Error enabling Charge mode"); + } + + // canRunOnBattery() returns true if the battery voltage is < the minimum + // systems voltage + if (PMIC.canRunOnBattery()) { + + // loop until charge is done + if (PMIC.chargeStatus() != CHARGE_TERMINATION_DONE) { + delay(1000); + } else { + // Disable the charger + Serial.println("Disable Charge mode"); + if (!PMIC.disableCharge()) { + Serial.println("Error disabling Charge mode"); + } + // if you really want to detach the battery call + // PMIC.disableBATFET(); + //isbatteryconnected = false; + } + } + } + delay(100); +} + +void batteryConnected() { + time_last_interrupt = millis(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/PMICBoostMode/PMICBoostMode.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/PMICBoostMode/PMICBoostMode.ino new file mode 100644 index 00000000..6d1f0c6e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/PMICBoostMode/PMICBoostMode.ino @@ -0,0 +1,48 @@ +/* + PMIC Boost Mode Example + + This example shows how to enable boost mode on Arduino MKR boards + + Circuit: + - Arduino MKR board + - OTG cable + + created 21 Aug 2019 + by Riccardo Rizzo + + This sample code is part of the public domain. +*/ + +#include + +int usb_mode = UNKNOWN_MODE; + +void setup() { + // Serial1 shall be used to print messages because the programming + // port is busy with the guest device + Serial1.begin(9600); + if (!PMIC.begin()) { + Serial1.println("Failed to initialize PMIC!"); + while (1) + ; + } + + // Enable boost mode, this mode allows using the board as host to + // connect a guest device such as a keyboard + if (!PMIC.enableBoostMode()) { + Serial1.println("Error enabling Boost Mode"); + } + Serial1.println("Initialization Done!"); +} + +void loop() { + int actual_mode = PMIC.USBmode(); + if (actual_mode != usb_mode) { + usb_mode = actual_mode; + if (actual_mode == BOOST_MODE) { + // if the boost mode was correctly enabled, 5 V should appear on 5V pin + // and on the USB connector + Serial1.println("Boost mode status enabled"); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/PMICFaultCheck/PMICFaultCheck.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/PMICFaultCheck/PMICFaultCheck.ino new file mode 100644 index 00000000..13c56b7f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_BQ24195/examples/PMICFaultCheck/PMICFaultCheck.ino @@ -0,0 +1,73 @@ +/* + PMIC Fault Check Example + + This example shows how to check the PMIC fault states + + Circuit: + - Arduino MKR board + + created 21 Aug 2019 + by Riccardo Rizzo + + This sample code is part of the public domain. +*/ + +#include + +int chargefault = NO_CHARGE_FAULT; +int batTempfault = NO_TEMPERATURE_FAULT; + +void setup() { + if (!PMIC.begin()) { + Serial.println("Failed to initialize PMIC!"); + while (1) + ; + } +} + +void loop() { + // getChargeFault() returns the charge fault state, the fault could be: + // - Thermal shutdown: occurs if internal junction temperature exceeds + // the preset limit; + // - input over voltage: occurs if VBUS voltage exceeds 18 V; + // - charge safety timer expiration: occurs if the charge timer expires. + chargefault = PMIC.getChargeFault(); + // getChargeFault() returns charge fault status + switch (chargefault) { + case INPUT_OVER_VOLTAGE: + Serial.println("Input over voltage fault occurred"); + break; + case THERMAL_SHUTDOWN: + Serial.println("Thermal shutdown occurred"); + break; + case CHARGE_SAFETY_TIME_EXPIRED: + Serial.println("Charge safety timer expired"); + break; + case NO_CHARGE_FAULT: + Serial.println("No Charge fault"); + break; + default: break; + } + + // The isBatteryInOverVoltage() returns if battery over-voltage fault occurs. + // When battery over voltage occurs, the charger device immediately disables + // charge and sets the battery fault bit, in fault register, to high. + if (PMIC.isBatteryInOverVoltage()) { + Serial.println("Error: battery over voltage fault"); + } + + + batTempfault = PMIC.hasBatteryTemperatureFault(); + switch (batTempfault) { + case NO_TEMPERATURE_FAULT: + Serial.println("No temperature fault"); + break; + case LOWER_THRESHOLD_TEMPERATURE_FAULT: + Serial.println("Lower threshold Battery temperature fault"); + break; + case HIGHER_THRESHOLD_TEMPERATURE_FAULT: + Serial.println("Higher threshold Battery temperature fault"); + break; + default: break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/README.md new file mode 100644 index 00000000..17eef2e6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/README.md @@ -0,0 +1,63 @@ +Arduino Library for network connections management +================================================== + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) + +Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: +* **WiFi**: [`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), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), `ESP8266` +* **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) +* **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) +* **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) + +### How-to-use + +```C++ +#include +/* ... */ +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler conMan("SECRET_SSID", "SECRET_PASS"); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS"); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS"); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler conMan("SECRET_APP_EUI", "SECRET_APP_KEY"); +#endif +/* ... */ +void setup() { + Serial.begin(9600); + while(!Serial) { } + + setDebugMessageLevel(DBG_INFO); + + conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); + conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); + conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); +} + +void loop() { + /* The following code keeps on running connection workflows on our + * ConnectionHandler object, hence allowing reconnection in case of failure + * and notification of connect/disconnect event if enabled (see + * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within + * the loop or methods called from it will delay the execution of .check(), + * which might not guarantee the correct functioning of the ConnectionHandler + * object. + */ + conMan.check(); +} +/* ... */ +void onNetworkConnect() { + Serial.println(">>>> CONNECTED to network"); +} + +void onNetworkDisconnect() { + Serial.println(">>>> DISCONNECTED from network"); +} + +void onNetworkError() { + Serial.println(">>>> ERROR"); +} +``` diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino new file mode 100644 index 00000000..b106eed6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -0,0 +1,68 @@ +/* SECRET_ fields are in arduino_secrets.h included above + * if using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO + * WiFi Rev 2 or ESP8266/32), create a WiFiConnectionHandler object by adding + * Network Name (SECRET_SSID) and password (SECRET_PASS) in the arduino_secrets.h + * file (or Secrets tab in Create Web Editor). + * + * WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS); + * + * If using a MKR GSM 1400 or other GSM boards supporting the same API you'll + * need a GSMConnectionHandler object as follows + * + * GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); + * + * If using a MKR NB1500 you'll need a NBConnectionHandler object as follows + * + * NBConnectionHandler conMan(SECRET_PIN); + */ + +#include "arduino_secrets.h" + +#include + +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_PASS); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler conMan(SECRET_PIN); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler conMan(SECRET_APP_EUI, SECRET_APP_KEY); +#endif + +void setup() { + Serial.begin(9600); + /* Give a few seconds for the Serial connection to be available */ + delay(4000); +#ifndef __AVR__ + setDebugMessageLevel(DBG_INFO); +#endif + conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); + conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); + conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); +} + +void loop() { + /* The following code keeps on running connection workflows on our + * ConnectionHandler object, hence allowing reconnection in case of failure + * and notification of connect/disconnect event if enabled (see + * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within + * the loop or methods called from it will delay the execution of .update(), + * which might not guarantee the correct functioning of the ConnectionHandler + * object. + */ + + conMan.check(); +} + +void onNetworkConnect() { + Serial.println(">>>> CONNECTED to network"); +} + +void onNetworkDisconnect() { + Serial.println(">>>> DISCONNECTED from network"); +} + +void onNetworkError() { + Serial.println(">>>> ERROR"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/arduino_secrets.h new file mode 100644 index 00000000..8c24b895 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/arduino_secrets.h @@ -0,0 +1,10 @@ +const char SECRET_SSID[] = "NETWORK NAME"; +const char SECRET_PASS[] = "NETWORK PASSWORD"; + +const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; +const char SECRET_PIN[] = "0000"; +const char SECRET_GSM_USER[] = "GSM USERNAME"; +const char SECRET_GSM_PASS[] = "GSM PASSWORD"; + +const char SECRET_APP_EUI[] = "APP_EUI"; +const char SECRET_APP_KEY[] = "APP_KEY"; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/LICENSE new file mode 100644 index 00000000..cd4defc3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/LICENSE @@ -0,0 +1,688 @@ +This file includes licensing information for Arduino_DebugUtils. + +Copyright (c) 2018 ARDUINO SA (www.arduino.cc) + +The software is released under the GNU General Public License, which covers the main body +of the Arduino_DebugUtils code. The terms of this license can be found at: +https://www.gnu.org/licenses/gpl-3.0.en.html + +You can be released from the requirements of the above licenses by purchasing +a commercial license. Buying such a license is mandatory if you want to modify or +otherwise use the software for commercial activities involving the Arduino +software without disclosing the source code of your own applications. To purchase +a commercial license, send an email to license@arduino.cc + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + Arduino_DebugUtils encapsulates functionality useful for debugging code via printf statements. + Copyright (C) Arduino SA, 2019, Author: Alexander Entinger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Arduino_DebugUtils Copyright (C) 2019, Arduino SA + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/README.md new file mode 100644 index 00000000..bd8dcd61 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/README.md @@ -0,0 +1,113 @@ +Arduino_DebugUtils +================== + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/spell-check.yml) + +This class provides functionality useful for debugging sketches via `printf`-style statements. + +# How-To-Use Basic +Arduino_DebugUtils has 6 different debug levels (described descending from highest to lowest priority): +* `DBG_NONE` - no debug output is shown +* `DBG_ERROR` - critical errors +* `DBG_WARNING` - non-critical errors +* `DBG_INFO` - information +* `DBG_DEBUG` - more information +* `DBG_VERBOSE` - most information + +The desired debug level can be set via `setDebugLevel(DBG_WARNING)`. + +Debug messages are written via `print` which supports `printf`-style formatted output. + +Example: +```C++ +int i = 1; +float pi = 3.1459; +Debug.print(DBG_VERBOSE, "i = %d, pi = %f", i, pi); +``` +**Note**: The output of floating point numbers (`%f`) does NOT work on [ArduinoCore-avr](https://github.com/arduino/ArduinoCore-avr). + +If desired, timestamps can be prefixed to the debug message. Timestamp output can be enabled and disabled via `timestampOn` and `timestampOff`. + +# How-To-Use Advanced +Normally all debug output is redirected to the primary serial output of each board (`Serial`). In case you want to redirect the output to another output stream you can make use of `setDebugOutputStream(&Serial2)`. + +# Documentation +### Debug : +Arduino_DebugUtils Object that will be used for calling member functions. + +### Debug.setDebugLevel(int const debug_level) : +Parameter debug_level in order of lowest to highest priority are : `DBG_NONE`, `DBG_ERROR`, `DBG_WARNING`, `DBG_INFO` (default), `DBG_DEBUG`, and `DBG_VERBOSE`. + +Return type: void. + +Example: +``` +Debug.setDebugLevel(DBG_VERBOSE); +``` +### Debug.setDebugOutputStream(Stream * stream) : +By default, Output Stream is Serial. In advanced cases other objects could be other serial ports (if available), or can be a Software Serial object. + +Return type: void. + +Example: +``` +SoftwareSerial mySerial(10, 11); // RX, TX +Debug.setDebugOutputStream(&mySerial); +``` +### Debug.timestampOn() : +Calling this function switches on the timestamp in the `Debug.print()` function call; +By default, printing timestamp is off, unless turned on using this function call. + +Return type: void. + +Example: +``` +Debug.timestampOn(); +Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : [ 21007 ] i = 21 +``` + +### Debug.timestampOff() : +Calling this function switches off the timestamp in the `Debug.print()` function call; + +Return type: void. + +Example: +``` +Debug.timestampOff(); +Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : i = 21 +``` + +### Debug.newlineOn() : +Calling this function ensures that a newline will be sent at the end of the `Debug.print()` function call; +By default, a newline is sent +Return type: void. + +Example: +``` +Debug.newlineOn(); +``` + +### Debug.newlineOff() : +Calling this function ensure that a newline will NOT be sent at the end of the `Debug.print()` function call; +By default a newline is sent. Call this to shut that functionality off. +Return type: void. + +Example: +``` +Debug.timestampOff(); +``` + + +### Debug.print(int const debug_level, const char * fmt, ...); +This function prints the message if parameter `debug_level` in the `Debug.print(debug_level, ...)` function call belongs to the range: DBG_ERROR <= debug_level <= ( that has been set using `setDebugLevel()` function). + +Return type: void. + +Example: +``` +Debug.setDebugLevel(DBG_VERBOSE); +int i = 0; +Debug.print(DBG_VERBOSE, "DBG_VERBOSE i = %d", i); +``` diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Advance/Arduino_Debug_Advance.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Advance/Arduino_Debug_Advance.ino new file mode 100644 index 00000000..e5390604 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Advance/Arduino_Debug_Advance.ino @@ -0,0 +1,30 @@ +/* + Advanced Debug can be helpful in embedded applications when + there are more than two microcontrollers connected serially + or a wireless sensor like XBee is connected to the serial port + that will send data wirelessly to other XBee nodes. + + In boards like Arduino Nano, UNO, or MEGA only one serial port is available, + therefore additional software serial ports can be made using the + SoftwareSerial library. +*/ + +#include "Arduino_DebugUtils.h" +#include + +SoftwareSerial mySerial(10, 11); // RX, TX + +void setup() { + mySerial.begin(9600); + Debug.setDebugOutputStream(&mySerial); + Debug.setDebugLevel(DBG_VERBOSE); + Debug.timestampOn(); +} + +int i = 0; + +void loop() { + Debug.print(DBG_VERBOSE, "i = %d", i); + i++; + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino new file mode 100644 index 00000000..ddfedfeb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino @@ -0,0 +1,14 @@ +#include "Arduino_DebugUtils.h" + +void setup() { + Serial.begin(9600); + Debug.timestampOn(); +} + +int i = 0; + +void loop() { + Debug.print(DBG_INFO, "i = %d", i); + i++; + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/LICENSE new file mode 100644 index 00000000..a612ad98 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/README.md new file mode 100644 index 00000000..27d1162e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/README.md @@ -0,0 +1,16 @@ +![Compile Examples](https://github.com/arduino-libraries/Arduino_EdgeControl/actions/workflows/compile-examples.yml/badge.svg) + +# Arduino_EdgeControl + +Arduino Library for Arduino Edge Control + +## License + +Copyright (C) 2021 Arduino AG (http://www.arduino.cc/) + +SPDX-License-Identifier: MPL-2.0 + + +This Source Code Form is subject to the terms of the Mozilla Public +License, v. 2.0. If a copy of the MPL was not distributed with this +file, You can obtain one at https://mozilla.org/MPL/2.0/. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/3WiresValve/3WiresValve.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/3WiresValve/3WiresValve.ino new file mode 100644 index 00000000..981be75a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/3WiresValve/3WiresValve.ino @@ -0,0 +1,29 @@ +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + delay(1000); + + Serial.println("3-Wire Valve Demo"); + + EdgeControl.begin(); + Latching.begin(); + + Serial.println("Starting"); +} + +void loop() { + Serial.println("Closing"); + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(4500); + + delay(2500); + + Serial.println("Opening"); + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(4500); + delay(2500); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.cpp new file mode 100644 index 00000000..388a0475 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.cpp @@ -0,0 +1,81 @@ +#include "AlarmTasks.h" + +/** +* Parse a task line from the alarmtab.txt file +* +* Lines must follow the following structure. +* +* The name of the command to execute must match an entry +* in the 'commandMap' map defined in the CustomTasks.h file. +* +* In case of TR, TO and RO alarm types, the day of week, hour +* and minute parameters are ignored. +* In case of RO alarm type, the second parameters must bean UNIX +* specified as UNIX timestamp (seconds since EPOCH). +* +* See the TimeAlarms (https://github.com/PaulStoffregen/TimeAlarms) +* docs for further specs. +* +* Lines starting with pound symbol (#) are ignored. +* +* +* ┌──────────── alarm type: AR == AlarmRepeat, AO == AlarmOnce, +* | TR == TimerRepeat, TO == TimerOnne, +* | RO == TriggerOnce +* | ┌────────── day of week: 0 == None, 1 == Sun, ..., 7 == Sat +* | | ┌─────── hour +* | | | ┌──── minute +* | | | | ┌─ second +* | | | | | +* | | | | | +* AR 0 18 45 0 OpenLatchingValve +* AR 0 18 45 30 CloseLatchingValve +* AR 0 18 46 0 OpenLatchingValve +* AR 0 18 46 30 CloseLatchingValve +* TR 0 0 0 20 DisplayClock +* TR 0 0 0 10 BlinkLed +* TO 0 0 0 10 DisplayClockOnce +* RO 0 0 0 1602759860 DisplayClockTrigger +* +*/ +AlarmTask parseAlarmTask(const String line) { + auto const len{ line.length() + 1 }; + char buf[len]{ 0 }; + char cmd[32]{ 0 }; + char method[3]{ 0 }; + + AlarmTask task; + + line.toCharArray(buf, len); + auto n = sscanf(buf, "%s %d %d %d %d %s", method, &task.day, &task.hour, &task.min, &task.sec, cmd); + if (n != 6) + return task; + + auto itm = alarmMethods.find(method); + if (itm != alarmMethods.end()) + task.method = itm->second; + + auto itc = commandMap.find(cmd); + if (itc != commandMap.end()) + task.handler = itc->second; + + return task; +} + +/** + * Parse the alarmtab.txt file + */ +std::list parseAlarmTab(File& file) { + std::list taskList; + + while (file.available()) { + auto line = file.readStringUntil('\n'); + if (line.charAt(0) == '#') + continue; + auto task = parseAlarmTask(line); + if (task.handler != nullptr && task.method != METHOD_INVALID) + taskList.push_back(task); + } + + return taskList; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.h new file mode 100644 index 00000000..47a02199 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + +#include "CustomTasks.h" + +/** + * Supported alarm types + */ +enum AlarmMethod { + METHOD_INVALID, + ALARM_REPEAT, + ALARM_ONCE, + TIMER_REPEAT, + TIMER_ONCE, + TRIGGER_ONCE, +}; + +/** + * The internal structure for managing tasks + */ +struct AlarmTask { + AlarmMethod method{ METHOD_INVALID }; + OnTick_t handler{ nullptr }; + timeDayOfWeek_t day; + int hour; + int min; + int sec; +}; + +/** + * An helper map for parsing alarm types from alarmtab lines + */ +static std::map alarmMethods{ + { "AR", ALARM_REPEAT }, + { "AO", ALARM_ONCE }, + { "TR", TIMER_REPEAT }, + { "TO", TIMER_ONCE }, + { "RO", TRIGGER_ONCE }, +}; + +/** + * Parse a task line from the alarmtab.txt file + */ +AlarmTask parseAlarmTask(const String line); + +/** + * Parse the alarmtab.txt file + */ +std::list parseAlarmTab(File& file); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.cpp new file mode 100644 index 00000000..66243b25 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.cpp @@ -0,0 +1,106 @@ +#include "CustomTasks.h" + +void openLatchingValve() { + Serial.println("Alarm: Opening Latching Valve"); + + Serial.print("["); + Serial.print(getLocaltime()); + Serial.print("] Opening Valve: "); + + // Polarize the opening pin of the 3-wires valve + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(5000); + + Serial.println("Valve Open"); +} + +void closeLatchingValve() { + Serial.println("Alarm: Closing Latching Valve"); + + Serial.print("["); + Serial.print(getLocaltime()); + Serial.print("] Closing Valve: "); + + // Polarize the closing pin of the 3-wires valve + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(5000); + + Serial.println("Valve Closed"); +} + +void openSolenoidValve() { + Serial.println("Alarm: Opening Solenoid Valve"); + + Serial.print("["); + Serial.print(getLocaltime()); + Serial.print("] Opening Valve: "); + + // Open the Solid State Relay on Channel 1 + Relay.on(RELAY_CH01); + + Serial.println("Valve Open"); +} + +void closeSolenoidValve() { + Serial.println("Alarm: Closing Solenoid Valve"); + + Serial.print("["); + Serial.print(getLocaltime()); + Serial.print("] Closing Valve: "); + + // Close the Solid State Relay on Channel 1 + Relay.off(RELAY_CH01); + + Serial.println("Valve Closed"); +} + +void displayClock() { + String date = getLocaltime("%Y-%m-%d", true, 0); + String time = getLocaltime("%k:%M:%S", true, 0); + Serial.println(date); + Serial.println(time); +} + +void blinkLed() { + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, LOW); + delay(10); + + // Power off the on-board LED (active low) + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, HIGH); +} + +void getSensors() { + extern std::list dataPoints; + + Serial.print("Moisture: "); + + auto value = getAverageInputRead(INPUT_05V_CH01); + auto perc = getMoisturePerc(INPUT_05V_CH01); + + DataPoint d{ value, perc }; + + Serial.println(d); + dataPoints.push_back(d); +} + +void saveData() { + Serial.println("Saving Data..."); + + auto ret = saveSensorsData(); + if (ret <= 0) + Serial.print("Error: "); + else + Serial.print("Saved: "); + + Serial.println(ret); +} + +void helloWorld() { + Serial.println("Hello, World!"); +} + +void hiThere() { + Serial.println("Hi, There!"); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.h new file mode 100644 index 00000000..43dd2389 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +#include "Helpers.h" +#include "SensorsData.h" +#include "TimeHelpers.h" + +void openLatchingValve(); +void closeLatchingValve(); +void openSolenoidValve(); +void closeSolenoidValve(); +void displayClock(); +void blinkLed(); +void saveData(); +void helloWorld(); +void hiThere(); +void getSensors(); + +/** + * Define your task function and add it to the commandMap. + * The key of the map is the name to be used in the alarmtab file. + */ +static std::map commandMap{ + { "OpenLatchingValve", openLatchingValve }, + { "CloseLatchingValve", closeLatchingValve }, + { "OpenSolenoidValve", openSolenoidValve }, + { "CloseSolenoidValve", closeSolenoidValve }, + { "DisplayClock", displayClock }, + { "BlinkLed", blinkLed }, + { "SaveData", saveData }, + { "HelloWorld", helloWorld }, + { "HiThere", hiThere }, + { "GetSensors", getSensors }, +}; \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.cpp new file mode 100644 index 00000000..0c155502 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.cpp @@ -0,0 +1,105 @@ +#include "Helpers.h" + +/** + * Set system and TimeAlarm clock from compile datetime or RTC + */ +void setSystemClock(String buildDate, String buildTime) { + // Retrieve clock time from compile date... + auto buildDateTime = buildDateTimeToSystemTime(buildDate, buildTime, true, 2); + // ... ore use the one from integrated RTC. + auto rtcTime = time(NULL); + + // Remember to connect at least the CR2032 battery + // to keep the RTC running. + auto actualTime = rtcTime > buildDateTime ? rtcTime : buildDateTime; + + // Set both system time and the alarms one + set_time(actualTime); + setTime(actualTime); + + Serial.print("Compile Date and Time: "); + Serial.println(getLocaltime(buildDateTime)); + Serial.print("RTC Date and Time: "); + Serial.println(getLocaltime(rtcTime)); + Serial.print("System Clock: "); + Serial.println(getLocaltime()); +} + +void statusPrint() { + String msg; + + Serial.println("Measures..."); + + msg = "Moisture ["; + msg += dataPoints.size(); + msg += "]"; + Serial.println(msg); + + msg = "Latest: "; + auto d = dataPoints.back(); + msg += d.moistureP; + msg += "%"; + Serial.println(msg); + + Serial.println("Loaded Tasks..."); + + msg = "Custom: "; + msg += alarmTabIDs.size(); + Serial.println(msg); + + msg = "Sketch: "; + msg += alarmSketchIDs.size(); + Serial.println(msg); +} + +float getAverage05VRead(int pin) { + constexpr size_t loops{ 10 }; + constexpr float toV{ 3.3f / float{ (1 << ADC_RESOLUTION) - 1 } }; + + // Resistor divider on Input ports + constexpr float rDiv{ 17.4f / (10.0f + 17.4f) }; + + int tot{ 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return avg / rDiv; +} + +uint16_t getAverageInputRead(int pin, const size_t loops) { + unsigned int tot{ 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + return tot / loops; +} + +uint8_t getMoisturePerc(int pin) { + // Keep track ok dry/wet values. YMMV. + static long dryValue{ 2160 }; + static long wetValue{ 975 }; + + auto val = getAverageInputRead(pin); + + // Self-update dry/wet values range. + if (val > dryValue) + dryValue = val; + if (val < wetValue) + wetValue = val; + + auto perc = map(val, dryValue, wetValue, 0, 100); + + return static_cast(perc); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.h new file mode 100644 index 00000000..dd3153e0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.h @@ -0,0 +1,20 @@ +#pragma once + +#include "SensorsData.h" +#include "TimeHelpers.h" +#include +#include +#include + +#include +#include + +void setSystemClock(String date = __DATE__, String time = __TIME__); +void statusPrint(); +uint16_t getAverageInputRead(int pin, size_t loops = 20); +float getAverage05VRead(int pin); +uint8_t getMoisturePerc(int pin); + +extern std::list alarmTabIDs; +extern std::list alarmSketchIDs; +extern std::list dataPoints; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/IrrigationSimple.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/IrrigationSimple.ino new file mode 100644 index 00000000..b442eef9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/IrrigationSimple.ino @@ -0,0 +1,174 @@ +/** + * Simple irrigation system with Arduino EdgeControl + * + * Circuit: + * - Arduino EdgeControl + * - MicroSD card + * - CR2032 Battery and/or 12V Lead Battery + * - Button connected to POWER_ON pin on the LCD breakout header + * + * Usage: + * - Define your callback functions in CustomTasks.{h,cpp} + * - Map the callback functions to alarmatab command names in + * CustomTasks.h::commandMap map. + * - Add tasks to the alarmtab.txt file and copy it on the SD card; + * See alarmtab.txt and AlarmTasks.cpp for documentation. + */ + +#include + +#include "AlarmTasks.h" +#include "SensorsData.h" +#include "TimeHelpers.h" +#include "TasksHelpers.h" +#include "Helpers.h" + +/** UI Management **/ +// Button statuses +enum ButtonStatus : byte { + ZERO_TAP, + SINGLE_TAP, + DOUBLE_TAP, + TRIPLE_TAP, + LOT_OF_TAPS +}; + +// ISR: count the button taps +volatile byte taps{ 0 }; +// ISR: keep elapsed timings +volatile unsigned long previousPress{ 0 }; +// ISR: Final button status +volatile ButtonStatus buttonStatus{ ZERO_TAP }; + +/** + * Used to keep track of the running alarms from + * alarmtab.txt. + * + * The loadAndSetTasks() function will fill this + * with tasks defined in CustomTasks.{h.cpp} and + * loaded from the alarmtab.txt on the SD. + * + */ +std::list alarmTabIDs; + +/** + * Used to keep track of the alarms defined in the + * sketch. + */ +std::list alarmSketchIDs; + +/** + * Used to keep track of the measurements points + */ +std::list dataPoints; + +void setup() { + Serial.begin(9600); + constexpr unsigned long timeout{ 2500 }; + + // Wait for Serial Monitor for timeout ms + auto startNow = millis() + timeout; + while (!Serial && millis() < startNow) + ; + + delay(1000); + + // Set System and Alarm clock + // Use compile datetime as proxy clock synch + // Use a CR2032 battery for persistent RTC. + setSystemClock(); + + // Init board-related objects + EdgeControl.begin(); + + // Enable the 3V3 and 12V power rails. + // Needed for IO Expander and SD card. + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + // Init the sensors inputs. + // If needed, will also take care of enabling the + // 3V3 and 12V power rails and to initialize the IO Expander. + Input.begin(); + + Latching.begin(); + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(5000); + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(5000); + + Relay.begin(); + delay(1000); + Relay.on(RELAY_CH01); + delay(5000); + Relay.off(RELAY_CH01); + + // Load alarm tasks list from file on SD. + // See example alarmtab.txt for example and + // AlarmTasks.{h, cpp} source files for documentation. + loadAndSetTasks(alarmTabIDs); + + // Use the a button for housekeeping stuff: + // Single Tap: Show status + // Double Tap: Reload alarm tasks from SD + // Triple Tap: Force saving data to SD + pinMode(POWER_ON, INPUT); + attachInterrupt(POWER_ON, buttonPress, RISING); + + auto id = Alarm.timerRepeat(10, getSensors); + alarmSketchIDs.push_back(id); +} + +void loop() { + // Do alarms processing + Alarm.delay(10); + + // Detect Single Tap, Double Tap, etc. + // to buttonStatus + detectTaps(); + + switch (buttonStatus) { + case ZERO_TAP: + break; + case SINGLE_TAP: + Serial.println("Single Tap"); + statusPrint(); + buttonStatus = ZERO_TAP; + break; + case DOUBLE_TAP: + Serial.println("Double Tap"); + loadAndSetTasks(alarmTabIDs, true); + buttonStatus = ZERO_TAP; + break; + case TRIPLE_TAP: + Serial.println("Triple Tap"); + saveData(); + buttonStatus = ZERO_TAP; + break; + default: + Serial.println("Too Many Taps"); + buttonStatus = ZERO_TAP; + break; + } +} + +void buttonPress() { + const auto now = millis(); + // Poor-man debouncing + if (now - previousPress > 100) + taps++; + + previousPress = now; +} + +void detectTaps() { + // Timeout to validate the button taps counter + constexpr unsigned int buttonTapsTimeout{ 300 }; + + // Set the button status and reset the taps counter when button has been + // pressed at least once and button taps validation timeout has been reached. + if (taps > 0 && millis() - previousPress >= buttonTapsTimeout) { + buttonStatus = static_cast(taps); + taps = 0; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.cpp new file mode 100644 index 00000000..beeb8719 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.cpp @@ -0,0 +1,43 @@ +#include "SensorsData.h" + +DataPoint::DataPoint(uint16_t moistureA, uint8_t moistureP) + : ts(time(nullptr)), moistureA(moistureA), moistureP(moistureP) { +} + +size_t DataPoint::printTo(Print& p) const { + size_t written{ 0 }; + + written += p.print((unsigned long)ts); + written += p.print(','); + written += p.print(moistureA); + written += p.print(','); + written += p.print(moistureP); + + return written; +} + +int saveSensorsData() { + extern std::list dataPoints; + + unsigned int count{ 0 }; + + if (!SD.begin(PIN_SD_CS)) + return -2; + + auto dataLog = SD.open("datalog.csv", FILE_WRITE); + if (!dataLog) + return -1; + + for (auto d = dataPoints.begin(); d != dataPoints.end(); ++d) { + auto bytes = dataLog.println(*d); + if (bytes == 0) // if write failed, don't erase + continue; + count++; + dataPoints.erase(d); + } + + dataLog.close(); + SD.end(); + + return count; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.h new file mode 100644 index 00000000..f4b4451d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include + +struct DataPoint : Printable { + time_t ts; + uint16_t moistureA; + uint8_t moistureP; + + DataPoint(uint16_t moistureA, uint8_t moistureP); + + virtual size_t printTo(Print& p) const; +}; + +int saveSensorsData(); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.cpp new file mode 100644 index 00000000..9624318c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.cpp @@ -0,0 +1,138 @@ +#include "TasksHelpers.h" + +/** + * Load alarm task from parsed alarmtab.txt file on SD. + */ +std::list loadTasks() { + if (!SD.begin(PIN_SD_CS)) { + Serial.println("SD initialization failed"); + while (true) + ; + } + auto alarmtab = SD.open("alarmtab.txt"); + auto taskList = parseAlarmTab(alarmtab); + + alarmtab.close(); + SD.end(); + + return taskList; +} + +/** + * Set the alarm tasks from the loaded list. + */ +std::list setTasks(std::list taskList) { + AlarmID_t alarmID{ dtINVALID_ALARM_ID }; + std::list alarmIDs; + + for (auto& task : taskList) { + switch (task.method) { + case ALARM_REPEAT: + { + if (task.day == 0) + alarmID = Alarm.alarmRepeat(task.hour, task.min, task.sec, task.handler); + else + alarmID = Alarm.alarmRepeat(task.day, task.hour, task.min, task.sec, task.handler); + break; + } + case ALARM_ONCE: + { + if (task.day == 0) + alarmID = Alarm.alarmOnce(task.hour, task.min, task.sec, task.handler); + else + alarmID = Alarm.alarmOnce(task.day, task.hour, task.min, task.sec, task.handler); + break; + } + case TIMER_REPEAT: + { + alarmID = Alarm.timerRepeat(task.sec, task.handler); + break; + } + case TIMER_ONCE: + { + alarmID = Alarm.timerOnce(task.sec, task.handler); + break; + } + case TRIGGER_ONCE: + { + alarmID = Alarm.triggerOnce(task.sec, task.handler); + break; + } + default: + break; + } + alarmIDs.push_back(alarmID); + } + + return alarmIDs; +} + +/** + * Free the current alarm tasks + */ +void freeTasks(std::list& alarmIDs) { + for (auto& id : alarmIDs) { + Alarm.free(id); + id = dtINVALID_ALARM_ID; + } +} + +/** + * Load and set tasks from alarmtab.txt file. + * + * Remove previously loaded tasks if parameter is true. + */ +void loadAndSetTasks(std::list& alarmIDs, bool reload) { + if (reload) { + Serial.println("Reloading Tasks: "); + freeTasks(alarmIDs); + } else { + Serial.println("Loading Tasks: "); + } + + auto taskList = loadTasks(); + alarmIDs = setTasks(taskList); + printTasks(taskList); + + Serial.print(alarmIDs.size()); + Serial.println(" loaded"); +} + +void printTasks(const std::list taskList) { + for (auto const task : taskList) { + Serial.print("- "); + switch (task.method) { + case ALARM_REPEAT: + Serial.print("ALARM_REPEAT"); + break; + case ALARM_ONCE: + Serial.print("ALARM_ONCE"); + break; + case TIMER_REPEAT: + Serial.print("TIMER_REPEAT"); + break; + case TIMER_ONCE: + Serial.print("TIMER_ONCE"); + break; + case TRIGGER_ONCE: + Serial.print("TRIGGER_ONCE"); + break; + default: + Serial.print("UNKNOWN"); + break; + } + Serial.print(" "); + Serial.print(task.day); + Serial.print(" "); + Serial.print(task.hour); + Serial.print(" "); + Serial.print(task.min); + Serial.print(" "); + Serial.print(task.sec); + Serial.print(" "); + Serial.println((uint64_t)(task.handler), HEX); + } + + Serial.print(taskList.size()); + Serial.println(" tasks loaded."); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.h new file mode 100644 index 00000000..3185e7c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include +#include + +#include "AlarmTasks.h" + +std::list loadTasks(); +std::list setTasks(std::list taskList); +void freeTasks(std::list& alarmIDs); +void loadAndSetTasks(std::list& alarmIDs, bool reload = false); +void printTasks(const std::list taskList); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.cpp new file mode 100644 index 00000000..0dff616e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.cpp @@ -0,0 +1,84 @@ +#include "TimeHelpers.h" + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String date, const String time, bool local_time = true, int tz = 0) { + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + sscanf(date.c_str(), "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(time.c_str(), "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() { + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t &build_time) { + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char *fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char *fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.h new file mode 100644 index 00000000..31646165 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String, const String, bool local_time, int tz); +String getLocaltime(); +String getLocaltime(const time_t &build_time); +String getLocaltime(const char *fmt, bool local_time, int); +String getLocaltime(const time_t build_time, const char *fmt, bool local_time, int tz); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/alarmtab.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/alarmtab.txt new file mode 100644 index 00000000..934a3bbe --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/alarmtab.txt @@ -0,0 +1,23 @@ +#┌──────────── alarm type: AR == AlarmRepeat, AO == AlarmOnce, +#| TR == TimerRepeat, TO == TimerOnce, +#| RO == TriggerOnce +#| See TimeAlarms (https://github.com/PaulStoffregen/TimeAlarms) for specs +#| ┌────────── day of week: 0 == None, 1 == Sun, ..., 7 == Sat +#| | ┌─────── hour +#| | | ┌──── minute +#| | | | ┌─ second +#| | | | | +#| | | | | +AR 0 15 55 0 OpenLatchingValve +AR 0 15 55 30 CloseLatchingValve +AR 0 15 56 0 OpenLatchingValve +AR 0 15 56 30 CloseLatchingValve +AR 0 15 57 0 OpenSolenoidValve +AR 0 15 57 30 CloseSolenoidValve +AR 0 15 58 0 OpenSolenoidValve +AR 0 15 58 30 CloseSolenoidValve +TR 0 0 0 300 SaveData +TR 0 0 0 60 DisplayClock +TR 0 0 0 30 BlinkLed +TO 0 0 0 10 HelloWorld +RO 0 0 0 1603895279 HiThere \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.cpp new file mode 100644 index 00000000..388a0475 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.cpp @@ -0,0 +1,81 @@ +#include "AlarmTasks.h" + +/** +* Parse a task line from the alarmtab.txt file +* +* Lines must follow the following structure. +* +* The name of the command to execute must match an entry +* in the 'commandMap' map defined in the CustomTasks.h file. +* +* In case of TR, TO and RO alarm types, the day of week, hour +* and minute parameters are ignored. +* In case of RO alarm type, the second parameters must bean UNIX +* specified as UNIX timestamp (seconds since EPOCH). +* +* See the TimeAlarms (https://github.com/PaulStoffregen/TimeAlarms) +* docs for further specs. +* +* Lines starting with pound symbol (#) are ignored. +* +* +* ┌──────────── alarm type: AR == AlarmRepeat, AO == AlarmOnce, +* | TR == TimerRepeat, TO == TimerOnne, +* | RO == TriggerOnce +* | ┌────────── day of week: 0 == None, 1 == Sun, ..., 7 == Sat +* | | ┌─────── hour +* | | | ┌──── minute +* | | | | ┌─ second +* | | | | | +* | | | | | +* AR 0 18 45 0 OpenLatchingValve +* AR 0 18 45 30 CloseLatchingValve +* AR 0 18 46 0 OpenLatchingValve +* AR 0 18 46 30 CloseLatchingValve +* TR 0 0 0 20 DisplayClock +* TR 0 0 0 10 BlinkLed +* TO 0 0 0 10 DisplayClockOnce +* RO 0 0 0 1602759860 DisplayClockTrigger +* +*/ +AlarmTask parseAlarmTask(const String line) { + auto const len{ line.length() + 1 }; + char buf[len]{ 0 }; + char cmd[32]{ 0 }; + char method[3]{ 0 }; + + AlarmTask task; + + line.toCharArray(buf, len); + auto n = sscanf(buf, "%s %d %d %d %d %s", method, &task.day, &task.hour, &task.min, &task.sec, cmd); + if (n != 6) + return task; + + auto itm = alarmMethods.find(method); + if (itm != alarmMethods.end()) + task.method = itm->second; + + auto itc = commandMap.find(cmd); + if (itc != commandMap.end()) + task.handler = itc->second; + + return task; +} + +/** + * Parse the alarmtab.txt file + */ +std::list parseAlarmTab(File& file) { + std::list taskList; + + while (file.available()) { + auto line = file.readStringUntil('\n'); + if (line.charAt(0) == '#') + continue; + auto task = parseAlarmTask(line); + if (task.handler != nullptr && task.method != METHOD_INVALID) + taskList.push_back(task); + } + + return taskList; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.h new file mode 100644 index 00000000..47a02199 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + +#include "CustomTasks.h" + +/** + * Supported alarm types + */ +enum AlarmMethod { + METHOD_INVALID, + ALARM_REPEAT, + ALARM_ONCE, + TIMER_REPEAT, + TIMER_ONCE, + TRIGGER_ONCE, +}; + +/** + * The internal structure for managing tasks + */ +struct AlarmTask { + AlarmMethod method{ METHOD_INVALID }; + OnTick_t handler{ nullptr }; + timeDayOfWeek_t day; + int hour; + int min; + int sec; +}; + +/** + * An helper map for parsing alarm types from alarmtab lines + */ +static std::map alarmMethods{ + { "AR", ALARM_REPEAT }, + { "AO", ALARM_ONCE }, + { "TR", TIMER_REPEAT }, + { "TO", TIMER_ONCE }, + { "RO", TRIGGER_ONCE }, +}; + +/** + * Parse a task line from the alarmtab.txt file + */ +AlarmTask parseAlarmTask(const String line); + +/** + * Parse the alarmtab.txt file + */ +std::list parseAlarmTab(File& file); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.cpp new file mode 100644 index 00000000..4919bdd5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.cpp @@ -0,0 +1,158 @@ +#include "CustomTasks.h" + +void openLatchingValve() { + Serial.println("Alarm: Opening Latching Valve"); + + LCD.home(); + LCD.backlight(); + LCD.print(getLocaltime()); + LCD.setCursor(0, 1); + LCD.print("Opening Valve "); + + // Polarize the opening pin of the 3-wires valve + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(5000); + + LCD.setCursor(0, 1); + LCD.print("Valve Open "); + + // Power off the backlight after 5 seconds + Alarm.timerOnce(5, [] { + backlightOff(false); + }); +} + +void closeLatchingValve() { + Serial.println("Alarm: Closing Latching Valve"); + + LCD.home(); + LCD.backlight(); + LCD.print(getLocaltime()); + LCD.setCursor(0, 1); + LCD.print("Closing Valve "); + + // Polarize the closing pin of the 3-wires valve + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(5000); + + LCD.setCursor(0, 1); + LCD.print("Valve Closed "); + + // Power off the backlight after 5 seconds + // and power off everything else + Alarm.timerOnce(5, [] { + backlightOff(true); + }); +} + +void openSolenoidValve() { + Serial.println("Alarm: Opening Solenoid Valve"); + + LCD.home(); + LCD.backlight(); + LCD.print(getLocaltime()); + LCD.setCursor(0, 1); + LCD.print("Opening Valve "); + + // Open the Solid State Relay on Channel 1 + Relay.on(RELAY_CH01); + + LCD.setCursor(0, 1); + LCD.print("Valve Open "); + + // Power off the backlight after 5 seconds + Alarm.timerOnce(5, [] { + backlightOff(false); + }); +} + +void closeSolenoidValve() { + Serial.println("Alarm: Closing Solenoid Valve"); + + LCD.home(); + LCD.backlight(); + LCD.print(getLocaltime()); + LCD.setCursor(0, 1); + LCD.print("Closing Valve "); + + // Close the Solid State Relay on Channel 1 + Relay.off(RELAY_CH01); + + LCD.setCursor(0, 1); + LCD.print("Valve Closed "); + + // Power off the backlight after 5 seconds + // and power off everything else + Alarm.timerOnce(5, [] { + backlightOff(true); + }); +} + +void displayClock() { + String date = getLocaltime("%Y-%m-%d", true, 0); + String time = getLocaltime("%k:%M:%S", true, 0); + displayMsg(date, 0, 0, true, false); + displayMsg(time, 5000, 1, false, true); +} + +void blinkLed() { + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, LOW); + delay(10); + + // Power off the on-board LED (active low) + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, HIGH); +} + +void getSensors() { + extern std::list dataPoints; + + String msg = "Moisture: "; + Serial.print(msg); + + auto value = getAverageInputRead(INPUT_05V_CH01); + auto perc = getMoisturePerc(INPUT_05V_CH01); + + DataPoint d{ value, perc }; + + Serial.println(d); + dataPoints.push_back(d); + + Alarm.timerOnce(5, [] { + backlightOff(true); + }); +} + +void saveData() { + String msg = "Saving Data"; + Serial.println(msg); + LCD.clear(); + LCD.backlight(); + LCD.home(); + LCD.print(msg); + for (auto rem = 16 - msg.length(); rem > 0; rem--) + LCD.write(' '); + + LCD.home(); + LCD.setCursor(0, 1); + auto ret = saveSensorsData(); + if (ret <= 0) + LCD.print("ERROR:"); + else + LCD.print("Saved:"); + + LCD.print(ret); + + Alarm.timerOnce(5, [] { + backlightOff(true); + }); +} + +void helloWorld() { + displayMsg("Hello, World!"); +} + +void hiThere() { + displayMsg("Hi, There!"); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.h new file mode 100644 index 00000000..43dd2389 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +#include "Helpers.h" +#include "SensorsData.h" +#include "TimeHelpers.h" + +void openLatchingValve(); +void closeLatchingValve(); +void openSolenoidValve(); +void closeSolenoidValve(); +void displayClock(); +void blinkLed(); +void saveData(); +void helloWorld(); +void hiThere(); +void getSensors(); + +/** + * Define your task function and add it to the commandMap. + * The key of the map is the name to be used in the alarmtab file. + */ +static std::map commandMap{ + { "OpenLatchingValve", openLatchingValve }, + { "CloseLatchingValve", closeLatchingValve }, + { "OpenSolenoidValve", openSolenoidValve }, + { "CloseSolenoidValve", closeSolenoidValve }, + { "DisplayClock", displayClock }, + { "BlinkLed", blinkLed }, + { "SaveData", saveData }, + { "HelloWorld", helloWorld }, + { "HiThere", hiThere }, + { "GetSensors", getSensors }, +}; \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.cpp new file mode 100644 index 00000000..7c65bb02 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.cpp @@ -0,0 +1,175 @@ +#include "Helpers.h" + +/** + * Set system and TimeAlarm clock from compile datetime or RTC + */ +void setSystemClock(String buildDate, String buildTime) { + // Retrieve clock time from compile date... + auto buildDateTime = buildDateTimeToSystemTime(buildDate, buildTime, true, 2); + // ... ore use the one from integrated RTC. + auto rtcTime = time(NULL); + + // Remember to connect at least the CR2032 battery + // to keep the RTC running. + auto actualTime = rtcTime > buildDateTime ? rtcTime : buildDateTime; + + // Set both system time and the alarms one + set_time(actualTime); + setTime(actualTime); + + Serial.print("Compile Date and Time: "); + Serial.println(getLocaltime(buildDateTime)); + Serial.print("RTC Date and Time: "); + Serial.println(getLocaltime(rtcTime)); + Serial.print("System Clock: "); + Serial.println(getLocaltime()); +} + +void statusLCD() { + // Small helper for waiting without delay() + auto wait = [](size_t timeout) { + for (auto go = millis() + timeout; millis() < go; yield()) + ; + }; + + String msg; + + LCD.clear(); + LCD.backlight(); + + LCD.home(); + LCD.print("Measures..."); + + wait(500); + + LCD.setCursor(16, 0); + msg = "Moisture ["; + msg += dataPoints.size(); + msg += "]"; + LCD.print(msg); + LCD.autoscroll(); + LCD.setCursor(16, 1); + msg = "Latest: "; + auto d = dataPoints.back(); + msg += d.moistureP; + msg += "%"; + + while (msg.length() < 16) + msg += ' '; + + LCD.print(msg); + LCD.noAutoscroll(); + wait(1000); + + LCD.clear(); + LCD.home(); + LCD.print("Loaded Tasks..."); + + wait(500); + + LCD.setCursor(16, 0); + msg = "Custom: "; + msg += alarmTabIDs.size(); + LCD.print(msg); + LCD.autoscroll(); + LCD.setCursor(16, 1); + msg = "Sketch: "; + msg += alarmSketchIDs.size(); + + while (msg.length() < 16) + msg += ' '; + + LCD.print(msg); + LCD.noAutoscroll(); + wait(1000); + + // Power off the backlight after 5 seconds + // and power off everything else + Alarm.timerOnce(5, [] { + backlightOff(true); + }); +} + +void backlightOff(bool powerDown) { + LCD.noBacklight(); + if (powerDown) + LCD.clear(); +} + +float getAverage05VRead(int pin) { + constexpr size_t loops{ 10 }; + constexpr float toV{ 3.3f / float{ (1 << ADC_RESOLUTION) - 1 } }; + + // Resistor divider on Input ports + constexpr float rDiv{ 17.4f / (10.0f + 17.4f) }; + + int tot{ 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return avg / rDiv; +} + +uint16_t getAverageInputRead(int pin, const size_t loops) { + unsigned int tot{ 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + return tot / loops; +} + +uint8_t getMoisturePerc(int pin) { + // Keep track ok dry/wet values. YMMV. + static long dryValue{ 2160 }; + static long wetValue{ 975 }; + + auto val = getAverageInputRead(pin); + + // Self-update dry/wet values range. + if (val > dryValue) + dryValue = val; + if (val < wetValue) + wetValue = val; + + auto perc = map(val, dryValue, wetValue, 0, 100); + + return perc; +} + +void displayMsg(const String msg, const unsigned timeout, const unsigned line, const bool clear, const bool off) { + if (clear) + LCD.clear(); + + LCD.home(); + LCD.backlight(); + + if (line == 1) + LCD.setCursor(0, 1); + + if (msg.length() > 16) + LCD.autoscroll(); + + LCD.print(msg); + + for (auto go = millis() + timeout; millis() < go; yield()) + ; + + LCD.noAutoscroll(); + + if (off) { + LCD.clear(); + LCD.noBacklight(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.h new file mode 100644 index 00000000..ac811a6a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.h @@ -0,0 +1,23 @@ +#pragma once + +#include "SensorsData.h" +#include "TimeHelpers.h" +#include +#include +#include +#include + +#include +#include + +void setSystemClock(String date = __DATE__, String time = __TIME__); +void statusLCD(); +void backlightOff(bool powerDown); +uint16_t getAverageInputRead(int pin, size_t loops = 20); +float getAverage05VRead(int pin); +uint8_t getMoisturePerc(int pin); +void displayMsg(const String msg, const unsigned timeout = 5000, const unsigned line = 0, const bool clear = true, const bool off = true); + +extern std::list alarmTabIDs; +extern std::list alarmSketchIDs; +extern std::list dataPoints; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/IrrigationSimpleLCD.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/IrrigationSimpleLCD.ino new file mode 100644 index 00000000..2d8c4a15 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/IrrigationSimpleLCD.ino @@ -0,0 +1,177 @@ +/** + * Simple irrigation system with Arduino EdgeControl + * + * Circuit: + * - Arduino EdgeControl + * - MicroSD card + * - CR2032 Battery and/or 12V Lead Battery + * + * Usage: + * - Define your callback functions in CustomTasks.{h,cpp} + * - Map the callback functions to alarmatab command names in + * CustomTasks.h::commandMap map. + * - Add tasks to the alarmtab.txt file and copy it on the SD card; + * See alarmtab.txt and AlarmTasks.cpp for documentation. + */ + +#include + +#include "AlarmTasks.h" +#include "SensorsData.h" +#include "TimeHelpers.h" +#include "TasksHelpers.h" +#include "Helpers.h" + +/** UI Management **/ +// Button statuses +enum ButtonStatus : byte { + ZERO_TAP, + SINGLE_TAP, + DOUBLE_TAP, + TRIPLE_TAP, + LOT_OF_TAPS +}; + +// ISR: count the button taps +volatile byte taps{ 0 }; +// ISR: keep elapsed timings +volatile unsigned long previousPress{ 0 }; +// ISR: Final button status +volatile ButtonStatus buttonStatus{ ZERO_TAP }; + +/** + * Used to keep track of the running alarms from + * alarmtab.txt. + * + * The loadAndSetTasks() function will fill this + * with tasks defined in CustomTasks.{h.cpp} and + * loaded from the alarmtab.txt on the SD. + * + */ +std::list alarmTabIDs; + +/** + * Used to keep track of the alarms defined in the + * sketch. + */ +std::list alarmSketchIDs; + +/** + * Used to keep track of the measurements points + */ +std::list dataPoints; + +void setup() { + Serial.begin(9600); + constexpr unsigned long timeout{ 2500 }; + + // Wait for Serial Monitor for timeout ms + auto startNow = millis() + timeout; + while (!Serial && millis() < startNow) + ; + + delay(1000); + + // Set System and Alarm clock + // Use compile datetime as proxy clock synch + // Use a CR2032 battery for persistent RTC. + setSystemClock(); + + // Init board-related objects + EdgeControl.begin(); + + // Enable the 3V3 and 12V power rails. + // Needed for IO Expander and SD card. + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + // Init the sensors inputs. + // If needed, will also take care of enabling the + // 3V3 and 12V power rails and to initialize the IO Expander. + Input.begin(); + + Latching.begin(); + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(5000); + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(5000); + + Relay.begin(); + delay(1000); + Relay.on(RELAY_CH01); + delay(5000); + Relay.off(RELAY_CH01); + + // Init the LCD display + LCD.begin(16, 2); + LCD.leftToRight(); + + // Load alarm tasks list from file on SD. + // See example alarmtab.txt for example and + // AlarmTasks.{h, cpp} source files for documentation. + loadAndSetTasks(alarmTabIDs); + + // Use the LCD button for housekeeping stuff: + // Single Tap: Show status + // Double Tap: Reload alarm tasks from SD + // Triple Tap: Force saving data to SD + pinMode(POWER_ON, INPUT); + attachInterrupt(POWER_ON, buttonPress, RISING); + + auto id = Alarm.timerRepeat(10, getSensors); + alarmSketchIDs.push_back(id); +} + +void loop() { + // Do alarms processing + Alarm.delay(10); + + // Detect Single Tap, Double Tap, etc. + // to buttonStatus + detectTaps(); + + switch (buttonStatus) { + case ZERO_TAP: + break; + case SINGLE_TAP: + Serial.println("Single Tap"); + statusLCD(); + buttonStatus = ZERO_TAP; + break; + case DOUBLE_TAP: + Serial.println("Double Tap"); + loadAndSetTasks(alarmTabIDs, true); + buttonStatus = ZERO_TAP; + break; + case TRIPLE_TAP: + Serial.println("Triple Tap"); + saveData(); + buttonStatus = ZERO_TAP; + break; + default: + Serial.println("Too Many Taps"); + buttonStatus = ZERO_TAP; + break; + } +} + +void buttonPress() { + const auto now = millis(); + // Poor-man debouncing + if (now - previousPress > 100) + taps++; + + previousPress = now; +} + +void detectTaps() { + // Timeout to validate the button taps counter + constexpr unsigned int buttonTapsTimeout{ 300 }; + + // Set the button status and reset the taps counter when button has been + // pressed at least once and button taps validation timeout has been reached. + if (taps > 0 && millis() - previousPress >= buttonTapsTimeout) { + buttonStatus = static_cast(taps); + taps = 0; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.cpp new file mode 100644 index 00000000..beeb8719 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.cpp @@ -0,0 +1,43 @@ +#include "SensorsData.h" + +DataPoint::DataPoint(uint16_t moistureA, uint8_t moistureP) + : ts(time(nullptr)), moistureA(moistureA), moistureP(moistureP) { +} + +size_t DataPoint::printTo(Print& p) const { + size_t written{ 0 }; + + written += p.print((unsigned long)ts); + written += p.print(','); + written += p.print(moistureA); + written += p.print(','); + written += p.print(moistureP); + + return written; +} + +int saveSensorsData() { + extern std::list dataPoints; + + unsigned int count{ 0 }; + + if (!SD.begin(PIN_SD_CS)) + return -2; + + auto dataLog = SD.open("datalog.csv", FILE_WRITE); + if (!dataLog) + return -1; + + for (auto d = dataPoints.begin(); d != dataPoints.end(); ++d) { + auto bytes = dataLog.println(*d); + if (bytes == 0) // if write failed, don't erase + continue; + count++; + dataPoints.erase(d); + } + + dataLog.close(); + SD.end(); + + return count; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.h new file mode 100644 index 00000000..f4b4451d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.h @@ -0,0 +1,17 @@ +#pragma once + +#include +#include +#include + +struct DataPoint : Printable { + time_t ts; + uint16_t moistureA; + uint8_t moistureP; + + DataPoint(uint16_t moistureA, uint8_t moistureP); + + virtual size_t printTo(Print& p) const; +}; + +int saveSensorsData(); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.cpp new file mode 100644 index 00000000..8fdea31a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.cpp @@ -0,0 +1,151 @@ +#include "TasksHelpers.h" + +/** + * Load alarm task from parsed alarmtab.txt file on SD. + */ +std::list loadTasks() { + if (!SD.begin(PIN_SD_CS)) { + Serial.println("SD initialization failed"); + while (true) + ; + } + auto alarmtab = SD.open("alarmtab.txt"); + auto taskList = parseAlarmTab(alarmtab); + + alarmtab.close(); + SD.end(); + + return taskList; +} + +/** + * Set the alarm tasks from the loaded list. + */ +std::list setTasks(std::list taskList) { + AlarmID_t alarmID{ dtINVALID_ALARM_ID }; + std::list alarmIDs; + + for (auto& task : taskList) { + switch (task.method) { + case ALARM_REPEAT: + { + if (task.day == 0) + alarmID = Alarm.alarmRepeat(task.hour, task.min, task.sec, task.handler); + else + alarmID = Alarm.alarmRepeat(task.day, task.hour, task.min, task.sec, task.handler); + break; + } + case ALARM_ONCE: + { + if (task.day == 0) + alarmID = Alarm.alarmOnce(task.hour, task.min, task.sec, task.handler); + else + alarmID = Alarm.alarmOnce(task.day, task.hour, task.min, task.sec, task.handler); + break; + } + case TIMER_REPEAT: + { + alarmID = Alarm.timerRepeat(task.sec, task.handler); + break; + } + case TIMER_ONCE: + { + alarmID = Alarm.timerOnce(task.sec, task.handler); + break; + } + case TRIGGER_ONCE: + { + alarmID = Alarm.triggerOnce(task.sec, task.handler); + break; + } + default: + break; + } + alarmIDs.push_back(alarmID); + } + + return alarmIDs; +} + +/** + * Free the current alarm tasks + */ +void freeTasks(std::list& alarmIDs) { + for (auto& id : alarmIDs) { + Alarm.free(id); + id = dtINVALID_ALARM_ID; + } +} + +/** + * Load and set tasks from alarmtab.txt file. + * + * Remove previously loaded tasks if parameter is true. + */ +void loadAndSetTasks(std::list& alarmIDs, bool reload) { + LCD.clear(); + LCD.backlight(); + + LCD.setCursor(0, 0); + if (reload) { + Serial.println("Reloading Tasks: "); + LCD.print("Reloading Tasks:"); + freeTasks(alarmIDs); + } else { + Serial.println("Loading Tasks: "); + LCD.print("Loading Tasks:"); + } + + auto taskList = loadTasks(); + alarmIDs = setTasks(taskList); + printTasks(taskList); + + LCD.setCursor(0, 1); + LCD.print(alarmIDs.size()); + LCD.print(" loaded"); + + // Power off the backlight after 5 seconds + // and power off everything else + Alarm.timerOnce(5, [] { + backlightOff(true); + }); +} + +void printTasks(const std::list taskList) { + for (auto const task : taskList) { + Serial.print("- "); + switch (task.method) { + case ALARM_REPEAT: + Serial.print("ALARM_REPEAT"); + break; + case ALARM_ONCE: + Serial.print("ALARM_ONCE"); + break; + case TIMER_REPEAT: + Serial.print("TIMER_REPEAT"); + break; + case TIMER_ONCE: + Serial.print("TIMER_ONCE"); + break; + case TRIGGER_ONCE: + Serial.print("TRIGGER_ONCE"); + break; + default: + Serial.print("UNKNOWN"); + break; + } + Serial.print(" "); + Serial.print(task.day); + Serial.print(" "); + Serial.print(task.hour); + Serial.print(" "); + Serial.print(task.min); + Serial.print(" "); + Serial.print(task.sec); + Serial.print(" "); + Serial.println((uint64_t)(task.handler), HEX); + } + + Serial.print(taskList.size()); + Serial.println(" tasks loaded."); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.h new file mode 100644 index 00000000..3185e7c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.h @@ -0,0 +1,13 @@ +#pragma once + +#include +#include +#include + +#include "AlarmTasks.h" + +std::list loadTasks(); +std::list setTasks(std::list taskList); +void freeTasks(std::list& alarmIDs); +void loadAndSetTasks(std::list& alarmIDs, bool reload = false); +void printTasks(const std::list taskList); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.cpp new file mode 100644 index 00000000..0dff616e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.cpp @@ -0,0 +1,84 @@ +#include "TimeHelpers.h" + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String date, const String time, bool local_time = true, int tz = 0) { + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + sscanf(date.c_str(), "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(time.c_str(), "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() { + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t &build_time) { + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char *fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char *fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.h new file mode 100644 index 00000000..31646165 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String, const String, bool local_time, int tz); +String getLocaltime(); +String getLocaltime(const time_t &build_time); +String getLocaltime(const char *fmt, bool local_time, int); +String getLocaltime(const time_t build_time, const char *fmt, bool local_time, int tz); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/alarmtab.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/alarmtab.txt new file mode 100644 index 00000000..934a3bbe --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/alarmtab.txt @@ -0,0 +1,23 @@ +#┌──────────── alarm type: AR == AlarmRepeat, AO == AlarmOnce, +#| TR == TimerRepeat, TO == TimerOnce, +#| RO == TriggerOnce +#| See TimeAlarms (https://github.com/PaulStoffregen/TimeAlarms) for specs +#| ┌────────── day of week: 0 == None, 1 == Sun, ..., 7 == Sat +#| | ┌─────── hour +#| | | ┌──── minute +#| | | | ┌─ second +#| | | | | +#| | | | | +AR 0 15 55 0 OpenLatchingValve +AR 0 15 55 30 CloseLatchingValve +AR 0 15 56 0 OpenLatchingValve +AR 0 15 56 30 CloseLatchingValve +AR 0 15 57 0 OpenSolenoidValve +AR 0 15 57 30 CloseSolenoidValve +AR 0 15 58 0 OpenSolenoidValve +AR 0 15 58 30 CloseSolenoidValve +TR 0 0 0 300 SaveData +TR 0 0 0 60 DisplayClock +TR 0 0 0 30 BlinkLed +TO 0 0 0 10 HelloWorld +RO 0 0 0 1603895279 HiThere \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/DebugMode.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/DebugMode.h new file mode 100644 index 00000000..fb328f40 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/DebugMode.h @@ -0,0 +1,10 @@ +#pragma once + +#ifdef DEBUG +constexpr bool debugMode = true; +#else +constexpr bool debugMode = false; +#endif + +#define DebugSerial \ + if constexpr (debugMode) Serial \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/Helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/Helpers.h new file mode 100644 index 00000000..ee7dbfe0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/Helpers.h @@ -0,0 +1,124 @@ +#pragma once + +#include +#include + +#include "DebugMode.h" + +rtos::Mutex pwrMutex; + +void powerOn() { + DebugSerial.print("Powering On"); + auto locked = pwrMutex.trylock(); + if (!locked) { + DebugSerial.println(": Already Powered On!"); + return; + } + DebugSerial.println(); + + Power.on(PWR_VBAT); + Power.on(PWR_3V3); + Wire.begin(); + delay(500); + Expander.begin(); + Input.begin(); +} + +void powerOff() { + DebugSerial.print("Powering Off"); + auto owner = rtos::ThisThread::get_id() == pwrMutex.get_owner(); + if (!owner) { + DebugSerial.println(": Someone still needs power!"); + return; + } + DebugSerial.println(); + + Input.end(); + Expander.end(); + Wire.end(); + Power.off(PWR_3V3); + Power.off(PWR_VBAT); + pwrMutex.unlock(); +} + +int getAverageInputRead(int pin, const size_t loops) { + unsigned int tot{ 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + return tot / loops; +} + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String date, const String time, bool local_time = true, int tz = 0) { + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + sscanf(date.c_str(), "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(time.c_str(), "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() { + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) { + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +/** + * Set system clock from compile datetime or RTC + */ +void setSystemClock(String buildDate, String buildTime) { + // Retrieve clock time from compile date... + auto buildDateTime = buildDateTimeToSystemTime(buildDate, buildTime, true, 2); + // ... ore use the one from integrated RTC. + auto rtcTime = time(NULL); + + // Remember to connect at least the CR2032 battery + // to keep the RTC running. + auto actualTime = rtcTime > buildDateTime ? rtcTime : buildDateTime; + + // Set both system time + set_time(actualTime); + + DebugSerial.print("Compile Date and Time: "); + DebugSerial.println(getLocaltime(buildDateTime)); + DebugSerial.print("RTC Date and Time: "); + DebugSerial.println(getLocaltime(rtcTime)); + DebugSerial.print("System Clock: "); + DebugSerial.println(getLocaltime()); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/LowPowerDataLogger.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/LowPowerDataLogger.ino new file mode 100644 index 00000000..dd59b361 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/LowPowerDataLogger.ino @@ -0,0 +1,429 @@ +/* + A Low Power Data Logger for the Arduino Edge Control + + This example demonstrates how to use a few advanced features of the MbedOS + APIs to build a low power data logger. + + The sketch periodically reads data from one of the analog INPUTS and stores + it on the SPIF memory using a KeyValue datastore. When the user press a + button connected to the POWER_ON, the data is moved from the SPIF to a + FAT-formatted SD Card. + + Features: + * Low Power Ticker for managing recurring task + https://os.mbed.com/docs/mbed-os/v6.7/apis/lowpowerticker.html + * EventQueue for managing scheduled tasks in IRQ-friendly contexts + https://os.mbed.com/docs/mbed-os/v6.7/apis/eventqueue.html + * Mutex for coordinating R/W access to SPIF and Power management + https://os.mbed.com/docs/mbed-os/v6.7/apis/mutex.html + * TDBStore for keyvalue datastore + https://os.mbed.com/docs/mbed-os/v6.7/apis/kvstore.html + + Requirements: + * Arduino Edge Control + * SD Card + * Momentary button + + Circuit: + * Insert the SD Card + * Connect the button pins to GND and POWER_ON on the LCD header + * Connect a 12V Power Supply to GND/S pins + + + Created by Giampaolo Mancini +*/ +#include +#include +#include +#include +#include +#include +#include + +/* + To enable debugging print on Serial Monitor define DEBUG on "DebugMode.h" or + compile the sketch with the CLI using the '--build-property' parameter, eg. + + arduino-cli compile -b arduino:mbed:edge_control --build-property 'compiler.cpp.extra_flags="-DDEBUG=1"' +*/ +#include "DebugMode.h" +#include "Helpers.h" + +using namespace mbed; +using namespace events; +using namespace rtos; +using namespace std::chrono_literals; + +// Low Power Tickers for timed actions +LowPowerTicker meter; +LowPowerTicker printer; + +// Event queue for managing IRQ-Unsafe tasks +EventQueue queue(32 * EVENTS_EVENT_SIZE); +Thread t; + +// Serial Flash management +constexpr uint32_t SPIF_FREQ{ 32000000 }; +SPIFBlockDevice bd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_SS, SPIF_FREQ); +TDBStore tdb_store(&bd); + +// Use a Mutex to coordinate reads and writes to SPIF storage +Mutex spifMutex; + +/** UI Management **/ +// Button statuses +enum ButtonStatus : byte { + ZERO_TAP, + SINGLE_TAP, + DOUBLE_TAP, + LOT_OF_TAPS +}; + +// ISR: count the button taps +volatile byte taps{ 0 }; +// ISR: keep elapsed timings +volatile unsigned long previousPress{ 0 }; +// ISR: Final button status +volatile ButtonStatus buttonStatus{ ZERO_TAP }; + +// Struct for data storage +struct Data { + time_t ts; + uint32_t moist; +}; + +void setup() { + if constexpr (debugMode) { + Serial.begin(115200); + const uint32_t startNow{ millis() + 2500 }; + while (!Serial && millis() < startNow) + ; + delay(500); + } + + EdgeControl.begin(); + + // Init system clock from compilation time + setSystemClock(__DATE__, __TIME__); + + Power.on(PWR_3V3); + + pinMode(POWER_ON, INPUT); + attachInterrupt(POWER_ON, buttonPress, RISING); + + // Init the Key/Value Store + DebugSerial.println("Init TinyDB Key Value store"); + auto err = tdb_store.init(); + DebugSerial.println("TDB Init " + String(err == 0 ? "OK" : "KO") + " (" + String(err) + ")"); + + // Initialize the SD Card and the FAT filesystem function-wide + // to manage SD Card extraction and insertion at run-time + SDBlockDevice sd(SD_MOSI, SD_MISO, SD_CLK, SD_CS); + FATFileSystem fat("fat"); + DebugSerial.print("Checking the SD Card"); + auto ret = fat.mount(&sd); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": Error"); + DebugSerial.println("Please, check your SD Card."); + while (true) + ; + } + DebugSerial.println(": Ok"); + fat.unmount(); + + // Start the Event Queue manager + t.start(callback(&queue, &EventQueue::dispatch_forever)); + + // Init the stats printer and metering tasks + printer.attach(printStatsISR, 30s); + meter.attach(readSensorsISR, 10s); +} + +void loop() { + // Use loop() just to manage UI + + detectTaps(); + + switch (buttonStatus) { + case ZERO_TAP: + { + break; + } + case SINGLE_TAP: + { + DebugSerial.println("Single Tap"); + printStats(); + buttonStatus = ZERO_TAP; + break; + } + case DOUBLE_TAP: + { + DebugSerial.println("Double Tap"); + storeData(); + buttonStatus = ZERO_TAP; + break; + } + default: + { + DebugSerial.println("Too Many Taps"); + buttonStatus = ZERO_TAP; + break; + } + } + + // Schedule for low-power operations. + delay(100); +} + +void buttonPress() { + const auto now = millis(); + // Poor-man debouncing + if (now - previousPress > 100) + taps++; + + previousPress = now; +} + +void detectTaps() { + // Timeout to validate the button taps counter + constexpr unsigned int buttonTapsTimeout{ 300 }; + + // Set the button status and reset the taps counter when button has been + // pressed at least once and button taps validation timeout has been reached. + if (taps > 0 && millis() - previousPress >= buttonTapsTimeout) { + buttonStatus = static_cast(taps); + taps = 0; + } +} + +void printStatsISR() { + // Do something IRQ-safe here... + // irqSafeCall(); + + // ... and distpatch IRQ-unsafe execution to Event Queue + queue.call(printStats); +} + +// Print current stored measures +void printStats() { + powerOn(); + + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, LOW); + delay(100); + Expander.digitalWrite(EXP_LED1, HIGH); + delay(100); + Expander.digitalWrite(EXP_LED1, LOW); + delay(100); + Expander.digitalWrite(EXP_LED1, HIGH); + + // If not in debug mode just blink the LED and exit + if constexpr (!debugMode) + return; + DebugSerial.begin(115200); + + spifMutex.lock(); + + // Use a TDBStore iterator to retrieve all the keys + TDBStore::iterator_t it; + TDBStore::info_t info; + // Iterate over all the keys starting with name "key_" + auto ret = tdb_store.iterator_open(&it, "key_"); + if (ret != MBED_SUCCESS) { + DebugSerial.println("Error opening the iterator"); + spifMutex.unlock(); + return; + } + + char key[128]{ 0 }; + unsigned int counter{ 0 }; + while (tdb_store.iterator_next(it, key, sizeof(key)) != MBED_ERROR_ITEM_NOT_FOUND) { + // Get info about the key and its contents + tdb_store.get_info(key, &info); + + String msg = "Key: "; + msg += String(key, 16); + msg += " - Size: "; + msg += info.size; + msg += " - "; + DebugSerial.print(msg); + + // Get the value using parameters from the info retrieved + Data out; + size_t actual_size; + tdb_store.get(key, &out, info.size, &actual_size); + + // Do something useful with the key-value pair... + msg = "Value ("; + msg += actual_size; + msg += ") - { ts: "; + msg += static_cast(out.ts); + msg += ", moist: "; + msg += out.moist; + msg += " }"; + DebugSerial.print(msg); + DebugSerial.println(); + counter++; + } + DebugSerial.print(counter); + DebugSerial.println(" keys stored"); + // Close the iterator at the end of the cycle + tdb_store.iterator_close(it); + spifMutex.unlock(); + + DebugSerial.end(); + powerOff(); +} + +void readSensorsISR() { + // Do something IRQ-safe here... + // irqSafeCall(); + + // ... and distpatch IRQ-unsafe execution to Event Queue + queue.call(readSensors); +} + + +// Read measures from sensors and store on SPIF +void readSensors() { + powerOn(); + + DebugSerial.begin(115200); + DebugSerial.println("Reading Sensors"); + + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, LOW); + delay(50); + Expander.digitalWrite(EXP_LED1, HIGH); + + auto value = getAverageInputRead(INPUT_05V_CH01, 10); + + String key = "key_"; + auto ts = time(nullptr); + key += static_cast(ts); + + Data data{ ts, value }; + spifMutex.lock(); + auto res = tdb_store.set(key.c_str(), reinterpret_cast(&data), sizeof(data), 0); + spifMutex.unlock(); + if (res == MBED_SUCCESS) + DebugSerial.println(key + ": " + String(value)); + + DebugSerial.end(); + + powerOff(); +} + +// Move data from SPIF to SD +void storeData() { + powerOn(); + + DebugSerial.begin(115200); + DebugSerial.println("Saving Data on SD Card"); + + Expander.pinMode(EXP_LED1, OUTPUT); + + SDBlockDevice sd(SD_MOSI, SD_MISO, SD_CLK, SD_CS); + FATFileSystem fat("fat"); + DebugSerial.print("Mounting the SD Card"); + auto ret = fat.mount(&sd); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": Error"); + return; + } + DebugSerial.println(": Ok"); + + DebugSerial.print("Opening the log file"); + auto f = fopen("/fat/datalog.csv", "a+"); + if (f == nullptr) { + DebugSerial.println(": Error"); + return; + } + DebugSerial.println(": Ok"); + + spifMutex.lock(); + TDBStore::iterator_t it; + ret = tdb_store.iterator_open(&it, "key_"); + if (ret != MBED_SUCCESS) { + DebugSerial.println("Error opening the iterator"); + spifMutex.unlock(); + return; + } + + unsigned int counter{ 0 }; + TDBStore::info_t info; + char key[128]{ 0 }; + while (tdb_store.iterator_next(it, key, sizeof(key)) != MBED_ERROR_ITEM_NOT_FOUND) { + DebugSerial.print("Saving "); + DebugSerial.print(key); + + ret = tdb_store.get_info(key, &info); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": error getting the info"); + continue; + } + + Data out; + size_t actual_size; + tdb_store.get(key, &out, info.size, &actual_size); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": error getting the keyvalue"); + continue; + } + + String line; + line += static_cast(out.ts); + line += ","; + line += out.moist; + + DebugSerial.print(" ("); + DebugSerial.print(line); + DebugSerial.print(") "); + + line += "\r\n"; + ret = fputs(line.c_str(), f); + if (ret < 0) { + DebugSerial.print(": saving error: "); + DebugSerial.print(strerror(errno)); + DebugSerial.print(" "); + DebugSerial.println(-errno); + continue; + } + + ret = fflush(f); + if (ret != 0) { + DebugSerial.print(": flushing error: "); + DebugSerial.print(strerror(errno)); + DebugSerial.print(" "); + DebugSerial.println(-errno); + continue; + } + + ret = tdb_store.remove(key); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": error removing."); + } + DebugSerial.println(": removed."); + + counter++; + + Expander.digitalWrite(EXP_LED1, LOW); + delay(25); + Expander.digitalWrite(EXP_LED1, HIGH); + delay(50); + } + DebugSerial.print(counter); + DebugSerial.println(" keys found."); + + tdb_store.iterator_close(it); + spifMutex.unlock(); + fclose(f); + fat.unmount(); + DebugSerial.end(); + + Expander.digitalWrite(EXP_LED1, LOW); + delay(500); + Expander.digitalWrite(EXP_LED1, HIGH); + + powerOff(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/Helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/Helpers.h new file mode 100644 index 00000000..547a1fa7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/Helpers.h @@ -0,0 +1,75 @@ +#pragma once + +#include +#include +#include + + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String date, const String time, bool local_time = true, int tz = 0) { + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + sscanf(date.c_str(), "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(time.c_str(), "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() { + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) { + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +/** + * Set system clock from compile datetime or RTC + */ +void setSystemClock(String buildDate, String buildTime) { + // Retrieve clock time from compile date... + auto buildDateTime = buildDateTimeToSystemTime(buildDate, buildTime, true, 2); + // ... ore use the one from integrated RTC. + auto rtcTime = time(NULL); + + // Remember to connect at least the CR2032 battery + // to keep the RTC running. + auto actualTime = rtcTime > buildDateTime ? rtcTime : buildDateTime; + + // Set both system time + set_time(actualTime); + + Serial.print("Compile Date and Time: "); + Serial.println(getLocaltime(buildDateTime)); + Serial.print("RTC Date and Time: "); + Serial.println(getLocaltime(rtcTime)); + Serial.print("System Clock: "); + Serial.println(getLocaltime()); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/RTCClock.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/RTCClock.ino new file mode 100644 index 00000000..6b11fc3d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/RTCClock.ino @@ -0,0 +1,21 @@ +// #include +#include "Helpers.h" + +void setup() { + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial & millis() < startNow; delay(500)) + ; + + Serial.println("Starting RTC example"); + // EdgeControl.begin(); + + // Init system clock from compilation time or RTC + setSystemClock(__DATE__, __TIME__); + + // Power.on(PWR_3V3); +} + +void loop() { + Serial.println(getLocaltime()); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/0-5V_Input/0-5V_Input.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/0-5V_Input/0-5V_Input.ino new file mode 100644 index 00000000..7c46ccf2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/0-5V_Input/0-5V_Input.ino @@ -0,0 +1,94 @@ +/* + Testing strategy: connect each 5V ANALOG-IN input pin alternatively to +5V on the same connector. +*/ + +#include + +constexpr unsigned int adcResolution{ 12 }; + +constexpr pin_size_t inputChannels[]{ + INPUT_05V_CH01, + INPUT_05V_CH02, + INPUT_05V_CH03, + INPUT_05V_CH04, + INPUT_05V_CH05, + INPUT_05V_CH06, + INPUT_05V_CH07, + INPUT_05V_CH08 +}; +constexpr size_t inputChannelsLen{ sizeof(inputChannels) / sizeof(inputChannels[0]) }; +int inputChannelIndex{ 0 }; + +struct Voltages { + float volt3V3; + float volt5V; +}; + +void setup() { + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + Expander.begin(); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + + Input.begin(); + Input.enable(); + + analogReadResolution(adcResolution); +} + +void loop() { + Serial.print("0-5V Input Channel "); + switch (inputChannels[inputChannelIndex]) { + case INPUT_05V_CH01: Serial.print("01"); break; + case INPUT_05V_CH02: Serial.print("02"); break; + case INPUT_05V_CH03: Serial.print("03"); break; + case INPUT_05V_CH04: Serial.print("04"); break; + case INPUT_05V_CH05: Serial.print("05"); break; + case INPUT_05V_CH06: Serial.print("06"); break; + case INPUT_05V_CH07: Serial.print("07"); break; + case INPUT_05V_CH08: Serial.print("08"); break; + default: break; + } + Serial.print(": "); + + auto [voltsMuxer, voltsInput] = getAverageAnalogRead(inputChannels[inputChannelIndex]); + + Serial.print(voltsInput); + Serial.print(" ("); + Serial.print(voltsMuxer); + Serial.println(")"); + delay(1000); + + inputChannelIndex = ++inputChannelIndex % inputChannelsLen; +} + +Voltages getAverageAnalogRead(int pin) { + constexpr size_t loops{ 100 }; + constexpr float toV{ 3.3f / float{ (1 << adcResolution) - 1 } }; + constexpr float rDiv{ 17.4f / (10.0f + 17.4f) }; + + int tot{ 0 }; + + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return { avg, avg / rDiv }; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/19V/19V.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/19V/19V.ino new file mode 100644 index 00000000..2f403503 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/19V/19V.ino @@ -0,0 +1,65 @@ +#include + +constexpr unsigned int adcResolution{ 12 }; + +struct Voltages { + float volt3V3; + float volt19V; +}; + +void setup() { + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + Power.on(PWR_19V); + + Wire.begin(); + Expander.begin(); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + + Input.begin(); + Input.enable(); + + analogReadResolution(adcResolution); +} + +void loop() { + Serial.print("19V Input Channel "); + Serial.print(": "); + + auto [voltsMuxer, voltsReference] = getAverageAnalogRead(INPUT_19V_REF); + + Serial.print(voltsReference); + Serial.print(" ("); + Serial.print(voltsMuxer); + Serial.println(")"); + delay(1000); +} + +Voltages getAverageAnalogRead(int pin) { + constexpr size_t loops{ 100 }; + constexpr float toV{ 3.3f / float{ (1 << adcResolution) - 1 } }; + constexpr float rDiv{ 0.0616f }; + + int tot{ 0 }; + + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return { avg, avg / rDiv }; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/4-20mA_Input/4-20mA_Input.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/4-20mA_Input/4-20mA_Input.ino new file mode 100644 index 00000000..f6b66c25 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/4-20mA_Input/4-20mA_Input.ino @@ -0,0 +1,90 @@ +/* + Testing strategy: + - Connect a GND Pin of a 10K potentiometer to +19V reference + - Connect each 4-20mA IN pin alternatively to signal pin of potentiomer + - Range the potentiometer +*/ + +#include + +constexpr unsigned int adcResolution{ 12 }; + +constexpr pin_size_t inputChannels[]{ + INPUT_420mA_CH01, + INPUT_420mA_CH02, + INPUT_420mA_CH03, + INPUT_420mA_CH04 +}; +constexpr size_t inputChannelsLen{ sizeof(inputChannels) / sizeof(inputChannels[0]) }; +int inputChannelIndex{ 0 }; + +struct Voltages { + float volt3V3; + float voltRef; +}; + +void setup() { + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + Power.on(PWR_19V); + + Wire.begin(); + Expander.begin(); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + + Input.begin(); + Input.enable(); + + analogReadResolution(adcResolution); +} + +void loop() { + Serial.print("4-20mA Input Channel "); + switch (inputChannels[inputChannelIndex]) { + case INPUT_420mA_CH01: Serial.print("01"); break; + case INPUT_420mA_CH02: Serial.print("02"); break; + case INPUT_420mA_CH03: Serial.print("03"); break; + case INPUT_420mA_CH04: Serial.print("04"); break; + default: break; + } + Serial.print(": "); + + auto [voltsMuxer, voltsReference] = getAverageAnalogRead(inputChannels[inputChannelIndex]); + + Serial.print(voltsReference); + Serial.print(" ("); + Serial.print(voltsMuxer); + Serial.println(")"); + delay(1000); + + inputChannelIndex = ++inputChannelIndex % inputChannelsLen; +} + +Voltages getAverageAnalogRead(int pin) { + constexpr size_t loops{ 100 }; + constexpr float toV{ 3.3f / float{ (1 << adcResolution) - 1 } }; + constexpr float rDiv{ 17.4f / (10.0f + 17.4f) }; + + int tot{ 0 }; + + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return { avg, avg / rDiv }; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/BatterySolarStatus/BatterySolarStatus.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/BatterySolarStatus/BatterySolarStatus.ino new file mode 100644 index 00000000..70d60a04 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/BatterySolarStatus/BatterySolarStatus.ino @@ -0,0 +1,54 @@ +#include + +constexpr uint32_t printInterval{ 5000 }; +uint32_t printNow{ 0 }; + +void setup() { + Serial.begin(115200); + + const uint32_t startNow{ millis() + 2500 }; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Checking Power Supply and Solar Charger status"); + + EdgeControl.begin(); + Power.on(PWR_VBAT); + Power.on(PWR_3V3); + + Wire.begin(); + delay(500); + + Serial.print("I/O Expander initializazion "); + while (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + delay(500); + } + Serial.println("succeeded."); + + Expander.pinMode(EXP_FAULT_SOLAR_PANEL, INPUT); + Expander.pinMode(EXP_FAULT_5V, INPUT); + + printNow = millis(); +} + +void loop() { + if (millis() > printNow) { + auto vbat = Power.getVBat(); + Serial.print("Battery Voltage: "); + Serial.println(vbat); + + auto solarStatus = Power.getSolarChargerStatus(); + Serial.print("Solar Panel Charger Status: "); + Serial.println(solarStatus ? "OK" : "Error"); + + auto fiveVoltsStatus = Power.get5VoltStatus(); + Serial.print("5V Power Rail Status: "); + Serial.println(fiveVoltsStatus ? "OK" : "Error"); + + printNow = millis() + printInterval; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Blink/Blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Blink/Blink.ino new file mode 100644 index 00000000..c8ad1c12 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Blink/Blink.ino @@ -0,0 +1,49 @@ +/* + Blink LED1 and external LED via the IO Expander (TCA6424). + + Connect an external LED to J1 connector: + - LED anod to J1-16 + - LED cathod to J1-15 via 1K Ohm resistor + +*/ + +#include + +void setup() { + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + + delay(500); + + Serial.print("IO Expander initializazion "); + if (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + } + Serial.println("succeeded."); + + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.pinMode(EXP_LCD_D7, OUTPUT); +} + +void loop() { + Serial.println("Blink"); + Expander.digitalWrite(EXP_LED1, LOW); + Expander.digitalWrite(EXP_LCD_D7, HIGH); + delay(500); + Expander.digitalWrite(EXP_LED1, HIGH); + Expander.digitalWrite(EXP_LCD_D7, LOW); + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounter/IRQCounter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounter/IRQCounter.ino new file mode 100644 index 00000000..ea4442aa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounter/IRQCounter.ino @@ -0,0 +1,78 @@ +/* + Testing strategy: alternatively create a short-time connection between + WAKEUP 1-6 and any of the +BAT_ext pins (the row above the WAKEUP ones). + + Check IRQChannelMap for advanced C++ implementation. +*/ + +#include + +volatile int irqCounts[6]{}; + +enum IRQChannelsIndex { + irqChannel1 = 0, + irqChannel2, + irqChannel3, + irqChannel4, + irqChannel5, + irqChannel6 +}; + + +void setup() { + EdgeControl.begin(); + + Serial.begin(115200); + + // Wait for Serial Monitor or start after 2.5s + for (const auto timeout = millis() + 2500; millis() < timeout && !Serial; delay(250)) + ; + + // Init IRQ INPUT pins + for (auto pin = IRQ_CH1; pin <= IRQ_CH6; pin++) + pinMode(pin, INPUT); + + // Attach callbacks to IRQ pins + attachInterrupt( + digitalPinToInterrupt(IRQ_CH1), [] { + irqCounts[irqChannel1]++; + }, + CHANGE); + attachInterrupt( + digitalPinToInterrupt(IRQ_CH2), [] { + irqCounts[irqChannel2]++; + }, + CHANGE); + attachInterrupt( + digitalPinToInterrupt(IRQ_CH3), [] { + irqCounts[irqChannel3]++; + }, + CHANGE); + attachInterrupt( + digitalPinToInterrupt(IRQ_CH4), [] { + irqCounts[irqChannel4]++; + }, + CHANGE); + attachInterrupt( + digitalPinToInterrupt(IRQ_CH5), [] { + irqCounts[irqChannel5]++; + }, + CHANGE); + attachInterrupt( + digitalPinToInterrupt(IRQ_CH6), [] { + irqCounts[irqChannel6]++; + }, + CHANGE); +} + +void loop() { + // Check for received IRQ every second. + Serial.println("--------"); + for (unsigned int i = irqChannel1; i <= irqChannel6; i++) { + Serial.print("IRQ Channel: "); + Serial.print(i + 1); + Serial.print(" - "); + Serial.println(irqCounts[i]); + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounterMap/IRQCounterMap.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounterMap/IRQCounterMap.ino new file mode 100644 index 00000000..3c632726 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounterMap/IRQCounterMap.ino @@ -0,0 +1,74 @@ +/* + Testing strategy: alternatively create a short-time connection between + WAKEUP 1-6 and any of the +BAT_ext pins (the row above the WAKEUP ones). + + Check IRQChannel for a simpler implementation. +*/ + +#include + +#include + +// Use a map to collect IRQ counts +std::map irqCounts{ + { IRQ_CH1, 0 }, + { IRQ_CH2, 0 }, + { IRQ_CH3, 0 }, + { IRQ_CH4, 0 }, + { IRQ_CH5, 0 }, + { IRQ_CH6, 0 } +}; + +// Map pin numbers to pin names for pretty printing +std::map irqNames{ +#define NE(IRQ) { IRQ, #IRQ } + NE(IRQ_CH1), + NE(IRQ_CH2), + NE(IRQ_CH3), + NE(IRQ_CH4), + NE(IRQ_CH5), + NE(IRQ_CH6), +}; + +void setup() { + EdgeControl.begin(); + + Serial.begin(115200); + + // Wait for Serial Monitor or start after 2.5s + for (const auto timeout = millis() + 2500; millis() < timeout && !Serial; delay(250)) + ; + + // Init IRQ pins and attach callbacks + // NOTE: .first holds the channel pin and .second holds the counter + for (const auto& irq : irqCounts) { + // Init pins + pinMode(irq.first, INPUT); + + // Create a type alias helper + using IrqCount = std::pair; + + // Define the IRQ callback as lambda function + // Will receive an entry from the irqCounts map: + auto isr = [](void* arg) { + IrqCount* ic = (IrqCount*)arg; + (*ic).second++; + }; + + // attach the callback passing the current map entry as parameter + attachInterruptParam( + digitalPinToInterrupt(irq.first), isr, RISING, (void*)&irq); + } +} + +void loop() { + // Print counters every second. + Serial.println("--------"); + for (const auto& irq : irqCounts) { + Serial.print("IRQ Channel: "); + Serial.print(irqNames[irq.first]); + Serial.print(" - Counts: "); + Serial.println(irq.second); + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LCD/LCD.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LCD/LCD.ino new file mode 100644 index 00000000..edb5d85d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LCD/LCD.ino @@ -0,0 +1,110 @@ +/* + LCD Display (HD44780) via LiquidCrystal for TCA6224A + + The circuit: + * Arduino Edge Control + * Arduino Edge Control LCD brekout board + +*/ + +#include +#include + +byte smiley[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b10001, + 0b01110, + 0b00000 +}; + +byte armsUp[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + 0b00100, + 0b01010 +}; + +byte frownie[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b00000, + 0b01110, + 0b10001 +}; + +void setup() { + EdgeControl.begin(); + + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Testing LCD for Arduino Edge Control"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + + delay(500); + + Serial.print("IO Expander initializazion "); + if (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + } + Serial.println("succeeded."); + + // set up the LCD's number of columns and rows: + LCD.begin(16, 2); + + LCD.createChar(0, smiley); // load character to the LCD + LCD.createChar(1, armsUp); // load character to the LCD + LCD.createChar(2, frownie); // load character to the LCD + + // Print a message to the LCD. + LCD.home(); // go home + LCD.print("Edge Control"); + LCD.setCursor(15, 0); + LCD.print(char(1)); +} + +void loop() { + static bool backlight = true; + + if (backlight) { + LCD.backlight(); + backlight = false; + } else { + LCD.noBacklight(); + backlight = true; + } + + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + LCD.setCursor(0, 1); + // print the number of seconds since reset: + LCD.print(millis() / 1000); + // Do a little animation by writing to the same location + LCD.setCursor(15, 1); + LCD.print(char(2)); + delay(200); + LCD.setCursor(15, 1); + LCD.print(char(0)); + delay(200); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Latching/Latching.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Latching/Latching.ino new file mode 100644 index 00000000..b393e8a6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Latching/Latching.ino @@ -0,0 +1,42 @@ +#include + +void setup() { + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Latching.begin(); +} + +void loop() { + Latching.channelDirection(LATCHING_CMD_1, POSITIVE); + Latching.strobe(200); + // Latching.channelDirection(LATCHING_CMD_1, POSITIVE); + // Latching.latch(); + // delay(200); + // Latching.release(); + Latching.channelDirection(LATCHING_CMD_1, NEGATIVE); + Latching.strobe(200); + // Latching.channelDirection(LATCHING_CMD_1, LOW); + // Latching.latch(); + // delay(200); + // Latching.release(); + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(200); + // Latching.digitalWrite(LATCHING_OUT_1, HIGH); + // Latching.latch(); + // delay(200); + // Latching.release(); + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(200); + // Latching.digitalWrite(LATCHING_OUT_1, LOW); + // Latching.latch(); + // delay(200); + // Latching.release(); + delay(1000); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LowPowerButton/LowPowerButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LowPowerButton/LowPowerButton.ino new file mode 100644 index 00000000..3d7dfadb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LowPowerButton/LowPowerButton.ino @@ -0,0 +1,162 @@ +/* +* Show usage of POWER_ON pin (J1-2). +* +* Board goes to low power mode as soon as started. +* Pressing a momentary button connected to POWER_ON pin +* will wake up the board for 5 seconds. +* +* Requirements: +* - Connect a momentary button between POWER_ON (J1-2) and GND (J1-9) +* - Connect the PC/Mac to USB and open the Arduino Serial Monitor +* or any serial communication application. +* +*/ + +#include +#include + +constexpr unsigned long printInterval{ 250 }; +unsigned long printNow{ 0 }; +constexpr unsigned long wakeUpInterval{ printInterval * 20 }; +unsigned long sleepNow{ 0 }; +volatile bool sleeping{ true }; +volatile bool poweredOn{ false }; + +void wakeUp() { + sleeping = false; + poweredOn = true; +} + +void setup() { + EdgeControl.begin(); + Power.on(PWR_3V3); + + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Testing Low Power"); + Serial.println("and Power On Button."); + + pinMode(POWER_ON, INPUT); + attachInterrupt(digitalPinToInterrupt(POWER_ON), wakeUp, FALLING); + + sleepNow = millis(); + printNow = millis() + printInterval; + + powerDown(); +} + +void loop() { + if (poweredOn) { + poweredOn = false; + + powerOn(); + + delay(1000); // Wait for Serial Monitor/Serial Communication Application + Serial.println(""); + Serial.println("Woke Up!"); + sleepNow = millis() + wakeUpInterval; + } + + if (millis() > sleepNow && !sleeping) { + // Going to sleep + powerDown(); + sleeping = true; + } + + if (sleeping) + delay(10000); // delay() puts the board in low power mode. + else if (millis() > printNow) { + Serial.print('.'); + printNow = millis() + printInterval; + } +} + +void powerOn() { + // Enable Gated 3V3 to devices and peripherals + Power.on(PWR_3V3); + + // Enable Gated 12V and 5V to output pins, devices and peripherals + Power.on(PWR_VBAT); + + // Enable Gated 12V and 5V to output pins, devices and peripherals + Power.on(PWR_19V); + + // Attach USB + PluggableUSBD().begin(); + + // Enable stdin + mbed::mbed_file_handle(STDIN_FILENO)->enable_input(true); + + // Open Serial and wait for connection + Serial.begin(9600); + while (!Serial) + ; +} + +void powerDown() { + Serial.println(); + Serial.println("Powering down"); + + // Disable Gated 3V3 + Power.off(PWR_3V3); + + // Disable Gated 12V and 5V + Power.off(PWR_VBAT); + + // Disable Gated 19V + Power.off(PWR_19V); + + // Close Serial + Serial.end(); + Serial1.end(); + // Disable stdin + mbed::mbed_file_handle(STDIN_FILENO)->enable_input(false); + // Detach USB + PluggableUSBD().deinit(); + // Put pins in threestate + powerDownPins(); +} + +void powerDownPins() { + pinMode(I2C_SDA, INPUT_PULLDOWN); + pinMode(I2C_SCL, INPUT_PULLDOWN); + pinMode(I2C_SDA1, INPUT_PULLDOWN); + pinMode(I2C_SCL1, INPUT_PULLDOWN); + + pinMode(VBAT_PROBE, INPUT_PULLDOWN); + + pinMode(CMD_TRIAC_1, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_2, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_3, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_4, INPUT_PULLDOWN); + + pinMode(SENSOR_COMMON, INPUT_PULLDOWN); + pinMode(SENSOR_CALIB, INPUT_PULLDOWN); + pinMode(SENSOR_INPUT_ADC, INPUT_PULLDOWN); + pinMode(SENSOR_CAPTURE_A, INPUT_PULLDOWN); + pinMode(SENSOR_CAPTURE, INPUT_PULLDOWN); + + pinMode(PULSE_DIRECTION, INPUT_PULLDOWN); + pinMode(PULSE_STROBE, INPUT_PULLDOWN); + + pinMode(SD_CS, INPUT_PULLDOWN); + + pinMode(QSPIDCS, INPUT_PULLDOWN); + pinMode(GPIOCLK, INPUT_PULLDOWN); + pinMode(QSPID0, INPUT_PULLDOWN); + pinMode(QSPID1, INPUT_PULLDOWN); + pinMode(QSPID2, INPUT_PULLDOWN); + pinMode(QSPID3, INPUT_PULLDOWN); + + pinMode(IRQ_CH1, INPUT); + pinMode(IRQ_CH2, INPUT); + pinMode(IRQ_CH3, INPUT); + pinMode(IRQ_CH4, INPUT); + pinMode(IRQ_CH5, INPUT); + pinMode(IRQ_CH6, INPUT); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/PowerOnButton/PowerOnButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/PowerOnButton/PowerOnButton.ino new file mode 100644 index 00000000..676001ef --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/PowerOnButton/PowerOnButton.ino @@ -0,0 +1,58 @@ +/* + Test Power On button on LCD breakout board + + Circuit: + * Arduino Edge Control + * Arduino Edge Control LCD brekout board +*/ + +#include + +// Keep track of toggle-style press with an ISR +volatile bool buttonPressed{ false }; +bool ledStatus{ false }; + +void setup() { + Serial.begin(9600); + + for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250)) + ; + + Serial.println("Hello, Arduino Edge Control!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + + delay(500); + + Serial.print("IO Expander initializazion "); + if (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + } + Serial.println("succeeded."); + + Expander.pinMode(EXP_LED1, OUTPUT); + + pinMode(POWER_ON, INPUT); + // ISR for button press detection + attachInterrupt( + digitalPinToInterrupt(POWER_ON), [] { + buttonPressed = true; + }, + FALLING); +} + +void loop() { + if (buttonPressed == true) { + buttonPressed = false; + ledStatus = !ledStatus; + Serial.print(millis()); + Serial.println(" Pressed"); + } + + Expander.digitalWrite(EXP_LED1, ledStatus == true ? LOW : HIGH); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/Helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/Helpers.h new file mode 100644 index 00000000..57382462 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/Helpers.h @@ -0,0 +1,124 @@ +#pragma once + +#include +#include +#include + +// Convert build time to UNIX time +time_t getBuildDateTime(bool local_time = true, int tz = 0) { + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + sscanf(__DATE__, "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(__TIME__, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3 + 1; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getRTCDate() { + // APIs to get date fields. + auto years = RealTimeClock.getYears(); + auto months = RealTimeClock.getMonths(); + auto days = RealTimeClock.getDays(); + + char buf[12]{}; + + snprintf(buf, 11, "20%02d-%02d-%02d", years, months, days); + + return String(buf); +} + +String getRTCTime() { + // APIs to get time fields. + auto hours = RealTimeClock.getHours(); + auto minutes = RealTimeClock.getMinutes(); + auto seconds = RealTimeClock.getSeconds(); + + char buf[11]{}; + + snprintf(buf, 10, "%02d:%02d:%02d", hours, minutes, seconds); + + return String(buf); +} + +String getRTCDateTime() { + auto date = getRTCDate(); + auto time = getRTCTime(); + + auto dateTime = date + ' ' + time; + + return dateTime; +} + +String getLocaltime() { + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) { + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char* fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char* fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/RealTimeClock.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/RealTimeClock.ino new file mode 100644 index 00000000..05203c71 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/RealTimeClock.ino @@ -0,0 +1,65 @@ +/* + Arduino Edge Control - RTC Example + + This sketch shows how to use the RTC (PCF8563T) on the Arduino + Edge Control and how to configure the RTC's time registers. + + Circuit: + - Arduino Edge Control + - CR2032 Battery + - Optional: Arduino Edge Control LCD + Button brekout + +*/ + +#include "Helpers.h" +#include + +void setup() { + pinMode(POWER_ON, INPUT); + + Serial.begin(9600); + + for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250)) + ; + + Serial.println("Hello, Arduino Edge Control!"); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Initializating the Real Time Clock..."); + while (!RealTimeClock.begin()) { + Serial.println(" failed! Retrying..."); + delay(250); + } + Serial.println(" done!"); + + // APIs to set date's fields: years, months, days, hours, minutes and seconds + // The RTC time can be set as epoch, using one of the following two options: + // - Calendar time: RealTimeClock.setEpoch(years, months, days, hours, minutes, seconds); + // - UTC time: RealTimeClock.setEpoch(date_in_seconds); + + // Set the RTC only when LCD's PowerOn button is pressed. + // YMMV. + if (digitalRead(POWER_ON) == LOW) { + Serial.println("Resetting the RTC to Sketch Build Datetime!"); + auto buildDateTime = getBuildDateTime(); + RealTimeClock.setEpoch(buildDateTime); + Serial.print("Build "); + } +} + +void loop() { + Serial.print("Date: "); + Serial.println(getRTCDateTime()); + + Serial.print("Unix time: "); + Serial.println(time(NULL)); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/Helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/Helpers.h new file mode 100644 index 00000000..6bed83ab --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/Helpers.h @@ -0,0 +1,88 @@ +#pragma once + +#include +#include + +// Convert build time to UNIX time +time_t getBuildDateTime(bool local_time = true, int tz = 0) { + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + sscanf(__DATE__, "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(__TIME__, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3 + 1; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() { + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) { + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char* fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char* fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/RealTimeClock_Alarm.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/RealTimeClock_Alarm.ino new file mode 100644 index 00000000..95147039 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/RealTimeClock_Alarm.ino @@ -0,0 +1,131 @@ +/* + Arduino Edge Control - RTC Alarm Example + + This sketch shows how to use the RTC (PCF8563T) on the Arduino + Edge Control and how to configure and use the RTC's alarm. + + Circuit: + - Arduino Edge Control + - CR2032 Battery + - Optional: Arduino Edge Control LCD + Button brekout + +*/ + +#include "Helpers.h" +#include + +volatile bool alarmFlag{ false }; +byte alarmInterval{ 1 }; + +void setup() { + Serial.begin(9600); + + for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250)) + ; + + Serial.println("Hello, Arduino Edge Control!"); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Initializating the Real Time Clock..."); + while (!RealTimeClock.begin()) { + Serial.println(" failed! Retrying..."); + delay(250); + } + Serial.println(" done!"); + + // Set the RTC only when LCD's PowerOn button is pressed. + // YMMV. + if (digitalRead(POWER_ON) == LOW) { + auto buildDateTime = getBuildDateTime(); + RealTimeClock.setEpoch(buildDateTime); + Serial.print("Build "); + } + + Serial.print("Date: "); + Serial.println(getRTCDateTime()); + + // Enables Alarm on the RTC + RealTimeClock.enableAlarm(); + + // Set the minutes at which the alarm should rise + // Trigger in a minute + auto minutes = RealTimeClock.getMinutes(); + RealTimeClock.setMinuteAlarm(minutes + alarmInterval); + + // Attach an interrupt to the RTC interrupt pin + attachInterrupt( + digitalPinToInterrupt(IRQ_RTC), [] { + alarmFlag = true; + }, + FALLING); + + Serial.println(); +} + +void loop() { + if (alarmFlag) { + Serial.println("Alarm!"); + + auto totalMinutes = RealTimeClock.getMinutes() + alarmInterval; + + // Take care of the 60-minute wrapping and... + auto minutesAlarm = totalMinutes % 60; + RealTimeClock.setMinuteAlarm(minutesAlarm); + + // don't forget to manage the hour increment. + if (totalMinutes >= 60) + RealTimeClock.setHourAlarm(RealTimeClock.getHours() + 1); + + RealTimeClock.clearAlarm(); + + // To disable the alarm uncomment the following line: + // RealTimeClock.disableAlarm(); + + alarmFlag = false; + } + + Serial.println(getRTCTime()); + delay(10000); +} + +String getRTCDate() { + // APIs to get date fields. + auto years = RealTimeClock.getYears(); + auto months = RealTimeClock.getMonths(); + auto days = RealTimeClock.getDays(); + + char buf[12]{}; + + snprintf(buf, 11, "20%02d-%02d-%02d", years, months, days); + + return String(buf); +} + +String getRTCTime() { + // APIs to get time fields. + auto hours = RealTimeClock.getHours(); + auto minutes = RealTimeClock.getMinutes(); + auto seconds = RealTimeClock.getSeconds(); + + char buf[11]{}; + + snprintf(buf, 10, "%02d:%02d:%02d", hours, minutes, seconds); + + return String(buf); +} + +String getRTCDateTime() { + auto date = getRTCDate(); + auto time = getRTCTime(); + + auto dateTime = date + ' ' + time; + + return dateTime; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/Helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/Helpers.h new file mode 100644 index 00000000..57382462 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/Helpers.h @@ -0,0 +1,124 @@ +#pragma once + +#include +#include +#include + +// Convert build time to UNIX time +time_t getBuildDateTime(bool local_time = true, int tz = 0) { + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + sscanf(__DATE__, "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(__TIME__, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3 + 1; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getRTCDate() { + // APIs to get date fields. + auto years = RealTimeClock.getYears(); + auto months = RealTimeClock.getMonths(); + auto days = RealTimeClock.getDays(); + + char buf[12]{}; + + snprintf(buf, 11, "20%02d-%02d-%02d", years, months, days); + + return String(buf); +} + +String getRTCTime() { + // APIs to get time fields. + auto hours = RealTimeClock.getHours(); + auto minutes = RealTimeClock.getMinutes(); + auto seconds = RealTimeClock.getSeconds(); + + char buf[11]{}; + + snprintf(buf, 10, "%02d:%02d:%02d", hours, minutes, seconds); + + return String(buf); +} + +String getRTCDateTime() { + auto date = getRTCDate(); + auto time = getRTCTime(); + + auto dateTime = date + ' ' + time; + + return dateTime; +} + +String getLocaltime() { + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) { + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char* fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char* fmt, bool local_time = true, int tz = 0) { + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/RealTimeClock_LowPower.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/RealTimeClock_LowPower.ino new file mode 100644 index 00000000..a678fe64 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/RealTimeClock_LowPower.ino @@ -0,0 +1,106 @@ +/* + Arduino Edge Control - RTC Low Power Example + + This sketch shows how to use the RTC (PCF8563T) on the Arduino + Edge Control and how to configure and use the RTC on Low Power mode. + + Circuit: + - Arduino Edge Control + - CR2032 Battery + - Optional: Arduino Edge Control LCD + Button brekout + +*/ + +#include "Helpers.h" +#include +#include + +void setup() { + Serial.begin(9600); + + for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250)) + ; + + Serial.println("Hello, Arduino Edge Control!"); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Initializating the Real Time Clock..."); + while (!RealTimeClock.begin()) { + Serial.println(" failed! Retrying..."); + delay(250); + } + Serial.println(" done!"); + + // Set the RTC only when LCD's PowerOn button is pressed. + // YMMV. + if (digitalRead(POWER_ON) == LOW) { + auto buildDateTime = getBuildDateTime(); + RealTimeClock.setEpoch(buildDateTime); + Serial.print("Build "); + } + + Serial.print("Date: "); + Serial.println(getRTCDateTime()); + + delay(5000); + + Wire.end(); + Serial.end(); + Serial1.end(); + + Power.off(PWR_3V3); + Power.off(PWR_VBAT); + + mbed::mbed_file_handle(STDIN_FILENO)->enable_input(false); + PluggableUSBD().deinit(); +} + +void loop() { + delay(10000); +} + +void powerDown() { + pinMode(I2C_SDA, INPUT_PULLDOWN); + pinMode(I2C_SCL, INPUT_PULLDOWN); + pinMode(I2C_SDA1, INPUT_PULLDOWN); + pinMode(I2C_SCL1, INPUT_PULLDOWN); + + pinMode(VBAT_PROBE, INPUT_PULLDOWN); + + pinMode(CMD_TRIAC_1, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_2, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_3, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_4, INPUT_PULLDOWN); + + pinMode(SENSOR_COMMON, INPUT_PULLDOWN); + pinMode(SENSOR_CALIB, INPUT_PULLDOWN); + pinMode(SENSOR_INPUT_ADC, INPUT_PULLDOWN); + pinMode(SENSOR_CAPTURE_A, INPUT_PULLDOWN); + pinMode(SENSOR_CAPTURE, INPUT_PULLDOWN); + + pinMode(PULSE_DIRECTION, INPUT_PULLDOWN); + pinMode(PULSE_STROBE, INPUT_PULLDOWN); + + pinMode(SD_CS, INPUT_PULLDOWN); + + pinMode(QSPIDCS, INPUT_PULLDOWN); + pinMode(GPIOCLK, INPUT_PULLDOWN); + pinMode(QSPID0, INPUT_PULLDOWN); + pinMode(QSPID1, INPUT_PULLDOWN); + pinMode(QSPID2, INPUT_PULLDOWN); + pinMode(QSPID3, INPUT_PULLDOWN); + + pinMode(IRQ_CH1, INPUT_PULLDOWN); + pinMode(IRQ_CH2, INPUT_PULLDOWN); + pinMode(IRQ_CH3, INPUT_PULLDOWN); + pinMode(IRQ_CH4, INPUT_PULLDOWN); + pinMode(IRQ_CH5, INPUT_PULLDOWN); + pinMode(IRQ_CH6, INPUT_PULLDOWN); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/SolidStateRelay/SolidStateRelay.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/SolidStateRelay/SolidStateRelay.ino new file mode 100644 index 00000000..4d8a42cc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/SolidStateRelay/SolidStateRelay.ino @@ -0,0 +1,78 @@ +#include "Arduino_EdgeControl.h" + +// #define SSR_POLL + +constexpr unsigned long onInterval = { 5000 }; +constexpr unsigned long offInterval = { 5000 }; +constexpr unsigned long pollInterval = { 1000 }; +unsigned long offTime; +unsigned long onTime; +unsigned long pollTime; +bool on = false; + +int relayChannel{ RELAY_CH01 }; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + delay(2000); + + Serial.println("Hello, SolidStateRelay!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + Expander.pinMode(EXP_LED1, OUTPUT); + + for (auto i = 0; i < 3; i++) { + Expander.digitalWrite(EXP_LED1, LOW); + delay(50); + Expander.digitalWrite(EXP_LED1, HIGH); + delay(100); + } + + Relay.begin(); +} + +void loop() { + if (millis() > onTime && !on) { + Serial.println("RELAY ON"); + + Relay.on(relayChannel); + + Expander.digitalWrite(EXP_LED1, LOW); + + on = true; + offTime = onInterval + millis(); + } + + if (millis() > offTime && on) { + Serial.println("RELAY OFF"); + + Relay.off(relayChannel); + + Expander.digitalWrite(EXP_LED1, HIGH); + + on = false; + onTime = millis() + offInterval; + } + +#if defined(SSR_POLL) + if (millis() > pollTime && on) { + Serial.println("POLLING"); + + Relay.poll(relayChannel); + + pollTime = millis() + pollInterval; + } +#endif +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Watermark10k/Watermark10k.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Watermark10k/Watermark10k.ino new file mode 100644 index 00000000..b242ede7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Watermark10k/Watermark10k.ino @@ -0,0 +1,61 @@ +#include + +constexpr unsigned int calibResistor{ 7870 }; + +void setup() { + Serial.begin(115200); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + EdgeControl.begin(); + delay(2000); + + Serial.println("Hello, 10k"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander.begin()) { + Serial.print("."); + delay(250); + } + Serial.println(" done."); + + Watermark.begin(); + Serial.println("Watermark OK"); + + Watermark.calibrationMode(OUTPUT); + Watermark.calibrationWrite(LOW); + + Watermark.commonMode(OUTPUT); + Watermark.commonWrite(HIGH); +} + +void loop() { + auto val = wmkAvgAnalogRead(WATERMARK_CH01); + Serial.print("Watermark Channel 01"); + Serial.print(" - average analogRead value: "); + Serial.print(val); + Serial.print(" - Calculated Resistor: "); + Serial.println(calibResistor * (1023 - val) / val); + + delay(1000); +} + +int wmkAvgAnalogRead(pin_size_t pin) { + constexpr size_t count{ 10 }; + unsigned int sum{ 0 }; + + Watermark.enable(); + for (auto i = 0u; i < count; i++) + sum += Watermark.analogRead(pin); + Watermark.disable(); + + return sum / count; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkMega/WatermarkMega.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkMega/WatermarkMega.ino new file mode 100644 index 00000000..e3c93790 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkMega/WatermarkMega.ino @@ -0,0 +1,136 @@ +/* + This sketch is the implementation of the classic Watermark example + for Arduino Mega ported to the Arduino Edge Control. + + Please, refer to https://www.irrometer.com/200ss.html for further info. + + Another algorithm that can be implemented using the Watermark circuits + on the Edge Control is the one described at + https://medium.com/fasal-engineering/a-low-cost-circuit-to-read-from-multiple-watermark-irrometer-200ss-sensors-a4c838da233a + + Requirements: + - Arduino Edge Control + - Watermark Sensor + - External 12V power supply + + Circuit: + - Connect PS 12V and GND to BATT+ and GND pins + - Connect the two sensor's cables to WATERMARK COMM and INPUT 1 pins + +*/ + +#include + +constexpr auto adcResolution{ 12 }; + +// You will need a proper temperature value to get correct results +auto refTemperature{ 24.5f }; + +void setup() { + Serial.begin(115200); + + // Wait for Serial or start after 2.5s + for (const auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(250)) + ; + + EdgeControl.begin(); + delay(2000); + + Serial.println("Hello, Watermark Mega"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander.begin()) { + Serial.print("."); + delay(250); + } + Serial.println(" done."); + + Watermark.begin(); + Serial.println("Watermark OK"); +} + +void loop() { + auto wm = getWatermark(WATERMARK_CH01); + Serial.print("Watermark = "); + Serial.print(wm); + Serial.println("kPa"); + + delay(1000); +} + + +int getAverageWatermarkRead(pin_size_t pin) { + constexpr size_t count{ 20 }; + int sum{ 0 }; + + Watermark.calibrationMode(OUTPUT); + Watermark.calibrationWrite(LOW); + + Watermark.commonMode(OUTPUT); + + Watermark.enable(); + + for (auto i = 0u; i < count; i++) { + Watermark.commonWrite(HIGH); + delay(2); + sum += Watermark.analogRead(pin); + Watermark.commonWrite(LOW); + } + + Watermark.disable(); + + return sum / count; +} + +float getWatermark(pin_size_t pin) { + constexpr unsigned int calibResistor{ 7870 }; + constexpr long openResistance{ 35000 }; + constexpr long shortResistance{ 200 }; + constexpr long shortkPa{ 240 }; + constexpr long openkPa{ 255 }; + + constexpr auto maxValue{ 1 << adcResolution }; + constexpr float toV{ 3.3f / float{ maxValue } }; + + float kPa; + + auto val = getAverageWatermarkRead(pin); + + if (val == 0) + return openkPa; + + auto resistor = calibResistor * float{ maxValue - val } / float{ val }; + + if (resistor > 550.f) { + if (resistor > 8000.f) { + kPa = -2.246f - 5.239f * (resistor / 1500.f) * (1.f + .018f * (refTemperature - 24.f)) - .06756f * (resistor / 1500.f) * (resistor / 1500.f) * ((1.f + 0.018f * (refTemperature - 24.f)) * (1.f + 0.018f * (refTemperature - 24.f))); + } else if (resistor > 1500.f) { + kPa = (-3.213f * (resistor / 1500.f) - 4.093f) / (1.f - 0.009733f * (resistor / 1500.f) - 0.01205f * (refTemperature)); + } else { + kPa = ((resistor / 1500.f) * 23.156f - 12.736f) * (1.f + 0.018f * (refTemperature - 24.f)); + } + } else { + if (resistor > 300.f) + kPa = 0.f; + if (resistor < 300.f && resistor >= shortResistance) + kPa = shortkPa; // 240 is a fault code for sensor terminal short + } + + if (resistor >= openResistance) { + kPa = openkPa; // 255 is a fault code for open circuit or sensor not present + } + + Serial.print("Watermark average analogRead value: "); + Serial.print(val); + Serial.print(" - Calculated Resistor: "); + Serial.print(resistor); + Serial.println(); + + return abs(kPa); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkTau/WatermarkTau.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkTau/WatermarkTau.ino new file mode 100644 index 00000000..beecf4f9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkTau/WatermarkTau.ino @@ -0,0 +1,137 @@ +#include +#include + +#include +#include + +constexpr unsigned int adcResolution{ 12 }; + +mbed::LowPowerTimeout TimerM; + +uint8_t watermarkChannel{ 1 }; + +constexpr float tauRatio{ 0.63f }; +constexpr float tauRatioSamples{ tauRatio * float{ (1 << adcResolution) - 1 } }; +constexpr unsigned long sensorDischargeDelay{ 2 }; + +constexpr unsigned int measuresCount{ 20 }; +RunningMedian measures{ measuresCount }; + +constexpr unsigned int calibsCount{ 10 }; +RunningMedian calibs{ calibsCount }; + +void setup() { + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + delay(2000); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + Expander.begin(); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + + Watermark.begin(); + + analogReadResolution(adcResolution); +} + +void loop() { + static bool highPrec{ false }; + Watermark.setHighPrecision(highPrec); + highPrec = !highPrec; + + // Init commands and reset devices + Watermark.calibrationMode(OUTPUT); + Watermark.calibrationWrite(LOW); + Watermark.commonMode(OUTPUT); + Watermark.commonWrite(LOW); + + Watermark.fastDischarge(sensorDischargeDelay); + + // Calibration cycle: + // disable Watermark demuxer + Watermark.disable(); + + Watermark.commonMode(INPUT); + Watermark.calibrationMode(OUTPUT); + for (auto i = 0u; i < measuresCount; i++) { + Watermark.calibrationWrite(HIGH); + + auto start = micros(); + while (Watermark.analogRead(watermarkChannel) < tauRatioSamples) + ; + auto stop = micros(); + + Watermark.calibrationWrite(LOW); + + Watermark.fastDischarge(sensorDischargeDelay); + + calibs.add(stop - start); + } + + Serial.print("CALIBS - Precision: "); + Serial.print(highPrec ? "High" : "Low "); + Serial.print(" - Median: "); + Serial.print(calibs.getMedian()); + Serial.print(" - Average: "); + Serial.print(calibs.getAverage()); + Serial.print(" - Lowest: "); + Serial.print(calibs.getLowest()); + Serial.print(" - Highest: "); + Serial.print(calibs.getHighest()); + Serial.println(); + + calibs.clear(); + + Watermark.fastDischarge(sensorDischargeDelay); + + // Measures cycle: + // enable Watermark demuxer + Watermark.enable(); + + Watermark.commonMode(OUTPUT); + Watermark.calibrationMode(INPUT); + for (auto i = 0u; i < measuresCount; i++) { + Watermark.commonWrite(HIGH); + + auto start = micros(); + while (Watermark.analogRead(watermarkChannel) < tauRatioSamples) + ; + auto stop = micros(); + + Watermark.commonWrite(LOW); + + Watermark.fastDischarge(sensorDischargeDelay); + + measures.add(stop - start); + } + + Serial.print("MEASURES - Precision: "); + Serial.print(highPrec ? "High" : "Low "); + Serial.print(" - Median: "); + Serial.print(measures.getMedian()); + Serial.print(" - Average: "); + Serial.print(measures.getAverage()); + Serial.print(" - Lowest: "); + Serial.print(measures.getLowest()); + Serial.print(" - Highest: "); + Serial.print(measures.getHighest()); + Serial.println(); + + measures.clear(); + + Serial.println(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/BlinkOverSerial/BlinkOverSerial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/BlinkOverSerial/BlinkOverSerial.ino new file mode 100644 index 00000000..0fb56d14 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/BlinkOverSerial/BlinkOverSerial.ino @@ -0,0 +1,45 @@ +/* + This sketch shows how to use an MKR board connected to one of the + two available slots. The Edge Control and the MKR board will communicate + over UART connection. + + Circuit: + - Arduino Edge Control + - Any Arduino MKR Board connected to MKR Slot 2 + - External 12V Power Supply + + To get the example working, please, load the extras/BlinkFromSerial + sketch on the MKR board. + + +*/ + +#include + +bool led{ false }; + +void setup() { + EdgeControl.begin(); + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + // Power on the MKR on slot 2 + Power.on(PWR_MKR2); + + // Wait for MKR to power on + delay(5000); + + // Open the serial communication with the MKR board on slot 2... + SerialMKR2.begin(115200); + + // ... and ait for the serial communication from the MKR board + while (!SerialMKR2) { + delay(500); + } +} + +void loop() { + SerialMKR2.write(led); + led = !led; + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/LORA_EdgeControl/LORA_EdgeControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/LORA_EdgeControl/LORA_EdgeControl.ino new file mode 100644 index 00000000..4368dd63 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/LORA_EdgeControl/LORA_EdgeControl.ino @@ -0,0 +1,109 @@ +// LoRa example for the Edge control. +// +// This script configures your Arduino Edge control to receive Lora messages from another Arduino. +// Requirements: +// 1 Edge Control board +// 2 MKR1300/1310 boards (sender and receiver) +// +// Connect one of the MKR1300 to the MKR2 socket in the EdgeControl board +// This script is designed to pair with "LORA_receiver-EC.ino". Also +// you will need a LoRa transmitter. We have used the LoRa Sender example from the other +// MKR1300. +// +// The sketch make use of the OpenMV RPC library for communicating between the EdgeControl +// and the MKR1300 via UART +// +// Created 20 April. 2021 +// by e.lopez + + +#include +#include + +openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer. +openmv::rpc_hardware_serial1_uart_master rpc(115200); + +//LoRa message received interrupt pin +const byte interruptPin = PIN_WIRE_SCL1; + +bool message_received = false; +uint16_t msg_count{ 0 }; + + +////////////////////////////////////////////////////////////// +// Call Back Handlers +////////////////////////////////////////////////////////////// + +void rpc_retrieve_LoRa_data() { + rpc.begin(); + void *message; + size_t result_data_len; + + if (rpc.call_no_copy_no_args(F("retrieve_msg"), &message, &result_data_len)) { + + char buff[result_data_len + 1]; + memset(buff, 0, result_data_len + 1); + // Copy what we received into our data type container. + memcpy(buff, message, result_data_len); + // Use it now. + Serial.print(F(": ")); + Serial.println(buff); + + //print on LCD + //LCD.setCursor(0, 0); + //LCD.print("LoRa MSG:"); + //LCD.setCursor(0, 1); + //LCD.print(buff); + + } else { + Serial.print(F("Error:rpc_retrieve_LoRa_data() failed! ")); + } + rpc.end(); +} + +//******************* +//SETUP +//******************* +void setup() { + //LoRa data available interrupt + pinMode(interruptPin, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(interruptPin), LoRa_ISR, FALLING); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Power.on(PWR_MKR2); + delay(5000); // Wait for MKR2 to power-on' + + Serial.begin(115200); + while (!Serial) + ; + + // //LCD init + // LCD.begin(16, 2); // set up the LCD's number of columns and rows: + // LCD.home(); // go home + // LCD.backlight(); // turn on Backlight + // LCD.print("EDGE:"); // Print a message to the LCD. + + String serialNumber = EdgeControl.serialNumber(); + Serial.print("Serial Number: "); + Serial.println(serialNumber); +} + +//******************* +//LOOP +//******************* +void loop() { + if (message_received) { + Serial.print("Message "); + Serial.print(++msg_count); + rpc_retrieve_LoRa_data(); + message_received = false; + } +} + +void LoRa_ISR() { + message_received = true; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/OpenMV_RPC_Controller/OpenMV_RPC_Controller.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/OpenMV_RPC_Controller/OpenMV_RPC_Controller.ino new file mode 100644 index 00000000..f9ca3267 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/OpenMV_RPC_Controller/OpenMV_RPC_Controller.ino @@ -0,0 +1,101 @@ +// Remote Control - As The Controller Device +// +// This script configures your Arduino to remotely control another Arduino. +// +// This script is designed to pair with "arduino_to_arduino_communication_as_the_remote_device.ino" +// example sketch included with this library. + +#include +#include + +openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer. + +#define RPC_OVER_SERIAL 1 + +#if defined(RPC_OVER_SERIAL) +openmv::rpc_hardware_serial1_uart_master rpc(115200); +#else +openmv::rpc_i2c1_master rpc(0x12, 10000); +#endif + +void setup() { + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Power.on(PWR_MKR2); + delay(5000); // Wait for MKR2 to power-on + + Serial.begin(115200); + rpc.begin(); +} + +////////////////////////////////////////////////////////////// +// Call Back Handlers +////////////////////////////////////////////////////////////// + +// This example shows reading a Digital I/O pin remotely. +// +void digital_read_example() { + uint8_t state; + if (rpc.call_no_args("digital_read", &state, sizeof(state))) { + Serial.print(F("Remote Digital I/O State: ")); + Serial.println(state); + } +} + +// This example shows reading an Analog I/O pin remotely. +// +void analog_read_example() { + uint16_t state; + if (rpc.call_no_args(F("analog_read"), &state, sizeof(state))) { + Serial.print(F("Remote Analog I/O State: ")); + Serial.println(state); + } +} + +// This example shows writing a Digital I/O pin remotely. +// +void digital_write_example() { + static uint8_t state = 0; + + auto ret = rpc.call("digital_write", &state, sizeof(state), nullptr, 0, false); + if (!ret) { + Serial.println("DigitalWrite Call Failed!"); + return; + } + state = !state; // flip state for next time +} + +// This example shows writing an Analog I/O pin remotely. +// +void analog_write_example() { + static uint8_t state = 0; + + auto ret = rpc.call("analog_write", &state, sizeof(state), nullptr, 0, false); + if (!ret) { + Serial.println("AnalogWrite Call Failed!"); + return; + } + + state = state + 1; // counts from 0 to 255 then rolls over +} + +void serial_print_example() { + String str = "Hello World @"; + str += millis(); + + char buffer[str.length() + 1]{}; + str.toCharArray(buffer, sizeof(buffer)); + + rpc.call("serial_print", buffer, sizeof(buffer)); +} + +void loop() { + digital_read_example(); + analog_read_example(); + digital_write_example(); + analog_write_example(); + serial_print_example(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/RPC_DweetBlink/RPC_DweetBlink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/RPC_DweetBlink/RPC_DweetBlink.ino new file mode 100644 index 00000000..1d723783 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/RPC_DweetBlink/RPC_DweetBlink.ino @@ -0,0 +1,179 @@ +/* + Blink LED via Dweet using an MKR connected board as network interface + + This example uses the OpenMV Arduino RPC Interface Library + https://github.com/openmv/openmv-arduino-rpc to control an + Arduino MKR WiFi 1010 board stacked on the MKR connector + to send REST requests to the Dweet.io. Please, install the library + from the repo as a zip library before compile the sketch. + + The code checks for a "led" key in the content payload of the Dweet + response and sets the on-board LED accordingly. + + Requirements: + * Arduino Edge Control powered via 12V power adapter or 12V lead-acid battery + * Arduino MKR WiFi1010 stacked on connector MKR2 (the one next to the CR2032 battery holder) + * OpenMV Arduino RPC Interface Library + + Steps: + * Upload this sketch to Edge Control + * Upload the "extras/RPC/RPC_DweetBlink_Remote" sketch to the MKR 1010 + (don't forget to configure your WiFi credentials) + * Connect your favorite serial monitor or terminal emulator to both the boards + * Retrieve the Serial Number () of the Edge Control by running the sketch + * Send a Dweet to the Serial Number of the Edge Control board setting the value + of the "led" key to "on" or "off" to blink the on-board LED. Eg. + + curl -X POST http://dweet.io/dweet/for/ -F led=on + + * Current status of the LED can be retrieved from Dweet at "SERIALNUMBER-status" path, eg. + + curl -i http://dweet.io/get/latest/dweet/for/-status + + created 12 Feb 2021 + by Giampaolo Mancini +*/ + +#include +#include +#include + +// Configure the RPC controller +openmv::rpc_scratch_buffer<256> scratch_buffer; // static memory buffer +openmv::rpc_hardware_serial1_uart_master rpc(115200); + +constexpr uint32_t requestInterval{ 20 * 1000 }; +uint32_t requestNow{}; + +bool ledStatus{ false }; + +String serialNumber; + +void setup() { + Serial.begin(115200); + const uint32_t startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + EdgeControl.begin(); + + Power.on(PWR_3V3); + + // Enable the 5V power rail + Power.on(PWR_VBAT); + + // Power on the MKR on connector 2 + Power.on(PWR_MKR2); + // Wait for MKR2 to power-on + delay(5000); + + serialNumber = EdgeControl.serialNumber(); + Serial.print("Serial Number: "); + Serial.println(serialNumber); + + // Init the I2C bus + Wire.begin(); + delay(500); + + // Init the I/O Expander + Serial.print("I/O Expander initializazion "); + if (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + } + Serial.println("succeeded."); + + // Configure the LED1 pin + Expander.pinMode(EXP_LED1, OUTPUT); + // LED1 is active low + Expander.digitalWrite(EXP_LED1, HIGH); + + // Start the RPC controller + rpc.begin(); + + requestNow = millis(); +} + +void loop() { + if (millis() > requestNow) { + + // Post the status of the LED to Dweet using + // the serial number as device ID + rpcPostDweetFor(serialNumber); + + delay(1000); + + // Get the next status of the LED + rpcGetLatestDweetFor(serialNumber); + + requestNow = millis() + requestInterval; + } + + Expander.digitalWrite(EXP_LED1, ledStatus); +} + +void rpcPostDweetFor(String deviceID) { + Serial.print("Posting Status Dweet For "); + Serial.print(deviceID); + Serial.print(" via RPC: "); + + // Pass data to remote RPC client in JSON format. YMMV. + JSONVar data; + data["deviceID"] = deviceID; + // Pin LED is active low + data["ledStatus"] = !ledStatus; + + auto dataString = JSON.stringify(data); + Serial.println(dataString); + + // Call the "postDweetFor" callback on the MKR WiFi 1010 + // Remember to set large RPC timeouts: the Network is SLOW! + // + // Please, refer to openmv-rpc-arduino documentation for more + // call() examples. + auto ret = rpc.call("postDweetFor", + (void*)dataString.c_str(), dataString.length(), // arguments + NULL, 0, // no returns + false, 1000, 3000); // parameters + + if (ret == 0) { + Serial.println("Error"); + return; + } +} + +void rpcGetLatestDweetFor(String deviceID) { + Serial.print("Getting Latest Dweet For "); + Serial.print(deviceID); + Serial.print(" via RPC: "); + + // buffer for return data from RPC client + size_t bufferLen{ scratch_buffer.buffer_size() }; + char buffer[bufferLen]{}; + + // Call the "getLatestDweetFor" callback on the MKR WiFi 1010 + // Remember to set large RPC timeouts: the Network is SLOW! + auto ret = rpc.call("getLatestDweetFor", + (void*)deviceID.c_str(), deviceID.length(), // arguments + buffer, bufferLen, // returns + true, 1000, 3000); // parameters + + if (ret == 0) { + Serial.println("Error"); + return; + } + + // Data from Dweet is in JSON format + Serial.println(buffer); + JSONVar dweet = JSON.parse(buffer); + + // Extract next LED status + JSONVar ledCommandJSON = dweet["with"][0]["content"]["led"]; + String ledCommand = (const char*)ledCommandJSON; + + // Pin LED is active low + ledStatus = !(ledCommand == "on"); + Serial.print("LED "); + Serial.println(ledStatus ? "Off" : "On"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/CardInfo/CardInfo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/CardInfo/CardInfo.ino new file mode 100644 index 00000000..6546f453 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/CardInfo/CardInfo.ino @@ -0,0 +1,134 @@ +/* + SD card test ported to Arduino Edge Control + + All the other example from the SD Library will work out-of-the-box + on the Edge Control board provided you remember to enable the 3V3 + power rail using the + + Power.on(PWR_3V3); + + call. + + This example shows how use the utility libraries on which the' + SD library is based in order to get info about your SD card. + Very useful for testing a card when you're not sure whether its working or not. + + The circuit: + SD card attached to SPI bus as follows: + ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila + ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila + ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila + ** CS - depends on your SD card shield or module. + Pin 4 used here for consistency with other Arduino examples + + + created 28 Mar 2011 + by Limor Fried + modified 9 Apr 2012 + by Tom Igoe + modified 15 Feb 2021 + by Giampaolo Mancini +*/ + +#include + +// include the SD library: +#include +#include + +// set up variables using the SD utility library functions: +Sd2Card card; +SdVolume volume; +SdFile root; + +// change this to match your SD shield or module; +// Arduino Ethernet shield: pin 4 +// Adafruit SD shields and modules: pin 10 +// Sparkfun SD shield: pin 8 +// MKRZero SD: SDCARD_SS_PIN +const int chipSelect = PIN_SD_CS; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + EdgeControl.begin(); + // Power on the 3V3 rail for SD Card + Power.on(PWR_3V3); + + Serial.print("\nInitializing SD card..."); + + // we'll use the initialization code from the utility libraries + // since we're just testing if the card is working! + if (!card.init(SPI_HALF_SPEED, chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("* is a card inserted?"); + Serial.println("* is your wiring correct?"); + Serial.println("* did you change the chipSelect pin to match your shield or module?"); + while (1) + ; + } else { + Serial.println("Wiring is correct and a card is present."); + } + + // print the type of card + Serial.println(); + Serial.print("Card type: "); + switch (card.type()) { + case SD_CARD_TYPE_SD1: + Serial.println("SD1"); + break; + case SD_CARD_TYPE_SD2: + Serial.println("SD2"); + break; + case SD_CARD_TYPE_SDHC: + Serial.println("SDHC"); + break; + default: + Serial.println("Unknown"); + } + + // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 + if (!volume.init(card)) { + Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); + while (1) + ; + } + + Serial.print("Clusters: "); + Serial.println(volume.clusterCount()); + Serial.print("Blocks x Cluster: "); + Serial.println(volume.blocksPerCluster()); + + Serial.print("Total Blocks: "); + Serial.println(volume.blocksPerCluster() * volume.clusterCount()); + Serial.println(); + + // print the type and size of the first FAT-type volume + uint32_t volumesize; + Serial.print("Volume type is: FAT"); + Serial.println(volume.fatType(), DEC); + + volumesize = volume.blocksPerCluster(); // clusters are collections of blocks + volumesize *= volume.clusterCount(); // we'll have a lot of clusters + volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB) + Serial.print("Volume size (Kb): "); + Serial.println(volumesize); + Serial.print("Volume size (Mb): "); + volumesize /= 1024; + Serial.println(volumesize); + Serial.print("Volume size (Gb): "); + Serial.println((float)volumesize / 1024.0); + + Serial.println("\nFiles found on the card (name, date and size in bytes): "); + root.openRoot(volume); + + // list all files in the card with date and size + root.ls(LS_R | LS_DATE | LS_SIZE); +} + +void loop(void) { +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/SecureDigital/SecureDigital.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/SecureDigital/SecureDigital.ino new file mode 100644 index 00000000..f2072e1d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/SecureDigital/SecureDigital.ino @@ -0,0 +1,220 @@ +/* + Demonstrate use of Mbed OS FAT API for SD cards on Arduino Edge Control. + Please, note that this example uses POSIX File and Filesyteam APIS. + + If your are looking for how to use the classic Arduino "SD" library with + the Arduino Edge Control, check the CardInfo example. + + Please, look at Mbed OS documentation for details + * https://os.mbed.com/docs/mbed-os/v6.7/apis/sdblockdevice.html + * https://os.mbed.com/docs/mbed-os/v6.7/apis/fatfilesystem.html + + + Ported from mbed-os-example-filesystem + + * Arduino Edge Control + * MicroSD Memory Card +*/ + +#include + +#include +#include +using namespace mbed; + +SDBlockDevice bd(SD_MOSI, SD_MISO, SD_CLK, SD_CS); + +// The parameter indicates the MbedOS-wide mount point +// where the root of the filesystem on the SD will be available at. +FATFileSystem fat("fat"); + +void setup() { + EdgeControl.begin(); + Power.on(PWR_3V3); + + Serial.begin(115200); + while (!Serial) + ; + + delay(2000); + Serial.println("Arduino Edge Control w/ SD and FAT"); + + Serial.print("Initializing SD Card:"); + int err = bd.init(); + if (err != 0) { + Serial.print(" FAIL!"); + Serial.print("Please, check your SD Card."); + while (true) + ; + } + Serial.println(" SUCCESS!"); + Serial.print("SD size: "); + Serial.println(bd.size()); + Serial.print("SD read size: "); + Serial.println(bd.get_read_size()); + Serial.print("SD program size: "); + Serial.println(bd.get_program_size()); + Serial.print("SD erase size: "); + Serial.println(bd.get_erase_size()); + + Serial.print("Mounting... "); + err = fat.mount(&bd); + Serial.println(err ? "Fail :(" : "OK"); + if (err) { + Error(); + // Format and remount + Serial.println("No filesystem found, formatting..."); + err = fat.reformat(&bd); + if (err) { + Error(); + while (1) + ; + } + } + + Serial.println("Hello, FAT!"); + // Open the numbers file + Serial.print("Opening \"/fat/numbers.txt\"... "); + FILE* f = fopen("/fat/numbers.txt", "r+"); + Serial.println(!f ? "Fail :(" : "OK"); + if (!f) { + // Create the numbers file if it doesn't exist + Serial.print("No file found, creating a new file... "); + f = fopen("/fat/numbers.txt", "w+"); + Serial.println(!f ? "Fail :(" : "OK"); + if (!f) { + Error(); + while (1) + ; + } + + for (int i = 0; i < 10; i++) { + Serial.println(); + Serial.print("Writing numbers ("); + Serial.print(i); + Serial.print("/"); + Serial.print(10); + Serial.print(")... "); + err = fprintf(f, " %d\n", i); + if (err < 0) { + Serial.println("Fail :("); + Error(); + } + } + Serial.println(); + Serial.println("Writing numbers (10/10)... OK"); + + Serial.print("Seeking file... "); + err = fseek(f, 0, SEEK_SET); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + } + + // Go through and increment the numbers + Serial.println("Incrementing numbers:"); + for (int i = 0; i < 10; i++) { + Serial.print("("); + Serial.print(i); + Serial.print("/"); + Serial.print(10); + Serial.print("): "); + + // Get current stream position + long pos = ftell(f); + + // Parse out the number and increment + int32_t number; + fscanf(f, "%d", &number); + Serial.println(number); + number += 1; + + // Seek to beginning of number + fseek(f, pos, SEEK_SET); + + // Store number + fprintf(f, " %d\n", number); + + // Flush between write and read on same file + fflush(f); + } + Serial.println("Done."); + + // Close the file which also flushes any cached writes + Serial.print("Closing \"/fat/numbers.txt\"... "); + err = fclose(f); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + + // Display the root directory + Serial.print("Opening the root directory... "); + DIR* d = opendir("/fat/"); + Serial.println(!d ? "Fail :(" : "OK"); + if (!d) { + Error(); + } + + Serial.println("root directory:"); + while (true) { + struct dirent* e = readdir(d); + if (!e) { + break; + } + + Serial.print(" "); + Serial.println(e->d_name); + } + + Serial.print("Closing the root directory... "); + err = closedir(d); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + + // Display the numbers file + Serial.print("Opening \"/fat/numbers.txt\"... "); + f = fopen("/fat/numbers.txt", "r"); + Serial.println(!f ? "Fail :(" : "OK"); + if (!f) { + Error(); + } + + Serial.println("numbers:"); + while (!feof(f)) { + int c = fgetc(f); + Serial.print(c); + } + + Serial.print("Closing \"/fat/numbers.txt\"... "); + err = fclose(f); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + + // Tidy up + Serial.print("Unmounting... "); + err = fat.unmount(); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + + Serial.println("Mbed OS filesystem example done!"); +} + +void loop() { + // put your main code here, to run repeatedly: +} + +void Error() { + Serial.print("ERRNO: "); + Serial.print(errno); + Serial.print("("); + Serial.print(strerror(errno)); + Serial.println(")"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/StoragePartitions.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/StoragePartitions.ino new file mode 100644 index 00000000..83185181 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/StoragePartitions.ino @@ -0,0 +1,222 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +using namespace std::chrono_literals; + +#include "edge_control_storage_limits.h" + +using namespace mbed; + +// Connect to the on-board serial flash device +// https://os.mbed.com/docs/mbed-os/v6.4/apis/spifblockdevice.html +// SPIFBlockDevice root(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_SS, 40000000); +SPIFBlockDevice root(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_SS, SPIF_FREQ); + +constexpr int USER_DATA_PARTITION{ 1 }; +constexpr int TDBS_DATA_PARTITION{ 2 }; + +// Define block devices for serial flash partitions +// https://os.mbed.com/docs/mbed-os/v6.4/apis/mbrblockdevice.html +// Partition for user filesystem (LittleFS) +MBRBlockDevice user_data(&root, USER_DATA_PARTITION); +// Partition for user keyvalu store (TDBStore) +MBRBlockDevice tdbs_data(&root, TDBS_DATA_PARTITION); + +// Define the start and stop addresses of the partitions +// Start from the first user-available block... +constexpr bd_addr_t USER_DATA_PARTITION_START{ USER_BLOCKS_START }; +// ... reserve 4MB for user filesystem... +constexpr bd_addr_t USER_DATA_PARTITION_STOP{ SPIF_SIZE / 2 }; +// ... start keyvalue store space from there... +constexpr bd_addr_t TDBS_DATA_PARTITION_START{ USER_DATA_PARTITION_STOP }; +// ... and reserve all the ramaining space until last user-available block. +constexpr bd_addr_t TDBS_DATA_PARTITION_STOP{ USER_BLOCKS_STOP }; + +// Filesystem for user data +// https://os.mbed.com/docs/mbed-os/v6.4/apis/littlefilesystem.html +// +// LittleFS is a fail-safe filesystem for embedded systems: +// this is the recommended filesystem for user data storage. +LittleFileSystem user_data_fs("user"); + +// KeyValue store for user data +// https://os.mbed.com/docs/mbed-os/v6.4/apis/kvstore.html +// ATTENTION, PLEASE! +// This is a very powerful API that can be used to create +// an EEPROM-style API using the on-board serial flash. +TDBStore tdb_store(&tdbs_data); + +// Define MbesOS Tickers for recurring tasks +// https://os.mbed.com/docs/mbed-os/v6.4/apis/ticker.html +Ticker lister; +Ticker writer; +volatile bool doList{ false }; +volatile bool doWrite{ false }; + +Timer t; + +void setup() { + int err; + + Serial.begin(115200); + while (!Serial) + ; + + delay(1000); + + Serial.println("Starting Partitions and Storage Example."); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + + // Define partition for User LittleFS filesystem + err = MBRBlockDevice::partition(&root, USER_DATA_PARTITION, 0x83, USER_DATA_PARTITION_START, USER_DATA_PARTITION_STOP); + Serial.println("Partition " + String(USER_DATA_PARTITION) + (err == 0 ? " OK" : " KO") + " (" + String(err) + ")"); + + // Define partition for User KeyValue store + err = MBRBlockDevice::partition(&root, TDBS_DATA_PARTITION, 0x83, TDBS_DATA_PARTITION_START, TDBS_DATA_PARTITION_STOP); + Serial.println("Partition " + String(TDBS_DATA_PARTITION) + (err == 0 ? " OK" : " KO") + " (" + String(err) + ")"); + + Serial.print("Mount LittleFS filesystem on Partition " + String(USER_DATA_PARTITION) + ": "); + err = user_data_fs.mount(&user_data); + if (err) { + Serial.print("No LittleFS filesystem found, formatting... "); + err = user_data_fs.reformat(&user_data); + } + Serial.println("done"); + + Serial.println("Init TinyDB Key Value store"); + err = tdb_store.init(); + Serial.println("TDB Init " + String(err == 0 ? "OK" : "KO") + " (" + String(err) + ")"); + + // Store data every 1 second + writer.attach([] { + doWrite = true; + }, + 1s); + + // Display data every 5 seconds + lister.attach([] { + doList = true; + }, + 5s); + + // Init the RNG + srand(t.elapsed_time().count()); +} + +void loop() { + if (doList) { + doList = false; + listDirs(); + } + + if (doWrite) { + doWrite = false; + storeData(); + } +} + +void storeData() { + constexpr char data_key[]{ "data_key" }; + uint8_t data_value{ 0 }; + size_t _actual; + + int res; + + // Get stored data, if any. Increment and save on success. + // Please, refer to https://os.mbed.com/docs/mbed-os/v6.4/apis/kvstore.html + // for more API use examples. + res = tdb_store.get(data_key, &data_value, sizeof(data_value), &_actual); + if (res == MBED_SUCCESS) { + Serial.print(data_key); + Serial.print(": "); + Serial.println(data_value); + data_value++; + } + tdb_store.set(data_key, &data_value, sizeof(data_value), 0); + + // Store a random key with random data + String random_key = "key_"; + random_key += String(rand(), HEX); + auto random_data = rand(); + res = tdb_store.set(random_key.c_str(), &random_data, sizeof(random_data), 0); + if (res == MBED_SUCCESS) + Serial.println(random_key + ": " + String(random_data)); + + // Append data to file on LittleFS filesystem + // Any MbedOS filesystem exposes a POSIX-compliant API: + // use the standard functions here. + FILE* f = fopen("/user/numbers.csv", "a"); + if (f != nullptr) { + String line; + line += static_cast(time(nullptr)); + line += ','; + line += data_value; + line += '\n'; + fputs(line.c_str(), f); + fclose(f); + } +} + +void listDirs() { + DIR* dir; + struct dirent* ent; + + Serial.println("Listing /user on LittleFS Filesystem"); + if ((dir = opendir("/user")) != nullptr) { + while ((ent = readdir(dir)) != nullptr) { + String fullname = "/user/" + String(ent->d_name); + Serial.println(fullname); + } + closedir(dir); + + FILE* f = fopen("/user/numbers.csv", "r+"); + if (f != nullptr) { + char buf[64]{ 0 }; + while (std::fgets(buf, sizeof buf, f) != nullptr) + Serial.print(buf); + fclose(f); + } + } + + + // Use a TDBStore iterator to retrieve all the keys + TDBStore::iterator_t it; + TDBStore::info_t info; + size_t actual_size; + + // Iterate over all the keys starting with name "key_" + tdb_store.iterator_open(&it, "key_"); + char key[128]{ 0 }; + while (tdb_store.iterator_next(it, key, sizeof(key)) != MBED_ERROR_ITEM_NOT_FOUND) { + // Get info about the key and its contents + tdb_store.get_info(key, &info); + + char buf[128]; + sprintf(buf, "Key: %-12s - Size: %d - ", key, info.size); + Serial.print(buf); + + // Get the value using parameters from the info retrieved + int out; + tdb_store.get(key, &out, info.size, &actual_size); + + // Do something useful with the key-value pair... + sprintf(buf, "Value (%d): %10d - ", actual_size, out); + Serial.print(buf); + + + // .. then (optionally) remove the key + tdb_store.remove(key); + Serial.println("Removed."); + } + // Close the iterator at the end of the cycle + tdb_store.iterator_close(it); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/edge_control_storage_limits.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/edge_control_storage_limits.h new file mode 100644 index 00000000..5a96a44a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/edge_control_storage_limits.h @@ -0,0 +1,11 @@ +#pragma once + +using namespace mbed; + + +constexpr bd_addr_t SPIF_SIZE{ 2 * 1024 * 1024 }; + +constexpr bd_addr_t USER_BLOCKS_START{ 0 }; +constexpr bd_addr_t USER_BLOCKS_STOP{ SPIF_SIZE }; + +constexpr int SPIF_FREQ{ 32'000'000 }; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/README.adoc new file mode 100644 index 00000000..a46504df --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/README.adoc @@ -0,0 +1,29 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_HTS221 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the temperature and humidity sensors of your Nano 33 BLE Sense. + + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensors/ReadSensors.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensors/ReadSensors.ino new file mode 100644 index 00000000..1fa55c64 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensors/ReadSensors.ino @@ -0,0 +1,47 @@ +/* + HTS221 - Read Sensors + + This example reads data from the on-board HTS221 sensor of the + Nano 33 BLE Sense and prints the temperature and humidity sensor + values to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!HTS.begin()) { + Serial.println("Failed to initialize humidity temperature sensor!"); + while (1) + ; + } +} + +void loop() { + // read all the sensor values + float temperature = HTS.readTemperature(); + float humidity = HTS.readHumidity(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °C"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensorsImperial/ReadSensorsImperial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensorsImperial/ReadSensorsImperial.ino new file mode 100644 index 00000000..29591d9b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensorsImperial/ReadSensorsImperial.ino @@ -0,0 +1,48 @@ +/* + HTS221 - Read Sensors Imperial + + This example reads data from the on-board HTS221 sensor of the + Nano 33 BLE Sense then, prints the temperature and humidity sensor + values in imperial units to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!HTS.begin()) { + Serial.println("Failed to initialize humidity temperature sensor!"); + while (1) + ; + } +} + +void loop() { + // Passing in FAHRENHEIT as the unit parameter to HTS.readTemperature(...), + // allows you to read the sensor values in imperial units + float temperature = HTS.readTemperature(FAHRENHEIT); + float humidity = HTS.readHumidity(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °F"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/TemperatureAlert/TemperatureAlert.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/TemperatureAlert/TemperatureAlert.ino new file mode 100644 index 00000000..456ab3c5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_HTS221/examples/TemperatureAlert/TemperatureAlert.ino @@ -0,0 +1,47 @@ +/* + HTS221 - Temperature Alert + This example reads data from the on-board HTS221 sensor of the + Nano 33 BLE Sense. If the temperature increases above a certain limit, it turns the buzzer on. + The circuit: + - Arduino Nano 33 BLE Sense + - Active buzzer module connected to pin 9 and GND + + written by K.Abhijeet + This example code is in the public domain +*/ + +#include + +float tempLimit = 37; // set your temperature limit in °C + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + pinMode(9, OUTPUT); + + if (!HTS.begin()) { + Serial.println("Failed to initialize humidity temperature sensor!"); + while (1) + ; + } +} + +void loop() { + + float temperature = HTS.readTemperature(); // read the sensor value + + Serial.print("Temperature = "); // print the sensor value + Serial.print(temperature); + Serial.println(" °C"); + + if (temperature > tempLimit) { + digitalWrite(9, HIGH); + delay(500); + digitalWrite(9, LOW); + delay(500); + } else { + delay(2000); // wait a while before displaying the next reading If the temperature is below the limit + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/README.adoc new file mode 100644 index 00000000..04f99b60 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_JSON + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Process JSON in your Arduino sketches. + +This library is based on https://github.com/DaveGamble/cJSON[cJSON]. + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONArray/JSONArray.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONArray/JSONArray.ino new file mode 100644 index 00000000..4c72f7ac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONArray/JSONArray.ino @@ -0,0 +1,105 @@ +/* + JSON Array + + This sketch demonstrates how to use various features + of the Official Arduino_JSON library, in particular for JSON arrays. + + This example code is in the public domain. +*/ + +#include + +const char input[] = "[true, 42, \"apple\"]"; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + demoParse(); + + demoCreation(); +} + +void loop() { +} + +void demoParse() { + Serial.println("parse"); + Serial.println("====="); + + JSONVar myArray = JSON.parse(input); + + // JSON.typeof(jsonVar) can be used to get the type of the variable + if (JSON.typeof(myArray) == "undefined") { + Serial.println("Parsing input failed!"); + return; + } + + Serial.print("JSON.typeof(myArray) = "); + Serial.println(JSON.typeof(myArray)); // prints: array + + // myArray.length() can be used to get the length of the array + Serial.print("myArray.length() = "); + Serial.println(myArray.length()); + Serial.println(); + + Serial.print("JSON.typeof(myArray[0]) = "); + Serial.println(JSON.typeof(myArray[0])); + + Serial.print("myArray[0] = "); + Serial.println(myArray[0]); + Serial.println(); + + Serial.print("myArray[1] = "); + Serial.println((int)myArray[1]); + Serial.println(); + + Serial.print("myArray[2] = "); + Serial.println((const char*)myArray[2]); + Serial.println(); + + Serial.println(); +} + +void demoCreation() { + Serial.println("creation"); + Serial.println("========"); + + JSONVar myArray; + + myArray[0] = false; + myArray[1] = 4242.5; + myArray[2] = "orange"; + myArray[3] = "world"; + myArray[4] = true; + myArray[5] = 42; + + Serial.print("myArray.length() = "); + Serial.println(myArray.length()); + + // JSON.stringify(myVar) can be used to convert the JSONVar to a String + String jsonString = JSON.stringify(myArray); + + Serial.print("JSON.stringify(myArray) = "); + Serial.println(jsonString); + Serial.println(); + + for (int i = 0; i < myArray.length(); i++) { + JSONVar value = myArray[i]; + + Serial.print("JSON.typeof(myArray["); + Serial.print(i); + Serial.print("]) = "); + Serial.println(JSON.typeof(value)); + + Serial.print("myArray["); + Serial.print(i); + Serial.print("] = "); + Serial.println(value); + + Serial.println(); + } + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONKitchenSink/JSONKitchenSink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONKitchenSink/JSONKitchenSink.ino new file mode 100644 index 00000000..bf95e3d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONKitchenSink/JSONKitchenSink.ino @@ -0,0 +1,166 @@ +/* + JSON Kitchen Sink + + This sketch demonstrates how to use various features + of the Official Arduino_JSON library. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // boolean + booleanDemo(); + + intDemo(); + + doubleDemo(); + + stringDemo(); + + arrayDemo(); + + objectDemo(); +} + +void loop() { +} + +void booleanDemo() { + Serial.println("boolean"); + Serial.println("======="); + + JSONVar myBoolean = true; + + Serial.print("JSON.typeof(myBoolean) = "); + Serial.println(JSON.typeof(myBoolean)); // prints: boolean + + Serial.print("myBoolean = "); + Serial.println(myBoolean); // prints: true + + myBoolean = false; + + Serial.print("myBoolean = "); + Serial.println((boolean)myBoolean); // prints: 0 + + Serial.println(); +} + +void intDemo() { + Serial.println("int"); + Serial.println("==="); + + JSONVar myInt = 42; + + Serial.print("JSON.typeof(myInt) = "); + Serial.println(JSON.typeof(myInt)); // prints: number + + Serial.print("myInt = "); + Serial.println(myInt); // prints: 42 + + myInt = 4242; + + Serial.print("myInt = "); + Serial.println((int)myInt); // prints: 4242 + + Serial.println(); +} + +void doubleDemo() { + Serial.println("double"); + Serial.println("======"); + + JSONVar myDouble = 42.5; + + Serial.print("JSON.typeof(myDouble) = "); + Serial.println(JSON.typeof(myDouble)); // prints: number + + Serial.print("myDouble = "); + Serial.println(myDouble); // prints: 42.5 + + myDouble = 4242.4242; + + Serial.print("myDouble = "); + Serial.println((double)myDouble, 4); // prints: 4242.4242 + + Serial.println(); +} + +void stringDemo() { + Serial.println("string"); + Serial.println("======"); + + JSONVar myString = "Hello World!"; + + Serial.print("JSON.typeof(myString) = "); + Serial.println(JSON.typeof(myString)); // prints: string + + Serial.print("myString = "); + Serial.println(myString); // prints: Hello World! + + myString = ":)"; + + Serial.print("myString = "); + Serial.println((const char*)myString); // prints: :) + + Serial.println(); +} + +void arrayDemo() { + Serial.println("array"); + Serial.println("====="); + + JSONVar myArray; + + myArray[0] = 42; + + Serial.print("JSON.typeof(myArray) = "); + Serial.println(JSON.typeof(myArray)); // prints: array + + Serial.print("myArray = "); + Serial.println(myArray); // prints: [42] + + Serial.print("myArray[0] = "); + Serial.println((int)myArray[0]); // prints: 42 + + myArray[1] = 42.5; + + Serial.print("myArray = "); + Serial.println(myArray); // prints: [42,42.5] + + Serial.print("myArray[1] = "); + Serial.println((double)myArray[1]); // prints: 42.50 + + Serial.println(); +} + +void objectDemo() { + Serial.println("object"); + Serial.println("======"); + + JSONVar myObject; + + myObject["foo"] = "bar"; + + Serial.print("JSON.typeof(myObject) = "); + Serial.println(JSON.typeof(myObject)); // prints: object + + Serial.print("myObject.keys() = "); + Serial.println(myObject.keys()); // prints: ["foo"] + + Serial.print("myObject = "); + Serial.println(myObject); // prints: {"foo":"bar"} + + myObject["blah"]["abc"] = 42; + + Serial.print("myObject.keys() = "); + Serial.println(myObject.keys()); // prints: ["foo","blah"] + + Serial.print("myObject = "); + Serial.println(myObject); // prints: {"foo":"bar","blah":{"abc":42}} +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONObject/JSONObject.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONObject/JSONObject.ino new file mode 100644 index 00000000..419de8e2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_JSON/examples/JSONObject/JSONObject.ino @@ -0,0 +1,124 @@ +/* + JSON Object + + This sketch demonstrates how to use various features + of the Official Arduino_JSON library, in particular for JSON objects. + + This example code is in the public domain. +*/ + +#include + +const char input[] = "{\"result\":true,\"count\":42,\"foo\":\"bar\"}"; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + demoParse(); + + demoCreation(); +} + +void loop() { +} + +void demoParse() { + Serial.println("parse"); + Serial.println("====="); + + JSONVar myObject = JSON.parse(input); + + // JSON.typeof(jsonVar) can be used to get the type of the variable + if (JSON.typeof(myObject) == "undefined") { + Serial.println("Parsing input failed!"); + return; + } + + Serial.print("JSON.typeof(myObject) = "); + Serial.println(JSON.typeof(myObject)); // prints: object + + // myObject.hasOwnProperty(key) checks if the object contains an entry for key + if (myObject.hasOwnProperty("result")) { + Serial.print("myObject[\"result\"] = "); + + Serial.println((bool)myObject["result"]); + } + + if (myObject.hasOwnProperty("count")) { + Serial.print("myObject[\"count\"] = "); + + Serial.println((int)myObject["count"]); + } + + if (myObject.hasOwnProperty("count")) { + Serial.print("myObject[\"count\"] = "); + + Serial.println((double)myObject["count"]); + } + + if (myObject.hasOwnProperty("foo")) { + Serial.print("myObject[\"foo\"] = "); + + Serial.println((const char*)myObject["foo"]); + } + + // JSONVars can be printed using print or println + Serial.print("myObject = "); + Serial.println(myObject); + + Serial.println(); +} + +void demoCreation() { + Serial.println("creation"); + Serial.println("========"); + + JSONVar myObject; + + myObject["hello"] = "world"; + myObject["true"] = true; + myObject["x"] = 42; + + Serial.print("myObject.keys() = "); + Serial.println(myObject.keys()); + + // JSON.stringify(myVar) can be used to convert the JSONVar to a String + String jsonString = JSON.stringify(myObject); + + Serial.print("JSON.stringify(myObject) = "); + Serial.println(jsonString); + + Serial.println(); + + // myObject.keys() can be used to get an array of all the keys in the object + JSONVar keys = myObject.keys(); + + for (int i = 0; i < keys.length(); i++) { + JSONVar value = myObject[keys[i]]; + + Serial.print("JSON.typeof(myObject["); + Serial.print(keys[i]); + Serial.print("]) = "); + Serial.println(JSON.typeof(value)); + + Serial.print("myObject["); + Serial.print(keys[i]); + Serial.print("] = "); + Serial.println(value); + + Serial.println(); + } + + Serial.println(); + + // setting a value to undefined can remove it from the object + myObject["x"] = undefined; + + // you can also change a value + myObject["hello"] = "there!"; + + Serial.print("myObject = "); + Serial.println(myObject); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/README.adoc new file mode 100644 index 00000000..157ea387 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/README.adoc @@ -0,0 +1,29 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_LPS22HB + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the pressure sensor of your Nano 33 BLE Sense. + + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressure/ReadPressure.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressure/ReadPressure.ino new file mode 100644 index 00000000..82402f4f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressure/ReadPressure.ino @@ -0,0 +1,49 @@ +/* + LPS22HB - Read Pressure + + This example reads data from the on-board LPS22HB sensor of the + Nano 33 BLE Sense and prints the temperature and pressure sensor + value to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!BARO.begin()) { + Serial.println("Failed to initialize pressure sensor!"); + while (1) + ; + } +} + +void loop() { + // read the sensor value + float pressure = BARO.readPressure(); + + // print the sensor value + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" kPa"); + + float temperature = BARO.readTemperature(); + + // print the sensor value + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" C"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressureImperial/ReadPressureImperial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressureImperial/ReadPressureImperial.ino new file mode 100644 index 00000000..e7203629 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressureImperial/ReadPressureImperial.ino @@ -0,0 +1,50 @@ +/* + LPS22HB - Read Pressure Imperial + + This example reads data from the on-board LPS22HB sensor of the + Nano 33 BLE Sense and prints the temperature and pressure sensor + value in imperial units to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!BARO.begin()) { + Serial.println("Failed to initialize pressure sensor!"); + while (1) + ; + } +} + +void loop() { + // Passing PSI to readPressure(...) + // allows you to read the sensor values in imperial units + float pressure = BARO.readPressure(PSI); + + // print the sensor value + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" psi"); + + float temperature = BARO.readTemperature(); + + // print the sensor value + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" C"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/README.adoc new file mode 100644 index 00000000..81f5ae88 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/README.adoc @@ -0,0 +1,12 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_LSM6DS3 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the accelerometer and gyroscope values from the LSM6DS3 IMU on your Arduino Nano 33 IoT or Arduino Uno WiFi Rev2 boards. + +For more information about this library please visit us at https://www.arduino.cc/reference/en/libraries/arduino_lsm6ds3/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleAccelerometer/SimpleAccelerometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleAccelerometer/SimpleAccelerometer.ino new file mode 100644 index 00000000..d41c5748 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleAccelerometer/SimpleAccelerometer.ino @@ -0,0 +1,51 @@ +/* + Arduino LSM6DS3 - Simple Accelerometer + + This example reads the acceleration values from the LSM6DS3 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1) + ; + } + + Serial.print("Accelerometer sample rate = "); + Serial.print(IMU.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Acceleration in g's"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.accelerationAvailable()) { + IMU.readAcceleration(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleGyroscope/SimpleGyroscope.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleGyroscope/SimpleGyroscope.ino new file mode 100644 index 00000000..db0e84e2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleGyroscope/SimpleGyroscope.ino @@ -0,0 +1,51 @@ +/* + Arduino LSM6DS3 - Simple Gyroscope + + This example reads the gyroscope values from the LSM6DS3 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1) + ; + } + + Serial.print("Gyroscope sample rate = "); + Serial.print(IMU.gyroscopeSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Gyroscope in degrees/second"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.gyroscopeAvailable()) { + IMU.readGyroscope(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/README.adoc new file mode 100644 index 00000000..d4cd7b51 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/README.adoc @@ -0,0 +1,10 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_LSM9DS1 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the accelerometer, magnetometer and gyroscope values from the LSM9DS1 IMU on your Arduino Nano 33 BLE Sense. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleAccelerometer/SimpleAccelerometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleAccelerometer/SimpleAccelerometer.ino new file mode 100644 index 00000000..1b084d99 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleAccelerometer/SimpleAccelerometer.ino @@ -0,0 +1,51 @@ +/* + Arduino LSM9DS1 - Simple Accelerometer + + This example reads the acceleration values from the LSM9DS1 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Nano 33 BLE Sense + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + Serial.println("Started"); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1) + ; + } + + Serial.print("Accelerometer sample rate = "); + Serial.print(IMU.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Acceleration in g's"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.accelerationAvailable()) { + IMU.readAcceleration(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleGyroscope/SimpleGyroscope.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleGyroscope/SimpleGyroscope.ino new file mode 100644 index 00000000..8e5f7059 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleGyroscope/SimpleGyroscope.ino @@ -0,0 +1,50 @@ +/* + Arduino LSM9DS1 - Simple Gyroscope + + This example reads the gyroscope values from the LSM9DS1 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Nano 33 BLE Sense + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + Serial.println("Started"); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1) + ; + } + Serial.print("Gyroscope sample rate = "); + Serial.print(IMU.gyroscopeSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Gyroscope in degrees/second"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.gyroscopeAvailable()) { + IMU.readGyroscope(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleMagnetometer/SimpleMagnetometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleMagnetometer/SimpleMagnetometer.ino new file mode 100644 index 00000000..be5c76aa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleMagnetometer/SimpleMagnetometer.ino @@ -0,0 +1,50 @@ +/* + Arduino LSM9DS1 - Simple Magnetometer + + This example reads the magnetic field values from the LSM9DS1 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Nano 33 BLE Sense + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + Serial.println("Started"); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1) + ; + } + Serial.print("Magnetic field sample rate = "); + Serial.print(IMU.magneticFieldSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Magnetic Field in uT"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.magneticFieldAvailable()) { + IMU.readMagneticField(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/README.md new file mode 100644 index 00000000..993484a5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/README.md @@ -0,0 +1,32 @@ +# MCHPTouch Library for Arduino + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/spell-check.yml) + +This library allows you to read touch sensors values from the [Arduino MKR](https://store.arduino.cc/arduino-mkr-wifi-1010) boards and the [Arduino Nano 33 IoT](https://store.arduino.cc/arduino-nano-33-iot). Touch sensing is a hardware capability of the SAMD21 processor. + +```c++ +#include "Arduino_MCHPTouch.h" + +void setup() { + TOUCH.begin(); +} + +void loop() { + TOUCH.poll(); + if (TOUCH.available()) { + int value = TOUCH.read(0); // read sensor 0 + } +} +``` + +See the bundled [examples](examples/) for usage and visit the [Microchip Developer](https://microchipdeveloper.com/touch:start) website to learn more about touch sensing. + +## License + +This library is a wrapper around the MCHPTouch library by Microchip, which is bundled in binary form in this distribution in agreement with Microchip. + +> Microchip Technology Inc., provides the Microchip Touch Library software subject to the license terms contained at the link below.  By using the Microchip Touch Library, you acknowledge and agree to the terms of the license contained at the link below. [Microchip Touch Library License Agreement](Microchip%20Touch%20Library%20License%20Agreement%20-%20Arduino%20082420.pdf) + +The Arduino_MCHPTouch wrapper library is distributed under the terms of the MPL-2.0 license. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/examples/ReadSensors/ReadSensors.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/examples/ReadSensors/ReadSensors.ino new file mode 100644 index 00000000..57e23728 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/examples/ReadSensors/ReadSensors.ino @@ -0,0 +1,48 @@ +/* + Arduino_MCHPTouch - Sensor data read example + This example shows how to configure and read data + from touch sensor buttons on MKR IoT Carrier and + prints updates to the Serial Monitor. + + The circuit: + - Arduino MKR board + - MKR IoT Carrier + + This example code is in the public domain. +*/ +#include "Arduino_MCHPTouch.h" + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + // QTouch initialization + if (!TOUCH.begin()) { + Serial.println("Error in sensors initialization!"); + while (1) + ; + } + Serial.println("Touch initialization Done!"); +} + +void loop() { + // polling the sensor for new data + TOUCH.poll(); + + // Checks if new data are available + if (TOUCH.available()) { + //reads senseors + Serial.print("Sensor 1 status: "); + Serial.println(TOUCH.read(0)); + Serial.print("Sensor 2 status: "); + Serial.println(TOUCH.read(1)); + Serial.print("Sensor 3 status: "); + Serial.println(TOUCH.read(2)); + Serial.print("Sensor 4 status: "); + Serial.println(TOUCH.read(3)); + Serial.print("Sensor 5 status: "); + Serial.println(TOUCH.read(4)); + Serial.println(); + } + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/examples/setCustomSensitivity/setCustomSensitivity.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/examples/setCustomSensitivity/setCustomSensitivity.ino new file mode 100644 index 00000000..c6dfd59a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MCHPTouch/examples/setCustomSensitivity/setCustomSensitivity.ino @@ -0,0 +1,52 @@ +/* + Arduino_MCHPTouch - Sensor data read example + This example shows how to configure and read data + from touch sensor buttons on MKR IoT Carrier and + prints updates to the Serial Monitor. + + The circuit: + - Arduino MKR board + - MKR IoT Carrier + + This example code is in the public domain. +*/ +#include "Arduino_MCHPTouch.h" + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + //Set custom sensitivity on X channel + //TOUCH.setSensorsSensitivity(*newSensitivity*, channel); + TOUCH.setSensorsSensitivity(98, 0); + // QTouch initialization + if (!TOUCH.begin()) { + Serial.println("Error in sensors initialization!"); + while (1) + ; + } + Serial.println("Touch initialization Done!"); +} + +void loop() { + // polling the sensor for new measure + TOUCH.poll(); + + // Checks if new data are available + if (TOUCH.available()) { + //reads sensors + + Serial.print("Sensor 1 status: "); + Serial.println(TOUCH.read(0)); + Serial.print("Sensor 2 status: "); + Serial.println(TOUCH.read(1)); + Serial.print("Sensor 3 status: "); + Serial.println(TOUCH.read(2)); + Serial.print("Sensor 4 status: "); + Serial.println(TOUCH.read(3)); + Serial.print("Sensor 5 status: "); + Serial.println(TOUCH.read(4)); + Serial.println(); + } + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/README.adoc new file mode 100644 index 00000000..9a36c5cc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_MKRENV + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the temperature, humidity, pressure, light and UV sensors of your MKR ENV shield. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensors/ReadSensors.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensors/ReadSensors.ino new file mode 100644 index 00000000..68fe6ebb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensors/ReadSensors.ino @@ -0,0 +1,69 @@ +/* + MKR ENV Shield - Read Sensors + + This example reads the sensors on-board the MKR ENV Shield + and prints them to the Serial Monitor once a second. + + The circuit: + - Arduino MKR board + - Arduino MKR ENV Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ENV.begin()) { + Serial.println("Failed to initialize MKR ENV Shield!"); + while (1) + ; + } +} + +void loop() { + // read all the sensor values + float temperature = ENV.readTemperature(); + float humidity = ENV.readHumidity(); + float pressure = ENV.readPressure(); + float illuminance = ENV.readIlluminance(); + float uva = ENV.readUVA(); + float uvb = ENV.readUVB(); + float uvIndex = ENV.readUVIndex(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °C"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" kPa"); + + Serial.print("Illuminance = "); + Serial.print(illuminance); + Serial.println(" lx"); + + Serial.print("UVA = "); + Serial.println(uva); + + Serial.print("UVB = "); + Serial.println(uvb); + + Serial.print("UV Index = "); + Serial.println(uvIndex); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensorsImperial/ReadSensorsImperial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensorsImperial/ReadSensorsImperial.ino new file mode 100644 index 00000000..1f99829d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensorsImperial/ReadSensorsImperial.ino @@ -0,0 +1,71 @@ +/* + MKR ENV Shield - Read Sensors Imperial + + This example reads the sensors on-board the MKR ENV Shield + and prints them in imperial units to the Serial Monitor once a second. + + The circuit: + - Arduino MKR board + - Arduino MKR ENV Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ENV.begin()) { + Serial.println("Failed to initialize MKR ENV Shield!"); + while (1) + ; + } +} + +void loop() { + // Passing in FAHRENHEIT as the unit parameter to ENV.readTemperature(...), + // PSI to readPressure(...) and FOOTCANDLE to readIlluminance(...) + // allows you to read the sensor values in imperial units + float temperature = ENV.readTemperature(FAHRENHEIT); + float humidity = ENV.readHumidity(); + float pressure = ENV.readPressure(PSI); + float illuminance = ENV.readIlluminance(FOOTCANDLE); + float uva = ENV.readUVA(); + float uvb = ENV.readUVB(); + float uvIndex = ENV.readUVIndex(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °F"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" psi"); + + Serial.print("Illuminance = "); + Serial.print(illuminance); + Serial.println(" fc"); + + Serial.print("UVA = "); + Serial.println(uva); + + Serial.print("UVB = "); + Serial.println(uvb); + + Serial.print("UV Index = "); + Serial.println(uvIndex); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/README.adoc new file mode 100644 index 00000000..9e61f2f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/README.adoc @@ -0,0 +1,14 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_MKRGPS + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the location from the GPS on your MKR GPS Shield. + +This library is based on https://github.com/kosma/minmea[minmea]. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/ArduinoMKRGPS diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocation/GPSLocation.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocation/GPSLocation.ino new file mode 100644 index 00000000..7c26eb1e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocation/GPSLocation.ino @@ -0,0 +1,61 @@ +/* + GPS Location + + This sketch uses the GPS to determine the location of the board + and prints it to the Serial Monitor. + + Circuit: + - MKR board + - MKR GPS Shield attached via I2C cable + + This example code is in the public domain. +*/ + +#include + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // If you are using the MKR GPS as shield, change the next line to pass + // the GPS_MODE_SHIELD parameter to the GPS.begin(...) + if (!GPS.begin()) { + Serial.println("Failed to initialize GPS!"); + while (1) + ; + } +} + +void loop() { + // check if there is new GPS data available + if (GPS.available()) { + // read GPS values + float latitude = GPS.latitude(); + float longitude = GPS.longitude(); + float altitude = GPS.altitude(); + float speed = GPS.speed(); + int satellites = GPS.satellites(); + + // print GPS values + Serial.print("Location: "); + Serial.print(latitude, 7); + Serial.print(", "); + Serial.println(longitude, 7); + + Serial.print("Altitude: "); + Serial.print(altitude); + Serial.println("m"); + + Serial.print("Ground speed: "); + Serial.print(speed); + Serial.println(" km/h"); + + Serial.print("Number of satellites: "); + Serial.println(satellites); + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocationStandy/GPSLocationStandy.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocationStandy/GPSLocationStandy.ino new file mode 100644 index 00000000..a2b5e761 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocationStandy/GPSLocationStandy.ino @@ -0,0 +1,83 @@ +/* + GPS Location Standby + + This sketch uses the GPS to determine the location of the board + and prints it to the Serial Monitor. + + It puts the GPS into standby mode every 10 seconds, then wakes it up. + + Circuit: + - MKR board + - MKR GPS Shield attached via I2C cable + + This example code is in the public domain. +*/ + +#include + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // If you are using the MKR GPS as shield, change the next line to pass + // the GPS_MODE_SHIELD parameter to the GPS.begin(...) + if (!GPS.begin()) { + Serial.println("Failed to initialize GPS!"); + while (1) + ; + } +} + +void loop() { + // put the GPS in standby mode + Serial.println("standby"); + GPS.standby(); + + // wait for 10 seconds + Serial.print("delay "); + for (int i = 0; i < 10; i++) { + delay(1000); + Serial.print("."); + } + Serial.println(); + + // wake up the GPS + Serial.println("wakeup"); + GPS.wakeup(); + + Serial.print("wait location ... "); + + // wait for new GPS data to become available + unsigned long startMillis = millis(); + while (!GPS.available()) + ; + unsigned long endMillis = millis(); + + Serial.print(endMillis - startMillis); + Serial.println(" ms"); + + // read GPS values + float latitude = GPS.latitude(); + float longitude = GPS.longitude(); + float altitude = GPS.altitude(); + int satellites = GPS.satellites(); + + // print GPS values + Serial.println(); + Serial.print("Location: "); + Serial.print(latitude, 7); + Serial.print(", "); + Serial.println(longitude, 7); + + Serial.print("Altitude: "); + Serial.print(altitude); + Serial.println("m"); + + Serial.print("Number of satellites: "); + Serial.println(satellites); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/LICENSE new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/Readme.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/Readme.md new file mode 100644 index 00000000..6dba21b7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/Readme.md @@ -0,0 +1,34 @@ +# MKRIoTCarrier + +[![Compiling](https://github.com/arduino-libraries/Arduino_MKRIoTCarrier/actions/workflows/Compile%20Examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MKRIoTCarrier/actions/workflows/Compile%20Examples.yml) + +This library enables the MKR family to use the MKR IoT Carrier + +Get the carrier: + * [Standalone Board](https://store.arduino.cc/mkr-iot-carrier) + * Kits: + * [Explore IoT Kit](https://store.arduino.cc/explore-iot-kit) + * [Oplà IoT Kit](https://store.arduino.cc/opla-iot-kit) + + + +For more information about this library please visit us at +https://www.arduino.cc/reference/en/libraries/arduino_mkriotcarrier/ + +## License + +Copyright (c) 2020 Arduino AG. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/Buzzer_Melody.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/Buzzer_Melody.ino new file mode 100644 index 00000000..46a0b6c8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/Buzzer_Melody.ino @@ -0,0 +1,44 @@ +/* + Melody + + Adapted for the Arduino MKR IoT Carrier + +*/ +#include +#include "pitches.h" + +MKRIoTCarrier carrier; + +// notes in the melody: +int melody[] = { + NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 +}; + +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations[] = { + 4, 8, 8, 4, 4, 4, 4, 4 +}; + +void setup() { + carrier.begin(); + + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < 8; thisNote++) { + + // to calculate the note duration, take one second divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 1000 / noteDurations[thisNote]; + carrier.Buzzer.sound(melody[thisNote]); + delay(noteDuration); + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.30; + delay(pauseBetweenNotes); + // stop the tone playing: + carrier.Buzzer.noSound(); + } +} + +void loop() { + // no need to repeat the melody. +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/pitches.h new file mode 100644 index 00000000..f3037d5e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Relays_blink/Relays_blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Relays_blink/Relays_blink.ino new file mode 100644 index 00000000..2de0cfbb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Relays_blink/Relays_blink.ino @@ -0,0 +1,30 @@ +#include + +MKRIoTCarrier carrier; + +void setup() { + + Serial.begin(9600); + Serial.println("Init"); + carrier.noCase(); + carrier.begin(); +} + +void loop() { + //Switch to NO + carrier.Relay1.open(); + carrier.Relay2.open(); + Serial.println("Both Relays switched to NO"); + delay(2500); + + + //Switch to NC + carrier.Relay1.close(); + carrier.Relay2.close(); + Serial.println("Both Relays switched to NC"); + + //Get status + Serial.print("Relay 1 is: "); + Serial.println(carrier.Relay1.getStatus()); + delay(2500); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/All_Features/All_Features.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/All_Features/All_Features.ino new file mode 100644 index 00000000..17f34c9f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/All_Features/All_Features.ino @@ -0,0 +1,191 @@ +/* +This sketch will test the carrier board +Unless the touch pads +*/ + +#include +MKRIoTCarrier carrier; //Constructor of the carrier maybe we can include it on the library itself + +float temperature; +float humidity; + +int light; +int r, g, b; + +float pressure; + +float Gx, Gy, Gz; +float Ax, Ay, Az; + +void setup() { + // put your setup code here, to run once: + //Start Serial comm + Serial.begin(9600); + while (!Serial) + ; //Wait to open the Serial monitor to start the program and see details on errors + + //Init everything and outputs the errors + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + //LED show up + //( led index , red , green , blue ) + carrier.leds.setPixelColor(0, 0, 0, 20); + carrier.leds.setPixelColor(1, 0, 20, 0); + carrier.leds.setPixelColor(2, 20, 0, 0); + carrier.leds.setPixelColor(3, 0, 20, 20); + carrier.leds.setPixelColor(4, 20, 20, 20); + carrier.leds.show(); + + //Function to display + displayTitle(); + + //Buzzer sound sound(freq) + /* + * Can be used also with tone(BUZZER , freq); + */ + carrier.Buzzer.sound(8000); + delay(100); + carrier.Buzzer.noSound(); + + //Simple relay open and close loop + /* Relay function + open() - goes to Normally Open (NO) circuit, status LED will be ON + close() - goes to Normally Close (NC) circuit, status LED will be OFF + */ + carrier.Relay1.close(); + delay(1000); + printStatus(); + delay(100); + + carrier.Relay1.open(); + delay(1000); + printStatus(); + delay(100); + + printStatus(); + carrier.Relay2.close(); + delay(1000); + printStatus(); + delay(100); + + carrier.Relay2.open(); + delay(1000); + printStatus(); + delay(100); + + delay(1000); + + //SENSORS + //RGB and Light sensor + //It set the values that you point inside the brackets + while (!carrier.Light.colorAvailable()) { + delay(5); + } + carrier.Light.readColor(r, g, b, light); + Serial.println("Ambient light sensor"); + Serial.print("\t light: "); + Serial.println(light); + displayLight(); + + //Env sensor (Temp and Hum) + temperature = carrier.Env.readTemperature(); + humidity = carrier.Env.readHumidity(); + Serial.println("Env sensor"); + Serial.print("\t Temperature:"); + Serial.println(temperature); + Serial.print("\t Humidity: "); + Serial.println(humidity); + displayEnv(); + + //Barometric sensor + pressure = carrier.Pressure.readPressure(); + Serial.println("Barometric sensor"); + Serial.print("\t Pressure:"); + Serial.println(pressure); + displayBaro(); + + //IMU + //Gyroscope + Serial.println("IMU module"); + carrier.IMUmodule.readGyroscope(Gx, Gy, Gz); + Serial.println("Gyroscope:"); + Serial.print("\t X:"); + Serial.println(Gx); + Serial.print("\t Y:"); + Serial.println(Gy); + Serial.print("\t Z:"); + Serial.println(Gz); + + //Accelerometer + carrier.IMUmodule.readAcceleration(Ax, Ay, Az); + Serial.println("Accelerometer:"); + Serial.print("\t X:"); + Serial.println(Ax); + Serial.print("\t Y:"); + Serial.println(Ay); + Serial.print("\t Z:"); + Serial.println(Az); + + Serial.println(); + Serial.println("--- \t END OF READS \t ---"); + Serial.println(); +} + +void displayTitle() { + carrier.display.fillScreen(ST77XX_BLACK); + + carrier.display.setCursor(80, 120); + carrier.display.setTextColor(ST77XX_RED); + carrier.display.print("MKR "); + carrier.display.setTextColor(ST77XX_GREEN); + carrier.display.print("IoT "); + carrier.display.setTextColor(ST77XX_MAGENTA); + carrier.display.print("Carrier"); + carrier.display.setCursor(105, 130); + carrier.display.setTextColor(ST77XX_WHITE); + carrier.display.print("Library"); +} + +void printStatus() { + carrier.display.fillScreen(ST77XX_BLACK); //oled clear() + carrier.display.setCursor(70, 100); + carrier.display.setTextColor(ST77XX_BLUE); + carrier.display.print("Relay 1 status: "); + carrier.display.setTextColor(ST77XX_RED); + carrier.display.print(carrier.Relay1.getStatus()); + + carrier.display.setCursor(70, 120); + carrier.display.setTextColor(ST77XX_BLUE); + carrier.display.print("Relay 2 status: "); + carrier.display.setTextColor(ST77XX_RED); + carrier.display.print(carrier.Relay2.getStatus()); +} + +void displayLight() { + carrier.display.fillScreen(ST77XX_BLACK); //oled clear() + carrier.display.setCursor(70, 100); + carrier.display.print("Light: "); + carrier.display.setTextColor(ST77XX_MAGENTA); + carrier.display.print(light); + delay(2500); +} + +void displayEnv() { + carrier.display.fillScreen(ST77XX_BLACK); //oled clear() + carrier.display.setCursor(70, 100); + carrier.display.print("Humidity: "); + carrier.display.setTextColor(ST77XX_MAGENTA); + carrier.display.print(humidity); + carrier.display.setCursor(70, 115); + carrier.display.print("Temperature: "); + carrier.display.setTextColor(ST77XX_BLUE); + carrier.display.print(temperature); + delay(2500); +} + +void displayBaro() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Compose_images/Compose_images.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Compose_images/Compose_images.ino new file mode 100644 index 00000000..299adbb0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Compose_images/Compose_images.ino @@ -0,0 +1,87 @@ +/************************************************************************** + This example shows how to compose images from bitmaps + + We have used this tool to convert the .bmp to cpp + https://javl.github.io/image2cpp/ + Thanks! + + **************************************************************************/ +#include "Images.h" //We save the images code there +#include +MKRIoTCarrier carrier; + + +uint32_t orange = carrier.leds.Color(50, 242, 0); + +void setup() { + Serial.begin(9600); + carrier.noCase(); + carrier.begin(); + + uint16_t time = millis(); + carrier.display.fillScreen(ST77XX_BLACK); + time = millis() - time; + + carrier.leds.fill(orange, 0, 5); + carrier.leds.setBrightness(15); + carrier.leds.show(); +} + +int i = 0; +int ledC = 0; +int ledA = 0; + +void loop() { + carrier.display.fillScreen(ST77XX_BLACK); + drawArduino(0x04B3); + fadeLoop(); + carrier.display.fillScreen(ST77XX_BLACK); + drawEIoT(); + fadeLoop(); + + carrier.display.fillScreen(ST77XX_WHITE); + drawArduino(0x0000); + fadeLoop(); + + drawArduino(0xF324); + fadeLoop(); + drawArduino(0x04B3); + fadeLoop(); + + carrier.display.fillScreen(ST77XX_WHITE); + drawEIoT(); + fadeLoop(); +} + +//Fading Orange loop +void fadeLoop() { + carrier.leds.fill(orange, ledA, ledC); + for (i = 0; i < 125; i++) { + carrier.leds.setBrightness(i); + carrier.leds.show(); + delay(10); + } + + for (i = 125; i > -1; i--) { + carrier.leds.setBrightness(i); + carrier.leds.show(); + delay(10); + } + carrier.leds.clear(); + delay(500); +} + +//Compose the differentn parts of the image +void drawEIoT() { + carrier.display.drawBitmap(44, 25, ArduinoLogo, 152, 72, 0x04B3); + carrier.display.drawBitmap(48, 110, ArduinoText, 144, 23, 0x04B3); + carrier.display.drawBitmap(0, 150, ExploreFrame, 240, 75, 0xF324); + carrier.display.drawBitmap(0, 150, ExplreIoTKittext, 240, 75, 0x04B3); + carrier.display.drawBitmap(0, 150, ExploreIoTtext, 240, 75, 0xFFFF); +} + +//Same with the Arduino Logo and the text +void drawArduino(uint16_t color) { + carrier.display.drawBitmap(44, 60, ArduinoLogo, 152, 72, color); + carrier.display.drawBitmap(48, 145, ArduinoText, 144, 23, color); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Graphics/Graphics.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Graphics/Graphics.ino new file mode 100644 index 00000000..5e829922 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Graphics/Graphics.ino @@ -0,0 +1,263 @@ +/************************************************************************** + This example orignillay from Adafruit ST7735 library, just converted for the carrier usage + **************************************************************************/ + +#include +MKRIoTCarrier carrier; + +float p = 3.1415926; + +void setup(void) { + + Serial.begin(9600); + Serial.print(F("Hello! ST77xx TFT Test")); + carrier.noCase(); + carrier.begin(); + + uint16_t time = millis(); + carrier.display.fillScreen(ST77XX_BLACK); + time = millis() - time; + + Serial.println(time, DEC); + delay(500); + + // large block of text + carrier.display.fillScreen(ST77XX_BLACK); + testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE); + delay(1000); + + // tft print function! + tftPrintTest(); + delay(4000); + + // a single pixel + carrier.display.drawPixel(carrier.display.width() / 2, carrier.display.height() / 2, ST77XX_GREEN); + delay(500); + + // line draw test + testlines(ST77XX_YELLOW); + delay(500); + + // optimized lines + testfastlines(ST77XX_RED, ST77XX_BLUE); + delay(500); + + testdrawrects(ST77XX_GREEN); + delay(500); + + testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA); + delay(500); + + carrier.display.fillScreen(ST77XX_BLACK); + testfillcircles(10, ST77XX_BLUE); + testdrawcircles(10, ST77XX_WHITE); + delay(500); + + testroundrects(); + delay(500); + + testtriangles(); + delay(500); + + mediabuttons(); + delay(500); + + Serial.println("done"); + delay(1000); +} + +void loop() { + carrier.display.invertDisplay(true); + delay(500); + carrier.display.invertDisplay(false); + delay(500); +} + +void testlines(uint16_t color) { + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawLine(0, 0, x, carrier.display.height() - 1, color); + delay(0); + } + for (int16_t y = 0; y < carrier.display.height(); y += 6) { + carrier.display.drawLine(0, 0, carrier.display.width() - 1, y, color); + delay(0); + } + + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawLine(carrier.display.width() - 1, 0, x, carrier.display.height() - 1, color); + delay(0); + } + for (int16_t y = 0; y < carrier.display.height(); y += 6) { + carrier.display.drawLine(carrier.display.width() - 1, 0, 0, y, color); + delay(0); + } + + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawLine(0, carrier.display.height() - 1, x, 0, color); + delay(0); + } + for (int16_t y = 0; y < carrier.display.height(); y += 6) { + carrier.display.drawLine(0, carrier.display.height() - 1, carrier.display.width() - 1, y, color); + delay(0); + } + + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawLine(carrier.display.width() - 1, carrier.display.height() - 1, x, 0, color); + delay(0); + } + for (int16_t y = 0; y < carrier.display.height(); y += 6) { + carrier.display.drawLine(carrier.display.width() - 1, carrier.display.height() - 1, 0, y, color); + delay(0); + } +} + +void testdrawtext(char *text, uint16_t color) { + carrier.display.setCursor(0, 0); + carrier.display.setTextColor(color); + carrier.display.setTextWrap(true); + carrier.display.print(text); +} + +void testfastlines(uint16_t color1, uint16_t color2) { + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t y = 0; y < carrier.display.height(); y += 5) { + carrier.display.drawFastHLine(0, y, carrier.display.width(), color1); + } + for (int16_t x = 0; x < carrier.display.width(); x += 5) { + carrier.display.drawFastVLine(x, 0, carrier.display.height(), color2); + } +} + +void testdrawrects(uint16_t color) { + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawRect(carrier.display.width() / 2 - x / 2, carrier.display.height() / 2 - x / 2, x, x, color); + } +} + +void testfillrects(uint16_t color1, uint16_t color2) { + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = carrier.display.width() - 1; x > 6; x -= 6) { + carrier.display.fillRect(carrier.display.width() / 2 - x / 2, carrier.display.height() / 2 - x / 2, x, x, color1); + carrier.display.drawRect(carrier.display.width() / 2 - x / 2, carrier.display.height() / 2 - x / 2, x, x, color2); + } +} + +void testfillcircles(uint8_t radius, uint16_t color) { + for (int16_t x = radius; x < carrier.display.width(); x += radius * 2) { + for (int16_t y = radius; y < carrier.display.height(); y += radius * 2) { + carrier.display.fillCircle(x, y, radius, color); + } + } +} + +void testdrawcircles(uint8_t radius, uint16_t color) { + for (int16_t x = 0; x < carrier.display.width() + radius; x += radius * 2) { + for (int16_t y = 0; y < carrier.display.height() + radius; y += radius * 2) { + carrier.display.drawCircle(x, y, radius, color); + } + } +} + +void testtriangles() { + carrier.display.fillScreen(ST77XX_BLACK); + uint16_t color = 0xF800; + int t; + int w = carrier.display.width() / 2; + int x = carrier.display.height() - 1; + int y = 0; + int z = carrier.display.width(); + for (t = 0; t <= 15; t++) { + carrier.display.drawTriangle(w, y, y, x, z, x, color); + x -= 4; + y += 4; + z -= 4; + color += 100; + } +} + +void testroundrects() { + carrier.display.fillScreen(ST77XX_BLACK); + uint16_t color = 100; + int i; + int t; + for (t = 0; t <= 4; t += 1) { + int x = 0; + int y = 0; + int w = carrier.display.width() - 2; + int h = carrier.display.height() - 2; + for (i = 0; i <= 16; i += 1) { + carrier.display.drawRoundRect(x, y, w, h, 5, color); + x += 2; + y += 3; + w -= 4; + h -= 6; + color += 1100; + } + color += 100; + } +} + +void tftPrintTest() { + carrier.display.setTextWrap(false); + carrier.display.fillScreen(ST77XX_BLACK); + carrier.display.setCursor(0, 30); + carrier.display.setTextColor(ST77XX_RED); + carrier.display.setTextSize(1); + carrier.display.println("Hello World!"); + carrier.display.setTextColor(ST77XX_YELLOW); + carrier.display.setTextSize(2); + carrier.display.println("Hello World!"); + carrier.display.setTextColor(ST77XX_GREEN); + carrier.display.setTextSize(3); + carrier.display.println("Hello World!"); + carrier.display.setTextColor(ST77XX_BLUE); + carrier.display.setTextSize(4); + carrier.display.print(1234.567); + delay(1500); + carrier.display.setCursor(0, 0); + carrier.display.fillScreen(ST77XX_BLACK); + carrier.display.setTextColor(ST77XX_WHITE); + carrier.display.setTextSize(0); + carrier.display.println("Hello World!"); + carrier.display.setTextSize(1); + carrier.display.setTextColor(ST77XX_GREEN); + carrier.display.print(p, 6); + carrier.display.println(" Want pi?"); + carrier.display.println(" "); + carrier.display.print(8675309, HEX); // print 8,675,309 out in HEX! + carrier.display.println(" Print HEX!"); + carrier.display.println(" "); + carrier.display.setTextColor(ST77XX_WHITE); + carrier.display.println("Sketch has been"); + carrier.display.println("running for: "); + carrier.display.setTextColor(ST77XX_MAGENTA); + carrier.display.print(millis() / 1000); + carrier.display.setTextColor(ST77XX_WHITE); + carrier.display.print(" seconds."); +} + +void mediabuttons() { + // play + carrier.display.fillScreen(ST77XX_BLACK); + carrier.display.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE); + carrier.display.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED); + delay(500); + // pause + carrier.display.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE); + carrier.display.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN); + carrier.display.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN); + delay(500); + // play color + carrier.display.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE); + delay(50); + // pause color + carrier.display.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED); + carrier.display.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED); + // play color + carrier.display.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Show_GIF/Show_GIF.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Show_GIF/Show_GIF.ino new file mode 100644 index 00000000..12d6cbd7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Show_GIF/Show_GIF.ino @@ -0,0 +1,125 @@ +// Base sketch from Fil Connesso, https://www.youtube.com/watch?v=qNVWZY3WbhU +// Using AnimatedGIF from @bitbank2 +// Thanks!! + +#include +#include + +#include "Adafruit_GFX.h" + +#include "gifs.h" + +MKRIoTCarrier carrier; + +// AnimatedGIF library needed, https://github.com/bitbank2/AnimatedGIF +AnimatedGIF gif; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + + carrier.begin(); + carrier.display.setRotation(4); + carrier.display.fillScreen(ST77XX_BLACK); + + gif.begin(LITTLE_ENDIAN_PIXELS); + + carrier.leds.fill(0xFFFFFF, 0, 5); +} + +void loop() { + int c = 0; + if (gif.open((uint8_t *)LOGO_Arduino, sizeof(LOGO_Arduino), GIFDraw)) { + + while (gif.playFrame(false, NULL)) { + carrier.leds.setBrightness(c); + c++; + carrier.leds.show(); + } + c = 0; + carrier.leds.setBrightness(0); + carrier.leds.show(); + gif.close(); + } + delay(1500); +} + +void GIFDraw(GIFDRAW *pDraw) { + uint8_t *s; + uint16_t *d, *usPalette, usTemp[320]; + int x, y, dWidth, vardX, vardY, varY; + int DX = carrier.display.width(); + int DY = carrier.display.height(); + + dWidth = pDraw->iWidth; + vardX = pDraw->iX; + vardY = pDraw->iY; + varY = pDraw->y; + + if (dWidth + vardX > dWidth) + dWidth = DX - pDraw->iX; + usPalette = pDraw->pPalette; + y = varY + vardY; + if (y >= DY || vardX >= DX || dWidth < 1) + return; + s = pDraw->pPixels; + if (pDraw->ucDisposalMethod == 2) { + for (x = 0; x < dWidth; x++) { + if (s[x] == pDraw->ucTransparent) + s[x] = pDraw->ucBackground; + } + pDraw->ucHasTransparency = 0; + } + if (pDraw->ucHasTransparency) { + uint8_t *pEnd, c, ucTransparent = pDraw->ucTransparent; + int x, iCount; + pEnd = s + dWidth; + x = 10; //offset + y += 10; + iCount = 0; + while (x < dWidth) { + c = ucTransparent - 1; + d = usTemp; + while (c != ucTransparent && s < pEnd) { + c = *s++; + if (c == ucTransparent) { + s--; + } else { + *d++ = usPalette[c]; + iCount++; + } + } + if (iCount) { + carrier.display.startWrite(); + carrier.display.setAddrWindow(pDraw->iX + x, y, iCount, 1); + carrier.display.writePixels(usTemp, iCount, true, false); + carrier.display.endWrite(); + x += iCount; + iCount = 0; + } + c = ucTransparent; + while (c == ucTransparent && s < pEnd) { + c = *s++; + if (c == ucTransparent) + iCount++; + else + s--; + } + if (iCount) { + x += iCount; + iCount = 0; + } + } + } else { + s = pDraw->pPixels; + for (x = 0; x < dWidth; x++) + usTemp[x] = usPalette[*s++]; + carrier.display.startWrite(); + carrier.display.setAddrWindow(pDraw->iX + 50, y, dWidth, 1); + carrier.display.writePixels(usTemp, dWidth, true, false); + carrier.display.endWrite(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Grove_Inputs/Grove_Inputs.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Grove_Inputs/Grove_Inputs.ino new file mode 100644 index 00000000..f2a4eec4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Grove_Inputs/Grove_Inputs.ino @@ -0,0 +1,33 @@ +#include +MKRIoTCarrier carrier; //Constructor of the carrier maybe we can include it on the library itself + +//Be sure that the Pins are the same as your wiring +int moisture = A5; +int moist; +int pir = A6; +bool trigger = false; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while (!Serial) + ; + carrier.noCase(); + carrier.begin(); + pinMode(moisture, INPUT); + pinMode(pir, INPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + //Save readings + moist = analogRead(moisture); + trigger = digitalRead(pir); + Serial.println("Reading grove inputs A5 and A6"); + Serial.print("Moist: "); + Serial.print(moist); + Serial.print("\t Move state: "); + Serial.println(digitalRead(pir)); + Serial.println(); + //delay(00); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/LEDs-Examples/strandtest/strandtest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/LEDs-Examples/strandtest/strandtest.ino new file mode 100644 index 00000000..fa6a9a6e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/LEDs-Examples/strandtest/strandtest.ino @@ -0,0 +1,31 @@ +#include +MKRIoTCarrier carrier; + +#define NUMPIXELS 5 + +void setup() { + carrier.noCase(); + carrier.begin(); +} + +// Runs 10 LEDs at a time along strip, cycling through red, green and blue. +// This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel. + +int head = 0, tail = -4; // Index of first 'on' and 'off' pixels +uint32_t color = 0xFF0000; // 'On' color (starts red) + +void loop() { + + carrier.leds.setPixelColor(head, color); // 'On' pixel at head + carrier.leds.setPixelColor(tail, 0); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(20); // Pause 20 milliseconds (~50 FPS) + + + if (++head >= NUMPIXELS) { // Increment head index. Off end of strip? + head = 0; // Yes, reset head index to start + if ((color >>= 8) == 0) // Next color (R->G->B) ... past blue now? + color = 0xFF0000; // Yes, reset to red + } + if (++tail >= NUMPIXELS) tail = 0; // Increment, reset tail index +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/SD_card/SD_card.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/SD_card/SD_card.ino new file mode 100644 index 00000000..24e35d71 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/SD_card/SD_card.ino @@ -0,0 +1,52 @@ +#include +MKRIoTCarrier carrier; + +File myFile; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Init the entire Carrier + carrier.noCase(); + carrier.begin(); + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + myFile = SD.open("test.txt", FILE_WRITE); + + // if the file opened okay, write to it: + if (myFile) { + Serial.print("Writing to test.txt..."); + myFile.println("testing 1, 2, 3."); + // close the file: + myFile.close(); + Serial.println("done."); + } else { + // if the file didn't open, print an error: + Serial.println("error opening test.txt"); + } + + // re-open the file for reading: + myFile = SD.open("test.txt"); + if (myFile) { + Serial.println("test.txt:"); + + // read from the file until there's nothing else in it: + while (myFile.available()) { + Serial.write(myFile.read()); + } + // close the file: + myFile.close(); + } else { + // if the file didn't open, print an error: + Serial.println("error opening test.txt"); + } +} + +void loop() { + // nothing happens after setup +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensors/ReadSensors.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensors/ReadSensors.ino new file mode 100644 index 00000000..72d6b034 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensors/ReadSensors.ino @@ -0,0 +1,37 @@ +/* + HTS221 - Read Sensors +*/ + +#include +MKRIoTCarrier carrier; + + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // read all the sensor values + float temperature = carrier.Env.readTemperature(); + float humidity = carrier.Env.readHumidity(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °C"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensorsImperial/ReadSensorsImperial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensorsImperial/ReadSensorsImperial.ino new file mode 100644 index 00000000..1a8661a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensorsImperial/ReadSensorsImperial.ino @@ -0,0 +1,38 @@ +/* + HTS221 - Read Sensors Imperial + +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // Passing in FAHRENHEIT as the unit parameter to ENV.readTemperature(...), + // allows you to read the sensor values in imperial units + float temperature = carrier.Env.readTemperature(FAHRENHEIT); + float humidity = carrier.Env.readHumidity(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °F"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleAccelerometer/SimpleAccelerometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleAccelerometer/SimpleAccelerometer.ino new file mode 100644 index 00000000..fa1bc4f1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleAccelerometer/SimpleAccelerometer.ino @@ -0,0 +1,52 @@ +/* + Arduino LSM6DS3 - Simple Accelerometer + + This example reads the acceleration values from the LSM6DS3 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!carrier.IMUmodule.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1) + ; + } + + Serial.print("Accelerometer sample rate = "); + Serial.print(carrier.IMUmodule.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Acceleration in G's"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (carrier.IMUmodule.accelerationAvailable()) { + carrier.IMUmodule.readAcceleration(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleGyroscope/SimpleGyroscope.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleGyroscope/SimpleGyroscope.ino new file mode 100644 index 00000000..06caa6f5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleGyroscope/SimpleGyroscope.ino @@ -0,0 +1,53 @@ +/* + Arduino LSM6DS3 - Simple Gyroscope + + This example reads the gyroscope values from the LSM6DS3 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Failed to initialize!"); + + while (1) + ; + } + + Serial.print("Gyroscope sample rate = "); + Serial.print(carrier.IMUmodule.gyroscopeSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Gyroscope in degrees/second"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (carrier.IMUmodule.gyroscopeAvailable()) { + carrier.IMUmodule.readGyroscope(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/FullExample/FullExample.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/FullExample/FullExample.ino new file mode 100644 index 00000000..4ac5a0f1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/FullExample/FullExample.ino @@ -0,0 +1,87 @@ +/* + APDS9960 - All sensor data from APDS9960 + + This example reads all data from the on-board APDS9960 sensor of the + Nano 33 BLE Sense: + - color RGB (red, green, blue) + - proximity + - gesture + and prints updates to the Serial Monitor every 100 ms. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; // Wait for serial monitor to open + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Error"); + while (true) + ; // Stop forever + } +} + +int proximity = 0; +int r = 0, g = 0, b = 0; +unsigned long lastUpdate = 0; + +void loop() { + + // Check if a proximity reading is available. + if (carrier.Light.proximityAvailable()) { + proximity = carrier.Light.readProximity(); + } + + // check if a gesture reading is available + if (carrier.Light.gestureAvailable()) { + int gesture = carrier.Light.readGesture(); + switch (gesture) { + case GESTURE_UP: + Serial.println("Detected UP gesture"); + break; + + case GESTURE_DOWN: + Serial.println("Detected DOWN gesture"); + break; + + case GESTURE_LEFT: + Serial.println("Detected LEFT gesture"); + break; + + case GESTURE_RIGHT: + Serial.println("Detected RIGHT gesture"); + break; + + default: + // ignore + break; + } + } + + // check if a color reading is available + if (carrier.Light.colorAvailable()) { + carrier.Light.readColor(r, g, b); + } + + // Print updates every 100ms + if (millis() - lastUpdate > 100) { + lastUpdate = millis(); + Serial.print("PR="); + Serial.print(proximity); + Serial.print(" rgb="); + Serial.print(r); + Serial.print(","); + Serial.print(g); + Serial.print(","); + Serial.println(b); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/GestureSensor/GestureSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/GestureSensor/GestureSensor.ino new file mode 100644 index 00000000..b3c3f036 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/GestureSensor/GestureSensor.ino @@ -0,0 +1,69 @@ +/* + APDS9960 - Gesture Sensor + + This example reads gesture data from the on-board APDS9960 sensor of the + Nano 33 BLE Sense and prints any detected gestures to the Serial Monitor. + + Gesture directions are as follows: + - UP: from USB connector towards antenna + - DOWN: from antenna towards USB connector + - LEFT: from analog pins side towards digital pins side + - RIGHT: from digital pins side towards analog pins side + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Error"); + } + + // for setGestureSensitivity(..) a value between 1 and 100 is required. + // Higher values makes the gesture recognition more sensible but less accurate + // (a wrong gesture may be detected). Lower values makes the gesture recognition + // more accurate but less sensible (some gestures may be missed). + // Default is 80 + //APDS.setGestureSensitivity(80); + + Serial.println("Detecting gestures ..."); +} + +void loop() { + if (carrier.Light.gestureAvailable()) { + // a gesture was detected, read and print to serial monitor + int gesture = APDS.readGesture(); + + switch (gesture) { + case UP: + Serial.println("Detected UP gesture"); + break; + + case DOWN: + Serial.println("Detected DOWN gesture"); + break; + + case LEFT: + Serial.println("Detected LEFT gesture"); + break; + + case RIGHT: + Serial.println("Detected RIGHT gesture"); + break; + + default: + // ignore + break; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/ProximitySensor/ProximitySensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/ProximitySensor/ProximitySensor.ino new file mode 100644 index 00000000..e393fb53 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/ProximitySensor/ProximitySensor.ino @@ -0,0 +1,43 @@ +/* + APDS9960 - Proximity Sensor + + This example reads proximity data from the on-board APDS9960 sensor of the + Nano 33 BLE Sense and prints the proximity value to the Serial Monitor + every 100ms. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Error initializing APDS9960 sensor!"); + } +} + +void loop() { + // check if a proximity reading is available + if (carrier.Light.proximityAvailable()) { + // read the proximity + // - 0 => close + // - 255 => far + // - -1 => error + int proximity = carrier.Light.readProximity(); + + // print value to the Serial Monitor + Serial.println(proximity); + } + + // wait a bit before reading again + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/Read_Colors/Read_Colors.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/Read_Colors/Read_Colors.ino new file mode 100644 index 00000000..f1b7423e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/Read_Colors/Read_Colors.ino @@ -0,0 +1,38 @@ +/* + APDS9960 - Color Sensor +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // check if a color reading is available + while (!carrier.Light.colorAvailable()) { + delay(5); + } + int r, g, b; + + // read the color + carrier.Light.readColor(r, g, b); + + // print the values + Serial.print("r = "); + Serial.println(r); + Serial.print("g = "); + Serial.println(g); + Serial.print("b = "); + Serial.println(b); + Serial.println(); + + // wait a bit before reading again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressure/ReadPressure.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressure/ReadPressure.ino new file mode 100644 index 00000000..52866c95 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressure/ReadPressure.ino @@ -0,0 +1,44 @@ +/* + LPS22HB - Read Pressure + + This example reads data from the on-board LPS22HB sensor of the + Nano 33 BLE Sense and prints the pressure sensor value to the + Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Failed to initialize!"); + while (1) + ; + } +} + +void loop() { + // read the sensor value + float pressure = carrier.Pressure.readPressure(); + + // print the sensor value + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" kPa"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressureImperial/ReadPressureImperial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressureImperial/ReadPressureImperial.ino new file mode 100644 index 00000000..fd60569f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressureImperial/ReadPressureImperial.ino @@ -0,0 +1,45 @@ +/* + LPS22HB - Read Pressure Imperial + + This example reads data from the on-board LPS22HB sensor of the + Nano 33 BLE Sense and prints the pressure sensor value in imperial + units to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Failed to initialize!"); + while (1) + ; + } +} + +void loop() { + // Passing PSI to readPressure(...) + // allows you to read the sensor values in imperial units + float pressure = carrier.Pressure.readPressure(PSI); + + // print the sensor value + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" psi"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino new file mode 100644 index 00000000..6deef5fc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino @@ -0,0 +1,50 @@ +#include "Arduino_MKRIoTCarrier.h" +MKRIoTCarrier carrier; + +// When calling carrier.noCase() (default) it's set to 100 (closer) +// When calling carrier.case() it's set to 4 (further) +// But if you use Buttons.updateConfig(value) It will not set the above values + +unsigned int threshold = 98; +unsigned int threshold_btn_0 = 95; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while (!Serial) + ; + + carrier.begin(); + //carrier.noCase(); + //Now we can set our custom touch threshold + // First we update all the buttons with the new threshold + // Then we overwrite individually one of them (they can be all set individually too) + carrier.Buttons.updateConfig(threshold); + carrier.Buttons.updateConfig(threshold_btn_0, TOUCH0); +} + +void loop() { + // put your main code here, to run repeatedly: + carrier.Buttons.update(); + + // Verify your thresholds + if (carrier.Buttons.getTouch(TOUCH0)) { + Serial.println("touching 0"); + } + + if (carrier.Buttons.getTouch(TOUCH1)) { + Serial.println("touching 1"); + } + + if (carrier.Buttons.getTouch(TOUCH2)) { + Serial.println("touching 2"); + } + + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("touching 3"); + } + + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("touching 4"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino new file mode 100644 index 00000000..54ce0f60 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino @@ -0,0 +1,92 @@ +/* + Set the relays with touch pads +*/ +#include +MKRIoTCarrier carrier; + +//False means Normally closed +bool newRelay1 = false; +bool newRelay2 = false; + +//uint32_t myColor = carrier.leds.Color(green, red, blue) +uint32_t c_orange = carrier.leds.Color(15, 40, 0); +uint32_t c_green = carrier.leds.Color(40, 0, 0); + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + + carrier.noCase(); + carrier.begin(); + + carrier.leds.setPixelColor(0, c_green); + carrier.leds.setPixelColor(4, c_green); + carrier.leds.setPixelColor(2, c_green); + carrier.leds.show(); +} + +void loop() { + // put your main code here, to run repeatedly: + carrier.Buttons.update(); + + /* Qtouch events + ButtonX. + + onTouchDown() + onTouchUp() + onTouchChange() + getTouch() + + */ + + //Side pads set the new status for each relay + //The LED changes to Green its going to be NC (Normally Closed) or Orange to NO (Normally Open) + //Then the middle pad its going to upload the relay status, to confirm both new status + + if (carrier.Buttons.onTouchDown(TOUCH0)) { + newRelay2 = !newRelay2; + if (newRelay2) { + carrier.leds.setPixelColor(0, c_orange); + } else { + carrier.leds.setPixelColor(0, c_green); + } + carrier.leds.show(); + } + if (carrier.Buttons.onTouchDown(TOUCH3)) { + newRelay1 = !newRelay1; + if (newRelay1) { + carrier.leds.setPixelColor(4, c_orange); + } else { + carrier.leds.setPixelColor(4, c_green); + } + carrier.leds.show(); + } + + if (carrier.Buttons.onTouchDown(TOUCH1)) { + carrier.leds.setPixelColor(2, c_orange); + carrier.leds.show(); + + //Set the relays + //Relay 1 + if (newRelay1) { + carrier.Relay1.open(); + } else { + carrier.Relay1.close(); + } + //Relay 1 + if (newRelay2) { + carrier.Relay2.open(); + } else { + carrier.Relay2.close(); + } + + delay(250); + carrier.leds.setPixelColor(2, 0); + carrier.leds.show(); + delay(250); + carrier.leds.setPixelColor(2, c_green); + carrier.leds.show(); + } + + delay(20); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/TouchTypes/TouchTypes.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/TouchTypes/TouchTypes.ino new file mode 100644 index 00000000..5e51f5eb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/TouchTypes/TouchTypes.ino @@ -0,0 +1,50 @@ +/* + Arduino_Qtouch - Sensor data read Example + This example shows how to configure and read data + from touch sensors buttons on MKR IoT Carrier and + prints updates to the Serial Monitor. + + The circuit: + - Arduino MKR baord; + - MKR IoT carrier. + + This example code is in the public domain. +*/ +#include +MKRIoTCarrier carrier; + + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Error in sensors initialization!"); + while (1) + ; + } + Serial.println("Touch initialization Done!"); +} + +void loop() { + // polling the sensor for new measure + carrier.Buttons.update(); + + if (carrier.Buttons.onTouchDown(TOUCH0)) { + Serial.println("Touched Down Button 0"); + } + if (carrier.Buttons.onTouchUp(TOUCH1)) { + Serial.println("Release Touch Button 1"); + } + if (carrier.Buttons.onTouchChange(TOUCH2)) { + Serial.println("Changed Touch Button 2"); + } + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("Touching Button 3"); + } + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("Touching Button 4"); + } + delay(20); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino new file mode 100644 index 00000000..1d8e0336 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino @@ -0,0 +1,81 @@ +#include +MKRIoTCarrier carrier; //Constructor of the carrier maybe we can include it on the library itself + + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while (!Serial) + ; + + //Init all the components from the board + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + + //Each time you want to update the reads from the pads use this + //It will update all the pads at the same time + carrier.Buttons.update(); + + //Different types of touches + //When you first touch it + if (carrier.Buttons.onTouchDown(TOUCH0)) { + Serial.println("Touched Down Button 0"); + carrier.leds.setPixelColor(0, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(50); + } else { + carrier.leds.setPixelColor(0, 0); + carrier.leds.show(); // Refresh strip + } + + //When you release it + if (carrier.Buttons.onTouchUp(TOUCH1)) { + Serial.println("Release Touch Button 1"); + carrier.leds.setPixelColor(1, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(50); + } else { + carrier.leds.setPixelColor(1, 0); + carrier.leds.show(); // Refresh strip + } + + //When it detects a change, down or up + if (carrier.Buttons.onTouchChange(TOUCH2)) { + Serial.println("Changed Touch Button 2"); + carrier.leds.setPixelColor(2, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(50); + } else { + carrier.leds.setPixelColor(2, 0); + carrier.leds.show(); // Refresh strip + } + + //Normal, if it is being pressed + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("Touching Button 3"); + carrier.leds.setPixelColor(3, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(5); + } else { + carrier.leds.setPixelColor(3, 0); + carrier.leds.show(); // Refresh strip + } + + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("Touching Button 4"); + carrier.leds.setPixelColor(4, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(5); + } else { + carrier.leds.setPixelColor(4, 0); + carrier.leds.show(); // Refresh strip + } + + + Serial.println(); + delay(10); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_signals/Touch_signals.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_signals/Touch_signals.ino new file mode 100644 index 00000000..728c1015 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_signals/Touch_signals.ino @@ -0,0 +1,25 @@ +// Touch Buttons test + +#include +MKRIoTCarrier carrier; + +int msr[5]; + +void setup() { + // put your setup code here, to run once: + //carrier.noCase(); //No need to use it, default false + Serial.begin(9600); + carrier.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + for (int i = 0; i < 5; i++) { + msr[i] = analogRead(i); + Serial.print(i); + Serial.print(" - "); + Serial.print(msr[i]); + Serial.print("\t"); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/getTouch/getTouch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/getTouch/getTouch.ino new file mode 100644 index 00000000..5b319de6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/getTouch/getTouch.ino @@ -0,0 +1,50 @@ +/* + Arduino_Qtouch - Sensor data read Example + This example shows how to configure and read data + from touch sensors buttons on MKR IoT Carrier and + prints updates to the Serial Monitor. + + The circuit: + - Arduino MKR baord; + - MKR IoT carrier. + + This example code is in the public domain. +*/ +#include +MKRIoTCarrier carrier; + + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + // Qtouch initialization + if (!carrier.begin()) { + Serial.println("Error in sensors initialization!"); + while (1) + ; + } + Serial.println("Touch initialization Done!"); +} + +void loop() { + // polling the sensor for new measure + carrier.Buttons.update(); + + // Checks if new data are available + if (carrier.Buttons.getTouch(TOUCH0)) { + Serial.println("Touching Button 0"); + } + if (carrier.Buttons.getTouch(TOUCH1)) { + Serial.println("Touching Button 1"); + } + if (carrier.Buttons.getTouch(TOUCH2)) { + Serial.println("Touching Button 2"); + } + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("Touching Button 3"); + } + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("Touching Button 4"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/LICENSE new file mode 100644 index 00000000..0a041280 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/README.md new file mode 100644 index 00000000..a307b37d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/README.md @@ -0,0 +1,52 @@ +`Arduino_MKRMEM` +================ + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/spell-check.yml) + +This library provides a driver for the [Arduino MKR MEM Shield](https://store.arduino.cc/arduino-mkr-mem-shield) W25Q16DV SPI flash (with a capacity of 2 MByte) complete with integration for the [SPIFFS](https://github.com/pellepl/spiffs) embedded flash file system (EFFS). + +**Attention**: Before you can use SPIFFS you need to erase and format the flash memory chip using [SPIFFSFormat.ino](examples/SPIFFSFormat/SPIFFSFormat.ino). + +## Why use an EFFS? +The usage of semiconductor based flash memories differs fundamentally from other devices such as magnetic based hard discs. In flash terminology you don't write to memory but you **program** it. When a flash memory is programmed the default state of the flash memory (all bits equal to 1) is changed to the desired value. Note that you can only change bits from 1 to 0, in order to change a bit to 1 again an **erase operation** has to be performed. Such an erase operation can not be performed for each individual bit, only a bit block of bits and bytes can be "erased" together. The smallest possible erase size for the W25Q16DV is 4 kByte (sector erase). Also you can not just program any address on the flash, programming is usually performed **page-by-page**. The W25Q16DV page size is 256 bytes. + +If data stored on the flash memory needs to be changed the data has to be read, modified and written to another address while the the old entry has to be marked as as invalid. Since this tends to consume the available space fairly quickly, a process known as **garbage collection** has to be performed periodically. During garbage collection all valid data are copied to fresh blocks and the old blocks are erased. + +When a maximum number of program / erase cycles (≥ 10^5) are exceeded the flash memory will start to wear down, causing the flash memory to no longer function reliably. As a countermeasure **wear leveling** techniques are used which distribute the data evenly across all sectors of the flash memory to minimize the number of erase cycles per sector and thus extend the life of the flash memory. **Dynamic** Wear Leveling refers to a wear-leveling strategy which works only with those data. **Static** Wear Leveling refers to a wear-leveling strategy that looks at all data, including those already written to the flash memory. + +The goals of garbage collection (maximizing the free sectors) and wear-leveling (even utilization of all sectors) are in conflict with one another. To get both sufficient performance and endurance, a good trade-off must be found between these two tasks. + +So while the usage of an embedded flash file system comes with a bit of overhead, it is the only way to reasonably ensure successful long-term operation of flash memories. + +## How to use + +```C++ +#include +/* ... */ +static char const PANGRAM[] = "The quick brown fox jumps over the lazy dog."; +/* ... */ +void setup() +{ + Serial.begin(); + flash.begin(); + /* ... */ + if(SPIFFS_OK != filesystem.mount()) { + Serial.println("mount() failed with error code "); Serial.println(filesystem.err()); return; + } + /* ... */ + File file = filesystem.open("fox.txt", CREATE | READ_WRITE| TRUNCATE); + /* ... */ + file.write((void *)PANGRAM, strlen(PANGRAM)); + /* ... */ + file.lseek(0, START); /* Rewind file pointer to the start */ + char buf[64] = {0}; + int const bytes_read = file.read(buf, sizeof(buf)); + buf[bytes_read] = '\0'; + Serial.println(buf); + /* ... */ + file.close(); + filesystem.unmount(); +} +``` diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/RawFlashAccess/RawFlashAccess.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/RawFlashAccess/RawFlashAccess.ino new file mode 100644 index 00000000..7513c10f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/RawFlashAccess/RawFlashAccess.ino @@ -0,0 +1,129 @@ +/* RawFlashAccess.ino + * + * This sketch demonstrates the raw API of the W25Q16DV class + * which allows for low level flash memory control. + * + * Alexander Entinger + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#undef max +#undef min +#include +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) {}; + + flash.begin(); + + W25Q16DV_Id const id = flash.readId(); + + char msg[32] = { 0 }; + snprintf(msg, sizeof(msg), "ID: %02X %02X %02X", id.manufacturer_id, id.memory_type, id.capacity); + Serial.println(msg); + + + std::array data_write = { 0 }, + data_read = { 0 }; + + /************************************************************************************** + * CHIP ERASE + **************************************************************************************/ + + Serial.println("Erasing chip"); + + flash.eraseChip(); + + flash.read(0x000100, data_read.data(), data_read.size()); + + if (std::all_of(data_read.begin(), data_read.end(), [](uint8_t const elem) { + return (elem == 0xFF); + })) { + Serial.println("Comparison OK"); + } else { + Serial.println("Comparison FAIL"); + } + printArray("RD: ", data_read); + + /************************************************************************************** + * PAGE PROGRAM + **************************************************************************************/ + + Serial.println("Programming page"); + + /* Initialize data */ + std::transform(data_write.begin(), data_write.end(), data_write.begin(), + [](uint8_t const elem) { + static uint8_t i = 0; + return i++; + }); + + flash.programPage(0x000100, data_write.data(), data_write.size()); + flash.read(0x000100, data_read.data(), data_read.size()); + + printArray("WR: ", data_write); + printArray("RD: ", data_read); + + if (std::equal(data_write.begin(), data_write.end(), data_read.begin())) { + Serial.println("Comparison OK"); + } else { + Serial.println("Comparison FAIL"); + } + + /************************************************************************************** + * SECTOR ERASE + **************************************************************************************/ + + Serial.println("Sector erase"); + + /* Erase the whole first sector (4 kB) */ + flash.eraseSector(0x000000); + + /* Set the comparison buffer to 0xFF since we now need to compare if every value is 0xFF */ + std::fill(data_write.begin(), data_write.end(), 0xFF); + + /* Read the data */ + flash.read(0x000100, data_read.data(), data_read.size()); + printArray("RD: ", data_read); + + /* Compare the two data buffers */ + if (std::all_of(data_read.begin(), data_read.end(), [](uint8_t const elem) { + return (elem == 0xFF); + })) { + Serial.println("Comparison OK"); + } else { + Serial.println("Comparison FAIL"); + } +} + +void loop() { +} + +/************************************************************************************** + * HELPER + **************************************************************************************/ + +void printArray(char const* desc, std::array arr) { + Serial.print(desc); + + std::for_each(arr.begin(), arr.end(), + [](uint8_t const elem) { + Serial.print(elem, HEX); + Serial.print(" "); + }); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino new file mode 100644 index 00000000..3ce22b3b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino @@ -0,0 +1,56 @@ +/* SPIFFSDirectories.ino + * + * This sketch demonstrates how to use directories (as much + * as is supported by SPIFFS). + * + * Alexander Entinger + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) {}; + + flash.begin(); + + Serial.println("Mounting ..."); + int res = filesystem.mount(); + if (res != SPIFFS_OK && res != SPIFFS_ERR_NOT_A_FS) { + Serial.println("mount() failed with error code "); + Serial.println(res); + return; + } + + /* Note: SPIFFS is a flat file system; it doesn't have directories. */ + File file_A = filesystem.open("/testfile_A.txt", CREATE | WRITE_ONLY | TRUNCATE); + File file_B = filesystem.open("/testdir/testfile_B.txt", CREATE | WRITE_ONLY | TRUNCATE); + + Serial.println("opendir('/')"); + Directory dir = filesystem.opendir("/"); + DirEntry entry; + while (dir.readdir(entry)) { + if (entry.isFile()) Serial.print(" F "); + else if (entry.isDirectory()) + Serial.print(" D "); + Serial.print(entry.name()); + Serial.println(); + } + dir.closedir(); + + Serial.println("Unmounting ..."); + filesystem.unmount(); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSFormat/SPIFFSFormat.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSFormat/SPIFFSFormat.ino new file mode 100644 index 00000000..dffb0bdb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSFormat/SPIFFSFormat.ino @@ -0,0 +1,84 @@ +/* SPIFFSFormat.ino + * + * This sketch erases the complete flash and formats it for + * usage with the SPIFFS (SPI Flash File System). + * + * Alexander Entinger + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) {}; + + flash.begin(); + + Serial.println("Erasing chip ..."); + flash.eraseChip(); + + Serial.println("Mounting ..."); + int res = filesystem.mount(); + if (res != SPIFFS_OK && res != SPIFFS_ERR_NOT_A_FS) { + Serial.println("mount() failed with error code "); + Serial.println(res); + return; + } + + Serial.println("Unmounting ..."); + filesystem.unmount(); + + Serial.println("Formatting ..."); + res = filesystem.format(); + if (res != SPIFFS_OK) { + Serial.println("format() failed with error code "); + Serial.println(res); + return; + } + + Serial.println("Mounting ..."); + res = filesystem.mount(); + if (res != SPIFFS_OK) { + Serial.println("mount() failed with error code "); + Serial.println(res); + return; + } + + Serial.println("Checking ..."); + res = filesystem.check(); + if (res != SPIFFS_OK) { + Serial.println("check() failed with error code "); + Serial.println(res); + return; + } + + Serial.println("Retrieving filesystem info ..."); + unsigned int bytes_total = 0, + bytes_used = 0; + res = filesystem.info(bytes_total, bytes_used); + if (res != SPIFFS_OK) { + Serial.println("check() failed with error code "); + Serial.println(res); + return; + } else { + char msg[64] = { 0 }; + snprintf(msg, sizeof(msg), "SPIFFS Info:\nBytes Total: %d\nBytes Used: %d", bytes_total, bytes_used); + Serial.println(msg); + } + + Serial.println("Unmounting ..."); + filesystem.unmount(); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSUsage/SPIFFSUsage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSUsage/SPIFFSUsage.ino new file mode 100644 index 00000000..36ce183f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSUsage/SPIFFSUsage.ino @@ -0,0 +1,114 @@ +/* SPIFFSUsage.ino + * + * This sketch demonstrates various file operations utilizing + * the Arduino MKR MEM Shield port for the SPIFFS. + * + * Alexander Entinger + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +/* A pangram is a sentence using every letter of a given alphabet at least once. */ +static char const PANGRAM[] = "The quick brown fox jumps over the lazy dog."; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) {}; + + flash.begin(); + + Serial.println("Mounting ..."); + if (SPIFFS_OK != filesystem.mount()) { + Serial.println("mount() failed with error code "); + Serial.println(filesystem.err()); + return; + } + + + Serial.println("Checking ..."); + if (SPIFFS_OK != filesystem.check()) { + Serial.println("check() failed with error code "); + Serial.println(filesystem.err()); + return; + } + + Serial.print("Checking for file ... "); + File fnf = filesystem.open("404.txt", READ_ONLY); + if (!fnf) { + Serial.println(" 404.txt does not exist."); + } + + Serial.print("Checking for file ... "); + File fox = filesystem.open("fox.txt", READ_ONLY); + if (fox) { + Serial.println(" fox.txt exists. It will be overwritten."); + } + + Serial.println("Writing ..."); + /* Create file if it doesn't exist (SPIFFS_CREAT) and open in + * write only mode (SPIFFS_WRONLY). If the file does exist + * delete the existing content (SPIFFS_TRUNC). + */ + File file = filesystem.open("fox.txt", CREATE | READ_WRITE | TRUNCATE); + + int const bytes_to_write = strlen(PANGRAM); + int const bytes_written = file.write((void *)PANGRAM, bytes_to_write); + + if (bytes_written != bytes_to_write) { + Serial.println("write() failed with error code "); + Serial.println(filesystem.err()); + return; + } else { + Serial.print(bytes_written); + Serial.println(" bytes written"); + } + + + Serial.println("Retrieving filesystem info ..."); + unsigned int bytes_total = 0, + bytes_used = 0; + if (SPIFFS_OK != filesystem.info(bytes_total, bytes_used)) { + Serial.println("check() failed with error code "); + Serial.println(filesystem.err()); + return; + } else { + char msg[64] = { 0 }; + snprintf(msg, sizeof(msg), "SPIFFS Info:\nBytes Total: %d\nBytes Used: %d", bytes_total, bytes_used); + Serial.println(msg); + } + + + Serial.println("Reading ..."); + file.lseek(0, START); /* Rewind file pointer to the start */ + + char buf[64] = { 0 }; + int const bytes_read = file.read(buf, sizeof(buf)); + buf[bytes_read] = '\0'; + + file.close(); + Serial.print("["); + Serial.print(bytes_read); + Serial.print("] "); + Serial.println(buf); + + + Serial.println("Unmounting ..."); + filesystem.unmount(); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/README.adoc new file mode 100644 index 00000000..8e95cbe7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_MKRRGB + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to draw on your official Arduino MKR RGB shield. Depends on the ArduinoGraphics library. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/examples/ScrollText/ScrollText.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/examples/ScrollText/ScrollText.ino new file mode 100644 index 00000000..7c1ec3a5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/examples/ScrollText/ScrollText.ino @@ -0,0 +1,41 @@ +/* + MKR RGB - Scroll Text + + This example demonstrates how to display and scroll text + on the MKR RGB shield. It continuously scrolls the + current millis() value on the display. + + The circuit: + - Arduino MKR board + - Arduino MKR RGB shield attached + + This example code is in the public domain. +*/ + +#include // Arduino_MKRRGB depends on ArduinoGraphics +#include + +void setup() { + // initialize the display + MATRIX.begin(); + + // set the brightness, supported values are 0 - 255 + MATRIX.brightness(10); + + // configure the text scroll speed + MATRIX.textScrollSpeed(125); + + // display some short text without scrolling + MATRIX.beginText(0, 0, 127, 0, 0); // X, Y, then R, G, B + MATRIX.print("Hi"); + MATRIX.endText(); + + delay(2000); +} + +void loop() { + MATRIX.beginText(MATRIX.width() - 1, 0); // use the same color as before, start text at the right edge + MATRIX.print("millis="); + MATRIX.println(millis()); + MATRIX.endText(SCROLL_LEFT); // SCROLL_LEFT parameter here to configure scrolling left +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/examples/SimpleDraw/SimpleDraw.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/examples/SimpleDraw/SimpleDraw.ino new file mode 100644 index 00000000..b6d348f0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRRGB/examples/SimpleDraw/SimpleDraw.ino @@ -0,0 +1,104 @@ +/* + MKR RGB - Simple Draw + + This example demonstrates how to draw on the + MKR RGB shield. + + The circuit: + - Arduino MKR board + - Arduino MKR RGB shield attached + + This example code is in the public domain. +*/ + +#include // Arduino_MKRRGB depends on ArduinoGraphics +#include + +void setup() { + // initialize the display + MATRIX.begin(); + + // set the brightness, supported values are 0 - 255 + MATRIX.brightness(10); +} + +void loop() { + // set one pixel RED + MATRIX.beginDraw(); + MATRIX.set(0, 0, 255, 0, 0); // X, Y, and R, G, B + MATRIX.endDraw(); + + delay(1000); + + // clear the display + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.endDraw(); + + delay(1000); + + // set one pixel GREEN, using the stroke and point methods + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(0, 255, 0); + MATRIX.point(1, 1); + MATRIX.endDraw(); + + delay(1000); + + // set draw a BLUE line + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(0, 0, 255); + MATRIX.line(0, 0, MATRIX.width() - 1, MATRIX.height() - 1); + MATRIX.endDraw(); + + delay(1000); + + // outline a CYAN rectangle + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(0, 255, 255); + MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height()); + MATRIX.endDraw(); + + delay(1000); + + // fill a YELLOW rectangle + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.noStroke(); + MATRIX.fill(255, 255, 0); + MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height()); + MATRIX.endDraw(); + + delay(1000); + + // fill and stroke a rectangle + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(255, 0, 255); + MATRIX.fill(0, 255, 0); + MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height()); + MATRIX.endDraw(); + + delay(1000); + + // stroke a small text + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(255, 255, 255); + MATRIX.text("abc", 0, 1); + MATRIX.endDraw(); + + delay(1000); + + // clear the display + MATRIX.beginDraw(); + MATRIX.noFill(); + MATRIX.noStroke(); + MATRIX.clear(); + MATRIX.endDraw(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/README.adoc new file mode 100644 index 00000000..65feed40 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/README.adoc @@ -0,0 +1,12 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_MKRTHERM + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the temperature sensors connected to your MKR THERM Shield. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensor/ReadSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensor/ReadSensor.ino new file mode 100644 index 00000000..9ba433e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensor/ReadSensor.ino @@ -0,0 +1,45 @@ +/* + MKR THERM Shield - Read Sensors + + This example reads the temperatures measured by the thermocouple + connected to the MKR THERM Shield and prints them to the Serial Monitor + once a second. + + The circuit: + - Arduino MKR board + - Arduino MKR THERM Shield attached + - A type K thermocouple temperature sensor connected to the shield + + This example code is in the public domain. +*/ + +#include + +void setup() { + + Serial.begin(9600); + + while (!Serial) + ; + + if (!THERM.begin()) { + Serial.println("Failed to initialize MKR THERM Shield!"); + while (1) + ; + } +} + +void loop() { + + Serial.print("Reference temperature "); + Serial.print(THERM.readReferenceTemperature()); + Serial.println(" °C"); + + Serial.print("Temperature "); + Serial.print(THERM.readTemperature(CELSIUS)); + Serial.println(" °C"); + + Serial.println(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino new file mode 100644 index 00000000..bd4ae5d5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino @@ -0,0 +1,49 @@ +/* + MKR THERM Shield - Read Sensors + + This example reads the temperatures (in Fahrenheit and kelvins) measured by the thermocouple + connected to the MKR THERM Shield and prints them to the Serial Monitor + once a second. + + The circuit: + - Arduino MKR board + - Arduino MKR THERM Shield attached + - A type K thermocouple temperature sensor connected to the shield + + This example code is in the public domain. +*/ + +#include + +void setup() { + + Serial.begin(9600); + + while (!Serial) + ; + + if (!THERM.begin()) { + Serial.println("Failed to initialize MKR THERM Shield!"); + while (1) + ; + } +} + +void loop() { + + Serial.print("Reference temperature "); + Serial.print(THERM.readReferenceTemperature()); + Serial.println(" °C"); + + Serial.print("Temperature in Fahrenheit "); + Serial.print(THERM.readTemperature(FAHRENHEIT)); + Serial.println(" °F"); + + Serial.print("Temperature in kelvin "); + Serial.print(THERM.readTemperature(KELVIN)); + Serial.println(" K"); + + Serial.println(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/README.md new file mode 100644 index 00000000..1cf65333 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/README.md @@ -0,0 +1,30 @@ +# Portenta Machine Control Library for Arduino + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/spell-check.yml) + +Arduino Library for the Portenta Machine Control + +The Portenta Machine Control enhances existing products with minimal effort, allowing companies to implement a standard platform across different equipment models. It is now easy to create an infrastructure of interconnected machines, which can be controlled onsite or via the cloud when needed; moreover, human-machine interaction can be further enahnced via mobile apps thanks to BLE connectivity. + +For more information about this library please visit us at https://www.arduino.cc/reference/en/libraries/arduino_machinecontrol/ +For more information about this product: https://www.arduino.cc/pro/hardware/product/portenta-machine-control + +## License + +Copyright (c) 2021 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_Out/Analog_Out.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_Out/Analog_Out.ino new file mode 100644 index 00000000..d314bba8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_Out/Analog_Out.ino @@ -0,0 +1,50 @@ +/* + Machine Control - Analog out Example + + This example shows how to use the Analog out channels on + the Machine Control. + The example sets the channels PWM period in the setup, + then loops the channels voltage output value from 0V to 10.4V. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ + +#include + +using namespace machinecontrol; + +void setup() { + //analog_out.period_ms(CHANNEL, PERIOD_MILLISECONDS); + analog_out.period_ms(0, 4); + analog_out.period_ms(1, 4); + analog_out.period_ms(2, 4); + analog_out.period_ms(3, 4); + + Serial.begin(9600); + Serial.println("Analog out test"); +} + +//Output values which will be changed with this variable +float counter = 1; + +void loop() { + //analog_out.write(CHANNEL, OUTPUT_VOLTAGE_VALUE); + analog_out.write(0, counter); + analog_out.write(1, counter); + analog_out.write(2, counter); + analog_out.write(3, counter); + Serial.println("All channels set at " + String(counter) + "V"); + + counter = counter + 0.1; + //Maximum output value is 10.4V + if (counter >= 10.5) { + counter = 0; + //Additional 100 ms delay introduced to manage 10.5V -> 0V fall time of 150 ms + delay(100); + } + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_0_10V/Analog_input_0_10V.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_0_10V/Analog_input_0_10V.ino new file mode 100644 index 00000000..93058759 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_0_10V/Analog_input_0_10V.ino @@ -0,0 +1,52 @@ +/* + Machine Control - Analog in 0 - 10 V Example + + This example provides the voltage value acquired by the + Machine Control. For each channel of the ANALOG IN connector, + there is a resistor divider made by a 100k and 39k, + the input voltage is divided by a ratio of 0.28. + Maximum input voltage is 10V. + To use the 0V-10V functionality, a 24V supply on + the PWR SUPPLY connector is necessary. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ +#include + +using namespace machinecontrol; + +float res_divider = 0.28057; +float reference = 3.3; + +void setup() { + analogReadResolution(16); + + Serial.begin(9600); + analog_in.set0_10V(); +} + +void loop() { + float raw_voltage_ch0 = analog_in.read(0); + float voltage_ch0 = (raw_voltage_ch0 * reference) / 65535 / res_divider; + Serial.print("Voltage CH0: "); + Serial.print(voltage_ch0, 3); + Serial.println("V"); + + float raw_voltage_ch1 = analog_in.read(1); + float voltage_ch1 = (raw_voltage_ch1 * reference) / 65535 / res_divider; + Serial.print("Voltage CH1: "); + Serial.print(voltage_ch1, 3); + Serial.println("V"); + + float raw_voltage_ch2 = analog_in.read(2); + float voltage_ch2 = (raw_voltage_ch2 * reference) / 65535 / res_divider; + Serial.print("Voltage CH2: "); + Serial.print(voltage_ch2, 3); + Serial.println("V"); + Serial.println(); + delay(250); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_4_20mA/Analog_input_4_20mA.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_4_20mA/Analog_input_4_20mA.ino new file mode 100644 index 00000000..167de2dc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_4_20mA/Analog_input_4_20mA.ino @@ -0,0 +1,56 @@ +/* + Machine Control - Analog in 4 - 20 mA Example + + This example provides the current value acquired by the + Machine Control. For each channel of the ANALOG IN + connector, there is a 120 ohm resistor to GND. The current + of the 4-20mA sensor flows through it, generating a voltage + which is sampled by the Portenta's ADC. + To use the 4-20mA functionality, a 24V supply on + the PWR SUPPLY connector is necessary. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ +#include + +using namespace machinecontrol; + +#define SENSE_RES 120 + +float reference = 3.3; + +void setup() { + analogReadResolution(16); + + Serial.begin(9600); + analog_in.set4_20mA(); +} + +void loop() { + float raw_voltage_ch0 = analog_in.read(0); + float voltage_ch0 = (raw_voltage_ch0 * reference) / 65535; + float current_ch0 = (voltage_ch0 / SENSE_RES) * 1000; + Serial.print("Measured Current CH0: "); + Serial.print(current_ch0); + Serial.println("mA"); + + float raw_voltage_ch1 = analog_in.read(1); + float voltage_ch1 = (raw_voltage_ch1 * reference) / 65535; + float current_ch1 = (voltage_ch1 / SENSE_RES) * 1000; + Serial.print("Measured Current CH1: "); + Serial.print(current_ch1); + Serial.println("mA"); + float raw_voltage_ch2 = analog_in.read(2); + float voltage_ch2 = (raw_voltage_ch2 * reference) / 65535; + float current_ch2 = (voltage_ch2 / SENSE_RES) * 1000; + Serial.print("Measured Current CH2: "); + Serial.print(current_ch2); + Serial.println("mA"); + + Serial.println(); + delay(250); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_NTC/Analog_input_NTC.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_NTC/Analog_input_NTC.ino new file mode 100644 index 00000000..d15149ce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_NTC/Analog_input_NTC.ino @@ -0,0 +1,81 @@ +/* + Machine Control - Analog in NTC Example + + This example provides the resistance value acquired by the + Machine Control. A 3V voltage reference is connected + to each channel of the ANALOG IN connector. The reference + has a 100k resistor in series, so it can provide only a low + current. + The voltage sampled by the Portenta's ADC is the reference + voltage divided by the voltage divider composed by the + input resistor and the 100k in series to the voltage reference. + The resistor value is calculated by inverting the formula of the + voltage divider. + To use the NTC functionality, the 24V supply on + the PWR SUPPLY connector is necessary. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ +#include + +using namespace machinecontrol; + +#define REFERENCE_RES 100000 + +float reference = 3.3; +float lowest_voltage = 2.7; + +void setup() { + analogReadResolution(16); + + Serial.begin(9600); + analog_in.setNTC(); +} + +void loop() { + float raw_voltage_ch0 = analog_in.read(0); + float voltage_ch0 = (raw_voltage_ch0 * reference) / 65535; + float resistance_ch0; + Serial.print("Resistance CH0: "); + if (voltage_ch0 < lowest_voltage) { + resistance_ch0 = ((-REFERENCE_RES) * voltage_ch0) / (voltage_ch0 - reference); + Serial.print(resistance_ch0); + Serial.println(" ohm"); + } else { + resistance_ch0 = -1; + Serial.println("NaN"); + } + + float raw_voltage_ch1 = analog_in.read(1); + float voltage_ch1 = (raw_voltage_ch1 * reference) / 65535; + float resistance_ch1; + Serial.print("Resistance CH1: "); + if (voltage_ch1 < lowest_voltage) { + resistance_ch1 = ((-REFERENCE_RES) * voltage_ch1) / (voltage_ch1 - reference); + Serial.print(resistance_ch1); + Serial.println(" ohm"); + } else { + resistance_ch1 = -1; + Serial.println("NaN"); + } + + float raw_voltage_ch2 = analog_in.read(2); + float voltage_ch2 = (raw_voltage_ch2 * reference) / 65535; + float resistance_ch2; + Serial.print("Resistance CH2: "); + if (voltage_ch2 < lowest_voltage) { + resistance_ch2 = ((-REFERENCE_RES) * voltage_ch2) / (voltage_ch2 - reference); + Serial.print(resistance_ch2); + Serial.println(" ohm"); + } else { + resistance_ch2 = -1; + Serial.println("NaN"); + } + + Serial.println(); + delay(250); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/ReadCan/ReadCan.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/ReadCan/ReadCan.ino new file mode 100644 index 00000000..e67e0349 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/ReadCan/ReadCan.ino @@ -0,0 +1,50 @@ +/* + CAN Read Example + + This sketch shows how to use the CAN transceiver on the Machine + Control and how to receive data from the RX CAN channel. + + Circuit: + - Portenta H7 + - Machine Control + +*/ +#include +#include + +using namespace machinecontrol; + +#define DATARATE_2MB 2000000 +#define DATARATE_1_5MB 1500000 +#define DATARATE_1MB 1000000 +#define DATARATE_800KB 800000 + + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. + } + + Serial.println("Start CAN initialization"); + comm_protocols.enableCAN(); + comm_protocols.can.frequency(DATARATE_800KB); + Serial.println("Initialization done"); +} + + +void loop() { + mbed::CANMessage msg; + if (comm_protocols.can.read(msg)) { + + // Print the sender ID + Serial.print("ID: "); + Serial.println(msg.id); + + // Print the first Payload Byte + Serial.print("Message received:"); + Serial.println(msg.data[0], DEC); + } + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/WriteCan/WriteCan.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/WriteCan/WriteCan.ino new file mode 100644 index 00000000..2333aee0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/WriteCan/WriteCan.ino @@ -0,0 +1,50 @@ +/* + CAN Write Example + + This sketch shows how to use the CAN transceiver on the Machine + Control and how to transmit data from the TX CAN channel. + + Circuit: + - Portenta H7 + - Machine Control + +*/ +#include +#include +using namespace machinecontrol; + +#define DATARATE_2MB 2000000 +#define DATARATE_1_5MB 1500000 +#define DATARATE_1MB 1000000 +#define DATARATE_800KB 800000 + + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. + } + + Serial.println("Start CAN initialization"); + comm_protocols.enableCAN(); + comm_protocols.can.frequency(DATARATE_800KB); + Serial.println("Initialization done"); +} + +int counter = 0; +unsigned char payload = 0x49; +int payload_size = 1; + +void loop() { + + mbed::CANMessage msg = mbed::CANMessage(13ul, &payload, payload_size); + if (comm_protocols.can.write(msg)) { + Serial.println("Message sent"); + } else { + Serial.println("Transmission Error: "); + Serial.println(comm_protocols.can.tderror()); + comm_protocols.can.reset(); + } + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_output/Digital_output.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_output/Digital_output.ino new file mode 100644 index 00000000..755e3fd1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_output/Digital_output.ino @@ -0,0 +1,117 @@ +/* + Machine Control - Digital Output Example + + This sketch shows how to send values on the + DIGITAL OUT channels on the Machine Control. + Please remember that pin "24V IN" of the connector + DIGITAL_OUTPUTS must be connected to 24V. + The DIGITAL OUT channels are high side switches + capable to handle up to 0.5A. There is an over current + protection that open the channel when the current is + above 0.7A with a +-20% tolerance. + The over current protection can be set to have two + different behaviors, and it is the same for all channels: + 1) Latch mode: when the over current is detected + the channel is opened, and will remain opened until + it is toggled via software. + 2) Auto retry: when the over current is detected + the channel is opened, but after some tens of + milliseconds the channel will automatically try + to close itself again. In case of a persistent + overcurrent the channel will continuously toggle. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ + +#include + +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + // The loop starts only when the Serial Monitor is opened. + while (!Serial) + ; + + //Set over current behavior of all channels to latch mode: + digital_outputs.setLatch(); + + // Uncomment this line to set over current behavior of all + // channels to auto retry mode instead of latch mode: + //digital_outputs.setRetry(); + + //At startup set all channels to OPEN + digital_outputs.setAll(0); +} + + +void loop() { + Serial.println("DIGITAL OUT:"); + + // Set all channels to CLOSED + digital_outputs.setAll(255); + Serial.print("All channels are CLOSED for 1 s..."); + delay(1000); + + // Set all channels to OPEN + digital_outputs.setAll(0); + Serial.println("now they are OPEN."); + delay(1000); + + // Toggle each channel for 1 s, one by one + + digital_outputs.set(0, HIGH); + Serial.print("CH0 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(0, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(1, HIGH); + Serial.print("CH1 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(1, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(2, HIGH); + Serial.print("CH2 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(2, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(3, HIGH); + Serial.print("CH3 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(3, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(4, HIGH); + Serial.print("CH4 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(4, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(5, HIGH); + Serial.print("CH5 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(5, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(6, HIGH); + Serial.print("CH6 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(6, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(7, HIGH); + Serial.print("CH7 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(7, LOW); + Serial.println("now is OPEN."); + + Serial.println(); + delay(1000); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/CombinedIOExpander/CombinedIOExpander.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/CombinedIOExpander/CombinedIOExpander.ino new file mode 100644 index 00000000..3e91d7df --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/CombinedIOExpander/CombinedIOExpander.ino @@ -0,0 +1,98 @@ +/* + Machine Control - IOExpander Read And Write Example + + This sketch shows how to use the GPIO Expanders on the Machine Control, + how to periodically send a value on the PROGRAMMABLE DIGITAL I/O + output channels and how to periodically read from the PROGRAMMABLE + DIGITAL I/O input channels and DIGITAL INPUT channels. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ + +#include +#include "Wire.h" +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + Wire.begin(); + if (!digital_inputs.init()) { + Serial.println("GPIO expander initialization fail!!"); + } + if (!digital_programmables.init()) { + Serial.println("GPIO expander initialization fail!!"); + } + + Serial.println("GPIO expander initialization done"); + digital_programmables.setLatch(); + Serial.println("GPIO expander initialization done"); + // digital_inputs.setLatch(); +} + +void loop() { + // Write the status value to On to Pin 3 + digital_programmables.set(IO_WRITE_CH_PIN_03, SWITCH_ON); + delay(1000); + + // Read from PROGRAMMABLE DIGITAL I/O Pin 3 + Serial.println("Read IO Pin 03: " + String(digital_programmables.read(IO_READ_CH_PIN_03))); + delay(1000); + + // Read from DIGITAL INPUT Expander Pin 3 + Serial.println("Read DIN Pin 03: " + String(digital_inputs.read(DIN_READ_CH_PIN_03))); + delay(1000); + + // Write the status value to Off to Pin 3 + digital_programmables.set(IO_WRITE_CH_PIN_03, SWITCH_OFF); + delay(1000); + + Serial.println(); + // Write the status value to On to all the Output Pins + digital_programmables.writeAll(SWITCH_ON_ALL); + + // Reads from all Input Pins + readAll(); + delay(1000); + + // Write the status value to Off all to all the Output Pins + digital_programmables.writeAll(SWITCH_OFF_ALL); + + // Reads from all Input Pins + readAll(); + Serial.println(); + delay(1000); +} + + +void readAll() { + uint32_t inputs = digital_programmables.readAll(); + Serial.println("CH00: " + String((inputs & (1 << IO_READ_CH_PIN_00)) >> IO_READ_CH_PIN_00)); + Serial.println("CH01: " + String((inputs & (1 << IO_READ_CH_PIN_01)) >> IO_READ_CH_PIN_01)); + Serial.println("CH02: " + String((inputs & (1 << IO_READ_CH_PIN_02)) >> IO_READ_CH_PIN_02)); + Serial.println("CH03: " + String((inputs & (1 << IO_READ_CH_PIN_03)) >> IO_READ_CH_PIN_03)); + Serial.println("CH04: " + String((inputs & (1 << IO_READ_CH_PIN_04)) >> IO_READ_CH_PIN_04)); + Serial.println("CH05: " + String((inputs & (1 << IO_READ_CH_PIN_05)) >> IO_READ_CH_PIN_05)); + Serial.println("CH06: " + String((inputs & (1 << IO_READ_CH_PIN_06)) >> IO_READ_CH_PIN_06)); + Serial.println("CH07: " + String((inputs & (1 << IO_READ_CH_PIN_07)) >> IO_READ_CH_PIN_07)); + Serial.println("CH08: " + String((inputs & (1 << IO_READ_CH_PIN_08)) >> IO_READ_CH_PIN_08)); + Serial.println("CH09: " + String((inputs & (1 << IO_READ_CH_PIN_09)) >> IO_READ_CH_PIN_09)); + Serial.println("CH10: " + String((inputs & (1 << IO_READ_CH_PIN_10)) >> IO_READ_CH_PIN_10)); + Serial.println("CH11: " + String((inputs & (1 << IO_READ_CH_PIN_11)) >> IO_READ_CH_PIN_11)); + Serial.println(); + inputs = digital_inputs.readAll(); + Serial.println("CH00: " + String((inputs & (1 << DIN_READ_CH_PIN_00)) >> DIN_READ_CH_PIN_00)); + Serial.println("CH01: " + String((inputs & (1 << DIN_READ_CH_PIN_01)) >> DIN_READ_CH_PIN_01)); + Serial.println("CH02: " + String((inputs & (1 << DIN_READ_CH_PIN_02)) >> DIN_READ_CH_PIN_02)); + Serial.println("CH03: " + String((inputs & (1 << DIN_READ_CH_PIN_03)) >> DIN_READ_CH_PIN_03)); + Serial.println("CH04: " + String((inputs & (1 << DIN_READ_CH_PIN_04)) >> DIN_READ_CH_PIN_04)); + Serial.println("CH05: " + String((inputs & (1 << DIN_READ_CH_PIN_05)) >> DIN_READ_CH_PIN_05)); + Serial.println("CH06: " + String((inputs & (1 << DIN_READ_CH_PIN_06)) >> DIN_READ_CH_PIN_06)); + Serial.println("CH07: " + String((inputs & (1 << DIN_READ_CH_PIN_07)) >> DIN_READ_CH_PIN_07)); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/Digital_input/Digital_input.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/Digital_input/Digital_input.ino new file mode 100644 index 00000000..9a9c825f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/Digital_input/Digital_input.ino @@ -0,0 +1,76 @@ +/* + Machine Control - Digital Input Example + + This sketch shows how to periodically read from all the DIGITAL + INPUTS channels on the Machine Control. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ +#include +#include "Wire.h" + +using namespace machinecontrol; +uint16_t readings = 0; + +void setup() { + Serial.begin(9600); + //The loop starts only when the Serial Monitor is opened. + while (!Serial) + ; + Wire.begin(); + + if (!digital_inputs.init()) { + Serial.println("Digital input GPIO expander initialization fail!!"); + } +} + +void loop() { + //Reads and Prints all channels (in a single operation) + readAll(); + + //Read one-by-one each channel and print them one-by-one + readings = digital_inputs.read(DIN_READ_CH_PIN_00); + Serial.println("CH00: " + String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_01); + Serial.println("CH01: " + String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_02); + Serial.println("CH02: " + String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_03); + Serial.println("CH03: " + String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_04); + Serial.println("CH04: " + String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_05); + Serial.println("CH05: " + String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_06); + Serial.println("CH06: " + String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_07); + Serial.println("CH07: " + String(readings)); + + Serial.println(); + + delay(250); +} + +uint8_t readAll() { + uint32_t inputs = digital_inputs.readAll(); + Serial.println("CH00: " + String((inputs & (1 << DIN_READ_CH_PIN_00)) >> DIN_READ_CH_PIN_00)); + Serial.println("CH01: " + String((inputs & (1 << DIN_READ_CH_PIN_01)) >> DIN_READ_CH_PIN_01)); + Serial.println("CH02: " + String((inputs & (1 << DIN_READ_CH_PIN_02)) >> DIN_READ_CH_PIN_02)); + Serial.println("CH03: " + String((inputs & (1 << DIN_READ_CH_PIN_03)) >> DIN_READ_CH_PIN_03)); + Serial.println("CH04: " + String((inputs & (1 << DIN_READ_CH_PIN_04)) >> DIN_READ_CH_PIN_04)); + Serial.println("CH05: " + String((inputs & (1 << DIN_READ_CH_PIN_05)) >> DIN_READ_CH_PIN_05)); + Serial.println("CH06: " + String((inputs & (1 << DIN_READ_CH_PIN_06)) >> DIN_READ_CH_PIN_06)); + Serial.println("CH07: " + String((inputs & (1 << DIN_READ_CH_PIN_07)) >> DIN_READ_CH_PIN_07)); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/GPIO_programmable/GPIO_programmable.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/GPIO_programmable/GPIO_programmable.ino new file mode 100644 index 00000000..b751d110 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/GPIO_programmable/GPIO_programmable.ino @@ -0,0 +1,88 @@ +/* + Machine Control - IOExpander Read And Write Example + + This sketch shows how to use the GPIO Expanders on the Machine Control, + how to periodically send a value on the PROGRAMMABLE DIGITAL I/O + output channels and how to periodically read from the PROGRAMMABLE + DIGITAL I/O input channels. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ + +#include +#include "Wire.h" +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + Wire.begin(); + if (!digital_programmables.init()) { + Serial.println("GPIO expander initialization fail!!"); + } + + Serial.println("GPIO expander initialization done"); + digital_programmables.setLatch(); +} + +void loop() { + // Write the status value to On to Pin 3 + digital_programmables.set(IO_WRITE_CH_PIN_03, SWITCH_ON); + delay(1000); + + // Read from Pin 3 + Serial.println("Read Pin 03: " + String(digital_programmables.read(IO_READ_CH_PIN_03))); + delay(1000); + + // Write the status value to Off to Pin 3 + digital_programmables.set(IO_WRITE_CH_PIN_03, SWITCH_OFF); + delay(1000); + + Serial.println(); + // Sets all the status Pins Values to On in one single operation + uint32_t status = ON_VALUE_PIN_10 | ON_VALUE_PIN_08 | ON_VALUE_PIN_06 | ON_VALUE_PIN_04 | ON_VALUE_PIN_02 | ON_VALUE_PIN_00; + digital_programmables.writeAll(status); + delay(1000); + + // Toggles the actual status values of all digital programmables Pins + digital_programmables.toggle(); + delay(1000); + + Serial.println(); + // Write the status value to On to all the Output Pins + digital_programmables.writeAll(SWITCH_ON_ALL); + + // Reads from all Input Pins + readAll(); + delay(1000); + + // Write the status value to Off all to all the Output Pins + digital_programmables.writeAll(SWITCH_OFF_ALL); + + // Reads from all Input Pins + readAll(); + Serial.println(); + delay(1000); +} + +uint8_t readAll() { + uint32_t inputs = digital_programmables.readAll(); + Serial.println("CH00: " + String((inputs & (1 << IO_READ_CH_PIN_00)) >> IO_READ_CH_PIN_00)); + Serial.println("CH01: " + String((inputs & (1 << IO_READ_CH_PIN_01)) >> IO_READ_CH_PIN_01)); + Serial.println("CH02: " + String((inputs & (1 << IO_READ_CH_PIN_02)) >> IO_READ_CH_PIN_02)); + Serial.println("CH03: " + String((inputs & (1 << IO_READ_CH_PIN_03)) >> IO_READ_CH_PIN_03)); + Serial.println("CH04: " + String((inputs & (1 << IO_READ_CH_PIN_04)) >> IO_READ_CH_PIN_04)); + Serial.println("CH05: " + String((inputs & (1 << IO_READ_CH_PIN_05)) >> IO_READ_CH_PIN_05)); + Serial.println("CH06: " + String((inputs & (1 << IO_READ_CH_PIN_06)) >> IO_READ_CH_PIN_06)); + Serial.println("CH07: " + String((inputs & (1 << IO_READ_CH_PIN_07)) >> IO_READ_CH_PIN_07)); + Serial.println("CH08: " + String((inputs & (1 << IO_READ_CH_PIN_08)) >> IO_READ_CH_PIN_08)); + Serial.println("CH09: " + String((inputs & (1 << IO_READ_CH_PIN_09)) >> IO_READ_CH_PIN_09)); + Serial.println("CH10: " + String((inputs & (1 << IO_READ_CH_PIN_10)) >> IO_READ_CH_PIN_10)); + Serial.println("CH11: " + String((inputs & (1 << IO_READ_CH_PIN_11)) >> IO_READ_CH_PIN_11)); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Encoders/Encoders.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Encoders/Encoders.ino new file mode 100644 index 00000000..38e84d4e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Encoders/Encoders.ino @@ -0,0 +1,29 @@ +#include + +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; +} + +void loop() { + // put your main code here, to run repeatedly: + Serial.print("Encoder 0 State: "); + Serial.println(encoders[0].getCurrentState(), BIN); + Serial.print("Encoder 0 Pulses: "); + Serial.println(encoders[0].getPulses()); + Serial.print("Encoder 0 Revolutions: "); + Serial.println(encoders[0].getRevolutions()); + Serial.println(); + + Serial.print("Encoder 1 State: "); + Serial.println(encoders[1].getCurrentState(), BIN); + Serial.print("Encoder 1 Pulses: "); + Serial.println(encoders[1].getPulses()); + Serial.print("Encoder 1 Revolutions: "); + Serial.println(encoders[1].getRevolutions()); + Serial.println(); + delay(25); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Ethernet/Ethernet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Ethernet/Ethernet.ino new file mode 100644 index 00000000..07b5ed2e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Ethernet/Ethernet.ino @@ -0,0 +1,82 @@ +#include "EthernetInterface.h" +EthernetInterface net; + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + Serial.println("Ethernet example for H7 + PMC"); + + // Bring up the ethernet interface + net.connect(); + + // Show the network address + SocketAddress addr; + net.get_ip_address(&addr); + Serial.print("IP address: "); + Serial.println(addr.get_ip_address() ? addr.get_ip_address() : "None"); + + // Open a socket on the network interface, and create a TCP connection to mbed.org + TCPSocket socket; + socket.open(&net); + + net.gethostbyname("ifconfig.io", &addr); + addr.set_port(80); + socket.connect(addr); + + String request; + request += "GET / HTTP/1.1\r\n"; + request += "Host: ifconfig.io\r\n"; + request += "User-Agent: curl/7.64.1\r\n"; + request += "Accept: */*\r\n"; + request += "Connection: close\r\n"; + request += "\r\n"; + + auto scount = socket.send(request.c_str(), request.length()); + Serial.print("Sent "); + Serial.print(scount); + Serial.println(" bytes: "); + Serial.print(request); + + // Receive a simple HTTP response + const size_t rlen{ 64 }; + char rbuffer[rlen + 1]{}; + size_t rcount; + size_t rec{ 0 }; + String response; + + while ((rec = socket.recv(rbuffer, rlen)) > 0) { + rcount += rec; + response += rbuffer; + memset(rbuffer, 0, rlen); + } + Serial.print("Received "); + Serial.print(rcount); + Serial.println(" bytes: "); + Serial.println(response); + + const String clTag = "Content-Length: "; + auto clIndex = response.indexOf(clTag); + clIndex += clTag.length(); + auto cl = response.substring(clIndex, clIndex + 2); + const String bodyTag = "\r\n\r\n"; + auto bodyIndex = response.indexOf(bodyTag); + if (bodyIndex != -1) { + bodyIndex += bodyTag.length(); + auto body = response.substring(bodyIndex, bodyIndex + cl.toInt()); + Serial.print("My public IPv4 Address is: "); + Serial.println(body); + } + + + // Close the socket to return its memory and bring down the network interface + socket.close(); + + // Bring down the ethernet interface + net.disconnect(); + Serial.println("Done"); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS232/RS232.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS232/RS232.ino new file mode 100644 index 00000000..f665a95c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS232/RS232.ino @@ -0,0 +1,86 @@ +/* + RS232 communication + + This sketch shows how to use the SP335ECR1 on the Machine + Control as a RS232 interface, how to periodically send + a string on the RS232 TX channel and how to receive data + from the interface RX channel. + + Circuit: + - Arduino Portenta Machine Control (PMC) + - Device with RS232 interface + - Connect PMC TXN to RS232 Device RXD + - Connect PMC RXP to RS232 Device TXD + - Connect PMC GND to RS232 Device GND + +*/ + +#include + +using namespace machinecontrol; + +constexpr unsigned long sendInterval{ 1000 }; +unsigned long sendNow{ 0 }; + +unsigned long counter{ 0 }; + +void setup() { + + Serial.begin(115200); + // Wait for Serial or start after 2.5s + for (auto const timeout = millis() + 2500; !Serial && timeout < millis(); delay(500)) + ; + + delay(2500); + Serial.println("Start RS232 initialization"); + + // Set the PMC Communication Protocols to default config + comm_protocols.init(); + + // RS485/RS232 default config is: + // - RS485/RS232 system disabled + // - RS485 mode + // - Half Duplex + // - No A/B and Y/Z 120 Ohm termination enabled + + // Enable the RS485/RS232 system + comm_protocols.rs485Enable(true); + // Enable the RS232 mode + comm_protocols.rs485ModeRS232(true); + + // Specify baudrate for RS232 communication + comm_protocols.rs485.begin(115200); + // Start in receive mode + comm_protocols.rs485.receive(); + + Serial.println("Initialization done!"); +} + +void loop() { + if (comm_protocols.rs485.available()) + Serial.write(comm_protocols.rs485.read()); + + if (millis() > sendNow) { + String log = "["; + log += sendNow; + log += "] "; + + String msg = "hello "; + msg += counter++; + + log += msg; + Serial.println(log); + + // Disable receive mode before transmission + comm_protocols.rs485.noReceive(); + + comm_protocols.rs485.beginTransmission(); + comm_protocols.rs485.println(msg); + comm_protocols.rs485.endTransmission(); + + // Re-enable receive mode after transmission + comm_protocols.rs485.receive(); + + sendNow = millis() + sendInterval; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_fullduplex/RS485_fullduplex.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_fullduplex/RS485_fullduplex.ino new file mode 100644 index 00000000..93fbffce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_fullduplex/RS485_fullduplex.ino @@ -0,0 +1,79 @@ +/* + RS485 Full duplex communication + + This sketch shows how to use the SP335ECR1 on the Machine + Control as a full duplex (AB and YZ) RS485 interface, how to periodically + send a string on the RS485 TX channel and how to receive data + from the interface RX channel. + + Circuit: + - Portenta H7 + - Machine Control + - A Slave device with RS485 interface + - Connect TXP to A(+) and TXN to B(-) + - Connect RXP to Y(+) and RXN to Z(-) + +*/ + +#include "Arduino_MachineControl.h" + +using namespace machinecontrol; + +constexpr unsigned long sendInterval{ 1000 }; +unsigned long sendNow{ 0 }; +unsigned long counter = 0; + +void setup() { + + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. + } + delay(1000); + Serial.println("Start RS485 initialization"); + + // Set the PMC Communication Protocols to default config + comm_protocols.init(); + // RS485/RS232 default config is: + // - RS485 mode + // - Half Duplex + // - No A/B and Y/Z 120 Ohm termination enabled + + // Enable the RS485/RS232 system + comm_protocols.rs485Enable(true); + + // Enable Full Duplex mode + // This will also enable A/B and Y/Z 120 Ohm termination resistors + comm_protocols.rs485FullDuplex(true); + + // Specify baudrate, and preamble and postamble times for RS485 communication + comm_protocols.rs485.begin(115200, 0, 500); + + // Start in receive mode + comm_protocols.rs485.receive(); + + + Serial.println("Initialization done!"); +} + +void loop() { + if (comm_protocols.rs485.available()) + Serial.write(comm_protocols.rs485.read()); + + if (millis() > sendNow) { + // Disable receive mode before transmission + comm_protocols.rs485.noReceive(); + + comm_protocols.rs485.beginTransmission(); + + comm_protocols.rs485.print("hello "); + comm_protocols.rs485.println(counter++); + + comm_protocols.rs485.endTransmission(); + + // Re-enable receive mode after transmission + comm_protocols.rs485.receive(); + + sendNow = millis() + sendInterval; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_halfduplex/RS485_halfduplex.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_halfduplex/RS485_halfduplex.ino new file mode 100644 index 00000000..d1f8cae4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_halfduplex/RS485_halfduplex.ino @@ -0,0 +1,75 @@ +/* + RS485 Half Duplex communication + + This sketch shows how to use the SP335ECR1 on the Machine + Control as a half duplex (AB) RS485 interface, how to periodically + send a string on the RS485 TX channel and how to receive data + from the interface RX channel. + + Circuit: + - Portenta H7 + - Machine Control + - A Slave device with RS485 interface + - Connect TXP to A(+) and TXN to B(-) + +*/ + +#include "Arduino_MachineControl.h" + +using namespace machinecontrol; + +constexpr unsigned long sendInterval{ 1000 }; +unsigned long sendNow{ 0 }; + +unsigned long counter{ 0 }; + +void setup() { + + Serial.begin(115200); + // Wait for Serial or start after 2.5s + for (auto const timeout = millis() + 2500; !Serial && timeout < millis(); delay(500)) + ; + + delay(2500); + Serial.println("Start RS485 initialization"); + + // Set the PMC Communication Protocols to default config + comm_protocols.init(); + + // RS485/RS232 default config is: + // - RS485 mode + // - Half Duplex + // - No A/B and Y/Z 120 Ohm termination enabled + + // Enable the RS485/RS232 system + comm_protocols.rs485Enable(true); + + // Specify baudrate, and preamble and postamble times for RS485 communication + comm_protocols.rs485.begin(115200, 0, 500); + // Start in receive mode + comm_protocols.rs485.receive(); + + Serial.println("Initialization done!"); +} + +void loop() { + if (comm_protocols.rs485.available()) + Serial.write(comm_protocols.rs485.read()); + + if (millis() > sendNow) { + // Disable receive mode before transmission + comm_protocols.rs485.noReceive(); + + comm_protocols.rs485.beginTransmission(); + + comm_protocols.rs485.print("hello "); + comm_protocols.rs485.println(counter++); + + comm_protocols.rs485.endTransmission(); + + // Re-enable receive mode after transmission + comm_protocols.rs485.receive(); + + sendNow = millis() + sendInterval; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RTC/RTC.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RTC/RTC.ino new file mode 100644 index 00000000..f74c5b68 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RTC/RTC.ino @@ -0,0 +1,68 @@ +/* + Machine Control - RTC Example + + This sketch shows how to use the RTC PCF8563T on the Machine + Control Carrier and how to configure the PCF8563T's + time registers. + + Circuit: + - Portenta H7 + - Machine Control + +*/ +#include + +using namespace machinecontrol; + +int years = 20; +int months = 9; +int days = 24; +int hours = 12; +int minutes = 43; +int seconds = 31; + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. + } + + Serial.println("Initialization"); + if (!rtc_controller.begin()) { + Serial.println("Initialization fail!"); + } + Serial.println("Initialization Done!"); + + // APIs to set date's fields: years, months, days, hours, minutes and seconds + // The RTC time can be set as epoch, using one of the following two options: + // - Calendar time: rtc_controller.setEpoch(years, months, days, hours, minutes, seconds); + // - UTC time: rtc_controller.setEpoch(date_in_seconds); + rtc_controller.setYears(years); + rtc_controller.setMonths(months); + rtc_controller.setDays(days); + rtc_controller.setHours(hours); + rtc_controller.setMinutes(minutes); + rtc_controller.setSeconds(seconds); + rtc_controller.setEpoch(); +} + +void loop() { + // APIs to get date's fields. + Serial.print("Date: "); + Serial.print(rtc_controller.getYears()); + Serial.print("/"); + Serial.print(rtc_controller.getMonths()); + Serial.print("/"); + Serial.print(rtc_controller.getDays()); + Serial.print(" - "); + Serial.print(rtc_controller.getHours()); + Serial.print(":"); + Serial.print(rtc_controller.getMinutes()); + Serial.print(":"); + Serial.println(rtc_controller.getSeconds()); + time_t utc_time = time(NULL); + Serial.print("Date as UTC time: "); + Serial.println(utc_time); + Serial.println(); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RTC_Alarm/RTC_Alarm.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RTC_Alarm/RTC_Alarm.ino new file mode 100644 index 00000000..41c4e7b7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/RTC_Alarm/RTC_Alarm.ino @@ -0,0 +1,81 @@ +/* + Machine Control - RTC Alarm Example + + This sketch shows how to use the RTC PCF8563T on the Machine + Control Carrier and how to configure and use the PCF8563T's + alarm. + + Circuit: + - Portenta H7 + - Machine Control + +*/ +#include + +using namespace machinecontrol; + +int hours = 12; +int minutes = 45; +int seconds = 57; + +void callback_alarm(); + +bool alarm_flag = false; + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. + } + Serial.println("Initialization"); + + if (!rtc_controller.begin()) { + Serial.println("Initialization fail!"); + } + + + Serial.println("Initialization Done!"); + + // APIs to set date's fields: hours, minutes and seconds + rtc_controller.setHours(hours); + rtc_controller.setMinutes(minutes); + rtc_controller.setSeconds(seconds); + // Enables Alarm on PCF8563T + rtc_controller.enableAlarm(); + + // set the minutes at which the alarm should rise + rtc_controller.setMinuteAlarm(46); + + // Attach an interrupt to the RTC interrupt pin + attachInterrupt(RTC_INT, callback_alarm, FALLING); + + Serial.println(); +} +int counter = 1; +void loop() { + if (alarm_flag) { + Serial.println("Alarm!!"); + detachInterrupt(RTC_INT); + rtc_controller.setSeconds(seconds); + rtc_controller.setMinuteAlarm(minutes + counter); + rtc_controller.clearAlarm(); + attachInterrupt(RTC_INT, callback_alarm, FALLING); + alarm_flag = false; + + // To disable the alarm uncomment the following line: + // rtc_controller.disableAlarm(); + } + + // APIs to get date's fields. + //Serial.println(digitalRead(rtc_controller.int_pin)); + Serial.print(rtc_controller.getHours()); + Serial.print(":"); + Serial.print(rtc_controller.getMinutes()); + Serial.print(":"); + Serial.println(rtc_controller.getSeconds()); + delay(1000); +} + +void callback_alarm() { + alarm_flag = true; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_RTD/Temp_probes_RTD.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_RTD/Temp_probes_RTD.ino new file mode 100644 index 00000000..42ac425e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_RTD/Temp_probes_RTD.ino @@ -0,0 +1,163 @@ +/* + Machine Control - Temperature probes RTD example + + This example provides a way to test the 3-wire RTDs + on the Machine control Carrier. It is possible to + acquire 2-wire RTD simply by shorting the RTDx pin + to the TPx pin. The Machine control carrier has on + board a precise 400 ohm 0.1% reference resistor which + is used as a reference by the MAX31865. + + The circuit: + - Portenta H7 + - Portenta Machine Control Carrier + - 3-wire RTD or 2-wire RTD +*/ + +#include + +using namespace machinecontrol; + +// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000 +#define RREF 400.0 +// The 'nominal' 0-degrees-C resistance of the sensor +// 100.0 for PT100, 1000.0 for PT1000 +#define RNOMINAL 100.0 + +void setup() { + Serial.begin(9600); + Serial.println("MAX31865 PT100 Sensor Test!"); + temp_probes.rtd.begin(THREE_WIRE); + temp_probes.enableRTD(); +} + +void loop() { + temp_probes.selectChannel(0); + Serial.println("CHANNEL 0 SELECTED"); + uint16_t rtd = temp_probes.rtd.readRTD(); + float ratio = rtd; + ratio /= 32768; + + // Check and print any faults + uint8_t fault = temp_probes.rtd.readFault(); + if (fault) { + Serial.print("Fault 0x"); + Serial.println(fault, HEX); + if (temp_probes.rtd.getHighThresholdFault(fault)) { + Serial.println("RTD High Threshold"); + } + if (temp_probes.rtd.getLowThresholdFault(fault)) { + Serial.println("RTD Low Threshold"); + } + if (temp_probes.rtd.getLowREFINFault(fault)) { + Serial.println("REFIN- > 0.85 x Bias"); + } + if (temp_probes.rtd.getHighREFINFault(fault)) { + Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getLowRTDINFault(fault)) { + Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getVoltageFault(fault)) { + Serial.println("Under/Over voltage"); + } + temp_probes.rtd.clearFault(); + } else { + Serial.print("RTD value: "); + Serial.println(rtd); + Serial.print("Ratio = "); + Serial.println(ratio, 8); + Serial.print("Resistance = "); + Serial.println(RREF * ratio, 8); + Serial.print("Temperature = "); + Serial.println(temp_probes.rtd.readTemperature(RNOMINAL, RREF)); + } + Serial.println(); + delay(100); + + temp_probes.selectChannel(1); + Serial.println("CHANNEL 1 SELECTED"); + rtd = temp_probes.rtd.readRTD(); + ratio = rtd; + ratio /= 32768; + + // Check and print any faults + fault = temp_probes.rtd.readFault(); + if (fault) { + Serial.print("Fault 0x"); + Serial.println(fault, HEX); + if (temp_probes.rtd.getHighThresholdFault(fault)) { + Serial.println("RTD High Threshold"); + } + if (temp_probes.rtd.getLowThresholdFault(fault)) { + Serial.println("RTD Low Threshold"); + } + if (temp_probes.rtd.getLowREFINFault(fault)) { + Serial.println("REFIN- > 0.85 x Bias"); + } + if (temp_probes.rtd.getHighREFINFault(fault)) { + Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getLowRTDINFault(fault)) { + Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getVoltageFault(fault)) { + Serial.println("Under/Over voltage"); + } + temp_probes.rtd.clearFault(); + } else { + Serial.print("RTD value: "); + Serial.println(rtd); + Serial.print("Ratio = "); + Serial.println(ratio, 8); + Serial.print("Resistance = "); + Serial.println(RREF * ratio, 8); + Serial.print("Temperature = "); + Serial.println(temp_probes.rtd.readTemperature(RNOMINAL, RREF)); + } + Serial.println(); + delay(100); + + temp_probes.selectChannel(2); + Serial.println("CHANNEL 2 SELECTED"); + rtd = temp_probes.rtd.readRTD(); + ratio = rtd; + ratio /= 32768; + + // Check and print any faults + fault = temp_probes.rtd.readFault(); + if (fault) { + Serial.print("Fault 0x"); + Serial.println(fault, HEX); + if (temp_probes.rtd.getHighThresholdFault(fault)) { + Serial.println("RTD High Threshold"); + } + if (temp_probes.rtd.getLowThresholdFault(fault)) { + Serial.println("RTD Low Threshold"); + } + if (temp_probes.rtd.getLowREFINFault(fault)) { + Serial.println("REFIN- > 0.85 x Bias"); + } + if (temp_probes.rtd.getHighREFINFault(fault)) { + Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getLowRTDINFault(fault)) { + Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getVoltageFault(fault)) { + Serial.println("Under/Over voltage"); + } + temp_probes.rtd.clearFault(); + } else { + Serial.print("RTD value: "); + Serial.println(rtd); + Serial.print("Ratio = "); + Serial.println(ratio, 8); + Serial.print("Resistance = "); + Serial.println(RREF * ratio, 8); + Serial.print("Temperature = "); + Serial.println(temp_probes.rtd.readTemperature(RNOMINAL, RREF)); + } + Serial.println(); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_Thermocouples/Temp_probes_Thermocouples.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_Thermocouples/Temp_probes_Thermocouples.ino new file mode 100644 index 00000000..446b9417 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_Thermocouples/Temp_probes_Thermocouples.ino @@ -0,0 +1,59 @@ +/* + Machine Control - Thermocouples Read Sensors + + This example reads the temperatures measured by the thermocouples + connected to the Machine Control Carrier's temp probe inputs and prints + them to the Serial Monitor once a second. + + The circuit: + - Portenta H7 + - Portenta Machine Control Carrier + - Two K Type thermocouple temperature sensors connected to + TEMP PROBES CH0 and CH1 on the Machine Control + - A J Type thermocouple temperature sensor connected to + TEMP PROBES CH3 on the Machine Control + + This example code is in the public domain. +*/ + +#include + +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + // Initialize temperature probes + temp_probes.tc.begin(); + Serial.println("Temperature probes initialization done"); + // Enables Thermocouples chip select + temp_probes.enableTC(); + Serial.println("Thermocouples enabled"); +} + +void loop() { + //Set CH0, has internal 150 ms delay + temp_probes.selectChannel(0); + //Take CH0 measurement + float temp_ch0 = temp_probes.tc.readTemperature(); + Serial.print("Temperature CH0 [°C]: "); + Serial.print(temp_ch0); + Serial.println(); + + //Set CH1, has internal 150 ms delay + temp_probes.selectChannel(1); + //Take CH1 measurement + float temp_ch1 = temp_probes.tc.readTemperature(); + Serial.print("Temperature CH1 [°C]: "); + Serial.print(temp_ch1); + Serial.println(); + + //Set CH2, has internal 150 ms delay + temp_probes.selectChannel(2); + //Take CH2 measurement + float temp_ch2 = temp_probes.tc.readTemperature(); + Serial.print("Temperature CH2 [°C]: "); + Serial.print(temp_ch2); + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/TUSB_helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/TUSB_helpers.h new file mode 100644 index 00000000..db72ab3d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/TUSB_helpers.h @@ -0,0 +1,150 @@ +/* + _______ _ _ _____ ____ + |__ __| | | | |/ ____| _ \ + | | ___ ___ _ __ _ _| | | | (___ | |_) | + | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < + | | __/ __/ | | | |_| | |__| |____) | |_) | + |_|\___|\___|_| |_|\__, |\____/|_____/|____/ + __/ | + |___/ + + TeenyUSB - light weight usb stack for STM32 micro controllers + + Copyright (c) 2019 XToolBox - admin@xtoolbox.org + www.tusb.org + + 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. +*/ + +#pragma once + +#include + +static const tusbh_boot_key_class_t cls_boot_key = { + .backend = &tusbh_boot_keyboard_backend, + //.on_key = process_key +}; + +static const tusbh_boot_mouse_class_t cls_boot_mouse = { + .backend = &tusbh_boot_mouse_backend, + // .on_mouse = process_mouse +}; + +static const tusbh_hid_class_t cls_hid = { + .backend = &tusbh_hid_backend, + //.on_recv_data = process_hid_recv, + //.on_send_done = process_hid_sent, +}; + +static const tusbh_hub_class_t cls_hub = { + .backend = &tusbh_hub_backend, +}; + +static const tusbh_vendor_class_t cls_vendor = { + .backend = &tusbh_vendor_backend, + //.transfer_done = process_vendor_xfer_done +}; + +int msc_ff_mount(tusbh_interface_t* interface, int max_lun, const tusbh_block_info_t* blocks); +int msc_ff_unmount(tusbh_interface_t* interface); + +static const tusbh_msc_class_t cls_msc_bot = { + .backend = &tusbh_msc_bot_backend, + // .mount = msc_ff_mount, + // .unmount = msc_ff_unmount, +}; + +static const tusbh_cdc_acm_class_t cls_cdc_acm = { + .backend = &tusbh_cdc_acm_backend, +}; + +static const tusbh_cdc_rndis_class_t cls_cdc_rndis = { + .backend = &tusbh_cdc_rndis_backend, +}; + +static const tusbh_class_reg_t class_table[] = { + (tusbh_class_reg_t)&cls_boot_key, + (tusbh_class_reg_t)&cls_boot_mouse, + (tusbh_class_reg_t)&cls_hub, + (tusbh_class_reg_t)&cls_msc_bot, + (tusbh_class_reg_t)&cls_cdc_acm, + (tusbh_class_reg_t)&cls_cdc_rndis, + (tusbh_class_reg_t)&cls_hid, + (tusbh_class_reg_t)&cls_vendor, + 0, +}; + +#define MOD_CTRL (0x01 | 0x10) +#define MOD_SHIFT (0x02 | 0x20) +#define MOD_ALT (0x04 | 0x40) +#define MOD_WIN (0x08 | 0x80) + +#define LED_NUM_LOCK 1 +#define LED_CAPS_LOCK 2 +#define LED_SCROLL_LOCK 4 + +#define stdin_recvchar Serial1.write + +static uint8_t key_leds; +static const char knum[] = "1234567890"; +static const char ksign[] = "!@#$%^&*()"; +static const char tabA[] = "\t -=[]\\#;'`,./"; +static const char tabB[] = "\t _+{}|~:\"~<>?"; + +// route the key event to stdin +static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) { + Serial.println(); + + uint8_t modify = keys[0]; + uint8_t key = keys[2]; + uint8_t last_leds = key_leds; + if (key >= KEY_A && key <= KEY_Z) { + char ch = 'A' + key - KEY_A; + if ((!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK))) { + ch += 'a' - 'A'; + } + stdin_recvchar(ch); + Serial.print(ch); + } else if (key >= KEY_1 && key <= KEY_0) { + if (modify & MOD_SHIFT) { + stdin_recvchar(ksign[key - KEY_1]); + } else { + stdin_recvchar(knum[key - KEY_1]); + } + } else if (key >= KEY_TAB && key <= KEY_SLASH) { + if (modify & MOD_SHIFT) { + stdin_recvchar(tabB[key - KEY_TAB]); + } else { + stdin_recvchar(tabA[key - KEY_TAB]); + } + } else if (key == KEY_ENTER) { + stdin_recvchar('\r'); + } else if (key == KEY_CAPSLOCK) { + key_leds ^= LED_CAPS_LOCK; + } else if (key == KEY_NUMLOCK) { + key_leds ^= LED_NUM_LOCK; + } else if (key == KEY_SCROLLLOCK) { + key_leds ^= LED_SCROLL_LOCK; + } + + if (key_leds != last_leds) { + tusbh_set_keyboard_led(ep, key_leds); + } + return 0; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/USB_host.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/USB_host.ino new file mode 100644 index 00000000..d5bca420 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/USB_host.ino @@ -0,0 +1,21 @@ +#include +#include + +#include "TUSB_helpers.h" + +using namespace machinecontrol; + +// Redirect log output from MbedOS and low-level libraries to Serial +REDIRECT_STDOUT_TO(Serial); + +USBHost usb; + +void setup() { + Serial1.begin(115200); + usb_controller.powerEnable(); + usb.Init(USB_CORE_ID_FS, class_table); +} + +void loop() { + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/LICENSE.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/LICENSE.md new file mode 100644 index 00000000..a39b7233 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/LICENSE.md @@ -0,0 +1,39 @@ +Copyright (C) 2011 - 2014 Bosch Sensortec GmbH + +Arduino_NAxisMotion Library +Date: 2014/09/12 +Usage:Library and example code for the BNO055 + +License: + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +Neither the name of the copyright holder nor the names of the +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + +The information provided is believed to be accurate and reliable. +The copyright holder assumes no responsibility for the consequences of use +of such information nor for any infringement of patents or +other rights of third parties which may result from its use. +No license is granted by implication or otherwise under any patent or +patent rights of the copyright holder. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/README.md new file mode 100644 index 00000000..44ec8225 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/README.md @@ -0,0 +1,48 @@ +> **Note:** this library is deprecated and no longer maintained. + +9 Axes Motion Library + +[![Check Arduino status](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/spell-check.yml) + +----------- +The Arduino_NineAxesMotion.cpp and Arduino_NineAxesMotion.h files are C++ wrapper codes for the +BNO055.c and BNO055.h Sensor API. The wrapper code has been designed to +abstract the Sensor API and also to give an idea on how to use the +advanced features in the Sensor API. Apart from that it acts a bridge +between the Sensor API and the Arduino framework. Copy this library into +"yourArduinoInstallation"/libraries folder. + + +------------------------------------------------------------------------------- +There are 4 examples with the 9 Axes Motion library. + + - BareMinimum: This example code is as the name says the minimum code + required to use the 9 Axes Motion shield. + + - Euler: This example code reads out the Euler angles in the NDoF mode to + the Serial Monitor. It also reads out the Calibration Status. Each sensor + and the System itself has its own Calibration Status. See below on how to + calibrate each of the sensors. + + - Accelerometer: This example code reads out the Accelerometer data and + associated data which are the Linear Acceleration data, which is the + Accelerometer data without the gravity vector, the other is the Gravity + Acceleration data, which is only the gravity vector. + + - Motion: This example code is a game to test how steadily you can move an + object, in this case it is the shield with the Arduino board. The goal is + to demonstrate on how to use the Any motion and No motion Interrupts. + +Calibration helps the Sensor identify its environment and automatically +determine offsets. Follow the instructions below to calibrate your sensor. + + - Gyroscope: Keep it steady and do not move it. Preferably keep it on a fixed + surface such as a table. + + - Accelerometer: Rotate the shield slowly and pause at every 45deg for a + second. Rotate one 1 axis at a time. Preferably rotate along 2 axes. + + - Magnetometer: Move the magnetometer in a large 8 like pattern a few times + gently. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Accelerometer/Accelerometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Accelerometer/Accelerometer.ino new file mode 100644 index 00000000..6819153c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Accelerometer/Accelerometer.ino @@ -0,0 +1,144 @@ +/**************************************************************************** +* Copyright (C) 2011 - 2014 Bosch Sensortec GmbH +* +* Accelerometer.ino +* Date: 2014/09/09 +* Revision: 3.0 $ +* +* Usage: Example code to stream Accelerometer data +* +**************************************************************************** +/*************************************************************************** +* License: +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* Neither the name of the copyright holder nor the names of the +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE +* +* The information provided is believed to be accurate and reliable. +* The copyright holder assumes no responsibility for the consequences of use +* of such information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of the copyright holder. +*/ + +#include "Arduino_NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment +#include + +NineAxesMotion mySensor; //Object that for the sensor +unsigned long lastStreamTime = 0; //To store the last streamed time stamp +const int streamPeriod = 40; //To stream at 25Hz without using additional timers (time period(ms) =1000/frequency(Hz)) +bool updateSensorData = true; //Flag to update the sensor data. Default is true to perform the first read before the first stream + +void setup() //This code is executed once +{ + //Peripheral Initialization + Serial.begin(9600); //Initialize the Serial Port to view information on the Serial Monitor + Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + //Sensor Initialization + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired + mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to manual requires calling the relevant update functions prior to calling the read functions + //Setting to MANUAL requires lesser reads to the sensor + mySensor.updateAccelConfig(); + updateSensorData = true; + Serial.println(); + Serial.println("Default accelerometer configuration settings..."); + Serial.print("Range: "); + Serial.println(mySensor.readAccelRange()); + Serial.print("Bandwidth: "); + Serial.println(mySensor.readAccelBandwidth()); + Serial.print("Power Mode: "); + Serial.println(mySensor.readAccelPowerMode()); + Serial.println("Streaming in ..."); //Countdown + Serial.print("3..."); + delay(1000); //Wait for a second + Serial.print("2..."); + delay(1000); //Wait for a second + Serial.println("1..."); + delay(1000); //Wait for a second +} + +void loop() //This code is looped forever +{ + if (updateSensorData) //Keep the updating of data as a separate task + { + mySensor.updateAccel(); //Update the Accelerometer data + mySensor.updateLinearAccel(); //Update the Linear Acceleration data + mySensor.updateGravAccel(); //Update the Gravity Acceleration data + mySensor.updateCalibStatus(); //Update the Calibration Status + updateSensorData = false; + } + if ((millis() - lastStreamTime) >= streamPeriod) { + lastStreamTime = millis(); + + Serial.print("Time: "); + Serial.print(lastStreamTime); + Serial.print("ms "); + + Serial.print(" aX: "); + Serial.print(mySensor.readAccelerometer(X_AXIS)); //Accelerometer X-Axis data + Serial.print("m/s2 "); + + Serial.print(" aY: "); + Serial.print(mySensor.readAccelerometer(Y_AXIS)); //Accelerometer Y-Axis data + Serial.print("m/s2 "); + + Serial.print(" aZ: "); + Serial.print(mySensor.readAccelerometer(Z_AXIS)); //Accelerometer Z-Axis data + Serial.print("m/s2 "); + + Serial.print(" lX: "); + Serial.print(mySensor.readLinearAcceleration(X_AXIS)); //Linear Acceleration X-Axis data + Serial.print("m/s2 "); + + Serial.print(" lY: "); + Serial.print(mySensor.readLinearAcceleration(Y_AXIS)); //Linear Acceleration Y-Axis data + Serial.print("m/s2 "); + + Serial.print(" lZ: "); + Serial.print(mySensor.readLinearAcceleration(Z_AXIS)); //Linear Acceleration Z-Axis data + Serial.print("m/s2 "); + + Serial.print(" gX: "); + Serial.print(mySensor.readGravAcceleration(X_AXIS)); //Gravity Acceleration X-Axis data + Serial.print("m/s2 "); + + Serial.print(" gY: "); + Serial.print(mySensor.readGravAcceleration(Y_AXIS)); //Gravity Acceleration Y-Axis data + Serial.print("m/s2 "); + + Serial.print(" gZ: "); + Serial.print(mySensor.readGravAcceleration(Z_AXIS)); //Gravity Acceleration Z-Axis data + Serial.print("m/s2 "); + + Serial.print(" C: "); + Serial.print(mySensor.readAccelCalibStatus()); //Accelerometer Calibration Status (0 - 3) + + Serial.println(); + + updateSensorData = true; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/BareMinimum/BareMinimum.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/BareMinimum/BareMinimum.ino new file mode 100644 index 00000000..ec0b8741 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/BareMinimum/BareMinimum.ino @@ -0,0 +1,64 @@ +/**************************************************************************** +* Copyright (C) 2011 - 2014 Bosch Sensortec GmbH +* +* BareMinimum.ino +* Date: 2014/08/25 +* Revision: 2.1 $ +* +* Usage: Example code to describe the Bare Minimum +* +**************************************************************************** +/*************************************************************************** +* License: +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* Neither the name of the copyright holder nor the names of the +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE +* +* The information provided is believed to be accurate and reliable. +* The copyright holder assumes no responsibility for the consequences of use +* of such information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of the copyright holder. +*/ + +#include "Arduino_NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment +#include + +NineAxesMotion mySensor; //Object that for the sensor + +void setup() //This code is executed once +{ + //Peripheral Initialization + Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + //Sensor Initialization + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired +} + +void loop() //This code is looped forever +{ + //Blank +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Euler/Euler.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Euler/Euler.ino new file mode 100644 index 00000000..637e231a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Euler/Euler.ino @@ -0,0 +1,103 @@ +/**************************************************************************** +* Copyright (C) 2011 - 2014 Bosch Sensortec GmbH +* +* Euler.ino +* Date: 2014/09/09 +* Revision: 3.0 $ +* +* Usage: Example code to stream Euler data +* +**************************************************************************** +/*************************************************************************** +* License: +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* Neither the name of the copyright holder nor the names of the +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE +* +* The information provided is believed to be accurate and reliable. +* The copyright holder assumes no responsibility for the consequences of use +* of such information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of the copyright holder. +*/ + +#include "Arduino_NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment +#include + +NineAxesMotion mySensor; //Object that for the sensor +unsigned long lastStreamTime = 0; //To store the last streamed time stamp +const int streamPeriod = 20; //To stream at 50Hz without using additional timers (time period(ms) =1000/frequency(Hz)) + +void setup() //This code is executed once +{ + //Peripheral Initialization + Serial.begin(9600); //Initialize the Serial Port to view information on the Serial Monitor + Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + //Sensor Initialization + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired + mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions + //Setting to MANUAL requires fewer reads to the sensor +} + +void loop() //This code is looped forever +{ + if ((millis() - lastStreamTime) >= streamPeriod) { + lastStreamTime = millis(); + mySensor.updateEuler(); //Update the Euler data into the structure of the object + mySensor.updateCalibStatus(); //Update the Calibration Status + + Serial.print("Time: "); + Serial.print(lastStreamTime); + Serial.print("ms "); + + Serial.print(" H: "); + Serial.print(mySensor.readEulerHeading()); //Heading data + Serial.print("deg "); + + Serial.print(" R: "); + Serial.print(mySensor.readEulerRoll()); //Roll data + Serial.print("deg"); + + Serial.print(" P: "); + Serial.print(mySensor.readEulerPitch()); //Pitch data + Serial.print("deg "); + + Serial.print(" A: "); + Serial.print(mySensor.readAccelCalibStatus()); //Accelerometer Calibration Status (0 - 3) + + Serial.print(" M: "); + Serial.print(mySensor.readMagCalibStatus()); //Magnetometer Calibration Status (0 - 3) + + Serial.print(" G: "); + Serial.print(mySensor.readGyroCalibStatus()); //Gyroscope Calibration Status (0 - 3) + + Serial.print(" S: "); + Serial.print(mySensor.readSystemCalibStatus()); //System Calibration Status (0 - 3) + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Motion/Motion.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Motion/Motion.ino new file mode 100644 index 00000000..5f724900 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Motion/Motion.ino @@ -0,0 +1,110 @@ +/**************************************************************************** + Copyright (C) 2011 - 2014 Bosch Sensortec GmbH + + Motion.ino + Date: 2014/09/09 + Revision: 2.0 $ + + Usage: Example code of a game to demonstrate the Any motion + and No motion Interrupt features + +**************************************************************************** + /*************************************************************************** + License: + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + Neither the name of the copyright holder nor the names of the + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + + The information provided is believed to be accurate and reliable. + The copyright holder assumes no responsibility for the consequences of use + of such information nor for any infringement of patents or + other rights of third parties which may result from its use. + No license is granted by implication or otherwise under any patent or + patent rights of the copyright holder. +*/ + +#include "Arduino_NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment +#include + +NineAxesMotion mySensor; //Object that for the sensor +bool intDetected = false; //Flag to indicate if an interrupt was detected +int threshold = 5; //At a Range of 4g, the threshold is set at 39.05mg or 0.3830m/s2. This Range is the default for NDOF Mode +int duration = 1; //At a filter Bandwidth of 62.5Hz, the duration is 8ms. This Bandwidth is the default for NDOF Mode +bool anyMotion = true; //To know which interrupt was triggered + +int InterruptPin = 2; // Pin D2 is connected to the INT LED + +void setup() //This code is executed once +{ + //Peripheral Initialization + Serial.begin(9600); //Initialize the Serial Port to view information on the Serial Monitor + Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + //Sensor Initialization + Serial.println("Please wait. Initialization in process."); + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired + mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to manual requires calling the relevant update functions prior to calling the read functions + //Setting to MANUAL requires lesser reads to the sensor + + + attachInterrupt(digitalPinToInterrupt(InterruptPin), motionISR, RISING); //Attach the interrupt to the Interrupt Service Routine for a Rising Edge. Change the interrupt pin depending on the board + + //Setup the initial interrupt to trigger at No Motion + mySensor.resetInterrupt(); + mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION); + anyMotion = false; + mySensor.accelInterrupts(ENABLE, ENABLE, ENABLE); //Accelerometer interrupts can be triggered from all 3 axes + Serial.println("This is a game to test how steady you can move an object with one hand. \nKeep the device on a table and mark 2 points."); + Serial.println("Move the Device from one place to another without triggering the Any Motion Interrupt.\n\n"); + delay(1000); //Delay for the player(s) to read + Serial.println("Move the device around and then place it at one position.\nChange the threshold and duration to increase the difficulty level."); + Serial.println("Have fun!\n\n"); +} + +void loop() //This code is looped forever +{ + if (intDetected) { + if (anyMotion) { + Serial.println("You moved!! Try again. Keep the Device at one place.\n"); + intDetected = false; + mySensor.resetInterrupt(); //Reset the interrupt line + mySensor.disableAnyMotion(); //Disable the Any motion interrupt + mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION); //Enable the No motion interrupt (can also use the Slow motion instead) + anyMotion = false; + } else { + Serial.println("Device is not moving. You may start again.\n\n\n"); + intDetected = false; + mySensor.resetInterrupt(); //Reset the interrupt line + mySensor.disableSlowNoMotion(); //Disable the Slow or No motion interrupt + mySensor.enableAnyMotion(threshold, duration); //Enable the Any motion interrupt + anyMotion = true; + } + } +} + +//Interrupt Service Routine when the sensor triggers an Interrupt +void motionISR() { + intDetected = true; +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/README.adoc new file mode 100644 index 00000000..16baf8ff --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_OAuth + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +OAuth 1.0 client library for Arduino. + +This library depends on ArduinoHttpClient and ArduinoBearSSL. + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/GetTwitterStatus.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/GetTwitterStatus.ino new file mode 100644 index 00000000..f15618e9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/GetTwitterStatus.ino @@ -0,0 +1,127 @@ +/* + Get Twitter status + + This example shows a REST API GET using OAuth 1.0 + authentication. It then parses the JSON response. + + OAuth credentials can be retrieved from your Twitter + developer account after creating a new app: + + https://developer.twitter.com/en/apps + + Circuit: + + - Arduino MKR WiFi 1010 board + + This example code is in the public domain. +*/ + +#include // ArduinoBearSSL depends on ArduinoECCX08 +#include // Arduino_OAuth depends on ArduinoBearSSL +#include // Arduino_OAuth depends on ArduinoHttpClient +#include +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +const char ssid[] = SECRET_SSID; // your network SSID (name) +const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +const char consumerKey[] = SECRET_CONSUMER_KEY; +const char consumerKeySecret[] = SECRET_CONSUMER_KEY_SECRET; +const char accessToken[] = SECRET_ACCESS_TOKEN; +const char accessTokenSecret[] = SECRET_ACCESS_TOKEN_SECRET; + +int status = WL_IDLE_STATUS; // the WiFi radio's status + +WiFiSSLClient wifiSSLClient; +OAuthClient oauthClient(wifiSSLClient, "api.twitter.com", 443); + +String twitterHandle = "arduino"; // Twitter handle to retrieve Tweets from + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now + Serial.println("You're connected to the network"); + Serial.println(); + + Serial.print("Waiting for the network time to sync "); + while (getTime() == 0) { + Serial.print("."); + delay(1000); + } + Serial.println(); + Serial.println(); + + // assign the OAuth credentials + oauthClient.setCredentials(consumerKey, consumerKeySecret, accessToken, accessTokenSecret); + + // assign the callback to get the current epoch time, the epoch time is + // needed for every OAuth request, as it's used in the HTTP "Authorization" + // request header value and to calculate the request's signature + oauthClient.onGetTime(getTime); +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void loop() { + // Twitter API requests latest Arduino status + oauthClient.get("/1.1/statuses/user_timeline.json?screen_name=" + twitterHandle + "&count=1"); + + int statusCode = oauthClient.responseStatusCode(); + String response = oauthClient.responseBody(); + + if (statusCode != 200) { + // An error occurred + Serial.println(statusCode); + Serial.println(response); + } else { + // Parse JSON response + JSONVar statusesObject = JSON.parse(response); + + // print the handle + Serial.print("@"); + Serial.print(twitterHandle); + Serial.println("'s twitter status: "); + + // print the tweet text, retweet + favorite counts + // we only care about the first item + Serial.println(statusesObject[0]["text"]); + Serial.print("Retweets: "); + Serial.println(statusesObject[0]["retweet_count"]); + Serial.print("Likes: "); + Serial.println(statusesObject[0]["favorite_count"]); + } + Serial.println(); + + // Wait one minute (see Twitter API rate limits before changing) + delay(60 * 1000L); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/arduino_secrets.h new file mode 100644 index 00000000..d2096b58 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/arduino_secrets.h @@ -0,0 +1,8 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" + +// from https://developer.twitter.com/en/apps +#define SECRET_CONSUMER_KEY "" +#define SECRET_CONSUMER_KEY_SECRET "" +#define SECRET_ACCESS_TOKEN "" +#define SECRET_ACCESS_TOKEN_SECRET "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/Tweeter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/Tweeter.ino new file mode 100644 index 00000000..bfc275d8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/Tweeter.ino @@ -0,0 +1,129 @@ +/* + Tweeter + + This sketch demonstrates how to post a Tweet directly to + Twitter via the Twitter's HTTP API using OAuth 1.0 for authentication. + + OAuth credentials can be retrieved from the following + website, using your Twitter account and creating a new + app: + + https://developer.twitter.com/en/apps + + Circuit: + - MKR WiFi 1010 board + + This example code is in the public domain. +*/ + +#include // ArduinoBearSSL depends on ArduinoECCX08 +#include // Arduino_OAuth depends on ArduinoBearSSL +#include // Arduino_OAuth depends on ArduinoHttpClient +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +const char ssid[] = SECRET_SSID; // your network SSID (name) +const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +const char consumerKey[] = SECRET_CONSUMER_KEY; +const char consumerKeySecret[] = SECRET_CONSUMER_KEY_SECRET; +const char accessToken[] = SECRET_ACCESS_TOKEN; +const char accessTokenSecret[] = SECRET_ACCESS_TOKEN_SECRET; + +int status = WL_IDLE_STATUS; // the WiFi radio's status + +WiFiSSLClient wifiSSLClient; +OAuthClient oauthClient(wifiSSLClient, "api.twitter.com", 443); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now + Serial.println("You're connected to the network"); + Serial.println(); + + Serial.print("Waiting for the network time to sync "); + while (getTime() == 0) { + Serial.print("."); + delay(1000); + } + Serial.println(); + Serial.println(); + + // assign the OAuth credentials + oauthClient.setCredentials(consumerKey, consumerKeySecret, accessToken, accessTokenSecret); + + // assign the callback to get the current epoch time, the epoch time is + // needed for every OAuth request, as it's used in the HTTP "Authorization" + // request header value and to calculate the request's signature + oauthClient.onGetTime(getTime); +} + +void loop() { + String status; + + // create the status text + status += "millis() is now: "; + status += millis(); + + tweet(status); + + // wait one minute before Tweeting again + delay(60 * 1000L); +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void tweet(String text) { + Serial.println("Sending tweet: "); + Serial.println(text); + + String requestBody; + + // build the URL encoded request body, the text must be URL encoded + requestBody += "status="; + requestBody += URLEncoder.encode(text); + + // HTTP POST it via the OAuth client, which sets the Authorization header for us + oauthClient.post("/1.1/statuses/update.json", "application/x-www-form-urlencoded", requestBody); + + // read the HTTP status code and body + int statusCode = oauthClient.responseStatusCode(); + String responseBody = oauthClient.responseBody(); + + Serial.print("statusCode = "); + Serial.println(statusCode); + + Serial.print("responseBody = "); + Serial.println(responseBody); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/arduino_secrets.h new file mode 100644 index 00000000..d2096b58 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/arduino_secrets.h @@ -0,0 +1,8 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" + +// from https://developer.twitter.com/en/apps +#define SECRET_CONSUMER_KEY "" +#define SECRET_CONSUMER_KEY_SECRET "" +#define SECRET_ACCESS_TOKEN "" +#define SECRET_ACCESS_TOKEN_SECRET "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/LICENSE new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/README.adoc new file mode 100644 index 00000000..9db3fc6f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/README.adoc @@ -0,0 +1,22 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_OV767X + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Capture images from your OmniVision OV7670 camera in your Arduino sketches. + +This library is based on https://www.kernel.org[Linux Kernel's] V4L2 driver for OmniVision OV7670 cameras - which was created by Jonathan Corbet. + +== License == + +Copyright (c) 2021 Arduino SA. All rights reserved. + +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraCapture/CameraCapture.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraCapture/CameraCapture.ino new file mode 100644 index 00000000..e75c59aa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraCapture/CameraCapture.ino @@ -0,0 +1,94 @@ +/* + OV767X - Camera Test Pattern + + This sketch waits for the letter 'c' on the Serial Monitor, + it then reads a frame from the OmniVision OV7670 camera and + prints the data to the Serial Monitor as a hex string. + + The website https://rawpixels.net - can be used the visualize the data: + width: 176 + height: 144 + RGB565 + Little Endian + + Circuit: + - Arduino Nano 33 BLE board + - OV7670 camera module: + - 3.3 connected to 3.3 + - GND connected GND + - SIOC connected to A5 + - SIOD connected to A4 + - VSYNC connected to 8 + - HREF connected to A1 + - PCLK connected to A0 + - XCLK connected to 9 + - D7 connected to 4 + - D6 connected to 6 + - D5 connected to 5 + - D4 connected to 3 + - D3 connected to 2 + - D2 connected to 0 / RX + - D1 connected to 1 / TX + - D0 connected to 10 + + This example code is in the public domain. +*/ + +#include + +unsigned short pixels[176 * 144]; // QCIF: 176x144 X 2 bytes per pixel (RGB565) + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + Serial.println("OV767X Camera Capture"); + Serial.println(); + + if (!Camera.begin(QCIF, RGB565, 1)) { + Serial.println("Failed to initialize camera!"); + while (1) + ; + } + + Serial.println("Camera settings:"); + Serial.print("\twidth = "); + Serial.println(Camera.width()); + Serial.print("\theight = "); + Serial.println(Camera.height()); + Serial.print("\tbits per pixel = "); + Serial.println(Camera.bitsPerPixel()); + Serial.println(); + + Serial.println("Send the 'c' character to read a frame ..."); + Serial.println(); +} + +void loop() { + if (Serial.read() == 'c') { + Serial.println("Reading frame"); + Serial.println(); + Camera.readFrame(pixels); + + int numPixels = Camera.width() * Camera.height(); + + for (int i = 0; i < numPixels; i++) { + unsigned short p = pixels[i]; + + if (p < 0x1000) { + Serial.print('0'); + } + + if (p < 0x0100) { + Serial.print('0'); + } + + if (p < 0x0010) { + Serial.print('0'); + } + + Serial.print(p, HEX); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino new file mode 100644 index 00000000..27e5dbf2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino @@ -0,0 +1,58 @@ +/* + OV767X - Camera Capture Raw Bytes + + This sketch reads a frame from the OmniVision OV7670 camera + and writes the bytes to the Serial port. Use the Processing + sketch in the extras folder to visualize the camera output. + + Circuit: + - Arduino Nano 33 BLE board + - OV7670 camera module: + - 3.3 connected to 3.3 + - GND connected GND + - SIOC connected to A5 + - SIOD connected to A4 + - VSYNC connected to 8 + - HREF connected to A1 + - PCLK connected to A0 + - XCLK connected to 9 + - D7 connected to 4 + - D6 connected to 6 + - D5 connected to 5 + - D4 connected to 3 + - D3 connected to 2 + - D2 connected to 0 / RX + - D1 connected to 1 / TX + - D0 connected to 10 + + This example code is in the public domain. +*/ + +#include + +int bytesPerFrame; + +byte data[320 * 240 * 2]; // QVGA: 320x240 X 2 bytes per pixel (RGB565) + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!Camera.begin(QVGA, RGB565, 1)) { + Serial.println("Failed to initialize camera!"); + while (1) + ; + } + + bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel(); + + // Optionally, enable the test pattern for testing + // Camera.testPattern(); +} + +void loop() { + Camera.readFrame(data); + + Serial.write(data, bytesPerFrame); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraTestPattern/CameraTestPattern.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraTestPattern/CameraTestPattern.ino new file mode 100644 index 00000000..c4ed6d0e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/CameraTestPattern/CameraTestPattern.ino @@ -0,0 +1,97 @@ +/* + OV767X - Camera Test Pattern + + This sketch enables the test pattern mode, then reads a frame from + the OmniVision OV7670 camera and prints the data to the + Serial Monitor as a hex string. + + The website https://rawpixels.net - can be used the visualize the data: + width: 176 + height: 144 + RGB565 + Little Endian + + Circuit: + - Arduino Nano 33 BLE board + - OV7670 camera module: + - 3.3 connected to 3.3 + - GND connected GND + - SIOC connected to A5 + - SIOD connected to A4 + - VSYNC connected to 8 + - HREF connected to A1 + - PCLK connected to A0 + - XCLK connected to 9 + - D7 connected to 4 + - D6 connected to 6 + - D5 connected to 5 + - D4 connected to 3 + - D3 connected to 2 + - D2 connected to 0 / RX + - D1 connected to 1 / TX + - D0 connected to 10 + + This example code is in the public domain. +*/ + +#include + +unsigned short pixels[176 * 144]; // QCIF: 176x144 X 2 bytes per pixel (RGB565) + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + Serial.println("OV767X Test Pattern"); + Serial.println(); + + if (!Camera.begin(QCIF, RGB565, 1)) { + Serial.println("Failed to initialize camera!"); + while (1) + ; + } + + Serial.println("Camera settings:"); + Serial.print("\twidth = "); + Serial.println(Camera.width()); + Serial.print("\theight = "); + Serial.println(Camera.height()); + Serial.print("\tbits per pixel = "); + Serial.println(Camera.bitsPerPixel()); + Serial.println(); + + Serial.println("Enabling test pattern mode"); + Serial.println(); + Camera.testPattern(); + + Serial.println("Reading frame"); + Serial.println(); + Camera.readFrame(pixels); + + int numPixels = Camera.width() * Camera.height(); + + for (int i = 0; i < numPixels; i++) { + unsigned short p = pixels[i]; + + if (p < 0x1000) { + Serial.print('0'); + } + + if (p < 0x0100) { + Serial.print('0'); + } + + if (p < 0x0010) { + Serial.print('0'); + } + + Serial.print(p, HEX); + } + + Serial.println(); +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/ConnectionTest/ConnectionTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/ConnectionTest/ConnectionTest.ino new file mode 100644 index 00000000..c9e1b959 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_OV767X/examples/ConnectionTest/ConnectionTest.ino @@ -0,0 +1,96 @@ +/* + OV767X - ConnectionTest.ino + + Test that the connection between your Arduino and Camera is able to transfer data correctly at the given speed + + Circuit: + - Arduino Nano 33 BLE board + - OV7670 camera module: + - 3.3 connected to 3.3 + - GND connected GND + - SIOC connected to A5 + - SIOD connected to A4 + - VSYNC connected to 8 + - HREF connected to A1 + - PCLK connected to A0 + - XCLK connected to 9 + - D7 connected to 4 + - D6 connected to 6 + - D5 connected to 5 + - D4 connected to 3 + - D3 connected to 2 + - D2 connected to 0 / RX + - D1 connected to 1 / TX + - D0 connected to 10 + + This example code is in the public domain. + +*/ + +#include +#include + +int bytesPerFrame; +int errors = 0; +int count = 0; +int bestTime = 100000; +int worstTime = 0; +int delayTime = 300; + + +long timer = 0; +Arduino_CRC32 crc32; + +const bool error_checking = true; + +byte data[176 * 144 * 2]; // QCIF at 2 bytes per pixel + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!Camera.begin(QCIF, RGB565, 5)) { + Serial.println("Failed to initialize camera!"); + while (1) + ; + } + + bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel(); + + // Enable the test pattern so we have a fixed image to run a checksum against + Camera.testPattern(); +} + +void loop() { + + // sliding delay window to try different start times wrt camera VSYNC + if (delayTime > 0) { delayTime = delayTime - 10; } + delay(delayTime); + + // benchmarking + timer = millis(); + Camera.readFrame(data); + timer = millis() - timer; + // Check if it is a best case or worse case time + bestTime = min(timer, bestTime); + worstTime = max(timer, worstTime); + + // Test against known checksum values (minor pixel variations at the start but were visually confirmed to be a good test pattern) + uint32_t const crc32_res = crc32.calc(data, bytesPerFrame); + if (crc32_res != 0x15AB2939 && crc32_res != 0xD3EC95E && crc32_res != 0xB9C43ED9) { + errors++; + }; + + count++; + + Serial.print(" errors:"); + Serial.print(errors); + Serial.print("/"); + Serial.print(count); + Serial.print(" best:"); + Serial.print(bestTime); + Serial.print("ms worst:"); + Serial.print(worstTime); + Serial.println("ms"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_PF1550/examples/BasicUsage/BasicUsage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_PF1550/examples/BasicUsage/BasicUsage.ino new file mode 100644 index 00000000..c72c5bc9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_PF1550/examples/BasicUsage/BasicUsage.ino @@ -0,0 +1,33 @@ +#include "Arduino_PMIC.h" + +void setup() { + PMIC.begin(); + + PMIC.configLDO1(Ldo1Voltage::V_1_00, true, true, false); + PMIC.configLDO2(Ldo2Voltage::V_1_80, true, true, false); + PMIC.configLDO3(Ldo3Voltage::V_1_20, true, true, false); + + PMIC.configSw2(Sw2Voltage::V_3_30, /* V_SW2 Normal Mode */ + Sw2Voltage::V_3_30, /* V_SW2 Standby Mode */ + Sw2Voltage::V_3_30, /* V_SW2 Sleep Mode */ + Sw2CurrentLimit::I_1_5_A, /* Current Limit */ + true, /* Enable Normal Mode */ + true, /* Enable Standby Mode */ + true); /* Enable Sleep Mode */ + + PMIC.configCharger(IFastCharge::I_500_mA, + VFastCharge::V_3_80, + IEndOfCharge::I_5_mA, + IInputCurrentLimit::I_100_mA); + + /* TODO: Clarify if a interrupt event is generated by a rising or falling edge, + * according to schematic/datasheet it's a open-drain output with a pull-up resistor. + * Probably we need to do the registering with a ISR handler internally in the future + * since the PMIC_INT pin PK0 will not be exposed externally. + */ + attachInterrupt(digitalPinToInterrupt(0), PF1550::ISR_onPMICEvent, RISING); +} + + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_PF1550/examples/ReadWriteRegs/ReadWriteRegs.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_PF1550/examples/ReadWriteRegs/ReadWriteRegs.ino new file mode 100644 index 00000000..fb8158f0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_PF1550/examples/ReadWriteRegs/ReadWriteRegs.ino @@ -0,0 +1,39 @@ +#include "Arduino_PMIC.h" +#include "PF1550/PF1550_Register.h" + +#define Serial Serial1 + +uint8_t regVal; + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + PMIC.begin(); + + PMIC.debug(Serial); +} + + +void loop() { + PMIC.writePMICreg(Register::CHARGER_CHG_EOC_CNFG, 0x41); + regVal = PMIC.readPMICreg(Register::CHARGER_CHG_EOC_CNFG); + + Serial.print("CHARGER_CHG_SNS register value: "); + Serial.println(regVal, HEX); + + regVal = PMIC.readPMICreg(Register::CHARGER_VBUS_SNS); + + Serial.print("CHARGER_VBUS_SNS register value: "); + Serial.println(regVal, HEX); + + regVal = PMIC.readPMICreg(Register::CHARGER_CHG_INT_OK); + + Serial.print("CHARGER_CHG_INT_OK register value: "); + Serial.println(regVal, HEX); + Serial.println(); + Serial.println(); + + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/README.md new file mode 100644 index 00000000..5640e59a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/README.md @@ -0,0 +1,55 @@ +Arduino_Portenta_OTA +==================== + +[![Compile Examples](https://github.com/arduino-libraries/Arduino_Portenta_OTA/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/Arduino_Portenta_OTA/actions?workflow=Compile+Examples) +[![Arduino Lint](https://github.com/arduino-libraries/Arduino_Portenta_OTA/workflows/Arduino%20Lint/badge.svg)](https://github.com/arduino-libraries/Arduino_Portenta_OTA/actions?workflow=Arduino+Lint) +[![Spell Check](https://github.com/arduino-libraries/Arduino_Portenta_OTA/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/Arduino_Portenta_OTA/actions?workflow=Spell+Check) + +This library allows OTA (Over-The-Air) firmware updates for the Arduino Portenta H7. OTA binaries are downloaded via WiFi and stored on a SD card or on the Portenta H7's QSPI flash storage. Next, all information relevant to the firmware update is stored in non-volatile memory. After a reset the Portenta H7 bootloader accesses this information and uses it to perform the firmware update. + +### Example +```C++ +#include +#include +#include "arduino_secrets.h" +/* ... */ +void setup() +{ + if (WiFi.status() == WL_NO_SHIELD) + return; + + int status = WL_IDLE_STATUS; + while (status != WL_CONNECTED) + { + status = WiFi.begin(SSID, PASS); + delay(10000); + } + + Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2); + Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None; + + if (!ota.isOtaCapable()) + return; + + if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None) + return; + + int const ota_download = ota.download("http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota", false /* is_https */); + if (ota_download <= 0) + return; + + int const ota_decompress = ota.decompress(); + if (ota_decompress < 0) + return; + + if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None) + return; + + ota.reset(); +} + +void loop() +{ + +} +``` diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/OTA_Qspi_Flash.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/OTA_Qspi_Flash.ino new file mode 100644 index 00000000..8f4dc9af --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/OTA_Qspi_Flash.ino @@ -0,0 +1,117 @@ +/* + * This example demonstrates how to use to update the firmware of the Arduino Portenta H7 using + * a firmware image stored on the QSPI. + * + * Steps: + * 1) Create a sketch for the Portenta H7 and verifiy + * that it both compiles and works on a board. + * 2) In the IDE select: Sketch -> Export compiled Binary. + * 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in + * https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools . + * A) ./lzss.py --encode SKETCH.bin SKETCH.lzss + * B) ./bin2ota.py PORTENTA_H7_M7 SKETCH.lzss SKETCH.ota + * 4) Upload the OTA file to a network reachable location, e.g. OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * has been uploaded to: http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * 5) Perform an OTA update via steps outlined below. + */ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + +#include + +#include "arduino_secrets.h" + +/****************************************************************************** + * CONSTANT + ******************************************************************************/ + +/* Please enter your sensitive data in the Secret tab/arduino_secrets.h */ +static char const SSID[] = SECRET_SSID; /* your network SSID (name) */ +static char const PASS[] = SECRET_PASS; /* your network password (use for WPA, or use as key for WEP) */ + +static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota"; + +/****************************************************************************** + * SETUP/LOOP + ******************************************************************************/ + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("Communication with WiFi module failed!"); + return; + } + + int status = WL_IDLE_STATUS; + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to '"); + Serial.print(SSID); + Serial.println("'"); + status = WiFi.begin(SSID, PASS); + delay(10000); + } + Serial.print("You're connected to '"); + Serial.print(WiFi.SSID()); + Serial.println("'"); + + Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2); + Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None; + + if (!ota.isOtaCapable()) { + Serial.println("Higher version bootloader required to perform OTA."); + Serial.println("Please update the bootloader."); + Serial.println("File -> Examples -> Portenta_System -> PortentaH7_updateBootloader"); + return; + } + + Serial.println("Initializing OTA storage"); + if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None) { + Serial.print("Arduino_Portenta_OTA::begin() failed with error code "); + Serial.println((int)ota_err); + return; + } + + + Serial.println("Starting download to QSPI ..."); + int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */); + if (ota_download <= 0) { + Serial.print("Arduino_Portenta_OTA_QSPI::download failed with error code "); + Serial.println(ota_download); + return; + } + Serial.print(ota_download); + Serial.println(" bytes stored."); + + + Serial.println("Decompressing LZSS compressed file ..."); + int const ota_decompress = ota.decompress(); + if (ota_decompress < 0) { + Serial.print("Arduino_Portenta_OTA_QSPI::decompress() failed with error code"); + Serial.println(ota_decompress); + return; + } + Serial.print(ota_decompress); + Serial.println(" bytes decompressed."); + + + Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ..."); + if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None) { + Serial.print("ota.update() failed with error code "); + Serial.println((int)ota_err); + return; + } + + Serial.println("Performing a reset after which the bootloader will update the firmware."); + Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green."); + delay(1000); /* Make sure the serial message gets out before the reset. */ + ota.reset(); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/OTA_SD_Portenta.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/OTA_SD_Portenta.ino new file mode 100644 index 00000000..7d585832 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/OTA_SD_Portenta.ino @@ -0,0 +1,118 @@ +/* + * This example demonstrates how to use to update the firmware of the Arduino Portenta H7 using + * a firmware image stored on the SD. + * + * Steps: + * 1) Create a sketch for the Portenta H7 and verifiy + * that it both compiles and works on a board. + * 2) In the IDE select: Sketch -> Export compiled Binary. + * 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in + * https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools . + * A) ./lzss.py --encode SKETCH.bin PORTENTA_H7_M7.lzss + * B) ./bin2ota.py PORTENTA_H7_M7.lzss PORTENTA_H7_M7.ota + * 4) Upload the OTA file to a network reachable location, e.g. OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * has been uploaded to: http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * 5) Perform an OTA update via steps outlined below. + */ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + +#include + +#include "arduino_secrets.h" + +/****************************************************************************** + * CONSTANT + ******************************************************************************/ + +/* Please enter your sensitive data in the Secret tab/arduino_secrets.h */ +static char const SSID[] = SECRET_SSID; /* your network SSID (name) */ +static char const PASS[] = SECRET_PASS; /* your network password (use for WPA, or use as key for WEP) */ + +static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota"; + +/****************************************************************************** + * SETUP/LOOP + ******************************************************************************/ + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("Communication with WiFi module failed!"); + return; + } + + int status = WL_IDLE_STATUS; + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to '"); + Serial.print(SSID); + Serial.println("'"); + status = WiFi.begin(SSID, PASS); + delay(10000); + } + Serial.print("You're connected to '"); + Serial.print(WiFi.SSID()); + Serial.println("'"); + + //Arduino_Portenta_OTA_SD ota(SD_FATFS, 0); + Arduino_Portenta_OTA_SD ota(SD_FATFS_MBR, 1); + Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None; + + if (!ota.isOtaCapable()) { + Serial.println("Higher version bootloader required to perform OTA."); + Serial.println("Please update the bootloader."); + Serial.println("File -> Examples -> Portenta_System -> PortentaH7_updateBootloader"); + return; + } + + Serial.println("Initializing OTA storage"); + if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None) { + Serial.print("Arduino_Portenta_OTA::begin() failed with error code "); + Serial.println((int)ota_err); + return; + } + + + Serial.println("Starting download to SD ..."); + int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */); + if (ota_download <= 0) { + Serial.print("Arduino_Portenta_OTA_SD::download failed with error code "); + Serial.println(ota_download); + return; + } + Serial.print(ota_download); + Serial.println(" bytes stored."); + + + Serial.println("Decompressing LZSS compressed file ..."); + int const ota_decompress = ota.decompress(); + if (ota_decompress < 0) { + Serial.print("Arduino_Portenta_OTA_SD::decompress() failed with error code"); + Serial.println(ota_decompress); + return; + } + Serial.print(ota_decompress); + Serial.println(" bytes decompressed."); + + + Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory"); + if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None) { + Serial.print("Arduino_Portenta_OTA::update() failed with error code "); + Serial.println((int)ota_err); + return; + } + + Serial.println("Performing a reset after which the bootloader will update the firmware."); + Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green."); + delay(1000); + ota.reset(); +} + +void loop() { +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Usage_Portenta/OTA_Usage_Portenta.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Usage_Portenta/OTA_Usage_Portenta.ino new file mode 100644 index 00000000..fbc7b6e7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Usage_Portenta/OTA_Usage_Portenta.ino @@ -0,0 +1,53 @@ +/* + This sketch can be used to generate an example binary that can be uploaded to Portenta via OTA. + It needs to be used together with + - 'OTA_Qspi_Flash.ino' if you want to use the Qspi Flash as storage system + OR + - 'SD_Qspi_Flash.ino' if you want to use the SD card as storage system + + Steps to test OTA on Portenta: + 1) Upload this sketch or any other sketch (this one lights up the RGB LED with different colours). + 2) In the IDE select: Sketch -> Export compiled Binary + 3) Upload the exported binary to a server + 4) Choose a storage mechanism (SD or QSPI), open the related OTA_*_Portenta.ino sketch, + eventually update the OTA_FILE_LOCATION + 5) Upload the sketch OTA_*_Portenta.ino to perform OTA via SD or QSPI Flash +*/ + +void setLed(int blue, int gree, int red) { + if (blue == 1) { + digitalWrite(LEDB, LOW); + } else { + digitalWrite(LEDB, HIGH); + } + + if (gree == 1) { + digitalWrite(LEDG, LOW); + } else { + digitalWrite(LEDG, HIGH); + } + + if (red == 1) { + digitalWrite(LEDR, LOW); + } else { + digitalWrite(LEDR, HIGH); + } +} + + +void setup() { + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDR, OUTPUT); +} + +void loop() { //led BLUE ON + setLed(1, 0, 0); + delay(1000); + //led GREEN ON + setLed(0, 1, 0); + delay(1000); + //led RED ON + setLed(0, 0, 1); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/README.adoc new file mode 100644 index 00000000..1588e74f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/README.adoc @@ -0,0 +1,28 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_ScienceJournal + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Firmware for the Physics Lab kit and the Arduino Nano 33 BLE Sense. + +== License == + +Copyright (c) 2020 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.cpp new file mode 100644 index 00000000..4630b8db --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.cpp @@ -0,0 +1,34 @@ +#include "Arduino.h" +#include "mbed.h" +#include "ArduinoBLE.h" +#include "LowPower.h" + +#include "nrf_power.h" +#include "nrf_uarte.h" +#include "nrf_uart.h" + +void lowPower() { + // Disable UARTE0 which is initially enabled by the bootloader + nrf_uarte_task_trigger(NRF_UARTE0, NRF_UARTE_TASK_STOPRX); + while (!nrf_uarte_event_check(NRF_UARTE0, NRF_UARTE_EVENT_RXTO)) + ; + NRF_UARTE0->ENABLE = 0; + NRF_UART0->ENABLE = 0; + + // Enable DCDC + nrf_power_dcdcen_set(true); + + // Turn off LED_BUILTIN + digitalWrite(LED_BUILTIN, LOW); +} + +void lowPowerWait(unsigned long time) { + rtos::ThisThread::sleep_for(time); +} + +void lowPowerBleWait(unsigned long time) { + unsigned long timeRef = millis(); + while (millis() - timeRef < time) { + BLE.poll(time - (millis() - timeRef)); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.h new file mode 100644 index 00000000..6a4574be --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.h @@ -0,0 +1,8 @@ +#ifndef _LOWPOWER_H_ +#define _LOWPOWER_H_ + +void lowPower(); +void lowPowerWait(unsigned long time); +void lowPowerBleWait(unsigned long time); + +#endif //_LOWPOWER_H_ \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino new file mode 100644 index 00000000..df8729c0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino @@ -0,0 +1,249 @@ +#include "LowPower.h" +#include + +#include +#include +#include +#include +#include + +#include + +const int VERSION = 0x00000001; +const float TEMPERATURE_CALIBRATION = -5.0; + +#define SCIENCE_KIT_UUID(val) ("555a0002-" val "-467a-9538-01f0652c74e8") +#define RESISTANCE_PIN A0 +#define VOLTAGE_BUFFER_SIZE 16 + +//#define DEBUG 0 + +BLEService service(SCIENCE_KIT_UUID("0000")); +BLEUnsignedIntCharacteristic versionCharacteristic(SCIENCE_KIT_UUID("0001"), BLERead); +BLECharacteristic accelerationCharacteristic(SCIENCE_KIT_UUID("0011"), BLENotify, 3 * sizeof(float)); +BLECharacteristic gyroscopeCharacteristic(SCIENCE_KIT_UUID("0012"), BLENotify, 3 * sizeof(float)); +BLECharacteristic magneticFieldCharacteristic(SCIENCE_KIT_UUID("0013"), BLENotify, 3 * sizeof(float)); +BLEFloatCharacteristic temperatureCharacteristic(SCIENCE_KIT_UUID("0014"), BLENotify); +BLEFloatCharacteristic pressureCharacteristic(SCIENCE_KIT_UUID("0015"), BLENotify); +BLEFloatCharacteristic humidityCharacteristic(SCIENCE_KIT_UUID("0016"), BLENotify); +BLEUnsignedIntCharacteristic proximityCharacteristic(SCIENCE_KIT_UUID("0017"), BLENotify); +BLECharacteristic colorCharacteristic(SCIENCE_KIT_UUID("0018"), BLENotify, 4 * sizeof(int)); +BLEUnsignedShortCharacteristic soundPressureCharacteristic(SCIENCE_KIT_UUID("0019"), BLENotify); +BLEFloatCharacteristic resistanceCharacteristic(SCIENCE_KIT_UUID("0020"), BLENotify); + +byte voltageBufferIndex = 0; +bool voltageBufferFilled = false; +short soundSampleBuffer[256]; +short voltageSampleBuffer[VOLTAGE_BUFFER_SIZE]; + +void onPDMdata() { + // query the number of bytes available + int bytesAvailable = PDM.available(); + + // read into the sample buffer + PDM.read(soundSampleBuffer, bytesAvailable); +} + +uint16_t getSoundAverage() { + uint32_t avg = 0; + for (int i = 0; i < sizeof(soundSampleBuffer) / sizeof(soundSampleBuffer[0]); i++) { + avg += soundSampleBuffer[i] * soundSampleBuffer[i]; + } + return sqrt(avg); +} + +void readVoltage() { + voltageSampleBuffer[voltageBufferIndex] = analogRead(RESISTANCE_PIN); + if (!voltageBufferFilled && voltageBufferIndex == VOLTAGE_BUFFER_SIZE - 1) { + voltageBufferFilled = true; + } + voltageBufferIndex = (++voltageBufferIndex) % VOLTAGE_BUFFER_SIZE; +} + +uint16_t getVoltageAverage() { + uint16_t avg = 0; + byte upperBound = voltageBufferFilled ? VOLTAGE_BUFFER_SIZE : voltageBufferIndex; + for (int i = 0; i < upperBound; i++) { + avg += voltageSampleBuffer[i]; + } + return avg / upperBound; +} + +// String to calculate the local and device name +String name; +unsigned long lastNotify = 0; + +void printSerialMsg(const char* msg) { +#ifdef DEBUG + if (Serial) { + Serial.println(msg); + } +#endif +} + +void blinkLoop() { + while (1) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } +} + +void setup() { +#ifdef DEBUG + Serial.begin(9600); + while (!Serial) + ; + Serial.println("Started"); +#endif + + delay(2000); + + pinMode(RESISTANCE_PIN, INPUT); // Used for reading resistance + + if (!APDS.begin()) { + printSerialMsg("Failed to initialized APDS!"); + blinkLoop(); + } + + if (!HTS.begin()) { + printSerialMsg("Failed to initialized HTS!"); + blinkLoop(); + } + + if (!BARO.begin()) { + printSerialMsg("Failed to initialized BARO!"); + blinkLoop(); + } + + if (!IMU.begin()) { + printSerialMsg("Failed to initialized IMU!"); + blinkLoop(); + } + + PDM.onReceive(onPDMdata); + if (!PDM.begin(1, 16000)) { + printSerialMsg("Failed to start PDM!"); + blinkLoop(); + } + + if (!BLE.begin()) { + printSerialMsg("Failed to initialized BLE!"); + blinkLoop(); + } + + String address = BLE.address(); +#ifdef DEBUG + if (Serial) { + Serial.print("address = "); + Serial.println(address); + } +#endif + address.toUpperCase(); + + name = "BLE Sense - "; + name += address[address.length() - 5]; + name += address[address.length() - 4]; + name += address[address.length() - 2]; + name += address[address.length() - 1]; + +#ifdef DEBUG + if (Serial) { + Serial.print("name = "); + Serial.println(name); + } +#endif + + BLE.setLocalName(name.c_str()); + BLE.setDeviceName(name.c_str()); + BLE.setAdvertisedService(service); + + service.addCharacteristic(versionCharacteristic); + service.addCharacteristic(accelerationCharacteristic); + service.addCharacteristic(gyroscopeCharacteristic); + service.addCharacteristic(magneticFieldCharacteristic); + service.addCharacteristic(temperatureCharacteristic); + service.addCharacteristic(pressureCharacteristic); + service.addCharacteristic(humidityCharacteristic); + service.addCharacteristic(proximityCharacteristic); + service.addCharacteristic(colorCharacteristic); + service.addCharacteristic(soundPressureCharacteristic); + service.addCharacteristic(resistanceCharacteristic); + + versionCharacteristic.setValue(VERSION); + + BLE.addService(service); + BLE.advertise(); + + lowPower(); +} + +void loop() { + BLE.poll(1000); + while (BLE.connected()) { + lowPowerBleWait(100); + updateSubscribedCharacteristics(); + } +} + +void updateSubscribedCharacteristics() { + if (accelerationCharacteristic.subscribed()) { + float acceleration[3]; + if (IMU.accelerationAvailable() && IMU.readAcceleration(acceleration[0], acceleration[1], acceleration[2])) { + accelerationCharacteristic.writeValue((byte*)acceleration, sizeof(acceleration)); + } + } + if (gyroscopeCharacteristic.subscribed()) { + float gyroscope[3]; + if (IMU.gyroscopeAvailable() && IMU.readGyroscope(gyroscope[0], gyroscope[1], gyroscope[2])) { + gyroscopeCharacteristic.writeValue((byte*)gyroscope, sizeof(gyroscope)); + } + } + + if (magneticFieldCharacteristic.subscribed()) { + float magneticField[3]; + if (IMU.magneticFieldAvailable() && IMU.readMagneticField(magneticField[0], magneticField[1], magneticField[2])) { + magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField)); + } + } + if (soundPressureCharacteristic.subscribed()) { + uint16_t sound = getSoundAverage(); + soundPressureCharacteristic.writeValue(sound); + } + if (proximityCharacteristic.subscribed() && APDS.proximityAvailable()) { + uint32_t proximity = APDS.readProximity(); + proximityCharacteristic.writeValue(proximity); + } + if (colorCharacteristic.subscribed() && APDS.colorAvailable()) { + int color[4]; + APDS.readColor(color[0], color[1], color[2], color[3]); + colorCharacteristic.writeValue((byte*)color, sizeof(color)); + } + bool doTemperature = temperatureCharacteristic.subscribed(); + bool doHumidity = humidityCharacteristic.subscribed(); + if (doTemperature || doHumidity) { + float temperature = HTS.readTemperature(); + float temperatureCalibrated = temperature + TEMPERATURE_CALIBRATION; + if (doTemperature) { + temperatureCharacteristic.writeValue(temperatureCalibrated); + } + if (doHumidity) { + float humidity = HTS.readHumidity(); + float dp = temperature - ((100.0 - humidity) / 5.0); + float humidityCalibrated = 100.0 - (5.0 * (temperatureCalibrated - dp)); + humidityCharacteristic.writeValue(humidityCalibrated); + } + } + if (pressureCharacteristic.subscribed()) { + float pressure = BARO.readPressure(); + pressureCharacteristic.writeValue(pressure); + } + + if (resistanceCharacteristic.subscribed()) { + readVoltage(); + uint16_t measuredValue = getVoltageAverage(); + float voltageRatio = 1024.0f / measuredValue; + resistanceCharacteristic.writeValue(voltageRatio); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/PhysicsLabFirmware/PhysicsLabFirmware.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/PhysicsLabFirmware/PhysicsLabFirmware.ino new file mode 100644 index 00000000..24ba8028 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/PhysicsLabFirmware/PhysicsLabFirmware.ino @@ -0,0 +1,301 @@ +/* + This file is part of the PhysicsLabFirmware library. + Copyright (c) 2019 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include // click here to install the library: http://librarymanager#ArduinoBLE +#include // click here to install the library: http://librarymanager#Adafruit&LSM9DS1 +#include // click here to install the library: http://librarymanager#Adafruit&unified&Sensor&abstraction + +#include "INA226.h" + +#define SCIENCE_KIT_UUID(val) ("555a0001-" val "-467a-9538-01f0652c74e8") + +BLEService service(SCIENCE_KIT_UUID("0000")); +BLEUnsignedIntCharacteristic versionCharacteristic(SCIENCE_KIT_UUID("0001"), BLERead); +BLEByteCharacteristic ledCharacteristic(SCIENCE_KIT_UUID("1001"), BLERead | BLEWrite); +BLEUnsignedShortCharacteristic input1Characteristic(SCIENCE_KIT_UUID("2001"), BLENotify); +BLEUnsignedShortCharacteristic input2Characteristic(SCIENCE_KIT_UUID("2002"), BLENotify); +BLEUnsignedShortCharacteristic input3Characteristic(SCIENCE_KIT_UUID("2003"), BLENotify); +BLEByteCharacteristic ouput1Characteristic(SCIENCE_KIT_UUID("3001"), BLERead | BLEWrite); +BLEByteCharacteristic ouput2Characteristic(SCIENCE_KIT_UUID("3002"), BLERead | BLEWrite); +BLEFloatCharacteristic voltageCharacteristic(SCIENCE_KIT_UUID("4001"), BLENotify); +BLEFloatCharacteristic currentCharacteristic(SCIENCE_KIT_UUID("4002"), BLENotify); +BLEFloatCharacteristic resistanceCharacteristic(SCIENCE_KIT_UUID("4003"), BLENotify); +BLECharacteristic accelerationCharacteristic(SCIENCE_KIT_UUID("5001"), BLENotify, 3 * sizeof(float)); +BLECharacteristic gyroscopeCharacteristic(SCIENCE_KIT_UUID("5002"), BLENotify, 3 * sizeof(float)); +BLECharacteristic magneticFieldCharacteristic(SCIENCE_KIT_UUID("5003"), BLENotify, 3 * sizeof(float)); + +const int LED_PIN = 0; +const int INPUT1_PIN = A3; +const int INPUT2_PIN = A1; +const int INPUT3_PIN = A0; +const int OUTPUT1_PIN = 5; +const int OUTPUT2_PIN = 1; +const int RESISTANCE_PIN = A2; +const int RESISTANCE_AUX_PIN = 8; + +String name; +unsigned long lastNotify = 0; + +unsigned long imuTime; + +#define RESISTOR_AUX_LOW 47000.0 +#define RESISTOR_AUX_HIGH 979.16 // 47k in parallel with 1k = 979.16 Ohm + +#define IMU_UPDATE_TIME 50 + +//#define DEBUG //uncomment to debug the code :) + +Adafruit_LSM9DS1 imu = Adafruit_LSM9DS1(); + +void setup() { + Serial.begin(9600); +#ifdef DEBUG + while (!Serial) + ; + Serial.println("Started"); +#endif + + pinMode(LED_PIN, OUTPUT); + pinMode(INPUT1_PIN, INPUT); + pinMode(INPUT2_PIN, INPUT); + pinMode(INPUT3_PIN, INPUT); + pinMode(OUTPUT1_PIN, OUTPUT); + pinMode(OUTPUT2_PIN, OUTPUT); + pinMode(RESISTANCE_AUX_PIN, OUTPUT); + + digitalWrite(RESISTANCE_AUX_PIN, LOW); + + if (!INA226.begin(0x45)) { + Serial.println("Failed to initialized INA226!"); + + while (1) + ; + } + + if (!imu.begin()) { + Serial.println("Failed to initialized IMU!"); + + while (1) + ; + } + + imu.setupAccel(imu.LSM9DS1_ACCELRANGE_2G); + imu.setupMag(imu.LSM9DS1_MAGGAIN_4GAUSS); + imu.setupGyro(imu.LSM9DS1_GYROSCALE_245DPS); + + if (!BLE.begin()) { + Serial.println("Failed to initialized BLE!"); + + while (1) + ; + } + + String address = BLE.address(); + + address.toUpperCase(); + + name = "MKRSci"; + name += address[address.length() - 5]; + name += address[address.length() - 4]; + name += address[address.length() - 2]; + name += address[address.length() - 1]; + + BLE.setLocalName(name.c_str()); + BLE.setDeviceName(name.c_str()); + BLE.setAdvertisedService(service); + + service.addCharacteristic(versionCharacteristic); + service.addCharacteristic(ledCharacteristic); + service.addCharacteristic(input1Characteristic); + service.addCharacteristic(input2Characteristic); + service.addCharacteristic(input3Characteristic); + service.addCharacteristic(ouput1Characteristic); + service.addCharacteristic(ouput2Characteristic); + service.addCharacteristic(voltageCharacteristic); + service.addCharacteristic(currentCharacteristic); + service.addCharacteristic(resistanceCharacteristic); + service.addCharacteristic(accelerationCharacteristic); + service.addCharacteristic(gyroscopeCharacteristic); + service.addCharacteristic(magneticFieldCharacteristic); + + BLE.addService(service); + + BLE.advertise(); + imuTime = millis(); +} + +void loop() { + lastNotify = 0; + + while (BLE.connected()) { + if (ledCharacteristic.written()) { + analogWrite(LED_PIN, ledCharacteristic.value()); + } + + if (ouput1Characteristic.written()) { + analogWrite(OUTPUT1_PIN, ouput1Characteristic.value()); + } + + if (ouput2Characteristic.written()) { + analogWrite(OUTPUT2_PIN, ouput2Characteristic.value()); + } + + unsigned long now = millis(); + + if (abs((long)now - (long)lastNotify) >= 100) { + lastNotify = now; + + // every 100ms update subscribed characteristics + updateSubscribedCharacteristics(); + } + + updateSubscribedIMUCharacteristics(); + } +} + +void updateSubscribedCharacteristics() { + if (input1Characteristic.subscribed()) { + input1Characteristic.writeValue(analogReadAverage(INPUT1_PIN, 30)); + } + + if (input2Characteristic.subscribed()) { + input2Characteristic.writeValue(analogReadAverage(INPUT2_PIN, 30)); + } + + if (input3Characteristic.subscribed()) { + input3Characteristic.writeValue(analogReadAverage(INPUT3_PIN, 30)); + } + + if (voltageCharacteristic.subscribed()) { + float voltage = INA226.readBusVoltage(); + + voltageCharacteristic.writeValue(voltage); + } + + if (currentCharacteristic.subscribed()) { + float current = INA226.readCurrent(); + + currentCharacteristic.writeValue(current); + } + + if (resistanceCharacteristic.subscribed()) { + float Vout = 0; + float resistanceAuxLow = INFINITY; + float resistanceAuxHigh = INFINITY; + float resistanceAvg = INFINITY; //open circuit as default + + digitalWrite(RESISTANCE_AUX_PIN, LOW); + Vout = getVoutAverage(); + if ((Vout >= 0.1) && (Vout <= 3.0)) { + resistanceAuxLow = RESISTOR_AUX_LOW * ((3.3 / Vout) - 1); + } + + digitalWrite(RESISTANCE_AUX_PIN, HIGH); + Vout = getVoutAverage(); + if (Vout >= 0.1) { + resistanceAuxHigh = RESISTOR_AUX_HIGH * ((3.3 / Vout) - 1); + } + +#ifdef DEBUG + Serial.print("Resistance (HIGH): "); + Serial.print(resistanceAuxHigh); + Serial.println(" Ohm"); + + Serial.print("Resistance (LOW): "); + Serial.print(resistanceAuxLow); + Serial.println(" Ohm"); +#endif + + if ((resistanceAuxHigh != INFINITY) && (resistanceAuxLow != INFINITY)) { + resistanceAvg = (resistanceAuxHigh + resistanceAuxLow) / 2; + } else if ((resistanceAuxHigh != INFINITY) && (resistanceAuxLow == INFINITY)) { + resistanceAvg = resistanceAuxHigh; + } else if ((resistanceAuxHigh == INFINITY) && (resistanceAuxLow != INFINITY)) { + resistanceAvg = resistanceAuxLow; + } + resistanceAvg += 0.025 * resistanceAvg; + +#ifdef DEBUG + Serial.print("Resistance (AVG): "); + Serial.print(resistanceAvg); + Serial.println(" Ohm"); +#endif + resistanceCharacteristic.writeValue(resistanceAvg); + } +} + +float getVoutAverage() { + float Vout = 0; + for (int i = 0; i < 30; i++) { + Vout += (analogRead(RESISTANCE_PIN) * 3.30) / 1023.0; + } + Vout /= 30; + +#ifdef DEBUG + Serial.print("Vout: "); + Serial.print(Vout); + Serial.println("V"); +#endif + return Vout; +} + +int analogReadAverage(int pin, int numberOfSamples) { + int averageValue = 0; + for (int i = 0; i < numberOfSamples; i++) { + averageValue += analogRead(pin); + } + + return (averageValue / numberOfSamples); +} + +void updateSubscribedIMUCharacteristics() { + if (millis() - imuTime > IMU_UPDATE_TIME) { + imuTime = millis(); + imu.read(); + sensors_event_t a, m, g, temp; + imu.getEvent(&a, &m, &g, &temp); + + if (accelerationCharacteristic.subscribed()) { + float acceleration[3]; + + acceleration[0] = a.acceleration.x; + acceleration[1] = a.acceleration.y; + acceleration[2] = a.acceleration.z / 10; + accelerationCharacteristic.writeValue((byte*)acceleration, sizeof(acceleration)); + } + + if (gyroscopeCharacteristic.subscribed()) { + float gyroscope[3]; + + gyroscope[0] = g.gyro.x; + gyroscope[1] = g.gyro.y; + gyroscope[2] = g.gyro.z; + gyroscopeCharacteristic.writeValue((byte*)gyroscope, sizeof(gyroscope)); + } + + if (magneticFieldCharacteristic.subscribed()) { + float magneticField[3]; + + magneticField[0] = m.magnetic.x; + magneticField[1] = m.magnetic.y; + magneticField[2] = m.magnetic.z; + magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField)); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/RP2040ConnectFirmware/RP2040ConnectFirmware.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/RP2040ConnectFirmware/RP2040ConnectFirmware.ino new file mode 100644 index 00000000..929d58c8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_ScienceJournal/examples/RP2040ConnectFirmware/RP2040ConnectFirmware.ino @@ -0,0 +1,179 @@ +#include +#include + +#include + +const int VERSION = 0x00000001; + +#define SCIENCE_KIT_UUID(val) ("555a0002-" val "-467a-9538-01f0652c74e8") +#define RESISTANCE_PIN A0 +#define VOLTAGE_BUFFER_SIZE 16 + +//#define DEBUG 0 + +BLEService service(SCIENCE_KIT_UUID("0000")); +BLEUnsignedIntCharacteristic versionCharacteristic(SCIENCE_KIT_UUID("0001"), BLERead); +BLECharacteristic accelerationCharacteristic(SCIENCE_KIT_UUID("0011"), BLENotify, 3 * sizeof(float)); +BLECharacteristic gyroscopeCharacteristic(SCIENCE_KIT_UUID("0012"), BLENotify, 3 * sizeof(float)); +BLEUnsignedShortCharacteristic soundPressureCharacteristic(SCIENCE_KIT_UUID("0019"), BLENotify); +BLEFloatCharacteristic resistanceCharacteristic(SCIENCE_KIT_UUID("0020"), BLENotify); + +byte voltageBufferIndex = 0; +bool voltageBufferFilled = false; +short soundSampleBuffer[256]; +short voltageSampleBuffer[VOLTAGE_BUFFER_SIZE]; + +void onPDMdata() { + // query the number of bytes available + int bytesAvailable = PDM.available(); + + // read into the sample buffer + PDM.read(soundSampleBuffer, bytesAvailable); +} + +uint16_t getSoundAverage() { + uint32_t avg = 0; + for (int i = 0; i < sizeof(soundSampleBuffer) / sizeof(soundSampleBuffer[0]); i++) { + avg += soundSampleBuffer[i] * soundSampleBuffer[i]; + } + return sqrt(avg); +} + +void readVoltage() { + voltageSampleBuffer[voltageBufferIndex] = analogRead(RESISTANCE_PIN); + if (!voltageBufferFilled && voltageBufferIndex == VOLTAGE_BUFFER_SIZE - 1) { + voltageBufferFilled = true; + } + voltageBufferIndex = (++voltageBufferIndex) % VOLTAGE_BUFFER_SIZE; +} + +uint16_t getVoltageAverage() { + uint16_t avg = 0; + byte upperBound = voltageBufferFilled ? VOLTAGE_BUFFER_SIZE : voltageBufferIndex; + for (int i = 0; i < upperBound; i++) { + avg += voltageSampleBuffer[i]; + } + return avg / upperBound; +} + +// String to calculate the local and device name +String name; +unsigned long lastNotify = 0; + +void printSerialMsg(const char* msg) { +#ifdef DEBUG + if (Serial) { + Serial.println(msg); + } +#endif +} + +void blinkLoop() { + while (1) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } +} + +void setup() { +#ifdef DEBUG + Serial.begin(9600); + while (!Serial) + ; + Serial.println("Started"); +#endif + + delay(2000); + + pinMode(RESISTANCE_PIN, INPUT); // Used for reading resistance + + if (!IMU.begin()) { + printSerialMsg("Failed to initialize IMU!"); + blinkLoop(); + } + + PDM.onReceive(onPDMdata); + if (!PDM.begin(1, 16000)) { + printSerialMsg("Failed to start PDM!"); + blinkLoop(); + } + + if (!BLE.begin()) { + printSerialMsg("Failed to initialize BLE!"); + blinkLoop(); + } + + String address = BLE.address(); +#ifdef DEBUG + if (Serial) { + Serial.print("address = "); + Serial.println(address); + } +#endif + address.toUpperCase(); + + name = "BLE Sense - "; + name += address[address.length() - 5]; + name += address[address.length() - 4]; + name += address[address.length() - 2]; + name += address[address.length() - 1]; + +#ifdef DEBUG + if (Serial) { + Serial.print("name = "); + Serial.println(name); + } +#endif + + BLE.setLocalName(name.c_str()); + BLE.setDeviceName(name.c_str()); + BLE.setAdvertisedService(service); + + service.addCharacteristic(versionCharacteristic); + service.addCharacteristic(accelerationCharacteristic); + service.addCharacteristic(gyroscopeCharacteristic); + service.addCharacteristic(soundPressureCharacteristic); + service.addCharacteristic(resistanceCharacteristic); + + versionCharacteristic.setValue(VERSION); + + BLE.addService(service); + BLE.advertise(); +} + +void loop() { + BLE.poll(1000); + while (BLE.connected()) { + updateSubscribedCharacteristics(); + } +} + +void updateSubscribedCharacteristics() { + if (accelerationCharacteristic.subscribed()) { + float acceleration[3]; + if (IMU.accelerationAvailable() && IMU.readAcceleration(acceleration[0], acceleration[1], acceleration[2])) { + accelerationCharacteristic.writeValue((byte*)acceleration, sizeof(acceleration)); + } + } + + if (gyroscopeCharacteristic.subscribed()) { + float gyroscope[3]; + if (IMU.gyroscopeAvailable() && IMU.readGyroscope(gyroscope[0], gyroscope[1], gyroscope[2])) { + gyroscopeCharacteristic.writeValue((byte*)gyroscope, sizeof(gyroscope)); + } + } + + if (soundPressureCharacteristic.subscribed()) { + uint16_t sound = getSoundAverage(); + soundPressureCharacteristic.writeValue(sound); + } + + if (resistanceCharacteristic.subscribed()) { + readVoltage(); + uint16_t measuredValue = getVoltageAverage(); + float voltageRatio = 1024.0f / measuredValue; + resistanceCharacteristic.writeValue(voltageRatio); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/README.md new file mode 100644 index 00000000..5b53668d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/README.md @@ -0,0 +1,14 @@ +# Arduino SensorKit Library + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/spell-check.yml) + +This documentation contains information about the classes and the usage of Arduino_SensorKit library which is primarily used in the [Arduino Sensor Kit](https://store.arduino.cc/sensor-kit-base). This library is a wrapper for other libraries such as + +* [U8g2_Arduino](https://github.com/olikraus/U8g2_Arduino) Library for monochrome displays +* [Seeed_Arduino_LIS3DHTR](https://github.com/Seeed-Studio/Seeed_Arduino_LIS3DHTR) for the 3 Axis Accelerometer +* [Grove_BMP280](https://github.com/Seeed-Studio/Grove_BMP280) Library for the Barometer +* [DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library) for the Temperature and Humidity Sensor + +The Arduino_SensorKit Library can be downloaded from the Arduino IDE's library manager or from the GitHub repository. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Accelerometer/Accelerometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Accelerometer/Accelerometer.ino new file mode 100644 index 00000000..d112be48 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Accelerometer/Accelerometer.ino @@ -0,0 +1,25 @@ +#include "Arduino_SensorKit.h" + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while (!Serial) + ; + + Accelerometer.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + // 3 axis + Serial.print("x:"); + Serial.print(Accelerometer.readX()); + Serial.print(" "); + Serial.print("y:"); + Serial.print(Accelerometer.readY()); + Serial.print(" "); + Serial.print("z:"); + Serial.println(Accelerometer.readZ()); + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Combined_Demo/Combined_Demo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Combined_Demo/Combined_Demo.ino new file mode 100644 index 00000000..14cc048b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Combined_Demo/Combined_Demo.ino @@ -0,0 +1,102 @@ +// Combined Demo by Marc MERLIN +// Reviewed by Pablo Marquínez +// This demo uses all the devices from the Arduino Sensor Kit +// Showing the values on the Display + +#include "Arduino_SensorKit.h" + +#define BUZZER 5 +#define BUTTON 4 +#define LED 6 +#define POT A0 +#define MIC A2 +#define LIGHT A3 + +int pot_value; +bool button_state; +int mic_value; +int light_value; + +void setup() { + Serial.begin(9600); + + pinMode(MIC, INPUT); + pinMode(LIGHT, INPUT); + pinMode(BUTTON, INPUT); + + pinMode(LED, OUTPUT); + digitalWrite(LED, LOW); + pinMode(BUZZER, OUTPUT); + + Environment.begin(); + + Oled.begin(); + Oled.setFlipMode(true); + + Accelerometer.begin(); + Pressure.begin(); +} + +void loop() { + Oled.setFont(u8x8_font_amstrad_cpc_extended_r); + + //cursor values are in characters, not pixels + Oled.setCursor(0, 4); + + // If accelerometer and altimeter are queried too close to one another + // this causes a hang, so we read this first. + Oled.print("x:"); + Oled.print(Accelerometer.readX()); + Oled.print(" y:"); + Oled.print(Accelerometer.readY()); + Oled.setCursor(0, 5); + Oled.print("z:"); + Oled.print(Accelerometer.readZ()); + Oled.print(" T:"); + Oled.print(Environment.readTemperature()); + Oled.print("C"); + + Oled.setCursor(0, 0); + Oled.print("But:"); + + pot_value = analogRead(POT); + + button_state = digitalRead(BUTTON); + Oled.print(button_state); + + if (button_state == true) { + digitalWrite(LED, HIGH); + tone(BUZZER, pot_value); + } else { + digitalWrite(LED, LOW); + noTone(BUZZER); + } + + Oled.setCursor(0, 1); + Oled.print("BuzPot: "); + Oled.print(pot_value); + Oled.print("Hz "); + + mic_value = analogRead(MIC); + Oled.setCursor(0, 2); + Oled.print("Mic: "); + Oled.print(mic_value); + Oled.print(" "); + + light_value = analogRead(LIGHT); + Oled.setCursor(0, 3); + Oled.print("Light: "); + Oled.print(light_value); + Oled.print(" "); + + Oled.setCursor(0, 6); + Oled.print("Hum: "); + Oled.print(Environment.readHumidity()); + Oled.print("%"); + + Oled.setCursor(0, 7); + Oled.print("Alt:"); + Oled.print(Pressure.readAltitude()); + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Oled_Display/Oled_Display.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Oled_Display/Oled_Display.ino new file mode 100644 index 00000000..01e34f4f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Oled_Display/Oled_Display.ino @@ -0,0 +1,16 @@ +#include "Arduino_SensorKit.h" + +void setup() { + Oled.begin(); + Oled.setFlipMode(true); +} + +void loop() { + int random_value = random(0, 1023); // create a random value + + Oled.setFont(u8x8_font_chroma48medium8_r); + Oled.setCursor(0, 3); + Oled.print("Value: "); + Oled.print(random_value); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Plug_Sketch_Play/Plug_Sketch_Play.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Plug_Sketch_Play/Plug_Sketch_Play.ino new file mode 100644 index 00000000..075b1c8e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Plug_Sketch_Play/Plug_Sketch_Play.ino @@ -0,0 +1,25 @@ +#include "Arduino_SensorKit.h" + +int button = 4; +int LED = 6; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while (!Serial) + ; + + pinMode(button, INPUT); + pinMode(LED, OUTPUT); + + digitalWrite(LED, LOW); +} + +void loop() { + // put your main code here, to run repeatedly: + if (digitalRead(button)) { + digitalWrite(LED, HIGH); + } else { + digitalWrite(LED, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Pressure_Sensor/Pressure_Sensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Pressure_Sensor/Pressure_Sensor.ino new file mode 100644 index 00000000..184e8d71 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Pressure_Sensor/Pressure_Sensor.ino @@ -0,0 +1,27 @@ +#include "Arduino_SensorKit.h" + +void setup() { + Serial.begin(9600); + Pressure.begin(); +} + +void loop() { + // Get and print temperatures + Serial.print("Temp: "); + Serial.print(Pressure.readTemperature()); + Serial.println("C"); // The unit for Celsius because original Arduino don't support special symbols + + // Get and print atmospheric pressure data + Serial.print("Pressure: "); + Serial.print(Pressure.readPressure()); + Serial.println("Pa"); + + // Get and print altitude data + Serial.print("Altitude: "); + Serial.print(Pressure.readAltitude()); + Serial.println("m"); + + Serial.println("\n"); //add a line between output of different times. + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Temp_and_Humidity/Temp_and_Humidity.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Temp_and_Humidity/Temp_and_Humidity.ino new file mode 100644 index 00000000..523032a8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_SensorKit/examples/Temp_and_Humidity/Temp_and_Humidity.ino @@ -0,0 +1,17 @@ +//#define DHTPIN 3 // By default its connected to pin D3, it can be changed, define it before the #include of the library +#include "Arduino_SensorKit.h" + +void setup() { + Serial.begin(9600); + Environment.begin(); +} + +void loop() { + Serial.print("Temperature = "); + Serial.print(Environment.readTemperature()); //print temperature + Serial.println(" C"); + Serial.print("Humidity = "); + Serial.print(Environment.readHumidity()); //print humidity + Serial.println(" %"); + delay(2000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/LICENSE new file mode 100644 index 00000000..b4e6b5f5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + This library enables threadsafe peripheral IO access via pipes. + Copyright (C) 2021 Alexander Entinger / Arduino + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/README.md new file mode 100644 index 00000000..ca585ae0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/README.md @@ -0,0 +1,82 @@ + + +`Arduino_Threads` +================= +*Note: This library is currently in [beta](#zap-caveats).* + +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/compile-examples.yml) +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/check-arduino.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/spell-check.yml) + +This library makes it easy to use the multi-threading capability of [Arduino](https://www.arduino.cc/) boards that use an [Mbed OS](https://os.mbed.com/docs/mbed-os/latest/introduction/index.html)-based core library. Additionally this library provides thread-safe access to `Wire`, `SPI` and `Serial` which is relevant when creating multi-threaded sketches in order to avoid common pitfalls such as race-conditions and invalid state. ​ + +Preeliminary **documentation** and download links for **required tooling** are available within the [`/docs`](docs/README.md) subfolder. + +## :star: Features +### :thread: Multi-threaded sketch execution +Instead of one big state-machine-of-doom you can split your application into multiple independent threads, each with it's own `setup()` and `loop()` function. Instead of implementing your application in a single `.ino` file, each independent thread is implemented in a dedicated `.inot` file (t suffix stands for **t**hread) representing a clear separation of concerns on a file level. + +### :calling: Easy communication between multiple threads +Easy inter-thread-communication is facilitated via a `Shared` abstraction object providing thread-safe sink/source semantics allowing to safely exchange data of any type between threads. + +### :shield: Thread-safe I/O +A key problem of multi-tasking is the **prevention of erroneous state when multiple threads share a single resource**. The following example borrowed from a typical application demonstrates the problems resulting from multiple threads accessing a single resource: + +Imagine an embedded system where multiple `Wire` client devices are physically connected to a single `Wire` server. Each `Wire` client device is managed by a separate software thread. Each thread polls its `Wire` client device periodically. Access to the I2C bus is managed via the `Wire` library and typically follows this pattern: + +```C++ +/* Wire Write Access */ +Wire.beginTransmission(address); +Wire.write(value); +// Interrupting the current thread e.g. at this point can lead to an erroneous state +// if another thread performs Wire I/O before the transmission ends. +Wire.endTransmission(); + +/* Wire Read Access */ +Wire.requestFrom(address, bytes) +while(Wire.available()) { + int value = Wire.read(); +} +``` + +Since we are using [ARM Mbed OS](https://os.mbed.com/mbed-os/) which is a [preemptive](https://en.wikipedia.org/wiki/Preemption_(computing)) [RTOS](https://en.wikipedia.org/wiki/Real-time_operating_system) for achieving multi-tasking capability and under the assumption that all threads share the same priority (which leads to a [round-robin](https://en.wikipedia.org/wiki/Round-robin_scheduling) scheduling) it can easily happen that one thread is half-way through its Wire I/O access when the scheduler interrupts its execution and schedules the next thread which in turn starts, continues or ends its own Wire I/O access. + +As a result this interruption by the scheduler will break Wire I/O access for both devices and leave the Wire I/O controller in an undefined state :fire:. + +`Arduino_Threads` solves this problem by encapsulating the complete I/O access (e.g. reading from a `Wire` client device) within a single function call which generates an I/O request to be asynchronously executed by a high-priority I/O thread. The high-priority I/O thread is the **only** instance which directly communicates with physical hardware. + +### :runner: Asynchronous +The mechanisms implemented in this library allow any thread to dispatch an I/O request asynchronously and either continue its operation or [yield](https://en.wikipedia.org/wiki/Yield_(multithreading)) control to the next scheduled thread. All I/O requests are stored in a queue and are executed within a high-priority I/O thread after a [context-switch](https://en.wikipedia.org/wiki/Context_switch). An example of this can be seen [here](examples/Threadsafe_IO/Threadsafe_SPI/Threadsafe_SPI.ino). + +### :relieved: Convenient API +Although you are free to directly manipulate I/O requests and responses (e.g. [Threadsafe_Wire](examples/Threadsafe_IO/Threadsafe_Wire/Threadsafe_Wire.ino)) there are convenient `read`/`write`/`writeThenRead` abstractions inspired by the [Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO) library (e.g. [Threadsafe_Wire_BusIO](examples/Threadsafe_IO/Threadsafe_Wire_BusIO/Threadsafe_Wire_BusIO.ino)). + +## :zap: Caveats + +This library is currently in **BETA** phase. This means that neither the API nor the usage patterns are set in stone and are likely to change. We are publishing this library in the full knowledge that we can't foresee every possible use-case and edge-case. Therefore we would like to treat this library, while it's in beta phase, as an experiment and ask for your input for shaping this library. Please help us by providing feedback in the [issues section](https://github.com/bcmi-labs/Arduino_Threads/issues) or participating in our [discussions](https://github.com/arduino/language/discussions). + +## :mag_right: Resources + +* [How to install a library](https://www.arduino.cc/en/guide/libraries) +* [Help Center](https://support.arduino.cc/) - Get help from Arduino's official support team +* [Forum](https://forum.arduino.cc) - Get support from the community + +## :bug: Bugs & Issues + +If you found an issue in this library, you can submit it to the [issue tracker](issues) of this repository. Remember to include as much detail as you can about your hardware set-up, code and steps for reproducing the issue. To prevent hardware related incompatibilities make sure to use an [original Arduino board](https://support.arduino.cc/hc/en-us/articles/360020652100-How-to-spot-a-counterfeit-Arduino). + +## :technologist: Contribute + +There are many ways to contribute: + +* Improve documentation and examples +* Fix a bug +* Test open Pull Requests +* Implement a new feature +* Discuss potential ways to improve this library + +You can submit your patches directly to this repository as Pull Requests. Please provide a detailed description of the problem you're trying to solve and make sure you test on real hardware. + +## :yellow_heart: Donations + +This open-source code is maintained by Arduino with the help of the community. We invest a considerable amount of time in testing code, optimizing it and introducing new features. Please consider [donating](https://www.arduino.cc/en/donate/) or [sponsoring](https://github.com/sponsors/arduino) to support our work, as well as [buying original Arduino boards](https://store.arduino.cc/) which is the best way to make sure our effort can continue in the long term. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Consumer.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Consumer.inot new file mode 100644 index 00000000..44bca8e1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Consumer.inot @@ -0,0 +1,14 @@ +void setup() { + Serial.begin(9600); + while (!Serial) {} +} + +void loop() { + /* If a value is available for reading within the internal + * queue then the value is removed from the queue and made + * available to the calling function. Should no data be + * available, then this thread is suspended until new data + * is available for reading. + */ + Serial.println(counter.pop()); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Producer.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Producer.inot new file mode 100644 index 00000000..bebc44a3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Producer.inot @@ -0,0 +1,13 @@ +void setup() { +} + +void loop() { + static int i = 0; + /* Every 100 ms a new value is inserted into the shared variable + * 'counter'. Internally this is stored within a queue in a FIFO + * (First-In/First-Out) manner. + */ + counter.push(i); + i++; + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/SharedVariables.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/SharedVariables.h new file mode 100644 index 00000000..7cc8c0c0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/SharedVariables.h @@ -0,0 +1,2 @@ +/* Define a shared variable named 'counter' of type 'int'. */ +SHARED(counter, int); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Shared_Counter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Shared_Counter.ino new file mode 100644 index 00000000..adc40540 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Shared_Counter.ino @@ -0,0 +1,12 @@ +/* This example demonstrates data exchange between + * threads using a shared counter variable defined + * within 'SharedVariables.h'. + */ + +void setup() { + Producer.start(); + Consumer.start(); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Consumer.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Consumer.inot new file mode 100644 index 00000000..ab7d63ea --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Consumer.inot @@ -0,0 +1,11 @@ +/* Define a data sink named 'counter' of type 'int' with a internal queue size of 10. */ +SINK(counter, int, 10); + +void setup() { + Serial.begin(9600); + while (!Serial) {} +} + +void loop() { + Serial.println(counter.pop()); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Producer.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Producer.inot new file mode 100644 index 00000000..b82eb23b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Producer.inot @@ -0,0 +1,11 @@ +/* Define a data source named 'counter' of type 'int'. */ +SOURCE(counter, int); + +void setup() { +} + +void loop() { + static int i = 0; + counter.push(i); + i++; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/SharedVariables.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Source_Sink_Counter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Source_Sink_Counter.ino new file mode 100644 index 00000000..20505583 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Source_Sink_Counter.ino @@ -0,0 +1,13 @@ +/* This examples demonstrates the SOURCE/SINK abstraction. Each thread + * may have any number of SOURCES and SINKS that can be connected + * together using the 'connectTo' method. + */ + +void setup() { + Producer.counter.connectTo(Consumer.counter); + Producer.start(); + Consumer.start(); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/SharedVariables.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Sink_Thread.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Sink_Thread.inot new file mode 100644 index 00000000..87213a81 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Sink_Thread.inot @@ -0,0 +1,14 @@ +/* Define a data sink named 'led' of type 'bool' with a internal queue size of 1. */ +SINK(led, bool); + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() { + /* Read a 'bool' value from the SINK and discard it. Since there is no delay in the loop + * this call will block until new data is inserted from the connected SOURCE. This means + * that the pace is dictated by the SOURCE that sends data every 100 ms. + */ + digitalWrite(LED_BUILTIN, led.pop()); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Sink_LED.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Sink_LED.ino new file mode 100644 index 00000000..cf7c2bcb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Sink_LED.ino @@ -0,0 +1,13 @@ +/* This examples demonstrates the SOURCE/SINK abstraction. Each thread + * may have any number of SOURCES and SINKS that can be connected + * together using the 'connectTo' method. + */ + +void setup() { + Source_Thread.led.connectTo(Sink_Thread.led); + Sink_Thread.start(); + Source_Thread.start(); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Thread.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Thread.inot new file mode 100644 index 00000000..b8d13982 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Thread.inot @@ -0,0 +1,12 @@ +/* Define a data source named 'led' of type 'bool'. */ +SOURCE(led, bool); + +void setup() { +} + +void loop() { + led.push(true); + delay(100); + led.push(false); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI/SPI.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI/SPI.ino new file mode 100644 index 00000000..785db89b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI/SPI.ino @@ -0,0 +1,87 @@ +/* This example demonstrates how multiple threads can communicate + * with a single SPI client device using the BusDevice abstraction + * for SPI. In a similar way multiple threads can interface + * with different client devices on the same SPI bus. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static int const BMP388_CS_PIN = 2; +static int const BMP388_INT_PIN = 6; +static byte const BMP388_CHIP_ID_REG_ADDR = 0x00; + +static size_t constexpr NUM_THREADS = 20; + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +byte bmp388_read_reg(byte const reg_addr); +void bmp388_thread_func(); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice bmp388(SPI, BMP388_CS_PIN, 1000000, MSBFIRST, SPI_MODE0); + +static char thread_name[NUM_THREADS][32]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + while (!Serial) {} + + pinMode(BMP388_CS_PIN, OUTPUT); + digitalWrite(BMP388_CS_PIN, HIGH); + + for (size_t i = 0; i < NUM_THREADS; i++) { + snprintf(thread_name[i], sizeof(thread_name[i]), "Thread #%02d", i); + rtos::Thread* t = new rtos::Thread(osPriorityNormal, OS_STACK_SIZE, nullptr, thread_name[i]); + t->start(bmp388_thread_func); + } +} + +void loop() { +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +byte bmp388_read_reg(byte const reg_addr) { + /* REG_ADDR | DUMMY_BYTE | REG_VAL is on SDO */ + byte read_write_buf[] = { static_cast(0x80 | reg_addr), 0, 0 }; + + IoRequest req(read_write_buf, sizeof(read_write_buf), nullptr, 0); + IoResponse rsp = transferAndWait(bmp388, req); + + return read_write_buf[2]; +} + +void bmp388_thread_func() { + Serial.begin(9600); + while (!Serial) {} + + for (;;) { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5, 500))); + /* Try to read some data from the BMP3888. */ + byte const chip_id = bmp388_read_reg(BMP388_CHIP_ID_REG_ADDR); + /* Print thread id and chip id value to serial. */ + char msg[64] = { 0 }; + snprintf(msg, sizeof(msg), "%s: Chip ID = 0x%X", rtos::ThisThread::get_name(), chip_id); + Serial.println(msg); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI_BusIO/SPI_BusIO.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI_BusIO/SPI_BusIO.ino new file mode 100644 index 00000000..9e3fc869 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI_BusIO/SPI_BusIO.ino @@ -0,0 +1,86 @@ +/* This example demonstrates how multiple threads can communicate + * with a single SPI client device using the BusDevice abstraction + * for SPI. In a similar way multiple threads can interface + * with different client devices on the same SPI bus. + * + * This example uses Adafruit_BusIO style read(), write(), + * writeThenRead() APIs. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static int const BMP388_CS_PIN = 2; +static int const BMP388_INT_PIN = 6; +static byte const BMP388_CHIP_ID_REG_ADDR = 0x00; + +static size_t constexpr NUM_THREADS = 20; + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +byte bmp388_read_reg(byte const reg_addr); +void bmp388_thread_func(); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice bmp388(SPI, BMP388_CS_PIN, 1000000, MSBFIRST, SPI_MODE0); + +static char thread_name[NUM_THREADS][32]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + pinMode(BMP388_CS_PIN, OUTPUT); + digitalWrite(BMP388_CS_PIN, HIGH); + + for (size_t i = 0; i < NUM_THREADS; i++) { + snprintf(thread_name[i], sizeof(thread_name[i]), "Thread #%02d", i); + rtos::Thread* t = new rtos::Thread(osPriorityNormal, OS_STACK_SIZE, nullptr, thread_name[i]); + t->start(bmp388_thread_func); + } +} + +void loop() { +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +byte bmp388_read_reg(byte const reg_addr) { + /* REG_ADDR | DUMMY_BYTE | REG_VAL is on SDO */ + byte write_buf[2] = { static_cast(0x80 | reg_addr), 0 }; + byte read_buf = 0; + + bmp388.spi().writeThenRead(write_buf, sizeof(write_buf), &read_buf, sizeof(read_buf)); + return read_buf; +} + +void bmp388_thread_func() { + Serial.begin(9600); + while (!Serial) {} + + for (;;) { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5, 500))); + /* Try to read some data from the BMP3888. */ + byte const chip_id = bmp388_read_reg(BMP388_CHIP_ID_REG_ADDR); + /* Print thread id and chip id value to serial. */ + char msg[64] = { 0 }; + snprintf(msg, sizeof(msg), "%s: Chip ID = 0x%X", rtos::ThisThread::get_name(), chip_id); + Serial.println(msg); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Serial_GlobalPrefixSuffix.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Serial_GlobalPrefixSuffix.ino new file mode 100644 index 00000000..590e339b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Serial_GlobalPrefixSuffix.ino @@ -0,0 +1,54 @@ +/* This example demonstrates how every Serial message can be prefixed + * as well as suffixed by a user-configurable message. In this example + * this functionality is used for appending the current timestamp and + * prepending a line feed. Other uses might be to prepend the thread + * from which a given serial message is originating. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +String serial_log_message_prefix(String const& /* msg */); +String serial_log_message_suffix(String const& prefix, String const& msg); + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + while (!Serial) {} + + Serial.globalPrefix(serial_log_message_prefix); + Serial.globalSuffix(serial_log_message_suffix); + + Thread_1.start(); + Thread_2.start(); + Thread_3.start(); +} + +void loop() { + Serial.block(); + Serial.println("Thread #0: Lorem ipsum ..."); + Serial.unblock(); +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +String serial_log_message_prefix(String const& /* msg */) { + char msg[32] = { 0 }; + snprintf(msg, sizeof(msg), "[%05lu] ", millis()); + return String(msg); +} + +String serial_log_message_suffix(String const& prefix, String const& msg) { + return String("\r\n"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/SharedVariables.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_1.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_1.inot new file mode 100644 index 00000000..ea1b9989 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_1.inot @@ -0,0 +1,9 @@ +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.block(); + Serial.println("Thread #1: Lorem ipsum ..."); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_2.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_2.inot new file mode 100644 index 00000000..71fa7a1e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_2.inot @@ -0,0 +1,9 @@ +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.block(); + Serial.println("Thread #2: Lorem ipsum ..."); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_3.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_3.inot new file mode 100644 index 00000000..8450b17a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_3.inot @@ -0,0 +1,9 @@ +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.block(); + Serial.println("Thread #3: Lorem ipsum ..."); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/GPS_Thread.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/GPS_Thread.inot new file mode 100644 index 00000000..aed2e427 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/GPS_Thread.inot @@ -0,0 +1,59 @@ +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +static String nmea_message_prefix(String const& /* msg */) { + return String("$"); +} + +static String nmea_message_suffix(String const& prefix, String const& msg) { + /* NMEA checksum is calculated over the complete message + * starting with '$' and ending with the end of the message. + */ + byte checksum = 0; + std::for_each(msg.c_str(), + msg.c_str() + msg.length(), + [&checksum](char const c) { + checksum ^= static_cast(c); + }); + /* Assemble the footer of the NMEA message. */ + char footer[16] = { 0 }; + snprintf(footer, sizeof(footer), "*%02X\r\n", checksum); + return String(footer); +} + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + Serial.prefix(nmea_message_prefix); + Serial.suffix(nmea_message_suffix); +} + +void loop() { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5, 500))); + + /* Print a fake NMEA GPRMC message: + * $GPRMC,062101.714,A,5001.869,N,01912.114,E,955535.7,116.2,290520,000.0,W*45\r\n + */ + Serial.block(); + + Serial.print("GPRMC,"); + Serial.print(millis()); + Serial.print(",A,"); + Serial.print("5001.869,"); + Serial.print("N,"); + Serial.print("01912.114,"); + Serial.print("E,"); + Serial.print("955535.7,"); + Serial.print("116.2,"); + Serial.print("290520,"); + Serial.print("000.0,"); + Serial.print("W"); + + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/Serial_ProtocolWrapping.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/Serial_ProtocolWrapping.ino new file mode 100644 index 00000000..0824d203 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/Serial_ProtocolWrapping.ino @@ -0,0 +1,26 @@ +/* This example demonstrates how every Serial message can be prefixed + * as well as suffixed by a user-configurable message. In this example + * this functionality is used for prepending the right header for a + * pseudo NMEA-encoded (think GPS) message as well as for calculating + * and appending the checksum at the end. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + while (!Serial) {} + + GPS_Thread.start(); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/SharedVariables.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Serial_Reader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Serial_Reader.ino new file mode 100644 index 00000000..20e44f7e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Serial_Reader.ino @@ -0,0 +1,46 @@ +/* This example demonstrates how multiple threads can subscribe to + * reading from the same physical Serial interface. Incoming data + * is copied into per-thread receive buffers so that no thread + * can "steal" data from another thread by reading it first. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + while (!Serial) {} + + Thread_1.start(); + Thread_2.start(); + Thread_3.start(); + + Serial.block(); + Serial.println("Thread #0 started."); + Serial.unblock(); +} + +void loop() { + /* Read data from the serial interface into a String. */ + String serial_msg; + while (Serial.available()) + serial_msg += (char)Serial.read(); + + /* Print thread id and chip id value to serial. */ + if (serial_msg.length()) { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #0: "); + Serial.print(serial_msg); + Serial.println(); + Serial.unblock(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/SharedVariables.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_1.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_1.inot new file mode 100644 index 00000000..b10f52e9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_1.inot @@ -0,0 +1,25 @@ +void setup() { + Serial.begin(9600); + + Serial.block(); + Serial.println("Thread #1 started."); + Serial.unblock(); +} + +void loop() { + /* Read data from the serial interface into a String. */ + String serial_msg; + while (Serial.available()) + serial_msg += (char)Serial.read(); + + /* Print thread id and chip id value to serial. */ + if (serial_msg.length()) { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #1: "); + Serial.print(serial_msg); + Serial.println(); + Serial.unblock(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_2.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_2.inot new file mode 100644 index 00000000..eac89b84 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_2.inot @@ -0,0 +1,25 @@ +void setup() { + Serial.begin(9600); + + Serial.block(); + Serial.println("Thread #2 started."); + Serial.unblock(); +} + +void loop() { + /* Read data from the serial interface into a String. */ + String serial_msg; + while (Serial.available()) + serial_msg += (char)Serial.read(); + + /* Print thread id and chip id value to serial. */ + if (serial_msg.length()) { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #2: "); + Serial.print(serial_msg); + Serial.println(); + Serial.unblock(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_3.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_3.inot new file mode 100644 index 00000000..b1c5cb75 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_3.inot @@ -0,0 +1,25 @@ +void setup() { + Serial.begin(9600); + + Serial.block(); + Serial.println("Thread #3 started."); + Serial.unblock(); +} + +void loop() { + /* Read data from the serial interface into a String. */ + String serial_msg; + while (Serial.available()) + serial_msg += (char)Serial.read(); + + /* Print thread id and chip id value to serial. */ + if (serial_msg.length()) { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #3: "); + Serial.print(serial_msg); + Serial.println(); + Serial.unblock(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Serial_Writer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Serial_Writer.ino new file mode 100644 index 00000000..13dd2be4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Serial_Writer.ino @@ -0,0 +1,32 @@ +/* This example demonstrates how multiple threads can write to + * the same physical Serial interface without interfering with + * one another. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + while (!Serial) {} + + Thread_1.start(); + Thread_2.start(); + Thread_3.start(); +} + +void loop() { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #0: Lorem ipsum ..."); + Serial.println(); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/SharedVariables.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_1.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_1.inot new file mode 100644 index 00000000..a3fc1095 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_1.inot @@ -0,0 +1,12 @@ +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #1: Lorem ipsum ..."); + Serial.println(); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_2.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_2.inot new file mode 100644 index 00000000..5ff200f1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_2.inot @@ -0,0 +1,12 @@ +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #2: Lorem ipsum ..."); + Serial.println(); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_3.inot b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_3.inot new file mode 100644 index 00000000..dfe9b05b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_3.inot @@ -0,0 +1,12 @@ +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #3: Lorem ipsum ..."); + Serial.println(); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire/Wire.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire/Wire.ino new file mode 100644 index 00000000..e98d2d8a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire/Wire.ino @@ -0,0 +1,85 @@ +/* This example demonstrates how multiple threads can communicate + * with a single Wire client device using the BusDevice abstraction + * for Wire. In a similar way multiple threads can interface + * with different client devices on the same Wire bus. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static byte constexpr LSM6DSOX_ADDRESS = 0x6A; +static byte constexpr LSM6DSOX_WHO_AM_I_REG = 0x0F; + +static size_t constexpr NUM_THREADS = 20; + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte const reg_addr); +void lsm6dsox_thread_func(); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice lsm6dsox(Wire, LSM6DSOX_ADDRESS); + +static char thread_name[NUM_THREADS][32]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + /* Fire up some threads all accessing the LSM6DSOX */ + for (size_t i = 0; i < NUM_THREADS; i++) { + snprintf(thread_name[i], sizeof(thread_name[i]), "Thread #%02d", i); + rtos::Thread* t = new rtos::Thread(osPriorityNormal, OS_STACK_SIZE, nullptr, thread_name[i]); + t->start(lsm6dsox_thread_func); + } +} + +void loop() { +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte const reg_addr) { + /* As we need only 1 byte large write/read buffers for this IO transaction + * the buffers are not arrays but rather simple variables. + */ + byte write_buf = reg_addr; + byte read_buf = 0; + + IoRequest req(write_buf, read_buf); + IoResponse rsp = transferAndWait(lsm6dsox, req); + + return read_buf; +} + + +void lsm6dsox_thread_func() { + Serial.begin(9600); + while (!Serial) {} + + for (;;) { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5, 500))); + /* Try to read some data from the LSM6DSOX. */ + byte const who_am_i = lsm6dsox_read_reg(LSM6DSOX_WHO_AM_I_REG); + /* Print thread id and chip id value to serial. */ + char msg[64] = { 0 }; + snprintf(msg, sizeof(msg), "%s: LSM6DSOX[WHO_AM_I] = 0x%X", rtos::ThisThread::get_name(), who_am_i); + Serial.println(msg); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire_BusIO/Wire_BusIO.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire_BusIO/Wire_BusIO.ino new file mode 100644 index 00000000..51868cea --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire_BusIO/Wire_BusIO.ino @@ -0,0 +1,80 @@ +/* This example demonstrates how multiple threads can communicate + * with a single Wire client device using the BusDevice abstraction + * for Wire. In a similar way multiple threads can interface + * with different client devices on the same Wire bus. + * + * This example uses Adafruit_BusIO style read(), write(), + * writeThenRead() APIs. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static byte constexpr LSM6DSOX_ADDRESS = 0x6A; +static byte constexpr LSM6DSOX_WHO_AM_I_REG = 0x0F; + +static size_t constexpr NUM_THREADS = 20; + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte const reg_addr); +void lsm6dsox_thread_func(); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice lsm6dsox(Wire, LSM6DSOX_ADDRESS); + +static char thread_name[NUM_THREADS][32]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + /* Fire up some threads all accessing the LSM6DSOX */ + for (size_t i = 0; i < NUM_THREADS; i++) { + snprintf(thread_name[i], sizeof(thread_name[i]), "Thread #%02d", i); + rtos::Thread* t = new rtos::Thread(osPriorityNormal, OS_STACK_SIZE, nullptr, thread_name[i]); + t->start(lsm6dsox_thread_func); + } +} + +void loop() { +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte reg_addr) { + byte read_buf = 0; + lsm6dsox.wire().writeThenRead(®_addr, 1, &read_buf, 1); + return read_buf; +} + +void lsm6dsox_thread_func() { + Serial.begin(9600); + while (!Serial) {} + + for (;;) { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5, 500))); + /* Try to read some data from the LSM6DSOX. */ + byte const who_am_i = lsm6dsox_read_reg(LSM6DSOX_WHO_AM_I_REG); + /* Print thread id and chip id value to serial. */ + char msg[64] = { 0 }; + snprintf(msg, sizeof(msg), "%s: LSM6DSOX[WHO_AM_I] = 0x%X", rtos::ThisThread::get_name(), who_am_i); + Serial.println(msg); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/README.adoc new file mode 100644 index 00000000..950fff1a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: Audio + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The Audio library enables an Arduino Due board to play back .wav files from a storage device like an SD card. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino new file mode 100644 index 00000000..31ea8438 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino @@ -0,0 +1,84 @@ +/* + Simple Audio Player + + Demonstrates the use of the Audio library for the Arduino Due + + Hardware required : + * Arduino shield with a SD card on CS4 + * A sound file named "test.wav" in the root directory of the SD card + * An audio amplifier to connect to the DAC0 and ground + * A speaker to connect to the audio amplifier + + Original by Massimo Banzi September 20, 2012 + Modified by Scott Fitzgerald October 19, 2012 + Modified by Arturo Guadalupi December 18, 2015 + + This example code is in the public domain + + http://www.arduino.cc/en/Tutorial/SimpleAudioPlayer + +*/ + +#include +#include +#include + +void setup() { + // debug output at 9600 baud + Serial.begin(9600); + + // setup SD-card + Serial.print("Initializing SD card..."); + if (!SD.begin(4)) { + Serial.println(" failed!"); + while (true) + ; + } + Serial.println(" done."); + // hi-speed SPI transfers + + // 44100 Hz stereo => 88200 Hz sample rate + // 100 mSec of prebuffering. +} + +void loop() { + int count = 0; + + // open wave file from SD card + File myFile = SD.open("test.wav"); + Audio.begin(88200, 100); + if (!myFile) { + // if the file didn't open, print an error and stop + Serial.println("error opening test.wav"); + while (true) + ; + } + + const int S = 1024; // Number of samples to read in block + short buffer[S]; + + Serial.print("Playing"); + // until the file is finished + while (myFile.available()) { + // read from the file into buffer + myFile.read(buffer, sizeof(buffer)); + + // Prepare samples + int volume = 1024; + Audio.prepare(buffer, S, volume); + // Feed samples to audio + Audio.write(buffer, S); + + // Every 100 blocks print a '.' + count++; + if (count == 100) { + Serial.print("."); + count = 0; + } + } + myFile.close(); + Audio.close(); + Serial.println("End of file. Thank you for listening!"); + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioFrequencyMeter/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioFrequencyMeter/README.adoc new file mode 100644 index 00000000..86f6820b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioFrequencyMeter/README.adoc @@ -0,0 +1,48 @@ +:repository-owner: arduino-libraries +:repository-name: AudioFrequencyMeter + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows the Arduino Zero and MKR1000 to sample a generic input audio signal and get the fundamental pitch. + + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +== Methods == +* begin(uint32_t ulPin, uint32_t sampleRate) : initialize the ADC to sample ulPin at the chosen sample rate. This process works in interrupt using TC5 to start the sampling process. ADC resolution is set to 8 bit + +* end() : stops the sampling process disabling both the ADC and TC5 and resetting TC5 + +* setClippingPin(int pin) : put pin in output to be used as a clipping indicator + +* checkClipping : checks if there is a clipping event (converted value equals to the top or the bottom of the ADC dynamic) and drives HIGH the clippingPin + +* setAmplitudeThreshold(uint8_t threshold) : sets the threshold for which a detected frequency is considered right or wrong. Default is 30 + +* setTimerTolerance(int tolerance) : sets the tolerance for which a sampled signal is considered valid. Default is 10 + +* setSlopeTolerance(int tolerance) : sets the tolerance for which the slope is valid for the trigger process. Default is 3 + +* setBandwidth(float minFrequency, float maxFrequency) : set the range of frequencies for which the detected frequency is valid. Default values for now are 60 Hz - 1500 Hz. This must be improved + +* getFrequency : return the value of the detected frequency if it is above the threshold defined by setAmplitudeThreshold, else -1 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioFrequencyMeter/examples/SimpleAudioFrequencyMeter/SimpleAudioFrequencyMeter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioFrequencyMeter/examples/SimpleAudioFrequencyMeter/SimpleAudioFrequencyMeter.ino new file mode 100644 index 00000000..4c87a339 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioFrequencyMeter/examples/SimpleAudioFrequencyMeter/SimpleAudioFrequencyMeter.ino @@ -0,0 +1,34 @@ +/* + Simple Frequency Meter for Arduino Zero + + Demonstrates how to sample an input signal and get back its frequency + + This example code is in the public domain + + https://www.arduino.cc/en/Tutorial/SimpleAudioFrequencyMeter + + created by Arturo Guadalupi + 10 Nov 2015 +*/ + +#include + +AudioFrequencyMeter meter; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + Serial.println("started"); + + meter.setBandwidth(70.00, 1500); // Ignore frequency out of this range + meter.begin(A0, 45000); // Initialize A0 at sample rate of 45 kHz +} + +void loop() { + // put your main code here, to run repeatedly: + float frequency = meter.getFrequency(); + if (frequency > 0) { + Serial.print(frequency); + Serial.println(" Hz"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioZero/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioZero/README.adoc new file mode 100644 index 00000000..547433f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioZero/README.adoc @@ -0,0 +1,31 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: AudioZero + += {repository-name} library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The {repository-name} library enables an Arduino SAMD Board (e.g., https://store.arduino.cc/catalogsearch/result/?q=mkr[MKR boards], https://store.arduino.cc/arduino-nano-33-iot[Nano 33 IoT], https://store.arduino.cc/arduino-zero[Zero]) to play back .wav files from a storage device like an SD card to the `DAC0`/`A0` pin. +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioZero/examples/SimpleAudioPlayerZero/SimpleAudioPlayerZero.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioZero/examples/SimpleAudioPlayerZero/SimpleAudioPlayerZero.ino new file mode 100644 index 00000000..77728a50 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/AudioZero/examples/SimpleAudioPlayerZero/SimpleAudioPlayerZero.ino @@ -0,0 +1,63 @@ +/* + Simple Audio Player for Arduino Zero + + Demonstrates the use of the Audio library for the Arduino Zero + + Hardware required : + * Arduino shield with a SD card on CS4 + * A sound file named "test.wav" in the root directory of the SD card + * An audio amplifier to connect to the DAC0 and ground + * A speaker to connect to the audio amplifier + + + Arturo Guadalupi + Angelo Scialabba + Claudio Indellicati + + This example code is in the public domain + + https://www.arduino.cc/en/Tutorial/SimpleAudioPlayerZero + +*/ + +#include +#include +#include + +void setup() { + // debug output at 115200 baud + Serial.begin(115200); + + // setup SD-card + Serial.print("Initializing SD card..."); + if (!SD.begin(4)) { + Serial.println(" failed!"); + while (true) + ; + } + Serial.println(" done."); +} + +void loop() { + int count = 0; + + // open wave file from sdcard + File myFile = SD.open("test.wav"); + // 44100kHz stereo => 88200 sample rate + AudioZero.begin(2 * 44100); + if (!myFile) { + // if the file didn't open, print an error and stop + Serial.println("error opening test.wav"); + while (true) + ; + } + + Serial.print("Playing"); + + // until the file is not finished + AudioZero.play(myFile); + AudioZero.close(); + Serial.println("End of file. Thank you for listening!"); + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/README.md new file mode 100644 index 00000000..eadcaba7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/README.md @@ -0,0 +1,22 @@ +Sample SW for using BNO055 with Arduino + +[![Check Arduino status](https://github.com/arduino-libraries/BNO055/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/BNO055/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/BNO055/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/BNO055/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/BNO055/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/BNO055/actions/workflows/spell-check.yml) + +(C) All rights reserved by ROBERT BOSCH GMBH + +Copyright (C) 2014 Bosch Sensortec GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Basic/Basic.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Basic/Basic.ino new file mode 100644 index 00000000..84071439 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Basic/Basic.ino @@ -0,0 +1,99 @@ +/* + *************************************************************************** + * + * Basic.ino - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* BNO055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); + + //Read out device information + Serial.print("Chip ID: "); + Serial.println(myBNO.chip_id); + + //Read out the software revision ID + Serial.print("Software Revision ID: "); + Serial.println(myBNO.sw_revision_id); + + //Read out the page ID + Serial.print("Page ID: "); + Serial.println(myBNO.page_id); + + //Read out the accelerometer revision ID + Serial.print("Accelerometer Revision ID: "); + Serial.println(myBNO.accel_revision_id); + + //Read out the gyroscope revision ID + Serial.print("Gyroscope Revision ID: "); + Serial.println(myBNO.gyro_revision_id); + + //Read out the magnetometer revision ID + Serial.print("Magnetometer Revision ID: "); + Serial.println(myBNO.mag_revision_id); + + //Read out the bootloader revision ID + Serial.print("Bootloader Revision ID: "); + Serial.println(myBNO.bootloader_revision_id); + + //Read out the device address + Serial.print("Device Address: "); + Serial.println(myBNO.dev_addr); +} + +void loop() //This code is looped forever +{ + //Blank +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Command_Line_Configuration/Command_Line_Configuration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Command_Line_Configuration/Command_Line_Configuration.ino new file mode 100644 index 00000000..5637844b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Command_Line_Configuration/Command_Line_Configuration.ino @@ -0,0 +1,245 @@ +/* + *************************************************************************** + * + * Command_Line_Configuration.ino - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* BNO055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +//Variables and Flags +unsigned long lastTime = 0; +bool streamReqd = false; //Flag to indicate the requirement for streaming of data + +//Function Prototypes +void streamData(void); //Function to stream data +void getCommand(void); //Function to receive the command and parse it +void execCommand(char, int); //Function to execute relevant functions depending on the command + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode (Currently defaulted to NDoF) + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); + + //Indication on the Serial Monitor that the Initialization is complete + Serial.println("Initialization Complete"); + Serial.println("Set the terminal character to newline and baud rate to 115200"); + Serial.println("List of commands:"); + Serial.println("s toggles streaming of Euler data"); + Serial.println("c0 to c12 changes the Operation mode"); + Serial.println("p0 to p2 changes the Power mode"); +} + +void loop() //This code is looped forever +{ + if (streamReqd) //If data needs to be streamed then stream data + streamData(); + getCommand(); //To look for incoming UART commands and call relevant functions +} + +void streamData(void) { + if ((millis() - lastTime) >= 100) //To stream at 10Hz without using additional timers + { + lastTime = millis(); + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p) / 16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} + +void getCommand(void) { + int commPos = 0; //Register used to keep track of the index of the command + char par1 = 0; //To store the first parameter of the command + int par2 = 0; //To store the seconds parameter of the command + char command[10] = { 0 }; //Array to store the incoming commands + int index; + for (index = 0; index < 10; index++) //Initialize the command array to NULL + command[index] = 0; + if (Serial.available()) { + int commLen = Serial.readBytesUntil('\n', &command[0], 10); //Store the command in an array and store the length of the incoming command + for (index = 0; index < 10; index++) //Echo the incoming command + Serial.print(command[index]); + Serial.println(); + par1 = command[0]; //Store the first parameter of the command + commPos++; + while ((command[commPos] >= '0') && (command[commPos] <= '9')) //To process digits [0-9]+ and store in par2 + { + par2 *= 10; //Shift the digit position + par2 += command[commPos] - '0'; //Convert ASCII to Integer + commPos++; //Increment the position of the array + } + execCommand(par1, par2); + } +} + +void execCommand(char head, int tail) { + switch (head) { + case 's': //Command to toggle Streaming of data + streamReqd = !streamReqd; + if (streamReqd) + Serial.println("Streaming ON"); + else + Serial.println("Streaming OFF"); + break; + + case 'c': //Command to change the operation mode + streamReqd = false; //Comment this line if you want to data streaming to be kept on + switch (tail) { + case 0: + Serial.println("Set into Configuration Mode"); + bno055_set_operation_mode(OPERATION_MODE_CONFIG); + break; + + case 1: + Serial.println("Set into Accelerometer Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCONLY); + break; + + case 2: + Serial.println("Set into Magnetometer Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_MAGONLY); + break; + + case 3: + Serial.println("Set into Gyroscope Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_GYRONLY); + break; + + case 4: + Serial.println("Set into Accelerometer and Magnetometer Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCMAG); + break; + + case 5: + Serial.println("Set into Accelerometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCGYRO); + break; + + case 6: + Serial.println("Set into Magnetometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_MAGGYRO); + break; + + case 7: + Serial.println("Set into Accelerometer, Magnetometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_AMG); + break; + + case 8: + Serial.println("Set into Sensor Fusion IMU Plus Mode"); + bno055_set_operation_mode(OPERATION_MODE_IMUPLUS); + break; + + case 9: + Serial.println("Set into Sensor Fusion Compass Mode"); + bno055_set_operation_mode(OPERATION_MODE_COMPASS); + break; + + case 10: + Serial.println("Set into Sensor Fusion Magnetometer for Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_M4G); + break; + + case 11: + Serial.println("Set into Sensor Fusion NDoF Mode with Fast Magnetometer Calibration Off"); + bno055_set_operation_mode(OPERATION_MODE_NDOF_FMC_OFF); + break; + + case 12: + Serial.println("Set into Sensor Fusion NDoF Mode"); + bno055_set_operation_mode(OPERATION_MODE_NDOF); + break; + + default: + Serial.println("Invalid Configuration Mode"); + } + break; + + case 'p': //To change power modes + streamReqd = false; //Comment this line if you want to data streaming to be kept on + switch (tail) { + case 0: + Serial.println("Set into Normal Power Mode"); + bno055_set_powermode(POWER_MODE_NORMAL); + break; + + case 1: + Serial.println("Set into Low Power Mode"); + bno055_set_operation_mode(POWER_MODE_LOW_POWER); + break; + + case 2: + Serial.println("Set into Suspend Power Mode"); + bno055_set_operation_mode(POWER_MODE_SUSPEND); + break; + + default: + Serial.println("Invalid Power Mode"); + } + break; + + default: + Serial.println("Invalid Command"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Euler_Streaming/Euler_Streaming.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Euler_Streaming/Euler_Streaming.ino new file mode 100644 index 00000000..ecabf585 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Euler_Streaming/Euler_Streaming.ino @@ -0,0 +1,89 @@ +/* + *************************************************************************** + + Euler_Streaming.ino - part of sample SW for using BNO055 with Arduino + + (C) All rights reserved by ROBERT BOSCH GMBH + + Copyright (C) 2014 Bosch Sensortec GmbH + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + **************************************************************************/ +/* Date: 2014/01/07 + Revision: 1.2 + +*/ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* BNO055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if ((millis() - lastTime) >= 100) //To stream at 10 Hz without using additional timers + { + lastTime = millis(); + + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p) / 16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Sensor_Calibration/Sensor_Calibration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Sensor_Calibration/Sensor_Calibration.ino new file mode 100644 index 00000000..5e30663d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/BNO055/examples/Sensor_Calibration/Sensor_Calibration.ino @@ -0,0 +1,97 @@ +/* + *************************************************************************** + * + * Sensor_Calibration.ino - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* BNO055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +unsigned char accelCalibStatus = 0; //Variable to hold the calibration status of the Accelerometer +unsigned char magCalibStatus = 0; //Variable to hold the calibration status of the Magnetometer +unsigned char gyroCalibStatus = 0; //Variable to hold the calibration status of the Gyroscope +unsigned char sysCalibStatus = 0; //Variable to hold the calibration status of the System (BNO055's MCU) + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if ((millis() - lastTime) >= 200) //To read calibration status at 5 Hz without using additional timers + { + lastTime = millis(); + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + bno055_get_accelcalib_status(&accelCalibStatus); + Serial.print("Accelerometer Calibration Status: "); //To read out the Accelerometer Calibration Status (0-3) + Serial.println(accelCalibStatus); + + bno055_get_magcalib_status(&magCalibStatus); + Serial.print("Magnetometer Calibration Status: "); //To read out the Magnetometer Calibration Status (0-3) + Serial.println(magCalibStatus); + + bno055_get_magcalib_status(&gyroCalibStatus); + Serial.print("Gyroscope Calibration Status: "); //To read out the Gyroscope Calibration Status (0-3) + Serial.println(gyroCalibStatus); + + bno055_get_syscalib_status(&sysCalibStatus); + Serial.print("System Calibration Status: "); //To read out the Magnetometer Calibration Status (0-3) + Serial.println(sysCalibStatus); + + Serial.println(); //To separate between packets + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/README.adoc new file mode 100644 index 00000000..a5688b89 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/README.adoc @@ -0,0 +1,29 @@ +:repository-owner: arduino-libraries +:repository-name: Braccio + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The library offers easy access to the data from the onboard TinkerKit Braccio, and provides moves for the Braccio. + +For more information about this library please visit us at +https://www.arduino.cc/en/Guide/Braccio + +== License == + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/braccioOfUnoWiFi/braccioOfUnoWiFi.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/braccioOfUnoWiFi/braccioOfUnoWiFi.ino new file mode 100644 index 00000000..1f0401f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/braccioOfUnoWiFi/braccioOfUnoWiFi.ino @@ -0,0 +1,263 @@ +/* + + braccioOfUnoWifi.ino + + Based on Arduino Uno WiFi Rest Server example + + This example for the Arduino Uno WiFi shows how to + control a TinkerKit Braccio through REST calls. + You can create your mobile app or your + browser app to control the Braccio in wireless mode + + Note that with the Braccio shield version less than V4 + you need to disconnect the pin A4 from the shield to the board + + Possible commands created in this sketch: + + * "/arduino/custom/base/value:80" -> Moves the base of the Braccio at 80 degrees + * "/arduino/custom/shoulder/value:150" -> Moves the shoulder of the Braccio at 150 degrees + * "/arduino/custom/elbow/value:45" -> Moves the elbow of the Braccio at 45 degrees + * "/arduino/custom/wristv/value:10" -> Moves the wristv of the Braccio at 10 degrees + * "/arduino/custom/wristr/value:120" -> Moves the wristr of the Braccio at 120 degrees + * "/arduino/custom/gripper/value:73" -> Close the gripper + * "/arduino/custom/ledon" -> Turn ON the LED 13 + * "/arduino/custom/ledoff" -> Turn OFF the LED 13 + * "/arduino/custom/servo:3/value:73" -> Moves the servo to the pin 3 at 73 degrees + * "/arduino/custom/sayciao" -> Run the function sayciao(). The Braccio says "Ciao" with the gripper + * "/arduino/custom/takesponge" -> Run the function takesponge(). The Braccio takes the big sponge you can find in its box + * "/arduino/custom/showsponge" -> Run the function showsponge(). The Braccio shows the sponge to the user + * "/arduino/custom/throwsponge" -> Run the function throwsponge(). The Braccio throws away the sponge + + This example code is part of the public domain + + https://web.archive.org/web/20160502122840/http://labs.arduino.org/RestServer+and+RestClient + https://store.arduino.cc/tinkerkit-braccio-robot + +*/ + +#include +#include +#include +#include + +//Initial Value for each Motor +int m1 = 0; +int m2 = 45; +int m3 = 180; +int m4 = 180; +int m5 = 90; +int m6 = 0; + +bool moveBraccio = false; + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + + +void setup() { + //Initialization of Braccio + Braccio.begin(); + //Initialization of the Uno WiFi + Wifi.begin(); + Wifi.println("REST Server is up"); +} + +void loop() { + //Wait until the board receives HTTP commands + while (Wifi.available()) { + process(Wifi); + } + delay(50); +} + +/** +Parse Command from REST +It parse a command like: /arduino/custom/base/value:45 +@param command: The message to parse +@param type: the key for parsing +@return the value for the key +*/ +int parseCommand(String command, String type) { + int typeIndex = command.indexOf(type); + int dotsIndex = command.indexOf(':', typeIndex + type.length()); + + int idxtmp = dotsIndex + 4; + if ((dotsIndex + 4) > command.length()) idxtmp = command.length(); + String tmp = command.substring(dotsIndex + 1, idxtmp); + + return tmp.toInt(); +} + +/** +It process data from the HTTP protocol +*/ +void process(WifiData client) { + // read the command + String command = client.readString(); + command.toUpperCase(); + + if (command.indexOf("CUSTOM") == -1) { + client.println("Invalid command: " + command + ""); + return; + } + + //The message from sender + String message = command.substring(16); + //client.println(message); //Debug + + /* + For each message perform the proper command + */ + if (message == "LEDON") { + //Turn ON Led 13 + digitalWrite(13, HIGH); + //Return message to the sender (Eg: the browser) + client.println("alert('Led D13 ON');"); + } else if (message == "LEDOFF") { + digitalWrite(13, LOW); + client.println("alert('Led D13 OFF');"); + } + //This command allow you to move a desired servo motor giving the + //PWM pin where is connected + //eg: http://192.168.240.1/arduino/custom/servo:3/value:45 or http://192.168.240.1/arduino/custom/base/value:45 + else if (message.startsWith("SERVO")) { + //Parse the message to retrieve which servo to move + int servo = parseCommand(message, "SERVO"); + //Parse the message to retrieve the value for the servo + int value = parseCommand(message, "VALUE"); + + client.println("Message:" + String(message) + "SERVO: " + String(servo) + " " + String(value)); + + moveBraccio = true; + } + //http://192.168.240.1/arduino/custom/base:45 or http://192.168.240.1/arduino/custom/base/value:45 + //Command for the base of the Braccio (M1) + else if (message.startsWith("BASE")) { + m1 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("BASE: " + String(m1)); + } + //Command for the shoulder of the Braccio (M2) + else if (message.startsWith("SHOULDER")) { + m2 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("SHOULDER: " + String(m2)); + } + //Command for the elbow of the Braccio (M3) + else if (message.startsWith("ELBOW")) { + m3 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("ELBOW: " + String(m3)); + } + //Command for the wrist of the Braccio to move it up and down (M4) + else if (message.startsWith("WRISTV")) { + m4 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("WRISTV: " + String(m4)); + } + //Command for the wrist of the Braccio to rotate it (M5) + else if (message.startsWith("WRISTR")) { + m5 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("WRISTR: " + String(m5)); + } + //Command for the GRIPPER of the Braccio to open and close it (M6) + else if (message.startsWith("GRIPPER")) { + m6 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("GRIPPER: " + String(m6)); + } + //Command to say "Ciao" + else if (message.startsWith("SAYCIAO")) { + sayCiao(); + client.println("SAYCIAO: " + String(m6)); + } + //Command for take the sponge + else if (message.startsWith("TAKESPONGE")) { + takesponge(); + client.println("TAKESPONGE: " + String(m6)); + } + //Command for show the sponge + else if (message.startsWith("SHOWSPONGE")) { + showsponge(); + client.println("SHOWSPONGE: " + String(m6)); + } + //Command for throw away the sponge + else if (message.startsWith("THROWSPONGE")) { + throwsponge(); + client.println("THROWSPONGE: " + String(m6)); + } else + client.println("command error: " + message); + + //if flag moveBraccio is true fire the movement + if (moveBraccio) { + //client.println("moveBraccio"); + Braccio.ServoMovement(20, m1, m2, m3, m4, m5, m6); + moveBraccio = false; + } + + client.flush(); +} + +/** +The Braccio Say 'Ciao' with the GRIPPER +*/ +void sayCiao() { + Braccio.ServoMovement(20, 90, 0, 180, 160, 0, 15); + + for (int i = 0; i < 5; i++) { + Braccio.ServoMovement(10, 90, 0, 180, 160, 0, 15); + delay(500); + + Braccio.ServoMovement(10, 90, 0, 180, 160, 0, 73); + delay(500); + } +} + +/** +Braccio take the Sponge +*/ +void takesponge() { + //starting position + //(step delay M1 , M2 , M3 , M4 , M5 , M6); + Braccio.ServoMovement(20, 0, 45, 180, 180, 90, 0); + + //I move arm towards the sponge + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 0); + + //the GRIPPER takes the sponge + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 60); + + //up the sponge + Braccio.ServoMovement(20, 0, 45, 180, 45, 0, 60); +} + + +/** +Braccio show the sponge to the user +*/ +void showsponge() { + for (int i = 0; i < 2; i++) { + + //(step delay M1 , M2 , M3 , M4 , M5 , M6 ); + Braccio.ServoMovement(10, 0, 45, 180, 45, 180, 60); + + Braccio.ServoMovement(10, 0, 45, 180, 45, 0, 60); + } +} + +/** +Braccio throw away the sponge +*/ +void throwsponge() { + //(step delay M1 , M2 , M3 , M4 , M5 , M6 ); + Braccio.ServoMovement(20, 0, 45, 90, 45, 90, 60); + + Braccio.ServoMovement(5, 0, 45, 135, 90, 90, 60); + + Braccio.ServoMovement(5, 0, 90, 150, 90, 90, 0); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/ciaoBraccio/ciaoBraccio.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/ciaoBraccio/ciaoBraccio.ino new file mode 100644 index 00000000..9d9d8a43 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/ciaoBraccio/ciaoBraccio.ino @@ -0,0 +1,236 @@ +/* + + This sketch uses the REST connector to receive command for the MCU from a REST client. + Each command received will fire an action for the Braccio. + Run the sketch with Arduino Braccio - Web Examples to move your Braccio via web page. + Visit the Demo section of the Braccio's page. + https://www.arduino.cc/en/Guide/Braccio + + + +REST command example: + + * "ledon" -> turn on led 13 + * "ledoff" -> turn off led 13 + + example: http://arduino.local/arduino/ledon + + NOTE: be sure to activate and configure REST connector on Linino OS + https://www.arduino.cc/en/Reference/Ciao + + created March 2016 + by andrea[at]arduino[dot]org and a.ferrante[at]arduino[dot]org + + */ + +#include +#include +#include + +//Initial Value for each Motor +int m1 = 0; +int m2 = 45; +int m3 = 180; +int m4 = 180; +int m5 = 90; +int m6 = 0; + +bool moveBraccio = false; + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + +void setup() { + //Initialization function for Ciao + Ciao.begin(); + //Initialization function for Braccio + //You should set begin(SOFT_START_DISABLED) if you are using the Arm Robot shield V1.6 + Braccio.begin(); +} + +/** +Parse Command from REST +It parses a command like: /arduino/base/value:45 +Giving "base" it return the value +@param command: The message to parse +@param type: the key for parsing +*/ +int parseCommand(String command, String type) { + int typeIndex = command.indexOf(type); + int dotsIndex = command.indexOf(':', typeIndex + type.length()); + + int idxtmp = dotsIndex + 4; + if ((dotsIndex + 4) > command.length()) idxtmp = command.length(); + String tmp = command.substring(dotsIndex + 1, idxtmp); + + return tmp.toInt(); +} + +void loop() { + + //Select REST connector + CiaoData data = Ciao.read("restserver"); + //If data is not empty + if (!data.isEmpty()) { + //ID of the command + String id = data.get(0); + //Sender ID + String sender = data.get(1); + //The message from sender + String message = data.get(2); + + message.toUpperCase(); + + /* + For each message do the proper command + */ + if (message == "LEDON") { + //Turn OFF Led 13 + digitalWrite(13, HIGH); + //Return message to the sender (Eg: the browser) + Ciao.writeResponse("restserver", id, "Led D13 ON"); + } else if (message == "LEDOFF") { + digitalWrite(13, LOW); + Ciao.writeResponse("restserver", id, "Led D13 OFF"); + } + //This command allow you to move a desired servo motor giving the + //PWM pin where is connected + else if (message.startsWith("SERVO")) { + //Parse the message to retrieve which servo to move + int servo = parseCommand(message, "SERVO"); + //Parse the message to retrieve the value for the servo + int value = parseCommand(message, "VALUE"); + + Ciao.writeResponse("restserver", id, "Message:" + String(message) + "SERVO: " + String(servo) + " " + String(value)); + } + //Command for the base of the Braccio (M1) + else if (message.startsWith("BASE")) { + m1 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "BASE: " + String(m1)); + } + //Command for the shoulder of the Braccio (M2) + else if (message.startsWith("SHOULDER")) { + m2 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "SHOULDER: " + String(m2)); + } + //Command for the elbow of the Braccio (M3) + else if (message.startsWith("ELBOW")) { + m3 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "ELBOW: " + String(m3)); + } + //Command for the wrist of the Braccio to move up and down (M4) + else if (message.startsWith("WRISTV")) { + m4 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "WRISTV: " + String(m4)); + } + //Command for the wrist of the Braccio to rotate (M5) + else if (message.startsWith("WRISTR")) { + m5 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "WRISTR: " + String(m5)); + } + //Command for the gripper of the Braccio to open and close (M6) + else if (message.startsWith("GRIPPER")) { + m6 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "GRIPPER: " + String(m6)); + } + //Command to say "Ciao" + else if (message.startsWith("SAYCIAO")) { + sayCiao(); + Ciao.writeResponse("restserver", id, "SAYCIAO: " + String(m6)); + } + //Command to take the sponge + else if (message.startsWith("TAKESPONGE")) { + takesponge(); + Ciao.writeResponse("restserver", id, "TAKESPONGE: " + String(m6)); + } + //Command to show the sponge + else if (message.startsWith("SHOWSPONGE")) { + showsponge(); + Ciao.writeResponse("restserver", id, "SHOWSPONGE: " + String(m6)); + } + //Command to throw away the sponge + else if (message.startsWith("THROWSPONGE")) { + throwsponge(); + Ciao.writeResponse("restserver", id, "THROWSPONGE: " + String(m6)); + } + + else + Ciao.writeResponse("restserver", id, "command error"); + + //if flag moveBraccio is true fire the movement + if (moveBraccio) { + Braccio.ServoMovement(20, m1, m2, m3, m4, m5, m6); + moveBraccio = false; + } + } +} + +/** +The Braccio says 'Ciao' with the Tongue +*/ +void sayCiao() { + + Braccio.ServoMovement(20, 90, 0, 180, 160, 0, 15); + + for (int i = 0; i < 5; i++) { + Braccio.ServoMovement(10, 90, 0, 180, 160, 0, 15); + delay(500); + + Braccio.ServoMovement(10, 90, 0, 180, 160, 0, 73); + delay(500); + } +} + +/** +Braccio takes the Sponge +*/ +void takesponge() { + //starting position + //(step delay M1 , M2 , M3 , M4 , M5 , M6); + Braccio.ServoMovement(20, 0, 45, 180, 180, 90, 0); + + //I move arm towards the sponge + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 0); + + //the gripper takes the sponge + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 60); + + //raise the sponge + Braccio.ServoMovement(20, 0, 45, 180, 45, 0, 60); +} + + +/** +Braccio shows the sponge to the user +*/ +void showsponge() { + for (int i = 0; i < 2; i++) { + + //(step delay M1 , M2 , M3 , M4 , M5 , M6 ); + Braccio.ServoMovement(10, 0, 45, 180, 45, 180, 60); + + Braccio.ServoMovement(10, 0, 45, 180, 45, 0, 60); + } +} + +/** +Braccio throws away the sponge +*/ +void throwsponge() { + //(step delay M1 , M2 , M3 , M4 , M5 , M6 ); + Braccio.ServoMovement(20, 0, 45, 90, 45, 90, 60); + + Braccio.ServoMovement(5, 0, 45, 135, 90, 90, 60); + + Braccio.ServoMovement(5, 0, 90, 150, 90, 90, 0); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/simpleMovements/simpleMovements.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/simpleMovements/simpleMovements.ino new file mode 100644 index 00000000..c85141f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/simpleMovements/simpleMovements.ino @@ -0,0 +1,56 @@ + +/* + simpleMovements.ino + + The simpleMovements sketch shows how to move each servo motor of the Braccio + + Created on 18 Nov 2015 + by Andrea Martino + + This example is in the public domain. + */ + +#include +#include + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + +void setup() { + //Initialization functions and set up the initial position for Braccio + //All the servo motors will be positioned in the "safety" position: + //Base (M1):90 degrees + //Shoulder (M2): 45 degrees + //Elbow (M3): 180 degrees + //Wrist vertical (M4): 180 degrees + //Wrist rotation (M5): 90 degrees + //gripper (M6): 10 degrees + Braccio.begin(); +} + +void loop() { + /* + Step Delay: a milliseconds delay between the movement of each servo. Allowed values from 10 to 30 msec. + M1=base degrees. Allowed values from 0 to 180 degrees + M2=shoulder degrees. Allowed values from 15 to 165 degrees + M3=elbow degrees. Allowed values from 0 to 180 degrees + M4=wrist vertical degrees. Allowed values from 0 to 180 degrees + M5=wrist rotation degrees. Allowed values from 0 to 180 degrees + M6=gripper degrees. Allowed values from 10 to 73 degrees. 10: the tongue is open, 73: the gripper is closed. + */ + + //(step delay, M1, M2, M3, M4, M5, M6); + Braccio.ServoMovement(20, 0, 15, 180, 170, 0, 73); + + //Wait 1 second + delay(1000); + + Braccio.ServoMovement(20, 180, 165, 0, 0, 180, 10); + + //Wait 1 second + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/takethesponge/takethesponge.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/takethesponge/takethesponge.ino new file mode 100644 index 00000000..698678bb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/takethesponge/takethesponge.ino @@ -0,0 +1,71 @@ +/* + takethesponge.ino + + This example commands the Braccio to take a sponge from the table and show it to the user + + Created on 18 Nov 2015 + by Andrea Martino + + This example is in the public domain. +*/ + +#include +#include + + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + + +void setup() { + //Initialization functions and set up the initial position for Braccio + //All the servo motors will be positioned in the "safety" position: + //Base (M1):90 degrees + //Shoulder (M2): 45 degrees + //Elbow (M3): 180 degrees + //Wrist vertical (M4): 180 degrees + //Wrist rotation (M5): 90 degrees + //gripper (M6): 10 degrees + Braccio.begin(); +} + +void loop() { + /* + Step Delay: a milliseconds delay between the movement of each servo. Allowed values from 10 to 30 msec. + M1=base degrees. Allowed values from 0 to 180 degrees + M2=shoulder degrees. Allowed values from 15 to 165 degrees + M3=elbow degrees. Allowed values from 0 to 180 degrees + M4=wrist vertical degrees. Allowed values from 0 to 180 degrees + M5=wrist rotation degrees. Allowed values from 0 to 180 degrees + M6=gripper degrees. Allowed values from 10 to 73 degrees. 10: the tongue is open, 73: the gripper is closed. + */ + + //Starting position + //(step delay M1 , M2 , M3 , M4 , M5 , M6); + Braccio.ServoMovement(20, 0, 45, 180, 180, 90, 10); + + //Wait 1 second + delay(1000); + + //The Braccio moves to the sponge. Only the M2 servo will moves + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 10); + + //Close the gripper to take the sponge. Only the M6 servo will moves + Braccio.ServoMovement(10, 0, 90, 180, 180, 90, 60); + + //Brings the sponge upwards. + Braccio.ServoMovement(20, 0, 45, 180, 45, 0, 60); + + //Show the sponge. Only the M1 servo will moves + Braccio.ServoMovement(20, 180, 45, 180, 45, 0, 60); + + //Return to the start position. + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 60); + + //Open the gripper + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/testBraccio90/testBraccio90.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/testBraccio90/testBraccio90.ino new file mode 100644 index 00000000..c90292e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Braccio/examples/testBraccio90/testBraccio90.ino @@ -0,0 +1,52 @@ +/* + testBraccio90.ino + + testBraccio90 is a setup sketch to check the alignment of all the servo motors + This is the first sketch you need to run on Braccio + When you start this sketch Braccio will be positioned perpendicular to the base + If you can't see the Braccio in this exact position you need to realign the servo motor positions + + Created on 18 Nov 2015 + by Andrea Martino + + This example is in the public domain. + */ + +#include +#include + + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + +void setup() { + //Initialization functions and set up the initial position for Braccio + //All the servo motors will be positioned in the "safety" position: + //Base (M1):90 degrees + //Shoulder (M2): 45 degrees + //Elbow (M3): 180 degrees + //Wrist vertical (M4): 180 degrees + //Wrist rotation (M5): 90 degrees + //gripper (M6): 10 degrees + Braccio.begin(); +} + +void loop() { + /* + Step Delay: a milliseconds delay between the movement of each servo. Allowed values from 10 to 30 msec. + M1=base degrees. Allowed values from 0 to 180 degrees + M2=shoulder degrees. Allowed values from 15 to 165 degrees + M3=elbow degrees. Allowed values from 0 to 180 degrees + M4=wrist vertical degrees. Allowed values from 0 to 180 degrees + M5=wrist rotation degrees. Allowed values from 0 to 180 degrees + M6=gripper degrees. Allowed values from 10 to 73 degrees. 10: the tongue is open, 73: the gripper is closed. + */ + + // the arm is aligned upwards and the gripper is closed + //(step delay, M1, M2, M3, M4, M5, M6); + Braccio.ServoMovement(20, 90, 90, 90, 90, 90, 73); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity1/AnalogInputs_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity1/AnalogInputs_Activity1.ino new file mode 100644 index 00000000..bcc657fc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity1/AnalogInputs_Activity1.ino @@ -0,0 +1,20 @@ +/* + CTC GO! CORE MODULE + LESSON 07 - Analog Inputs + + This sketch is written to accompany Activity 1 in Lesson 07 of the CTC GO! core module +*/ + +int pot = A0; +int val = 0; + +void setup() { + Serial.begin(9600); +} + +void loop() { + // Read and display the value of the potentiometers + val = analogRead(pot); + Serial.print("Value read: "); + Serial.println(val); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity2/AnalogInputs_Activity2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity2/AnalogInputs_Activity2.ino new file mode 100644 index 00000000..8a1d86c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity2/AnalogInputs_Activity2.ino @@ -0,0 +1,31 @@ +/* + CTC GO! CORE MODULE + LESSON 07 - Analog Inputs + + This sketch is written to accompany Activity 2 in Lesson 07 of the CTC GO! core module +*/ + + +int lightSensor = A0; +int LED = 13; +int val = 0; +int trigger = 250; + +void setup() { + pinMode(LED, OUTPUT); + Serial.begin(9600); +} + +void loop() { + //savethe read on a variable and print it + val = analogRead(lightSensor); + Serial.print("Value read: "); + Serial.println(val); + + if (val < trigger) { + digitalWrite(LED, HIGH); + } else { + digitalWrite(LED, LOW); + } + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity3/AnalogInputs_Activity3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity3/AnalogInputs_Activity3.ino new file mode 100644 index 00000000..926003e6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity3/AnalogInputs_Activity3.ino @@ -0,0 +1,52 @@ + +/* + CTC GO! CORE MODULE + LESSON 07 - Analog Inputs + + This sketch is written to accompany Activity 3 in Lesson 07 of the CTC GO! core module +*/ + +int USsensor = A0; +int greenLED = 9; +int yellowLED = 11; +int redLED = 13; + +float distance = 0; +int value = 0; + + +void setup() { + pinMode(redLED, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(greenLED, OUTPUT); + + Serial.begin(9600); +} + +void loop() { + // reading, calculating and printing the distance + value = analogRead(USsensor); + distance = value * 3; + Serial.print("Dinstance to the object (mm): "); + Serial.println(distance); + delay(250); + + // visualizing the distance with the LEDs + if (distance < 200) { + digitalWrite(redLED, HIGH); + digitalWrite(yellowLED, LOW); + digitalWrite(greenLED, LOW); + } else if (distance < 400) { + digitalWrite(yellowLED, HIGH); + digitalWrite(redLED, LOW); + digitalWrite(greenLED, LOW); + } else if (distance < 600) { + digitalWrite(greenLED, HIGH); + digitalWrite(yellowLED, LOW); + digitalWrite(redLED, LOW); + } else { + digitalWrite(greenLED, LOW); + digitalWrite(yellowLED, LOW); + digitalWrite(redLED, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity1/AnalogOutputs_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity1/AnalogOutputs_Activity1.ino new file mode 100644 index 00000000..95ad0e90 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity1/AnalogOutputs_Activity1.ino @@ -0,0 +1,28 @@ + +/* + CTC GO! CORE MODULE + LESSON 08 - Analog Outputs + + This sketch is written to accompany Activity 1 in Lesson 08 of the CTC GO! core module +*/ + +int pot = A0; +int LED = 3; + +// to save the potentiometer position +int val = 0; + +// to change the LED bright +int PWM = 0; + +void setup() { + pinMode(LED, OUTPUT); +} + +void loop() { + val = analogRead(pot); + + //re-ranging val values + PWM = map(val, 0, 1023, 0, 255); + analogWrite(LED, PWM); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity2/AnalogOutputs_Activity2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity2/AnalogOutputs_Activity2.ino new file mode 100644 index 00000000..3ca971bc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity2/AnalogOutputs_Activity2.ino @@ -0,0 +1,41 @@ + +/* + CTC GO! CORE MODULE + LESSON 08 - Analog Outputs + + This sketch is written to accompany Activity 2 in Lesson 08 of the CTC GO! core module +*/ + +//pin connections +int buttonA = 13; +int buttonB = 12; +int piezo = 8; + +// notes frequency +int A_note = 262; +int B_note = 493; + +// to save the button states +int buttAvalue = 0; +int buttBvalue = 0; + +void setup() { + pinMode(buttonA, INPUT); + pinMode(buttonB, INPUT); + pinMode(piezo, OUTPUT); +} + +void loop() { + //reading the buttons states + buttAvalue = digitalRead(buttonA); + buttBvalue = digitalRead(buttonB); + + // play a note, based on the button pressed + if (buttAvalue == HIGH) { + tone(piezo, A_note); + } else if (buttBvalue == HIGH) { + tone(piezo, B_note); + } else { + noTone(piezo); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity3/AnalogOutputs_Activity3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity3/AnalogOutputs_Activity3.ino new file mode 100644 index 00000000..19199695 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity3/AnalogOutputs_Activity3.ino @@ -0,0 +1,66 @@ + +/* + CTC GO! CORE MODULE + LESSON 08 - Analog Outputs + + This sketch is written to accompany Activity 3 in Lesson 08 of the CTC GO! core module +*/ + + +int button = 13; +int piezo = 8; +int LED = 5; +int USsensor = A0; + +int C_note = 262; +int B_note = 493; + +int buttValue = 0; +int value = 0; +int distance = 0; + +int alarm = 0; +int trigger = 500; + +void setup() { + pinMode(button, INPUT); + pinMode(piezo, OUTPUT); + pinMode(LED, OUTPUT); +} + +void loop() { + // reading button state and distance + buttValue = digitalRead(button); + value = analogRead(USsensor); + distance = value * 3; + + // setting the trigger distance + if (distance < trigger) { + alarm = 1; + } + // deactivating the alarm + else if (buttValue == HIGH) { + alarm = 0; + } + + // if the alarm is triggered + if (alarm == 1) { + tone(piezo, C_note); + for (int i = 0; i < 255; i++) { + analogWrite(LED, i); + delay(5); + } + + tone(piezo, B_note); + for (int i = 255; i > 0; i--) { + analogWrite(LED, i); + delay(5); + } + } + + //if the alarm is not triggered + else { + digitalWrite(LED, LOW); + noTone(piezo); //stop playing sound + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity1/DigitalIO_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity1/DigitalIO_Activity1.ino new file mode 100644 index 00000000..30be5ea1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity1/DigitalIO_Activity1.ino @@ -0,0 +1,23 @@ +/* + CTC GO! CORE MODULE + LESSON 04 - Digital Inputs & Outputs + + This sketch is written to accompany Activity 1 in Lesson 04 of the CTC GO! core module +*/ + +// Initialising the pins and other variables. + +int button_pin = 2; +int button_state = 0; + +void setup() { + // Setting up the pins as OUTPUTS & INPUTS. + pinMode(LED_BUILTIN, OUTPUT); + pinMode(button_pin, INPUT); +} + +void loop() { + // Saving the button state in a variable + button_state = digitalRead(button_pin); + digitalWrite(LED_BUILTIN, button_state); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity2/DigitalIO_Activity2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity2/DigitalIO_Activity2.ino new file mode 100644 index 00000000..82fd4895 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity2/DigitalIO_Activity2.ino @@ -0,0 +1,29 @@ +/* + CTC GO! CORE MODULE + LESSON 04 - Digital Inputs & Outputs + + This sketch is written to accompany Activity 2 in Lesson 04 of the CTC GO! core module +*/ + +int button_pin = 2; +int button_state = 0; + +void setup() { + // Setting up the pins as OUTPUTS & INPUTS. + pinMode(LED_BUILTIN, OUTPUT); + pinMode(button_pin, INPUT); +} + +void loop() { + button_state = digitalRead(button_pin); + + // if the button is presed, blink the LEDS + if (button_state == HIGH) { + digitalWrite(LED_BUILTIN, HIGH); + delay(1000); + digitalWrite(LED_BUILTIN, LOW); + delay(1000); + } else { + digitalWrite(LED_BUILTIN, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity3/DigitalIO_Activity3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity3/DigitalIO_Activity3.ino new file mode 100644 index 00000000..35c2da93 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity3/DigitalIO_Activity3.ino @@ -0,0 +1,41 @@ +/* + CTC GO! CORE MODULE + LESSON 04 - Digital Inputs & Outputs + + This sketch is written to accompany Activity 3 in Lesson 04 of the CTC GO! core module +*/ + +// Initialising the pins and other variables. +int greenLED = 11; +int yellowLED = 12; +int redLED = 13; + +int blinkingLED = 0; + +void setup() { + // Setting up the pins as OUTPUTS. + pinMode(greenLED, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(redLED, OUTPUT); +} + +void loop() { + // Randomly blink the LEDs + blinkingLED = random(11, 14); + + if (blinkingLED == greenLED) { + digitalWrite(greenLED, HIGH); + } + + else if (blinkingLED == yellowLED) { + digitalWrite(yellowLED, HIGH); + } else if (blinkingLED == redLED) { + digitalWrite(redLED, HIGH); + } + + delay(1000); + digitalWrite(greenLED, LOW); + digitalWrite(yellowLED, LOW); + digitalWrite(redLED, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity1/Programming_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity1/Programming_Activity1.ino new file mode 100644 index 00000000..d2417585 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity1/Programming_Activity1.ino @@ -0,0 +1,19 @@ +/* + CTC GO! CORE MODULE + LESSON 03 - Let's Start Programming + + This sketch is written to accompany Activity 1 in Lesson 03 of the CTC GO! core module + +*/ + +void setup() { + // initialize digital pin LED_BUILTIN as an output. + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity3/Programming_Activity3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity3/Programming_Activity3.ino new file mode 100644 index 00000000..c6fbd40c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity3/Programming_Activity3.ino @@ -0,0 +1,27 @@ +/* + CTC GO! CORE MODULE + LESSON 03 - Let's Start Programming + + This sketch is written to accompany Activity 3 in Lesson 03 of the CTC GO! core module + +*/ + +// initialising the pins. +int redLED = 13; +int yellowLED = 12; + +void setup() { + // Setting up the pins as OUTPUTS. + pinMode(redLED, OUTPUT); + pinMode(yellowLED, OUTPUT); +} + +void loop() { + // Blink the LEDs. + digitalWrite(redLED, HIGH); + digitalWrite(yellowLED, HIGH); + delay(1000); + digitalWrite(redLED, LOW); + digitalWrite(yellowLED, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity1/SerialToBoard_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity1/SerialToBoard_Activity1.ino new file mode 100644 index 00000000..f4ba0979 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity1/SerialToBoard_Activity1.ino @@ -0,0 +1,27 @@ + +/* + CTC GO! CORE MODULE + LESSON 06 - Sending Data to the Board + + This sketch is written to accompany Activity 1 in Lesson 06 of the CTC GO! core module +*/ + +int incomingNum = 0; +char incomingChar; + +void setup() { + Serial.begin(9600); +} + +void loop() { + // if there are characters available, read and print them + if (Serial.available() > 0) { + incomingNum = Serial.read(); + incomingChar = incomingNum; + + Serial.println("Character Code"); + Serial.print(incomingChar); + Serial.print(" "); + Serial.println(incomingNum); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity2/SerialToBoard_Activity2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity2/SerialToBoard_Activity2.ino new file mode 100644 index 00000000..1730d3be --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity2/SerialToBoard_Activity2.ino @@ -0,0 +1,81 @@ +/* + CTC GO! CORE MODULE + LESSON 06 - Sending Data to the Board + + This sketch is written to accompany Activity 2 in Lesson 06 of the CTC GO! core module +*/ + +char incomingWord[10]; +int counter = 0; +int i = 0; + +// initialising the pins. +int redLED = 13; +int greenLED = 12; + +void setup() { + pinMode(redLED, OUTPUT); + pinMode(greenLED, OUTPUT); + Serial.begin(9600); +} + +void loop() { + // send data only when you receive data: + if (Serial.available() > 0) { + incomingWord[i] = Serial.read(); + + if (incomingWord[i] == 'a') { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } else if (incomingWord[i] == 'e') { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } else if (incomingWord[i] == 'i') { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } else if (incomingWord[i] == 'o') { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } else if (incomingWord[i] == 'u') { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } else { + digitalWrite(redLED, HIGH); + delay(500); + digitalWrite(redLED, LOW); + delay(500); + } + + i += 1; + } else { + Serial.print("The word introduced is: "); + for (int i = 0; i < 10; i++) { + Serial.print(incomingWord[i]); + } + Serial.println(""); + Serial.print("It has: "); + Serial.print(counter); + Serial.println(" Vowels"); + delay(5000); + counter = 0; + i = 0; + for (int i = 0; i < 10; i++) { + incomingWord[i] = 0; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity3/SerialToBoard_Activity3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity3/SerialToBoard_Activity3.ino new file mode 100644 index 00000000..ebbed20d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity3/SerialToBoard_Activity3.ino @@ -0,0 +1,78 @@ +/* + CTC GO! CORE MODULE + LESSON 06 - Sending Data to the Board + + This sketch is written to accompany Activity 3 in Lesson 06 of the CTC GO! core module +*/ + +// choosing the word to guess +char selectedWord[] = { "HelloWorld" }; +char guessingWord[sizeof(selectedWord)]; +char incoming = 0; + +int counter = 0; +int mistakes = 0; +int success = 0; +int chances = 3; + +void setup() { + // opens serial port, sets data rate to 9600 bps + Serial.begin(9600); + // to show the length of the word has to be guessed + for (int i = 0; i < sizeof(selectedWord) - 1; i++) { + guessingWord[i] = '_'; + } + Serial.print("The Word you are looking for is: "); + Serial.println(guessingWord); +} + +void loop() { + + if (Serial.available() > 0) { + incoming = Serial.read(); + // checking if it is a success or mistake + for (int i = 0; i < sizeof(selectedWord); i++) { + if (incoming == selectedWord[i]) { + guessingWord[i] = incoming; + success += 1; + } else { + counter = counter + 1; + } + } + + if (counter == sizeof(selectedWord)) { + mistakes += 1; + Serial.println("Wrong letter!! Try again..."); + } + } + + // printing the state of the guess word + if (mistakes < chances) { + Serial.print("The Word you are looking for is: "); + for (int i = 0; i < sizeof(selectedWord); i++) { + Serial.print(guessingWord[i]); + } + Serial.print(" Mistakes: "); + Serial.println(mistakes); + counter = 0; + delay(1000); + } + + // finishing the game + else if (mistakes == chances) { + Serial.println(); + Serial.println("Game Over"); + mistakes = 5; + } + + // end of the game + else {} + + // winning + if (success == sizeof(selectedWord) - 1) { + Serial.println(); + Serial.print("WINEER!!"); + success = 0; + mistakes = 5; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity1/SerialToPC_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity1/SerialToPC_Activity1.ino new file mode 100644 index 00000000..37b34416 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity1/SerialToPC_Activity1.ino @@ -0,0 +1,17 @@ +/* + CTC GO! CORE MODULE + LESSON 05 - Showing messages on PC + + This sketch is written to accompany Activity 1 in Lesson 05 of the CTC GO! core module +*/ + +void setup() { + // initialize digital serial communication at 9600baud. + Serial.begin(9600); +} + +void loop() { + //Printing a sentnce every second + Serial.println("Hello World!!"); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity2/SerialToPC_Activity2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity2/SerialToPC_Activity2.ino new file mode 100644 index 00000000..f091a742 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity2/SerialToPC_Activity2.ino @@ -0,0 +1,34 @@ +/* + CTC GO! CORE MODULE + LESSON 05 - Showing messages on PC + + This sketch is written to accompany Activity 2 in Lesson 05 of the CTC GO! core module +*/ + +// initialising the pins and other variables. +int button = 2; +int button_state = 0; +int counter = 0; + +void setup() { + Serial.begin(9600); + // Setting up the pins as OUTPUTS. + pinMode(button, INPUT); +} + +void loop() { + button_state = digitalRead(button); + + //increase the value of counter one unit when button is pressed + if (button_state == HIGH) { + counter += 1; + delay(500); + Serial.print("counter value = "); + Serial.println(counter); + + //Reset counter when it reaches 100 + if (counter == 100) { + counter = 0; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage1/ARGlasses_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage1/ARGlasses_Stage1.ino new file mode 100644 index 00000000..440d0c9c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage1/ARGlasses_Stage1.ino @@ -0,0 +1,26 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 1 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; + +int freq_1 = 500; + +void setup() { + pinMode(_____, _____); + pinMode(_____, _____); +} + +void loop() { + digitalWrite(yellowLED, _____); + _____(piezo, _____); + delay(100); + + digitalWrite(yellowLED, _____); + _____(piezo); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage2/ARGlasses_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage2/ARGlasses_Stage2.ino new file mode 100644 index 00000000..cbf55f2b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage2/ARGlasses_Stage2.ino @@ -0,0 +1,38 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 2 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; + +int distanceSensor = A0; + +int freq_1 = 500; +int distanceSensorValue = 0; + +void setup() { + pinMode(piezo, OUTPUT); + pinMode(yellowLED, OUTPUT); + + Serial.begin(9600); +} + +void loop() { + + distanceSensorValue = _____(distanceSensor); + _____("Distance read: "); + Serial.println(_____); + + /* + //STEP 1; Blink the LED and Activate the Piezo + digitalWrite(yellowLED,HIGH); + tone(piezo,freq_1); + delay(100); + digitalWrite(yellowLED,LOW); + noTone(piezo); + delay(100); + */ +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage3/ARGlasses_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage3/ARGlasses_Stage3.ino new file mode 100644 index 00000000..0ff39fc4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage3/ARGlasses_Stage3.ino @@ -0,0 +1,43 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 3 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; + +int distanceSensor = A0; + +int freq_1 = 500; +int distanceSensorValue = 0; +int actualDistanceMM = 0; + +void setup() { + pinMode(piezo, OUTPUT); + pinMode(yellowLED, OUTPUT); + Serial.begin(9600); +} + +void loop() { + + distanceSensorValue = analogRead(distanceSensor); + actualDistanceMM = map(distanceSensorValue, 0, 1023, _____, _____); + + Serial.print("Distance read: "); + Serial.println(_____); + Serial.print("Distance converted: "); + Serial.println(_____); + + /* + digitalWrite(yellowLED,HIGH); + tone(piezo,freq_1); + delay(100); + digitalWrite(yellowLED,LOW); + noTone(piezo,freq_1); + delay(100); + */ + + delay(_____); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage4/ARGlasses_Stage4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage4/ARGlasses_Stage4.ino new file mode 100644 index 00000000..96e5740b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage4/ARGlasses_Stage4.ino @@ -0,0 +1,42 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 4 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; +int distanceSensor = A0; + +int freq_1 = 500; +int distanceSensorValue = 0; +int actualDistanceMM = 0; +int actualDelay = 0; + +void setup() { + pinMode(piezo, OUTPUT); + pinMode(yellowLED, OUTPUT); + Serial.begin(9600); +} + +void loop() { + + distanceSensorValue = analogRead(distanceSensor); + + actualDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + + Serial.print("Distance read: "); + Serial.println(distanceSensorValue); + Serial.print("Distance converted: "); + Serial.println(actualDistanceMM); + + actualDelay = map(actualDistanceMM, _____, _____, _____, _____); + + digitalWrite(yellowLED, HIGH); + tone(piezo, freq_1); + delay(_____); + digitalWrite(yellowLED, LOW); + noTone(piezo); + delay(_____); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage5/ARGlasses_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage5/ARGlasses_Stage5.ino new file mode 100644 index 00000000..3900ae24 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage5/ARGlasses_Stage5.ino @@ -0,0 +1,50 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 5 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; +int redLED = 12; +int distanceSensor = A0; +int freq_1 = 500; +int distanceSensorValue = 0; +int actualDistanceMM = 0; +int actualDelay = 0; +int distance = 250; + +void setup() { + pinMode(piezo, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(redLED, OUTPUT); + + Serial.begin(9600); +} + +void loop() { + distanceSensorValue = analogRead(distanceSensor); + actualDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + Serial.print("Distance read: "); + Serial.println(distanceSensorValue); + Serial.print("Distance converted: "); + Serial.println(actualDistanceMM); + + actualDelay = map(actualDistanceMM, 0, 3000, 0, 1000); + + if (actualDistanceMM < _____) { + digitalWrite(redLED, _____); + _____(_____, freq_1); + delay(100); + digitalWrite(redLED, _____); + delay(100); + } else if (actualDistanceMM > _____) { + digitalWrite(yellowLED, _____); + tone(piezo, freq_1); + delay(actualDelay); + digitalWrite(yellowLED, _____); + noTone(piezo); + delay(actualDelay); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage1/CrazyDJ_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage1/CrazyDJ_Stage1.ino new file mode 100644 index 00000000..e9900362 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage1/CrazyDJ_Stage1.ino @@ -0,0 +1,28 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - CRAZY DJ + + This sketch is written to accompany Stage 1 in CRAZY DJ of the CTC GO! core module +*/ + +//STEP 1; Variables for blue LED & light sensor +int lightSensor = A0; +int ledPin = 10; + +int lightValue = 0; +int LEDvalue = 0; + +void setup() { + _____(ledPin, _____); + Serial.begin(9600); +} + +void loop() { + lightValue = _____(lightSensor); + LEDvalue = map(lightValue, _____, _____, _____, _____); + analogWrite(ledPin, LEDvalue); + + Serial.print("Light value: "); + Serial.println(lightValue); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage2/CrazyDJ_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage2/CrazyDJ_Stage2.ino new file mode 100644 index 00000000..0970968c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage2/CrazyDJ_Stage2.ino @@ -0,0 +1,39 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - CRAZY DJ + + This sketch is written to accompany Stage 2 in CRAZY DJ of the CTC GO! core module +*/ + + +int lightSensor = A0; +int ledPin = 10; +int piezo = 9; + +int lightValue = 0; +int LEDvalue = 0; +int soundValue = 0; + +void setup() { + pinMode(ledPin, OUTPUT); + pinMode(_____, _____); + Serial.begin(9600); +} + +void loop() { + lightValue = analogRead(lightSensor); + LEDvalue = map(lightValue, 0, 1023, 0, 255); + analogWrite(ledPin, LEDvalue); + + soundValue = map(lightValue, _____, _____, _____, _____); + _____(piezo, _____); + delay(_____); + _____(piezo); + delay(_____); + + Serial.print("Light value: "); + Serial.print(lightValue); + Serial.print(" Sound frequence: "); + Serial.println(soundValue); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage3/CrazyDJ_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage3/CrazyDJ_Stage3.ino new file mode 100644 index 00000000..b7eb0f20 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage3/CrazyDJ_Stage3.ino @@ -0,0 +1,49 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - CRAZY DJ + + This sketch is written to accompany Stage 3 in CRAZY DJ of the CTC GO! core module +*/ + +int lightSensor = A0; +int on_pot = A1; +int off_pot = A2; +int ledPin = 10; +int piezo = 9; + +int lightValue = 0; +int LEDvalue = 0; +int soundValue = 0; +int onTime = 0; +int offTime = 0; + +void setup() { + pinMode(ledPin, OUTPUT); + pinMode(piezo, OUTPUT); + Serial.begin(9600); +} + +void loop() { + lightValue = analogRead(lightSensor); + LEDvalue = map(lightValue, 0, 1023, 0, 255); + analogWrite(ledPin, LEDvalue); + + onTime = _____; + offTime = _____; + + soundValue = map(lightValue, 0, 1023, 31, 4000); + + tone(piezo, soundValue); + delay(_____); + noTone(piezo); + delay(_____); + + Serial.print("Light value: "); + Serial.print(lightValue); + Serial.print(" Sound frequence: "); + Serial.println(soundValue); + Serial.print("Time ON: "); + Serial.print(_____); + Serial.print(" Time OFF: "); + Serial.println(_____); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage4/CrazyDJ_Stage4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage4/CrazyDJ_Stage4.ino new file mode 100644 index 00000000..d88d9b51 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage4/CrazyDJ_Stage4.ino @@ -0,0 +1,52 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - CRAZY DJ + + This sketch is written to accompany Stage 4 in CRAZY DJ of the CTC GO! core module +*/ + +int lightSensor = A0; +int on_pot = A1; +int off_pot = A2; +int av_pot = A3; +int ledPin = 10; +int piezo = 9; + +int lightValue = 0; +int LEDvalue = 0; +int soundValue = 0; +int onTime = 0; +int offTime = 0; +int avPitch = 0; + +void setup() { + pinMode(ledPin, OUTPUT); + pinMode(piezo, OUTPUT); + Serial.begin(9600); +} + +void loop() { + lightValue = analogRead(lightSensor); + LEDvalue = map(lightValue, 0, 1023, 0, 255); + analogWrite(ledPin, LEDvalue); + + onTime = analogRead(on_pot); + offTime = analogRead(off_pot); + + avPitch = _____; + soundValue = map(_____, 0, 1023, 31, 4000); + + tone(piezo, soundValue); + delay(onTime); + noTone(piezo); + delay(offTime); + + Serial.print("Light value: "); + Serial.print(lightValue); + Serial.print(" Sound frequence: "); + Serial.println(soundValue); + Serial.print("Time ON: "); + Serial.print(onTime); + Serial.print(" Time OFF: "); + Serial.println(offTime); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage1/FingerRace_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage1/FingerRace_Stage1.ino new file mode 100644 index 00000000..b2c16408 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage1/FingerRace_Stage1.ino @@ -0,0 +1,22 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 1 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int button_P1 = 6; + +void setup() { + pinMode(greenLED_P1, _____); + pinMode(button_P1, _____); +} + +void loop() { + if (digitalRead(button_P1) == HIGH) { + digitalWrite(greenLED_P1, _____); + } else { + digitalWrite(greenLED_P1, _____); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage2/FingerRace_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage2/FingerRace_Stage2.ino new file mode 100644 index 00000000..9b8e05d4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage2/FingerRace_Stage2.ino @@ -0,0 +1,33 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 2 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int button_P1 = 6; +int greenLED_P2 = 9; +int button_P2 = 7; + +void setup() { + pinMode(greenLED_P1, OUTPUT); + pinMode(greenLED_P2, _____); + pinMode(button_P2, INPUT); + pinMode(button_P1, _____); +} + +void loop() { + + if (digitalRead(button_P1) == HIGH) { + digitalWrite(greenLED_P1, HIGH); + } else { + digitalWrite(greenLED_P1, LOW); + } + + if (digitalRead(_____) == _____) { + digitalWrite(_____, _____); + } else { + digitalWrite(_____, _____); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage3/FingerRace_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage3/FingerRace_Stage3.ino new file mode 100644 index 00000000..c21fcf44 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage3/FingerRace_Stage3.ino @@ -0,0 +1,60 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 3 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int greenLED_P2 = 9; + +int button_P1 = 6; +int button_P2 = 7; + +int blueLED_P1 = 12; +int blueLED_P2 = 10; + +int gameState = 0; + +void setup() { + pinMode(greenLED_P1, OUTPUT); + pinMode(blueLED_P1, _____); + pinMode(blueLED_P2, _____); + pinMode(greenLED_P2, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() { + + if (gameState == _____) { + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + delay(200); + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + delay(200); + } else if (gameState == 1) { + + } else if (gameState == 2) { + } + + if (digitalRead(button_P1) == HIGH) { + gameState = _____; + digitalWrite(greenLED_P1, HIGH); + } else { + digitalWrite(greenLED_P1, LOW); + } + + if (digitalRead(button_P2) == HIGH) { + gameState = _____; + digitalWrite(greenLED_P2, HIGH); + } else { + digitalWrite(greenLED_P2, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage4/FingerRace_Stage4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage4/FingerRace_Stage4.ino new file mode 100644 index 00000000..68e4463b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage4/FingerRace_Stage4.ino @@ -0,0 +1,104 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 4 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int blueLED_P1 = 12; + +int blueLED_P2 = 10; +int greenLED_P2 = 9; + +int button_P1 = 6; +int button_P2 = 7; + +int gameState = 0; + +int player_1 = 0; +int player_2 = 0; + +void setup() { + pinMode(greenLED_P1, OUTPUT); + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED_P2, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() { + + if (gameState == 0) { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED_P2, HIGH); + delay(200); + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + delay(200); + } + + else if (gameState == 1) { + + } + + else if (gameState == 2) { + if (_____) { + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + } else if (_____) { + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + } else { + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + } + if (_____) { + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + + delay(_____); + gameState = _____; + player_1 = _____; + player_2 = _____; + } + if (_____) { + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + + delay(_____); + gameState = _____; + player_1 = _____; + player_2 = _____; + } + } + + + if (digitalRead(button_P1) == HIGH) { + gameState = 2; + digitalWrite(greenLED_P1, HIGH); + player_1 = _____; + } + + else { + digitalWrite(greenLED_P1, LOW); + } + + if (digitalRead(button_P2) == HIGH) { + gameState = 2; + digitalWrite(greenLED_P2, HIGH); + player_2 = _____; + } else { + digitalWrite(greenLED_P2, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage5/FingerRace_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage5/FingerRace_Stage5.ino new file mode 100644 index 00000000..017bd0ca --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage5/FingerRace_Stage5.ino @@ -0,0 +1,114 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 5 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int blueLED_P1 = 12; + +int blueLED_P2 = 10; +int greenLED_P2 = 9; + +int button_P1 = 6; +int button_P2 = 7; + +int gameState = 0; + +int player_1 = 0; +int player_2 = 0; + +int previousButtonState_P1 = 0; +int previousButtonState_P2 = 0; + +void setup() { + pinMode(greenLED_P1, OUTPUT); + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED_P2, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() { + + if (gameState == 0) { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED_P2, HIGH); + delay(200); + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + delay(200); + } else if (gameState == 1) { + + } else if (gameState == 2) { + if (player_1 > player_2) { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, LOW); + } else if (player_2 > player_1) { + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, HIGH); + } else { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + } + + if (player_1 > 30) { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + + delay(3000); + gameState = 0; + player_1 = 0; + player_2 = 0; + } + + if (player_2 > 30) { + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, HIGH); + + delay(3000); + gameState = 0; + player_1 = 0; + player_2 = 0; + } + } else if (gameState == 2) { + } + + if (digitalRead(button_P1) == HIGH) { + gameState = 2; + digitalWrite(greenLED_P1, HIGH); + + if (previousButtonState_P1 == _____) { + player_1 = player_1 + 1; + } + previousButtonState_P1 = _____; + } + + else { + digitalWrite(greenLED_P1, LOW); + previousButtonState_P1 = HIGH; + } + + if (digitalRead(button_P2) == HIGH) { + gameState = 2; + digitalWrite(greenLED_P2, HIGH); + if (previousButtonState_P2 == _____) { + player_2 = player_2 + 1; + } + previousButtonState_P2 = _____; + } else { + digitalWrite(greenLED_P2, LOW); + previousButtonState_P2 = _____; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage6/FingerRace_Stage6.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage6/FingerRace_Stage6.ino new file mode 100644 index 00000000..f2d2f145 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage6/FingerRace_Stage6.ino @@ -0,0 +1,146 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 6 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int blueLED_P1 = 12; + +int blueLED_P2 = 10; +int greenLED_P2 = 9; + +int button_P1 = 6; +int button_P2 = 7; + +int gameState = 0; +int previousButtonState_P1 = 0; +int previousButtonState_P2 = 0; +int player_1 = 0; +int player_2 = 0; + +void setup() { + pinMode(greenLED_P1, OUTPUT); + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED_P2, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() { + if (gameState == 0) { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED_P2, HIGH); + delay(200); + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + delay(200); + } else if (gameState == 1) { + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + delay(_____); + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + delay(_____); + digitalWrite(greenLED_P1, _____); + digitalWrite(greenLED_P2, _____); + delay(_____); + digitalWrite(greenLED_P1, _____); + digitalWrite(greenLED_P2, _____); + delay(_____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + delay(_____); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + + player_1 = _____; + player_2 = _____; + gameState = _____; + } else if (gameState == 2) { + + if (player_1 > player_2) { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, LOW); + } + + else if (player_2 > player_1) { + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, HIGH); + } + + else { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + } + + if (player_1 > 30) { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + delay(3000); + + gameState = 0; + player_1 = 0; + player_2 = 0; + } + + if (player_2 > 30) { + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, HIGH); + delay(3000); + gameState = 0; + player_1 = 0; + player_2 = 0; + } + } + + delay(5); + + if (digitalRead(button_P1) == HIGH) { + if (gameState == _____) { + gameState = _____1; + } + digitalWrite(greenLED_P1, HIGH); + + if (previousButtonState_P1 == LOW) { + player_1 = player_1 + 1; + } + previousButtonState_P1 = HIGH; + } + + else { + + digitalWrite(greenLED_P1, LOW); + previousButtonState_P1 = LOW; + } + + if (digitalRead(button_P2) == HIGH) { + if (gameState == _____) { + gameState = _____; + } + + digitalWrite(greenLED_P2, HIGH); + if (previousButtonState_P2 == LOW) { + player_2 = player_2 + 1; + } + previousButtonState_P2 = HIGH; + } else { + digitalWrite(greenLED_P2, LOW); + previousButtonState_P2 = LOW; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage1/MorseAlien_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage1/MorseAlien_Stage1.ino new file mode 100644 index 00000000..38526a33 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage1/MorseAlien_Stage1.ino @@ -0,0 +1,32 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 1 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; + +void setup() { + pinMode(_____, _____); + Serial.begin(9600); +} + +void loop() { + + int distanceSensorValue = _____(distanceSensor); + + int actualDistanceMM = map(_____, 0, 1023, 0, 3000); + + Serial.print(_____); + Serial.print(","); + Serial.println(_____); + + if (_____ < 200) { + digitalWrite(_____, HIGH); + } + _____ { + digitalWrite(_____, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage2/MorseAlien_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage2/MorseAlien_Stage2.ino new file mode 100644 index 00000000..84f0f2f9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage2/MorseAlien_Stage2.ino @@ -0,0 +1,68 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 2 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; +int breakButton = 10; +int recordButton = 12; +int playButton = 11; +int piezo = 8; + +int prevBreakButtonState = LOW; +int prevRecordButtonState = LOW; +int prevPlayButtonState = LOW; + +void setup() { + pinMode(blueLED, OUTPUT); + pinMode(breakButton, _____); + pinMode(recordButton, _____); + pinMode(playButton, _____); + pinMode(piezo, _____); + + Serial.begin(9600); +} + +void loop() { + int distanceSensorValue = analogRead(distanceSensor); + int actualDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + + if (distanceSensorValue < 200) { + digitalWrite(blueLED, HIGH); + } else { + digitalWrite(blueLED, LOW); + } + + if (digitalRead(_____) == _____) { + if (prevRecordButtonState == _____) { + Serial.println("_____"); + tone(_____, 1000); + } + prevRecordButtonState = _____; + } else { + prevRecordButtonState = _____; + } + + if (_____ == _____) { + if (prevBreakButtonState == _____) { + Serial.println(_____); + tone(_____, _____); + } + prevBreakButtonState = _____; + } else { + prevBreakButtonState = _____; + } + + if (_____ == _____) { + if (prevPlayButtonState == _____) { + Serial.println(_____); + tone(_____, _____); + } + _____ = _____; + } else { + _____ = _____; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage3/MorseAlien_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage3/MorseAlien_Stage3.ino new file mode 100644 index 00000000..fbfa1ca6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage3/MorseAlien_Stage3.ino @@ -0,0 +1,107 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 3 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; +int breakButton = 10; +int recordButton = 12; +int playButton = 11; +int piezo = 8; + +int prevBreakButtonState = LOW; +int prevRecordButtonState = LOW; +int prevPlayButtonState = LOW; + +int mySymbols[50]; +int symbolIndex = 0; +int symbolLength = 300; +int currentSymbol = 0; +int sequencePlayed = false; + +int DASH = 2; +int DOT = 1; +int freq_DASH = 1500; +int freq_DOT = 1000; + +void setup() { + pinMode(blueLED, OUTPUT); + pinMode(breakButton, INPUT); + pinMode(recordButton, INPUT); + pinMode(playButton, INPUT); + pinMode(piezo, OUTPUT); + + Serial.begin(9600); +} + +void loop() { + int distanceSensorValue = analogRead(distanceSensor); + int actualDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + + if (distanceSensorValue < 200) { + digitalWrite(blueLED, HIGH); + currentSymbol = _____; + } else { + digitalWrite(blueLED, LOW); + currentSymbol = _____; + } + + if (digitalRead(recordButton) == HIGH) { + if (prevRecordButtonState == LOW) { + Serial.print("ADDING SYMBOL"); + Serial.print(_____); + Serial.print(" "); + Serial.println(_____); + digitalWrite(blueLED, LOW); + delay(symbolLength); + + if (currentSymbol == _____) { + digitalWrite(_____, _____); + tone(_____, freq_DOT); + delay(symbolLength); + digitalWrite(_____, _____); + } else if (currentSymbol == DASH) { + digitalWrite(_____, _____); + tone(piezo, _____); + delay(symbolLength * 3); + digitalWrite(_____, _____); + } + } + prevRecordButtonState = HIGH; + + /* + Add the symbol to the array + */ + if (sequencePlayed == true) { + sequencePlayed = _____; + symbolIndex = _____; + } + mySymbols[_____] = _____; + symbolIndex = _____; + } else { + prevRecordButtonState = LOW; + } + + if (digitalRead(breakButton) == HIGH) { + if (prevBreakButtonState == LOW) { + Serial.println("ADDING BREAK"); + tone(piezo, 1000); + } + prevBreakButtonState = HIGH; + } else { + prevBreakButtonState = LOW; + } + + if (digitalRead(playButton) == HIGH) { + if (prevPlayButtonState == LOW) { + Serial.println("START PLAYING SYMBOLS"); + tone(piezo, 1000); + } + prevPlayButtonState = HIGH; + } else { + prevPlayButtonState = LOW; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage4/MorseAlien_Stage4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage4/MorseAlien_Stage4.ino new file mode 100644 index 00000000..634cd58c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage4/MorseAlien_Stage4.ino @@ -0,0 +1,122 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 4 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; +int breakButton = 10; +int recordButton = 12; +int playButton = 11; +int piezo = 8; + +int prevBreakButtonState = LOW; +int prevRecordButtonState = LOW; +int prevPlayButtonState = LOW; + +int mySymbols[50]; +int symbolIndex = 0; +int symbolLength = 300; +int currentSymbol = 0; +int sequencePlayed = false; + +int DASH = 2; +int DOT = 1; +int BREAK = 0; + +int freq_DASH = 1500; +int freq_DOT = 1000; +int freq_BREAK = 500; + +void setup() { + pinMode(blueLED, OUTPUT); + pinMode(breakButton, INPUT); + pinMode(recordButton, INPUT); + pinMode(playButton, INPUT); + pinMode(piezo, OUTPUT); + + Serial.begin(9600); +} + +void loop() { + int distanceSensorValue = analogRead(distanceSensor); + int actualDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + + if (distanceSensorValue < 200) { + digitalWrite(blueLED, HIGH); + currentSymbol = DASH; + } else { + digitalWrite(blueLED, LOW); + currentSymbol = DOT; + } + + if (digitalRead(recordButton) == HIGH) { + if (prevRecordButtonState == LOW) { + Serial.print("ADDING SYMBOL"); + Serial.print(symbolIndex); + Serial.print(" "); + Serial.println(currentSymbol); + + digitalWrite(blueLED, LOW); + delay(symbolLength); + if (currentSymbol == DOT) { + digitalWrite(blueLED, HIGH); + tone(piezo, freq_DOT); + delay(symbolLength); + digitalWrite(blueLED, LOW); + } else if (currentSymbol == DASH) { + digitalWrite(blueLED, HIGH); + tone(piezo, freq_DASH); + delay(symbolLength * 3); + digitalWrite(blueLED, LOW); + } + } + prevRecordButtonState = HIGH; + + /* + Add the symbol to the array + */ + //If the sequence played already, start recording from scratch + if (sequencePlayed == true) { + sequencePlayed = false; + symbolIndex = 0; + } + mySymbols[symbolIndex] = currentSymbol; + symbolIndex = symbolIndex + 1; + } else { + prevRecordButtonState = LOW; + } + + if (digitalRead(breakButton) == HIGH) { + if (prevBreakButtonState == LOW) { + Serial.print("ADDING BREAK"); + currentSymbol = _____; + Serial.print(_____); + Serial.print(" "); + Serial.println(_____); + tone(piezo, freq_BREAK); + delay(symbolLength * 3); + + if (sequencePlayed == true) { + symbolIndex = _____; + } + mySymbols[_____] = _____; + symbolIndex = symbolIndex + 1; + } + prevBreakButtonState = HIGH; + } else { + prevBreakButtonState = LOW; + } + + if (digitalRead(playButton) == HIGH) { + if (prevPlayButtonState == LOW) { + Serial.println("START PLAYING SYMBOLS"); + tone(piezo, 1000); + } + prevPlayButtonState = HIGH; + } else { + prevPlayButtonState = LOW; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage5/MorseAlien_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage5/MorseAlien_Stage5.ino new file mode 100644 index 00000000..4cf8240f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage5/MorseAlien_Stage5.ino @@ -0,0 +1,140 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 5 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; +int breakButton = 10; +int recordButton = 12; +int playButton = 11; +int piezo = 8; + +int prevBreakButtonState = LOW; +int prevRecordButtonState = LOW; +int prevPlayButtonState = LOW; + +int mySymbols[50]; +int symbolIndex = 0; +int symbolLength = 300; +int currentSymbol = 0; +int sequencePlayed = false; + +int DASH = 2; +int DOT = 1; +int BREAK = 0; + +int freq_DASH = 1500; +int freq_DOT = 1000; +int freq_BREAK = 500; + +void setup() { + pinMode(blueLED, OUTPUT); + pinMode(breakButton, INPUT); + pinMode(recordButton, INPUT); + pinMode(playButton, INPUT); + pinMode(piezo, OUTPUT); + + Serial.begin(9600); +} + +void loop() { + int distanceSensorValue = analogRead(distanceSensor); + int actualDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + + if (distanceSensorValue < 200) { + digitalWrite(blueLED, HIGH); + currentSymbol = DASH; + } else { + digitalWrite(blueLED, LOW); + currentSymbol = DOT; + } + + if (digitalRead(recordButton) == HIGH) { + if (prevRecordButtonState == LOW) { + Serial.print("ADDING SYMBOL "); + Serial.print(symbolIndex); + Serial.print(" "); + Serial.println(currentSymbol); + + digitalWrite(blueLED, LOW); + delay(symbolLength); + + if (currentSymbol == DOT) { + digitalWrite(blueLED, HIGH); + tone(piezo, freq_DOT); + delay(symbolLength); + digitalWrite(blueLED, LOW); + } else if (currentSymbol == DASH) { + digitalWrite(blueLED, HIGH); + tone(piezo, freq_DASH); + delay(symbolLength * 3); + digitalWrite(blueLED, LOW); + } + } + prevRecordButtonState = HIGH; + + if (sequencePlayed == true) { + sequencePlayed = false; + symbolIndex = 0; + } + mySymbols[symbolIndex] = currentSymbol; + symbolIndex = symbolIndex + 1; + } else { + prevRecordButtonState = LOW; + } + + if (digitalRead(breakButton) == HIGH) { + if (prevBreakButtonState == LOW) { + Serial.print("ADDING BREAK"); + currentSymbol = BREAK; + Serial.print(symbolIndex); + Serial.println(currentSymbol); + tone(piezo, freq_BREAK); + delay(symbolLength * 3); + /* + Add the symbol to the array + */ + //If the sequence played already, start recording from scratch + if (sequencePlayed == true) { + symbolIndex = 0; + } + mySymbols[symbolIndex] = currentSymbol; + symbolIndex = symbolIndex + 1; + } + prevBreakButtonState = HIGH; + } else { + prevBreakButtonState = LOW; + } + + if (digitalRead(playButton) == HIGH) { + if (prevPlayButtonState == LOW) { + Serial.println("START PLAYING SYMBOLS"); + sequencePlayed = true; + for (int i = 0; i < symbolIndex; i++) { + digitalWrite(blueLED, LOW); + delay(symbolLength); + + if (mySymbols[i] == _____) { + digitalWrite(_____, _____); + tone(piezo, _____); + delay(_____); + digitalWrite(_____, _____); + } else if (_____ == DASH) { + digitalWrite(_____, _____); + tone(_____, _____); + delay(_____); + digitalWrite(_____, _____); + } else if (mySymbols[i] == _____) { + digitalWrite(_____, _____); + delay(_____); + } + } + prevPlayButtonState = HIGH; + } + } else { + prevPlayButtonState = LOW; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage1/PersonalTrainer_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage1/PersonalTrainer_Stage1.ino new file mode 100644 index 00000000..7d753a84 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage1/PersonalTrainer_Stage1.ino @@ -0,0 +1,34 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 1 in PERSONAL TRAINER of the CTC GO! core module +*/ + + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; + +void setup() { + + pinMode(ledCounter_1, _____); + pinMode(ledCounter_2, _____); + pinMode(ledCounter_3, _____); +} + +void loop() { + + digitalWrite(ledCounter_1, _____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + delay(100); + digitalWrite(ledCounter_1, _____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + delay(100); + digitalWrite(ledCounter_1, _____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage2/PersonalTrainer_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage2/PersonalTrainer_Stage2.ino new file mode 100644 index 00000000..c72a5ff9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage2/PersonalTrainer_Stage2.ino @@ -0,0 +1,45 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 2 in PERSONAL TRAINER of the CTC GO! core module +*/ + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; +int distanceSensor = A0; + +int distanceSensorValue; +int currentDistanceMM = 0; +int lastDistance = 0; + +void setup() { + pinMode(ledCounter_1, OUTPUT); + pinMode(ledCounter_2, OUTPUT); + pinMode(ledCounter_3, OUTPUT); + + Serial.begin(_____); +} + +void loop() { + + digitalWrite(ledCounter_1, HIGH); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, HIGH); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, HIGH); + delay(100); + + distanceSensorValue = analogRead(_____); + currentDistanceMM = map(_____, _____, _____, 0, 3000); + Serial.println(_____); + + lastDistance = currentDistanceMM; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage3/PersonalTrainer_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage3/PersonalTrainer_Stage3.ino new file mode 100644 index 00000000..2581cd37 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage3/PersonalTrainer_Stage3.ino @@ -0,0 +1,66 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 3 in PERSONAL TRAINER of the CTC GO! core module +*/ + + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; +int distanceSensor = A0; +int incrementButton = 8; + +int distanceSensorValue; +int currentDistanceMM = 0; +int lastDistance = 0; + +int incrementButtonState = LOW; +int lastIncrementButtonState = LOW; +int stepCounter = 30; + +void setup() { + + pinMode(ledCounter_1, OUTPUT); + pinMode(ledCounter_2, OUTPUT); + pinMode(ledCounter_3, OUTPUT); + pinMode(incrementButton, INPUT); + Serial.begin(9600); +} + +void loop() { + + digitalWrite(ledCounter_1, HIGH); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, HIGH); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, HIGH); + delay(100); + + distanceSensorValue = analogRead(distanceSensor); + currentDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + //Serial.println(currentDistanceMM); + + incrementButtonState = digitalRead(_____); + + if (_____ == HIGH && lastIncrementButtonState == _____) { + if (_____) { + Serial.println("increase the stepCounter by 10"); + stepCounter += _____; + } else { + stepCounter = _____; + } + Serial.print("stepCounter is "); + Serial.println(stepCounter); + } + lastIncrementButtonState = incrementButtonState; + + lastDistance = currentDistanceMM; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage4/PersonalTrainer_Stage4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage4/PersonalTrainer_Stage4.ino new file mode 100644 index 00000000..21aab204 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage4/PersonalTrainer_Stage4.ino @@ -0,0 +1,110 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 4 in PERSONAL TRAINER of the CTC GO! core module +*/ + + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; +int distanceSensor = A0; +int incrementButton = 8; +int piezo = 6; + +int distanceSensorValue; +int currentDistanceMM = 0; +int lastDistance = 0; + +int incrementButtonState = LOW; +int lastIncrementButtonState = LOW; +int stepCounter = 30; + +int freq_1 = 1000; +int freq_2 = 1500; + +void setup() { + + pinMode(ledCounter_1, OUTPUT); + pinMode(ledCounter_2, OUTPUT); + pinMode(ledCounter_3, OUTPUT); + pinMode(incrementButton, INPUT); + pinMode(piezo, OUTPUT); + Serial.begin(9600); +} + +void loop() { + /* + digitalWrite(ledCounter_1,HIGH); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, HIGH); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, HIGH); + delay(100); + */ + + distanceSensorValue = analogRead(distanceSensor); + currentDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + //Serial.println(currentDistanceMM); + + incrementButtonState = digitalRead(incrementButton); + if (incrementButtonState == HIGH && lastIncrementButtonState == LOW) { + Serial.println("increase the stepCounter by 10"); + if (stepCounter < 30) { + stepCounter += 10; + //STEP 4; make a litte sound to indicate a button press + tone(piezo, freq_2); + delay(100); + noTone(piezo); + } else { + stepCounter = 10; + //STEP 4; make two sounds to indicate an overflow + tone(piezo, freq_1); + delay(100); + noTone(piezo); + delay(100); + tone(piezo, freq_1); + delay(100); + noTone(piezo); + } + Serial.print("stepCounter is "); + Serial.println(stepCounter); + } + lastIncrementButtonState = incrementButtonState; + + if (lastDistance > 200 && currentDistanceMM < 200) { + Serial.println("decrease the stepCounter with one"); + stepCounter = stepCounter - 1; + Serial.print("stepCounter is "); + Serial.println(_____); + digitalWrite(ledCounter_1, _____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + tone(piezo, freq_2); + delay(100); + noTone(piezo); + delay(100); + } + + digitalWrite(ledCounter_1, _____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + if (stepCounter > 0) { + digitalWrite(ledCounter_1, _____); + } + if (stepCounter > 10) { + digitalWrite(ledCounter_2, _____); + } + if (stepCounter > 20) { + digitalWrite(ledCounter_3, _____); + } + + lastDistance = currentDistanceMM; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage5/PersonalTrainer_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage5/PersonalTrainer_Stage5.ino new file mode 100644 index 00000000..fc190d9b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage5/PersonalTrainer_Stage5.ino @@ -0,0 +1,109 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 5 in PERSONAL TRAINER of the CTC GO! core module +*/ + + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; +int distanceSensor = A0; +int incrementButton = 8; +int piezo = 6; + +int currentDistanceMM = 0; +int distanceSensorValue; +int lastDistance = 0; + +int incrementButtonState = LOW; +int lastIncrementButtonState = LOW; +int stepCounter = 30; + +int freq_1 = 1000; +int freq_2 = 1500; +int freq_3 = 2000; + +void setup() { + + pinMode(ledCounter_1, OUTPUT); + pinMode(ledCounter_2, OUTPUT); + pinMode(ledCounter_3, OUTPUT); + pinMode(incrementButton, INPUT); + pinMode(piezo, OUTPUT); + + Serial.begin(9600); +} + +void loop() { + + distanceSensorValue = analogRead(distanceSensor); + currentDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + + incrementButtonState = digitalRead(incrementButton); + if (incrementButtonState == HIGH && lastIncrementButtonState == LOW) { + Serial.println("increase the stepCounter by 10"); + if (stepCounter < 30) { + stepCounter = stepCounter + 10; + tone(piezo, freq_2); + delay(100); + noTone(piezo); + } else { + stepCounter = 10; + tone(piezo, freq_1); + delay(100); + noTone(piezo); + delay(100); + tone(piezo, freq_1); + delay(100); + noTone(piezo); + } + Serial.print("stepCounter is "); + Serial.println(stepCounter); + } + lastIncrementButtonState = incrementButtonState; + + if (lastDistance > 200 && currentDistanceMM < 200) { + Serial.println("decrease the stepCounter with one"); + stepCounter = stepCounter - 1; + Serial.print("stepCounter is "); + Serial.println(stepCounter); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + tone(piezo, freq_2); + delay(100); + noTone(piezo); + delay(100); + } + + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + + if (stepCounter <= 0) { + Serial.println("Woopwoop, you succeeded"); + tone(piezo, _____); + delay(100); + noTone(_____); + delay(100); + tone(piezo, _____); + delay(200); + noTone(_____); + digitalWrite(_____, _____); + digitalWrite(_____, _____); + digitalWrite(_____, _____); + } else { + if (stepCounter > 0) { + digitalWrite(ledCounter_1, HIGH); + } + if (stepCounter > 10) { + digitalWrite(ledCounter_2, HIGH); + } + if (stepCounter > 20) { + digitalWrite(ledCounter_3, HIGH); + } + } + lastDistance = currentDistanceMM; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage1/Pinball_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage1/Pinball_Stage1.ino new file mode 100644 index 00000000..4d1c52fe --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage1/Pinball_Stage1.ino @@ -0,0 +1,31 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 1 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; + +void setup() { + pinMode(blueLED_1, _____); + pinMode(blueLED_2, _____); + pinMode(redLED, _____); + pinMode(greenLED, _____); +} + +void loop() { + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2, _____); + digitalWrite(redLED, _____); + digitalWrite(greenLED, _____); + delay(1000); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2, LOW); + digitalWrite(redLED, LOW); + digitalWrite(greenLED, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage2/Pinball_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage2/Pinball_Stage2.ino new file mode 100644 index 00000000..7f6b7660 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage2/Pinball_Stage2.ino @@ -0,0 +1,53 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 2 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; + +int button_1 = 7; +int button_2 = 6; + +void setup() { + pinMode(blueLED_1, OUTPUT); + pinMode(blueLED_2, OUTPUT); + pinMode(redLED, OUTPUT); + pinMode(greenLED, OUTPUT); + + pinMode(button_1, _____); + pinMode(button_2, _____); +} + +void loop() { + + /* + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2,HIGH); + digitalWrite(redLED,HIGH); + digitalWrite(greenLED,HIGH); + delay(1000); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2,LOW); + digitalWrite(redLED,LOW); + digitalWrite(greenLED,LOW); + delay(1000); + */ + + if (digitalRead(button_1) == _____) { + digitalWrite(greenLED, _____); + delay(_____); + } + + if (digitalRead(_____) == _____) { + digitalWrite(blueLED_1, _____); + delay(_____); + } + + digitalWrite(blueLED_1, _____); + digitalWrite(greenLED, _____); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage3/Pinball_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage3/Pinball_Stage3.ino new file mode 100644 index 00000000..449bcc5f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage3/Pinball_Stage3.ino @@ -0,0 +1,56 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 3 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; +int button_1 = 7; +int button_2 = 6; + +int losing = 0; +int winning = 0; + +void setup() { + pinMode(blueLED_1, OUTPUT); + pinMode(blueLED_2, OUTPUT); + pinMode(redLED, OUTPUT); + pinMode(greenLED, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); +} + +void loop() { + + if (digitalRead(button_1) == HIGH) { + digitalWrite(greenLED, HIGH); + winning = _____; + delay(_____); + } + + if (digitalRead(button_2) == HIGH) { + digitalWrite(blueLED_1, HIGH); + losing = _____; + delay(_____); + } + + digitalWrite(blueLED_1, LOW); + digitalWrite(greenLED, LOW); + + if (losing == _____ && winning == _____) { + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2, HIGH); + digitalWrite(redLED, HIGH); + digitalWrite(greenLED, HIGH); + delay(1000); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2, LOW); + digitalWrite(redLED, LOW); + digitalWrite(greenLED, LOW); + delay(1000); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage4/Pinball_Stage4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage4/Pinball_Stage4.ino new file mode 100644 index 00000000..f1c51264 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage4/Pinball_Stage4.ino @@ -0,0 +1,84 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 4 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; + +int button_1 = 7; +int button_2 = 6; + +int losing = 0; +int winning = 0; + +void setup() { + pinMode(blueLED_1, OUTPUT); + pinMode(blueLED_2, OUTPUT); + pinMode(redLED, OUTPUT); + pinMode(greenLED, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); +} + +void loop() { + + + if (digitalRead(button_1) == HIGH) { + winning = 1; + delay(2000); + } + + if (digitalRead(button_2) == HIGH) { + losing = losing + 1; + delay(2000); + } + + if (losing == 0 && winning == 0) { + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2, HIGH); + digitalWrite(redLED, HIGH); + digitalWrite(greenLED, HIGH); + delay(1000); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2, LOW); + digitalWrite(redLED, LOW); + digitalWrite(greenLED, LOW); + delay(1000); + } + + else if (losing == 1) { + digitalWrite(_____, _____); + delay(1500); + } else if (losing == 2) { + digitalWrite(_____, _____); + delay(1500); + } else if (losing == 3) { + digitalWrite(redLED, HIGH); + digitalWrite(greenLED, LOW); + delay(_____); + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2, _____); + digitalWrite(redLED, _____); + delay(_____); + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2, _____); + digitalWrite(redLED, _____); + delay(_____); + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2, _____); + digitalWrite(redLED, _____); + delay(_____); + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2, _____); + digitalWrite(redLED, _____); + delay(_____); + + losing = _____; + winning = _____; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage5/Pinball_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage5/Pinball_Stage5.ino new file mode 100644 index 00000000..b0a5b8b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage5/Pinball_Stage5.ino @@ -0,0 +1,100 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 5 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; + +int button_1 = 7; +int button_2 = 6; + +int losing = 0; +int winning = 0; + +void setup() { + pinMode(blueLED_1, OUTPUT); + pinMode(blueLED_2, OUTPUT); + pinMode(redLED, OUTPUT); + pinMode(greenLED, OUTPUT); + + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); +} + +void loop() { + + if (digitalRead(button_1) == HIGH) { + winning = 1; + delay(2000); + } + + if (digitalRead(button_2) == HIGH) { + losing = losing + 1; + delay(2000); + } + + if (losing == 0 && winning == 0) { + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2, HIGH); + digitalWrite(redLED, HIGH); + digitalWrite(greenLED, HIGH); + delay(1000); + ddigitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2, LOW); + digitalWrite(redLED, LOW); + digitalWrite(greenLED, LOW); + delay(1000); + } else if (losing == 1) { + digitalWrite(blueLED_1, HIGH); + delay(1500); + } else if (losing == 2) { + digitalWrite(blueLED_2, HIGH); + delay(1500); + } else if (losing == 3) { + digitalWrite(redLED, HIGH); + digitalWrite(greenLED, LOW); + delay(200); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2, LOW); + digitalWrite(redLED, LOW); + delay(200); + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2, HIGH); + digitalWrite(redLED, HIGH); + delay(200); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2, LOW); + digitalWrite(redLED, LOW); + delay(200); + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2, HIGH); + digitalWrite(redLED, HIGH); + delay(3000); + + losing = 0; + winning = 0; + } + + if (_____) { + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(3000); + + winning = _____; + losing = _____; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage1/React_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage1/React_Stage1.ino new file mode 100644 index 00000000..61756518 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage1/React_Stage1.ino @@ -0,0 +1,32 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 1 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; + + +void setup() { + pinMode(blueLED_P1, _____); + pinMode(blueLED_P2, _____); + pinMode(greenLED, _____); + pinMode(redLED, _____); +} + +void loop() { + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED, _____); + digitalWrite(redLED, _____); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage2/React_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage2/React_Stage2.ino new file mode 100644 index 00000000..b0ddac21 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage2/React_Stage2.ino @@ -0,0 +1,54 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 2 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; +int button_P1 = 2; +int button_P2 = 3; + +void setup() { + + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED, OUTPUT); + pinMode(redLED, OUTPUT); + + pinMode(button_P1, _____); + pinMode(button_P2, _____); +} + +void loop() { + /* + //STEP 1; check if the LEDs are working + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); + */ + + if (digitalRead(button_P1) == _____) { + digitalWrite(blueLED_P1, _____); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + } + + if (digitalRead(button_P2) == _____) { + digitalWrite(blueLED_P2, _____); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage3/React_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage3/React_Stage3.ino new file mode 100644 index 00000000..069d36b1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage3/React_Stage3.ino @@ -0,0 +1,75 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 3 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; + +int button_P1 = 2; +int button_P2 = 3; + +int game = 0; + +void setup() { + + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED, OUTPUT); + pinMode(redLED, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() { + + if (game == _____) { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); + + if (digitalRead(button_P1) == _____ || digitalRead(button_P2) == _____) { + game += 1; + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(_____); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(_____); + } + } + + if (game == _____) { + if (digitalRead(button_P1) == HIGH) { + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + game = _____; + } + + if (digitalRead(button_P2) == HIGH) { + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + game = _____; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage4/React_Stage4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage4/React_Stage4.ino new file mode 100644 index 00000000..70d3f8c0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage4/React_Stage4.ino @@ -0,0 +1,95 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 4 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; + +int button_P1 = 2; +int button_P2 = 3; + +int game = 0; +int level = 300; +int gameSpeed = 0; + +void setup() { + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED, OUTPUT); + pinMode(redLED, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() { + + if (game == 0) { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); + + + if (digitalRead(button_P1) == HIGH || digitalRead(button_P2) == HIGH) { + game += 1; + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(3000); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(1000); + } + } + + if (game == 1) { + + digitalWrite(redLED, _____); + digitalWrite(greenLED, _____); + delay(level); + + if (digitalRead(button_P1) == HIGH) { + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + game = 0; + } + + if (digitalRead(button_P2) == HIGH) { + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + game = 0; + } + + digitalWrite(greenLED, _____); + digitalWrite(redLED, _____); + gameSpeed = random(_____, _____); + delay(gameSpeed); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage5/React_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage5/React_Stage5.ino new file mode 100644 index 00000000..39cbdbb8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage5/React_Stage5.ino @@ -0,0 +1,150 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 5 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; + +int button_P1 = 2; +int button_P2 = 3; + +int game = 0; + +int level = 300; +int gameSpeed = 0; +int win_P1 = 0; +int win_P2 = 0; + +void setup() { + + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED, OUTPUT); + pinMode(redLED, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() { + + if (game == 0) { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); + + if (digitalRead(button_P1) == HIGH || digitalRead(button_P2) == HIGH) { + game += 1; + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(3000); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(1000); + } + } + + if (game == 1) { + digitalWrite(redLED, LOW); + digitalWrite(greenLED, HIGH); + + delay(level); + + if (digitalRead(button_P1) == HIGH) { + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + win_P1 += _____; + } + + if (digitalRead(button_P2) == HIGH) { + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + win_P2 += _____; + } + + digitalWrite(greenLED, LOW); + digitalWrite(redLED, HIGH); + + if (win_P1 == 5) { + digitalWrite(redLED, LOW); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(2000); + win_P1 = 0; + win_P2 = 0; + game = 0; + } + + //STEP 5; Code to show the victory of player 2 + if (win_P2 == _____) { + digitalWrite(redLED, LOW); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(2000); + win_P1 = 0; + win_P2 = 0; + game = 0; + } + + gameSpeed = random(1000, 5000); + delay(gameSpeed); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage1/WhackAMole_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage1/WhackAMole_Stage1.ino new file mode 100644 index 00000000..8f56e04f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage1/WhackAMole_Stage1.ino @@ -0,0 +1,35 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 1 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; + +void setup() { + pinMode(loseLED, _____); + pinMode(winLED, _____); + pinMode(yellowLED_1, _____); + pinMode(yellowLED_2, _____); + pinMode(yellowLED_3, _____); +} + +void loop() { + digitalWrite(loseLED, _____); + digitalWrite(winLED, _____); + digitalWrite(yellowLED_1, _____); + digitalWrite(yellowLED_2, _____); + digitalWrite(yellowLED_3, _____); + delay(1000); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage2/WhackAMole_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage2/WhackAMole_Stage2.ino new file mode 100644 index 00000000..392c3ea2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage2/WhackAMole_Stage2.ino @@ -0,0 +1,58 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 2 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +void setup() { + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + + pinMode(button_1, _____); + pinMode(button_2, _____); + pinMode(button_3, _____); +} + +void loop() { + /* + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(1000); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(1000); + */ + + if (digitalRead(button_1) == _____) { + digitalWrite(yellowLED_1, _____); + } else if (digitalRead(button_2) == _____) { + digitalWrite(yellowLED_2, _____); + } else if (digitalRead(button_3) == _____) { + digitalWrite(yellowLED_3, _____); + } else { + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage3/WhackAMole_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage3/WhackAMole_Stage3.ino new file mode 100644 index 00000000..bb124335 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage3/WhackAMole_Stage3.ino @@ -0,0 +1,64 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 3 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +int startLevel = 500; +int gameStarted = 0; + +void setup() { + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + pinMode(button_3, INPUT); +} + +void loop() { + if (gameStarted == 0) { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(_____); + + if (digitalRead(button_1) == _____) { + gameStarted = 1; + } + } else if (gameStarted == 1) { + if (digitalRead(button_1) == _____) { + digitalWrite(yellowLED_1, HIGH); + } else if (digitalRead(button_2) == _____) { + digitalWrite(yellowLED_2, HIGH); + } else if (digitalRead(button_3) == HIGH) { + digitalWrite(yellowLED_3, HIGH); + } else { + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage4/WhackAMole_Stage4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage4/WhackAMole_Stage4.ino new file mode 100644 index 00000000..05fc5f8d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage4/WhackAMole_Stage4.ino @@ -0,0 +1,69 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 4 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +int startLevel = 500; +int gameStarted = 0; + +void setup() { + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + pinMode(button_3, INPUT); +} + +void loop() { + if (gameStarted == 0) { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(startLevel); + + if (digitalRead(button_1) == _____ || digitalRead(button_2) == HIGH _____ digitalRead(button_3) == _____) { + digitalWrite(loseLED, _____); + digitalWrite(winLED, _____); + gameStarted = 1; + delay(_____); + digitalWrite(loseLED, _____); + digitalWrite(winLED, _____); + } + } else if (gameStarted == 1) { + if (digitalRead(button_1) == HIGH) { + digitalWrite(yellowLED_1, HIGH); + } else if (digitalRead(button_2) == HIGH) { + digitalWrite(yellowLED_2, HIGH); + } else if (digitalRead(button_3) == HIGH) { + digitalWrite(yellowLED_3, HIGH); + } else { + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage5/WhackAMole_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage5/WhackAMole_Stage5.ino new file mode 100644 index 00000000..275f663c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage5/WhackAMole_Stage5.ino @@ -0,0 +1,80 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 5 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +int startLevel = 500; +int gameStarted = 0; +int blinkLED = 0; + +void setup() { + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + pinMode(button_3, INPUT); +} + +void loop() { + if (gameStarted == 0) { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(startLevel); + + if (digitalRead(button_1) == HIGH || digitalRead(button_2) == HIGH || digitalRead(button_3) == HIGH) { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + gameStarted = 1; + delay(2000); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + } + } else if (gameStarted == 1) { + blinkLED = random(_____, _____); + + if (blinkLED == _____) { + digitalWrite(yellowLED_1, HIGH); + delay(startLevel); + } + + if (blinkLED == _____) { + digitalWrite(yellowLED_2, HIGH); + delay(startLevel); + } + + + if (blinkLED == _____) { + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + } + } + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(_____); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage6/WhackAMole_Stage6.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage6/WhackAMole_Stage6.ino new file mode 100644 index 00000000..b1965076 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage6/WhackAMole_Stage6.ino @@ -0,0 +1,125 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 6 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +int startLevel = 500; +int gameStarted = 0; +int blinkLED = 0; +int level = 0; + +void setup() { + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + pinMode(button_3, INPUT); +} + +void loop() { + if (gameStarted == 0) { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(startLevel); + + if (digitalRead(button_1) == HIGH || digitalRead(button_2) == HIGH || digitalRead(button_3) == HIGH) { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + + gameStarted = 1; + delay(2000); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + } + + + } else if (gameStarted == 1) { + + blinkLED = random(1, 4); + + if (blinkLED == 1) { + digitalWrite(yellowLED_1, HIGH); + delay(startLevel - level); + + if (digitalRead(button_2) == _____ || digitalRead(button_3) == _____) { + digitalWrite(loseLED, HIGH); + delay(2000); + gameStarted = _____; + } + + else if (digitalRead(button_1) == _____) { + digitalWrite(winLED, HIGH); + delay(_____); + level = level + 5; + } + } + + if (blinkLED == 2) { + digitalWrite(yellowLED_2, HIGH); + delay(startLevel - _____); + + + if (digitalRead(button_1) == _____ || digitalRead(button_3) == _____) { + digitalWrite(loseLED, HIGH); + delay(2000); + gameStarted = _____; + } + + else if (digitalRead(button_2) == _____) { + digitalWrite(winLED, HIGH); + delay(_____); + level = level + 5; + } + } + + + if (blinkLED == 3) { + digitalWrite(yellowLED_3, HIGH); + delay(startLevel - _____); + + if (digitalRead(button_1) == _____ || digitalRead(button_2) == _____) { + digitalWrite(loseLED, HIGH); + delay(2000); + gameStarted = _____; + } + + else if (digitalRead(button_3) == _____) { + digitalWrite(winLED, HIGH); + delay(_____); + level = level + 5; + } + } + } + if (level >= startLevel) { + level = startLevel; + } + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(startLevel - _____); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/README.md new file mode 100644 index 00000000..404eb569 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/README.md @@ -0,0 +1,2 @@ +# CTC-Go-Motions-Expansion +CTC GO MOTIONS EXPANSION - the repository for the motions expansion pack to Arduino's CTC Go educational programmes diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity1/MakingThingsMove_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity1/MakingThingsMove_Activity1.ino new file mode 100644 index 00000000..b798aad7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity1/MakingThingsMove_Activity1.ino @@ -0,0 +1,33 @@ +/* + CTC GO! MOTION + LESSON 01 - Making Things Move + + This sketch is written to accompany activity 1 of Lesson 1 +*/ + +#include + +Servo servo_Standard; + +int pos = 0; + +void setup() { + servo_Standard.attach(9); + + Serial.begin(9600); +} + +void loop() { + for (pos = 0; pos <= 180; pos += 1) { + servo_Standard.write(pos); + Serial.print("Shaft position: "); + Serial.println(pos); + delay(50); + } + for (pos = 180; pos >= 0; pos -= 1) { + servo_Standard.write(pos); + Serial.print("Shaft position: "); + Serial.println(pos); + delay(50); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity2/MakingThingsMove_Activity2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity2/MakingThingsMove_Activity2.ino new file mode 100644 index 00000000..b3616644 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity2/MakingThingsMove_Activity2.ino @@ -0,0 +1,32 @@ +/* + CTC GO! MOTION + LESSON 01 - Making Things Move + + This sketch is written to accompany activity 2 of Lesson 1 +*/ + + +#include + +Servo servo_Standard; + +int potPin = A0; + +int potValue = 0; +int pos = 0; + +void setup() { + servo_Standard.attach(9); + + Serial.begin(9600); +} + +void loop() { + potValue = analogRead(potPin); + pos = map(potValue, 0, 1023, 0, 180); + + servo_Standard.write(pos); + delay(15); + Serial.print("Shaft position: "); + Serial.println(pos); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity3/MakingThingsMove_Activity3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity3/MakingThingsMove_Activity3.ino new file mode 100644 index 00000000..cf93b228 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity3/MakingThingsMove_Activity3.ino @@ -0,0 +1,41 @@ +/* + CTC GO! MOTION + LESSON 01 - Making Things Move + + This sketch is written to accompany activity 3 of Lesson 1 +*/ + +#include + +Servo servo_Standard; + +int USsensor = A0; + +int USvalue = 0; +int distance = 0; +int triggerDistance = 500; + +void setup() { + servo_Standard.attach(9); + + Serial.begin(9600); +} + +void loop() { + USvalue = analogRead(USsensor); + distance = USvalue * 3; + distance = map(distance, 0, 1023, 0, 3000); + + Serial.print("Distance to the object (mm): "); + Serial.println(distance); + + if (distance <= triggerDistance) { + servo_Standard.write(90); + delay(5000); + Serial.print("Door opened"); + } else { + servo_Standard.write(0); + delay(15); + Serial.print("Door closed"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity1/CircularToLinearMovement_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity1/CircularToLinearMovement_Activity1.ino new file mode 100644 index 00000000..995ebaab --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity1/CircularToLinearMovement_Activity1.ino @@ -0,0 +1,35 @@ +/* + CTC GO! MOTION + LESSON 02 - Circular To Linear Movement + + This sketch is written to accompany activity 1 of Lesson 2 +*/ + +#include + +Servo servo_Standard; + +int potPin = A0; + +int pos = 0; +int potValue = 0; + +int max_pos = 180; +int min_pos = 0; + +void setup() { + servo_Standard.attach(6); + + Serial.begin(9600); +} + +void loop() { + potValue = analogRead(potPin); + + pos = map(potValue, 0, 1023, min_pos, max_pos); + + servo_Standard.write(pos); + Serial.print("Shaft position: "); + Serial.println(pos); + delay(15); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity2/CircularToLinearMovement_Activity2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity2/CircularToLinearMovement_Activity2.ino new file mode 100644 index 00000000..e278eed4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity2/CircularToLinearMovement_Activity2.ino @@ -0,0 +1,69 @@ + +/* + CTC GO! MOTION + LESSON 02 - Circular To Linear Movement + + This sketch is written to accompany activity 2 of Lesson 2 +*/ + +#include + +Servo servo_Standard; + +int photo = A0; +int piezo = 3; + +bool open = true; +bool closed = false; + +int light = 0; +int trigger = 400; +int open_pos = 30; +int closed_pos = 125; +int closed_tone = 250; +int open_tone = 1500; + +void setup() { + servo_Standard.attach(9); + pinMode(piezo, OUTPUT); +} + +void loop() { + light = analogRead(A0); + + if (light <= trigger) { + servo_Standard.write(closed_pos); + delay(400); + sounds(closed); + } else { + servo_Standard.write(open_pos); + delay(400); + sounds(open); + } +} + + +void sounds(bool state) { + static bool prev_state = open; + + if (state != prev_state) { + if (state == true) { + for (int i = 0; i < 2; i++) { + tone(piezo, open_tone); + delay(50); + noTone(piezo); + delay(50); + } + } else { + for (int i = 0; i < 2; i++) { + tone(piezo, closed_tone); + delay(50); + noTone(piezo); + delay(50); + } + } + } else { + noTone(piezo); + } + prev_state = state; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity1/ContinuousRotation_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity1/ContinuousRotation_Activity1.ino new file mode 100644 index 00000000..412e155e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity1/ContinuousRotation_Activity1.ino @@ -0,0 +1,32 @@ +/* + CTC GO! MOTION + LESSON 03 - Continuous Rotation + + This sketch is written to accompany activity 1 of Lesson 3 +*/ + +#include + +Servo servo_Cont; + +int pos = 0; + +void setup() { + servo_Cont.attach(9); + Serial.begin(9600); +} + +void loop() { + for (pos = 0; pos <= 180; pos += 1) { + servo_Cont.write(pos); + Serial.print("Position value: "); + Serial.println(pos); + delay(0); + } + for (pos = 180; pos >= 0; pos -= 1) { + servo_Cont.write(pos); + Serial.print("Position value: "); + Serial.println(pos); + delay(0); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity2/ContinuousRotation_Activity2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity2/ContinuousRotation_Activity2.ino new file mode 100644 index 00000000..19410607 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity2/ContinuousRotation_Activity2.ino @@ -0,0 +1,30 @@ +/* + CTC GO! MOTION + LESSON 03 - Continuous Rotation + + This sketch is written to accompany activity 2 of Lesson 3 +*/ + +#include + +Servo servo_Cont; + +int potPin = A0; + +int potValue = 0; +int vel = 0; + +void setup() { + servo_Cont.attach(9); + Serial.begin(9600); +} + +void loop() { + potValue = analogRead(potPin); + vel = map(potValue, 0, 1023, 0, 180); + + servo_Cont.write(vel); + delay(15); + Serial.print("Shaft spee: "); + Serial.println(vel); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity3/ContinuousRotation_Activity3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity3/ContinuousRotation_Activity3.ino new file mode 100644 index 00000000..2fa716af --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity3/ContinuousRotation_Activity3.ino @@ -0,0 +1,50 @@ +/* + CTC GO! MOTION + LESSON 03 - Continuous Rotation + + This sketch is written to accompany activity 3 of Lesson 3 +*/ + +#include + +Servo servo_Cont; + +int USsensor = A0; + +int USvalue = 0; +int distance = 0; +int speed = 0; + +void setup() { + servo_Cont.attach(9); + Serial.begin(9600); +} + +void loop() { + USvalue = analogRead(USsensor); + distance = map(USvalue, 0, 1023, 0, 3000); + + Serial.print("Distance: "); + Serial.println(distance); + + if (distance < 150) { + servo_Cont.write(135); + Serial.print("Object too close to the sensor"); + } else if (distance >= 150 && distance <= 200) { + servo_Cont.write(90); + Serial.print("Object in the targeted position"); + } else if (distance > 200 && distance <= 350) { + servo_Cont.write(80); + Serial.print("Third speed control range"); + } else if (distance > 350 && distance <= 500) { + servo_Cont.write(50); + Serial.print("Second speed control range"); + } + + else { + servo_Cont.write(0); + Serial.print("Full speed range"); + } + + delay(250); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/04_GearsAndPulleys/GearsAndPulleys_Activity1/GearsAndPulleys_Activity1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/04_GearsAndPulleys/GearsAndPulleys_Activity1/GearsAndPulleys_Activity1.ino new file mode 100644 index 00000000..7de605ab --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/04_GearsAndPulleys/GearsAndPulleys_Activity1/GearsAndPulleys_Activity1.ino @@ -0,0 +1,60 @@ +/* + CTC GO! MOTION + LESSON 04 - Gears and Pulleys + + This sketch is written to accompany activity 1 of Lesson 4 +*/ + +#include + +Servo waterServo; + +int button1 = 2; +int button2 = 3; + +int waterLevel = 0; +int b1_state = 0; +int b2_state = 0; + +void setup() { + waterServo.attach(9); + + Serial.begin(9600); +} + +void loop() { + b1_state = digitalRead(button1); + b2_state = digitalRead(button2); + + if (b1_state == 1 && b2_state == 1) { + waterLevel = 100; + } else if (b1_state == 1 && b2_state == 0) { + waterLevel = 60; + } else if (b1_state == 0 && b2_state == 1) { + waterLevel = 30; + } else { + waterLevel = 0; + } + + switch (waterLevel) { + case 100: + waterServo.write(180); + Serial.println("Water level 100%"); + break; + + case 60: + waterServo.write(110); + Serial.println("Water level 60%"); + break; + + case 30: + waterServo.write(100); + Serial.println("Water level 30%"); + break; + + default: + waterServo.write(90); + Serial.println("Water level 0%"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage1/rockPaperScissor_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage1/rockPaperScissor_Stage1.ino new file mode 100644 index 00000000..323b956b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage1/rockPaperScissor_Stage1.ino @@ -0,0 +1,34 @@ +/* + CTC GO! MOTION + PROJECT - ROCK PAPER SCISSOR + + This sketch is written to accompany Stage 1 of the ROCK PAPER SCISSOR project +*/ + +int piezo = 8; +int USsensor = A0; + +int USvalue = 0; +float distance = 0; + + +void setup() { + ______(piezo, ______); + Serial.begin(9600); +} + +void loop() { + USvalue = ______(______); + distance = ______ * 3; + + Serial.print("Distance to object: "); + Serial.println(______); + + if (______ < 400) { + tone(______, 500); + delay(100); + noTone(______); + } + + delay(250); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage2/rockPaperScissor_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage2/rockPaperScissor_Stage2.ino new file mode 100644 index 00000000..cacefbc4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage2/rockPaperScissor_Stage2.ino @@ -0,0 +1,65 @@ +/* + CTC GO! MOTION + PROJECT - ROCK PAPER SCISSOR + + This sketch is written to accompany Stage 2 of the ROCK PAPER SCISSOR project +*/ + +int redLED = 2; +int yellowLED = 3; +int greenLED = 4; +int piezo = 8; +int USsensor = A0; + +int USvalue = 0; +float distance = 0; +int check = 0; + +void setup() { + pinMode(piezo, OUTPUT); + + ______(redLED, ______); + ______(yellowLED, ______); + ______(greenLED, ______); + + Serial.begin(9600); +} + +void loop() { + USvalue = analogRead(USsensor); + distance = USvalue * 3; + + if (distance < 400) { + /*tone(piezo, 500); + delay(100); + noTone(piezo);*/ + + ______++; + delay(400); + Serial.println(______); + } + + if (check == 0) { + ____________(redLED, ______); + ____________(yellowLED, ______); + ____________(greenLED, ______); + } + + else if (check == 1) { + ______(redLED, ______); + } + + else if (check == 2) { + ____________(yellowLED, ______); + ____________(redLED, ______); + } + + else if (check == 3) { + ____________(greenLED, ______); + ____________(yellowLED, ______); + tone(piezo, 500); + delay(100); + noTone(piezo); + ______ = 0; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage3/rockPaperScissor_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage3/rockPaperScissor_Stage3.ino new file mode 100644 index 00000000..e328cb41 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage3/rockPaperScissor_Stage3.ino @@ -0,0 +1,112 @@ +/* + CTC GO! MOTION + PROJECT - ROCK PAPER SCISSOR + + This sketch is written to accompany Stage 3 of the ROCK PAPER SCISSOR project +*/ + +#include + +Servo servo_main; +Servo servo_wheel; + +int redLED = 2; +int yellowLED = 3; +int greenLED = 4; +int piezo = 11; +int USsensor = A0; + +int USvalue = 0; +float distance = 0; +int check = 0; +int randomNumber; + +void setup() { + pinMode(redLED, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(greenLED, OUTPUT); + + servo_main.______(6); + servo_wheel.______(9); + + servo_main.______(0); + delay(10); + + Serial.begin(9600); +} + +void loop() { + + USvalue = analogRead(USsensor); + distance = USvalue * 3; + + servo_wheel.______(80); + delay(10); + + if (distance < 400) { + check++; + delay(400); + Serial.println(check); + } + + if (check == 0) { + digitalWrite(redLED, LOW); + digitalWrite(yellowLED, LOW); + digitalWrite(greenLED, LOW); + } + + else if (check == 1) { + digitalWrite(redLED, HIGH); + } + + else if (check == 2) { + digitalWrite(yellowLED, HIGH); + digitalWrite(redLED, LOW); + } + + else if (check == 3) { + digitalWrite(greenLED, HIGH); + digitalWrite(yellowLED, LOW); + tone(piezo, 500); + delay(100); + noTone(piezo); + randomNumber = ______(1, 4); + delay(10); + Serial.println(randomNumber); + delay(100); + check = 0; + + switch (____________) { + case 1: + servo_main.______(0); + delay(1000); + servo_wheel.______(93); + delay(2000); + servo_main.______(0); + delay(2000); + break; + + case 2: + servo_main.______(80); + delay(1000); + servo_wheel.______(93); + delay(2000); + servo_main.______(0); + delay(2000); + break; + + case 3: + servo_main.______(160); + delay(1000); + servo_wheel.______(93); + delay(2000); + servo_main.______(0); + delay(2000); + break; + } + + ____________ = 0; + } + + delay(250); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage5/rockPaperScissor_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage5/rockPaperScissor_Stage5.ino new file mode 100644 index 00000000..6a4fda66 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage5/rockPaperScissor_Stage5.ino @@ -0,0 +1,111 @@ +/* + CTC GO! MOTION + PROJECT - ROCK PAPER SCISSOR + + This sketch is written to accompany Stage 5 of the ROCK PAPER SCISSOR project +*/ + +#include + +Servo servo_main; +Servo servo_wheel; + +int redLED = 2; +int yellowLED = 3; +int greenLED = 4; +int piezo = 8; +int USsensor = A0; + +int rock = 0; +int paper = 80; +int scissor = 160; + +int USvalue = 0; +float distance = 0; +int check = 0; +int randomNumber; + +void setup() { + pinMode(redLED, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(greenLED, OUTPUT); + + servo_main.attach(6); + servo_wheel.attach(9); + + servo_main.write(0); + delay(10); + + Serial.begin(9600); +} + +void loop() { + USvalue = analogRead(USsensor); + distance = USvalue * 3; + + servo_wheel.write(80); + delay(10); + + + if (distance < 400) { + check++; + delay(400); + } + + if (check == 0) { + digitalWrite(redLED, LOW); + digitalWrite(yellowLED, LOW); + digitalWrite(greenLED, LOW); + } + + else if (check == 1) { + digitalWrite(redLED, HIGH); + } + + else if (check == 2) { + digitalWrite(yellowLED, HIGH); + digitalWrite(redLED, LOW); + } + + else if (check == 3) { + digitalWrite(greenLED, HIGH); + digitalWrite(yellowLED, LOW); + tone(piezo, 500); + delay(100); + noTone(piezo); + randomNumber = random(1, 4); + Serial.println(randomNumber); + delay(100); + check = 0; + + switch (randomNumber) { + case 1: + ____________(rock); + break; + + case 2: + ____________(paper); + break; + + case 3: + ____________(scissor); + break; + } + + randomNumber = 0; + } + + delay(250); +} + +void ____________(int object) { + servo_main.write(______); + delay(1000); + + servo_wheel.write(95); + delay(2000); + + servo_main.write(0); + digitalWrite(greenLED, LOW); + delay(2000); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage1/spinAWheel_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage1/spinAWheel_Stage1.ino new file mode 100644 index 00000000..8cc02040 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage1/spinAWheel_Stage1.ino @@ -0,0 +1,22 @@ +/* CTC GO! MOTION PROJECT - Spin-A-Wheel This sketch is written to accompany Stage 1 of the Spin-a-Wheel project */ int button_1 = 2; +int button_2 = 3; +int buttonState_1; +int buttonState_2; +void setup() { + ______(button_1, ______); + ______(button_2, ______); + Serial.begin(9600); +} +void loop() { + buttonState_1 = ______(button_1); + buttonState_2 = ______(button_2); + if (____________ == HIGH) { + Serial.println("Button 1 pressed"); + delay(1000); + } + if (____________ == HIGH) { + Serial.println("Button 2 pressed"); + delay(1000); + } + delay(100); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage2/spinAWheel_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage2/spinAWheel_Stage2.ino new file mode 100644 index 00000000..e4dcd596 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage2/spinAWheel_Stage2.ino @@ -0,0 +1,52 @@ +/* + CTC GO! MOTION + PROJECT - Spin-A-Wheel + + This sketch is written to accompany Stage 2 of the Spin-a-Wheel project +*/ + +#include + +______ servo_wheel; +______ servo_pointer; + +int button_1 = 2; +int button_2 = 3; + +int buttonState_1; +int buttonState_2; + +void setup() { + + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + + servo_pointer.______(6); + servo_wheel.______(9); + + Serial.begin(9600); +} + +void loop() { + + buttonState_1 = digitalRead(button_1); + buttonState_2 = digitalRead(button_2); + + if (buttonState_1 == HIGH) { + Serial.println("Button 1 pressed"); + servo_pointer.______(30); + delay(10); + servo_wheel.______(30); + delay(1000); + } + + if (buttonState_2 == HIGH) { + Serial.println("Button 2 pressed"); + ______.______(70); + delay(10); + ______.______(93); + delay(1000); + } + + delay(100); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage3/spinAWheel_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage3/spinAWheel_Stage3.ino new file mode 100644 index 00000000..826d7f3f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage3/spinAWheel_Stage3.ino @@ -0,0 +1,66 @@ +/* + CTC GO! MOTION + PROJECT - Spin-A-Wheel + + This sketch is written to accompany Stage 3 of the Spin-a-Wheel project +*/ + +#include + +Servo servo_wheel; +Servo servo_pointer; + +int button_1 = 2; +int button_2 = 3; + +int yellowLED = 4; +int blueLED = 5; +int piezo = 8; + +int buttonState_1; +int buttonState_2; + +void setup() { + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + ______(yellowLED, ______); + ______(blueLED, ______); + ______(piezo, ______); + + servo_pointer.attach(6); + servo_wheel.attach(9); + + Serial.begin(9600); +} + + +void loop() { + buttonState_1 = digitalRead(button_1); + buttonState_2 = digitalRead(button_2); + + if (buttonState_1 == HIGH) { + Serial.println("Button 1 pressed"); + servo_pointer.write(30); + delay(10); + servo_wheel.write(30); + ______(blueLED, HIGH); + ______(yellowLED, LOW); + tone(______, ______); + delay(1000); + noTone(______); + } + + if (buttonState_2 == HIGH) { + Serial.println("Button 2 pressed"); + servo_pointer.write(70); + delay(10); + servo_wheel.write(93); + ______(blueLED, ______); + ______(yellowLED, ______); + tone(______, ______); + delay(1000); + noTone(______); + } + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage5/spinAWheel_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage5/spinAWheel_Stage5.ino new file mode 100644 index 00000000..f54985a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage5/spinAWheel_Stage5.ino @@ -0,0 +1,107 @@ +/* + CTC GO! MOTION + PROJECT - SPIN-A-WHEEL + + This sketch is written to accompany Stage 5 of the SPIN-A-WHEEL project +*/ + +#include + +Servo servo_wheel; +Servo servo_pointer; + +int button_1 = 2; +int button_2 = 3; +int yellowLED = 4; +int blueLED = 5; +int piezo = 8; + +int buttonState_1; +int buttonState_2; + +int counter; + +void setup() { + + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + + pinMode(yellowLED, OUTPUT); + pinMode(blueLED, OUTPUT); + + servo_pointer.attach(6); + servo_wheel.attach(9); + + Serial.begin(9600); +} + +void loop() { + + buttonState_1 = digitalRead(button_1); + buttonState_2 = digitalRead(button_2); + + if (buttonState_1 == HIGH) { + Serial.println("Button 1 pressed"); + servo_pointer.write(30); + delay(10); + servo_wheel.write(30); + delay(1000); + } + + if (buttonState_2 == HIGH) { + Serial.println("Button 2 pressed"); + servo_pointer.write(70); + delay(10); + servo_wheel.write(93); + delay(1000); + ____________(); + } +} + +void ____________() { + + ______++; + + if (counter <= 2) { + digitalWrite(yellowLED, HIGH); + digitalWrite(blueLED, LOW); + } + + else if (counter == 3) { + ______(); + counter++; + digitalWrite(blueLED, HIGH); + digitalWrite(yellowLED, LOW); + } + + else if (counter >= 4 && counter <= 6) { + digitalWrite(blueLED, HIGH); + digitalWrite(yellowLED, LOW); + } + + else if (counter == 7) { + ______(); + ______ = 0; + digitalWrite(blueLED, LOW); + digitalWrite(yellowLED, HIGH); + } + + delay(100); +} + +void ______() { + tone(______, 500); + delay(300); + ______(______); + delay(300); + + tone(______, 1200); + delay(500); + ______(______); + delay(300); + + tone(______, 200); + delay(700); + ______(______); + delay(300); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage1/waveGenerator_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage1/waveGenerator_Stage1.ino new file mode 100644 index 00000000..dc25481f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage1/waveGenerator_Stage1.ino @@ -0,0 +1,19 @@ +/* CTC GO! MOTION PROJECT - Wave Generator This sketch is written to accompany Stage 1 of the Wave Generator project */ int potPin = A0; +int lightSensor = A1; +int lightValue = 0; +int potValue = 0; +void setup() { + ______(9600); +} +void loop() { + _____ = analogRead(_____); + Serial._____("Light Value: "); + Serial.println(_____); + delay(20); + _____ = analogRead(____); + Serial._____("Pot Value: "); + Serial.println(_____); + delay(20); + Serial.println(" "); + delay(250); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage2/waveGenerator_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage2/waveGenerator_Stage2.ino new file mode 100644 index 00000000..48069b36 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage2/waveGenerator_Stage2.ino @@ -0,0 +1,28 @@ +/* CTC GO! MOTION PROJECT - Wave Generator This sketch is written to accompany Stage 2 of the Wave Generator project */ #include _____ servo_rotate; +_____ servo_arm; +int lightSensor = A1; +int potPin = A0; +int lightValue = 0; +int potValue = 0; +int new_potValue; +int new_lightValue; +void setup() { + servo_rotate._____(6); + servo_arm._____(9); + Serial.begin(9600); +} +void loop() { + lightValue = analogRead(lightSensor); + Serial.print("Light Value: "); + Serial.println(lightValue); + new_lightValue = map(lightValue, 100, 900, ____, _____); + servo_arm.____(____); + delay(20); + potValue = analogRead(potPin); + Serial.print("Pot Value: "); + Serial.println(potValue); + new_potValue = map(potValue, 0, 1023, ____, ____); + servo_rotate._____(____); + delay(20); + Serial.println(""); //delay(250); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage3/waveGenerator_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage3/waveGenerator_Stage3.ino new file mode 100644 index 00000000..9dbe7a20 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage3/waveGenerator_Stage3.ino @@ -0,0 +1,50 @@ +/* CTC GO! MOTION PROJECT - Wave Generator This sketch is written to accompany Stage 3 of the Wave Generator project */ #include Servo servo_rotate; +Servo servo_arm; +int button = 2; +int lightSensor = A1; +int potPin = A0; +int lightValue = 0; +int potValue = 0; +int new_potValue; +int new_lightValue; +int buttonState = LOW; +_____ previousState = LOW; +_____ isButtonPressed = false; +int modeCounter = 1; +void setup() { + pinMode(button, _____); + servo_rotate.attach(6); + servo_arm.attach(9); + Serial.begin(9600); +} +void loop() { + potValue = analogRead(potPin); + Serial.println(potValue); + new_potValue = map(potValue, 100, 900, 0, 180); + servo_rotate.write(new_potValue); + delay(20); + lightValue = analogRead(lightSensor); + Serial.println(lightValue); + new_lightValue = map(lightValue, 0, 1023, 0, 180); + servo_arm.write(new_lightValue); + delay(20); + Serial.println(""); //delay(250); + buttonState = digitalRead(_____); + if (prevButtonState != buttonState) { isButtonPressed = buttonState; } + if (isButtonPressed == true) { + updateModeCounter(); + isButtonPressed = false; + } + prevButtonState = buttonState; +} +void updateModeCounter() { + if (modeCounter < 2) { + modeCounter++; + Serial.println("Counter value : "); + Serial.println(modeCounter); + } else { + modeCounter = 1; + Serial.println("Counter value: "); + Serial.println(modeCounter); + } +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage5/waveGenerator_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage5/waveGenerator_Stage5.ino new file mode 100644 index 00000000..7b0fb1d7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage5/waveGenerator_Stage5.ino @@ -0,0 +1,66 @@ +/* CTC GO! MOTION PROJECT - Wave Generator This sketch is written to accompany Stage 5 of the Wave Generator project */ #include Servo servo_rotate; +Servo servo_arm; +int button = 2; +int potPin = A0; +int lightSensor = A1; +int potValue = 0; +int lightValue = 0; +int new_potValue; +int new_lightValue; +int timing_lightValue; +int buttonState = LOW; +int isButtonPressed = LOW; +boolean isButtonPressed = false; +int modeCounter = 1; +void setup() { + pinMode(button, INPUT); + servo_rotate.attach(6); + servo_arm.attach(9); + Serial.begin(9600); +} +void loop() { + potValue = analogRead(potPin); + Serial.println(potValue); + new_potValue = map(potValue, 0, 1023, 0, 180); + servo_rotate.write(new_potValue); + delay(20); + lightValue = analogRead(lightSensor); + Serial.println(lightValue); // new_lightValue = map(lightValue, 100, 900, 0, 180); // servo_arm.write(new_lightValue); // delay(20); + Serial.println(""); //delay(250); + buttonState = digitalRead(button); + if (prevButtonState != buttonState) { isButtonPressed = buttonState; } + if (isButtonPressed == true) { + updateModeCounter(); + isButtonPressed = false; + } + prevButtonState = buttonState; + switch (_____) { + case 1: + Serial.println("mode 1"); + _____; + break; + case 2: + Serial.println("mode 2"); + _____; + break; + } +} +void updateModeCounter() { + if (modeCounter < 2) { + modeCounter++; + } else { + modeCounter = 1; + } +} +void modeOne() { + new_lightValue = map(lightValue, 100, 900, 0, 180); + servo_arm.write(new_lightValue); + delay(20); +} +void modeTwo() { + timing_lightValue = map(_____, 100, 900, 0, 500); + servo_arm.write(10); + delay(_____); + servo_arm.write(70); + delay(____); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage1/Wiggler_Stage1.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage1/Wiggler_Stage1.ino new file mode 100644 index 00000000..4c1c5c7c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage1/Wiggler_Stage1.ino @@ -0,0 +1,16 @@ +/* CTC GO! MOTION PROJECT - Wiggler This sketch is written to accompany Stage 1 of the Wiggler project */ int lightSensor_1 = A0; +int lightSensor_2 = A1; +int lightValue_1 = 0; +int lightValue_2 = 0; +void setup() { + Serial.begin(9600); +} +void loop() { + lightValue_1 = ______(______); + lightValue_2 = ______(______); + Serial.print("First Light Value: "); + Serial.println(______); + Serial.print("Second Light Value: "); + Serial.println(______); + delay(1000); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage2/Wiggler_Stage2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage2/Wiggler_Stage2.ino new file mode 100644 index 00000000..7c7961b6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage2/Wiggler_Stage2.ino @@ -0,0 +1,24 @@ +/* CTC GO! MOTION PROJECT - Wiggler This sketch is written to accompany Stage 2 of the Wiggler project */ #include Servo servo_drive; +Servo servo_steer; +int lightSensor_1 = A0; +int lightSensor_2 = A1; +int lightValue_1 = 0; +int lightValue_2 = 0; +void setup() { + servo_steer.______(6); + servo_drive.____(9); + Serial.begin(9600); +} +void loop() { + lightValue_1 = analogRead(lightSensor_1); + lightValue_2 = analogRead(lightSensor_2); + Serial.print("First Light Value: "); + Serial.println(lightValue_1); + Serial.print("Second Light Value: "); + Serial.println(lightValue_2); + servo_drive.______(120); + servo_steer.______(30); + delay(500); + servo_steer.______(150); + delay(500); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage3/Wiggler_Stage3.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage3/Wiggler_Stage3.ino new file mode 100644 index 00000000..dae12f3f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage3/Wiggler_Stage3.ino @@ -0,0 +1,50 @@ +/* + CTC GO! MOTION + PROJECT - Wiggler + + This sketch is written to accompany Stage 3 of the Wiggler project +*/ + +#include + +Servo servo_drive; +Servo servo_steer; + +int lightSensor_1 = A0; +int lightSensor_2 = A1; + +int lightValue_1 = 0; +int lightValue_2 = 0; + +void setup() { + servo_steer.attach(6); + servo_drive.attach(9); + Serial.begin(9600); +} + +void loop() { + lightValue_1 = analogRead(lightSensor_1); + lightValue_2 = analogRead(lightSensor_2); + + Serial.print("First Light Value: "); + Serial.println(lightValue_1); + Serial.print("Second Light Value: "); + Serial.println(lightValue_2); + + + servo_drive.write(120); + servo_steer.write(90); + delay(15); + + if (______ >= 900) { + ______.write(60); + ______.write(30); + delay(3000); + } + + if (______ >= 900) { + ______.write(60); + ______.write(150); + delay(3000); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage5/Wiggler_Stage5.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage5/Wiggler_Stage5.ino new file mode 100644 index 00000000..5d59211f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage5/Wiggler_Stage5.ino @@ -0,0 +1,45 @@ +/* CTC GO! MOTION PROJECT - Wiggler This sketch is written to accompany Stage 5 of the Wiggler project */ #include Servo servo_drive; +Servo servo_steer; +int lightSensor_1 = A0; +int lightSensor_2 = A1; +int lightValue_1 = 0; +int lightValue_2 = 0; +int ______ = 30; +int ______ = 150; +void setup() { + servo_steer.attach(6); + servo_drive.attach(9); + Serial.begin(9600); +} +void loop() { + lightValue_1 = analogRead(lightSensor_1); + lightValue_2 = analogRead(lightSensor_2); + Serial.print("First Light Value: "); + Serial.println(lightValue_1); + Serial.print("Second Light Value: "); + Serial.println(lightValue_2); + servo_drive.write(120); + servo_steer.write(90); + delay(15); + if (lightValue_1 >= 900) { /*servo_drive.write(60); servo_steer.write(30); delay(3000); */ + ____________(right); + } + if (lightValue_2 >= 900) { /*servo_drive.write(60); servo_steer.write(150); delay(3000); */ + ____________(left); + } + if (lightValue_1 <= 50 && lightValue_2 <= 50) { ____________(); } + delay(100); +} +void ____________(int direction) { + servo_drive.write(60); + delay(10); + servo_steer.write(______); + delay(3000); + servo_steer.write(90); + delay(10); +} +void ____________() { + servo_drive.write(______); + servo_steer.write(______); + delay(5000); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/README.md new file mode 100644 index 00000000..bf1f7cbe --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/README.md @@ -0,0 +1,25 @@ +Education Shield for Arduino 101 +======== + +[![Check Arduino status](https://github.com/arduino-libraries/EducationShield/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/EducationShield/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/EducationShield/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/EducationShield/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/EducationShield/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/EducationShield/actions/workflows/spell-check.yml) + +The EducationShield library is intended to be used with the Education Shield provided in the CTC kit. It presents the necessary functions to interact with 3 and 4 pin connectors used in many sensors and actuators. Furthermore, it includes the functionality of SD-Card Reader and audio jack. + +![alt tag](references/images/EducationShield.jpg) + +CTC 101 Project +=========== + +CTC 101 is a modular STEAM program consisting of a toolbox with more than 25 projects and easy to assemble experiments, an online platform, and guided educators support. +The library is an educational project carried by Arduino LLC in Malmo. It is a collection of exercises commissioned by the Center of Resources for Education at Castilla La Mancha to be tried out in the classrooms during the Spring 2013. If you want to collaborate by adding translations to this collection of exercises, just send us a note to d.cuartielles AT arduino.cc. + +References +=========== +[Reference](references/) section which explains the functions and constants defined in the library. + +Credits +=========== + +X. Yang, M. Johansson, C. Leivas, T. Hansson, L. Balboa, K. Engdahl, T. Pham , A. Goransson , D. Cuartielles diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.1_blink/_2.1_blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.1_blink/_2.1_blink.ino new file mode 100644 index 00000000..54cd1d99 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.1_blink/_2.1_blink.ino @@ -0,0 +1,19 @@ +/* +* _2.1_blink +* +* The on-board LED blinks with a 2 second interval, +* being turned on for 1 second and then turned off for 1 second. +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + pinMode(13, OUTPUT); +} + +void loop() { + digitalWrite(13, HIGH); + delay(1000); + digitalWrite(13, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.2_blink/_2.2_blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.2_blink/_2.2_blink.ino new file mode 100644 index 00000000..fe856548 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.2_blink/_2.2_blink.ino @@ -0,0 +1,19 @@ +/* +* _2.2_blink +* +* An external LED blinks with a 2 second interval, +* being turned on for 1 second and then turned off for 1 second. +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + pinMode(5, OUTPUT); +} + +void loop() { + digitalWrite(5, HIGH); + delay(1000); + digitalWrite(5, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.3_blink/_2.3_blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.3_blink/_2.3_blink.ino new file mode 100644 index 00000000..9233b5e5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.3_blink/_2.3_blink.ino @@ -0,0 +1,24 @@ +/* +* _2.3_blink +* +* An external LED blinks with a 2 second interval, +* being turned on for 1 second and then turned off for 1 second. +* +* The variable ledPin is declared to hold the value 5, the number +* of the digital pin you are using. +* +* (c) 2013-2016 Arduino LLC. +*/ + +int ledPin = 5; + +void setup() { + pinMode(ledPin, OUTPUT); +} + +void loop() { + digitalWrite(ledPin, HIGH); + delay(1000); + digitalWrite(ledPin, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.4_beep/_2.4_beep.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.4_beep/_2.4_beep.ino new file mode 100644 index 00000000..aee6d57b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.4_beep/_2.4_beep.ino @@ -0,0 +1,20 @@ +/* +* _2.4_beep +* +* The piezo makes clicks with a 2 second interval. +* +* (c) 2013-2016 Arduino LLC. +*/ + +int speakerPin = 8; + +void setup() { + pinMode(speakerPin, OUTPUT); +} + +void loop() { + digitalWrite(speakerPin, HIGH); + delay(1000); + digitalWrite(speakerPin, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.5_beep/_2.5_beep.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.5_beep/_2.5_beep.ino new file mode 100644 index 00000000..6e09712d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.5_beep/_2.5_beep.ino @@ -0,0 +1,19 @@ +/* +* _2.5_beep +* +* The piezo makes clicks with a 1 millisecond interval. +* +* (c) 2013-2016 Arduino LLC. +*/ +int speakerPin = 8; + +void setup() { + pinMode(speakerPin, OUTPUT); +} + +void loop() { + digitalWrite(speakerPin, HIGH); + delay(1); + digitalWrite(speakerPin, LOW); + delay(1); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.6_beep/_2.6_beep.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.6_beep/_2.6_beep.ino new file mode 100644 index 00000000..97e3236f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.6_beep/_2.6_beep.ino @@ -0,0 +1,13 @@ +/* +* _2.6_beep +* +* The piezo uses the tone() function to generate an A with a frequency of 440 hertz. +* +* (c) 2013-2016 Arduino LLC. +*/ +void setup() { + tone(8, 440, 1000); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.7_digital_input/_2.7_digital_input.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.7_digital_input/_2.7_digital_input.ino new file mode 100644 index 00000000..1cf1ac94 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.7_digital_input/_2.7_digital_input.ino @@ -0,0 +1,23 @@ +/* +* _2.7_digital_input +* +* The board will turn the on-board LED on or off +* +* (c) 2013-2016 Arduino LLC. +*/ + +int inputPin = 5; +int ledPin = 13; + +void setup() { + pinMode(inputPin, INPUT); + pinMode(ledPin, OUTPUT); +} + +void loop() { + if (digitalRead(inputPin) == HIGH) { + digitalWrite(ledPin, HIGH); + } else { + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.8_digital_input/_2.8_digital_input.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.8_digital_input/_2.8_digital_input.ino new file mode 100644 index 00000000..1b06a97f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.8_digital_input/_2.8_digital_input.ino @@ -0,0 +1,23 @@ +/* +* _2.8_digital_input +* +* The board will turn the on-board LED on or off, with a button module +* +* (c) 2013-2016 Arduino LLC. +*/ + +int inputPin = 6; +int ledPin = 13; + +void setup() { + pinMode(inputPin, INPUT); + pinMode(ledPin, OUTPUT); +} + +void loop() { + if (digitalRead(inputPin) == HIGH) { + digitalWrite(ledPin, HIGH); + } else { + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/Basketball.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/Basketball.ino new file mode 100644 index 00000000..95109f38 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/Basketball.ino @@ -0,0 +1,63 @@ +/* +* Basketball +* +* Score a goal! +* +* In this game, players will try to bounce a ping pong ball +* into a cup. Make five points to win. The score is tracked +* using a LightSensor. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include +#include "pitches.h" +/* +An array of pin numbers to which LEDs are attached +the defaults are 2 to 6 but you can choose any of the digital pins +*/ +int ledPins[] = { 2, 3, 4, 5, 6 }; +int pinCount = 5; +VUMeter vuMeter; + +Melody piezo = Melody(8); // the piezo connected to digital pin 8 +LightSensor sensor = LightSensor(A1); //the LightSensor connected to analog pin 1 + +int score = 0; + +void setup() { + //if your are using other pins than 2 to 6 you need to configure that here + vuMeter.config(pinCount, ledPins); + vuMeter.begin(); //does the same as pinMode, LEDs are outputs + + sensor.config(800, 600); //first run the LightSensorTest example to see what values you need to put here +} + +void loop() { + //if the LightSensor is covered the score increases with 1 + //and a sound is played + sensor.pressed(); + score++; + vuMeter.fill(score); //Turn on as many LEDs as the score + + int melody[] = { NOTE_GS4, NOTE_C5 }; + int noteDurations[] = { 8, 8 }; + int numberOfNotes = 2; + piezo.play(numberOfNotes, melody, noteDurations, 1); + + delay(50); + + if (score >= pinCount) startOver(); //If the score equals the amount of LEDs you start over +} + + +void startOver() { + score = 0; //reset the score + + int melody[] = { NOTE_C5, NOTE_G4, NOTE_G4, NOTE_A4, NOTE_G4, 0, NOTE_B4, NOTE_C5 }; + int noteDurations[] = { 4, 8, 8, 4, 4, 4, 4, 4 }; + int numberOfNotes = 8; + piezo.play(numberOfNotes, melody, noteDurations, 1); + + vuMeter.blinkAll(50, 10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/pitches.h new file mode 100644 index 00000000..f3037d5e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/DigitalDie/DigitalDie.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/DigitalDie/DigitalDie.ino new file mode 100644 index 00000000..d2ac7144 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/DigitalDie/DigitalDie.ino @@ -0,0 +1,142 @@ +/* +* DigitalDie +* +* Use this digital die next time you play a board game. +* +* You "throw" the die by shaking a tilt sensor. The LEDs +* will show different numbers, waiting a longer and longer +* time for each number, until it finally stops. Don't be +* too fast to cheer believing it stopped on your desired +* number or you might get disappointed ... +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//declare the pins used for LEDs, 9 LEDs in total +int pinCount = 9; +int ledPins[] = { 2, 3, 4, 5, 6, 7, 8, 11, 13 }; + +/* +declare the tilt switch, it's connected to TinkerKit +port 9 +*/ +TiltSwitch ts = TiltSwitch(9); + +/* + Define the patterns of die values. Each pattern is + an array of 9 integers, indicating the on/off state + of each LED. + And because there're 6 possible patterns, we need a + 2-dimensional array to define all the data. It's a + big array of 6 elements, each element is an array of + 9 integers. +*/ +int die[6][9] = { + //1 + { + 0, 0, 0, + 0, 1, 0, + 0, 0, 0 }, + + //2 + { + 1, 0, 0, + 0, 0, 0, + 0, 0, 1 }, + + //3 + { + 1, 0, 0, + 0, 1, 0, + 0, 0, 1 }, + + //4 + { + 1, 0, 1, + 0, 0, 0, + 1, 0, 1 }, + + //5 + { + 1, 0, 1, + 0, 1, 0, + 1, 0, 1 }, + + //6 + { + 1, 1, 1, + 0, 0, 0, + 1, 1, 1 } +}; + +/* + wait time between the die rolls to a different face. + Notice it's using float type here? Read on! +*/ +float waitTime = 1; + +void setup() { + //Configure each pin as an output. + for (int i = 0; i < pinCount; i++) { + pinMode(ledPins[i], OUTPUT); + } + + //initialize the tilt switch. + ts.begin(); + + //generate the random seed. We use the value from + //A0, since it's not connected to anything, it should + //generate some random noises. Perfect for our purpose + randomSeed(analogRead(A0)); +} +void loop() { + //Reset the wait time + waitTime = 2; + + /* + Imagine when you throw a die, it'll bounce around, + showing a few values before laying still. + + Let's keep generating new values until it's stable + (when time between new values become long enough) + */ + while (waitTime < 1000) { + /* + Generate a random die value. + The die value can be 1 to 6, in the array it's + die[0] to die[5]. random(0,6) generate a value + between 0 to 6, that would be 0 to 5 in effect. + */ + int value; + value = random(0, 6); + + //Display the die value + displayDie(value); + + /* + See why waitTime has to be float? If it's an integer, + multiplying it by 1.3 will make it lose everything behind + the decimal mark. We use 2 as the starting value, + 2*1.3 should be 2.6, losing the fractional parts means + it'll be 2 in the end, so 2*1.3=2! + */ + waitTime = waitTime * 1.3; + delay(waitTime); + } + + /* + Now the die is stable, wait until the tilt switch is + activated again. ts.pressed() stops the whole program + until it's activated. + */ + ts.pressed(); +} + +void displayDie(int num) { + //Show the die value by turning on/off the right LEDs + for (int i = 0; i < pinCount; i++) { + digitalWrite(ledPins[i], die[num][i]); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Fencing/Fencing.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Fencing/Fencing.ino new file mode 100644 index 00000000..3184d61c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Fencing/Fencing.ino @@ -0,0 +1,81 @@ +/* +* Fencing +* +* Test your reaction time against an opponent! +* +* In this game, two players will hold tilt switch swords. +* When the green LED randomly lights up, the first person +* to swing their sword wins. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +#include + +//Position of the LEDs in VU-meter is represented +//by their names here. So we can use names to find LEDs later +#define YELLOW_LED_1 0 +#define GREEN_LED 1 +#define RED_LED 2 +#define YELLOW_LED_2 3 + +//An array stores which pins the VU-meter is connected +int ledPins[] = { 2, 3, 4, 5 }; +//How many pins are used by VU-meter +int pinCount = 4; +VUMeter lights; + +TiltSwitch player_1 = TiltSwitch(6); +TiltSwitch player_2 = TiltSwitch(9); + +void setup() { + lights.config(pinCount, ledPins); + + //Initializing components + lights.begin(); + player_1.begin(); + player_2.begin(); + + //We need this for generating random numbers later + randomSeed(analogRead(0)); +} +void loop() { + lights.clear(); + + //Red LED means both of you should hold the tilt switch sword up right + lights.on(RED_LED); + + //Wait for a random period of time, between 3 seconds + //And 6 seconds. Get ready! + delay(random(3000, 6000)); + + lights.off(RED_LED); + //When the green LED turns on, game starts + lights.on(GREEN_LED); + + //Swing your swords as fast as you can, the faster one + //will be returned by getWinner() + int winner = getWinner(); + + //The yellow LED on the side of the winner will light up + if (winner == 1) { + lights.on(YELLOW_LED_1); + } else { + lights.on(YELLOW_LED_2); + } + delay(5000); +} + +//The function below waits for either of the tilter +//switch to be swung. The first one to swing +//will be returned by its number +int getWinner() { + do { + if (player_1.pressed(1)) { + return 1; + } else if (player_2.pressed(1)) { + return 2; + } + } while (true); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino new file mode 100644 index 00000000..1202da9a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino @@ -0,0 +1,81 @@ +/* +* Pong +* +* Play a simplified version of the classic arcade game, Pong! +* +* In this game, a “pong” will move across five LEDs (VU-meter) +* and bounce back and forth as players press the button. +* Players must press the button at the right time in order to +* return the pong. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include +/* + An array of pin numbers to which LEDs are attached + the defaults are 2 to 6 but you can choose any of the digital + pins. Just remember to leave digital pin 9 and 6 for the buttons. +*/ +int ledPins[] = { 2, 3, 4, 5, 7 }; +int pinCount = 5; +VUMeter vuMeter; + +Button button1 = Button(9); //the button connected to digital pin 9 +Button button2 = Button(6); //the button connected to digital pin 6 + +int ledTime = 100; //determines how fast the LEDs will switch +int pressTime = 200; //determines how long time a player has to press the button +int buttonNotPressed = 0; //this keeps track of who missed pressing the button + +void setup() { + //if you are using other pins than 2 to 6 you need to configure that here + vuMeter.config(pinCount, ledPins); + + vuMeter.begin(); //does the same as pinMode, LEDs are outputs + button1.begin(); //does the same as pinMode, buttons are inputs + button2.begin(); //does the same as pinMode, buttons are inputs + + vuMeter.scrollLeft(ledTime, 1); //The game starts by scrolling the LEDs to the left +} + +void loop() { + /* + if button1 is pressed within the press time, the game will continue + by scrolling the LEDs to the right + else if button1 is not pressed, the program will jump to gameOver() + */ + if (button1.released(pressTime)) { + vuMeter.scrollRight(ledTime, 1); + } else { + buttonNotPressed = 1; //Keep track of where we are in the game + gameOver(); + } + + /* + if button2 is pressed within the press time, the game will continue + by scrolling the LEDs to the left + else if button2 is not pressed, the program will jump to gameOver() + */ + if (button2.released(pressTime)) { + vuMeter.scrollLeft(ledTime, 1); + } else { + buttonNotPressed = 2; //Keep track of where we are in the game + gameOver(); + } +} + +/* + When a player doesn't press the right button within the right + time it is game over. Inside the function gameOver() you can + decide how the LEDs should blink. + Use vuMeter.blink(LED,delayTime,numberOfBlinks) to make one specific LED blink + Use vuMeter.blinkAll(delayTime,numberOfBlinks) to make all LEDs blink +*/ +void gameOver() { + vuMeter.blinkAll(100, 10); + + if (buttonNotPressed == 1) vuMeter.scrollRight(ledTime, 1); //if button1 was not pressed, scroll LEDs to the right to start over + else if (buttonNotPressed == 2) + vuMeter.scrollLeft(ledTime, 1); //if button2 was not pressed, scroll LEDs to the left to start over +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Racing/Racing.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Racing/Racing.ino new file mode 100644 index 00000000..48126dc6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Racing/Racing.ino @@ -0,0 +1,69 @@ +/* +* Racing +* +* Run with your fingers as fast as you can. +* +* In this game, the player must tap two sensors repeatedly +* in order to run laps. One LED will light up per lap. +* When all laps are completed, LEDs will blink in victory. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +/* + An array of pin numbers to which LEDs are attached + the defaults are 2 to 6 but you can choose any of the digital pins + just remember to leave digital pin 2,3 and 4 for the capacitive switches +*/ +int ledPins[] = { 8, 9, 10, 11, 13 }; +int pinCount = 5; +//This variable will let us keep track of which LED to turn on +int LED = 0; +VUMeter scoreBoard; + +//Configure the capacitive sensors +int capacitiveSensorThreshold = 400; +CapacitiveSwitch leftFoot = CapacitiveSwitch(2, 3); +CapacitiveSwitch rightFoot = CapacitiveSwitch(2, 4); + +int score; + +void setup() { + //initializing the game, set up all the components and variables + score = 0; + + //Connect scoreboard + scoreBoard.config(pinCount, ledPins); + scoreBoard.begin(); + + //initialize left and right "foot" + leftFoot.config(capacitiveSensorThreshold); + rightFoot.config(capacitiveSensorThreshold); +} + +void loop() { + //Wait for the left foot to be pressed + leftFoot.pressed(); + scoreBoard.on(LED); + + //Wait for the right foot to be pressed + rightFoot.pressed(); + scoreBoard.off(LED); + + score = score + 1; //After both feet are pressed, add one point + + //Every 20 points light up a LED + LED = score / 20; + scoreBoard.fill(LED); + + //When you get 100 points, you win + if (score > 100) { + //if you win, blink all LEDs for celebration + //See vuMeter in reference list to make your own blink animation + scoreBoard.blinkAll(50, 5); + //and reset the game + score = 0; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/React.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/React.ino new file mode 100644 index 00000000..22cb7df8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/React.ino @@ -0,0 +1,79 @@ +/* +* React +* +* Test your reaction time! +* +* In this game, one of three LEDs will randomly light up. +* You must tap the corresponding capacitive sensor as quick +* as possible. If you don’t react fast enough, the game is over. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include +#include "pitches.h" + +//Define the 3 LEDs +int ledPins[] = { 9, 10, 11 }; +int pinCount = 3; +VUMeter LEDs; + +//There're 3 pads for pressing +CapacitiveSwitch pad[3]; + +//You have 500 milliseconds to press the pad +int reactTime = 500; + +// the piezo connected to digital pin 8 +Melody piezo = Melody(8); + +void setup() { + LEDs.config(pinCount, ledPins); + LEDs.begin(); + + //Configure the pads + pad[0] = CapacitiveSwitch(2, 3); + pad[1] = CapacitiveSwitch(2, 4); + pad[2] = CapacitiveSwitch(2, 5); + pad[0].config(100); + pad[1].config(100); + pad[2].config(100); +} + +void loop() { + //Wait for a random time before each turn begins + delay(random(50, 2000)); + + //pick a target between the 3 pads + int target = random(0, 3); + //Light up the LED + LEDs.on(target); + + //If the pad corresponding to the LED is pressed + if (pad[target].pressed(reactTime)) { + LEDs.off(target); + + //Play the winning sound + int melody[] = { NOTE_GS4, NOTE_C5 }; + int noteDurations[] = { 8, 8 }; + int numberOfNotes = 2; + piezo.play(numberOfNotes, melody, noteDurations, 1); + } else { + //Else if the reaction is too slow, run the function gameOver() + gameOver(); + } +} + +void gameOver() { + //Turn all LEDs on + LEDs.fill(pinCount); + + //Play a melody + int melody[] = { NOTE_E2, NOTE_C2 }; + int noteDurations[] = { 2, 1 }; + int numberOfNotes = 2; + piezo.play(numberOfNotes, melody, noteDurations, 1); + + LEDs.blinkAll(100, 10); + LEDs.fill(0); //Tun all LEDs off +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/pitches.h new file mode 100644 index 00000000..f3037d5e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/SimonSays/SimonSays.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/SimonSays/SimonSays.ino new file mode 100644 index 00000000..39fbaba8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/SimonSays/SimonSays.ino @@ -0,0 +1,118 @@ +/* +* SimonSays +* +* Test your memory with this game! +* +* LEDs will blink in a pattern that you have to remember and repeat. +* If you get it right, the game gets more and more challenging. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +#include + +/* + An array of pin numbers to which LEDs are attached + the defaults are 2 to 6 but you can choose any of the digital + pins. +*/ +int ledPins[] = { 2, 3, 4, 5, 6 }; +int pinCount = 5; +VUMeter vuMeter; + +Knob pot = Knob(A0); //a knob is connected to A0 + +Button button = Button(9); //a button is connected to port D9 + +Melody piezo = Melody(8); //a piezo is connected to digital pin 8 + +//Set the game parameters +int turns_begin = 2; //a new game starts with 2 turns +int turns_max = 10; //the most difficult game has 10 turns + +int game[10]; //array for storing the "simon says" +int turns = 2; //for storing the number of turns in current game +int blinkTime = 500; //how fast does "simon says" blink + +void setup() { + //initialize the components + vuMeter.config(pinCount, ledPins); + vuMeter.begin(); + pot.setLevels(5); + button.begin(); + + //Create a random seed, so we can call random() later. + randomSeed(analogRead(A5)); +} +void loop() { + newGame(); + simonSays(); + delay(1000); + getInputs(); +} + +void newGame() { + vuMeter.blinkAll(200, 3); + vuMeter.clear(); + delay(500); + //Generate simon says, it'll be stored in an array + //So we can compare with player's input later + for (int i = 0; i < turns; i++) { + game[i] = random(pinCount); + } +} +void simonSays() { + //Display simon says to the player. + for (int i = 0; i < turns; i++) { + vuMeter.on(game[i]); + delay(blinkTime); + vuMeter.off(game[i]); + delay(blinkTime); + } +} +void getInputs() { + //Get "i" inputs where "i" matches the number of + //simon says in this round. + for (int i = 0; i < turns; i++) { + int input; + //button.released() stops the program, so + //let's do it in short pulses. In between + //we can change the vuMeter display. + while (!button.released(10)) { + vuMeter.clear(); + vuMeter.on(pot.getLevel()); + } + //When button is released, get the adjusted + //value from the knob + input = pot.getLevel(); + if (input == game[i]) { + //if your input is right, play a score sound + //and continue. + piezo.effect_score(); + } else { + //Otherwise, gameover. Stop the function from + //continuing by an empty return. + gameOver(); + return; + } + } + //When all the inputs matched simon says, you win + //this round and level up. + delay(500); + levelUp(); +} +void gameOver() { + //When it's gameover, difficulty resets + turns = turns_begin; + //And play the gameover sound + piezo.effect_gameover(); +} +void levelUp() { + //When level up, adds more difficulty until it reaches maximum + if (turns < turns_max) { + turns++; + } + //And play a winning sound + piezo.effect_win(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.1_reading_analog/_3.1_reading_analog.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.1_reading_analog/_3.1_reading_analog.ino new file mode 100644 index 00000000..9a235367 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.1_reading_analog/_3.1_reading_analog.ino @@ -0,0 +1,22 @@ +/* +* _3.1_reading_analog +* +* The board uses a potentiometer to control the blinking speed of the on-board LED. +* +* (c) 2013-2016 Arduino LLC. +*/ + +int ledPin = 13; + +void setup() { + pinMode(ledPin, OUTPUT); +} + +void loop() { + int val = analogRead(A5); + + digitalWrite(ledPin, HIGH); + delay(val); + digitalWrite(ledPin, LOW); + delay(val); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.2_writing_analog/_3.2_writing_analog.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.2_writing_analog/_3.2_writing_analog.ino new file mode 100644 index 00000000..2bd6e993 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.2_writing_analog/_3.2_writing_analog.ino @@ -0,0 +1,21 @@ +/* +* _3.2_writing_analog +* +* The board will gradually change the light intensity of an LED, connected to a PWM pin. +* +* (c) 2013-2016 Arduino LLC. +*/ + +int ledPin = 9; +int fade = 0; + +void setup() { + // nothing here +} + +void loop() { + analogWrite(ledPin, fade); + delay(10); + fade = fade + 10; + if (fade > 255) fade = 0; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.3_light_sensor/_3.3_light_sensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.3_light_sensor/_3.3_light_sensor.ino new file mode 100644 index 00000000..3d85e689 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.3_light_sensor/_3.3_light_sensor.ino @@ -0,0 +1,23 @@ +/* +* _3.3_light_sensor +* +* The board changes the light intensity of an LED depending on the readings from a light sensor. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +int ledPin = 9; +int lightSensorPin = A1; + +void setup() { + //nothing here +} + +void loop() { + int lightSensorValue = analogRead(lightSensorPin); + int ledValue = map(lightSensorValue, 0, 1023, 0, 255); + + analogWrite(ledPin, ledValue); + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.4_light_sensor/_3.4_light_sensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.4_light_sensor/_3.4_light_sensor.ino new file mode 100644 index 00000000..7e3f1f75 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.4_light_sensor/_3.4_light_sensor.ino @@ -0,0 +1,29 @@ +/* +* _3.4_light_sensor +* +* The light sensor acts as a switch and turns an LED on or off depending on the readings. +* With a potentiometer to set the switch threshold. +* +* (c) 2013-2016 Arduino LLC. +*/ + +int ledPin = 9; +int lightSensorPin = A1; +int potPin = A5; + +void setup() { + pinMode(ledPin, OUTPUT); +} + +void loop() { + int lightSensorValue = analogRead(lightSensorPin); + int threshold = analogRead(potPin); + + if (lightSensorValue > threshold) { + digitalWrite(ledPin, LOW); + } else { + digitalWrite(ledPin, HIGH); + } + + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.5_sending_serial/_3.5_sending_serial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.5_sending_serial/_3.5_sending_serial.ino new file mode 100644 index 00000000..f1088f8c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.5_sending_serial/_3.5_sending_serial.ino @@ -0,0 +1,16 @@ +/* +* _3.5_sending_serial +* +* The board will send a text message from the board to the computer and Serial Monitor +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.println("Hello World"); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.6_sending_serial/_3.6_sending_serial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.6_sending_serial/_3.6_sending_serial.ino new file mode 100644 index 00000000..9cd916cf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.6_sending_serial/_3.6_sending_serial.ino @@ -0,0 +1,18 @@ +/* +* _3.6_sending_serial +* +* The board will read the analog value from a light sensor and print that value to the Serial Monitor. +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + Serial.begin(9600); +} + +void loop() { + int sensorValue = analogRead(A1); + + Serial.println(sensorValue); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.7_receiving_serial/_3.7_receiving_serial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.7_receiving_serial/_3.7_receiving_serial.ino new file mode 100644 index 00000000..5244d802 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.7_receiving_serial/_3.7_receiving_serial.ino @@ -0,0 +1,27 @@ +/* +* _3.7_receiving_serial +* +* The board turns the on-board LED on or off by sending an ‘H’ or ‘L’ to the control board from the Serial Monitor +* +* (c) 2013-2016 Arduino LLC. +*/ + +int ledPin = 13; +int incomingByte; + +void setup() { + Serial.begin(9600); + pinMode(ledPin, OUTPUT); +} +void loop() { + if (Serial.available() > 0) { + incomingByte = Serial.read(); + + if (incomingByte == 'H') { + digitalWrite(ledPin, HIGH); + } + if (incomingByte == 'L') { + digitalWrite(ledPin, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/BinaryLP.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/BinaryLP.ino new file mode 100644 index 00000000..a4db7c15 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/BinaryLP.ino @@ -0,0 +1,86 @@ +/* +* BinaryLP +* +* This sort of works as an LP player. The difference is +* that instead of using a needle on a plastic disc, +* we use three IR sensors in a row to read a pattern from +* a paper disc. +* +* If you are both musically and digitally inclined, +* you will have lots of fun creating melodies with this. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +#include +#include "pitches.h" + +//IRArray(left, middle, right); +IRArray ir = IRArray(A1, A2, A3); + +int piezo = 8; //Piezo pin +int lastReading = 0; + +void setup() { + pinMode(piezo, OUTPUT); + + //Use this line to set the threshold of the IR sensors. + //If you are using the Uno board, set the threshold to 380. If you're using the 101 board, set it to 530. + //Use ir.test() to check the values of each sensor in the loop() + ir.setThreshold(530); + + Serial.begin(9600); +} + +void loop() { + //Use this line to check the values from each IR sensor + //ir.test(); + + //Read the binary pattern and get a number from 0 to 7 + int reading = ir.readBinary(); + + //Play a note depending on the read value + playNote(reading); +} + +void playNote(int r) { + //If the last note we played is the same as the new note + //we make a short break so that two notes are distinguished + if (lastReading == r) { + noTone(piezo); + delay(20); + } + + //Play a different note depending on the value of r. + //Check pitches.h to see which notes you can use. + //In this case the scale is C Major. + switch (r) { + case 0: + break; + case 1: + tone(piezo, NOTE_C4); + break; + case 2: + tone(piezo, NOTE_D4); + break; + case 3: + tone(piezo, NOTE_E4); + break; + case 4: + tone(piezo, NOTE_F4); + break; + case 5: + tone(piezo, NOTE_G4); + break; + case 6: + tone(piezo, NOTE_A4); + break; + case 7: + tone(piezo, NOTE_B4); + break; + } + + //If r is more than 0 we save that value to lastReading + if (r > 0) lastReading = r; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/pitches.h new file mode 100644 index 00000000..f3037d5e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/BinaryLP_Workshop.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/BinaryLP_Workshop.ino new file mode 100644 index 00000000..a4db7c15 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/BinaryLP_Workshop.ino @@ -0,0 +1,86 @@ +/* +* BinaryLP +* +* This sort of works as an LP player. The difference is +* that instead of using a needle on a plastic disc, +* we use three IR sensors in a row to read a pattern from +* a paper disc. +* +* If you are both musically and digitally inclined, +* you will have lots of fun creating melodies with this. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +#include +#include "pitches.h" + +//IRArray(left, middle, right); +IRArray ir = IRArray(A1, A2, A3); + +int piezo = 8; //Piezo pin +int lastReading = 0; + +void setup() { + pinMode(piezo, OUTPUT); + + //Use this line to set the threshold of the IR sensors. + //If you are using the Uno board, set the threshold to 380. If you're using the 101 board, set it to 530. + //Use ir.test() to check the values of each sensor in the loop() + ir.setThreshold(530); + + Serial.begin(9600); +} + +void loop() { + //Use this line to check the values from each IR sensor + //ir.test(); + + //Read the binary pattern and get a number from 0 to 7 + int reading = ir.readBinary(); + + //Play a note depending on the read value + playNote(reading); +} + +void playNote(int r) { + //If the last note we played is the same as the new note + //we make a short break so that two notes are distinguished + if (lastReading == r) { + noTone(piezo); + delay(20); + } + + //Play a different note depending on the value of r. + //Check pitches.h to see which notes you can use. + //In this case the scale is C Major. + switch (r) { + case 0: + break; + case 1: + tone(piezo, NOTE_C4); + break; + case 2: + tone(piezo, NOTE_D4); + break; + case 3: + tone(piezo, NOTE_E4); + break; + case 4: + tone(piezo, NOTE_F4); + break; + case 5: + tone(piezo, NOTE_G4); + break; + case 6: + tone(piezo, NOTE_A4); + break; + case 7: + tone(piezo, NOTE_B4); + break; + } + + //If r is more than 0 we save that value to lastReading + if (r > 0) lastReading = r; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/pitches.h new file mode 100644 index 00000000..f3037d5e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BoomBox/BoomBox.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BoomBox/BoomBox.ino new file mode 100644 index 00000000..aeff917b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BoomBox/BoomBox.ino @@ -0,0 +1,63 @@ +/* +* BoomBox +* +* This is your first step towards these kinds of skills: +* http://www.youtube.com/watch?v=FcJCxe1VSLA&noredirect=1 +* The boom box is a small sample player you can use to make music, +* or just random sound. It comes with three prerecorded samples +* but we probably don’t have the same creative cleverness when it +* comes to recording as you do so you should definitely record your +* own samples too! +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare a button group with 3 buttons. The +//sound player secretly takes pin 3, 4 and 11, +//so don't use them. +ButtonGroup bg; +int buttons[] = { 5, 6, 7 }; + +//There're 3 buttons in the button group. +int buttonsCount = 3; + +//Declare the sound player +Player player = Player(); + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + + // Initialize the sound player. Open the Serial Monitor to see + //the sound files found on your micro SD card + player.begin(); + + //Initialize the button group. + bg.begin(buttonsCount, buttons); +} + +void loop() { + //Wait for one of the buttons to be pressed. + //According to which button is pressed, it + //returns either 0, 1 or 2 + int pressedButton = bg.pressed(); + + //Play a different sound according to the + //button pressed. + switch (pressedButton) { + case 0: + Serial.println("sound 0"); + player.play("0.wav"); + break; + case 1: + Serial.println("sound 1"); + player.play("1.wav"); + break; + case 2: + Serial.println("sound 2"); + player.play("2.wav"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/CookieMonster/CookieMonster.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/CookieMonster/CookieMonster.ino new file mode 100644 index 00000000..ae20ee46 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/CookieMonster/CookieMonster.ino @@ -0,0 +1,45 @@ +/* +* CookieMonster +* +* Someone is eating our cookies, let's gather some proof +* about that person and get him/her to confess. +* +* (c) 2013-2016 Arduino LLC. B&D Cuartielles +* +* This code is Free Software, licensed under GPLv3 +* Based on code by Paul Badger 2008 +* +*/ + + +#include + +//Define the capacitive sensor +CapacitiveSwitch sensor = CapacitiveSwitch(2, 3); + +//Define the LED +int led = 6; + +void setup() { + // configure the serial port + Serial.begin(9600); + + //initialize components + sensor.config(200); + pinMode(led, OUTPUT); +} + +void loop() { + //When someone attempts to open the + //cookie jar, the sensor is activated + if (sensor.pressed()) { + //Turn on the LED + digitalWrite(led, HIGH); + //Sends signal to processing, so a picture + //will be captured + Serial.print('p'); + //Wait 2 seconds before turning the LED off + delay(2000); + digitalWrite(led, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/Drawdio.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/Drawdio.ino new file mode 100644 index 00000000..6ef7a13e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/Drawdio.ino @@ -0,0 +1,59 @@ +/* +* Drawdio +* +* Draw audio with drawdio. You might think that this pen is magic, +* and it might just be. Drawdio turns (almost) everything that is +* conductive into an instrument. You can either make music by +* drawing a picture or by touching the tip of it to different +* conductive things around you. +* +* (c) 2013-2016 Arduino LLC. +* Inspiration from Jay Siver's DRAWDIO +* http://web.media.mit.edu/~silver/drawdio/ +* +*/ + +#include +#include "pitches.h" + +//Capacitive switch connected between 2 and 3 +CapacitiveSwitch me = CapacitiveSwitch(2, 3); + +//A piezo speaker connected to digital pin 8 +Melody speaker = Melody(8); + +//The range of capacitive sensor values to be +//mapped to music tones. See example +//"Help/CapacitiveSwitchTest" for how to get +//the values +int lowerThreshold = 80; +int upperThreshold = 900; + +//Define the lowest and highest tone. Defined +//in pitches.h +int toneLow = NOTE_C3; +int toneHigh = NOTE_B6; + +void setup() { + //Nothing to do here. Magic? +} +void loop() { + //Get value of the sensor. If it's smaller + //than the threshold, it'll be 0 + int value = me.getValue(lowerThreshold); + + //map the sensor value to tones. The map() + //function maps values smaller than lower + //threshold to the lowest desired value. If + //you want to keep drawdio quiet when you're + //not playing, you have to deal with 0 separately + int pitch; + if (value > 0) { + pitch = map(value, lowerThreshold, upperThreshold, toneLow, toneHigh); + } else { + pitch = 0; + } + + //Play the tone to the speaker. + speaker.playTone(pitch, 10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/pitches.h new file mode 100644 index 00000000..f3037d5e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/KnockKnockBox/KnockKnockBox.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/KnockKnockBox/KnockKnockBox.ino new file mode 100644 index 00000000..f3544b8c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/KnockKnockBox/KnockKnockBox.ino @@ -0,0 +1,104 @@ +/* +* KnockKnockBox +* +* Knock on this coffin to awake the dead. Don’t worry, +* the skeleton won’t get out and come after you but it +* will reply from inside. +* +* Ok, we know that you know that there isn’t a real +* skeleton there. It's really a piezo used as a knock +* sensor. After you've made this project you might +* think of a handy way to use this sensor in other ways. +* Check out this secret knock detecting lock for some +* inspiration: http://www.youtube.com/watch?v=zE5PGeh2K9k +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The number of knocks that can be recorded +#define MAX_KNOCKS 30 + +PiezoKnockSensor sensor = PiezoKnockSensor(A0); +int speaker = 8; + +//An array for remembering the knock pattern +long timer[MAX_KNOCKS]; + +//If it has started recording +boolean started; + +//Used for calculating if you have finished the pattern +long timeoutBase; + +//If you stop knocking for the period of timeout, it'll +//stop recording +long timeout = 2000; + +//Keep track of the number of knocks you've knocked +int currentKnock; + +void setup() { + //define the threshold and debounce time of the knock + //sensor. Threshold defines how hard you need to knock, + //debounce time prevents the sensor from detecting + //false knocks, but also limits how rapid you can knock. + sensor.config(100, 80); + + //initializing the values + started = false; + timeoutBase = 0; + currentKnock = 0; + clearArray(); +} + +void loop() { + //Knock sensor waits for a short time if a knock is detected + //and then move on. + if (sensor.knocked(20)) { + //If it's the first knock in the round, start recording + if (!started) { + started = true; + } + + long currentTime = millis(); + //Reset timeout + timeoutBase = currentTime; + //Save the amount of milliseconds that have + //passed since the last knock + timer[currentKnock] = currentTime; + currentKnock++; + } + if (started) { + //If recording has started and you stop + //knocking for the time of "timeout", it'll + //stop recording and play it back to you. + if (millis() - timeoutBase > timeout) { + playback(); + //reset the parameters, so a new round begins + started = false; + clearArray(); + currentKnock = 0; + } + } +} +void clearArray() { + //clean up values in the timer array + for (int i = 0; i < MAX_KNOCKS; i++) { + timer[i] = 0; + } +} +void playback() { + //Play the knock pattern back to you through the + //speaker piezo + for (int i = 0; timer[i] != 0; i++) { + //Make a beep sound with tone 200 for 30 milliseconds + tone(speaker, 200, 30); + if (timer[i + 1]) { + //Wait the same amount of milliseconds that was detected + //between the knocks + delay(timer[i + 1] - timer[i]); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/POV/POV.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/POV/POV.ino new file mode 100644 index 00000000..d3e6a4c5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/POV/POV.ino @@ -0,0 +1,67 @@ +/* +* POV (Persistence of Vision) +* +* With POV, persistence of vision, you can take eg a bike wheel +* and make it into a display with just a few LEDs. Check out +* this video to see what we mean: +* http://www.youtube.com/watch?v=-TvGvVWS3IE +* +* In this project you will make one of these displays yourself. +* Wave it with long strokes or even hold it while running to +* display a text, a statement or a picture. The effect is most +* visible in a dark place so if you’re running, make sure not +* to run in to a tree or a friend. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include +/* +An array of pin numbers to which LEDs are attached +the defaults are 2 to 6 but you can choose any of the digital pins +*/ +int ledPins[] = { 2, 3, 4, 5, 6 }; +int pinCount = 5; +VUMeter vuMeter; + +int rowCount = 0; // Stores the number of rows +int rowLength = 22; // Width of the message, copy this number to the message array +int delayTime = 9; // Time it takes to show a row in milliseconds + +// The message where 0 is LOW and 1 is HIGH +boolean message[5][22] = { + // H H H H O O O O L L L L A A A A + { 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0 }, + { 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 }, + { 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0 }, + { 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0 }, + { 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0 } + +}; + +void setup() { + // If your are using other pins than 2 to 6 you need to configure that here + vuMeter.config(pinCount, ledPins); + + vuMeter.begin(); //does the same as pinMode, LEDs are outputs +} + +void loop() { + // If the whole array has been drawn + if (rowCount == rowLength) { + rowCount = 0; // Reset the rowCount + } else { + // Shows the message + for (int i = 0; i < pinCount; i++) { + // Checks if the array says HIGH + if (message[i][rowCount] == 1) { + vuMeter.on(i); + } else { + vuMeter.off(i); + } + } + rowCount++; + } + + delay(delayTime); // This is the delay per row +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Sequencer/Sequencer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Sequencer/Sequencer.ino new file mode 100644 index 00000000..510bc061 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Sequencer/Sequencer.ino @@ -0,0 +1,114 @@ +/* +* Sequencer +* +* Play beats and change the sequence in real time. Basically +* all you need to become a hiphop artist. That, and rapping +* skills. But that's another course. +* +* (c) 2013-2016 Arduino LLC. +*/ +#include + +//Declare the sound player +Player player = Player(); + +//There're 4 slots for 4 sequences. We use 4 analog pins +//to read them. +int analog_pins[] = { 3, 2, 1, 0 }; +int pin_count = 4; +int analog_values[4]; + +//Template for the music file names. +char filename[] = "seq0.wav"; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + + //The system automatically calibrates itself + calibrate(); + + // Initialize the sound player. Open the Serial Monitor to see + //the sound files found on your micro SD card + player.begin(); +} +void loop() { + //Loop through 4 pins and play the right sequence accordingly + for (int i = 0; i < pin_count; i++) { + int slot_value = analogRead(analog_pins[i]); + int sequence = getSeq(slot_value); + + //Get the right file name by sequence + filename[3] = '0' + sequence; + Serial.println(filename); + //Play the file + player.play(filename); + } + + //End of one loop + Serial.println("======="); +} + +void calibrate() { + delay(1000); + Serial.println("Begin Calibration"); + for (int i = 0; i < 4; i++) { + Serial.print("calibrating slot "); + Serial.println(i); + int val = 0; + do { + val = analogRead(analog_pins[i]); + Serial.println(i); + } while (val > 1010); + analog_values[i] = val; + } + for (int i = 0; i < 4; i++) { + for (int j = i; j < 4; j++) { + if (analog_values[i] > analog_values[j]) { + int temp = analog_values[i]; + analog_values[i] = analog_values[j]; + analog_values[j] = temp; + } + } + } + Serial.println("Done Calibration"); +} + +int getSeq(int analogVal) { + for (int i = 0; i < 4; i++) { + if (analogVal > analog_values[i] - 50 && analogVal < analog_values[i] + 50) { + return i + 1; + } + } + + return 0; + + /* + if(analogVal>200 && analogVal<300){ //220 Ohm + return 1; + }else if(analogVal>360 && analogVal<460){ //470 Ohm + return 2; + }else if(analogVal>480 && analogVal<580){ //680 Ohm + return 3; + }else if(analogVal>600 && analogVal<700){ //1k2 Ohm + return 4; + }else{ //No resistor + return 0; + } +*/ + //If you're using Arduino 101, the same resistors give + //different analog read values. Use the following code + //instead. + /* + if(analogVal>200 && analogVal<300){ //220 Ohm + return 1; + }else if(analogVal>400 && analogVal<500){ //470 Ohm + return 2; + }else if(analogVal>600 && analogVal<700){ //680 Ohm + return 3; + }else if(analogVal>800 && analogVal<900){ //1k2 Ohm + return 4; + }else{ //No resistor + return 0; + }*/ +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.1_standard_servo/_4.1_standard_servo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.1_standard_servo/_4.1_standard_servo.ino new file mode 100644 index 00000000..9187ff86 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.1_standard_servo/_4.1_standard_servo.ino @@ -0,0 +1,22 @@ +/* +* _4.1_standard_servo +* +* The board will control the servo to repeatedly move its arm between 0 and 180 degrees. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo myservo; + +void setup() { + myservo.attach(6); +} + +void loop() { + myservo.write(0); + delay(1000); + myservo.write(180); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.2_continuous_servo/_4.2_continuous_servo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.2_continuous_servo/_4.2_continuous_servo.ino new file mode 100644 index 00000000..ed66badb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.2_continuous_servo/_4.2_continuous_servo.ino @@ -0,0 +1,22 @@ +/* +* _4.2_continuous_servo +* +* The board will control the continuous rotation servo by writing a speed to it instead of a position. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo myservo; + +void setup() { + myservo.attach(6); +} + +void loop() { + myservo.write(0); + delay(1000); + myservo.write(180); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.3_input_controlled_servo/_4.3_input_controlled_servo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.3_input_controlled_servo/_4.3_input_controlled_servo.ino new file mode 100644 index 00000000..2da02d80 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.3_input_controlled_servo/_4.3_input_controlled_servo.ino @@ -0,0 +1,25 @@ +/* +* _4.3_input_controlled_servo +* +* The board will use a potentiometer to control the position of a standard servo. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo myservo; +int potPin = A5; +int val; + +void setup() { + myservo.attach(6); +} + +void loop() { + val = analogRead(potPin); + val = map(val, 0, 1023, 0, 179); + + myservo.write(val); + delay(15); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.4_two_servos/_4.4_two_servos.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.4_two_servos/_4.4_two_servos.ino new file mode 100644 index 00000000..a44819e7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.4_two_servos/_4.4_two_servos.ino @@ -0,0 +1,32 @@ +/* +* _4.4_two_servos +* +* The board will control two servos, moving one at a time to make sure that it can provide enough current. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo myservo1, myservo2; + +void setup() { + myservo1.attach(6); + myservo2.attach(9); +} + +void loop() { + myservo2.detach(); + myservo1.attach(6); + myservo1.write(70); + delay(1000); + myservo1.write(120); + delay(1000); + + myservo1.detach(); + myservo2.attach(9); + myservo2.write(70); + delay(1000); + myservo2.write(120); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino new file mode 100644 index 00000000..dd1f32a7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino @@ -0,0 +1,60 @@ +/* +* CameraRobot +* +* Spy on your cat with this robot camera. Mount the camera robot and +* control it with a small joystick. You can run everything from the +* computer and when you see your cat doing something suspicious, +* take a picture! +* +* You need to run the processing sketch included in the sketch folder +* to be able to take photos with a webcam connected to your computer. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The joystick uses two analog pins. Here pin A0 and A1 +Joystick joystick = Joystick(A1, A0); //Joystick(XanalogPin, YanalogPin) + +Servo pan, tilt; + +int panAngle = 90; //Pan angle starts in the middle position +int tiltAngle = 90; //Tilt angle starts in the middle position + +int panJoystick = 0; +int tiltJoystick = 0; + +void setup() { + //servos are initialized + pan.attach(6); + tilt.attach(9); +} +void loop() { + panJoystick = joystick.getX(); //Get X value from joystick + tiltJoystick = joystick.getY(); //Get Y value from joystick + + //If the joysticks X value isn't 0 we will pan + if (panJoystick != 0) { + //If the X value from the joystick equals 1 and + //panAngle is less than 180 degrees, increase panAngle with 1 + if (panJoystick == 1 && panAngle < 180) panAngle++; + //If the X value from the joystick equals -1 and + //panAngle is more than 0 degrees, decrease panAngle with 1 + else if (panJoystick == -1 && panAngle > 0) + panAngle--; + } + //If the joysYicks Y value is 0 we will tilt + if (tiltJoystick != 0) { + //If the Y value from the joystick equals 1 and + //tiltAngle is less than 180 degrees, increase tiltAngle with 1 + if (tiltJoystick == 1 && tiltAngle < 180) tiltAngle++; + //If the Y value from the joystick equals -1 and + //tiltAngle is more than 0 degrees, decrease tiltAngle with 1 + else if (tiltJoystick == -1 && tiltAngle > 0) + tiltAngle--; + } + pan.write(panAngle); //Set position of the pan servo + tilt.write(tiltAngle); //Set position of the tilt servo + delay(5); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CrawlingRobot/CrawlingRobot.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CrawlingRobot/CrawlingRobot.ino new file mode 100644 index 00000000..ed7540a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CrawlingRobot/CrawlingRobot.ino @@ -0,0 +1,35 @@ +/* +* CrawlingRobot +* +* This small robot can crawl. It’s all it can do, and it isn’t +* very good at it. But it is super cute and great fun. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo front, back; + +void setup() { + //servos are initialized + front.attach(6); + back.attach(9); +} + +void loop() { + //Make the robot crawl by setting the servos to opposite angles. + //90 is the middle angle + + //First step of each pair of legs + front.write(110); + delay(200); + back.write(70); + delay(200); + + //Second step of each pair of legs + front.write(70); + delay(200); + back.write(110); + delay(200); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LightChaser/LightChaser.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LightChaser/LightChaser.ino new file mode 100644 index 00000000..f2d80fca --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LightChaser/LightChaser.ino @@ -0,0 +1,41 @@ +/* +* LightChaser +* +* This little vehicle is on an impossible, never ending +* mission to catch the light. You can make it follow you +* by pointing a flashlight at it. (The one on your mobile +* phone eg.) It will always turn towards the light. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the two wheels of robot, left wheel to D6 and +// right wheel to D9 +Wheels wheels = Wheels(6, 9); + +//Declare the two LightSensor +LightSensor sensorLeft = LightSensor(A0); +LightSensor sensorRight = LightSensor(A2); + +void setup() { + //initialize the LightSensor + sensorLeft.config(600, 800); + sensorRight.config(600, 800); + + //initialize the servo motors + wheels.begin(); +} +void loop() { + if (sensorLeft.getState()) { + //Left LightSensor detects strong light, the vehicle turns left + wheels.turnLeft(); + } else if (sensorRight.getState()) { + //Right LightSensor detects strong light, the vehicle turns right + wheels.turnRight(); + } else { + //No strong light detected, the vehicle goes straight + wheels.goForward(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LineFollower/LineFollower.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LineFollower/LineFollower.ino new file mode 100644 index 00000000..7e5e9121 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LineFollower/LineFollower.ino @@ -0,0 +1,30 @@ +/* +* LineFollower +* The Line Follower does exactly what the name suggests, +* it follows a line. Make it go wherever you want by +* showing the way with a 3 cm wide, black line. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//IRArray(IR1, IR2, IR3) +IRArray ir = IRArray(A1, A2, A3); +//Wheels(left, right) +Wheels wheels = Wheels(6, 9); + +void setup() { + wheels.begin(); + + //Use this line to set the threshold of the IR sensors. The default is 380. If you're using Arduino 101 board, use 530 instead. + //Use test() to check the values of each sensor in loop() + ir.setThreshold(530); + + delay(1000); +} + +void loop() { + int dir = ir.readLine(); + wheels.follow(dir); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/MagicBox/MagicBox.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/MagicBox/MagicBox.ino new file mode 100644 index 00000000..4b5f4807 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/MagicBox/MagicBox.ino @@ -0,0 +1,43 @@ +/* +* MagicBox +* +* MagicBox is an open source box that contains open source +* electronics. Oh, and it automatically opens when you +* knock on it. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the piezo knock sensor. Connected to A0 +PiezoKnockSensor sensor = PiezoKnockSensor(A0); + +//Declare the servo motor for opening the lid +Servo lidOpener; + +void setup() { + //define the threshold and debounce time of the knock + //sensor. Threshold defines how hard you need to knock, + //debounce time prevents the sensor from detecting + //false knocks, but also limits how rapid you can knock. + //See the PiezoKnockSensor sketch in the help folder + //to make sure your values are correct + sensor.config(100, 80); + + //initialize the servo + lidOpener.attach(9); + //Rotate servo to close lid + lidOpener.write(60); +} +void loop() { + + if (sensor.knocked(20)) { + //rotate the servo motor to open the lid + lidOpener.write(0); + delay(3000); //Wait for 3 seconds + //close the lid + lidOpener.write(60); + delay(200); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/TickleRobot/TickleRobot.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/TickleRobot/TickleRobot.ino new file mode 100644 index 00000000..ac428541 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/TickleRobot/TickleRobot.ino @@ -0,0 +1,37 @@ +/* +* TickleRobot +* +* This is just a regular ticklish robot in a rocking chair. +* Come to think of it, that doesn't sound very regular at all. +* Tickle the robot on its heart and it will start to wiggle like crazy. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the servo for controlling the string robot +Servo pull; + +//Declare the capacitive sensor +CapacitiveSwitch sensor = CapacitiveSwitch(2, 3); + +void setup() { + //initialize the capacitive sensor. Threshold is 400 + //See the example CapacitiveSwitchTest in the Help folder + //to find the right threshold + sensor.config(400); + + //initialize the servo motor + pull.attach(9); +} +void loop() { + if (sensor.getState()) { + //If the capacitive sensor is touched, pull the strings + pull.write(0); + } else { + //Otherwise, loosen the strings + pull.write(90); + } + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.1_gyro_demo/_5.1_gyro_demo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.1_gyro_demo/_5.1_gyro_demo.ino new file mode 100644 index 00000000..40b224e0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.1_gyro_demo/_5.1_gyro_demo.ino @@ -0,0 +1,85 @@ +/* +* _5.1_gyro_demo +* +* The Piezo will play sound based on how fast you tilt the board in the X and Y axes. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + +IMU imu; // the IMU + +const int piezoPin = 8; //piezo + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + + +void setup() { + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed + + + Serial.begin(9600); // initialize Serial communication + while (!Serial) + ; // wait for the serial port to open + + + imu.begin(); + + + + + // blink the LED again to show that the calibration is done + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + + pinMode(piezoPin, OUTPUT); +} + +void loop() { + // start the IMU read + imu.run(); + + // read raw gyro measurements from the IMU device + int gx = imu.getGyroX(); + int gy = imu.getGyroY(); + + // map the raw value to be on a smaller scale + gx = map(gx, -36044, 36043, -360, 360); + gy = map(gy, -36044, 36043, -360, 360); + + + // print the measurements + Serial.print(gx); + Serial.print("\t"); + Serial.println(gy); + + + + //Computes the absolute value of the IMU read + gx = abs(gx); + gy = abs(gy); + + + + // add together the 2 values and use them for setting the frequency for the speaker to play + int frequency = gx + gy; + frequency = frequency / 2; + frequency = map(frequency, 0, 360, 0, 1000); + + // only play a sound if the frequency is not too low or the IMU is still + if (frequency > 50) { + tone(piezoPin, frequency); + } else { + noTone(piezoPin); // stop the sound + } + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.2_acc_demo/_5.2_acc_demo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.2_acc_demo/_5.2_acc_demo.ino new file mode 100644 index 00000000..c20d482b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.2_acc_demo/_5.2_acc_demo.ino @@ -0,0 +1,86 @@ +/* +* _5.2_acc_demo +* +* The Piezo will play sound based on how fast you move the board in the X and Y axes. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + + +IMU imu; // the IMU + +const int piezoPin = 8; //piezo + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + + +void setup() { + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed + + + Serial.begin(9600); // initialize Serial communication + while (!Serial) + ; // wait for the serial port to open + + + imu.begin(); + + + + + // blink the LED again to show that the calibration is done + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + + pinMode(piezoPin, OUTPUT); +} + +void loop() { + // start the IMU read + imu.run(); + + // read raw accel measurements from the IMU device + int ax = imu.getAccelerometerX(); + int ay = imu.getAccelerometerY(); + + // map the raw value to be on a smaller scale + ax = map(ax, -36044, 36043, -360, 360); + ay = map(ay, -36044, 36043, -360, 360); + + + // print the measurements + Serial.print(ax); + Serial.print("\t"); + Serial.println(ay); + + + + //Computes the absolute value of the IMU read + ax = abs(ax); + ay = abs(ay); + + + + // add together the 2 values and use them for setting the frequency for the speaker to play + int frequency = ax + ay; + frequency = frequency / 2; + frequency = map(frequency, 0, 360, 0, 1000); + + // only play a sound if the frequency is not too low or the IMU is still + if (frequency > 50) { + tone(piezoPin, frequency); + } else { + noTone(piezoPin); // stop the sound + } + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.3_pitchroll_demo/_5.3_pitchroll_demo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.3_pitchroll_demo/_5.3_pitchroll_demo.ino new file mode 100644 index 00000000..354ffdf7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.3_pitchroll_demo/_5.3_pitchroll_demo.ino @@ -0,0 +1,81 @@ +/* +* _5.3_pitchroll_demo +* +* The Piezo will now play sound based on how you angle the board in the two axes +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + + +IMU imu; // the IMU + +const int piezoPin = 8; //piezo + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + + +void setup() { + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on led to show that the board has executed + + + Serial.begin(9600); // initialize Serial communication + while (!Serial) + ; // wait for the serial port to open + + + imu.begin(); + + + + + // blink the LED again to show that the calibration is done + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + + pinMode(piezoPin, OUTPUT); +} + +void loop() { + // start the IMU read + imu.run(); + + // get the pitch and roll result from the filter + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + // print the measurements + Serial.print(pitch); + Serial.print("\t"); + Serial.println(roll); + + + + //Computes the absolute value of the IMU read + pitch = abs(pitch); + roll = abs(roll); + + + + // add together the 2 values and use them for setting the frequency for the speaker to play + int frequency = pitch + roll; + frequency = frequency / 2; + frequency = map(frequency, 0, 360, 0, 1000); + + // only play a sound if the frequency is not too low or the IMU is still + if (frequency > 50) { + tone(piezoPin, frequency); + } else { + noTone(piezoPin); // stop the sound + } + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.4_ble_demo/_5.4_ble_demo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.4_ble_demo/_5.4_ble_demo.ino new file mode 100644 index 00000000..11cf5325 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.4_ble_demo/_5.4_ble_demo.ino @@ -0,0 +1,42 @@ + +/* +* _5.4_ble_demo +* +* The board will now store a message that is sent to it and send it back to anyone connecting to it +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +BLEuart ble = BLEuart(TYPE_MESSENGER); + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + ble.setName("Message"); + ble.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + if (ble.searchCentral()) { + Serial.println("Connected to central "); + while (ble.connected()) { + + //When receiving data from mobile app, write it + //back to the sender + if (ble.dataReceived()) { + ble.fetchData(); + Serial.println(ble.receivedString()); + char data[20]; + int length = ble.getReceivedLength(); + for (int i = 0; i < length; i++) { + data[i] = ble.receivedString()[i]; + } + ble.sendString(data, length); + } + } + Serial.println(F("Disconnected from central ")); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.5_ble_valueDisplay/_5.5_ble_valueDisplay.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.5_ble_valueDisplay/_5.5_ble_valueDisplay.ino new file mode 100644 index 00000000..734df3f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.5_ble_valueDisplay/_5.5_ble_valueDisplay.ino @@ -0,0 +1,64 @@ +/* +* _5.5_ble_valueDisplay +* +* The 101 board monitors the status of a button connected to digital pin 9, +* a press counter, and a light sensor connected to pin A0. +* The 3 values are sent through the BLE in such sequence, +* and the app reads the values in the same sequence. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +#include + +BLEuart ble = BLEuart(); + +Button button(9); + +int count; + +void setup() { + Serial.begin(9600); + + // Curie BLE setup + // set advertised local name + ble.setName("valDisp"); + ble.begin(); + + button.begin(); + + count = 0; +} + +void loop() { + // if a central is connected to peripheral: + if (ble.searchCentral()) { + Serial.println("Connected to central "); + // while the central is still connected to peripheral: + while (ble.connected()) { + //Get readings from sensors + int buttonValue = button.getState(); + int lightValue = analogRead(A1); + + //Value Display can only pass numbers smaller than 255 + lightValue = map(lightValue, 0, 1023, 0, 255); + + //Check if the button is being pressed, and update the + //counter accordingly + if (button.isPressed()) { + count++; + } + + + //Note the sequence of data being sent, the phone app displays + //the values in the same sequence. + ble.addValue(buttonValue); + ble.addValue(count); + ble.addValue(lightValue); + ble.send(); + } + // when the central disconnects, print it out: + Serial.println(F("Disconnected from central ")); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.6_ble_CustomControl/_5.6_ble_CustomControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.6_ble_CustomControl/_5.6_ble_CustomControl.ino new file mode 100644 index 00000000..4218f3ac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.6_ble_CustomControl/_5.6_ble_CustomControl.ino @@ -0,0 +1,43 @@ +/* +* _5.5_ble_valueDisplay +* +* This example shows how to receive data in the Arduino 101. When you tap the buttons in the CTC app Custom +* Control interface, the values associated with the buttons will be received by 101 in the form of a +* one char sized array. The value is displayed to Serial Monitor afterwards. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +BLEuart ble = BLEuart(); + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + + // Curie BLE setup + // set advertised local name + ble.setName("CustomC"); + ble.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + if (ble.searchCentral()) { + Serial.println("Connected to central "); + while (ble.connected()) { + + //If data is sent through BLE to 101 board + if (ble.dataReceived()) { + //Fetch all data from BLE + ble.fetchData(); + + //Read the 1 byte data received + unsigned char data = ble.getValueAt(0); + Serial.println(data); + } + } + Serial.println(F("Disconnected from central ")); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/AsteroidAttack/AsteroidAttack.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/AsteroidAttack/AsteroidAttack.ino new file mode 100644 index 00000000..25cefe7d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/AsteroidAttack/AsteroidAttack.ino @@ -0,0 +1,72 @@ +/* +* AsteroidAttack +* +* You will create a retro style space +* shooter game, and learn about how to use classes and functions. In the end you will be able to +* tweak values and rewrite the program to redesign the game so it suits your taste. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + +IMU imu; // the IMU + +Button button(6); +int buttonState = 0; + + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + +void setup() { + Serial.begin(9600); // initialize Serial communication + + imu.begin(); + button.begin(); + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on led to show that the board has executed +} + +void loop() { + + // read raw gyro measurements from device + imu.run(); + + + // get the gyro result from the filter and convert them into INT + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + //Check buttons + if (button.isPressed()) { + buttonState = true; + } + + // when Serial is open, send a "s" to processing + if (Serial.available() > 0) { + int val = Serial.read(); + if (val == 's') { // if incoming serial is "s" + Serial.print(roll); + Serial.print(","); + + + Serial.print(buttonState); + Serial.print(","); + Serial.println(""); + + buttonState = 0; + } + } + + + + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/NovaBeam/NovaBeam.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/NovaBeam/NovaBeam.ino new file mode 100644 index 00000000..933ff42d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/NovaBeam/NovaBeam.ino @@ -0,0 +1,117 @@ +/* +* NovaBeam +* +* Ever wondered what it might be like to swing a laser beam? Then this project is for you! See +* yourself play with the Nova Beam on screen, and listen to the awesome sounds it makes. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +IMU imu; // the IMU +Button toggleButton(10); + +int piezoPin = 8; //piezo + +bool toggleState = false; + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + +//smoothing function +const int numReadings = 50; +int readings[numReadings]; // the readings from the analog input +int readIndex = 0; // the index of the current reading + +//int total2,average2; + +void setup() { + Serial.begin(9600); // initialize Serial communication + + imu.begin(); + toggleButton.begin(); + + //smoothing function + // initialize all the readings to 0: + for (int i = 0; i < numReadings; i++) { + readings[i] = 0; + } + + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed +} + +void loop() { + // start the IMU read + imu.run(); + + // read raw accel measurements from the IMU device + int ay = imu.getAccelerometerY(); + + // map the raw value to be on a smaller scale + ay = map(ay, -36044, 36043, -360, 360); + + // read from the sensor: + readings[readIndex] = ay; + // advance to the next position in the array: + readIndex = readIndex + 1; + // if we're at the end of the array... + if (readIndex >= numReadings) { + // ...wrap around to the beginning: + readIndex = 0; + } + + // get the total of last 10 readings + int total = 0; + for (int i = 0; i < numReadings; i++) { + total += readings[i]; + } + // calculate the average: + int average = total / numReadings; + + // map the average to a scale for the frequency for the piezo + int frequency = map(abs(average), 0, 360, 200, 700); + + + if (toggleButton.isPressed()) { + //toggle the button each time its pressed + toggleState = !toggleState; + } + + if (toggleState) { + //play sound based on the average reading for the ay value + tone(piezoPin, frequency); + } else { + //turn off the sound + noTone(piezoPin); + } + + // get the gyro result from the filter and convert them into INT + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + // when Serial is open, check for a 's' from Procssing + if (Serial.available() > 0) { + int val = Serial.read(); + if (val == 's') { // if incoming serial is "s" + + // print the roll,pitch and toggleState to the Procssing + Serial.print(average); + Serial.print(","); + Serial.print(pitch); + Serial.print(","); + Serial.print(toggleState); + Serial.print(","); + Serial.println(""); + } + } + + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/PlanetFinder/PlanetFinder.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/PlanetFinder/PlanetFinder.ino new file mode 100644 index 00000000..9b04e9e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/PlanetFinder/PlanetFinder.ino @@ -0,0 +1,147 @@ +/* +* PlanetFinder +* +* The universe is big, really big, so if you are ever going to be able to find any planets then you'll +* need a tool track them down for you. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + +IMU imu; // the IMU + +bool blinkState = false; // state of the LED +const int ledPin = 13; // activity LED pin +const int piezoPin = 8; //piezo +const int redPin = 6; // the red LED +int piezoState = LOW; // piezoState used to set the piezo + +bool newGame = true; +int x = 0; +int y = 0; +const int errorMargin = 10; + +unsigned long previousMillis = 0; // last time the click played, in ms + + +// notes in the melody: +int melody[] = { + 196, 196, 262 +}; + +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations[] = { + 8, 8, 4 +}; + + +void setup() { + Serial.begin(9600); // initialize Serial communication + + + imu.begin(); + + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed + + pinMode(piezoPin, OUTPUT); // sets piezo + pinMode(redPin, OUTPUT); // sets red LED + randomSeed(analogRead(0)); // initializes the pseudo-random number generator +} + +void loop() { + + // start the IMU read + imu.run(); + + // get the pitch and roll result from the filter + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + + // new round the game + if (newGame) { + + //pick goal + x = random(-180, 180); + y = random(-90, 90); + newGame = false; + } + + + // print the roll/pitch and the target roll/pitch needed for debugging only + Serial.print("roll:"); + Serial.print(roll); + Serial.print("\t"); + Serial.print("pitch:"); + Serial.print(pitch); + Serial.print("\t"); + + Serial.print("Target roll:"); + Serial.print(x); + Serial.print("\t"); + Serial.print("Target pitch:"); + Serial.println(y); + + + // calculate how close the gyro is to the goal values + + //Computes the value of the IMU reads and the goal target + int absoluteRollDiff = abs(roll - x); + int absolutePitchDiff = abs(pitch - y); + int closeTogoal = absoluteRollDiff + absolutePitchDiff; + + + + // click in shorter intervals the closer the gyro read is to the goal + unsigned long currentMillis = millis(); + if (currentMillis - previousMillis >= closeTogoal) { + // save the last time you clicked the piezo + previousMillis = currentMillis; + + // if the piezo is off turn it on and vice-versa: + if (piezoState == LOW) { + piezoState = HIGH; + } else { + piezoState = LOW; + } + + digitalWrite(piezoPin, piezoState); + digitalWrite(redPin, piezoState); + } + + // if the gyro value is at the goal + if (closeTogoal <= errorMargin) { + + Serial.print("Win"); + + + // play the win tune + for (int thisNote = 0; thisNote < 3; thisNote++) { + + // to calculate the note duration, take one second + // divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 1000 / noteDurations[thisNote]; + tone(piezoPin, melody[thisNote], noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.30; + delay(pauseBetweenNotes); + // stop the tone playing: + noTone(piezoPin); + } + // a new goal and new game round is needed + newGame = true; + } + + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ShipNavigator/ShipNavigator.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ShipNavigator/ShipNavigator.ino new file mode 100644 index 00000000..1e603239 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ShipNavigator/ShipNavigator.ino @@ -0,0 +1,164 @@ +/* +* ShipNavigator +* +* To find your way around space safely, your ship will need a navigator. Follow your ship’s AI +* instructions to navigate your ship without crashing it into anything. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Player player = Player(); // for playing sounds +IMU imu; // the IMU + + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + +bool up, down, left, right; //used for checking if the board has been moved in any direction +int moveTask = 1; //used for picking what direction should be done +bool newMove = false; // used for checking if a newMove is needed + +long lastTimer; //used for saving millis() + +void setup() { + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on led to show that the board has executed + + + Serial.begin(9600); // initialize Serial communication + + + imu.begin(); + + + //Initialize the sound player + player.begin(); + + randomSeed(analogRead(0)); // initializes the pseudo-random number generator +} + +void loop() { + // read raw rollro measurements from device + imu.run(); + // get the pitch and roll result from the filter + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + Serial.print("roll:"); + Serial.print(pitch); + Serial.print("\t"); + Serial.print("pitch:"); + Serial.println(roll); + + // short pause before the next round start + if (!newMove) { + Serial.println("New round"); + + delay(1000); + } + + + + + // check if the board has been tilted in any direction and set the direction bools accordingly + if (pitch < -45) { + up = true; + down = false; + left = false; + right = false; + } else if (pitch > 45) { + up = false; + down = true; + left = false; + right = false; + } else if (roll < -45) { + up = false; + down = false; + left = true; + right = false; + } else if (roll > 45) { + up = false; + down = false; + left = false; + right = true; + } else { + up = false; + down = false; + left = false; + right = false; + } + + + // if a new move is needed, generate random direction and play the sound for that direction + if (!newMove) { + // picks a random number from 1 to 4 + moveTask = random(1, 5); + + //Playsound + if (moveTask == 1) { + Serial.println("move up"); + player.play("up.wav"); + + } else if (moveTask == 2) { + Serial.println("move down"); + player.play("down.wav"); + + } else if (moveTask == 3) { + Serial.println("move left"); + player.play("left.wav"); + + } else if (moveTask == 4) { + Serial.println("move right"); + player.play("right.wav"); + } + + newMove = true; // a new move is created + lastTimer = millis(); // reset the 3 sec timer + } + + // check if the random direction and the direction the board moved in is the same + if (up && moveTask == 1) { + Serial.println("up"); + newMove = false; + } + if (down && moveTask == 2) { + Serial.println("down"); + newMove = false; + } + if (left && moveTask == 3) { + Serial.println("left"); + newMove = false; + } + if (right && moveTask == 4) { + Serial.println("right"); + newMove = false; + } + + + // if the right move is not done before the 3 sec timer, reset the newMove bool and the timer to start a new round + if (millis() - lastTimer >= 3000) { + + if (newMove) { + Serial.println("To slow"); + //Play the sound for being too slow + player.play("slow.wav"); + newMove = false; + } + + lastTimer = millis(); + } + + + + + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + + delay(250); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/SpaceRover/SpaceRover.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/SpaceRover/SpaceRover.ino new file mode 100644 index 00000000..00324ae8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/SpaceRover/SpaceRover.ino @@ -0,0 +1,72 @@ +/* +* SpaceRover +* +* Getting around on alien planets can be difficult. +* You are going to need a rover to investigate these new alien worlds. +* Now you will be able to control the rover to explore alien planets. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +BLEuart ble = BLEuart(TYPE_LOGOROBOT); + +Wheels wheels = Wheels(6, 9); + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + ble.setName("Rover"); + ble.begin(); + + wheels.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + if (ble.searchCentral()) { + Serial.println("Connected to central "); + while (ble.connected()) { + if (ble.dataReceived()) { + ble.fetchData(); + + Serial.print("Received number of commands: "); + Serial.println(ble.getReceivedLength()); + + for (int i = 0; i < ble.getReceivedLength(); i++) { + unsigned char n = ble.receivedString()[i]; + + Serial.print(n); + + logoMove(n); + } + Serial.println(); + } + } + Serial.println(F("Disconnected from central ")); + } +} + +void logoMove(unsigned char direction) { + switch (direction) { + case 1: //forward + wheels.goForward(); + delay(750); + break; + case 2: //backwards + wheels.goBackwards(); + delay(750); + break; + case 3: //left + wheels.turnLeft(); + delay(250); + break; + case 4: //right + wheels.turnRight(); + delay(250); + break; + } + wheels.standStill(); + delay(300); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ZazzTheAlien/ZazzTheAlien.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ZazzTheAlien/ZazzTheAlien.ino new file mode 100644 index 00000000..0666968e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ZazzTheAlien/ZazzTheAlien.ino @@ -0,0 +1,103 @@ +/* +* ZazzTheAlien +* +* It is a lot of responsibility, but now you will have to take care of the alien baby. This particular +* alien baby communicates with Bluetooth. You need to make sure it has proper exercises, gets +* enough food and sleep. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +BLEuart ble = BLEuart(TYPE_TAMAGOTCHI); +IMU imu; + +//const int lightPin = A0; //phototransistor +LightSensor sleepSensor(A1); + +Button foodButton(9); + +int exerciseLv, foodLv, sleepLv; // the saved stats that will go down over time + +long sleepTimer; +long updateTimer; + +void setup() { + Serial.begin(9600); + + // Curie IMU setup + imu.begin(); + imu.detectShock(); + imu.attachCallback(shockCallback); + + // set advertised local name + ble.setName("Zazz"); + ble.begin(); + + foodButton.begin(); + + sleepSensor.config(1000, 200); + + //Set initial values for the three states + exerciseLv = 100; + foodLv = 100; + sleepLv = 100; + + updateTimer = millis(); + sleepTimer = millis(); +} + +void loop() { + + updateStatus(); // used to update the stats values + + // if a central is connected to peripheral: + if (ble.searchCentral()) { + Serial.println("Connected to central "); + // while the central is still connected to peripheral: + while (ble.connected()) { + updateStatus(); // used to update the stats values + Serial.println("Sending data"); + ble.addValue(exerciseLv); + ble.addValue(foodLv); + ble.addValue(sleepLv); + ble.send(); + } + // when the central disconnects, print it out: + Serial.println(F("Disconnected from central ")); + } +} + +void updateStatus() { + // if the light level is low, add 1 to the sleepLv + if (sleepSensor.getState() && millis() - sleepTimer > 200) { + sleepLv++; + sleepTimer = millis(); + } + + //Fill the food stat when the button is being pressed + if (foodButton.isPressed()) { + foodLv += 5; + } + + // every 3 sec update and lower the 3 stats in different rates + if (millis() - updateTimer >= 3000) { + exerciseLv = exerciseLv - 1; + foodLv = foodLv - 2; + sleepLv = sleepLv - 3; + + updateTimer = millis(); + } + + //Constrain the values so they don't exceed 100 or go below 0 + exerciseLv = constrain(exerciseLv, 0, 100); + foodLv = constrain(foodLv, 0, 100); + sleepLv = constrain(sleepLv, 0, 100); +} + +// this is called when the IMU detects a shock in any direction +static void shockCallback(void) { + //add 1 to the exerciseLv + exerciseLv++; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Button/Button.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Button/Button.ino new file mode 100644 index 00000000..44b80f4d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Button/Button.ino @@ -0,0 +1,61 @@ +/* +* Button +* A button is a digital input. This means that it can have two +* states, either HIGH (5 V in Uno, 3 V in 101) or LOW (0 V). When +* you connect a button to your control board you can read these +* states as 1 or 0. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the button component. +//6 is the pin number. If it's a button module, use 6 or 9. +//HIGH can be ignored mostly, which means when the button is +//pressed, what state it is in. +Button me = Button(6, HIGH); + +void setup() { + Serial.begin(9600); + + while (!Serial) + ; + + //Initialize the component. Must be called. + me.begin(); +} +void loop() { + Serial.println("Please press..."); + //pressed(timeout) + // timeout: milliseconds within which the button should + // be pressed. If pressed within time, the function + // returns 1, otherwise 0. If not used, it waits + // until being pressed. + // + //Wait until the button is pressed. + Serial.println(me.pressed()); + + + Serial.println("Please release..."); + //released(timeout) + // timeout: same as in pressed(timeout). + // + //Wait until the button is released. + Serial.println(me.released()); + + Serial.println("Press a few times..."); + //beenPressed() + // + //Check if the button has been pressed without blocking the + //sketch execution. Useful when press detection is not part + //of the main program logic. + long timer = millis(); + int counter = 0; + while (millis() - timer < 3000) { + if (me.isPressed()) { + counter++; + } + } + Serial.println(counter); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/ButtonGroup/ButtonGroup.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/ButtonGroup/ButtonGroup.ino new file mode 100644 index 00000000..9d6cf584 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/ButtonGroup/ButtonGroup.ino @@ -0,0 +1,39 @@ +/* +* ButtonGroup +* ButtonGroup is used for making a few buttons work together. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declaring the button group +ButtonGroup bg; + +//Declaring the pins to which the buttons are connected +int buttons[] = { 4, 5, 6 }; + +void setup() { + Serial.begin(9600); + + while (!Serial) + ; + + //initialize the button group. The first parameter is + //number of buttons, the second is the array containing + //pins used by these buttons. + bg.begin(3, buttons); +} +void loop() { + Serial.println("Please press a button"); + //pressed(timeout) + // timeout:milliseconds within which one button should + // be pressed. If pressed within time, the function + // returns number of the button within initial list. + // Otherwise -1. If not used, it waits until being + // pressed. + // + //Wait until one button is pressed. + Serial.println(bg.pressed()); + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitch/CapacitiveSwitch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitch/CapacitiveSwitch.ino new file mode 100644 index 00000000..c882047c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitch/CapacitiveSwitch.ino @@ -0,0 +1,64 @@ +/* CapacitiveSwitch +* +* CapacitiveSwitch can be constructed in various ways. +* Typically a 1 million ohm resistor between sender pin +* and receiver pin(we use 2 as sender, 3 as receiver +* here), and conductive material connected to the receive +* pin. +* +* When you touch the conductive material with your hand, or +* other objects (should be conductive), the sensor will +* get a different reading. +* +* The library includes some features for using the +* capacitive sensor as a button, or getting values directly. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The sensor is connected between 2 and 3 by default +CapacitiveSwitch me = CapacitiveSwitch(2, 3); + +void setup() { + Serial.begin(9600); + + while (!Serial) + ; + + //Config the sensor, set threshold for the sensor used as + //button. If sensor reading passes it, it's counted as + //being pressed/released + me.config(400); +} +void loop() { + Serial.println("Please press..."); + //pressed(timeout) + // timeout: milliseconds within which the sensor should + // be pressed. If pressed within time, the function + // returns 1, otherwise 0. If not used, it waits + // until being pressed. + // + //Wait until the capacitive sensor is pressed. + Serial.println(me.pressed()); + + delay(1000); + + Serial.println("Please release..."); + //released(timeout) + // timeout: same as in pressed(timeout). + // + //Wait until the capacitive sensor is released. + Serial.println(me.released()); + + do { + //getValue(minimum) + // minimum: minimum value that needs to be returned. If + // the sensor reading is smaller than minimum, it'll + // return 0. + // + //Print values bigger than 20. Print 0 otherwise. + Serial.println(me.getValue(20)); + } while (true); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitchTest/CapacitiveSwitchTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitchTest/CapacitiveSwitchTest.ino new file mode 100644 index 00000000..a656e862 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitchTest/CapacitiveSwitchTest.ino @@ -0,0 +1,30 @@ +/* CapacitiveSwitch Test +* +* When making use of sensor readings from CapacitiveSwitch, +* This sketch helps you decide the threshold by showing +* capacitive values of different materials. +* +* Just touch the objects you're going to experiment with, +* take note of the biggest and smallest values. In your +* project code, use these values to map to your desired +* outcome. +* +* It can also be used for adjusting the threshold when using +* capacitive sensor as a button. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The sensor is connected between 2 and 3 by default +CapacitiveSwitch me = CapacitiveSwitch(2, 3); + +void setup() { + Serial.begin(9600); +} +void loop() { + //Print out the value of the sensor + me.test(); + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/ContinuousServo/ContinuousServo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/ContinuousServo/ContinuousServo.ino new file mode 100644 index 00000000..1d7949fb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/ContinuousServo/ContinuousServo.ino @@ -0,0 +1,35 @@ +/* ContinuousServo +* +* Continuous servo looks the same as a standard servo, but it's +* capable of rotating continuously like a normal motor. You can not +* control which angle it's pointing to, but you can specify how +* fast it spins, and which direction it spins. +* +* To control two servos as wheels on a vehicle please see the +* example Wheels in the Help folder. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo me; + +void setup() { + //Servo is initialized, + //in this example connected to digital pin 9 + me.attach(9); +} + +void loop() { + //write(speed): + // speed: the speed in which you want to rotate + // the servo. It is ranged between 0 and 180. + // 180 is fastest speed in one direction and 0 + // fastest speed in the opposite direction. + // 90 should make it stand still. This exact + // value is slightly different for each servo. + // + //Make the servo rotate in speed 120. + me.write(120); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/IRArray/IRArray.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/IRArray/IRArray.ino new file mode 100644 index 00000000..7647ea70 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/IRArray/IRArray.ino @@ -0,0 +1,35 @@ +/* +* IRArray +* This program will print each IR sensor reading to the +* Serial Monitor. +* +* When you hold the IRarray over a white surface all sensors +* should give you a value of 400. When held over a black surface +* it should go down to around 330. Make sure that you've +* connected all sensor pins right by alternate each sensor +* between black and white and see the that values of the +* corresponding IR sensor is changing. E.g. if you move IR1 from +* black to white but only the value of IR2 is changed you need +* to either change the analog pins in the code or change the +* connections to the analog pins on the control board. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//IRArray(IR1, IR2, IR3) +IRArray ir = IRArray(A1, A2, A3); + +void setup() { + + //Use this line to set the threshold of the IR sensors. The default is 380. If you're using Arduino 101 board, use 530 instead. + //Use test() to check the values of each sensor in loop() + ir.setThreshold(530); + + Serial.begin(9600); +} + +void loop() { + ir.test(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Joystick/Joystick.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Joystick/Joystick.ino new file mode 100644 index 00000000..b7879baf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Joystick/Joystick.ino @@ -0,0 +1,25 @@ +/* Joystick +* The joystick is one component but uses two analog sensors and +* gives you two values. One x value and one y value. The value +* for each direction is zero if it’s in the middle, -1 on one side +* and 1 on the other side. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The joystick uses two analog pins. One for X and one for Y. +Joystick me = Joystick(A1, A0); + +void setup() { + //Start serial communication to be able to print values to the Serial Monitor + Serial.begin(9600); +} +void loop() { + Serial.print("X: "); + Serial.print(me.getX()); //Get the X value and print it. + Serial.print(" Y: "); + Serial.println(me.getY()); //Get the Y value and print it. + delay(200); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Knob/Knob.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Knob/Knob.ino new file mode 100644 index 00000000..f33a4aa9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Knob/Knob.ino @@ -0,0 +1,45 @@ +/* +* Knob +* +* The Knob class is used for working with potentiometers. It provides +* functionalities to divide the raw value into a set amount of levels, +* which is helpful when a set of options are picked by the level of +* the knob. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Knob pot = Knob(A5); //a knob is connected to A5 + +void setup() { + Serial.begin(9600); + + //setLevels(levels) + // levels: the amount of levels needed. So the possible output of the + // knob will be between 0 and levels + // + //Initializing the knob with total number of levels + pot.setLevels(10); +} + +void loop() { + //getValue() + // + //Return the current reading of the knob. Same as analogRead() + int a = pot.getValue(); + + //getLevel() + // + //Return the current level. It ranges between 0 and the max levels, as + //pre-configured by Knob.setLevels(). + int b = pot.getLevel(); + + Serial.print("Analog: "); + Serial.print(a); + Serial.print(" Level: "); + Serial.println(b); + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/LightSensor/LightSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/LightSensor/LightSensor.ino new file mode 100644 index 00000000..b24c1c31 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/LightSensor/LightSensor.ino @@ -0,0 +1,68 @@ +/* +* LightSensor +* +* LightSensor is a sensor that reads the intensity of light. +* It gives analog reading. When connected with analog +* pins, its value ranges from 0 to 1023 depending on the amount +* of light shining on it. +* +* The EducationShield library includes some features for +* using the LightSensor as a button, or get values directly. See +* the example LightSensorTest for more information about how to +* configure it correctly. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Phototransistor component is connected to analog 1. +LightSensor sensor = LightSensor(A1); + +void setup() { + + Serial.begin(9600); + + //LDR needs to be configured with baseValue + //and threshold. See LightSensorTest sketch for + //details. + sensor.config(700, 900); +} + +void loop() { + Serial.println("Please press..."); + + //pressed(timeout) + // timeout: milliseconds within which the + // phototransistor should be cover-uncovered. If + // cover-uncovered within time, the + // function returns 1, otherwise 0. If + // not used, it waits until being + // cover-uncovered. + // + //Wait until the phototransistor gets cover-uncovered. + Serial.println(sensor.pressed()); + + Serial.println("Please release..."); + + //released(timeout) + // timeout: same as in pressed(timeout). + // + //Wait until the phototransistor gets uncover-covered. + Serial.println(sensor.released()); + + + while (true) { + //getState() + // returns whether the sensor readings has + // passed the threshold. Returns true if the + // threshold has been passed, false if not. + // Unlike pressed or released, this function + // does not stop the whole program. + // + //Continuously output whether the sensor has + //passed threshold. + Serial.println(sensor.getState()); + delay(30); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/LightSensorTest/LightSensorTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/LightSensorTest/LightSensorTest.ino new file mode 100644 index 00000000..b2ddfad4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/LightSensorTest/LightSensorTest.ino @@ -0,0 +1,40 @@ +/* LightSensor test +* This sketch should be used prior to using the component in +* Projects. Projects suitable for this library should have 2 +* states: uncovered and covered. That is to say, you want to +* track objects covering/moving past the sensor. +* +* HOW-TO: +* Upload this sketch to the control board, open the Serial Monitor. You +* will see the current value of the phototransistor. +* +* Make sure the sensor is in its desired setting and not +* moving. When the value gets stable, take note of it (we call +* it "baseValue"). +* +* Now cover the sensor with desired object. When the value +* gets stable, take note of it (topValue). Remember these values +* and use them when configuring. +* +* "baseValue" and "threshold" will be used for defining the +* LightSensor switch in your project. You can fine tune the +* threshold to make the sensor more/less sensitive. The closer +* to baseValue, the more sensitive it is. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Phototransistor module is connected to analog 1. +LightSensor sensor = LightSensor(A1); + +void setup() { + Serial.begin(9600); +} + +void loop() { + //test() prints data to Serial port. + sensor.test(); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Melody/Melody.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Melody/Melody.ino new file mode 100644 index 00000000..771f6a4b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Melody/Melody.ino @@ -0,0 +1,71 @@ +/* Melody +* +* For playing sound with a piezo. +* +* Connect one pin of the piezo to a digital pin +* (8 in this example) and the other pin to ground. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//pitches.h includes the definition of notes. Put it in your sketch +//folder if you want to play music. +#include "pitches.h" + +//Declaring the component. 8 is the pin the piezo is connected to. +Melody me = Melody(8); + +void setup() { +} + +void loop() { + //Defining the notes used in the music. No more than 30. + int notes[] = { + NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 + }; + + //Duration of each note. should be corresponding to the notes above. + int noteDurations[] = { + 4, 8, 8, 4, 4, 4, 4, 4 + }; + + //play(length, notes, duration, speed) + // length: number of notes in your music. + // notes: the array of notes. + // noteDuration: the array of note duration + // speed: how fast the music plays. No less than 1.0, the bigger the slower + // + //Play the notes defined above + me.play(8, notes, noteDurations, 1.4); + + delay(3000); + + //beep(length) + // length: how long the beep goes. Default to 30. + // + //Make a beep sound + me.beep(); + + delay(1000); + //effect_win() + // + //Make a win sound effect + me.effect_win(); + + delay(1000); + //effect_gameover() + // + //Make a gameover sound effect + me.effect_gameover(); + + delay(1000); + //effect_score() + // + //Make a scoring sound effect + me.effect_score(); + + + delay(3000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Melody/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Melody/pitches.h new file mode 100644 index 00000000..f3037d5e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Melody/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/PiezoKnockSensor/PiezoKnockSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/PiezoKnockSensor/PiezoKnockSensor.ino new file mode 100644 index 00000000..8795dfca --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/PiezoKnockSensor/PiezoKnockSensor.ino @@ -0,0 +1,43 @@ +/* +* Piezo Knock Sensor +* Piezo can play music, as well as be used as knock sensor. +* +* Connect the red pin of the piezo to a 1M ohm resistor, +* and the resistor to an analog pin (A5 in this example), +* the other pin to GND. Connect a 3.3 V Zener diode in +* parallel to the piezo and resistor circuit, with its +* anode to GND, cathode to A5. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Remember: Piezo as speaker is connected to digital pin +//while piezo as knock sensor is connected to analog pin. +PiezoKnockSensor sensor = PiezoKnockSensor(A0); + +void setup() { + Serial.begin(9600); + + while (!Serial) + ; + + //define the threshold and debounce time of the knock + //sensor. Threshold defines how hard you need to knock, + //debounce time prevents the sensor from returning several + //hits from one knock, but also limits how rapid you can knock. + sensor.config(120, 80); +} +void loop() { + Serial.println("Please knock..."); + + //knocked(timeout) + // timeout: milliseconds within which the sensor should + // be knocked. If knocked within time, the function + // returns 1, otherwise 0. If not used, it waits + // until being knocked. + // + //Wait until the button is knocked. + Serial.println(sensor.knocked()); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Player/Player.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Player/Player.ino new file mode 100644 index 00000000..d3c1ae76 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Player/Player.ino @@ -0,0 +1,29 @@ +/* Player +* You can play a sound from an SD card using the Player class. +* The sound file need to be 8bit, uncompressed WAV. Follow this +* tutorial to record and prepare your sound correctly: +* http://web.archive.org/web/20150731231913/http://cuartielles.com/verkstad/en/Reference/PrepareWavSound +* +* Or use one of the .wav files in the BoomBox example. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Player player = Player(); + +void setup() { + //Initialize the sound player + player.begin(); +} + +void loop() { + //play(filename) + // filename: filename of the sound stored in SD card + // must be a .wav file + // + //Play the file named "0.wav" on SD card + player.play("0.wav"); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Serialportsend/Serialportsend.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Serialportsend/Serialportsend.ino new file mode 100644 index 00000000..2c958eb6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Serialportsend/Serialportsend.ino @@ -0,0 +1,17 @@ +/* Serialportsend +* +* connect a potentiometer to your board and you will check its value by using Processing +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + + Serial.begin(9600); +} + +void loop() { + // send to port + Serial.write(analogRead(A5) / 4); + delay(1); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/StandardServo/StandardServo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/StandardServo/StandardServo.ino new file mode 100644 index 00000000..922434de --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/StandardServo/StandardServo.ino @@ -0,0 +1,31 @@ +/* +* StandardServo +* + * 180º standard servos are a type of motor which have a limited +* rotation angle. It has precise control over the angle of rotation. +* +* The ones provided for Education Shield projects are +* microservos. Microservos behave the same as a standard servo, +* but are slimmer in size and exert less turning power. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo me; + +void setup() { + //Servo is initialized, + //in this example connected to digital pin 9 + me.attach(9); +} + +void loop() { + //write(angle): + // angle: the angle to which you want to rotate + // the servo. It is ranged between 0 and 180. + // + //Make the servo rotate to 76 degrees. + me.write(76); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/TiltSwitch/TiltSwitch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/TiltSwitch/TiltSwitch.ino new file mode 100644 index 00000000..7ecc71f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/TiltSwitch/TiltSwitch.ino @@ -0,0 +1,35 @@ +/* TiltSwitch +* +* Tilt Switch is a component that detects if it’s right side up +* or tilted. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the tilt switch. A tilt switch module can be +//connected to D6 or D9 (We use D9 here). +TiltSwitch me = TiltSwitch(9); + +void setup() { + Serial.begin(9600); + + while (!Serial) + ; + + //Initialize the component. Must be called. + me.begin(); +} +void loop() { + Serial.println("Please tilt..."); + + //pressed(timeout) + // timeout: milliseconds within which the tilt switch should + // be tilted. If tilted within time, the function + // returns 1, otherwise 0. If not used, it waits + // until being pressed. + // + //Wait until the tilt switch is tilted. + Serial.println(me.pressed()); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/UltrasonicSensor/UltrasonicSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/UltrasonicSensor/UltrasonicSensor.ino new file mode 100644 index 00000000..6ba57852 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/UltrasonicSensor/UltrasonicSensor.ino @@ -0,0 +1,35 @@ +/* +* Ultrasonic Sensor +* An ultrasonic sensor is used to detect the distance to the +* closest object in front of the sensor. It uses ultrasound, +* sound with a frequency higher than humans can hear. As you +* probably know, sound can reflect from surfaces creating an +* echo. This echo is what the sensor uses to estimate the +* distance. The sensor sends out a burst of ultrasound and +* then waits for the echo. By knowing the speed of sound and +* the time between the burst and the detection we can +* calculate the distance. The shorter time it takes to detect +* the echo, the closer the object is. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the ultrasonic sensor with the trigger pin connected to +// digital pin 11, and the echo pin to digital pin 12. +UltrasonicSensor us = UltrasonicSensor(11, 12); + +void setup() { + //Initialize the serial communication + Serial.begin(9600); +} + +void loop() { + //Get the distance in cm + int distance = us.getDistance(); + + //Print out the distance to the Serial Monitor + Serial.println(distance); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Wheels/Wheels.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Wheels/Wheels.ino new file mode 100644 index 00000000..3a88a579 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/Wheels/Wheels.ino @@ -0,0 +1,45 @@ +/* +* Wheels +* +* If you ever want to use two continuous rotation servos as a pair +* of wheels we've made it easy for you. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Wheels(left, right) +// Declares the wheels. +// left: the digital pin where you connect the left wheel +// right: the digital pin where you connect the right wheel +Wheels wheels = Wheels(6, 9); + +void setup() { + //Initialize the servo wheels + wheels.begin(); +} + +void loop() { + //Makes the wheel spin forward + wheels.goForward(); + delay(2000); + + //Makes the wheels spin backwards + wheels.goBackwards(); + delay(2000); + + //Makes the wheels spin in opposite direction so that + //the vehicle will spin left + wheels.turnLeft(); + delay(2000); + + //Makes the wheels spin in opposite direction so that + //the vehicle will spin right + wheels.turnRight(); + delay(2000); + + //Makes the wheels stop + wheels.standStill(); + delay(2000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/vuMeter/vuMeter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/vuMeter/vuMeter.ino new file mode 100644 index 00000000..0f9c93fc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/EducationShield/examples/Help/vuMeter/vuMeter.ino @@ -0,0 +1,108 @@ +/* +* VU-Meter +* VU-Meter is a few LEDs grouped together into a line. +* +* This library has some features that makes it easy to control +* several LEDs. Functions to use are: +* +* clear() - turns all LEDs off. +* on(LEDindex) - turns one LED on +* off(LEDindex) - turns one LED off +* scrollRight(speed, startIndex) - one LED lights up at a time from left to right +* scrollLeft(speed, startIndex) - one LED lights up at a time from right to left +* blink(LEDindex,speed, times) - one LED blinks +* blinkAll(speed, times) - all LEDs blink +* fillFrom(startIndex, stopIndex) - turns LEDs from startIndex to stopIndex on +* fill(numberOfLEDs) - turns LEDs on from first to numberOfLEDs +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the VUMeter +VUMeter me; + +//The pins used by the VUMeter, default to 2-5 and 7. Can be +//customized as you wish, but do change the pinCount if the +//number of LEDs are changed. +int pins[] = { 2, 3, 4, 5, 7 }; + +//How many pins are used. Should reflect the pins array above. +int pinCount = 5; + +void setup() { + //Configure the VU meter using parameters defined previously. + me.config(pinCount, pins); + + //initialize the component. Must be called. + me.begin(); +} +void loop() { + //fill(number) + // number: how many LEDs from first pin shall be turned on + // + //Fill 5 LEDs + me.fill(5); + delay(3000); + + //clear() + // + //turn all the LEDs off + me.clear(); + delay(1000); + + //on(index) + // index: which LED being turned on + // + //Turn the 3rd LED on + me.on(2); + delay(1000); + + //off(index) + // index: which LED being turned off + // + //Turn the 3rd LED off + me.off(2); + delay(1000); + + //scrollRight(speed, startIndex) + // speed: milliseconds before the next LED turns on + // startIndex: from which LED to the left it starts + // scrolling. If not specified, it's 1. + // + //One LED lights up at a time, scrolling from left to right + me.scrollRight(700); + + //scrollLeft(speed, startIndex) + // speed: milliseconds before the next LED turns on + // startIndex: from which LED TO THE RIGHT it starts + // scrolling. If not specified, it's 1. + // + //And then scroll back from the 2nd on the right + me.scrollLeft(700, 1); + + //blink(index, speed, times) + // index: which LED should blink + // speed: milliseconds, of which the LED lights on and off + // times: how many times the LED blinks. Defaults to 1 + // + //the 3rd LED will be blinking 10 times, each time + //with 100 milliseconds on and 100 milliseconds off + me.blink(2, 100, 10); + + //blinkAll(speed, times) + // speed: milliseconds, of which all LEDs light on and off + // times: how many times the LED blinks. Defaults to 1 + // + //All LEDs will be blinking 10 times + me.blinkAll(100, 10); + + //fillFrom(leftIndex,rightIndex) + // leftIndex: start filling from which LED + // rightIndex: end filling to which LED + // + //The 2nd to 4th LED will light up + me.fillFrom(1, 3); + delay(2000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/AUTHORS b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/AUTHORS new file mode 100644 index 00000000..1faeec41 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/AUTHORS @@ -0,0 +1,36 @@ +Alberto Panu https://github.com/bigjohnson +Alasdair Allan https://github.com/aallan +Alice Pintus https://github.com/00alis +Adrian McEwen https://github.com/amcewen +Arduino LLC https://arduino.cc/ +Arnie97 https://github.com/Arnie97 +Arturo Guadalupi https://github.com/agdl +Bjoern Hartmann https://people.eecs.berkeley.edu/~bjoern/ +chaveiro https://github.com/chaveiro +Cristian Maglie https://github.com/cmaglie +David A. Mellis https://github.com/damellis +Dino Tinitigan https://github.com/bigdinotech +Eddy https://github.com/eddyst +Federico Vanzati https://github.com/Fede85 +Federico Fissore https://github.com/ffissore +Jack Christensen https://github.com/JChristensen +Johann Richard https://github.com/johannrichard +Jordan Terrell https://github.com/iSynaptic +Justin Paulin https://github.com/interwho +lathoub https://github.com/lathoub +Martino Facchin https://github.com/facchinm +Matthias Hertel https://github.com/mathertel +Matthijs Kooijman https://github.com/matthijskooijman +Matt Robinson https://github.com/ribbons +MCQN Ltd. http://mcqn.com/ +Michael Amie https://github.com/michaelamie +Michael Margolis https://github.com/michaelmargolis +Norbert Truchsess https://github.com/ntruchsess +Paul Stoffregen https://github.com/PaulStoffregen +per1234 https://github.com/per1234 +Richard Sim +Scott Fitzgerald https://github.com/shfitz +Thibaut Viard https://github.com/aethaniel +Tom Igoe https://github.com/tigoe +WIZnet http://www.wiznet.co.kr +Zach Eveland https://github.com/zeveland diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/README.adoc new file mode 100644 index 00000000..ed937b1b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/README.adoc @@ -0,0 +1,31 @@ +:repository-owner: arduino-libraries +:repository-name: Ethernet + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +With the Arduino Ethernet Shield, this library allows an Arduino board to connect to the internet. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2010 Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino new file mode 100644 index 00000000..c9dc23ea --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino @@ -0,0 +1,119 @@ +/* + Advanced Chat Server + + A more advanced server that distributes any incoming messages + to all connected clients but the client the message comes from. + To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino WIZnet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + redesigned to make use of operator== 25 Nov 2013 + by Norbert Truchsess + + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); + +EthernetClient clients[8]; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // initialize the Ethernet device + Ethernet.begin(mac, ip, myDns, gateway, subnet); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // check for any new client connecting, and say hello (before any incoming data) + EthernetClient newClient = server.accept(); + if (newClient) { + for (byte i = 0; i < 8; i++) { + if (!clients[i]) { + Serial.print("We have a new client #"); + Serial.println(i); + newClient.print("Hello, client number: "); + newClient.println(i); + // Once we "accept", the client is no longer tracked by EthernetServer + // so we must store it into our list of clients + clients[i] = newClient; + break; + } + } + } + + // check for incoming data from all clients + for (byte i = 0; i < 8; i++) { + if (clients[i] && clients[i].available() > 0) { + // read bytes from a client + byte buffer[80]; + int count = clients[i].read(buffer, 80); + // write the bytes to all other connected clients + for (byte j = 0; j < 8; j++) { + if (j != i && clients[j].connected()) { + clients[j].write(buffer, count); + } + } + } + } + + // stop any clients which disconnect + for (byte i = 0; i < 8; i++) { + if (clients[i] && !clients[i].connected()) { + Serial.print("disconnect client #"); + Serial.println(i); + clients[i].stop(); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino new file mode 100644 index 00000000..56811b93 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino @@ -0,0 +1,246 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Serves the output of a Barometric Pressure Sensor as a web page. + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + TODO: this hardware is long obsolete. This example program should + be rewritten to use https://www.sparkfun.com/products/9721 + + Circuit: + SCP1000 sensor attached to pins 6,7, and 11 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + by Tom Igoe + */ + +#include +// the sensor communicates using SPI, so include the library: +#include + + +// assign a MAC address for the Ethernet controller. +// fill in your address here: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +// assign an IP address for the controller: +IPAddress ip(192, 168, 1, 20); + + +// Initialize the Ethernet server library +// with the IP address and port you want to use +// (port 80 is default for HTTP): +EthernetServer server(80); + + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading + +// pins used for the connection with the sensor +// the others you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +float temperature = 0.0; +long pressure = 0; +long lastReadingTime = 0; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // start the SPI library: + SPI.begin(); + + // start the Ethernet connection + Ethernet.begin(mac, ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + // initialize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + + // give the sensor and Ethernet shield time to set up: + delay(1000); + + //Set the sensor to high resolution mode to start readings: + writeRegister(0x03, 0x0A); +} + +void loop() { + // check for a reading no more than once a second. + if (millis() - lastReadingTime > 1000) { + // if there's a reading ready, read it: + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + getData(); + // timestamp the last time you got a reading: + lastReadingTime = millis(); + } + } + + // listen for incoming Ethernet connections: + listenForEthernetClients(); +} + + +void getData() { + Serial.println("Getting reading"); + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to Celsius and display it: + temperature = (float)tempData / 20.0; + + //Read the pressure data highest 3 bits: + byte pressureDataHigh = readRegister(0x1F, 1); + pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressureDataLow = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4; + + Serial.print("Temperature: "); + Serial.print(temperature); + Serial.println(" degrees C"); + Serial.print("Pressure: " + String(pressure)); + Serial.println(" Pa"); +} + +void listenForEthernetClients() { + // listen for incoming clients + EthernetClient client = server.available(); + if (client) { + Serial.println("Got a client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println(); + // print the current readings, in HTML format: + client.print("Temperature: "); + client.print(temperature); + client.print(" degrees C"); + client.println("
"); + client.print("Pressure: " + String(pressure)); + client.print(" Pa"); + client.println("
"); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + } +} + + +//Send a write command to SCP1000 +void writeRegister(byte registerName, byte registerValue) { + // SCP1000 expects the register name in the upper 6 bits + // of the byte: + registerName <<= 2; + // command (read or write) goes in the lower two bits: + registerName |= 0b00000010; //Write command + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(registerName); //Send register location + SPI.transfer(registerValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} + + +//Read register from the SCP1000: +unsigned int readRegister(byte registerName, int numBytes) { + byte inByte = 0; // incoming from the SPI read + unsigned int result = 0; // result to return + + // SCP1000 expects the register name in the upper 6 bits + // of the byte: + registerName <<= 2; + // command (read or write) goes in the lower two bits: + registerName &= 0b11111100; //Read command + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(registerName); + // send a value of 0 to read the first byte returned: + inByte = SPI.transfer(0x00); + + result = inByte; + // if there's more than one byte returned, + // shift the first byte then get the second byte: + if (numBytes > 1) { + result = inByte << 8; + inByte = SPI.transfer(0x00); + result = result | inByte; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/ChatServer/ChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/ChatServer/ChatServer.ino new file mode 100644 index 00000000..30e38280 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -0,0 +1,97 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino WIZnet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); +bool alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // initialize the Ethernet device + Ethernet.begin(mac, ip, myDns, gateway, subnet); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clear out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino new file mode 100644 index 00000000..f55ada4a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino @@ -0,0 +1,94 @@ +/* + DHCP-based IP printer + + This sketch uses the DHCP extensions to the Ethernet library + to get an IP address via DHCP and print the address obtained. + using an Arduino WIZnet Ethernet shield. + + Circuit: + Ethernet shield attached to pins 10, 11, 12, 13 + + created 12 April 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // no point in carrying on, so do nothing forevermore: + while (true) { + delay(1); + } + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); +} + +void loop() { + switch (Ethernet.maintain()) { + case 1: + //renewed fail + Serial.println("Error: renewed fail"); + break; + + case 2: + //renewed success + Serial.println("Renewed success"); + //print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + break; + + case 3: + //rebind fail + Serial.println("Error: rebind fail"); + break; + + case 4: + //rebind success + Serial.println("Rebind success"); + //print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + break; + + default: + //nothing happened + break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino new file mode 100644 index 00000000..1815403e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -0,0 +1,101 @@ +/* + DHCP Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino WIZnet Ethernet shield. + + THis version attempts to get an IP address using DHCP + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 21 May 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + Based on ChatServer example by David A. Mellis + + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + +// telnet defaults to port 23 +EthernetServer server(23); +bool gotAMessage = false; // whether or not you got a message from the client yet + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Trying to get an IP address using DHCP"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // initialize the Ethernet device not using DHCP: + Ethernet.begin(mac, ip, myDns, gateway, subnet); + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + + // start listening for clients + server.begin(); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!gotAMessage) { + Serial.println("We have a new client"); + client.println("Hello, client!"); + gotAMessage = true; + } + + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.print(thisChar); + Ethernet.maintain(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/LinkStatus/LinkStatus.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/LinkStatus/LinkStatus.ino new file mode 100644 index 00000000..84651d09 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/LinkStatus/LinkStatus.ino @@ -0,0 +1,44 @@ +/* + Link Status + + This sketch prints the Ethernet link status. When the + Ethernet cable is connected the link status should go to "ON". + NOTE: Only WIZnet W5200 and W5500 are capable of reporting + the link status. W5100 will report "Unknown". + Hardware: + - Ethernet shield or equivalent board/shield with WIZnet W5200/W5500 + Written by Cristian Maglie + This example is public domain. +*/ + +#include +#include + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + Serial.begin(9600); +} + +void loop() { + auto link = Ethernet.linkStatus(); + Serial.print("Link status: "); + switch (link) { + case Unknown: + Serial.println("Unknown"); + break; + case LinkON: + Serial.println("ON"); + break; + case LinkOFF: + Serial.println("OFF"); + break; + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/PagerServer/PagerServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/PagerServer/PagerServer.ino new file mode 100644 index 00000000..a1994385 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/PagerServer/PagerServer.ino @@ -0,0 +1,72 @@ +/* + Pager Server + + A simple server that echoes any incoming messages to all + connected clients. Connect two or more telnet sessions + to see how server.available() and server.print() works. + + created in September 2020 for the Ethernet library + by Juraj Andrassy https://github.com/jandrassy + +*/ +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 0, 177); + +EthernetServer server(2323); + +void setup() { + + Serial.begin(9600); + while (!Serial) + ; + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to configure using IP address instead of DHCP: + Ethernet.begin(mac, ip); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + + server.begin(); + + IPAddress ip = Ethernet.localIP(); + Serial.println(); + Serial.print("To access the server, connect with Telnet client to "); + Serial.print(ip); + Serial.println(" 2323"); +} + +void loop() { + + EthernetClient client = server.available(); // returns first client which has data to read or a 'false' client + if (client) { // client is true only if it is connected and has data to read + String s = client.readStringUntil('\n'); // read the message incoming from one of the clients + s.trim(); // trim eventual \r + Serial.println(s); // print the message to Serial Monitor + client.print("echo: "); // this is only for the sending client + server.println(s); // send the message to all connected clients +#ifndef ARDUINO_ARCH_SAM + server.flush(); // flush the buffers +#endif /* !defined(ARDUINO_ARCH_SAM) */ + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/TelnetClient/TelnetClient.ino new file mode 100644 index 00000000..ee3c7976 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -0,0 +1,109 @@ +/* + Telnet client + + This sketch connects to a telnet server (http://www.google.com) + using an Arduino WIZnet Ethernet shield. You'll need a telnet server + to test this with. + Processing's ChatServer example (part of the Network library) works well, + running on port 10002. It can be found as part of the examples + in the Processing application, available at + https://processing.org/ + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 14 Sep 2010 + modified 9 Apr 2012 + by Tom Igoe + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +// Enter the IP address of the server you're connecting to: +IPAddress server(1, 1, 1, 1); + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 23 is default for telnet; +// if you're using Processing's ChatServer, use port 10002): +EthernetClient client; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // start the Ethernet connection: + Ethernet.begin(mac, ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + while (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + delay(500); + } + + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, 10002)) { + Serial.println("connected"); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // as long as there are bytes in the serial queue, + // read them and send them out the socket if it's open: + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (client.connected()) { + client.print(inChar); + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + // do nothing: + while (true) { + delay(1); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino new file mode 100644 index 00000000..48bc2f3f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino @@ -0,0 +1,138 @@ +/* + UDPSendReceiveString + + This sketch receives UDP message strings, prints them to the serial port + and sends an "acknowledge" string back to the sender + + A Processing sketch is included at the end of file that can be used to send + and receive messages for testing with a computer. + + created 21 Aug 2010 + by Michael Margolis + + This code is in the public domain. + */ + + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +unsigned int localPort = 8888; // local port to listen on + +// buffers for receiving and sending data +char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet, +char ReplyBuffer[] = "acknowledged"; // a string to send back + +// An EthernetUDP instance to let us send and receive packets over UDP +EthernetUDP Udp; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // start the Ethernet + Ethernet.begin(mac, ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start UDP + Udp.begin(localPort); +} + +void loop() { + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remote = Udp.remoteIP(); + for (int i = 0; i < 4; i++) { + Serial.print(remote[i], DEC); + if (i < 3) { + Serial.print("."); + } + } + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBuffer + Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } + delay(10); +} + + +/* + Processing sketch to run with this example + ===================================================== + + // Processing UDP example to send and receive string data from Arduino + // press any key to send the "Hello Arduino" message + + + import hypermedia.net.*; + + UDP udp; // define the UDP object + + + void setup() { + udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000 + //udp.log( true ); // <-- printout the connection activity + udp.listen( true ); // and wait for incoming message + } + + void draw() + { + } + + void keyPressed() { + String ip = "192.168.1.177"; // the remote IP address + int port = 8888; // the destination port + + udp.send("Hello World", ip, port ); // the message to send + + } + + void receive( byte[] data ) { // <-- default handler + //void receive( byte[] data, String ip, int port ) { // <-- extended handler + + for(int i=0; i < data.length; i++) + print(char(data[i])); + println(); + } + */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino new file mode 100644 index 00000000..01f43a12 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -0,0 +1,145 @@ +/* + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see https://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + This code is in the public domain. + + */ + +#include +#include +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; + +unsigned int localPort = 8888; // local port to listen for UDP packets + +const char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +EthernetUDP Udp; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start Ethernet and UDP + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // no point in carrying on, so do nothing forevermore: + while (true) { + delay(1); + } + } + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + // the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); + Ethernet.maintain(); +} + +// send an NTP request to the time server at the given address +void sendNTPpacket(const char* address) { + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); // NTP requests are to port 123 + Udp.write(packetBuffer, NTP_PACKET_SIZE); + Udp.endPacket(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebClient/WebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebClient/WebClient.ino new file mode 100644 index 00000000..c1e9e154 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebClient/WebClient.ino @@ -0,0 +1,136 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using an Arduino WIZnet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe, based on work by Adrian McEwen + + */ + +#include +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 0, 177); +IPAddress myDns(192, 168, 0, 1); + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +EthernetClient client; + +// Variables to measure the speed +unsigned long beginMicros, endMicros; +unsigned long byteCount = 0; +bool printWebData = true; // set to false for better speed measurement + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to configure using IP address instead of DHCP: + Ethernet.begin(mac, ip, myDns); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.print("connecting to "); + Serial.print(server); + Serial.println("..."); + + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.print("connected to "); + Serial.println(client.remoteIP()); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } + beginMicros = micros(); +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + int len = client.available(); + if (len > 0) { + byte buffer[80]; + if (len > 80) len = 80; + client.read(buffer, len); + if (printWebData) { + Serial.write(buffer, len); // show in the serial monitor (slows some boards) + } + byteCount = byteCount + len; + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + endMicros = micros(); + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + Serial.print("Received "); + Serial.print(byteCount); + Serial.print(" bytes in "); + float seconds = (float)(endMicros - beginMicros) / 1000000.0; + Serial.print(seconds, 4); + float rate = (float)byteCount / seconds / 1000.0; + Serial.print(", rate = "); + Serial.print(rate); + Serial.print(" kbytes/second"); + Serial.println(); + + // do nothing forevermore: + while (true) { + delay(1); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino new file mode 100644 index 00000000..61837e52 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino @@ -0,0 +1,125 @@ +/* + Repeating Web client + + This sketch connects to a web server and makes a request + using a WIZnet Ethernet shield. You can use the Arduino Ethernet Shield, or + the Adafruit Ethernet shield, either one will work, as long as it's got + a WIZnet Ethernet module on board. + + This example uses DNS, by assigning the Ethernet client with a MAC address, + IP address, and DNS address. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 19 Apr 2012 + by Tom Igoe + modified 21 Jan 2014 + by Federico Vanzati + + https://www.arduino.cc/en/Tutorial/WebClientRepeating + This code is in the public domain. + + */ + +#include +#include + +// assign a MAC address for the Ethernet controller. +// fill in your address here: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 0, 177); +IPAddress myDns(192, 168, 0, 1); + +// initialize the library instance: +EthernetClient client; + +char server[] = "www.arduino.cc"; // also change the Host line in httpRequest() +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // start serial port: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to configure using IP address instead of DHCP: + Ethernet.begin(mac, ip, myDns); + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + if (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the Ethernet shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET /latest.txt HTTP/1.1"); + client.println("Host: www.arduino.cc"); + client.println("User-Agent: arduino-ethernet"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebServer/WebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebServer/WebServer.ino new file mode 100644 index 00000000..d2aa8455 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Ethernet/examples/WebServer/WebServer.ino @@ -0,0 +1,122 @@ +/* + Web Server + + A simple web server that shows the value of the analog input pins. + using an Arduino WIZnet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + * Analog inputs attached to pins A0 through A5 (optional) + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +// Initialize the Ethernet server library +// with the IP address and port you want to use +// (port 80 is default for HTTP): +EthernetServer server(80); + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.println("Ethernet WebServer Example"); + + // start the Ethernet connection and the server: + Ethernet.begin(mac, ip); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start the server + server.begin(); + Serial.print("server is at "); + Serial.println(Ethernet.localIP()); +} + + +void loop() { + // listen for incoming clients + EthernetClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
"); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/LICENSE new file mode 100644 index 00000000..0a041280 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/README.adoc new file mode 100644 index 00000000..9b5f9baa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/README.adoc @@ -0,0 +1,31 @@ +:repository-owner: arduino-libraries +:repository-name: Keyboard + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino board with USB capabilities to act as a keyboard. + +For more information about this library please visit us at +https://www.arduino.cc/reference/en/language/functions/usb/keyboard/ + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/examples/Serial/Serial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/examples/Serial/Serial.ino new file mode 100644 index 00000000..050bb18c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Keyboard/examples/Serial/Serial.ino @@ -0,0 +1,39 @@ +/* + Keyboard test + + For the Arduino Leonardo, Micro or Due + + Reads a byte from the serial port, sends a keystroke back. + The sent keystroke is one higher than what's received, e.g. if you send a, + you get b, send A you get B, and so forth. + + The circuit: + - none + + created 21 Oct 2011 + modified 27 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardSerial +*/ + +#include "Keyboard.h" + +void setup() { + // open the serial port: + Serial.begin(9600); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + // check for incoming serial data: + if (Serial.available() > 0) { + // read incoming serial data: + char inChar = Serial.read(); + // Type the next ASCII value from what you received: + Keyboard.write(inChar + 1); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/README.adoc new file mode 100644 index 00000000..a46cd034 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/README.adoc @@ -0,0 +1,33 @@ +:repository-owner: arduino-libraries +:repository-name: LiquidCrystal + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino board to control liquid crystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. + +For more information about this library please visit us at + +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. +Copyright (c) 2010 Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino new file mode 100644 index 00000000..e5f369b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino @@ -0,0 +1,77 @@ +/* + LiquidCrystal Library - Autoscroll + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates the use of the autoscroll() + and noAutoscroll() functions to make new text scroll or not. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalAutoscroll + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); +} + +void loop() { + // set the cursor to (0,0): + lcd.setCursor(0, 0); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + + // set the cursor to (16,1): + lcd.setCursor(16, 1); + // set the display to automatically scroll: + lcd.autoscroll(); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + // turn off automatic scrolling + lcd.noAutoscroll(); + + // clear screen for the next loop: + lcd.clear(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Blink/Blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Blink/Blink.ino new file mode 100644 index 00000000..fd79e5a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Blink/Blink.ino @@ -0,0 +1,63 @@ +/* + LiquidCrystal Library - Blink + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD and makes the + cursor block blink. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalBlink + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the blinking cursor: + lcd.noBlink(); + delay(3000); + // Turn on the blinking cursor: + lcd.blink(); + delay(3000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Cursor/Cursor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Cursor/Cursor.ino new file mode 100644 index 00000000..3132a19d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Cursor/Cursor.ino @@ -0,0 +1,64 @@ +/* + LiquidCrystal Library - Cursor + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD and + uses the cursor() and noCursor() methods to turn + on and off the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalCursor + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the cursor: + lcd.noCursor(); + delay(500); + // Turn on the cursor: + lcd.cursor(); + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino new file mode 100644 index 00000000..80f38d62 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino @@ -0,0 +1,147 @@ +/* + LiquidCrystal Library - Custom Characters + + Demonstrates how to add custom characters on an LCD display. + The LiquidCrystal library works with all LCD displays that are + compatible with the Hitachi HD44780 driver. There are many of + them out there, and you can usually tell them by the 16-pin interface. + + This sketch prints "I Arduino!" and a little dancing man + to the LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + * 10K potentiometer on pin A0 + + created 21 Mar 2011 + by Tom Igoe + modified 11 Nov 2013 + by Scott Fitzgerald + modified 7 Nov 2016 + by Arturo Guadalupi + modified 17 Mar 2020 + by Deepak Khatri + + Based on Adafruit's example at + https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde + + This example code is in the public domain. + + Also useful: + https://maxpromer.github.io/LCD-Character-Creator/ + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +// make some custom characters: +byte heart[8] = { + 0b00000, + 0b01010, + 0b11111, + 0b11111, + 0b11111, + 0b01110, + 0b00100, + 0b00000 +}; + +byte smiley[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b10001, + 0b01110, + 0b00000 +}; + +byte frownie[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b00000, + 0b01110, + 0b10001 +}; + +byte armsDown[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b00100, + 0b01110, + 0b10101, + 0b00100, + 0b01010 +}; + +byte armsUp[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + 0b00100, + 0b01010 +}; + +void setup() { + // initialize LCD and set up the number of columns and rows: + lcd.begin(16, 2); + + // create a new character + lcd.createChar(0, heart); + // create a new character + lcd.createChar(1, smiley); + // create a new character + lcd.createChar(2, frownie); + // create a new character + lcd.createChar(3, armsDown); + // create a new character + lcd.createChar(4, armsUp); + + // set the cursor to the top left + lcd.setCursor(0, 0); + + // Print a message to the LCD. + lcd.print("I "); + lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte + lcd.print(" Arduino! "); + lcd.write((byte)1); +} + +void loop() { + // read the potentiometer on A0: + int sensorReading = analogRead(A0); + // map the result to 200 - 1000: + int delayTime = map(sensorReading, 0, 1023, 200, 1000); + // set the cursor to the bottom row, 5th position: + lcd.setCursor(4, 1); + // draw the little man, arms down: + lcd.write(3); + delay(delayTime); + lcd.setCursor(4, 1); + // draw him arms up: + lcd.write(4); + delay(delayTime); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Display/Display.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Display/Display.ino new file mode 100644 index 00000000..fe1a4527 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Display/Display.ino @@ -0,0 +1,64 @@ +/* + LiquidCrystal Library - display() and noDisplay() + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD and uses the + display() and noDisplay() functions to turn on and off + the display. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalDisplay + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the display: + lcd.noDisplay(); + delay(500); + // Turn on the display: + lcd.display(); + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino new file mode 100644 index 00000000..4fdc5e58 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino @@ -0,0 +1,64 @@ +/* + LiquidCrystal Library - Hello World + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD + and shows the time. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * LCD VSS pin to ground + * LCD VCC pin to 5V + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/HelloWorld + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis() / 1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Scroll/Scroll.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Scroll/Scroll.ino new file mode 100644 index 00000000..c72e54f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/Scroll/Scroll.ino @@ -0,0 +1,88 @@ +/* + LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD and uses the + scrollDisplayLeft() and scrollDisplayRight() methods to scroll + the text. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalScroll + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); + delay(1000); +} + +void loop() { + // scroll 13 positions (string length) to the left + // to move it offscreen left: + for (int positionCounter = 0; positionCounter < 13; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // scroll 29 positions (string length + display length) to the right + // to move it offscreen right: + for (int positionCounter = 0; positionCounter < 29; positionCounter++) { + // scroll one position right: + lcd.scrollDisplayRight(); + // wait a bit: + delay(150); + } + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: + for (int positionCounter = 0; positionCounter < 16; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // delay at the end of the full loop: + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino new file mode 100644 index 00000000..ae93e21f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino @@ -0,0 +1,69 @@ +/* + LiquidCrystal Library - Serial Input + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch displays text sent over the serial port + (e.g. from the Serial Monitor) on an attached LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystalSerialDisplay + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // initialize the serial communications: + Serial.begin(9600); +} + +void loop() { + // when characters arrive over the serial port... + if (Serial.available()) { + // wait a bit for the entire message to arrive + delay(100); + // clear the screen + lcd.clear(); + // read all the available characters + while (Serial.available() > 0) { + // display each character to the LCD + lcd.write(Serial.read()); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino new file mode 100644 index 00000000..37be1d45 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino @@ -0,0 +1,82 @@ +/* + LiquidCrystal Library - TextDirection + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates how to use leftToRight() and rightToLeft() + to move the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystalTextDirection + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +int thisChar = 'a'; + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // turn on the cursor: + lcd.cursor(); +} + +void loop() { + // reverse directions at 'm': + if (thisChar == 'm') { + // go right for the next letter + lcd.rightToLeft(); + } + // reverse again at 's': + if (thisChar == 's') { + // go left for the next letter + lcd.leftToRight(); + } + // reset at 'z': + if (thisChar > 'z') { + // go to (0,0): + lcd.home(); + // start again at 0 + thisChar = 'a'; + } + // print the character + lcd.write(thisChar); + // wait a second: + delay(1000); + // increment the letter: + thisChar++; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/setCursor/setCursor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/setCursor/setCursor.ino new file mode 100644 index 00000000..7624366b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/LiquidCrystal/examples/setCursor/setCursor.ino @@ -0,0 +1,74 @@ +/* + LiquidCrystal Library - setCursor + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints to all the positions of the LCD using the + setCursor() method: + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalSetCursor + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +// these constants won't change. But you can change the size of +// your LCD using them: +const int numRows = 2; +const int numCols = 16; + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(numCols, numRows); +} + +void loop() { + // loop from ASCII 'a' to ASCII 'z': + for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { + // loop over the columns: + for (int thisRow = 0; thisRow < numRows; thisRow++) { + // loop over the rows: + for (int thisCol = 0; thisCol < numCols; thisCol++) { + // set the cursor position: + lcd.setCursor(thisCol, thisRow); + // print the letter: + lcd.write(thisLetter); + delay(200); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/README.adoc new file mode 100644 index 00000000..90f43c98 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/README.adoc @@ -0,0 +1,46 @@ +:repository-owner: arduino-libraries +:repository-name: MIDIUSB + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino board with USB capabilities to act as a MIDI instrument over USB. The library is based on PluggableUSB, so is only compatible with Arduino IDE 1.6.6 and newer. + +Furthermore, since PluggableUSB only targets boards with native USB capabilities, this library only supports these boards (eg. Leonardo, Micro, Due, Zero and so on) + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== Test procedure (Linux) == + +Load the correct driver (`sudo modprobe snd_seq_midi`) + +Flash the board with `MIDIUSB_loop` example, then execute `aseqdump -l`; the output will be something similar to +```bash +Port Client name Port name + 0:0 System Timer + 0:1 System Announce + 14:0 Midi Through Midi Through Port-0 + 20:0 Arduino Micro Arduino Micro MIDI 1 +``` +Port `20` is the one we'll use in the following examples. + +Start `fluidsynth` inside a shell with a soundbank +```bash +fluidsynth --server --audio-driver=alsa -o audio.alsa.device=hw:0 ~/Synth.SF2 +``` + +In another shell, execute +```bash +aconnect 20 128 +``` +to connect our MIDI device with fluidsynth + +Then, execute +```bash +aplaymidi --port=20:0 ~/some_midi_file.mid +``` +and the file will be played after a complete roundtrip to the board. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_buzzer/MIDIUSB_buzzer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_buzzer/MIDIUSB_buzzer.ino new file mode 100644 index 00000000..34d317e4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_buzzer/MIDIUSB_buzzer.ino @@ -0,0 +1,98 @@ +/* + * MIDIUSB_buzzer.ino + * + * Author: Paulo Costa + */ + +#include +#include "pitchToFrequency.h" + +#define BUZZ_PIN 9 + +const char* pitch_name(byte pitch) { + static const char* names[] = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" }; + return names[pitch % 12]; +} + +int pitch_octave(byte pitch) { + return (pitch / 12) - 1; +} + +void noteOn(byte channel, byte pitch, byte velocity) { + tone(BUZZ_PIN, pitchFrequency[pitch]); + + Serial.print("Note On: "); + Serial.print(pitch_name(pitch)); + Serial.print(pitch_octave(pitch)); + Serial.print(", channel="); + Serial.print(channel); + Serial.print(", velocity="); + Serial.println(velocity); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + noTone(BUZZ_PIN); + + Serial.print("Note Off: "); + Serial.print(pitch_name(pitch)); + Serial.print(pitch_octave(pitch)); + Serial.print(", channel="); + Serial.print(channel); + Serial.print(", velocity="); + Serial.println(velocity); +} + +void controlChange(byte channel, byte control, byte value) { + Serial.print("Control change: control="); + Serial.print(control); + Serial.print(", value="); + Serial.print(value); + Serial.print(", channel="); + Serial.println(channel); +} + +void setup() { + Serial.begin(115200); +} + +void loop() { + midiEventPacket_t rx = MidiUSB.read(); + switch (rx.header) { + case 0: + break; //No pending events + + case 0x9: + noteOn( + rx.byte1 & 0xF, //channel + rx.byte2, //pitch + rx.byte3 //velocity + ); + break; + + case 0x8: + noteOff( + rx.byte1 & 0xF, //channel + rx.byte2, //pitch + rx.byte3 //velocity + ); + break; + + case 0xB: + controlChange( + rx.byte1 & 0xF, //channel + rx.byte2, //control + rx.byte3 //value + ); + break; + + default: + Serial.print("Unhandled MIDI message: "); + Serial.print(rx.header, HEX); + Serial.print("-"); + Serial.print(rx.byte1, HEX); + Serial.print("-"); + Serial.print(rx.byte2, HEX); + Serial.print("-"); + Serial.println(rx.byte3, HEX); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_clock/MIDIUSB_clock.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_clock/MIDIUSB_clock.ino new file mode 100644 index 00000000..4abcf85f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_clock/MIDIUSB_clock.ino @@ -0,0 +1,68 @@ +/* + * MIDIUSB_clock.ino + * + * Simple example of beat clock based on MIDI pulse messages + * received from software. + * + * Tested on Leonardo with Ableton. + * + * In preferences go to MIDI Sync. Select device Output + * and toggle Sync button, change clock type to Pattern. + * Usually changing Sync Delay is required. + * + * Created: 19/12/2016 + * Author: Ernest Warzocha + */ + +#include "MIDIUSB.h" + +//Pulse per quarter note. Each beat has 24 pulses. +//Tempo is based on software inner BPM. +int ppqn = 0; + +void noteOn(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOn = { 0x09, 0x90 | channel, pitch, velocity }; + MidiUSB.sendMIDI(noteOn); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOff = { 0x08, 0x80 | channel, pitch, velocity }; + MidiUSB.sendMIDI(noteOff); +} + +void setup() { + Serial.begin(115200); +} + +void loop() { + + midiEventPacket_t rx; + + do { + rx = MidiUSB.read(); + + //Count pulses and send note + if (rx.byte1 == 0xF8) { + ++ppqn; + + if (ppqn == 24) { + noteOn(1, 48, 127); + MidiUSB.flush(); + ppqn = 0; + }; + } + //Clock start byte + else if (rx.byte1 == 0xFA) { + noteOn(1, 48, 127); + MidiUSB.flush(); + ppqn = 0; + } + //Clock stop byte + else if (rx.byte1 == 0xFC) { + noteOff(1, 48, 0); + MidiUSB.flush(); + ppqn = 0; + }; + + } while (rx.header != 0); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_loop/MIDIUSB_loop.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_loop/MIDIUSB_loop.ino new file mode 100644 index 00000000..5d143627 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_loop/MIDIUSB_loop.ino @@ -0,0 +1,54 @@ +/* + * MIDIUSB_loop.ino + * + * Created: 4/6/2015 10:47:08 AM + * Author: gurbrinder grewal + * Modified by Arduino LLC (2015) + */ + +#include "MIDIUSB.h" + +// First parameter is the event type (0x09 = note on, 0x08 = note off). +// Second parameter is note-on/note-off, combined with the channel. +// Channel can be anything between 0-15. Typically reported to the user as 1-16. +// Third parameter is the note number (48 = middle C). +// Fourth parameter is the velocity (64 = normal, 127 = fastest). + +void noteOn(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOn = { 0x09, 0x90 | channel, pitch, velocity }; + MidiUSB.sendMIDI(noteOn); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOff = { 0x08, 0x80 | channel, pitch, velocity }; + MidiUSB.sendMIDI(noteOff); +} + +void setup() { + Serial.begin(115200); + pinMode(LED_BUILTIN, OUTPUT); +} + +// First parameter is the event type (0x0B = control change). +// Second parameter is the event type, combined with the channel. +// Third parameter is the control number number (0-119). +// Fourth parameter is the control value (0-127). + +void controlChange(byte channel, byte control, byte value) { + midiEventPacket_t event = { 0x0B, 0xB0 | channel, control, value }; + MidiUSB.sendMIDI(event); +} + +void loop() { + //MidiUSB.accept(); + //delayMicroseconds(1); + midiEventPacket_t rx; + do { + rx = MidiUSB.read(); + if (rx.header != 0) { + //send back the received MIDI command + MidiUSB.sendMIDI(rx); + MidiUSB.flush(); + } + } while (rx.header != 0); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_read/MIDIUSB_read.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_read/MIDIUSB_read.ino new file mode 100644 index 00000000..7a4192c1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_read/MIDIUSB_read.ino @@ -0,0 +1,56 @@ +/* + * MIDIUSB_test.ino + * + * Created: 4/6/2015 10:47:08 AM + * Author: gurbrinder grewal + * Modified by Arduino LLC (2015) + */ + +#include "MIDIUSB.h" + +// First parameter is the event type (0x09 = note on, 0x08 = note off). +// Second parameter is note-on/note-off, combined with the channel. +// Channel can be anything between 0-15. Typically reported to the user as 1-16. +// Third parameter is the note number (48 = middle C). +// Fourth parameter is the velocity (64 = normal, 127 = fastest). + +void noteOn(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOn = { 0x09, 0x90 | channel, pitch, velocity }; + MidiUSB.sendMIDI(noteOn); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOff = { 0x08, 0x80 | channel, pitch, velocity }; + MidiUSB.sendMIDI(noteOff); +} + +void setup() { + Serial.begin(115200); +} + +// First parameter is the event type (0x0B = control change). +// Second parameter is the event type, combined with the channel. +// Third parameter is the control number number (0-119). +// Fourth parameter is the control value (0-127). + +void controlChange(byte channel, byte control, byte value) { + midiEventPacket_t event = { 0x0B, 0xB0 | channel, control, value }; + MidiUSB.sendMIDI(event); +} + +void loop() { + midiEventPacket_t rx; + do { + rx = MidiUSB.read(); + if (rx.header != 0) { + Serial.print("Received: "); + Serial.print(rx.header, HEX); + Serial.print("-"); + Serial.print(rx.byte1, HEX); + Serial.print("-"); + Serial.print(rx.byte2, HEX); + Serial.print("-"); + Serial.println(rx.byte3, HEX); + } + } while (rx.header != 0); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_write/MIDIUSB_write.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_write/MIDIUSB_write.ino new file mode 100644 index 00000000..dc9d18b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_write/MIDIUSB_write.ino @@ -0,0 +1,52 @@ +/* + * MIDIUSB_test.ino + * + * Created: 4/6/2015 10:47:08 AM + * Author: gurbrinder grewal + * Modified by Arduino LLC (2015) + */ + +#include "MIDIUSB.h" + +// First parameter is the event type (0x09 = note on, 0x08 = note off). +// Second parameter is note-on/note-off, combined with the channel. +// Channel can be anything between 0-15. Typically reported to the user as 1-16. +// Third parameter is the note number (48 = middle C). +// Fourth parameter is the velocity (64 = normal, 127 = fastest). + +void noteOn(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOn = { 0x09, 0x90 | channel, pitch, velocity }; + MidiUSB.sendMIDI(noteOn); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOff = { 0x08, 0x80 | channel, pitch, velocity }; + MidiUSB.sendMIDI(noteOff); +} + +void setup() { + Serial.begin(115200); +} + +// First parameter is the event type (0x0B = control change). +// Second parameter is the event type, combined with the channel. +// Third parameter is the control number number (0-119). +// Fourth parameter is the control value (0-127). + +void controlChange(byte channel, byte control, byte value) { + midiEventPacket_t event = { 0x0B, 0xB0 | channel, control, value }; + MidiUSB.sendMIDI(event); +} + +void loop() { + Serial.println("Sending note on"); + noteOn(0, 48, 64); // Channel 0, middle C, normal velocity + MidiUSB.flush(); + delay(500); + Serial.println("Sending note off"); + noteOff(0, 48, 64); // Channel 0, middle C, normal velocity + MidiUSB.flush(); + delay(1500); + + // controlChange(0, 10, 65); // Set the value of controller 10 on channel 0 to 65 +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/README.adoc new file mode 100644 index 00000000..29a1b28b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: MKRGSM + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library enables an Arduino MKR GSM 1400 board to do most of the operations you can do with a GSM phone: place and receive voice calls, send and receive SMS, and connect to the internet over a GPRS network. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSPing/GPRSPing.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSPing/GPRSPing.ino new file mode 100644 index 00000000..3f30b2c8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSPing/GPRSPing.ino @@ -0,0 +1,73 @@ +/* + + This uses an MKR GSM 1400 to continuously ping a host specified by IP Address or name. + +Circuit: +* MKR GSM 1400 board +* Antenna +* SIM card with a data plan + + created 06 Dec 2017 + by Arturo Guadalupi +*/ +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; + +// Specify IP address or hostname +String hostName = "www.google.com"; +int pingResult; + +void setup() { + // Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino GPRS ping."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } +} + +void loop() { + Serial.print("Pinging "); + Serial.print(hostName); + Serial.print(": "); + + pingResult = gprs.ping(hostName); + + if (pingResult >= 0) { + Serial.print("SUCCESS! RTT = "); + Serial.print(pingResult); + Serial.println(" ms"); + } else { + Serial.print("FAILED! Error code: "); + Serial.println(pingResult); + } + + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSPing/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSPing/arduino_secrets.h new file mode 100644 index 00000000..cdd607cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSPing/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino new file mode 100644 index 00000000..5a9f5343 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino @@ -0,0 +1,153 @@ +/* + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + modified 6 Dec 2017 ported from WiFi101 to MKRGSM + by Arturo Guadalupi + + This code is in the public domain. + +*/ + +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// initialize the library instance +GSMClient client; +GPRS gprs; +GSM gsmAccess; + +// A UDP instance to let us send and receive packets over UDP +GSMUDP Udp; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino GPRS NTP client."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) { + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/arduino_secrets.h new file mode 100644 index 00000000..cdd607cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmLocation/GsmLocation.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmLocation/GsmLocation.ino new file mode 100644 index 00000000..973b4106 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmLocation/GsmLocation.ino @@ -0,0 +1,76 @@ +/* + Location + + This sketch uses the celluar network to determine the location of a MKR GSM 1400 board + and prints it to the Serial Monitor. The location is based on the cellular towers in + range, and requires a GPRS data connection to be enabled. + + Circuit: + MKR GSM 1400 board + Antenna + SIM card with a data plan + + created 15 Dec 2017 + by Sandeep Mistry +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMLocation location; +GPRS gprs; +GSM gsmAccess; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting GSM location."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + location.begin(); +} + +void loop() { + if (location.available()) { + Serial.print("Location: "); + Serial.print(location.latitude(), 7); + Serial.print(", "); + Serial.println(location.longitude(), 7); + + Serial.print("Altitude: "); + Serial.print(location.altitude()); + Serial.println("m"); + + Serial.print("Accuracy: +/- "); + Serial.print(location.accuracy()); + Serial.println("m"); + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmLocation/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmLocation/arduino_secrets.h new file mode 100644 index 00000000..cdd607cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmLocation/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/GsmSSLWebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/GsmSSLWebClient.ino new file mode 100644 index 00000000..0f760ee7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/GsmSSLWebClient.ino @@ -0,0 +1,98 @@ +/* + Web client + + This sketch connects to a website using SSL through a MKR GSM 1400 board. Specifically, + this example downloads the URL "http://www.arduino.cc/asciilogo.txt" and + prints it to the Serial Monitor. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; + +// URL, path and port (for example: arduino.cc) +char server[] = "arduino.cc"; +char path[] = "/asciilogo.txt"; +int port = 443; // port 443 is the default for HTTPS + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET "); + client.print(path); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/arduino_secrets.h new file mode 100644 index 00000000..cdd607cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/GsmWebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/GsmWebClient.ino new file mode 100644 index 00000000..e6e2ac50 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/GsmWebClient.ino @@ -0,0 +1,98 @@ +/* + Web client + + This sketch connects to a website through a MKR GSM 1400 board. Specifically, + this example downloads the URL "http://www.example.org/" and + prints it to the Serial Monitor. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMClient client; +GPRS gprs; +GSM gsmAccess; + +// URL, path and port (for example: example.org) +char server[] = "example.org"; +char path[] = "/"; +int port = 80; // port 80 is the default for HTTP + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET "); + client.print(path); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/arduino_secrets.h new file mode 100644 index 00000000..cdd607cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/GsmWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/GsmWebServer.ino new file mode 100644 index 00000000..9a476fe7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/GsmWebServer.ino @@ -0,0 +1,114 @@ +/* + GSM Web Server + + A simple web server that shows the value of the analog input pins. + using a MKR GSM 1400 board. + + Circuit: + * MKR GSM 1400 board + * Antenna + * Analog inputs attached to pins A0 through A5 (optional) + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + + +// initialize the library instance +GPRS gprs; +GSM gsmAccess; // include a 'true' parameter for debug enabled +GSMServer server(80); // port 80 (http default) + +// timeout +const unsigned long __TIMEOUT__ = 10 * 1000; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected to GPRS network"); + + // start server + server.begin(); + + //Get IP. + IPAddress LocalIP = gprs.getIPAddress(); + Serial.println("Server IP address="); + Serial.println(LocalIP); +} + +void loop() { + + + // listen for incoming clients + GSMClient client = server.available(); + + + + if (client) { + while (client.connected()) { + if (client.available()) { + Serial.println("Receiving request!"); + bool sendResponse = false; + while (int c = client.read()) { + if (c == -1) { + break; + } else if (c == '\n') { + sendResponse = true; + } + } + + // if you've gotten to the end of the line (received a newline + // character) + if (sendResponse) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println(); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(analogRead(analogChannel)); + client.println("
"); + } + client.println(""); + //necessary delay + delay(1000); + client.stop(); + } + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/arduino_secrets.h new file mode 100644 index 00000000..cdd607cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/MakeVoiceCall.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/MakeVoiceCall.ino new file mode 100644 index 00000000..3d03a63e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/MakeVoiceCall.ino @@ -0,0 +1,104 @@ +/* + Make Voice Call + + This sketch, for the MKR GSM 1400 board, puts a voice call to + a remote phone number that you enter through the Serial Monitor. + To make it work, open the Serial Monitor, and when you see the + READY message, type a phone number. Make sure the Serial Monitor + is set to send a just newline when you press return. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card that can send voice calls + + + created Mar 2012 + by Javier Zorzano +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; // include a 'true' parameter for debug enabled +GSMVoiceCall vcs; + +String remoteNumber = ""; // the number you will call +char charbuffer[20]; + +void setup() { + + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Make Voice Call"); + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("GSM initialized."); + Serial.println("Enter phone number to call."); +} + +void loop() { + + // add any incoming characters to the String: + while (Serial.available() > 0) { + char inChar = Serial.read(); + // if it's a newline, that means you should make the call: + if (inChar == '\n') { + // make sure the phone number is not too long: + if (remoteNumber.length() < 20) { + // let the user know you're calling: + Serial.print("Calling to : "); + Serial.println(remoteNumber); + Serial.println(); + + // Call the remote number + remoteNumber.toCharArray(charbuffer, 20); + + + // Check if the receiving end has picked up the call + if (vcs.voiceCall(charbuffer)) { + Serial.println("Call Established. Enter line to end"); + // Wait for some input from the line + while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING)) + ; + // And hang up + vcs.hangCall(); + } + Serial.println("Call Finished"); + remoteNumber = ""; + Serial.println("Enter phone number to call."); + } else { + Serial.println("That's too long for a phone number. I'm forgetting it"); + remoteNumber = ""; + } + } else { + // add the latest character to the message to send: + if (inChar != '\r') { + remoteNumber += inChar; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/ReceiveSMS.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/ReceiveSMS.ino new file mode 100644 index 00000000..59f764b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/ReceiveSMS.ino @@ -0,0 +1,88 @@ +/* + SMS receiver + + This sketch, for the MKR GSM 1400 board, waits for a SMS message + and displays it through the Serial port. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card that can receive SMS messages + + created 25 Feb 2012 + by Javier Zorzano / TD +*/ + +// include the GSM library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instances +GSM gsmAccess; +GSM_SMS sms; + +// Array to hold the number a SMS is retrieved from +char senderNumber[20]; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("SMS Messages Receiver"); + + // connection state + bool connected = false; + + // Start GSM connection + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("GSM initialized"); + Serial.println("Waiting for messages"); +} + +void loop() { + int c; + + // If there are any SMSs available() + if (sms.available()) { + Serial.println("Message received from:"); + + // Get remote number + sms.remoteNumber(senderNumber, 20); + Serial.println(senderNumber); + + // An example of message disposal + // Any messages starting with # should be discarded + if (sms.peek() == '#') { + Serial.println("Discarded SMS"); + sms.flush(); + } + + // Read message bytes and print them + while ((c = sms.read()) != -1) { + Serial.print((char)c); + } + + Serial.println("\nEND OF MESSAGE"); + + // Delete message from modem memory + sms.flush(); + Serial.println("MESSAGE DELETED"); + } + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino new file mode 100644 index 00000000..10697cec --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino @@ -0,0 +1,93 @@ +/* + Receive Voice Call + + This sketch, for the MKR GSM 1400 board, receives voice calls, + displays the calling number, waits a few seconds then hangs up. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card that can accept voice calls + + created Mar 2012 + by Javier Zorzano +*/ + +// Include the GSM library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; +GSMVoiceCall vcs; + +// Array to hold the number for the incoming call +char numtel[20]; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Receive Voice Call"); + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + // This makes sure the modem correctly reports incoming events + vcs.hangCall(); + + Serial.println("Waiting for a call"); +} + +void loop() { + // Check the status of the voice call + switch (vcs.getvoiceCallStatus()) { + case IDLE_CALL: // Nothing is happening + + break; + + case RECEIVINGCALL: // Yes! Someone is calling us + + Serial.println("RECEIVING CALL"); + + // Retrieve the calling number + vcs.retrieveCallingNumber(numtel, 20); + + // Print the calling number + Serial.print("Number:"); + Serial.println(numtel); + + // Answer the call, establish the call + vcs.answerCall(); + break; + + case TALKING: // In this case the call would be established + + Serial.println("TALKING. Press enter to hang up."); + while (Serial.read() != '\n') { + delay(100); + } + vcs.hangCall(); + Serial.println("Hanging up and waiting for the next call."); + break; + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/SSLCertificateManagement.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/SSLCertificateManagement.ino new file mode 100644 index 00000000..01e66bf3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/SSLCertificateManagement.ino @@ -0,0 +1,123 @@ +/* + ArduinoMqttClient - SSLCertificateManagement + + This example shows how to upload a self signed certificate + by GSMSSLClient's APIs, connect to a MQTT broker, + and publish a message to a topic once a second. + + The circuit: + - Arduino MKR GSM 1400 + + This example code is in the public domain. +*/ + +#include +#include +#include "arduino_secrets.h" + + +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; +MqttClient mqttClient(client); + +// replace with your broker, port and topic +const char broker[] = ""; +int port = 8883; +const char topic[] = ""; + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + + +void setup() { + // Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + bool connected = false; + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // eraseAllCertificates erases all the certificates stored in the onboard + // GSM module + client.eraseAllCertificates(); + + client.setUserRoots(SECRET_GSM_ROOT_CERTS, SECRET_GSM_ROOT_SIZE); + client.setSignedCertificate(SECRET_CERT, "MKRGSM01", sizeof(SECRET_CERT)); + client.setPrivateKey(SECRET_KEY, "MKRGSMKEY01", sizeof(SECRET_KEY)); + + client.useSignedCertificate("MKRGSM01"); + client.usePrivateKey("MKRGSMKEY01"); + client.setTrustedRoot("Let_s_Encrypt_Authority_X3"); + + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1) + ; + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to send MQTT keep alives which + // avoids being disconnected by the broker + mqttClient.poll(); + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + Serial.print("Sending message to topic: "); + Serial.println(topic); + Serial.print("hello "); + Serial.println(count); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage(topic); + mqttClient.print("hello "); + mqttClient.print(count); + if (!mqttClient.endMessage()) { + Serial.println("transmission error"); + } + + Serial.println(); + + count++; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/arduino_secrets.h new file mode 100644 index 00000000..1b1f9935 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/arduino_secrets.h @@ -0,0 +1,305 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + + +// Replace with your client.crt certificate in DER format +const uint8_t SECRET_CERT[] = { + /*0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0x02, 0x09, 0x00, 0xc2, + 0x68, 0x43, 0x0c, 0x54, 0xae, 0xfe, 0x3a, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x62, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x54, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x05, + 0x49, 0x74, 0x61, 0x6c, 0x79, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, + 0x04, 0x07, 0x0c, 0x05, 0x54, 0x75, 0x72, 0x69, 0x6e, 0x31, 0x10, 0x30, + 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x41, 0x72, 0x64, 0x75, + 0x69, 0x6e, 0x6f, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b, + 0x0c, 0x03, 0x4d, 0x6e, 0x78, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, + 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x69, 0x75, 0x6d, + 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x36, 0x31, 0x36, + 0x31, 0x35, 0x32, 0x39, 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, + 0x36, 0x31, 0x36, 0x31, 0x35, 0x32, 0x39, 0x30, 0x31, 0x5a, 0x30, 0x63, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x54, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x08, + 0x50, 0x69, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x74, 0x31, 0x0e, 0x30, 0x0c, + 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x05, 0x54, 0x75, 0x72, 0x69, 0x6e, + 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x03, 0x4d, + 0x6e, 0x78, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, + 0x07, 0x41, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x31, 0x11, 0x30, 0x0f, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x08, 0x4d, 0x4b, 0x52, 0x47, 0x53, + 0x4d, 0x30, 0x31, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xb6, 0xb7, 0xa2, 0x73, 0x9e, 0x8b, 0xcc, 0x7f, 0x55, 0xb3, 0xb4, 0xad, + 0xfe, 0x6a, 0xbc, 0xa7, 0xe5, 0xec, 0x02, 0xd0, 0x4b, 0x25, 0xa4, 0xd3, + 0xc4, 0x33, 0x37, 0xa7, 0x76, 0xdf, 0xa3, 0x9f, 0xdd, 0x42, 0x3e, 0xb5, + 0xe2, 0xbc, 0x89, 0xe4, 0x18, 0x02, 0xb6, 0x62, 0xe4, 0x3b, 0xa6, 0x74, + 0x76, 0xf8, 0x73, 0xe7, 0x80, 0xea, 0x5d, 0x93, 0x9d, 0x61, 0x2a, 0x24, + 0x06, 0x4c, 0x6b, 0x68, 0xea, 0x63, 0x1d, 0x3a, 0xce, 0x8b, 0x31, 0x05, + 0x72, 0xe9, 0xdc, 0xce, 0x05, 0x8c, 0x7a, 0xc1, 0xf5, 0xd6, 0xe1, 0xd0, + 0x6d, 0x73, 0x4e, 0xc1, 0x8a, 0x16, 0x49, 0x4d, 0xac, 0x21, 0xfb, 0x2d, + 0x12, 0xdd, 0x1e, 0xef, 0x9b, 0xb3, 0x6d, 0x20, 0x69, 0xfb, 0xaa, 0x3c, + 0x2c, 0x8f, 0x0d, 0x7c, 0x09, 0x1c, 0x1a, 0xa5, 0x23, 0x83, 0x98, 0x10, + 0xf4, 0x0c, 0x78, 0xa4, 0xa0, 0x4b, 0x1a, 0x71, 0x52, 0x4b, 0xb3, 0x8b, + 0x4c, 0x29, 0xfe, 0x6f, 0x24, 0x88, 0x7e, 0xd6, 0xf0, 0x6a, 0x2c, 0x3c, + 0x6c, 0xad, 0x54, 0x0c, 0xb6, 0x7b, 0xa4, 0x76, 0x38, 0xbf, 0x35, 0xc6, + 0x66, 0xde, 0x6a, 0x92, 0x43, 0x26, 0x31, 0xae, 0x76, 0xb5, 0xf6, 0x15, + 0x87, 0x02, 0x37, 0x7e, 0x7b, 0x92, 0xda, 0x3f, 0x45, 0x1e, 0x89, 0xb7, + 0x26, 0xb3, 0x8d, 0x3c, 0xf6, 0x49, 0x25, 0xe9, 0x1e, 0x52, 0x6f, 0x40, + 0x2e, 0xb6, 0x7d, 0x5c, 0x2a, 0x8a, 0x9c, 0x7d, 0x2c, 0x09, 0xce, 0xde, + 0x73, 0x5d, 0x3b, 0x7d, 0x4f, 0x3f, 0x4b, 0xdc, 0xeb, 0x8b, 0x93, 0xd1, + 0xc2, 0xf3, 0x29, 0x08, 0x98, 0x06, 0x8c, 0x46, 0x38, 0xe1, 0xd5, 0x30, + 0xc1, 0xf0, 0x3c, 0x74, 0x58, 0xf0, 0x20, 0x8b, 0xea, 0x30, 0x43, 0xd8, + 0x3d, 0x19, 0xc4, 0xd1, 0x04, 0xc8, 0xe5, 0x76, 0x31, 0x36, 0x4a, 0xae, + .. .. .. .. .. .. .. .. .. .. .. .. + 0xd3, 0xb2, 0x75, 0x2b, 0x85, 0x71, 0x02, 0x9a, 0x51, 0x38, 0x08, 0x61, + 0xf8, 0x8b, 0x8b, 0x36, 0xf5, 0x10, 0x6e, 0xd9, 0xda, 0xf5, 0x3a, 0xf1, + 0xf1, 0x6f, 0xc4, 0xd7, 0x52, 0x6f, 0x22, 0x38, 0x8a, 0xff, 0x75, 0x82, + 0x93, 0x94, 0xc9, 0x45, 0xcf, 0xa3, 0x23, 0x04, 0x6f, 0x3a, 0x58, 0xe1, + 0xca, 0xfa, 0xa8, 0x1f, 0xd3, 0x87, 0x6e, 0xcb, 0xe3*/ +}; + +// Replace with your client.key certificate in DER format +uint8_t SECRET_KEY[] = { + /*0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xb6, 0xb7, 0xa2, 0x73, 0x9e, 0x8b, 0xcc, 0x7f, 0x55, 0xb3, 0xb4, 0xad, + 0xfe, 0x6a, 0xbc, 0xa7, 0xe5, 0xec, 0x02, 0xd0, 0x4b, 0x25, 0xa4, 0xd3, + 0xc4, 0x33, 0x37, 0xa7, 0x76, 0xdf, 0xa3, 0x9f, 0xdd, 0x42, 0x3e, 0xb5, + 0xe2, 0xbc, 0x89, 0xe4, 0x18, 0x02, 0xb6, 0x62, 0xe4, 0x3b, 0xa6, 0x74, + 0x76, 0xf8, 0x73, 0xe7, 0x80, 0xea, 0x5d, 0x93, 0x9d, 0x61, 0x2a, 0x24, + 0x06, 0x4c, 0x6b, 0x68, 0xea, 0x63, 0x1d, 0x3a, 0xce, 0x8b, 0x31, 0x05, + 0x72, 0xe9, 0xdc, 0xce, 0x05, 0x8c, 0x7a, 0xc1, 0xf5, 0xd6, 0xe1, 0xd0, + 0x6d, 0x73, 0x4e, 0xc1, 0x8a, 0x16, 0x49, 0x4d, 0xac, 0x21, 0xfb, 0x2d, + 0x12, 0xdd, 0x1e, 0xef, 0x9b, 0xb3, 0x6d, 0x20, 0x69, 0xfb, 0xaa, 0x3c, + 0x2c, 0x8f, 0x0d, 0x7c, 0x09, 0x1c, 0x1a, 0xa5, 0x23, 0x83, 0x98, 0x10, + 0xf4, 0x0c, 0x78, 0xa4, 0xa0, 0x4b, 0x1a, 0x71, 0x52, 0x4b, 0xb3, 0x8b, + 0x4c, 0x29, 0xfe, 0x6f, 0x24, 0x88, 0x7e, 0xd6, 0xf0, 0x6a, 0x2c, 0x3c, + 0x6c, 0xad, 0x54, 0x0c, 0xb6, 0x7b, 0xa4, 0x76, 0x38, 0xbf, 0x35, 0xc6, + 0x66, 0xde, 0x6a, 0x92, 0x43, 0x26, 0x31, 0xae, 0x76, 0xb5, 0xf6, 0x15, + 0x87, 0x02, 0x37, 0x7e, 0x7b, 0x92, 0xda, 0x3f, 0x45, 0x1e, 0x89, 0xb7, + 0x26, 0xb3, 0x8d, 0x3c, 0xf6, 0x49, 0x25, 0xe9, 0x1e, 0x52, 0x6f, 0x40, + 0x2e, 0xb6, 0x7d, 0x5c, 0x2a, 0x8a, 0x9c, 0x7d, 0x2c, 0x09, 0xce, 0xde, + 0x73, 0x5d, 0x3b, 0x7d, 0x4f, 0x3f, 0x4b, 0xdc, 0xeb, 0x8b, 0x93, 0xd1, + 0xc2, 0xf3, 0x29, 0x08, 0x98, 0x06, 0x8c, 0x46, 0x38, 0xe1, 0xd5, 0x30, + 0xc1, 0xf0, 0x3c, 0x74, 0x58, 0xf0, 0x20, 0x8b, 0xea, 0x30, 0x43, 0xd8, + 0x3d, 0x19, 0xc4, 0xd1, 0x04, 0xc8, 0xe5, 0x76, 0x31, 0x36, 0x4a, 0xae, + 0xf4, 0x21, 0x41, 0x0b, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, + 0x00, 0x7b, 0xe7, 0x87, 0x58, 0x54, 0x59, 0x84, 0xf1, 0x8c, 0x92, 0x72, + 0xa1, 0xd2, 0xf7, 0x5a, 0xbb, 0x98, 0xa5, 0x35, 0x3b, 0x3e, 0xda, 0x66, + 0x2d, 0xdc, 0xcc, 0xc6, 0x9e, 0xdf, 0x73, 0xc4, 0xa7, 0xb2, 0x09, 0x2c, + 0x31, 0x77, 0x72, 0x57, 0x27, 0xc0, 0x48, 0x86, 0x9a, 0x05, 0x1f, 0x96, + 0x3f, 0x40, 0x36, 0x37, 0x92, 0xf3, 0xce, 0xfa, 0x6a, 0x11, 0xbd, 0x44, + 0x30, 0x6d, 0xbd, 0x00, 0xd1, 0x82, 0xb0, 0x77, 0xaf, 0xdb, 0x44, 0x74, + 0x97, 0xb7, 0x57, 0x73, 0x8e, 0x9a, 0x20, 0xab, 0x56, 0x40, 0x79, 0xd9, + 0x63, 0xd7, 0xf4, 0xeb, 0xa1, 0x3f, 0x1c, 0xe1, 0xd4, 0xb4, 0x37, 0xce, + 0xf6, 0xbf, 0xe6, 0x07, 0x06, 0x81, 0x55, 0x69, 0x59, 0x23, 0xc5, 0xaf, + 0xa9, 0x62, 0xa6, 0x17, 0x84, 0xd7, 0x40, 0xa1, 0xa8, 0xfe, 0xae, 0x4c, + 0x3e, 0xa2, 0xe0, 0x9a, 0x27, 0x39, 0x33, 0xf4, 0xd7, 0x62, 0x94, 0xac, + 0x58, 0xb8, 0x45, 0x03, 0xdf, 0x19, 0x21, 0x5b, 0xf8, 0x0c, 0xfb, 0x44, + 0x7e, 0xc7, 0x94, 0x15, 0xc1, 0xb5, 0x34, 0xfe, 0x1a, 0x35, 0xf7, 0x73, + 0x7a, 0xf4, 0x5f, 0x15, 0xaf, 0x6e, 0x93, 0x46, 0xbc, 0xae, 0x16, 0x32, + 0xed, 0x37, 0x73, 0x69, 0x17, 0xd7, 0xcc, 0x41, 0x6a, 0x25, 0x17, 0xa6, + 0x35, 0x58, 0x46, 0xb6, 0x2f, 0x13, 0x64, 0x1b, 0x04, 0x02, 0xdc, 0x5d, + 0x06, 0xe6, 0xf3, 0xb8, 0xf5, 0x93, 0xee, 0x39, 0xff, 0x0a, 0xa3, 0x33, + 0x9b, 0x30, 0x63, 0x5e, 0xf8, 0xfd, 0xd6, 0x45, 0x56, 0xe8, 0xdf, 0x64, + 0x62, 0x23, 0xa0, 0xf1, 0x1e, 0x6a, 0x4c, 0xc0, 0xc1, 0x95, 0x47, 0x05, + 0xb7, 0x5a, 0xb3, 0xda, 0xa5, 0x91, 0x81, 0x49, 0xef, 0x1d, 0x36, 0x14, + 0x55, 0x0f, 0x00, 0x9e, 0x28, 0x1b, 0x15, 0x77, 0x6c, 0x24, 0xd0, 0xe8, + 0x3f, 0x79, 0x37, 0x6a, 0xd1, 0x02, 0x81, 0x81, 0x00, 0xdb, 0x95, 0x25, + 0xee, 0x4f, 0x77, 0x20, 0xcf, 0xf8, 0xc4, 0x3a, 0xa5, 0xcf, 0x15, 0x28, + 0x4f, 0xdf, 0x16, 0xbb, 0xfc, 0x10, 0xaa, 0xa5, 0x7f, 0x0d, 0xea, 0x93, + 0xe2, 0xaf, 0x91, 0x9c, 0x77, 0xcc, 0x51, 0x8e, 0xb0, 0x79, 0xc8, 0xba, + 0xe4, 0x75, 0xcb, 0x07, 0x47, 0x04, 0xab, 0xb5, 0xd0, 0x75, 0x6f, 0x61, + 0xa4, 0x98, 0x2d, 0x15, 0xa9, 0x8a, 0xa2, 0x44, 0xde, 0x4c, 0xd7, 0x7f, + 0x01, 0xb7, 0xb4, 0x71, 0x21, 0x6e, 0xff, 0x0b, 0x15, 0x46, 0x81, 0xd8, + 0x53, 0x11, 0x1d, 0x7c, 0x8f, 0x48, 0x6a, 0xd0, 0x1c, 0xe8, 0xe0, 0x7d, + 0xed, 0x44, 0x17, 0x30, 0xcb, 0xed, 0xfc, 0x65, 0x92, 0x21, 0x62, 0x75, + 0x1f, 0x5c, 0x6a, 0x32, 0x4f, 0xc9, 0xb8, 0x98, 0x11, 0xc7, 0x54, 0x18, + .. .. .. .. .. .. .. .. .. .. .. .. + 0x3b, 0x25, 0x36, 0xc2, 0xcd, 0x02, 0x81, 0x81, 0x00, 0xd5, 0x05, 0x4a, + 0x96, 0xf5, 0x50, 0xc4, 0x46, 0x95*/ +}; + + +static const GSMRootCert SECRET_GSM_ROOT_CERTS[] = { + { "DST_Root_CA_X3", + (const uint8_t[]){ + 0x30, 0x82, 0x03, 0x4a, 0x30, 0x82, 0x02, 0x32, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x44, 0xaf, 0xb0, 0x80, 0xd6, 0xa3, 0x27, 0xba, 0x89, + 0x30, 0x39, 0x86, 0x2e, 0xf8, 0x40, 0x6b, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3f, + 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43, + 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, + 0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x30, 0x30, 0x39, 0x33, + 0x30, 0x32, 0x31, 0x31, 0x32, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x31, + 0x30, 0x39, 0x33, 0x30, 0x31, 0x34, 0x30, 0x31, 0x31, 0x35, 0x5a, 0x30, + 0x3f, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, + 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, + 0x43, 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x13, 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, + 0x41, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, + 0x00, 0xdf, 0xaf, 0xe9, 0x97, 0x50, 0x08, 0x83, 0x57, 0xb4, 0xcc, 0x62, + 0x65, 0xf6, 0x90, 0x82, 0xec, 0xc7, 0xd3, 0x2c, 0x6b, 0x30, 0xca, 0x5b, + 0xec, 0xd9, 0xc3, 0x7d, 0xc7, 0x40, 0xc1, 0x18, 0x14, 0x8b, 0xe0, 0xe8, + 0x33, 0x76, 0x49, 0x2a, 0xe3, 0x3f, 0x21, 0x49, 0x93, 0xac, 0x4e, 0x0e, + 0xaf, 0x3e, 0x48, 0xcb, 0x65, 0xee, 0xfc, 0xd3, 0x21, 0x0f, 0x65, 0xd2, + 0x2a, 0xd9, 0x32, 0x8f, 0x8c, 0xe5, 0xf7, 0x77, 0xb0, 0x12, 0x7b, 0xb5, + 0x95, 0xc0, 0x89, 0xa3, 0xa9, 0xba, 0xed, 0x73, 0x2e, 0x7a, 0x0c, 0x06, + 0x32, 0x83, 0xa2, 0x7e, 0x8a, 0x14, 0x30, 0xcd, 0x11, 0xa0, 0xe1, 0x2a, + 0x38, 0xb9, 0x79, 0x0a, 0x31, 0xfd, 0x50, 0xbd, 0x80, 0x65, 0xdf, 0xb7, + 0x51, 0x63, 0x83, 0xc8, 0xe2, 0x88, 0x61, 0xea, 0x4b, 0x61, 0x81, 0xec, + 0x52, 0x6b, 0xb9, 0xa2, 0xe2, 0x4b, 0x1a, 0x28, 0x9f, 0x48, 0xa3, 0x9e, + 0x0c, 0xda, 0x09, 0x8e, 0x3e, 0x17, 0x2e, 0x1e, 0xdd, 0x20, 0xdf, 0x5b, + 0xc6, 0x2a, 0x8a, 0xab, 0x2e, 0xbd, 0x70, 0xad, 0xc5, 0x0b, 0x1a, 0x25, + 0x90, 0x74, 0x72, 0xc5, 0x7b, 0x6a, 0xab, 0x34, 0xd6, 0x30, 0x89, 0xff, + 0xe5, 0x68, 0x13, 0x7b, 0x54, 0x0b, 0xc8, 0xd6, 0xae, 0xec, 0x5a, 0x9c, + 0x92, 0x1e, 0x3d, 0x64, 0xb3, 0x8c, 0xc6, 0xdf, 0xbf, 0xc9, 0x41, 0x70, + 0xec, 0x16, 0x72, 0xd5, 0x26, 0xec, 0x38, 0x55, 0x39, 0x43, 0xd0, 0xfc, + 0xfd, 0x18, 0x5c, 0x40, 0xf1, 0x97, 0xeb, 0xd5, 0x9a, 0x9b, 0x8d, 0x1d, + 0xba, 0xda, 0x25, 0xb9, 0xc6, 0xd8, 0xdf, 0xc1, 0x15, 0x02, 0x3a, 0xab, + 0xda, 0x6e, 0xf1, 0x3e, 0x2e, 0xf5, 0x5c, 0x08, 0x9c, 0x3c, 0xd6, 0x83, + 0x69, 0xe4, 0x10, 0x9b, 0x19, 0x2a, 0xb6, 0x29, 0x57, 0xe3, 0xe5, 0x3d, + 0x9b, 0x9f, 0xf0, 0x02, 0x5d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42, + 0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, + 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, + 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, + 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc4, 0xa7, + 0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, 0xe1, 0x4b, 0x90, 0x75, 0xff, + 0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, + 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, + 0x01, 0x00, 0xa3, 0x1a, 0x2c, 0x9b, 0x17, 0x00, 0x5c, 0xa9, 0x1e, 0xee, + 0x28, 0x66, 0x37, 0x3a, 0xbf, 0x83, 0xc7, 0x3f, 0x4b, 0xc3, 0x09, 0xa0, + 0x95, 0x20, 0x5d, 0xe3, 0xd9, 0x59, 0x44, 0xd2, 0x3e, 0x0d, 0x3e, 0xbd, + 0x8a, 0x4b, 0xa0, 0x74, 0x1f, 0xce, 0x10, 0x82, 0x9c, 0x74, 0x1a, 0x1d, + 0x7e, 0x98, 0x1a, 0xdd, 0xcb, 0x13, 0x4b, 0xb3, 0x20, 0x44, 0xe4, 0x91, + 0xe9, 0xcc, 0xfc, 0x7d, 0xa5, 0xdb, 0x6a, 0xe5, 0xfe, 0xe6, 0xfd, 0xe0, + 0x4e, 0xdd, 0xb7, 0x00, 0x3a, 0xb5, 0x70, 0x49, 0xaf, 0xf2, 0xe5, 0xeb, + 0x02, 0xf1, 0xd1, 0x02, 0x8b, 0x19, 0xcb, 0x94, 0x3a, 0x5e, 0x48, 0xc4, + 0x18, 0x1e, 0x58, 0x19, 0x5f, 0x1e, 0x02, 0x5a, 0xf0, 0x0c, 0xf1, 0xb1, + 0xad, 0xa9, 0xdc, 0x59, 0x86, 0x8b, 0x6e, 0xe9, 0x91, 0xf5, 0x86, 0xca, + 0xfa, 0xb9, 0x66, 0x33, 0xaa, 0x59, 0x5b, 0xce, 0xe2, 0xa7, 0x16, 0x73, + 0x47, 0xcb, 0x2b, 0xcc, 0x99, 0xb0, 0x37, 0x48, 0xcf, 0xe3, 0x56, 0x4b, + 0xf5, 0xcf, 0x0f, 0x0c, 0x72, 0x32, 0x87, 0xc6, 0xf0, 0x44, 0xbb, 0x53, + 0x72, 0x6d, 0x43, 0xf5, 0x26, 0x48, 0x9a, 0x52, 0x67, 0xb7, 0x58, 0xab, + 0xfe, 0x67, 0x76, 0x71, 0x78, 0xdb, 0x0d, 0xa2, 0x56, 0x14, 0x13, 0x39, + 0x24, 0x31, 0x85, 0xa2, 0xa8, 0x02, 0x5a, 0x30, 0x47, 0xe1, 0xdd, 0x50, + 0x07, 0xbc, 0x02, 0x09, 0x90, 0x00, 0xeb, 0x64, 0x63, 0x60, 0x9b, 0x16, + 0xbc, 0x88, 0xc9, 0x12, 0xe6, 0xd2, 0x7d, 0x91, 0x8b, 0xf9, 0x3d, 0x32, + 0x8d, 0x65, 0xb4, 0xe9, 0x7c, 0xb1, 0x57, 0x76, 0xea, 0xc5, 0xb6, 0x28, + 0x39, 0xbf, 0x15, 0x65, 0x1c, 0xc8, 0xf6, 0x77, 0x96, 0x6a, 0x0a, 0x8d, + 0x77, 0x0b, 0xd8, 0x91, 0x0b, 0x04, 0x8e, 0x07, 0xdb, 0x29, 0xb6, 0x0a, + 0xee, 0x9d, 0x82, 0x35, 0x35, 0x10 }, + 846 }, + { "Let_s_Encrypt_Authority_X3", + (const uint8_t[]){ + 0x30, 0x82, 0x04, 0x92, 0x30, 0x82, 0x03, 0x7a, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x0a, 0x01, 0x41, 0x42, 0x00, 0x00, 0x01, 0x53, 0x85, + 0x73, 0x6a, 0x0b, 0x85, 0xec, 0xa7, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3f, + 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43, + 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, + 0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x33, 0x31, + 0x37, 0x31, 0x36, 0x34, 0x30, 0x34, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x31, + 0x30, 0x33, 0x31, 0x37, 0x31, 0x36, 0x34, 0x30, 0x34, 0x36, 0x5a, 0x30, + 0x4a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + 0x55, 0x53, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, + 0x0d, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x31, 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x1a, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, + 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, + 0x9c, 0xd3, 0x0c, 0xf0, 0x5a, 0xe5, 0x2e, 0x47, 0xb7, 0x72, 0x5d, 0x37, + 0x83, 0xb3, 0x68, 0x63, 0x30, 0xea, 0xd7, 0x35, 0x26, 0x19, 0x25, 0xe1, + 0xbd, 0xbe, 0x35, 0xf1, 0x70, 0x92, 0x2f, 0xb7, 0xb8, 0x4b, 0x41, 0x05, + 0xab, 0xa9, 0x9e, 0x35, 0x08, 0x58, 0xec, 0xb1, 0x2a, 0xc4, 0x68, 0x87, + 0x0b, 0xa3, 0xe3, 0x75, 0xe4, 0xe6, 0xf3, 0xa7, 0x62, 0x71, 0xba, 0x79, + 0x81, 0x60, 0x1f, 0xd7, 0x91, 0x9a, 0x9f, 0xf3, 0xd0, 0x78, 0x67, 0x71, + 0xc8, 0x69, 0x0e, 0x95, 0x91, 0xcf, 0xfe, 0xe6, 0x99, 0xe9, 0x60, 0x3c, + 0x48, 0xcc, 0x7e, 0xca, 0x4d, 0x77, 0x12, 0x24, 0x9d, 0x47, 0x1b, 0x5a, + 0xeb, 0xb9, 0xec, 0x1e, 0x37, 0x00, 0x1c, 0x9c, 0xac, 0x7b, 0xa7, 0x05, + 0xea, 0xce, 0x4a, 0xeb, 0xbd, 0x41, 0xe5, 0x36, 0x98, 0xb9, 0xcb, 0xfd, + 0x6d, 0x3c, 0x96, 0x68, 0xdf, 0x23, 0x2a, 0x42, 0x90, 0x0c, 0x86, 0x74, + 0x67, 0xc8, 0x7f, 0xa5, 0x9a, 0xb8, 0x52, 0x61, 0x14, 0x13, 0x3f, 0x65, + 0xe9, 0x82, 0x87, 0xcb, 0xdb, 0xfa, 0x0e, 0x56, 0xf6, 0x86, 0x89, 0xf3, + 0x85, 0x3f, 0x97, 0x86, 0xaf, 0xb0, 0xdc, 0x1a, 0xef, 0x6b, 0x0d, 0x95, + 0x16, 0x7d, 0xc4, 0x2b, 0xa0, 0x65, 0xb2, 0x99, 0x04, 0x36, 0x75, 0x80, + 0x6b, 0xac, 0x4a, 0xf3, 0x1b, 0x90, 0x49, 0x78, 0x2f, 0xa2, 0x96, 0x4f, + 0x2a, 0x20, 0x25, 0x29, 0x04, 0xc6, 0x74, 0xc0, 0xd0, 0x31, 0xcd, 0x8f, + 0x31, 0x38, 0x95, 0x16, 0xba, 0xa8, 0x33, 0xb8, 0x43, 0xf1, 0xb1, 0x1f, + 0xc3, 0x30, 0x7f, 0xa2, 0x79, 0x31, 0x13, 0x3d, 0x2d, 0x36, 0xf8, 0xe3, + 0xfc, 0xf2, 0x33, 0x6a, 0xb9, 0x39, 0x31, 0xc5, 0xaf, 0xc4, 0x8d, 0x0d, + 0x1d, 0x64, 0x16, 0x33, 0xaa, 0xfa, 0x84, 0x29, 0xb6, 0xd4, 0x0b, 0xc0, + 0xd8, 0x7d, 0xc3, 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, + 0x7d, 0x30, 0x82, 0x01, 0x79, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, + 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, + 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, + 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x7f, 0x06, 0x08, 0x2b, 0x06, 0x01, + 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x73, 0x30, 0x71, 0x30, 0x32, 0x06, + 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x26, 0x68, + 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x69, 0x73, 0x72, 0x67, 0x2e, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x69, 0x64, 0x2e, 0x6f, 0x63, 0x73, 0x70, 0x2e, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, 0x2e, 0x63, 0x6f, + 0x6d, 0x30, 0x3b, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, + 0x02, 0x86, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x61, 0x70, + 0x70, 0x73, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x6f, 0x6f, 0x74, 0x73, 0x2f, 0x64, + 0x73, 0x74, 0x72, 0x6f, 0x6f, 0x74, 0x63, 0x61, 0x78, 0x33, 0x2e, 0x70, + 0x37, 0x63, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, + 0x16, 0x80, 0x14, 0xc4, 0xa7, 0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, + 0xe1, 0x4b, 0x90, 0x75, 0xff, 0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, + 0x54, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x4d, 0x30, 0x4b, 0x30, 0x08, + 0x06, 0x06, 0x67, 0x81, 0x0c, 0x01, 0x02, 0x01, 0x30, 0x3f, 0x06, 0x0b, + 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xdf, 0x13, 0x01, 0x01, 0x01, 0x30, + 0x30, 0x30, 0x2e, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, + 0x01, 0x16, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x70, + 0x73, 0x2e, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x78, 0x31, 0x2e, 0x6c, 0x65, + 0x74, 0x73, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2e, 0x6f, 0x72, + 0x67, 0x30, 0x3c, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x35, 0x30, 0x33, + 0x30, 0x31, 0xa0, 0x2f, 0xa0, 0x2d, 0x86, 0x2b, 0x68, 0x74, 0x74, 0x70, + 0x3a, 0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x44, 0x53, 0x54, + 0x52, 0x4f, 0x4f, 0x54, 0x43, 0x41, 0x58, 0x33, 0x43, 0x52, 0x4c, 0x2e, + 0x63, 0x72, 0x6c, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, + 0x04, 0x14, 0xa8, 0x4a, 0x6a, 0x63, 0x04, 0x7d, 0xdd, 0xba, 0xe6, 0xd1, + 0x39, 0xb7, 0xa6, 0x45, 0x65, 0xef, 0xf3, 0xa8, 0xec, 0xa1, 0x30, 0x0d, + 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, + 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0xdd, 0x33, 0xd7, 0x11, 0xf3, 0x63, + 0x58, 0x38, 0xdd, 0x18, 0x15, 0xfb, 0x09, 0x55, 0xbe, 0x76, 0x56, 0xb9, + 0x70, 0x48, 0xa5, 0x69, 0x47, 0x27, 0x7b, 0xc2, 0x24, 0x08, 0x92, 0xf1, + 0x5a, 0x1f, 0x4a, 0x12, 0x29, 0x37, 0x24, 0x74, 0x51, 0x1c, 0x62, 0x68, + 0xb8, 0xcd, 0x95, 0x70, 0x67, 0xe5, 0xf7, 0xa4, 0xbc, 0x4e, 0x28, 0x51, + 0xcd, 0x9b, 0xe8, 0xae, 0x87, 0x9d, 0xea, 0xd8, 0xba, 0x5a, 0xa1, 0x01, + 0x9a, 0xdc, 0xf0, 0xdd, 0x6a, 0x1d, 0x6a, 0xd8, 0x3e, 0x57, 0x23, 0x9e, + 0xa6, 0x1e, 0x04, 0x62, 0x9a, 0xff, 0xd7, 0x05, 0xca, 0xb7, 0x1f, 0x3f, + 0xc0, 0x0a, 0x48, 0xbc, 0x94, 0xb0, 0xb6, 0x65, 0x62, 0xe0, 0xc1, 0x54, + 0xe5, 0xa3, 0x2a, 0xad, 0x20, 0xc4, 0xe9, 0xe6, 0xbb, 0xdc, 0xc8, 0xf6, + 0xb5, 0xc3, 0x32, 0xa3, 0x98, 0xcc, 0x77, 0xa8, 0xe6, 0x79, 0x65, 0x07, + 0x2b, 0xcb, 0x28, 0xfe, 0x3a, 0x16, 0x52, 0x81, 0xce, 0x52, 0x0c, 0x2e, + 0x5f, 0x83, 0xe8, 0xd5, 0x06, 0x33, 0xfb, 0x77, 0x6c, 0xce, 0x40, 0xea, + 0x32, 0x9e, 0x1f, 0x92, 0x5c, 0x41, 0xc1, 0x74, 0x6c, 0x5b, 0x5d, 0x0a, + 0x5f, 0x33, 0xcc, 0x4d, 0x9f, 0xac, 0x38, 0xf0, 0x2f, 0x7b, 0x2c, 0x62, + 0x9d, 0xd9, 0xa3, 0x91, 0x6f, 0x25, 0x1b, 0x2f, 0x90, 0xb1, 0x19, 0x46, + 0x3d, 0xf6, 0x7e, 0x1b, 0xa6, 0x7a, 0x87, 0xb9, 0xa3, 0x7a, 0x6d, 0x18, + 0xfa, 0x25, 0xa5, 0x91, 0x87, 0x15, 0xe0, 0xf2, 0x16, 0x2f, 0x58, 0xb0, + 0x06, 0x2f, 0x2c, 0x68, 0x26, 0xc6, 0x4b, 0x98, 0xcd, 0xda, 0x9f, 0x0c, + 0xf9, 0x7f, 0x90, 0xed, 0x43, 0x4a, 0x12, 0x44, 0x4e, 0x6f, 0x73, 0x7a, + 0x28, 0xea, 0xa4, 0xaa, 0x6e, 0x7b, 0x4c, 0x7d, 0x87, 0xdd, 0xe0, 0xc9, + 0x02, 0x44, 0xa7, 0x87, 0xaf, 0xc3, 0x34, 0x5b, 0xb4, 0x42 }, + 1174 } +}; + + +#define SECRET_GSM_ROOT_SIZE (sizeof(SECRET_GSM_ROOT_CERTS) / sizeof(SECRET_GSM_ROOT_CERTS[0])) diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SendSMS/SendSMS.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SendSMS/SendSMS.ino new file mode 100644 index 00000000..210b1063 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SendSMS/SendSMS.ino @@ -0,0 +1,100 @@ +/* + SMS sender + + This sketch, for the MKR GSM 1400 board,sends an SMS message + you enter in the Serial Monitor. Connect your Arduino with the + GSM shield and SIM card, open the Serial Monitor, and wait for + the "READY" message to appear in the monitor. Next, type a + message to send and press "return". Make sure the serial + monitor is set to send a newline when you press return. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card that can send SMS + + created 25 Feb 2012 + by Tom Igoe +*/ + +// Include the GSM library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; +GSM_SMS sms; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("SMS Messages Sender"); + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("GSM initialized"); +} + +void loop() { + + Serial.print("Enter a mobile number: "); + char remoteNum[20]; // telephone number to send SMS + readSerial(remoteNum); + Serial.println(remoteNum); + + // SMS text + Serial.print("Now, enter SMS content: "); + char txtMsg[200]; + readSerial(txtMsg); + Serial.println("SENDING"); + Serial.println(); + Serial.println("Message:"); + Serial.println(txtMsg); + + // send the message + sms.beginSMS(remoteNum); + sms.print(txtMsg); + sms.endSMS(); + Serial.println("\nCOMPLETE!\n"); +} + +/* + Read input serial + */ +int readSerial(char result[]) { + int i = 0; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + result[i] = '\0'; + Serial.flush(); + return 0; + } + if (inChar != '\r') { + result[i] = inChar; + i++; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SendSMS/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SendSMS/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/SendSMS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/BandManagement/BandManagement.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/BandManagement/BandManagement.ino new file mode 100644 index 00000000..6da5ebf5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/BandManagement/BandManagement.ino @@ -0,0 +1,117 @@ +/* + Band Management + + This sketch, for the MKR GSM 1400 board, checks the band + currently configured in the modem and allows you to change + it. + + Please check http://www.worldtimezone.com/gsm.html + Usual configurations: + Europe, Africa, Middle East: E-GSM(900)+DCS(1800) + USA, Canada, South America: GSM(850)+PCS(1900) + Mexico: PCS(1900) + Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900) + + + Circuit: + * MKR GSM 1400 board + * Antenna + + created 12 June 2012 + by Javier Zorzano, Scott Fitzgerald +*/ + +// libraries +#include + +// initialize the library instance +GSMBand band; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Beginning the band manager restarts the modem + Serial.println("Restarting modem..."); + band.begin(); + Serial.println("Modem restarted."); +}; + + +void loop() { + // Get current band + String bandName = band.getBand(); // Get and print band name + Serial.print("Current band:"); + Serial.println(bandName); + Serial.println("Want to change the band you’re on?"); + String newBandName; + newBandName = askUser(); + // Tell the user what we are about to do… + Serial.print("\nConfiguring band "); + Serial.println(newBandName); + // Change the band + bool operationSuccess; + operationSuccess = band.setBand(newBandName); + // Tell the user if the operation was OK + if (operationSuccess) { + Serial.println("Success"); + } else { + Serial.println("Error while changing band"); + } + + if (operationSuccess) { + while (true) + ; + } +} + +// This function offers the user different options +// through the Serial interface +// The user selects one +String askUser() { + String newBand; + Serial.println("Select band:"); + // Print the different options + Serial.println("1 : E-GSM(900)"); + Serial.println("2 : DCS(1800)"); + Serial.println("3 : PCS(1900)"); + Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe"); + Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am."); + Serial.println("6 : GSM800(800)+GSM(850)+E-GSM(900)+PCS(1900)"); + Serial.println("7 : UMTS(2100)"); + Serial.println("8 : GSM(850)+E-GSM(900)+PCS(1900)+UMTS(2100)"); + + // Empty the incoming buffer + while (Serial.available()) { + Serial.read(); + } + + // Wait for an answer, just look at the first character + while (!Serial.available()) + ; + char c = Serial.read(); + if (c == '1') { + newBand = GSM_MODE_EGSM; + } else if (c == '2') { + newBand = GSM_MODE_DCS; + } else if (c == '3') { + newBand = GSM_MODE_PCS; + } else if (c == '4') { + newBand = GSM_MODE_EGSM_DCS; + } else if (c == '5') { + newBand = GSM_MODE_GSM850_PCS; + } else if (c == '6') { + newBand = GSM_MODE_GSM850_EGSM_DCS_PCS; + } else if (c == '7') { + newBand = GSM_MODE_UMTS; + } else if (c == '8') { + newBand = GSM_MODE_GSM850_EGSM_PCS_UMTS; + } else { + newBand = "GSM_MODE_UNDEFINED"; + } + + return newBand; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino new file mode 100644 index 00000000..f24eabfe --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino @@ -0,0 +1,132 @@ +/* + Radio Access Technology selection for Arduino MKR GSM 1400 + + This sketch allows you to select your preferred Radio Access + Technology (RAT). + + You can choose among 2G, 3G/UTMS or a combination of both. + + The chosen configuration will be saved to the modem's internal memory + and will be preserved through MKR GSM 1400 sketch uploads. + + In order to change the RAT, you will need to run this sketch again. + + Circuit: + - MKR GSM 1400 board + - Antenna + - SIM card + + Created 19 August 2019 + by Riccardo Rizzo + +*/ + +#include + + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + MODEM.begin(); + while (!MODEM.noop()) + ; + + for (int i = 0; i < 80; i++) Serial.print("*"); + Serial.println(); + Serial.println("This sketch allows you to select your preferred"); + Serial.println("GSM Radio Access Technology (RAT)."); + Serial.println(); + Serial.println("You can choose among 2G, 3G/UMTS or a combination of both."); + Serial.println(); + Serial.println("The chosen configuration will be saved to the modem's internal memory"); + Serial.println("and will be preserved through MKR GSM 1400 sketch uploads."); + Serial.println(); + Serial.println("In order to change the RAT, you will need to run this sketch again."); + for (int i = 0; i < 80; i++) Serial.print("*"); + + Serial.println(); + Serial.println(); + Serial.println("Please choose your Radio Access Technology:"); + Serial.println(); + Serial.println(" 0 - 2G only"); + Serial.println(" 1 - 3G/UMTS only"); + Serial.println(" 2 - 2G preferred, 3G/UMTS as failover"); + Serial.println(" 3 - 3G/UMTS preferred, 2G as failover (default)"); + Serial.println(); +} + +void loop() { + String uratChoice; + + Serial.print("> "); + + Serial.setTimeout(-1); + while (Serial.available() == 0) + ; + String uratInput = Serial.readStringUntil('\n'); + uratInput.trim(); + int urat = uratInput.toInt(); + Serial.println(urat); + + switch (urat) { + case 0: + uratChoice = "0"; + break; + case 1: + uratChoice = "2"; + break; + case 2: + uratChoice = "1,0"; + break; + case 3: + uratChoice = "1,2"; + break; + default: + Serial.println("Invalid input. Please, retry."); + return; + } + + setRAT(uratChoice); + apply(); + + Serial.println(); + Serial.println("Radio Access Technology selected."); + Serial.println("Now you can upload your 2G or 3G application sketch."); + while (true) + ; +} + +bool setRAT(String choice) { + String response; + + Serial.print("Disconnecting from network: "); + MODEM.sendf("AT+COPS=2"); + MODEM.waitForResponse(10000); + Serial.println("done."); + + Serial.print("Setting Radio Access Technology: "); + MODEM.sendf("AT+URAT=%s", choice.c_str()); + MODEM.waitForResponse(10000, &response); + Serial.println("done."); + + return true; +} + +bool apply() { + Serial.print("Applying changes and saving configuration: "); + MODEM.reset(); + delay(5000); + Serial.println("Modem restart"); + MODEM.begin(true); + + do { + delay(1000); + MODEM.noop(); + } while (MODEM.waitForResponse(1000) != 1); + + Serial.println("done."); + + return true; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/FileUtilsHttpDownload.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/FileUtilsHttpDownload.ino new file mode 100644 index 00000000..c458aec6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/FileUtilsHttpDownload.ino @@ -0,0 +1,212 @@ +/* + Download a large file and store it into the GSM module filesystem. + + This sketch connects to a website through a MKR GSM 1400 board and + downloads a large file and stores it into the filesystem of the GSM + module. + + The file is processed in blocks of 512 bytes in order to save RAM. + A block of data is read from the GSM module and the appended to a + file created by the sketch. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + created 19 June 2020 + by Giampaolo Mancini +*/ + +// libraries +#include + +GSMFileUtils fileUtils(false); + +#include "Helpers.h" + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMClient client; +GPRS gprs; +GSM gsmAccess; + +// URL, path and port (for example: example.org) + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + + fileUtils.begin(); + + // List files on the GSM module's filesystem + auto numberOfFiles = fileUtils.fileCount(); + Serial.print("Number of Files: "); + Serial.println(numberOfFiles); + Serial.println(); + + printFiles(fileUtils); + + auto server = promptAndReadLine("Please, enter server name:", "arduino.cc"); + auto port = promptAndReadInt("Please, enter server port:", 80); + auto filename = promptAndReadLine("Please, enter file name:", "asciilogo.txt"); + auto filesize = promptAndReadInt("Please, enter file size:", 2263); + Serial.println("Connecting..."); + + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + // if you get a connection, report back via serial: + if (client.connect(server.c_str(), port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET /"); + client.print(filename); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("Connection failed"); + } + + // Download and store block-by-block + storeFileBuffered(filename, filesize); + + auto updateBinSize = fileUtils.listFile(filename); + Serial.print(filename); + Serial.print(" downloaded size: "); + Serial.println(updateBinSize); + + numberOfFiles = fileUtils.fileCount(); + Serial.print("Number of Files: "); + Serial.println(numberOfFiles); + Serial.println(); + + printFiles(fileUtils); +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char r = client.read(); + if (r < 16) + Serial.print(0); + Serial.print(r, HEX); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} + +void storeFileBuffered(String filename, uint32_t totalLen) { + Serial.print("Ready to download \""); + Serial.print(filename); + Serial.print("\" - len: "); + Serial.print(totalLen); + Serial.println(" bytes."); + + constexpr uint32_t len{ 512 }; + + uint32_t cycles = totalLen / len; + uint32_t spares = totalLen % len; + + int totalRead{ 0 }; + + fileUtils.deleteFile(filename); + + Serial.print("Saving file in "); + Serial.print(cycles + 1); + Serial.print(" blocks. ["); + Serial.print(cycles); + Serial.print(' '); + Serial.print(len); + Serial.print(" -bytes blocks and "); + Serial.print(spares); + Serial.println(" bytes]."); + + bool is_header_complete = false; + String http_header; + + // Skip the HTTP header + while (!is_header_complete) { + while (client.available()) { + const char c = client.read(); + http_header += c; + if (http_header.endsWith("\r\n\r\n")) { + Serial.println("Header Complete"); + is_header_complete = true; + break; + } + } + } + + // Define download and save lambda + auto downloadAndSaveTrunk = [filename](uint32_t len) { + char buf[len]{ 0 }; + uint32_t written{ 0 }; + + if (client.available()) + written = client.readBytes(buf, len); + + fileUtils.appendFile(filename, buf, written); + return written; + }; + + // Define wrapper function + auto saveTrunk = [&totalRead, downloadAndSaveTrunk](size_t iter, uint32_t len) { + Serial.print("Block "); + if (iter < 10) Serial.print(' '); + if (iter < 100) Serial.print(' '); + Serial.print(iter); + + totalRead += downloadAndSaveTrunk(len); + + Serial.print(": "); + Serial.print(len); + Serial.print(" - "); + Serial.print(totalRead); + Serial.println(); + }; + + // Download and save complete trunks + spares + for (auto c = 0; c <= cycles; c++) + saveTrunk(c, len); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/Helpers.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/Helpers.h new file mode 100644 index 00000000..5d466377 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/Helpers.h @@ -0,0 +1,113 @@ +#pragma once +#include + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + } else if (c == '\n') { + break; + } + + line += c; + } + } + + line.trim(); + + return line; +} + +String promptAndReadLine(const char* prompt, const char* defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + + if (s.length() == 0) { + s = defaultValue; + } + + Serial.println(s); + + return s; +} + +int promptAndReadInt(const char* prompt, const int defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + int r; + + if (s.length() == 0) { + r = defaultValue; + } else { + r = s.toInt(); + } + + Serial.println(r); + + return r; +} + +String promptAndReadLine(const char* prompt) { + Serial.print(prompt); + String s = readLine(); + Serial.println(s); + + return s; +} + +int promptAndReadInt(const char* prompt) { + Serial.print(prompt); + String s = readLine(); + Serial.println(s); + + return s.toInt(); +} + + +String toHex(char c) { + String hex; + + hex = "0x"; + if (c < 16) + hex += "0"; + hex += String(c, HEX); + + return hex; +} + +void printHex(const String& buf, const unsigned int cols) { + for (size_t i = 0; i < buf.length(); i++) { + String hex = toHex(buf[i]); + hex += " "; + Serial.print(hex); + if (i % cols == (cols - 1)) + Serial.println(); + } + Serial.println(); +} + +void printHex(const uint8_t* buf, const size_t len, const unsigned int cols) { + for (size_t i = 0; i < len; i++) { + // Serial.print("0x"); + if (buf[i] < 16) + Serial.print(0); + Serial.print(buf[i], HEX); + // if (i != len - 1) Serial.print(", "); + if (i % cols == (cols - 1)) + Serial.println(); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/arduino_secrets.h new file mode 100644 index 00000000..cdd607cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/Config.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/Config.h new file mode 100644 index 00000000..26206ba4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/Config.h @@ -0,0 +1,64 @@ +#pragma once + +#include + + +// Make the struct Printable to allow Serial.print-ing +struct Config : public Printable { + String deviceId; + int timestamp; + + String toJson() { + JSONVar conf; + + conf["deviceId"] = deviceId; + conf["timestamp"] = timestamp; + + return JSON.stringify(conf); + } + + bool fromJSON(const String buf) { + auto conf = JSON.parse(buf); + + if (!checkProperty(conf, "deviceId", "string")) + return false; + + if (!checkProperty(conf, "timestamp", "number")) + return false; + + deviceId = conf["deviceId"]; + timestamp = int{ conf["timestamp"] }; + + return true; + } + + virtual size_t printTo(Print& p) const { + size_t written{ 0 }; + + written += p.print("DeviceId: "); + written += p.println(deviceId); + written += p.print("Timestamp: "); + written += p.println(timestamp); + + return written; + } + +private: + bool checkProperty(JSONVar json, String property, String type) { + if (!json.hasOwnProperty(property)) { + Serial.print(property); + Serial.println(" not found"); + return false; + } + + if (JSON.typeof(json[property]) != type) { + Serial.print(property); + Serial.print(" != \""); + Serial.print(type); + Serial.println("\""); + return false; + } + + return true; + } +}; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/FileUtilsJsonFile.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/FileUtilsJsonFile.ino new file mode 100644 index 00000000..ec6abe94 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/FileUtilsJsonFile.ino @@ -0,0 +1,117 @@ +/* + Manage JSON configurations via GSM module filesystem. + + This sketch demonstrates how to use the internal filesystem + of the GSM module to store and retrieve data and configurations + both as JSON objects or C++ structs. + + Circuit: + * MKR GSM 1400 board + + created 19 June 2020 + by Giampaolo Mancini +*/ + +#include +#include + +#include "Config.h" + +GSMFileUtils fileUtils; + +void setup() { + Serial.begin(9600); + + while (!Serial) + ; + + Serial.println("Store and Retrieve JSON data to GSM module storage."); + Serial.println(); + + fileUtils.begin(); + + simpleDemo(); + structDemo(); + + while (true) + ; +} + +void loop() { +} + +void simpleDemo() { + + Serial.println(); + Serial.println("========================"); + Serial.println("Running simple JSON demo"); + Serial.println(); + + JSONVar myObject; + + myObject["hello"] = "world"; + myObject["true"] = true; + myObject["x"] = 42; + + String jsonString = JSON.stringify(myObject); + + Serial.println("Saving JSON file (test.json): "); + Serial.println(jsonString); + Serial.println(); + fileUtils.downloadFile("test.json", jsonString); + + printFiles(fileUtils); + Serial.println(); + + String jsonData; + Serial.println("Reading JSON file (test.json): "); + fileUtils.readFile("test.json", &jsonData); + + Serial.println("File contents:"); + Serial.println(jsonData); + Serial.println(); + + Serial.println("Parsing JSON contents:"); + JSONVar myConf = JSON.parse(jsonData); + Serial.print("myConf[\"hello\"]: "); + Serial.println(myConf["hello"]); + Serial.print("myConf[\"true\"]: "); + Serial.println(myConf["true"]); + Serial.print("myConf[\"x\"]: "); + Serial.println(myConf["x"]); +} + +void structDemo() { + GSMModem modem; + + Serial.println(); + Serial.println("========================"); + Serial.println("Running Configuration via struct and JSON demo"); + Serial.println(); + Serial.println("Creating configuration struct:"); + + Config conf; + conf.deviceId = modem.getICCID(); + conf.timestamp = millis(); + + Serial.print(conf); + + fileUtils.downloadFile("conf.json", conf.toJson()); + + Serial.println(); + printFiles(fileUtils); + Serial.println(); + + Serial.println("Reading configuration file:"); + + String jsonConf; + fileUtils.readFile("conf.json", &jsonConf); + Serial.println(jsonConf); + Serial.println(); + + Serial.println("Reading configuration struct:"); + Config newConf; + newConf.fromJSON(jsonConf); + + Serial.print(newConf); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsReadBlock/FileUtilsReadBlock.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsReadBlock/FileUtilsReadBlock.ino new file mode 100644 index 00000000..a73b6d73 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsReadBlock/FileUtilsReadBlock.ino @@ -0,0 +1,64 @@ +/* + Read large files block-by-block from the GSM module filesystem. + + This sketch allows you to read large (max 2.5 MB) files from the + module's internal filesystem using successive block-by-block reads. + + The contents of the file are printed to the Serial port as an + hexadecimal string which can be later converted to the original + content using an external tool, such as 'xxd', eg. + + 'xxd -p -r sketch_output.txt data.bin' + + Circuit: + - MKR GSM 1400 board + + Created 19 June 2020 + by Giampaolo Mancini + +*/ + +#include + +GSMFileUtils fileUtils(false); + +// An existing file +constexpr char* filename{ "update.bin" }; + +// Read block size +constexpr unsigned int blockSize{ 512 }; + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + fileUtils.begin(); + + auto size = fileUtils.listFile(filename); + auto cycles = (size / blockSize) + 1; + + uint32_t totalRead{ 0 }; + + for (auto i = 0; i < cycles; i++) { + uint8_t block[blockSize]{ 0 }; + auto read = fileUtils.readBlock(filename, i * blockSize, blockSize, block); + totalRead += read; + for (auto j = 0; j < read; j++) { + if (block[j] < 16) + Serial.print(0); + Serial.print(block[j], HEX); + } + Serial.println(); + } + + if (totalRead != size) { + Serial.print("ERROR - File size: "); + Serial.print(size); + Serial.print(" Bytes read: "); + Serial.println(totalRead); + } +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino new file mode 100644 index 00000000..59a3d630 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino @@ -0,0 +1,89 @@ +/* + + GSM Scan Networks + + This example prints out the IMEI number of the modem, + then checks to see if it's connected to a carrier. If so, + it prints the phone number associated with the card. + Then it scans for nearby networks and prints out their signal strengths. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card + + Created 8 Mar 2012 + by Tom Igoe, implemented by Javier Carazo + Modified 4 Feb 2013 + by Scott Fitzgerald +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; // include a 'true' parameter to enable debugging +GSMScanner scannerNetworks; +GSMModem modemTest; + +// Save data variables +String IMEI = ""; + +// Serial Monitor result messages +String errortext = "ERROR"; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("GSM networks scanner"); + scannerNetworks.begin(); + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + // get modem parameters + // IMEI, modem unique identifier + Serial.print("Modem IMEI: "); + IMEI = modemTest.getIMEI(); + IMEI.replace("\n", ""); + if (IMEI != NULL) { + Serial.println(IMEI); + } +} + +void loop() { + // scan for existing networks, displays a list of networks + Serial.println("Scanning available networks. May take some seconds."); + Serial.println(scannerNetworks.readNetworks()); + + // currently connected carrier + Serial.print("Current carrier: "); + Serial.println(scannerNetworks.getCurrentCarrier()); + + // returns strength and BER + // signal strength in 0-31 scale. 31 means power > 51 dBm + // BER is the Bit Error Rate. 0-7 scale. 99=not detectable + Serial.print("Signal Strength: "); + Serial.print(scannerNetworks.getSignalStrength()); + Serial.println(" [0-31]"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/HttpUtilsGet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/HttpUtilsGet.ino new file mode 100644 index 00000000..8a04d4b0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/HttpUtilsGet.ino @@ -0,0 +1,88 @@ +/* + This sketch shows how to use the HTTP command to + make an HTTP request and store the result in the + SARA-U201 internal storage + + Circuit: + - MKR GSM 1400 board + + Created 3 September 2020 + by Riccardo Rizzo + +*/ + +#include +#include +#include "arduino_secrets.h" + + +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMHttpUtils httpClient; +GPRS gprs; +GSM gsmAccess; + +GSMFileUtils fileUtils(false); + +// URL, path and port (for example: example.org) +char server[] = "example.org"; +char path[] = "/"; +int port = 80; // port 80 is the default for HTTP + +// An existing file +constexpr char* filename{ "get.ffs" }; + +// Read block size +constexpr unsigned int blockSize{ 512 }; + + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + bool connected = false; + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + fileUtils.begin(false); + + // configure all the parameters to make the http request + httpClient.configServer(server, port); + httpClient.get(path, filename); +} + +void loop() { + if (httpClient.responseStatus()) { + Serial.println("received"); + String fileList[10]; + auto size = fileUtils.listFiles(fileList); + for (int i = 0; i < size && i < 10; i++) { + if (fileList[i] == filename) { + Serial.print("file found: "); + Serial.println(fileList[i]); + } + } + while (1) + ; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/arduino_secrets.h new file mode 100644 index 00000000..9a304c4f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/arduino_secrets.h @@ -0,0 +1,5 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/HttpUtilsSSLGet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/HttpUtilsSSLGet.ino new file mode 100644 index 00000000..a4a9da26 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/HttpUtilsSSLGet.ino @@ -0,0 +1,96 @@ +/* + This sketch shows how to use the HTTP command to + make an HTTP request to the HTTPS end point and store + the result in the SARA-U201 internal storage + + Circuit: + - MKR GSM 1400 board + + Created 3 September 2020 + by Riccardo Rizzo + +*/ + +#include +#include +#include "arduino_secrets.h" + + +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMHttpUtils httpClient; +GPRS gprs; +GSM gsmAccess; + +GSMFileUtils fileUtils(false); + +// URL, path and port (for example: example.org) +char server[] = "google.com"; +char path[] = "/"; +int port = 443; // port 80 is the default for HTTP + +// An existing file +constexpr char* filename{ "get.ffs" }; + + +// Read block size +constexpr unsigned int blockSize{ 512 }; + + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void readFile(); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + bool connected = false; + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + fileUtils.begin(false); + + httpClient.enableSSL(); + httpClient.configServer(server, port); + httpClient.get(path, filename); +} + +void loop() { + if (httpClient.responseStatus()) { + Serial.println("received"); + + readFile(); + while (1) + ; + } +} + +void readFile() { + String fileList[10]; + auto size = fileUtils.listFiles(fileList); + for (int i = 0; i < size && i < 10; i++) { + if (fileList[i] == filename) { + Serial.print("file found: "); + Serial.println(fileList[i]); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/arduino_secrets.h new file mode 100644 index 00000000..1b1f9935 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/arduino_secrets.h @@ -0,0 +1,305 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + + +// Replace with your client.crt certificate in DER format +const uint8_t SECRET_CERT[] = { + /*0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0x02, 0x09, 0x00, 0xc2, + 0x68, 0x43, 0x0c, 0x54, 0xae, 0xfe, 0x3a, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x62, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x54, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x05, + 0x49, 0x74, 0x61, 0x6c, 0x79, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, + 0x04, 0x07, 0x0c, 0x05, 0x54, 0x75, 0x72, 0x69, 0x6e, 0x31, 0x10, 0x30, + 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x41, 0x72, 0x64, 0x75, + 0x69, 0x6e, 0x6f, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b, + 0x0c, 0x03, 0x4d, 0x6e, 0x78, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, + 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x69, 0x75, 0x6d, + 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x36, 0x31, 0x36, + 0x31, 0x35, 0x32, 0x39, 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, + 0x36, 0x31, 0x36, 0x31, 0x35, 0x32, 0x39, 0x30, 0x31, 0x5a, 0x30, 0x63, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x54, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x08, + 0x50, 0x69, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x74, 0x31, 0x0e, 0x30, 0x0c, + 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x05, 0x54, 0x75, 0x72, 0x69, 0x6e, + 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x03, 0x4d, + 0x6e, 0x78, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, + 0x07, 0x41, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x31, 0x11, 0x30, 0x0f, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x08, 0x4d, 0x4b, 0x52, 0x47, 0x53, + 0x4d, 0x30, 0x31, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xb6, 0xb7, 0xa2, 0x73, 0x9e, 0x8b, 0xcc, 0x7f, 0x55, 0xb3, 0xb4, 0xad, + 0xfe, 0x6a, 0xbc, 0xa7, 0xe5, 0xec, 0x02, 0xd0, 0x4b, 0x25, 0xa4, 0xd3, + 0xc4, 0x33, 0x37, 0xa7, 0x76, 0xdf, 0xa3, 0x9f, 0xdd, 0x42, 0x3e, 0xb5, + 0xe2, 0xbc, 0x89, 0xe4, 0x18, 0x02, 0xb6, 0x62, 0xe4, 0x3b, 0xa6, 0x74, + 0x76, 0xf8, 0x73, 0xe7, 0x80, 0xea, 0x5d, 0x93, 0x9d, 0x61, 0x2a, 0x24, + 0x06, 0x4c, 0x6b, 0x68, 0xea, 0x63, 0x1d, 0x3a, 0xce, 0x8b, 0x31, 0x05, + 0x72, 0xe9, 0xdc, 0xce, 0x05, 0x8c, 0x7a, 0xc1, 0xf5, 0xd6, 0xe1, 0xd0, + 0x6d, 0x73, 0x4e, 0xc1, 0x8a, 0x16, 0x49, 0x4d, 0xac, 0x21, 0xfb, 0x2d, + 0x12, 0xdd, 0x1e, 0xef, 0x9b, 0xb3, 0x6d, 0x20, 0x69, 0xfb, 0xaa, 0x3c, + 0x2c, 0x8f, 0x0d, 0x7c, 0x09, 0x1c, 0x1a, 0xa5, 0x23, 0x83, 0x98, 0x10, + 0xf4, 0x0c, 0x78, 0xa4, 0xa0, 0x4b, 0x1a, 0x71, 0x52, 0x4b, 0xb3, 0x8b, + 0x4c, 0x29, 0xfe, 0x6f, 0x24, 0x88, 0x7e, 0xd6, 0xf0, 0x6a, 0x2c, 0x3c, + 0x6c, 0xad, 0x54, 0x0c, 0xb6, 0x7b, 0xa4, 0x76, 0x38, 0xbf, 0x35, 0xc6, + 0x66, 0xde, 0x6a, 0x92, 0x43, 0x26, 0x31, 0xae, 0x76, 0xb5, 0xf6, 0x15, + 0x87, 0x02, 0x37, 0x7e, 0x7b, 0x92, 0xda, 0x3f, 0x45, 0x1e, 0x89, 0xb7, + 0x26, 0xb3, 0x8d, 0x3c, 0xf6, 0x49, 0x25, 0xe9, 0x1e, 0x52, 0x6f, 0x40, + 0x2e, 0xb6, 0x7d, 0x5c, 0x2a, 0x8a, 0x9c, 0x7d, 0x2c, 0x09, 0xce, 0xde, + 0x73, 0x5d, 0x3b, 0x7d, 0x4f, 0x3f, 0x4b, 0xdc, 0xeb, 0x8b, 0x93, 0xd1, + 0xc2, 0xf3, 0x29, 0x08, 0x98, 0x06, 0x8c, 0x46, 0x38, 0xe1, 0xd5, 0x30, + 0xc1, 0xf0, 0x3c, 0x74, 0x58, 0xf0, 0x20, 0x8b, 0xea, 0x30, 0x43, 0xd8, + 0x3d, 0x19, 0xc4, 0xd1, 0x04, 0xc8, 0xe5, 0x76, 0x31, 0x36, 0x4a, 0xae, + .. .. .. .. .. .. .. .. .. .. .. .. + 0xd3, 0xb2, 0x75, 0x2b, 0x85, 0x71, 0x02, 0x9a, 0x51, 0x38, 0x08, 0x61, + 0xf8, 0x8b, 0x8b, 0x36, 0xf5, 0x10, 0x6e, 0xd9, 0xda, 0xf5, 0x3a, 0xf1, + 0xf1, 0x6f, 0xc4, 0xd7, 0x52, 0x6f, 0x22, 0x38, 0x8a, 0xff, 0x75, 0x82, + 0x93, 0x94, 0xc9, 0x45, 0xcf, 0xa3, 0x23, 0x04, 0x6f, 0x3a, 0x58, 0xe1, + 0xca, 0xfa, 0xa8, 0x1f, 0xd3, 0x87, 0x6e, 0xcb, 0xe3*/ +}; + +// Replace with your client.key certificate in DER format +uint8_t SECRET_KEY[] = { + /*0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xb6, 0xb7, 0xa2, 0x73, 0x9e, 0x8b, 0xcc, 0x7f, 0x55, 0xb3, 0xb4, 0xad, + 0xfe, 0x6a, 0xbc, 0xa7, 0xe5, 0xec, 0x02, 0xd0, 0x4b, 0x25, 0xa4, 0xd3, + 0xc4, 0x33, 0x37, 0xa7, 0x76, 0xdf, 0xa3, 0x9f, 0xdd, 0x42, 0x3e, 0xb5, + 0xe2, 0xbc, 0x89, 0xe4, 0x18, 0x02, 0xb6, 0x62, 0xe4, 0x3b, 0xa6, 0x74, + 0x76, 0xf8, 0x73, 0xe7, 0x80, 0xea, 0x5d, 0x93, 0x9d, 0x61, 0x2a, 0x24, + 0x06, 0x4c, 0x6b, 0x68, 0xea, 0x63, 0x1d, 0x3a, 0xce, 0x8b, 0x31, 0x05, + 0x72, 0xe9, 0xdc, 0xce, 0x05, 0x8c, 0x7a, 0xc1, 0xf5, 0xd6, 0xe1, 0xd0, + 0x6d, 0x73, 0x4e, 0xc1, 0x8a, 0x16, 0x49, 0x4d, 0xac, 0x21, 0xfb, 0x2d, + 0x12, 0xdd, 0x1e, 0xef, 0x9b, 0xb3, 0x6d, 0x20, 0x69, 0xfb, 0xaa, 0x3c, + 0x2c, 0x8f, 0x0d, 0x7c, 0x09, 0x1c, 0x1a, 0xa5, 0x23, 0x83, 0x98, 0x10, + 0xf4, 0x0c, 0x78, 0xa4, 0xa0, 0x4b, 0x1a, 0x71, 0x52, 0x4b, 0xb3, 0x8b, + 0x4c, 0x29, 0xfe, 0x6f, 0x24, 0x88, 0x7e, 0xd6, 0xf0, 0x6a, 0x2c, 0x3c, + 0x6c, 0xad, 0x54, 0x0c, 0xb6, 0x7b, 0xa4, 0x76, 0x38, 0xbf, 0x35, 0xc6, + 0x66, 0xde, 0x6a, 0x92, 0x43, 0x26, 0x31, 0xae, 0x76, 0xb5, 0xf6, 0x15, + 0x87, 0x02, 0x37, 0x7e, 0x7b, 0x92, 0xda, 0x3f, 0x45, 0x1e, 0x89, 0xb7, + 0x26, 0xb3, 0x8d, 0x3c, 0xf6, 0x49, 0x25, 0xe9, 0x1e, 0x52, 0x6f, 0x40, + 0x2e, 0xb6, 0x7d, 0x5c, 0x2a, 0x8a, 0x9c, 0x7d, 0x2c, 0x09, 0xce, 0xde, + 0x73, 0x5d, 0x3b, 0x7d, 0x4f, 0x3f, 0x4b, 0xdc, 0xeb, 0x8b, 0x93, 0xd1, + 0xc2, 0xf3, 0x29, 0x08, 0x98, 0x06, 0x8c, 0x46, 0x38, 0xe1, 0xd5, 0x30, + 0xc1, 0xf0, 0x3c, 0x74, 0x58, 0xf0, 0x20, 0x8b, 0xea, 0x30, 0x43, 0xd8, + 0x3d, 0x19, 0xc4, 0xd1, 0x04, 0xc8, 0xe5, 0x76, 0x31, 0x36, 0x4a, 0xae, + 0xf4, 0x21, 0x41, 0x0b, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, + 0x00, 0x7b, 0xe7, 0x87, 0x58, 0x54, 0x59, 0x84, 0xf1, 0x8c, 0x92, 0x72, + 0xa1, 0xd2, 0xf7, 0x5a, 0xbb, 0x98, 0xa5, 0x35, 0x3b, 0x3e, 0xda, 0x66, + 0x2d, 0xdc, 0xcc, 0xc6, 0x9e, 0xdf, 0x73, 0xc4, 0xa7, 0xb2, 0x09, 0x2c, + 0x31, 0x77, 0x72, 0x57, 0x27, 0xc0, 0x48, 0x86, 0x9a, 0x05, 0x1f, 0x96, + 0x3f, 0x40, 0x36, 0x37, 0x92, 0xf3, 0xce, 0xfa, 0x6a, 0x11, 0xbd, 0x44, + 0x30, 0x6d, 0xbd, 0x00, 0xd1, 0x82, 0xb0, 0x77, 0xaf, 0xdb, 0x44, 0x74, + 0x97, 0xb7, 0x57, 0x73, 0x8e, 0x9a, 0x20, 0xab, 0x56, 0x40, 0x79, 0xd9, + 0x63, 0xd7, 0xf4, 0xeb, 0xa1, 0x3f, 0x1c, 0xe1, 0xd4, 0xb4, 0x37, 0xce, + 0xf6, 0xbf, 0xe6, 0x07, 0x06, 0x81, 0x55, 0x69, 0x59, 0x23, 0xc5, 0xaf, + 0xa9, 0x62, 0xa6, 0x17, 0x84, 0xd7, 0x40, 0xa1, 0xa8, 0xfe, 0xae, 0x4c, + 0x3e, 0xa2, 0xe0, 0x9a, 0x27, 0x39, 0x33, 0xf4, 0xd7, 0x62, 0x94, 0xac, + 0x58, 0xb8, 0x45, 0x03, 0xdf, 0x19, 0x21, 0x5b, 0xf8, 0x0c, 0xfb, 0x44, + 0x7e, 0xc7, 0x94, 0x15, 0xc1, 0xb5, 0x34, 0xfe, 0x1a, 0x35, 0xf7, 0x73, + 0x7a, 0xf4, 0x5f, 0x15, 0xaf, 0x6e, 0x93, 0x46, 0xbc, 0xae, 0x16, 0x32, + 0xed, 0x37, 0x73, 0x69, 0x17, 0xd7, 0xcc, 0x41, 0x6a, 0x25, 0x17, 0xa6, + 0x35, 0x58, 0x46, 0xb6, 0x2f, 0x13, 0x64, 0x1b, 0x04, 0x02, 0xdc, 0x5d, + 0x06, 0xe6, 0xf3, 0xb8, 0xf5, 0x93, 0xee, 0x39, 0xff, 0x0a, 0xa3, 0x33, + 0x9b, 0x30, 0x63, 0x5e, 0xf8, 0xfd, 0xd6, 0x45, 0x56, 0xe8, 0xdf, 0x64, + 0x62, 0x23, 0xa0, 0xf1, 0x1e, 0x6a, 0x4c, 0xc0, 0xc1, 0x95, 0x47, 0x05, + 0xb7, 0x5a, 0xb3, 0xda, 0xa5, 0x91, 0x81, 0x49, 0xef, 0x1d, 0x36, 0x14, + 0x55, 0x0f, 0x00, 0x9e, 0x28, 0x1b, 0x15, 0x77, 0x6c, 0x24, 0xd0, 0xe8, + 0x3f, 0x79, 0x37, 0x6a, 0xd1, 0x02, 0x81, 0x81, 0x00, 0xdb, 0x95, 0x25, + 0xee, 0x4f, 0x77, 0x20, 0xcf, 0xf8, 0xc4, 0x3a, 0xa5, 0xcf, 0x15, 0x28, + 0x4f, 0xdf, 0x16, 0xbb, 0xfc, 0x10, 0xaa, 0xa5, 0x7f, 0x0d, 0xea, 0x93, + 0xe2, 0xaf, 0x91, 0x9c, 0x77, 0xcc, 0x51, 0x8e, 0xb0, 0x79, 0xc8, 0xba, + 0xe4, 0x75, 0xcb, 0x07, 0x47, 0x04, 0xab, 0xb5, 0xd0, 0x75, 0x6f, 0x61, + 0xa4, 0x98, 0x2d, 0x15, 0xa9, 0x8a, 0xa2, 0x44, 0xde, 0x4c, 0xd7, 0x7f, + 0x01, 0xb7, 0xb4, 0x71, 0x21, 0x6e, 0xff, 0x0b, 0x15, 0x46, 0x81, 0xd8, + 0x53, 0x11, 0x1d, 0x7c, 0x8f, 0x48, 0x6a, 0xd0, 0x1c, 0xe8, 0xe0, 0x7d, + 0xed, 0x44, 0x17, 0x30, 0xcb, 0xed, 0xfc, 0x65, 0x92, 0x21, 0x62, 0x75, + 0x1f, 0x5c, 0x6a, 0x32, 0x4f, 0xc9, 0xb8, 0x98, 0x11, 0xc7, 0x54, 0x18, + .. .. .. .. .. .. .. .. .. .. .. .. + 0x3b, 0x25, 0x36, 0xc2, 0xcd, 0x02, 0x81, 0x81, 0x00, 0xd5, 0x05, 0x4a, + 0x96, 0xf5, 0x50, 0xc4, 0x46, 0x95*/ +}; + + +static const GSMRootCert SECRET_GSM_ROOT_CERTS[] = { + { "DST_Root_CA_X3", + (const uint8_t[]){ + 0x30, 0x82, 0x03, 0x4a, 0x30, 0x82, 0x02, 0x32, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x44, 0xaf, 0xb0, 0x80, 0xd6, 0xa3, 0x27, 0xba, 0x89, + 0x30, 0x39, 0x86, 0x2e, 0xf8, 0x40, 0x6b, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3f, + 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43, + 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, + 0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x30, 0x30, 0x39, 0x33, + 0x30, 0x32, 0x31, 0x31, 0x32, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x31, + 0x30, 0x39, 0x33, 0x30, 0x31, 0x34, 0x30, 0x31, 0x31, 0x35, 0x5a, 0x30, + 0x3f, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, + 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, + 0x43, 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x13, 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, + 0x41, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, + 0x00, 0xdf, 0xaf, 0xe9, 0x97, 0x50, 0x08, 0x83, 0x57, 0xb4, 0xcc, 0x62, + 0x65, 0xf6, 0x90, 0x82, 0xec, 0xc7, 0xd3, 0x2c, 0x6b, 0x30, 0xca, 0x5b, + 0xec, 0xd9, 0xc3, 0x7d, 0xc7, 0x40, 0xc1, 0x18, 0x14, 0x8b, 0xe0, 0xe8, + 0x33, 0x76, 0x49, 0x2a, 0xe3, 0x3f, 0x21, 0x49, 0x93, 0xac, 0x4e, 0x0e, + 0xaf, 0x3e, 0x48, 0xcb, 0x65, 0xee, 0xfc, 0xd3, 0x21, 0x0f, 0x65, 0xd2, + 0x2a, 0xd9, 0x32, 0x8f, 0x8c, 0xe5, 0xf7, 0x77, 0xb0, 0x12, 0x7b, 0xb5, + 0x95, 0xc0, 0x89, 0xa3, 0xa9, 0xba, 0xed, 0x73, 0x2e, 0x7a, 0x0c, 0x06, + 0x32, 0x83, 0xa2, 0x7e, 0x8a, 0x14, 0x30, 0xcd, 0x11, 0xa0, 0xe1, 0x2a, + 0x38, 0xb9, 0x79, 0x0a, 0x31, 0xfd, 0x50, 0xbd, 0x80, 0x65, 0xdf, 0xb7, + 0x51, 0x63, 0x83, 0xc8, 0xe2, 0x88, 0x61, 0xea, 0x4b, 0x61, 0x81, 0xec, + 0x52, 0x6b, 0xb9, 0xa2, 0xe2, 0x4b, 0x1a, 0x28, 0x9f, 0x48, 0xa3, 0x9e, + 0x0c, 0xda, 0x09, 0x8e, 0x3e, 0x17, 0x2e, 0x1e, 0xdd, 0x20, 0xdf, 0x5b, + 0xc6, 0x2a, 0x8a, 0xab, 0x2e, 0xbd, 0x70, 0xad, 0xc5, 0x0b, 0x1a, 0x25, + 0x90, 0x74, 0x72, 0xc5, 0x7b, 0x6a, 0xab, 0x34, 0xd6, 0x30, 0x89, 0xff, + 0xe5, 0x68, 0x13, 0x7b, 0x54, 0x0b, 0xc8, 0xd6, 0xae, 0xec, 0x5a, 0x9c, + 0x92, 0x1e, 0x3d, 0x64, 0xb3, 0x8c, 0xc6, 0xdf, 0xbf, 0xc9, 0x41, 0x70, + 0xec, 0x16, 0x72, 0xd5, 0x26, 0xec, 0x38, 0x55, 0x39, 0x43, 0xd0, 0xfc, + 0xfd, 0x18, 0x5c, 0x40, 0xf1, 0x97, 0xeb, 0xd5, 0x9a, 0x9b, 0x8d, 0x1d, + 0xba, 0xda, 0x25, 0xb9, 0xc6, 0xd8, 0xdf, 0xc1, 0x15, 0x02, 0x3a, 0xab, + 0xda, 0x6e, 0xf1, 0x3e, 0x2e, 0xf5, 0x5c, 0x08, 0x9c, 0x3c, 0xd6, 0x83, + 0x69, 0xe4, 0x10, 0x9b, 0x19, 0x2a, 0xb6, 0x29, 0x57, 0xe3, 0xe5, 0x3d, + 0x9b, 0x9f, 0xf0, 0x02, 0x5d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42, + 0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, + 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, + 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, + 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc4, 0xa7, + 0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, 0xe1, 0x4b, 0x90, 0x75, 0xff, + 0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, + 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, + 0x01, 0x00, 0xa3, 0x1a, 0x2c, 0x9b, 0x17, 0x00, 0x5c, 0xa9, 0x1e, 0xee, + 0x28, 0x66, 0x37, 0x3a, 0xbf, 0x83, 0xc7, 0x3f, 0x4b, 0xc3, 0x09, 0xa0, + 0x95, 0x20, 0x5d, 0xe3, 0xd9, 0x59, 0x44, 0xd2, 0x3e, 0x0d, 0x3e, 0xbd, + 0x8a, 0x4b, 0xa0, 0x74, 0x1f, 0xce, 0x10, 0x82, 0x9c, 0x74, 0x1a, 0x1d, + 0x7e, 0x98, 0x1a, 0xdd, 0xcb, 0x13, 0x4b, 0xb3, 0x20, 0x44, 0xe4, 0x91, + 0xe9, 0xcc, 0xfc, 0x7d, 0xa5, 0xdb, 0x6a, 0xe5, 0xfe, 0xe6, 0xfd, 0xe0, + 0x4e, 0xdd, 0xb7, 0x00, 0x3a, 0xb5, 0x70, 0x49, 0xaf, 0xf2, 0xe5, 0xeb, + 0x02, 0xf1, 0xd1, 0x02, 0x8b, 0x19, 0xcb, 0x94, 0x3a, 0x5e, 0x48, 0xc4, + 0x18, 0x1e, 0x58, 0x19, 0x5f, 0x1e, 0x02, 0x5a, 0xf0, 0x0c, 0xf1, 0xb1, + 0xad, 0xa9, 0xdc, 0x59, 0x86, 0x8b, 0x6e, 0xe9, 0x91, 0xf5, 0x86, 0xca, + 0xfa, 0xb9, 0x66, 0x33, 0xaa, 0x59, 0x5b, 0xce, 0xe2, 0xa7, 0x16, 0x73, + 0x47, 0xcb, 0x2b, 0xcc, 0x99, 0xb0, 0x37, 0x48, 0xcf, 0xe3, 0x56, 0x4b, + 0xf5, 0xcf, 0x0f, 0x0c, 0x72, 0x32, 0x87, 0xc6, 0xf0, 0x44, 0xbb, 0x53, + 0x72, 0x6d, 0x43, 0xf5, 0x26, 0x48, 0x9a, 0x52, 0x67, 0xb7, 0x58, 0xab, + 0xfe, 0x67, 0x76, 0x71, 0x78, 0xdb, 0x0d, 0xa2, 0x56, 0x14, 0x13, 0x39, + 0x24, 0x31, 0x85, 0xa2, 0xa8, 0x02, 0x5a, 0x30, 0x47, 0xe1, 0xdd, 0x50, + 0x07, 0xbc, 0x02, 0x09, 0x90, 0x00, 0xeb, 0x64, 0x63, 0x60, 0x9b, 0x16, + 0xbc, 0x88, 0xc9, 0x12, 0xe6, 0xd2, 0x7d, 0x91, 0x8b, 0xf9, 0x3d, 0x32, + 0x8d, 0x65, 0xb4, 0xe9, 0x7c, 0xb1, 0x57, 0x76, 0xea, 0xc5, 0xb6, 0x28, + 0x39, 0xbf, 0x15, 0x65, 0x1c, 0xc8, 0xf6, 0x77, 0x96, 0x6a, 0x0a, 0x8d, + 0x77, 0x0b, 0xd8, 0x91, 0x0b, 0x04, 0x8e, 0x07, 0xdb, 0x29, 0xb6, 0x0a, + 0xee, 0x9d, 0x82, 0x35, 0x35, 0x10 }, + 846 }, + { "Let_s_Encrypt_Authority_X3", + (const uint8_t[]){ + 0x30, 0x82, 0x04, 0x92, 0x30, 0x82, 0x03, 0x7a, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x0a, 0x01, 0x41, 0x42, 0x00, 0x00, 0x01, 0x53, 0x85, + 0x73, 0x6a, 0x0b, 0x85, 0xec, 0xa7, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3f, + 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43, + 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, + 0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x33, 0x31, + 0x37, 0x31, 0x36, 0x34, 0x30, 0x34, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x31, + 0x30, 0x33, 0x31, 0x37, 0x31, 0x36, 0x34, 0x30, 0x34, 0x36, 0x5a, 0x30, + 0x4a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + 0x55, 0x53, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, + 0x0d, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x31, 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x1a, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, + 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, + 0x9c, 0xd3, 0x0c, 0xf0, 0x5a, 0xe5, 0x2e, 0x47, 0xb7, 0x72, 0x5d, 0x37, + 0x83, 0xb3, 0x68, 0x63, 0x30, 0xea, 0xd7, 0x35, 0x26, 0x19, 0x25, 0xe1, + 0xbd, 0xbe, 0x35, 0xf1, 0x70, 0x92, 0x2f, 0xb7, 0xb8, 0x4b, 0x41, 0x05, + 0xab, 0xa9, 0x9e, 0x35, 0x08, 0x58, 0xec, 0xb1, 0x2a, 0xc4, 0x68, 0x87, + 0x0b, 0xa3, 0xe3, 0x75, 0xe4, 0xe6, 0xf3, 0xa7, 0x62, 0x71, 0xba, 0x79, + 0x81, 0x60, 0x1f, 0xd7, 0x91, 0x9a, 0x9f, 0xf3, 0xd0, 0x78, 0x67, 0x71, + 0xc8, 0x69, 0x0e, 0x95, 0x91, 0xcf, 0xfe, 0xe6, 0x99, 0xe9, 0x60, 0x3c, + 0x48, 0xcc, 0x7e, 0xca, 0x4d, 0x77, 0x12, 0x24, 0x9d, 0x47, 0x1b, 0x5a, + 0xeb, 0xb9, 0xec, 0x1e, 0x37, 0x00, 0x1c, 0x9c, 0xac, 0x7b, 0xa7, 0x05, + 0xea, 0xce, 0x4a, 0xeb, 0xbd, 0x41, 0xe5, 0x36, 0x98, 0xb9, 0xcb, 0xfd, + 0x6d, 0x3c, 0x96, 0x68, 0xdf, 0x23, 0x2a, 0x42, 0x90, 0x0c, 0x86, 0x74, + 0x67, 0xc8, 0x7f, 0xa5, 0x9a, 0xb8, 0x52, 0x61, 0x14, 0x13, 0x3f, 0x65, + 0xe9, 0x82, 0x87, 0xcb, 0xdb, 0xfa, 0x0e, 0x56, 0xf6, 0x86, 0x89, 0xf3, + 0x85, 0x3f, 0x97, 0x86, 0xaf, 0xb0, 0xdc, 0x1a, 0xef, 0x6b, 0x0d, 0x95, + 0x16, 0x7d, 0xc4, 0x2b, 0xa0, 0x65, 0xb2, 0x99, 0x04, 0x36, 0x75, 0x80, + 0x6b, 0xac, 0x4a, 0xf3, 0x1b, 0x90, 0x49, 0x78, 0x2f, 0xa2, 0x96, 0x4f, + 0x2a, 0x20, 0x25, 0x29, 0x04, 0xc6, 0x74, 0xc0, 0xd0, 0x31, 0xcd, 0x8f, + 0x31, 0x38, 0x95, 0x16, 0xba, 0xa8, 0x33, 0xb8, 0x43, 0xf1, 0xb1, 0x1f, + 0xc3, 0x30, 0x7f, 0xa2, 0x79, 0x31, 0x13, 0x3d, 0x2d, 0x36, 0xf8, 0xe3, + 0xfc, 0xf2, 0x33, 0x6a, 0xb9, 0x39, 0x31, 0xc5, 0xaf, 0xc4, 0x8d, 0x0d, + 0x1d, 0x64, 0x16, 0x33, 0xaa, 0xfa, 0x84, 0x29, 0xb6, 0xd4, 0x0b, 0xc0, + 0xd8, 0x7d, 0xc3, 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, + 0x7d, 0x30, 0x82, 0x01, 0x79, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, + 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, + 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, + 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x7f, 0x06, 0x08, 0x2b, 0x06, 0x01, + 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x73, 0x30, 0x71, 0x30, 0x32, 0x06, + 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x26, 0x68, + 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x69, 0x73, 0x72, 0x67, 0x2e, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x69, 0x64, 0x2e, 0x6f, 0x63, 0x73, 0x70, 0x2e, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, 0x2e, 0x63, 0x6f, + 0x6d, 0x30, 0x3b, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, + 0x02, 0x86, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x61, 0x70, + 0x70, 0x73, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x6f, 0x6f, 0x74, 0x73, 0x2f, 0x64, + 0x73, 0x74, 0x72, 0x6f, 0x6f, 0x74, 0x63, 0x61, 0x78, 0x33, 0x2e, 0x70, + 0x37, 0x63, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, + 0x16, 0x80, 0x14, 0xc4, 0xa7, 0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, + 0xe1, 0x4b, 0x90, 0x75, 0xff, 0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, + 0x54, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x4d, 0x30, 0x4b, 0x30, 0x08, + 0x06, 0x06, 0x67, 0x81, 0x0c, 0x01, 0x02, 0x01, 0x30, 0x3f, 0x06, 0x0b, + 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xdf, 0x13, 0x01, 0x01, 0x01, 0x30, + 0x30, 0x30, 0x2e, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, + 0x01, 0x16, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x70, + 0x73, 0x2e, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x78, 0x31, 0x2e, 0x6c, 0x65, + 0x74, 0x73, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2e, 0x6f, 0x72, + 0x67, 0x30, 0x3c, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x35, 0x30, 0x33, + 0x30, 0x31, 0xa0, 0x2f, 0xa0, 0x2d, 0x86, 0x2b, 0x68, 0x74, 0x74, 0x70, + 0x3a, 0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x44, 0x53, 0x54, + 0x52, 0x4f, 0x4f, 0x54, 0x43, 0x41, 0x58, 0x33, 0x43, 0x52, 0x4c, 0x2e, + 0x63, 0x72, 0x6c, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, + 0x04, 0x14, 0xa8, 0x4a, 0x6a, 0x63, 0x04, 0x7d, 0xdd, 0xba, 0xe6, 0xd1, + 0x39, 0xb7, 0xa6, 0x45, 0x65, 0xef, 0xf3, 0xa8, 0xec, 0xa1, 0x30, 0x0d, + 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, + 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0xdd, 0x33, 0xd7, 0x11, 0xf3, 0x63, + 0x58, 0x38, 0xdd, 0x18, 0x15, 0xfb, 0x09, 0x55, 0xbe, 0x76, 0x56, 0xb9, + 0x70, 0x48, 0xa5, 0x69, 0x47, 0x27, 0x7b, 0xc2, 0x24, 0x08, 0x92, 0xf1, + 0x5a, 0x1f, 0x4a, 0x12, 0x29, 0x37, 0x24, 0x74, 0x51, 0x1c, 0x62, 0x68, + 0xb8, 0xcd, 0x95, 0x70, 0x67, 0xe5, 0xf7, 0xa4, 0xbc, 0x4e, 0x28, 0x51, + 0xcd, 0x9b, 0xe8, 0xae, 0x87, 0x9d, 0xea, 0xd8, 0xba, 0x5a, 0xa1, 0x01, + 0x9a, 0xdc, 0xf0, 0xdd, 0x6a, 0x1d, 0x6a, 0xd8, 0x3e, 0x57, 0x23, 0x9e, + 0xa6, 0x1e, 0x04, 0x62, 0x9a, 0xff, 0xd7, 0x05, 0xca, 0xb7, 0x1f, 0x3f, + 0xc0, 0x0a, 0x48, 0xbc, 0x94, 0xb0, 0xb6, 0x65, 0x62, 0xe0, 0xc1, 0x54, + 0xe5, 0xa3, 0x2a, 0xad, 0x20, 0xc4, 0xe9, 0xe6, 0xbb, 0xdc, 0xc8, 0xf6, + 0xb5, 0xc3, 0x32, 0xa3, 0x98, 0xcc, 0x77, 0xa8, 0xe6, 0x79, 0x65, 0x07, + 0x2b, 0xcb, 0x28, 0xfe, 0x3a, 0x16, 0x52, 0x81, 0xce, 0x52, 0x0c, 0x2e, + 0x5f, 0x83, 0xe8, 0xd5, 0x06, 0x33, 0xfb, 0x77, 0x6c, 0xce, 0x40, 0xea, + 0x32, 0x9e, 0x1f, 0x92, 0x5c, 0x41, 0xc1, 0x74, 0x6c, 0x5b, 0x5d, 0x0a, + 0x5f, 0x33, 0xcc, 0x4d, 0x9f, 0xac, 0x38, 0xf0, 0x2f, 0x7b, 0x2c, 0x62, + 0x9d, 0xd9, 0xa3, 0x91, 0x6f, 0x25, 0x1b, 0x2f, 0x90, 0xb1, 0x19, 0x46, + 0x3d, 0xf6, 0x7e, 0x1b, 0xa6, 0x7a, 0x87, 0xb9, 0xa3, 0x7a, 0x6d, 0x18, + 0xfa, 0x25, 0xa5, 0x91, 0x87, 0x15, 0xe0, 0xf2, 0x16, 0x2f, 0x58, 0xb0, + 0x06, 0x2f, 0x2c, 0x68, 0x26, 0xc6, 0x4b, 0x98, 0xcd, 0xda, 0x9f, 0x0c, + 0xf9, 0x7f, 0x90, 0xed, 0x43, 0x4a, 0x12, 0x44, 0x4e, 0x6f, 0x73, 0x7a, + 0x28, 0xea, 0xa4, 0xaa, 0x6e, 0x7b, 0x4c, 0x7d, 0x87, 0xdd, 0xe0, 0xc9, + 0x02, 0x44, 0xa7, 0x87, 0xaf, 0xc3, 0x34, 0x5b, 0xb4, 0x42 }, + 1174 } +}; + + +#define SECRET_GSM_ROOT_SIZE (sizeof(SECRET_GSM_ROOT_CERTS) / sizeof(SECRET_GSM_ROOT_CERTS[0])) diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/PinManagement/PinManagement.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/PinManagement/PinManagement.ino new file mode 100644 index 00000000..2581e06a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/PinManagement/PinManagement.ino @@ -0,0 +1,144 @@ +/* + + This example enables you to change or remove the PIN number of + a SIM card inserted into a GSM shield. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card + + Created 12 Jun 2012 + by David del Peral +*/ + +// libraries +#include + +// pin manager object +GSMPIN PINManager; + +// save input in serial by user +String user_input = ""; + +// authenticated with PIN code +bool auth = false; + +// Serial Monitor result messages +String oktext = "OK"; +String errortext = "ERROR"; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Change PIN example\n"); + PINManager.begin(); + + // check if the SIM has pin lock + while (!auth) { + int pin_query = PINManager.isPIN(); + if (pin_query == 1) { + // if SIM is locked, enter PIN code + Serial.print("Enter PIN code: "); + user_input = readSerial(); + // check PIN code + if (PINManager.checkPIN(user_input) == 0) { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } else { + // if PIN code was incorrect + Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); + } + } else if (pin_query == -1) { + // PIN code is locked, user must enter PUK code + Serial.println("PIN locked. Enter PUK code: "); + String puk = readSerial(); + Serial.print("Now, enter a new PIN code: "); + user_input = readSerial(); + // check PUK code + if (PINManager.checkPUK(puk, user_input) == 0) { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } else { + // if PUK or the new PIN are incorrect + Serial.println("Incorrect PUK or invalid new PIN. Try again!."); + } + } else if (pin_query == -2) { + // the worst case, PIN and PUK are locked + Serial.println("PIN and PUK locked. Use PIN2/PUK2 in a mobile phone."); + while (true) + ; + } else { + // SIM does not require authentication + Serial.println("No pin necessary."); + auth = true; + } + } + + // start GSM shield + Serial.print("Checking register in GSM network..."); + if (PINManager.checkReg() == 0) { + Serial.println(oktext); + } + // if you are connected by roaming + else if (PINManager.checkReg() == 1) { + Serial.println("ROAMING " + oktext); + } else { + // error connection + Serial.println(errortext); + while (true) + ; + } +} + +void loop() { + // Function loop implements pin management user menu + // Only if your SIM uses pin lock can you change the PIN code + // user_op variables save user option + + Serial.println("Choose an option:\n1 - On/Off PIN."); + if (PINManager.getPINUsed()) { + Serial.println("2 - Change PIN."); + } + String user_op = readSerial(); + if (user_op == "1") { + Serial.println("Enter your PIN code:"); + user_input = readSerial(); + // activate/deactivate PIN lock + PINManager.switchPIN(user_input); + } else if (user_op == "2" && PINManager.getPINUsed()) { + Serial.println("Enter your actual PIN code:"); + String oldPIN = readSerial(); + Serial.println("Now, enter your new PIN code:"); + String newPIN = readSerial(); + // change PIN + PINManager.changePIN(oldPIN, newPIN); + } else { + Serial.println("Incorrect option. Try again!."); + } + delay(1000); +} + +/* + Read input serial + */ +String readSerial() { + String text = ""; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + return text; + } + if (inChar != '\r') { + text += inChar; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/SerialGSMPassthrough/SerialGSMPassthrough.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/SerialGSMPassthrough/SerialGSMPassthrough.ino new file mode 100644 index 00000000..203967b3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/SerialGSMPassthrough/SerialGSMPassthrough.ino @@ -0,0 +1,44 @@ +/* + SerialGSMPassthrough sketch + + This sketch allows you to send AT commands from the USB CDC serial port + of the MKR GSM 1400 board to the onboard u-blox SARA-U201 celluar module. + + For a list of supported AT commands see: + https://www.u-blox.com/sites/default/files/u-blox-CEL_ATCommands_%28UBX-13002752%29.pdf + + Circuit: + - MKR GSM 1400 board + - Antenna + - 1500 mAh or higher LiPo battery connected + - SIM card + + Make sure the Serial Monitor's line ending is set to "Both NL and CR" + + create 11 December 2017 + Sandeep Mistry +*/ + +// baud rate used for both Serial ports +unsigned long baud = 115200; + +void setup() { + // reset the u-blox module + pinMode(GSM_RESETN, OUTPUT); + digitalWrite(GSM_RESETN, HIGH); + delay(100); + digitalWrite(GSM_RESETN, LOW); + + Serial.begin(baud); + SerialGSM.begin(baud); +} + +void loop() { + if (Serial.available()) { + SerialGSM.write(Serial.read()); + } + + if (SerialGSM.available()) { + Serial.write(SerialGSM.read()); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/TestGPRS.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/TestGPRS.ino new file mode 100644 index 00000000..f0ea7e88 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/TestGPRS.ino @@ -0,0 +1,189 @@ +/* + + This sketch tests the MKR GSM 1400 board's ability to connect to a + GPRS network. It asks for APN information through the + Serial Monitor and tries to connect to example.org. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with data plan + + Created 18 Jun 2012 + by David del Peral +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; // GSM access: include a 'true' parameter for debug enabled +GPRS gprsAccess; // GPRS access +GSMClient client; // Client service for TCP connection + +// messages for Serial Monitor response +String oktext = "OK"; +String errortext = "ERROR"; + +// URL and path (for example: example.org) +char url[] = "example.org"; +char urlproxy[] = "http://www.example.org"; +char path[] = "/"; + +// variable for save response obtained +String response = ""; + +// use a proxy +bool use_proxy = false; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } +} + +void loop() { + use_proxy = false; + + // start GSM shield + // if your SIM has PIN, pass it as a parameter of begin() in quotes + Serial.print("Connecting GSM network..."); + if (gsmAccess.begin(PINNUMBER) != GSM_READY) { + Serial.println(errortext); + while (true) + ; + } + Serial.println(oktext); + + // read APN introduced by user + char apn[50]; + Serial.print("Enter your APN: "); + readSerial(apn); + Serial.println(apn); + + // Read APN login introduced by user + char login[50]; + Serial.print("Now, enter your login: "); + readSerial(login); + Serial.println(login); + + // read APN password introduced by user + char password[20]; + Serial.print("Finally, enter your password: "); + readSerial(password); + + // attach GPRS + Serial.println("Attaching to GPRS with your APN..."); + if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY) { + Serial.println(errortext); + } else { + + Serial.println(oktext); + + // read proxy introduced by user + char proxy[100]; + Serial.print("If your carrier uses a proxy, enter it, if not press enter: "); + readSerial(proxy); + Serial.println(proxy); + + // if user introduced a proxy, asks them for proxy port + int pport; + if (proxy[0] != '\0') { + // read proxy port introduced by user + char proxyport[10]; + Serial.print("Enter the proxy port: "); + readSerial(proxyport); + // cast proxy port introduced to integer + pport = (int)proxyport; + use_proxy = true; + Serial.println(proxyport); + } + + // connection with example.org and realize HTTP request + Serial.print("Connecting and sending GET request to example.org..."); + int res_connect; + + // if using a proxy, connect with it + if (use_proxy) { + res_connect = client.connect(proxy, pport); + } else { + res_connect = client.connect(url, 80); + } + + if (res_connect) { + // make a HTTP 1.0 GET request (client sends the request) + client.print("GET "); + + // if using a proxy, the path is the example.org URL + if (use_proxy) { + client.print(urlproxy); + } else { + client.print(path); + } + + client.println(" HTTP/1.0"); + client.println(); + Serial.println(oktext); + } else { + // if you didn't get a connection to the server + Serial.println(errortext); + } + Serial.print("Receiving response..."); + + bool test = true; + while (test) { + // if there are incoming bytes available + // from the server, read and check them + if (client.available()) { + char c = client.read(); + response += c; + + // cast response obtained from string to char array + char responsechar[response.length() + 1]; + response.toCharArray(responsechar, response.length() + 1); + + // if response includes a "200 OK" substring + if (strstr(responsechar, "200 OK") != NULL) { + Serial.println(oktext); + Serial.println("TEST COMPLETE!"); + test = false; + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + test = false; + } + } + } +} + +/* + Read input serial + */ +int readSerial(char result[]) { + int i = 0; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + result[i] = '\0'; + return 0; + } + if (inChar != '\r') { + result[i] = inChar; + i++; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestModem/TestModem.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestModem/TestModem.ino new file mode 100644 index 00000000..2586eee4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestModem/TestModem.ino @@ -0,0 +1,66 @@ +/* + + This example tests to see if the modem of the + MKR GSM 1400 board is working correctly. You do not need + a SIM card for this example. + + Circuit: + * MKR GSM 1400 board + * Antenna + + Created 12 Jun 2012 + by David del Peral + modified 21 Nov 2012 + by Tom Igoe +*/ + +// libraries +#include + +// modem verification object +GSMModem modem; + +// IMEI variable +String IMEI = ""; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start modem test (reset and check response) + Serial.print("Starting modem test..."); + if (modem.begin()) { + Serial.println("modem.begin() succeeded"); + } else { + Serial.println("ERROR, no modem answer."); + } +} + +void loop() { + // get modem IMEI + Serial.print("Checking IMEI..."); + IMEI = modem.getIMEI(); + + // check IMEI response + if (IMEI != NULL) { + // show IMEI in Serial Monitor + Serial.println("Modem's IMEI: " + IMEI); + // reset modem to check booting: + Serial.print("Resetting modem..."); + modem.begin(); + // get and check IMEI one more time + if (modem.getIMEI() != NULL) { + Serial.println("Modem is functioning properly"); + } else { + Serial.println("Error: getIMEI() failed after modem.begin()"); + } + } else { + Serial.println("Error: Could not get IMEI"); + } + // do nothing: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/TestWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/TestWebServer.ino new file mode 100644 index 00000000..9a074ad3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/TestWebServer.ino @@ -0,0 +1,77 @@ +/* + Basic Web Server + + A simple web server that replies with nothing, but prints the client's request + and the server IP address. + + Circuit: + * MKR GSM 1400 board + * Antenna + + created + by David Cuartielles + modified 21 Nov 2012 + by Tom Igoe +*/ +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + + +// initialize the library instance +GPRS gprs; +GSM gsmAccess; // include a 'true' parameter for debug enabled +GSMServer server(80); // port 80 (http default) + +// timeout +const unsigned long __TIMEOUT__ = 10 * 1000; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("starting,.."); + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected to GPRS network"); + + // start server + server.begin(); + + //Get IP. + IPAddress LocalIP = gprs.getIPAddress(); + Serial.println("Server IP address="); + Serial.println(LocalIP); +} + +void loop() { + GSMClient client = server.available(); + + if (client) { + if (client.available()) { + Serial.write(client.read()); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/arduino_secrets.h new file mode 100644 index 00000000..cdd607cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/README.adoc new file mode 100644 index 00000000..96e35b9b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/README.adoc @@ -0,0 +1,10 @@ +:repository-owner: arduino-libraries +:repository-name: MKRIMU + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the acceleration, gyroscope, magnetic fields and Euler angles from the IMU on your MKR IMU Shield. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleAccelerometer/SimpleAccelerometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleAccelerometer/SimpleAccelerometer.ino new file mode 100644 index 00000000..26a7c853 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleAccelerometer/SimpleAccelerometer.ino @@ -0,0 +1,49 @@ +/* + MKR IMU Shield - Simple Accelerometer + + This example reads the acceleration values from the IMU + on the MKR IMU Shield and continuously prints them to the + Serial Monitor. + + The circuit: + - Arduino MKR board + - Arduino MKR IMU Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1) + ; + } + + Serial.print("Accelerometer sample rate = "); + Serial.print(IMU.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Acceleration in g's"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.accelerationAvailable()) { + IMU.readAcceleration(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleEulerAngles/SimpleEulerAngles.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleEulerAngles/SimpleEulerAngles.ino new file mode 100644 index 00000000..5bbd74da --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleEulerAngles/SimpleEulerAngles.ino @@ -0,0 +1,49 @@ +/* + MKR IMU Shield - Simple Euler Angles + + This example reads the Euler angle values from the IMU + on the MKR IMU Shield and continuously prints them to the + Serial Monitor. + + The circuit: + - Arduino MKR board + - Arduino MKR IMU Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1) + ; + } + + Serial.print("Euler Angles sample rate = "); + Serial.print(IMU.eulerAnglesSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Euler Angles in degrees"); + Serial.println("Heading\tRoll\tPitch"); +} + +void loop() { + float heading, roll, pitch; + + if (IMU.eulerAnglesAvailable()) { + IMU.readEulerAngles(heading, roll, pitch); + + Serial.print(heading); + Serial.print('\t'); + Serial.print(roll); + Serial.print('\t'); + Serial.println(pitch); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleGyroscope/SimpleGyroscope.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleGyroscope/SimpleGyroscope.ino new file mode 100644 index 00000000..6cd4d111 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleGyroscope/SimpleGyroscope.ino @@ -0,0 +1,49 @@ +/* + MKR IMU Shield - Simple Gyroscope + + This example reads the gyroscope values from the IMU + on the MKR IMU Shield and continuously prints them to the + Serial Monitor. + + The circuit: + - Arduino MKR board + - Arduino MKR IMU Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1) + ; + } + + Serial.print("Gyroscope sample rate = "); + Serial.print(IMU.gyroscopeSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Gyroscope in degrees/second"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.gyroscopeAvailable()) { + IMU.readGyroscope(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleMagnetometer/SimpleMagnetometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleMagnetometer/SimpleMagnetometer.ino new file mode 100644 index 00000000..57c02f4c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRIMU/examples/SimpleMagnetometer/SimpleMagnetometer.ino @@ -0,0 +1,49 @@ +/* + MKR IMU Shield - Simple Magnetometer + + This example reads the magnetic field values from the IMU + on the MKR IMU Shield and continuously prints them to the + Serial Monitor. + + The circuit: + - Arduino MKR board + - Arduino MKR IMU Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1) + ; + } + + Serial.print("Magnetic Field sample rate = "); + Serial.print(IMU.magneticFieldSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Magnetic Field in uT"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.magneticFieldAvailable()) { + IMU.readMagneticField(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/README.adoc new file mode 100644 index 00000000..2f6bc234 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/README.adoc @@ -0,0 +1,31 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: MKRNB + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/workflows/Compile%20Examples/badge.svg["Compile Examples Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Compile+Examples"] +image:https://github.com/{repository-owner}/{repository-name}/workflows/Spell%20Check/badge.svg["Spell Check Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Spell+Check"] + +This library enables an Arduino MKR NB 1500 board to connect to the internet over a NarrowBand IoT or LTE Cat M1 network. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino new file mode 100644 index 00000000..3a9e5190 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino @@ -0,0 +1,149 @@ +/* + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP write and parsePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + modified 6 Dec 2017 ported from WiFi101 to MKRGSM + by Arturo Guadalupi + + This code is in the public domain. + +*/ + +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// initialize the library instance +NBClient client; +GPRS gprs; +NB nbAccess; + +// A UDP instance to let us send and receive packets over UDP +NBUDP Udp; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino GPRS NTP client."); + // connection state + boolean connected = false; + + // After starting the modem with NB.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((nbAccess.begin(PINNUMBER) == NB_READY) && (gprs.attachGPRS() == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) { + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/NBSSLWebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/NBSSLWebClient.ino new file mode 100644 index 00000000..42049910 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/NBSSLWebClient.ino @@ -0,0 +1,94 @@ +/* + SSL Web client + + This sketch connects to a website using SSL through a MKR NB 1500 board. Specifically, + this example downloads the URL "https://www.arduino.cc/asciilogo.txt" and + prints it to the Serial monitor. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card with a data plan + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NBSSLClient client; +GPRS gprs; +NB nbAccess; + +// URL, path and port (for example: arduino.cc) +char server[] = "arduino.cc"; +char path[] = "/asciilogo.txt"; +int port = 443; // port 443 is the default for HTTPS + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + // connection state + boolean connected = false; + + // After starting the modem with NB.begin() + // attach to the GPRS network with the APN, login and password + while (!connected) { + if ((nbAccess.begin(PINNUMBER) == NB_READY) && (gprs.attachGPRS() == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET "); + client.print(path); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBWebClient/NBWebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBWebClient/NBWebClient.ino new file mode 100644 index 00000000..39a0cfb5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBWebClient/NBWebClient.ino @@ -0,0 +1,93 @@ +/* + Web client + + This sketch connects to a website through a MKR NB 1500 board. Specifically, + this example downloads the URL "http://example.org/" and + prints it to the Serial monitor. + + Circuit: + - MKR NB 1500 board + - Antenna + - SIM card with a data plan + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NBClient client; +GPRS gprs; +NB nbAccess; + +// URL, path and port (for example: example.org) +char server[] = "example.org"; +char path[] = "/"; +int port = 80; // port 80 is the default for HTTP + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + // connection state + boolean connected = false; + + // After starting the modem with NB.begin() + // attach to the GPRS network with the APN, login and password + while (!connected) { + if ((nbAccess.begin(PINNUMBER) == NB_READY) && (gprs.attachGPRS() == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET "); + client.print(path); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + Serial.print((char)client.read()); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBWebClient/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/NBWebClient/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/ReceiveSMS.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/ReceiveSMS.ino new file mode 100644 index 00000000..11b479d7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/ReceiveSMS.ino @@ -0,0 +1,88 @@ +/* + SMS receiver + + This sketch, for the MKR NB 1500 board, waits for a SMS message + and displays it through the Serial port. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card that can receive SMS messages + + created 25 Feb 2012 + by Javier Zorzano / TD +*/ + +// include the NB library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instances +NB nbAccess; +NB_SMS sms; + +// Array to hold the number an SMS is retrieved from +char senderNumber[20]; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("SMS Messages Receiver"); + + // connection state + bool connected = false; + + // Start GSM connection + while (!connected) { + if (nbAccess.begin(PINNUMBER) == NB_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("NB initialized"); + Serial.println("Waiting for messages"); +} + +void loop() { + int c; + + // If there are any SMSs available() + if (sms.available()) { + Serial.println("Message received from:"); + + // Get remote number + sms.remoteNumber(senderNumber, 20); + Serial.println(senderNumber); + + // An example of message disposal + // Any messages starting with # should be discarded + if (sms.peek() == '#') { + Serial.println("Discarded SMS"); + sms.flush(); + } + + // Read message bytes and print them + while ((c = sms.read()) != -1) { + Serial.print((char)c); + } + + Serial.println("\nEND OF MESSAGE"); + + // Delete message from modem memory + sms.flush(); + Serial.println("MESSAGE DELETED"); + } + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/SendSMS/SendSMS.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/SendSMS/SendSMS.ino new file mode 100644 index 00000000..71989f6e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/SendSMS/SendSMS.ino @@ -0,0 +1,100 @@ +/* + SMS sender + + This sketch, for the MKR NB 1500 board, sends an SMS message + you enter in the serial monitor. Connect your Arduino with the + SIM card, open the serial monitor, and wait for + the "READY" message to appear in the monitor. Next, type a + message to send and press "return". Make sure the serial + monitor is set to send a newline when you press return. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card that can send SMS + + created 25 Feb 2012 + by Tom Igoe +*/ + +// Include the NB library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NB nbAccess; +NB_SMS sms; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("SMS Messages Sender"); + + // connection state + bool connected = false; + + // Start NB module + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (nbAccess.begin(PINNUMBER) == NB_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("NB initialized"); +} + +void loop() { + + Serial.print("Enter a mobile number: "); + char remoteNum[20]; // telephone number to send SMS + readSerial(remoteNum); + Serial.println(remoteNum); + + // SMS text + Serial.print("Now, enter SMS content: "); + char txtMsg[200]; + readSerial(txtMsg); + Serial.println("SENDING"); + Serial.println(); + Serial.println("Message:"); + Serial.println(txtMsg); + + // send the message + sms.beginSMS(remoteNum); + sms.print(txtMsg); + sms.endSMS(); + Serial.println("\nCOMPLETE!\n"); +} + +/* + Read input serial + */ +int readSerial(char result[]) { + int i = 0; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + result[i] = '\0'; + Serial.flush(); + return 0; + } + if (inChar != '\r') { + result[i] = inChar; + i++; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/SendSMS/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/SendSMS/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/SendSMS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino new file mode 100644 index 00000000..7a2bb06c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino @@ -0,0 +1,135 @@ +/* + Radio Access Technology selection for Arduino MKR NB 1500 + + This sketch allows you to select your preferred 4G + Narrowband Radio Access Technology (RAT). + + You can choose among CAT-M1, NB-IoT or a combination of both. + + Selecting JUST ONE technology will speed up the modem's network + registration A LOT! + + The chosen configuration will be saved to modem's internal memory + and will be preserved through MKR NB 1500 sketch uploads. + + In order to change the RAT, you will need to run this sketch again. + + Circuit: + - MKR NB 1500 board + - Antenna + - SIM card + + Created 26 November 2018 + by Giampaolo Mancini + +*/ + +#include + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + MODEM.begin(); + while (!MODEM.noop()) + ; + + for (int i = 0; i < 80; i++) Serial.print("*"); + Serial.println(); + Serial.println("This sketch allows you to select your preferred"); + Serial.println("4G Narrowband Radio Access Technology (RAT)."); + Serial.println(); + Serial.println("You can choose among CAT-M1, NB-IoT or a combination of both."); + Serial.println(); + Serial.println("Selecting JUST ONE technology will speed up the modem's network registration A LOT!"); + Serial.println(); + Serial.println("The chosen configuration will be saved to modem's internal memory"); + Serial.println("and will be preserved through MKR NB 1500 sketch uploads."); + Serial.println(); + Serial.println("In order to change the RAT, you will need to run this sketch again."); + for (int i = 0; i < 80; i++) Serial.print("*"); + + Serial.println(); + Serial.println(); + Serial.println("Please choose your Radio Access Technology:"); + Serial.println(); + Serial.println(" 0 - CAT M1 only"); + Serial.println(" 1 - NB IoT only"); + Serial.println(" 2 - CAT M1 preferred, NB IoT as failover (default)"); + Serial.println(" 3 - NB IoT preferred, CAT M1 as failover"); + Serial.println(); +} + +void loop() { + String uratChoice; + + Serial.print("> "); + + Serial.setTimeout(-1); + while (Serial.available() == 0) + ; + String uratInput = Serial.readStringUntil('\n'); + uratInput.trim(); + int urat = uratInput.toInt(); + Serial.println(urat); + + switch (urat) { + case 0: + uratChoice = "7"; + break; + case 1: + uratChoice = "8"; + break; + case 2: + uratChoice = "7,8"; + break; + case 3: + uratChoice = "8,7"; + break; + default: + Serial.println("Invalid input. Please, retry."); + return; + } + + setRAT(uratChoice); + apply(); + + Serial.println(); + Serial.println("Radio Access Technology selected."); + Serial.println("Now you can upload your 4G application sketch."); + while (true) + ; +} + +bool setRAT(String choice) { + String response; + + Serial.print("Disconnecting from network: "); + MODEM.sendf("AT+COPS=2"); + MODEM.waitForResponse(2000); + Serial.println("done."); + + Serial.print("Setting Radio Access Technology: "); + MODEM.sendf("AT+URAT=%s", choice.c_str()); + MODEM.waitForResponse(2000, &response); + Serial.println("done."); + + return true; +} + +bool apply() { + Serial.print("Applying changes and saving configuration: "); + MODEM.send("AT+CFUN=15"); + MODEM.waitForResponse(5000); + delay(5000); + + do { + delay(1000); + MODEM.noop(); + } while (MODEM.waitForResponse(1000) != 1); + + Serial.println("done."); + + return true; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/NBScanNetworks.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/NBScanNetworks.ino new file mode 100644 index 00000000..f1bbdd69 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/NBScanNetworks.ino @@ -0,0 +1,90 @@ +/* + + NB Scan Networks + + This example prints out the IMEI number of the modem, + then checks to see if it's connected to a carrier. + Then it scans for nearby networks and prints out their signal strengths. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card + + Created 8 Mar 2012 + by Tom Igoe, implemented by Javier Carazo + Modified 4 Feb 2013 + by Scott Fitzgerald +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NB nbAccess; // include a 'true' parameter to enable debugging +NBScanner scannerNetworks; +NBModem modemTest; + +// Save data variables +String IMEI = ""; + +// serial monitor result messages +String errortext = "ERROR"; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + Serial.println("NB IoT/LTE Cat M1 networks scanner"); + scannerNetworks.begin(); + + // connection state + boolean connected = false; + + // Start module + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (nbAccess.begin(PINNUMBER) == NB_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + // get modem parameters + // IMEI, modem unique identifier + Serial.print("Modem IMEI: "); + IMEI = modemTest.getIMEI(); + IMEI.replace("\n", ""); + if (IMEI != NULL) { + Serial.println(IMEI); + } +} + +void loop() { + // currently connected carrier + Serial.print("Current carrier: "); + Serial.println(scannerNetworks.getCurrentCarrier()); + + // returns strength and BER + // signal strength in 0-31 scale. 31 means power > 51dBm + // BER is the Bit Error Rate. 0-7 scale. 99=not detectable + Serial.print("Signal Strength: "); + Serial.print(scannerNetworks.getSignalStrength()); + Serial.println(" [0-31]"); + + // scan for existing networks, displays a list of networks + Serial.println("Scanning available networks. May take some seconds."); + Serial.println(scannerNetworks.readNetworks()); + // wait ten seconds before scanning again + delay(10000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/PinManagement/PinManagement.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/PinManagement/PinManagement.ino new file mode 100644 index 00000000..cf7986e6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/PinManagement/PinManagement.ino @@ -0,0 +1,144 @@ +/* + + This example enables you to change or remove the PIN number of + a SIM card inserted into a MKR NB 1500 board. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card + + Created 12 Jun 2012 + by David del Peral +*/ + +// libraries +#include + +// pin manager object +NBPIN PINManager; + +// save input in serial by user +String user_input = ""; + +// authenticated with PIN code +boolean auth = false; + +// serial monitor result messages +String oktext = "OK"; +String errortext = "ERROR"; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + Serial.println("Change PIN example\n"); + PINManager.begin(); + + // check if the SIM have pin lock + while (!auth) { + int pin_query = PINManager.isPIN(); + if (pin_query == 1) { + // if SIM is locked, enter PIN code + Serial.print("Enter PIN code: "); + user_input = readSerial(); + // check PIN code + if (PINManager.checkPIN(user_input) == 0) { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } else { + // if PIN code was incorrected + Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); + } + } else if (pin_query == -1) { + // PIN code is locked, user must enter PUK code + Serial.println("PIN locked. Enter PUK code: "); + String puk = readSerial(); + Serial.print("Now, enter a new PIN code: "); + user_input = readSerial(); + // check PUK code + if (PINManager.checkPUK(puk, user_input) == 0) { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } else { + // if PUK o the new PIN are incorrect + Serial.println("Incorrect PUK or invalid new PIN. Try again!."); + } + } else if (pin_query == -2) { + // the worst case, PIN and PUK are locked + Serial.println("PIN and PUK locked. Use PIN2/PUK2 in a mobile phone."); + while (true) + ; + } else { + // SIM does not requires authentication + Serial.println("No pin necessary."); + auth = true; + } + } + + // start module + Serial.print("Checking register in NB IoT / LTE Cat M1 network..."); + if (PINManager.checkReg() == 0) { + Serial.println(oktext); + } + // if you are connect by roaming + else if (PINManager.checkReg() == 1) { + Serial.println("ROAMING " + oktext); + } else { + // error connection + Serial.println(errortext); + while (true) + ; + } +} + +void loop() { + // Function loop implements pin management user menu + // You can only change PIN code if your SIM uses pin lock + + Serial.println("Choose an option:\n1 - On/Off PIN."); + if (PINManager.getPINUsed()) { + Serial.println("2 - Change PIN."); + } + // save user input to user_op variable + String user_op = readSerial(); + if (user_op == "1") { + Serial.println("Enter your PIN code:"); + user_input = readSerial(); + // activate/deactivate PIN lock + PINManager.switchPIN(user_input); + } else if (user_op == "2" && PINManager.getPINUsed()) { + Serial.println("Enter your actual PIN code:"); + String oldPIN = readSerial(); + Serial.println("Now, enter your new PIN code:"); + String newPIN = readSerial(); + // change PIN + PINManager.changePIN(oldPIN, newPIN); + } else { + Serial.println("Incorrect option. Try again!."); + } + delay(1000); +} + +/* + Read serial input + */ +String readSerial() { + String text = ""; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + return text; + } + if (inChar != '\r') { + text += inChar; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/SerialSARAPassthrough/SerialSARAPassthrough.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/SerialSARAPassthrough/SerialSARAPassthrough.ino new file mode 100644 index 00000000..661d65ac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/SerialSARAPassthrough/SerialSARAPassthrough.ino @@ -0,0 +1,47 @@ +/* + SerialSARAPassthrough sketch + + This sketch allows you to send AT commands from the USB CDC serial port + of the MKR NB 1500 board to the onboard ublox SARA-R410 cellular module. + + For a list of supported AT commands see: + https://www.u-blox.com/sites/default/files/u-blox-CEL_ATCommands_%28UBX-13002752%29.pdf + + Circuit: + - MKR NB 1500 board + - Antenna + - SIM card + + Make sure the Serial Monitor's line ending is set to "Both NL and CR" or "Carriage Return" + + created 11 December 2017 + Sandeep Mistry +*/ + +// baud rate used for both Serial ports +unsigned long baud = 115200; + +void setup() { + // NEVER EVER use RESET_N + pinMode(SARA_RESETN, OUTPUT); + digitalWrite(SARA_RESETN, LOW); + + // Send Poweron pulse + pinMode(SARA_PWR_ON, OUTPUT); + digitalWrite(SARA_PWR_ON, HIGH); + delay(150); + digitalWrite(SARA_PWR_ON, LOW); + + Serial.begin(baud); + SerialSARA.begin(baud); +} + +void loop() { + if (Serial.available()) { + SerialSARA.write(Serial.read()); + } + + if (SerialSARA.available()) { + Serial.write(SerialSARA.read()); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/TestGPRS.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/TestGPRS.ino new file mode 100644 index 00000000..4e5742e1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/TestGPRS.ino @@ -0,0 +1,175 @@ +/* + + This sketch tests the MKR NB 1500 board's ability to connect to a + GPRS network. It asks for APN information through the + serial monitor and tries to connect to example.org. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card with data plan + + Created 18 Jun 2012 + by David del Peral +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NB nbAccess; // NB access: include a 'true' parameter for debug enabled +GPRS gprsAccess; // GPRS access +NBClient client; // Client service for TCP connection + +// messages for serial monitor response +String oktext = "OK"; +String errortext = "ERROR"; + +// URL and path (for example: example.org) +char url[] = "example.org"; +char urlproxy[] = "http://example.org"; +char path[] = "/"; + +// variable to save obtained response +String response = ""; + +// use a proxy +boolean use_proxy = false; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } +} + +void loop() { + use_proxy = false; + + // start module + // if your SIM has PIN, pass it as a parameter of begin() in quotes + Serial.print("Connecting NB IoT / LTE Cat M1 network..."); + if (nbAccess.begin(PINNUMBER) != NB_READY) { + Serial.println(errortext); + while (true) + ; + } + Serial.println(oktext); + + // attach GPRS + Serial.println("Attaching to GPRS..."); + if (gprsAccess.attachGPRS() != GPRS_READY) { + Serial.println(errortext); + } else { + + Serial.println(oktext); + + // read proxy introduced by user + char proxy[100]; + Serial.print("If your carrier uses a proxy, enter it, if not press enter: "); + readSerial(proxy); + Serial.println(proxy); + + // if user introduced a proxy, asks them for proxy port + int pport; + if (proxy[0] != '\0') { + // read proxy port introduced by user + char proxyport[10]; + Serial.print("Enter the proxy port: "); + readSerial(proxyport); + // cast proxy port introduced to integer + pport = (int)proxyport; + use_proxy = true; + Serial.println(proxyport); + } + + // connection with example.org and realize HTTP request + Serial.print("Connecting and sending GET request to example.org..."); + int res_connect; + + // if use a proxy, connect with it + if (use_proxy) { + res_connect = client.connect(proxy, pport); + } else { + res_connect = client.connect(url, 80); + } + + if (res_connect) { + // make a HTTP 1.0 GET request (client sends the request) + client.print("GET "); + + // if using a proxy, the path is example.org URL + if (use_proxy) { + client.print(urlproxy); + } else { + client.print(path); + } + + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(url); + client.println("Connection: close"); + client.println(); + Serial.println(oktext); + } else { + // if you didn't get a connection to the server + Serial.println(errortext); + } + Serial.print("Receiving response..."); + + boolean test = true; + while (test) { + // if there are incoming bytes available + // from the server, read and check them + if (client.available()) { + char c = client.read(); + response += c; + + // cast response obtained from string to char array + char responsechar[response.length() + 1]; + response.toCharArray(responsechar, response.length() + 1); + + // if response includes a "200 OK" substring + if (strstr(responsechar, "200 OK") != NULL) { + Serial.println(oktext); + Serial.println("TEST COMPLETE!"); + test = false; + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + test = false; + } + } + } +} + +/* + Read input serial + */ +int readSerial(char result[]) { + int i = 0; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + result[i] = '\0'; + return 0; + } + if (inChar != '\r') { + result[i] = inChar; + i++; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/arduino_secrets.h new file mode 100644 index 00000000..2e62f98c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestModem/TestModem.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestModem/TestModem.ino new file mode 100644 index 00000000..d5fd318c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRNB/examples/Tools/TestModem/TestModem.ino @@ -0,0 +1,66 @@ +/* + + This example tests to see if the modem of the + MKR NB 1500 board is working correctly. You do not need + a SIM card for this example. + + Circuit: + * MKR NB 1500 board + * Antenna + + Created 12 Jun 2012 + by David del Peral + modified 21 Nov 2012 + by Tom Igoe +*/ + +// libraries +#include + +// modem verification object +NBModem modem; + +// IMEI variable +String IMEI = ""; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // start modem test (reset and check response) + Serial.print("Starting modem test..."); + if (modem.begin()) { + Serial.println("modem.begin() succeeded"); + } else { + Serial.println("ERROR, no modem answer."); + } +} + +void loop() { + // get modem IMEI + Serial.print("Checking IMEI..."); + IMEI = modem.getIMEI(); + + // check IMEI response + if (IMEI != NULL) { + // show IMEI in serial monitor + Serial.println("Modem's IMEI: " + IMEI); + // reset modem to check booting: + Serial.print("Resetting modem..."); + modem.begin(); + // get and check IMEI one more time + if (modem.getIMEI() != NULL) { + Serial.println("Modem is functioning properly"); + } else { + Serial.println("Error: getIMEI() failed after modem.begin()"); + } + } else { + Serial.println("Error: Could not get IMEI"); + } + // do nothing: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/COPYING b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/COPYING new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/COPYING.LESSER b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/COPYING.LESSER new file mode 100644 index 00000000..0a041280 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/README.md new file mode 100644 index 00000000..06ee544d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/README.md @@ -0,0 +1,32 @@ +# MKRWAN + +[![Check Arduino status](https://github.com/arduino-libraries/MKRWAN/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/MKRWAN/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/MKRWAN/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN/actions/workflows/spell-check.yml) + +Provides APIs to communicate with LoRa and LoRaWAN networks + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/MKRWAN + +If you are looking for the firmware running on Murata CMWX1ZZABZ-078 module, the complete source code is hosted at https://github.com/arduino/mkrwan1300-fw + +## License + +Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) + +Based on the TinyGSM library https://github.com/vshymanskyy/TinyGSM +Copyright (c) 2016 Volodymyr Shymanskyy + +MKR WAN library is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MKR WAN library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with MKR WAN library. If not, see . diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/DumbModemLoraSender/DumbModemLoraSender.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/DumbModemLoraSender/DumbModemLoraSender.ino new file mode 100644 index 00000000..e7af2449 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/DumbModemLoraSender/DumbModemLoraSender.ino @@ -0,0 +1,56 @@ +/* This example shows how to use the SX1272 chip + * (part of Murata module) without any external stack. + * To achieve this, we must setup the modem in dumb mode + * and use LORA_IRQ_DUMB pin as chip select and SPI1 as communication port. + * + * The example is based on LoraSender by @sandeepmistry arduino-LoRa library + * https://github.com/sandeepmistry/arduino-LoRa + * + * Starting from https://github.com/sandeepmistry/arduino-LoRa/commit/5f62ed2ce9d1623bfc12f468b8152ba1878b5b16, + * LoRa library knows about MKR WAN 1300/1310 and automatically restarts the module in dumb mode, uses SPI1 and the correct GPIOs. + * + * Since there is no IRQ pin available, the host must poll for data (unfortunately) + * + */ + +#include +#include +//#include + +int counter = 0; + +//LoRaModem modem; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // No need to call modem.dumb() with arduino-LoRa >= 0.5.0 + //modem.dumb(); + + Serial.println("LoRa Sender"); + + // Configure LoRa module to transmit and receive at 915 MHz (915*10^6) + // Replace 915E6 with the frequency you need (eg. 433E6 for 433 MHz) + if (!LoRa.begin(915E6)) { + Serial.println("Starting LoRa failed!"); + while (1) + ; + } +} + +void loop() { + Serial.print("Sending packet: "); + Serial.println(counter); + + // send packet + LoRa.beginPacket(); + LoRa.print("hello "); + LoRa.print(counter); + LoRa.endPacket(); + + counter++; + + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/FWUpdaterBridge/FWUpdaterBridge.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/FWUpdaterBridge/FWUpdaterBridge.ino new file mode 100644 index 00000000..ed3df1d5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/FWUpdaterBridge/FWUpdaterBridge.ino @@ -0,0 +1,64 @@ +/* + FW Updater Bridge + This sketch demonstrates how to update the FW on the MKR WAN 1300/1310 LoRa module. + Once flashed it should be used in conjunction with stm32flash utility (https://github.com/facchinm/stm32flash) + + This example code is in the public domain. +*/ + +#define Serial1 Serial + +void setup() { + Serial1.begin(115200, SERIAL_8E1); + Serial2.begin(115200, SERIAL_8E1); + + delay(1000); + + pinMode(LED_BUILTIN, OUTPUT); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(200); + digitalWrite(LORA_RESET, LOW); + delay(200); + digitalWrite(LORA_RESET, HIGH); +} + +void resetModule() { + Serial.println("resetting module"); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + + while (!Serial) + ; +} + +char rx_buf[512]; +char tx_buf[512]; + +int rx = 0; +int tx = 0; + +void loop() { + while (Serial1.available()) { // If anything comes in Serial (USB), + tx_buf[tx++] = Serial1.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (tx > 0) { + Serial2.write(tx_buf, tx); + tx = 0; + } + + while (Serial2.available()) { // If anything comes in Serial (USB), + rx_buf[rx++] = Serial2.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (rx > 0) { + Serial1.write(rx_buf, rx); + rx = 0; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/FirstConfiguration/FirstConfiguration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/FirstConfiguration/FirstConfiguration.ino new file mode 100644 index 00000000..42f5ae2d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/FirstConfiguration/FirstConfiguration.ino @@ -0,0 +1,113 @@ +/* + First Configuration + This sketch demonstrates the usage of MKR WAN 1300/1310 LoRa module. + This example code is in the public domain. +*/ + +#include + +LoRaModem modem; + +// Uncomment if using the Murata chip as a module +// LoRaModem modem(Serial1); + +String appEui; +String appKey; +String devAddr; +String nwkSKey; +String appSKey; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial) + ; + Serial.println("Welcome to MKR WAN 1300/1310 first configuration sketch"); + Serial.println("Register to your favourite LoRa network and we are ready to go!"); + // change this to your regional band (eg. US915, AS923, ...) + if (!modem.begin(EU868)) { + Serial.println("Failed to start module"); + while (1) {} + }; + Serial.print("Your module version is: "); + Serial.println(modem.version()); + if (modem.version() != ARDUINO_FW_VERSION) { + Serial.println("Please make sure that the latest modem firmware is installed."); + Serial.println("To update the firmware upload the 'MKRWANFWUpdate_standalone.ino' sketch."); + } + Serial.print("Your device EUI is: "); + Serial.println(modem.deviceEUI()); + + int mode = 0; + while (mode != 1 && mode != 2) { + Serial.println("Are you connecting via OTAA (1) or ABP (2)?"); + while (!Serial.available()) + ; + mode = Serial.readStringUntil('\n').toInt(); + } + + int connected; + if (mode == 1) { + Serial.println("Enter your APP EUI"); + while (!Serial.available()) + ; + appEui = Serial.readStringUntil('\n'); + + Serial.println("Enter your APP KEY"); + while (!Serial.available()) + ; + appKey = Serial.readStringUntil('\n'); + + appKey.trim(); + appEui.trim(); + + connected = modem.joinOTAA(appEui, appKey); + } else if (mode == 2) { + + Serial.println("Enter your Device Address"); + while (!Serial.available()) + ; + devAddr = Serial.readStringUntil('\n'); + + Serial.println("Enter your NWS KEY"); + while (!Serial.available()) + ; + nwkSKey = Serial.readStringUntil('\n'); + + Serial.println("Enter your APP SKEY"); + while (!Serial.available()) + ; + appSKey = Serial.readStringUntil('\n'); + + devAddr.trim(); + nwkSKey.trim(); + appSKey.trim(); + + connected = modem.joinABP(devAddr, nwkSKey, appSKey); + } + + if (!connected) { + Serial.println("Something went wrong; are you indoor? Move near a window and retry"); + while (1) {} + } + + delay(5000); + + int err; + modem.setPort(3); + modem.beginPacket(); + modem.print("HeLoRA world!"); + err = modem.endPacket(true); + if (err > 0) { + Serial.println("Message sent correctly!"); + } else { + Serial.println("Error sending message :("); + } +} + +void loop() { + while (modem.available()) { + Serial.write(modem.read()); + } + modem.poll(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/LoraSendAndReceive.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/LoraSendAndReceive.ino new file mode 100644 index 00000000..86aee0a7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/LoraSendAndReceive.ino @@ -0,0 +1,93 @@ +/* + Lora Send And Receive + This sketch demonstrates how to send and receive data with the MKR WAN 1300/1310 LoRa module. + This example code is in the public domain. +*/ + +#include + +LoRaModem modem; + +// Uncomment if using the Murata chip as a module +// LoRaModem modem(Serial1); + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +String appEui = SECRET_APP_EUI; +String appKey = SECRET_APP_KEY; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial) + ; + // change this to your regional band (eg. US915, AS923, ...) + if (!modem.begin(EU868)) { + Serial.println("Failed to start module"); + while (1) {} + }; + Serial.print("Your module version is: "); + Serial.println(modem.version()); + Serial.print("Your device EUI is: "); + Serial.println(modem.deviceEUI()); + + int connected = modem.joinOTAA(appEui, appKey); + if (!connected) { + Serial.println("Something went wrong; are you indoor? Move near a window and retry"); + while (1) {} + } + + // Set poll interval to 60 secs. + modem.minPollInterval(60); + // NOTE: independent of this setting, the modem will + // not allow sending more than one message every 2 minutes, + // this is enforced by firmware and can not be changed. +} + +void loop() { + Serial.println(); + Serial.println("Enter a message to send to network"); + Serial.println("(make sure that end-of-line 'NL' is enabled)"); + + while (!Serial.available()) + ; + String msg = Serial.readStringUntil('\n'); + + Serial.println(); + Serial.print("Sending: " + msg + " - "); + for (unsigned int i = 0; i < msg.length(); i++) { + Serial.print(msg[i] >> 4, HEX); + Serial.print(msg[i] & 0xF, HEX); + Serial.print(" "); + } + Serial.println(); + + int err; + modem.beginPacket(); + modem.print(msg); + err = modem.endPacket(true); + if (err > 0) { + Serial.println("Message sent correctly!"); + } else { + Serial.println("Error sending message :("); + Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength"); + Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)"); + } + delay(1000); + if (!modem.available()) { + Serial.println("No downlink message received at this time."); + return; + } + char rcv[64]; + int i = 0; + while (modem.available()) { + rcv[i++] = (char)modem.read(); + } + Serial.print("Received: "); + for (unsigned int j = 0; j < i; j++) { + Serial.print(rcv[j] >> 4, HEX); + Serial.print(rcv[j] & 0xF, HEX); + Serial.print(" "); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/arduino_secrets.h new file mode 100644 index 00000000..3abaf3f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/arduino_secrets.h @@ -0,0 +1,3 @@ +// Replace with keys obtained from TheThingsNetwork console +#define SECRET_APP_EUI "xxxxxxxxxxxxx" +#define SECRET_APP_KEY "yyyyyyyyyyyyyyyyyyyyyyy" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino new file mode 100644 index 00000000..d2174c1e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino @@ -0,0 +1,368 @@ +/* + * STANDALONE FIRMWARE UPDATE FOR MKR WAN 1300/1310 + * This sketch implements STM32 bootloader protocol + * It is based on stm32flash (mirrored here git@github.com:facchinm/stm32flash.git) + * with as little modifications as possible. + * + * To generate it after a firmware update, execute + * + * echo -n "const " > fw.h && xxd -i mlm32l07x01.bin >> fw.h + * + */ + + +#include "fw.h" +#include "stm32.h" +#include "serial_arduino.h" +#include + +/* device globals */ +stm32_t *stm = NULL; +void *p_st = NULL; + +int ret = -1; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + + while (!Serial) + ; + + struct port_interface port; + struct port_options port_opts = { + .baudRate = 115200, + .serial_mode = SERIAL_8E1 + }; + + port.flags = PORT_CMD_INIT | PORT_GVR_ETX | PORT_BYTE | PORT_RETRY; + port.dev = &SerialLoRa; + port.ops = &port_opts; + + assignCallbacks(&port); + + pinMode(LED_BUILTIN, OUTPUT); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(200); + digitalWrite(LORA_RESET, LOW); + delay(200); + digitalWrite(LORA_RESET, HIGH); + delay(200); + + Serial.println("Press a key to start FW update"); + port.open(&port); + //port.flush(&port); + + stm = stm32_init(&port, 1); + + fprintf(diag, "Version : 0x%02x\n", stm->bl_version); + if (port.flags & PORT_GVR_ETX) { + fprintf(diag, "Option 1 : 0x%02x\n", stm->option1); + fprintf(diag, "Option 2 : 0x%02x\n", stm->option2); + } + fprintf(diag, "Device ID : 0x%04x (%s)\n", stm->pid, stm->dev->name); + fprintf(diag, "- RAM : Up to %dKiB (%db reserved by bootloader)\n", (stm->dev->ram_end - 0x20000000) / 1024, stm->dev->ram_start - 0x20000000); + fprintf(diag, "- Flash : Up to %dKiB (size first sector: %dx%d)\n", (stm->dev->fl_end - stm->dev->fl_start) / 1024, stm->dev->fl_pps, stm->dev->fl_ps[0]); + fprintf(diag, "- Option RAM : %db\n", stm->dev->opt_end - stm->dev->opt_start + 1); + fprintf(diag, "- System RAM : %dKiB\n", (stm->dev->mem_end - stm->dev->mem_start) / 1024); + + uint8_t buffer[256]; + uint32_t addr, start, end; + unsigned int len; + int failed = 0; + int first_page, num_pages; + + int npages = mlm32l07x01_bin_len / 128 + 1; + int spage = 0; + bool verify = 1; + int retry = 10; + bool reset_flag = 0; + bool exec_flag = 1; + int execute = 0; // address + + /* + Cleanup addresses: + + Starting from options + start_addr, readwrite_len, spage, npages + and using device memory size, compute + start, end, first_page, num_pages + */ + if (!npages) { + start = stm->dev->fl_start; + end = stm->dev->fl_end; + first_page = 0; + num_pages = STM32_MASS_ERASE; + } else { + first_page = spage; + start = flash_page_to_addr(first_page); + if (start > stm->dev->fl_end) { + fprintf(stderr, "Address range exceeds flash size.\n"); + ret = -1; + return; + } + + if (npages) { + num_pages = npages; + end = flash_page_to_addr(first_page + num_pages); + if (end > stm->dev->fl_end) + end = stm->dev->fl_end; + } else { + end = stm->dev->fl_end; + num_pages = flash_addr_to_page_ceil(end) - first_page; + } + + if (!first_page && end == stm->dev->fl_end) + num_pages = STM32_MASS_ERASE; + } + + ret = 0; + int s_err; + +#if 0 + fprintf(diag, "Erasing flash\n"); + + if (num_pages != STM32_MASS_ERASE && + (start != flash_page_to_addr(first_page) + || end != flash_page_to_addr(first_page + num_pages))) { + fprintf(stderr, "Specified start & length are invalid (must be page aligned)\n"); + ret = 1; + return; + } + + s_err = stm32_erase_memory(stm, first_page, num_pages); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to erase memory\n"); + ret = 1; + return; + } + ret = 0; + +#endif + + fprintf(diag, "Write to memory\n"); + + off_t offset = 0; + ssize_t r; + unsigned int size; + unsigned int max_wlen, max_rlen; + +#define STM32_MAX_RX_FRAME 256 /* cmd read memory */ +#define STM32_MAX_TX_FRAME (1 + 256 + 1) /* cmd write memory */ + + max_wlen = STM32_MAX_TX_FRAME - 2; /* skip len and crc */ + max_wlen &= ~3; /* 32 bit aligned */ + + max_rlen = STM32_MAX_RX_FRAME; + max_rlen = max_rlen < max_wlen ? max_rlen : max_wlen; + + /* Assume data from stdin is whole device */ + size = end - start; + + // TODO: It is possible to write to non-page boundaries, by reading out flash + // from partial pages and combining with the input data + // if ((start % stm->dev->fl_ps[i]) != 0 || (end % stm->dev->fl_ps[i]) != 0) { + // fprintf(stderr, "Specified start & length are invalid (must be page aligned)\n"); + // goto close; + // } + + // TODO: If writes are not page aligned, we should probably read out existing flash + // contents first, so it can be preserved and combined with new data + if (num_pages) { + fprintf(diag, "Erasing memory\n"); + s_err = stm32_erase_memory(stm, first_page, num_pages); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to erase memory\n"); + ret = -1; + return; + } + } + + addr = start; + while (addr < end && offset < size) { + uint32_t left = end - addr; + len = max_wlen > left ? left : max_wlen; + len = len > size - offset ? size - offset : len; + + memcpy(buffer, &mlm32l07x01_bin[offset], len); + + if (len == 0) { + fprintf(stderr, "Failed to read input file\n"); + ret = -1; + return; + } + +again: + s_err = stm32_write_memory(stm, addr, buffer, len); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to write memory at address 0x%08x\n", addr); + ret = -1; + return; + } + + if (verify) { + uint8_t compare[len]; + unsigned int offset, rlen; + + offset = 0; + while (offset < len) { + rlen = len - offset; + rlen = rlen < max_rlen ? rlen : max_rlen; + s_err = stm32_read_memory(stm, addr + offset, compare + offset, rlen); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to read memory at address 0x%08x\n", addr + offset); + ret = -1; + return; + } + offset += rlen; + } + + for (r = 0; r < len; ++r) + if (buffer[r] != compare[r]) { + if (failed == retry) { + fprintf(stderr, "Failed to verify at address 0x%08x, expected 0x%02x and found 0x%02x\n", + (uint32_t)(addr + r), + buffer[r], + compare[r]); + ret = -1; + return; + } + ++failed; + goto again; + } + + failed = 0; + } + + addr += len; + offset += len; + + fprintf(diag, + "Wrote %saddress 0x%08x (%d%%)\n ", + verify ? "and verified " : "", + addr, + 100 * offset / size); + } + + fprintf(diag, "Done.\n"); + ret = 0; + + if (stm && exec_flag && ret == 0) { + if (execute == 0) + execute = stm->dev->fl_start; + + fprintf(diag, "\nStarting execution at address 0x%08x... ", execute); + if (stm32_go(stm, execute) == STM32_ERR_OK) { + reset_flag = 0; + fprintf(diag, "done.\n"); + } else + fprintf(diag, "failed.\n"); + } +} + +void resetModuleRunning() { + digitalWrite(LORA_BOOT0, LOW); + SerialLoRa.end(); + SerialLoRa.begin(19200); + delay(100); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + delay(100); +} + +void loop() { + // put your main code here, to run repeatedly: + if (ret == 0) { + Serial.println("Flashing ok :)"); + SerialLoRa.end(); + LoRaModem *modem = new LoRaModem(); + modem->begin(EU868); + Serial.println(modem->version()); + } + while (1) + ; +} + +static int is_addr_in_ram(uint32_t addr) { + return addr >= stm->dev->ram_start && addr < stm->dev->ram_end; +} + +static int is_addr_in_flash(uint32_t addr) { + return addr >= stm->dev->fl_start && addr < stm->dev->fl_end; +} + +static int is_addr_in_opt_bytes(uint32_t addr) { + /* option bytes upper range is inclusive in our device table */ + return addr >= stm->dev->opt_start && addr <= stm->dev->opt_end; +} + +static int is_addr_in_sysmem(uint32_t addr) { + return addr >= stm->dev->mem_start && addr < stm->dev->mem_end; +} + +/* returns the page that contains address "addr" */ +static int flash_addr_to_page_floor(uint32_t addr) { + int page; + uint32_t *psize; + + if (!is_addr_in_flash(addr)) + return 0; + + page = 0; + addr -= stm->dev->fl_start; + psize = stm->dev->fl_ps; + + while (addr >= psize[0]) { + addr -= psize[0]; + page++; + if (psize[1]) + psize++; + } + + return page; +} + +/* returns the first page whose start addr is >= "addr" */ +int flash_addr_to_page_ceil(uint32_t addr) { + int page; + uint32_t *psize; + + if (!(addr >= stm->dev->fl_start && addr <= stm->dev->fl_end)) + return 0; + + page = 0; + addr -= stm->dev->fl_start; + psize = stm->dev->fl_ps; + + while (addr >= psize[0]) { + addr -= psize[0]; + page++; + if (psize[1]) + psize++; + } + + return addr ? page + 1 : page; +} + +/* returns the lower address of flash page "page" */ +static uint32_t flash_page_to_addr(int page) { + int i; + uint32_t addr, *psize; + + addr = stm->dev->fl_start; + psize = stm->dev->fl_ps; + + for (i = 0; i < page; i++) { + addr += psize[0]; + if (psize[1]) + psize++; + } + + return addr; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.cpp new file mode 100644 index 00000000..0fd611fc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.cpp @@ -0,0 +1,45 @@ +#include "serial_arduino.h" + + +static port_err_t arduino_serial_open(struct port_interface *port) { + port->dev->begin(port->ops->baudRate, port->ops->serial_mode); + return PORT_ERR_OK; +} + +static port_err_t arduino_close(struct port_interface *port) { + return PORT_ERR_OK; +} + +static port_err_t arduino_flush(struct port_interface *port) { + port->dev->flush(); + return PORT_ERR_OK; +} + +static port_err_t arduino_read(struct port_interface *port, void *buf, size_t nbyte) { + uint8_t *pos = (uint8_t *)buf; + while (nbyte) { + if (port->dev->available()) { + int c = port->dev->read(); + if (c < 0) { + return PORT_ERR_UNKNOWN; + } + pos[0] = (uint8_t)c; + nbyte--; + pos++; + } + } + return PORT_ERR_OK; +} + +static port_err_t arduino_write(struct port_interface *port, void *buf, size_t nbyte) { + port->dev->write((uint8_t *)buf, nbyte); + return PORT_ERR_OK; +} + +void assignCallbacks(struct port_interface *port) { + port->open = arduino_serial_open; + port->close = arduino_close; + port->flush = arduino_flush; + port->read = arduino_read; + port->write = arduino_write; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.h new file mode 100644 index 00000000..28f27c5b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.h @@ -0,0 +1,70 @@ +#ifndef _H_PORT +#define _H_PORT + +#include "Arduino.h" + +#define usleep(x) delayMicroseconds(x) + +#ifndef __MBED__ +#include "Uart.h" +#define UART Uart +#endif + +#define fprintf(output, ...) \ + { \ + do { \ + char string[100]; \ + sprintf(string, __VA_ARGS__); \ + Serial.print(string); \ + } while (0); \ + } + +/* flags */ +#define PORT_BYTE (1 << 0) /* byte (not frame) oriented */ +#define PORT_GVR_ETX (1 << 1) /* cmd GVR returns protection status */ +#define PORT_CMD_INIT (1 << 2) /* use INIT cmd to autodetect speed */ +#define PORT_RETRY (1 << 3) /* allowed read() retry after timeout */ +#define PORT_STRETCH_W (1 << 4) /* warning for no-stretching commands */ + +/* all options and flags used to open and configure an interface */ +struct port_options { + int baudRate; + int serial_mode; +}; + +/* + * Specify the length of reply for command GET + * This is helpful for frame-oriented protocols, e.g. i2c, to avoid time + * consuming try-fail-timeout-retry operation. + * On byte-oriented protocols, i.e. UART, this information would be skipped + * after read the first byte, so not needed. + */ +struct varlen_cmd { + uint8_t version; + uint8_t length; +}; + +typedef enum { + PORT_ERR_OK = 0, + PORT_ERR_NODEV, /* No such device */ + PORT_ERR_TIMEDOUT, /* Operation timed out */ + PORT_ERR_UNKNOWN, +} port_err_t; + +struct port_interface { + const char *name; + unsigned flags; + port_err_t (*open)(struct port_interface *port); + port_err_t (*close)(struct port_interface *port); + port_err_t (*flush)(struct port_interface *port); + port_err_t (*read)(struct port_interface *port, void *buf, size_t nbyte); + port_err_t (*write)(struct port_interface *port, void *buf, size_t nbyte); + struct varlen_cmd *cmd_get_reply = NULL; + UART *dev; + struct port_options *ops; +}; + +void assignCallbacks(struct port_interface *port); + + +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/stm32.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/stm32.h new file mode 100644 index 00000000..492cc405 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/stm32.h @@ -0,0 +1,90 @@ +/* + stm32flash - Open Source ST STM32 flash program for *nix + Copyright (C) 2010 Geoffrey McRae + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + + +#ifndef _STM32_H +#define _STM32_H + +#include + +#define STM32_MAX_RX_FRAME 256 /* cmd read memory */ +#define STM32_MAX_TX_FRAME (1 + 256 + 1) /* cmd write memory */ + +#define STM32_MAX_PAGES 0x0000ffff +#define STM32_MASS_ERASE 0x00100000 /* > 2 x max_pages */ + +typedef enum { + STM32_ERR_OK = 0, + STM32_ERR_UNKNOWN, /* Generic error */ + STM32_ERR_NACK, + STM32_ERR_NO_CMD, /* Command not available in bootloader */ +} stm32_err_t; + +typedef enum { + F_NO_ME = 1 << 0, /* Mass-Erase not supported */ + F_OBLL = 1 << 1, /* OBL_LAUNCH required */ +} flags_t; + +typedef struct stm32 stm32_t; +typedef struct stm32_cmd stm32_cmd_t; +typedef struct stm32_dev stm32_dev_t; + +struct stm32 { + struct port_interface *port; + uint8_t bl_version; + uint8_t version; + uint8_t option1, option2; + uint16_t pid; + stm32_cmd_t *cmd; + const stm32_dev_t *dev; +}; + +struct stm32_dev { + uint16_t id; + const char *name; + uint32_t ram_start, ram_end; + uint32_t fl_start, fl_end; + uint16_t fl_pps; // pages per sector + uint32_t *fl_ps; // page size + uint32_t opt_start, opt_end; + uint32_t mem_start, mem_end; + uint32_t flags; +}; + +stm32_t *stm32_init(struct port_interface *port, const char init); +void stm32_close(stm32_t *stm); +stm32_err_t stm32_read_memory(const stm32_t *stm, uint32_t address, + uint8_t data[], unsigned int len); +stm32_err_t stm32_write_memory(const stm32_t *stm, uint32_t address, + const uint8_t data[], unsigned int len); +stm32_err_t stm32_wunprot_memory(const stm32_t *stm); +stm32_err_t stm32_wprot_memory(const stm32_t *stm); +stm32_err_t stm32_erase_memory(const stm32_t *stm, uint32_t spage, + int32_t pages); +stm32_err_t stm32_go(const stm32_t *stm, uint32_t address); +stm32_err_t stm32_reset_device(const stm32_t *stm); +stm32_err_t stm32_readprot_memory(const stm32_t *stm); +stm32_err_t stm32_runprot_memory(const stm32_t *stm); +stm32_err_t stm32_crc_memory(const stm32_t *stm, uint32_t address, + uint32_t length, uint32_t *crc); +stm32_err_t stm32_crc_wrapper(const stm32_t *stm, uint32_t address, + uint32_t length, uint32_t *crc); +uint32_t stm32_sw_crc(uint32_t crc, uint8_t *buf, unsigned int len); + +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.c b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.c new file mode 100644 index 00000000..b0c77cce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.c @@ -0,0 +1,39 @@ +/* + stm32flash - Open Source ST STM32 flash program for *nix + Copyright (C) 2010 Geoffrey McRae + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include "utils.h" + +/* detect CPU endian */ +char cpu_le() { + const uint32_t cpu_le_test = 0x12345678; + return ((const unsigned char*)&cpu_le_test)[0] == 0x78; +} + +uint32_t be_u32(const uint32_t v) { + if (cpu_le()) + return ((v & 0xFF000000) >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | ((v & 0x000000FF) << 24); + return v; +} + +uint32_t le_u32(const uint32_t v) { + if (!cpu_le()) + return ((v & 0xFF000000) >> 24) | ((v & 0x00FF0000) >> 8) | ((v & 0x0000FF00) << 8) | ((v & 0x000000FF) << 24); + return v; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.h new file mode 100644 index 00000000..6825e453 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.h @@ -0,0 +1,33 @@ +/* + stm32flash - Open Source ST STM32 flash program for *nix + Copyright (C) 2010 Geoffrey McRae + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + + +#ifndef _H_UTILS +#define _H_UTILS + +#include +#include + +char cpu_le(); +uint32_t be_u32(const uint32_t v); +uint32_t le_u32(const uint32_t v); + +void printStatus(FILE *fd, int condition); + +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/COPYING b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/COPYING new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/COPYING.LESSER b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/COPYING.LESSER new file mode 100644 index 00000000..0a041280 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/README.md new file mode 100644 index 00000000..d9294d67 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/README.md @@ -0,0 +1,36 @@ +# MKRWAN_v2 + +[![Check Arduino status](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/spell-check.yml) + +Provides APIs to communicate with LoRa and LoraWAN networks + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/MKRWAN + +If you are looking for the firmware running on Murata CMWX1ZZABZ-078 module, the complete source code is hosted at https://github.com/arduino/mkrwan1300-fw + +This version of the library tracks https://github.com/arduino/mkrwan1300-fw/tree/master-1.3.1 , which is based on almost clean ST sources. + +The firmware update sketch should be flashed accordingly to the MKRWAN_v2 library version in use. + +## License + +Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) + +Based on the TinyGSM library https://github.com/vshymanskyy/TinyGSM +Copyright (c) 2016 Volodymyr Shymanskyy + +MKRWAN_v2 library is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MKRWAN_v2 library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with MKRWAN_v2 library. If not, see . diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/FWUpdaterBridge/FWUpdaterBridge.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/FWUpdaterBridge/FWUpdaterBridge.ino new file mode 100644 index 00000000..ed3df1d5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/FWUpdaterBridge/FWUpdaterBridge.ino @@ -0,0 +1,64 @@ +/* + FW Updater Bridge + This sketch demonstrates how to update the FW on the MKR WAN 1300/1310 LoRa module. + Once flashed it should be used in conjunction with stm32flash utility (https://github.com/facchinm/stm32flash) + + This example code is in the public domain. +*/ + +#define Serial1 Serial + +void setup() { + Serial1.begin(115200, SERIAL_8E1); + Serial2.begin(115200, SERIAL_8E1); + + delay(1000); + + pinMode(LED_BUILTIN, OUTPUT); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(200); + digitalWrite(LORA_RESET, LOW); + delay(200); + digitalWrite(LORA_RESET, HIGH); +} + +void resetModule() { + Serial.println("resetting module"); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + + while (!Serial) + ; +} + +char rx_buf[512]; +char tx_buf[512]; + +int rx = 0; +int tx = 0; + +void loop() { + while (Serial1.available()) { // If anything comes in Serial (USB), + tx_buf[tx++] = Serial1.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (tx > 0) { + Serial2.write(tx_buf, tx); + tx = 0; + } + + while (Serial2.available()) { // If anything comes in Serial (USB), + rx_buf[rx++] = Serial2.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (rx > 0) { + Serial1.write(rx_buf, rx); + rx = 0; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/FirstConfiguration/FirstConfiguration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/FirstConfiguration/FirstConfiguration.ino new file mode 100644 index 00000000..6ecbbdba --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/FirstConfiguration/FirstConfiguration.ino @@ -0,0 +1,109 @@ +/* + First Configuration + This sketch demonstrates the usage of MKR WAN 1300/1310 LoRa module. + This example code is in the public domain. +*/ + +#include + +LoRaModem modem; + +// Uncomment if using the Murata chip as a module +// LoRaModem modem(Serial1); + +String appEui; +String appKey; +String devAddr; +String nwkSKey; +String appSKey; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial) + ; + Serial.println("Welcome to MKR WAN 1300/1310 first configuration sketch"); + Serial.println("Register to your favourite LoRa network and we are ready to go!"); + // change this to your regional band (eg. US915, AS923, ...) + if (!modem.begin(EU868)) { + Serial.println("Failed to start module"); + while (1) {} + }; + Serial.print("Your module version is: "); + Serial.println(modem.version()); + Serial.print("Your device EUI is: "); + Serial.println(modem.deviceEUI()); + + int mode = 0; + while (mode != 1 && mode != 2) { + Serial.println("Are you connecting via OTAA (1) or ABP (2)?"); + while (!Serial.available()) + ; + mode = Serial.readStringUntil('\n').toInt(); + } + + int connected; + if (mode == 1) { + Serial.println("Enter your APP EUI"); + while (!Serial.available()) + ; + appEui = Serial.readStringUntil('\n'); + + Serial.println("Enter your APP KEY"); + while (!Serial.available()) + ; + appKey = Serial.readStringUntil('\n'); + + appKey.trim(); + appEui.trim(); + + connected = modem.joinOTAA(appEui, appKey); + } else if (mode == 2) { + + Serial.println("Enter your Device Address"); + while (!Serial.available()) + ; + devAddr = Serial.readStringUntil('\n'); + + Serial.println("Enter your NWS KEY"); + while (!Serial.available()) + ; + nwkSKey = Serial.readStringUntil('\n'); + + Serial.println("Enter your APP SKEY"); + while (!Serial.available()) + ; + appSKey = Serial.readStringUntil('\n'); + + devAddr.trim(); + nwkSKey.trim(); + appSKey.trim(); + + connected = modem.joinABP(devAddr, nwkSKey, appSKey); + } + + if (!connected) { + Serial.println("Something went wrong; are you indoor? Move near a window and retry"); + while (1) {} + } + + delay(5000); + + int err; + modem.setPort(3); + modem.beginPacket(); + modem.print("HeLoRA world!"); + err = modem.endPacket(true); + if (err > 0) { + Serial.println("Message sent correctly!"); + } else { + Serial.println("Error sending message :("); + } +} + +void loop() { + while (modem.available()) { + Serial.write(modem.read()); + } + modem.poll(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/LoraSendAndReceive.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/LoraSendAndReceive.ino new file mode 100644 index 00000000..9532cfbd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/LoraSendAndReceive.ino @@ -0,0 +1,93 @@ +/* + Lora Send And Receive + This sketch demonstrates how to send and receive data with the MKR WAN 1300/1310 LoRa module. + This example code is in the public domain. +*/ + +#include + +LoRaModem modem; + +// Uncomment if using the Murata chip as a module +// LoRaModem modem(Serial1); + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +String appEui = SECRET_APP_EUI; +String appKey = SECRET_APP_KEY; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial) + ; + // change this to your regional band (eg. US915, AS923, ...) + if (!modem.begin(EU868)) { + Serial.println("Failed to start module"); + while (1) {} + }; + Serial.print("Your module version is: "); + Serial.println(modem.version()); + Serial.print("Your device EUI is: "); + Serial.println(modem.deviceEUI()); + + int connected = modem.joinOTAA(appEui, appKey); + if (!connected) { + Serial.println("Something went wrong; are you indoor? Move near a window and retry"); + while (1) {} + } + + // Set poll interval to 60 secs. + modem.minPollInterval(60); + // NOTE: independently by this setting the modem will + // not allow to send more than one message every 2 minutes, + // this is enforced by firmware and can not be changed. +} + +void loop() { + Serial.println(); + Serial.println("Enter a message to send to network"); + Serial.println("(make sure that end-of-line 'NL' is enabled)"); + + while (!Serial.available()) + ; + String msg = Serial.readStringUntil('\n'); + + Serial.println(); + Serial.print("Sending: " + msg + " - "); + for (unsigned int i = 0; i < msg.length(); i++) { + Serial.print(msg[i] >> 4, HEX); + Serial.print(msg[i] & 0xF, HEX); + Serial.print(" "); + } + Serial.println(); + + int err; + modem.beginPacket(); + modem.print(msg); + err = modem.endPacket(true); + if (err > 0) { + Serial.println("Message sent correctly!"); + } else { + Serial.println("Error sending message :("); + Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength"); + Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)"); + } + delay(1000); + if (!modem.available()) { + Serial.println("No downlink message received at this time."); + return; + } + char rcv[64]; + int i = 0; + while (modem.available()) { + rcv[i++] = (char)modem.read(); + } + Serial.print("Received: "); + for (unsigned int j = 0; j < i; j++) { + Serial.print(rcv[j] >> 4, HEX); + Serial.print(rcv[j] & 0xF, HEX); + Serial.print(" "); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/arduino_secrets.h new file mode 100644 index 00000000..3abaf3f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/arduino_secrets.h @@ -0,0 +1,3 @@ +// Replace with keys obtained from TheThingsNetwork console +#define SECRET_APP_EUI "xxxxxxxxxxxxx" +#define SECRET_APP_KEY "yyyyyyyyyyyyyyyyyyyyyyy" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino new file mode 100644 index 00000000..12fcdf68 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MKRWAN_v2/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino @@ -0,0 +1,368 @@ +/* + * STANDALONE FIRMWARE UPDATE FOR MKR WAN 1300/1310 + * This sketch implements STM32 bootloader protocol + * It is based on stm32flash (mirrored here git@github.com:facchinm/stm32flash.git) + * with as little modifications as possible. + * + * To generate it after a firmware update, execute + * + * echo -n "const " > fw.h && xxd -i mlm32l07x01.bin >> fw.h + * + */ + + +#include "fw.h" +#include "stm32.h" +#include "serial_arduino.h" +#include + +/* device globals */ +stm32_t *stm = NULL; +void *p_st = NULL; + +int ret = -1; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + + while (!Serial) + ; + + struct port_interface port; + struct port_options port_opts = { + .baudRate = 115200, + .serial_mode = SERIAL_8E1 + }; + + port.flags = PORT_CMD_INIT | PORT_GVR_ETX | PORT_BYTE | PORT_RETRY; + port.dev = &SerialLoRa; + port.ops = &port_opts; + + assignCallbacks(&port); + + pinMode(LED_BUILTIN, OUTPUT); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(200); + digitalWrite(LORA_RESET, LOW); + delay(200); + digitalWrite(LORA_RESET, HIGH); + delay(200); + + Serial.println("Press a key to start FW update"); + port.open(&port); + //port.flush(&port); + + stm = stm32_init(&port, 1); + + fprintf(diag, "Version : 0x%02x\n", stm->bl_version); + if (port.flags & PORT_GVR_ETX) { + fprintf(diag, "Option 1 : 0x%02x\n", stm->option1); + fprintf(diag, "Option 2 : 0x%02x\n", stm->option2); + } + fprintf(diag, "Device ID : 0x%04x (%s)\n", stm->pid, stm->dev->name); + fprintf(diag, "- RAM : Up to %dKiB (%db reserved by bootloader)\n", (stm->dev->ram_end - 0x20000000) / 1024, stm->dev->ram_start - 0x20000000); + fprintf(diag, "- Flash : Up to %dKiB (size first sector: %dx%d)\n", (stm->dev->fl_end - stm->dev->fl_start) / 1024, stm->dev->fl_pps, stm->dev->fl_ps[0]); + fprintf(diag, "- Option RAM : %db\n", stm->dev->opt_end - stm->dev->opt_start + 1); + fprintf(diag, "- System RAM : %dKiB\n", (stm->dev->mem_end - stm->dev->mem_start) / 1024); + + uint8_t buffer[256]; + uint32_t addr, start, end; + unsigned int len; + int failed = 0; + int first_page, num_pages; + + int npages = mlm32l07x01_bin_len / 128 + 1; + int spage = 0; + bool verify = 1; + int retry = 10; + bool reset_flag = 0; + bool exec_flag = 1; + int execute = 0; // address + + /* + Cleanup addresses: + + Starting from options + start_addr, readwrite_len, spage, npages + and using device memory size, compute + start, end, first_page, num_pages + */ + if (!npages) { + start = stm->dev->fl_start; + end = stm->dev->fl_end; + first_page = 0; + num_pages = STM32_MASS_ERASE; + } else { + first_page = spage; + start = flash_page_to_addr(first_page); + if (start > stm->dev->fl_end) { + fprintf(stderr, "Address range exceeds flash size.\n"); + ret = -1; + return; + } + + if (npages) { + num_pages = npages; + end = flash_page_to_addr(first_page + num_pages); + if (end > stm->dev->fl_end) + end = stm->dev->fl_end; + } else { + end = stm->dev->fl_end; + num_pages = flash_addr_to_page_ceil(end) - first_page; + } + + if (!first_page && end == stm->dev->fl_end) + num_pages = STM32_MASS_ERASE; + } + + ret = 0; + int s_err; + +#if 0 + fprintf(diag, "Erasing flash\n"); + + if (num_pages != STM32_MASS_ERASE && + (start != flash_page_to_addr(first_page) + || end != flash_page_to_addr(first_page + num_pages))) { + fprintf(stderr, "Specified start & length are invalid (must be page aligned)\n"); + ret = 1; + return; + } + + s_err = stm32_erase_memory(stm, first_page, num_pages); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to erase memory\n"); + ret = 1; + return; + } + ret = 0; + +#endif + + fprintf(diag, "Write to memory\n"); + + off_t offset = 0; + ssize_t r; + unsigned int size; + unsigned int max_wlen, max_rlen; + +#define STM32_MAX_RX_FRAME 256 /* cmd read memory */ +#define STM32_MAX_TX_FRAME (1 + 256 + 1) /* cmd write memory */ + + max_wlen = STM32_MAX_TX_FRAME - 2; /* skip len and crc */ + max_wlen &= ~3; /* 32 bit aligned */ + + max_rlen = STM32_MAX_RX_FRAME; + max_rlen = max_rlen < max_wlen ? max_rlen : max_wlen; + + /* Assume data from stdin is whole device */ + size = end - start; + + // TODO: It is possible to write to non-page boundaries, by reading out flash + // from partial pages and combining with the input data + // if ((start % stm->dev->fl_ps[i]) != 0 || (end % stm->dev->fl_ps[i]) != 0) { + // fprintf(stderr, "Specified start & length are invalid (must be page aligned)\n"); + // goto close; + // } + + // TODO: If writes are not page aligned, we should probably read out existing flash + // contents first, so it can be preserved and combined with new data + if (num_pages) { + fprintf(diag, "Erasing memory\n"); + s_err = stm32_erase_memory(stm, first_page, num_pages); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to erase memory\n"); + ret = -1; + return; + } + } + + addr = start; + while (addr < end && offset < size) { + uint32_t left = end - addr; + len = max_wlen > left ? left : max_wlen; + len = len > size - offset ? size - offset : len; + + memcpy(buffer, &mlm32l07x01_bin[offset], len); + + if (len == 0) { + fprintf(stderr, "Failed to read input file\n"); + ret = -1; + return; + } + +again: + s_err = stm32_write_memory(stm, addr, buffer, len); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to write memory at address 0x%08x\n", addr); + ret = -1; + return; + } + + if (verify) { + uint8_t compare[len]; + unsigned int offset, rlen; + + offset = 0; + while (offset < len) { + rlen = len - offset; + rlen = rlen < max_rlen ? rlen : max_rlen; + s_err = stm32_read_memory(stm, addr + offset, compare + offset, rlen); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to read memory at address 0x%08x\n", addr + offset); + ret = -1; + return; + } + offset += rlen; + } + + for (r = 0; r < len; ++r) + if (buffer[r] != compare[r]) { + if (failed == retry) { + fprintf(stderr, "Failed to verify at address 0x%08x, expected 0x%02x and found 0x%02x\n", + (uint32_t)(addr + r), + buffer[r], + compare[r]); + ret = -1; + return; + } + ++failed; + goto again; + } + + failed = 0; + } + + addr += len; + offset += len; + + fprintf(diag, + "Wrote %saddress 0x%08x (%d%%)\n ", + verify ? "and verified " : "", + addr, + 100 * offset / size); + } + + fprintf(diag, "Done.\n"); + ret = 0; + + if (stm && exec_flag && ret == 0) { + if (execute == 0) + execute = stm->dev->fl_start; + + fprintf(diag, "\nStarting execution at address 0x%08x... ", execute); + if (stm32_go(stm, execute) == STM32_ERR_OK) { + reset_flag = 0; + fprintf(diag, "done.\n"); + } else + fprintf(diag, "failed.\n"); + } +} + +void resetModuleRunning() { + digitalWrite(LORA_BOOT0, LOW); + SerialLoRa.end(); + SerialLoRa.begin(19200); + delay(100); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + delay(100); +} + +void loop() { + // put your main code here, to run repeatedly: + if (ret == 0) { + Serial.println("Flashing ok :)"); + SerialLoRa.end(); + LoRaModem *modem = new LoRaModem(); + modem->begin(EU868); + Serial.println(modem->version()); + } + while (1) + ; +} + +static int is_addr_in_ram(uint32_t addr) { + return addr >= stm->dev->ram_start && addr < stm->dev->ram_end; +} + +static int is_addr_in_flash(uint32_t addr) { + return addr >= stm->dev->fl_start && addr < stm->dev->fl_end; +} + +static int is_addr_in_opt_bytes(uint32_t addr) { + /* option bytes upper range is inclusive in our device table */ + return addr >= stm->dev->opt_start && addr <= stm->dev->opt_end; +} + +static int is_addr_in_sysmem(uint32_t addr) { + return addr >= stm->dev->mem_start && addr < stm->dev->mem_end; +} + +/* returns the page that contains address "addr" */ +static int flash_addr_to_page_floor(uint32_t addr) { + int page; + uint32_t *psize; + + if (!is_addr_in_flash(addr)) + return 0; + + page = 0; + addr -= stm->dev->fl_start; + psize = stm->dev->fl_ps; + + while (addr >= psize[0]) { + addr -= psize[0]; + page++; + if (psize[1]) + psize++; + } + + return page; +} + +/* returns the first page whose start addr is >= "addr" */ +int flash_addr_to_page_ceil(uint32_t addr) { + int page; + uint32_t *psize; + + if (!(addr >= stm->dev->fl_start && addr <= stm->dev->fl_end)) + return 0; + + page = 0; + addr -= stm->dev->fl_start; + psize = stm->dev->fl_ps; + + while (addr >= psize[0]) { + addr -= psize[0]; + page++; + if (psize[1]) + psize++; + } + + return addr ? page + 1 : page; +} + +/* returns the lower address of flash page "page" */ +static uint32_t flash_page_to_addr(int page) { + int i; + uint32_t addr, *psize; + + addr = stm->dev->fl_start; + psize = stm->dev->fl_ps; + + for (i = 0; i < page; i++) { + addr += psize[0]; + if (psize[1]) + psize++; + } + + return addr; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MadgwickAHRS/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MadgwickAHRS/README.adoc new file mode 100644 index 00000000..774aff4c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MadgwickAHRS/README.adoc @@ -0,0 +1,37 @@ +:repository-owner: arduino-libraries +:repository-name: MadgwickAHRS + += Madgwick Library = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library wraps the official implementation of MadgwickAHRS algorithm to get orientation of an object based on accelerometer and gyroscope readings + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Implementation of Madgwick's IMU and AHRS algorithms. +See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms + +Date Author Notes +29/09/2011 SOH Madgwick Initial release +02/10/2011 SOH Madgwick Optimised for reduced CPU load +19/02/2012 SOH Madgwick Magnetometer measurement is normalised diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MadgwickAHRS/examples/Visualize101/Visualize101.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MadgwickAHRS/examples/Visualize101/Visualize101.ino new file mode 100644 index 00000000..69aa9b10 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/MadgwickAHRS/examples/Visualize101/Visualize101.ino @@ -0,0 +1,85 @@ +#include +#include + +Madgwick filter; +unsigned long microsPerReading, microsPrevious; +float accelScale, gyroScale; + +void setup() { + Serial.begin(9600); + + // start the IMU and filter + CurieIMU.begin(); + CurieIMU.setGyroRate(25); + CurieIMU.setAccelerometerRate(25); + filter.begin(25); + + // Set the accelerometer range to 2 g + CurieIMU.setAccelerometerRange(2); + // Set the gyroscope range to 250 degrees/second + CurieIMU.setGyroRange(250); + + // initialize variables to pace updates to correct rate + microsPerReading = 1000000 / 25; + microsPrevious = micros(); +} + +void loop() { + int aix, aiy, aiz; + int gix, giy, giz; + float ax, ay, az; + float gx, gy, gz; + float roll, pitch, heading; + unsigned long microsNow; + + // check if it's time to read data and update the filter + microsNow = micros(); + if (microsNow - microsPrevious >= microsPerReading) { + + // read raw data from CurieIMU + CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz); + + // convert from raw data to gravity and degrees/second units + ax = convertRawAcceleration(aix); + ay = convertRawAcceleration(aiy); + az = convertRawAcceleration(aiz); + gx = convertRawGyro(gix); + gy = convertRawGyro(giy); + gz = convertRawGyro(giz); + + // update the filter, which computes orientation + filter.updateIMU(gx, gy, gz, ax, ay, az); + + // print the heading, pitch and roll + roll = filter.getRoll(); + pitch = filter.getPitch(); + heading = filter.getYaw(); + Serial.print("Orientation: "); + Serial.print(heading); + Serial.print(" "); + Serial.print(pitch); + Serial.print(" "); + Serial.println(roll); + + // increment previous time, so we keep proper pace + microsPrevious = microsPrevious + microsPerReading; + } +} + +float convertRawAcceleration(int aRaw) { + // since we are using 2 g range + // -2 g maps to a raw value of -32768 + // +2 g maps to a raw value of 32767 + + float a = (aRaw * 2.0) / 32768.0; + return a; +} + +float convertRawGyro(int gRaw) { + // since we are using 250 degrees/seconds range + // -250 maps to a raw value of -32768 + // +250 maps to a raw value of 32767 + + float g = (gRaw * 250.0) / 32768.0; + return g; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/README.md new file mode 100644 index 00000000..f83882ce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/README.md @@ -0,0 +1,52 @@ +# NTPClient + +[![Check Arduino status](https://github.com/arduino-libraries/NTPClient/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/NTPClient/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/NTPClient/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/spell-check.yml) + +Connect to a NTP server, here is how: + +```cpp +#include +// change next line to use with another board/shield +#include +//#include // for WiFi shield +//#include // for WiFi 101 shield or MKR1000 +#include + +const char *ssid = ""; +const char *password = ""; + +WiFiUDP ntpUDP; + +// By default 'pool.ntp.org' is used with 60 seconds update interval and +// no offset +NTPClient timeClient(ntpUDP); + +// You can specify the time server pool and the offset, (in seconds) +// additionally you can specify the update interval (in milliseconds). +// NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); + +void setup(){ + Serial.begin(115200); + WiFi.begin(ssid, password); + + while ( WiFi.status() != WL_CONNECTED ) { + delay ( 500 ); + Serial.print ( "." ); + } + + timeClient.begin(); +} + +void loop() { + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + + delay(1000); +} +``` + +## Function documentation +`getEpochTime` returns the Unix epoch, which are the seconds elapsed since 00:00:00 UTC on 1 January 1970 (leap seconds are ignored, every day is treated as having 86400 seconds). **Attention**: If you have set a time offset this time offset will be added to your epoch timestamp. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/Advanced/Advanced.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/Advanced/Advanced.ino new file mode 100644 index 00000000..bc1182b4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/Advanced/Advanced.ino @@ -0,0 +1,37 @@ +#include +// change next line to use with another board/shield +#include +//#include // for WiFi shield +//#include // for WiFi 101 shield or MKR1000 +#include + +const char *ssid = ""; +const char *password = ""; + +WiFiUDP ntpUDP; + +// You can specify the time server pool and the offset (in seconds, can be +// changed later with setTimeOffset() ). Additionally you can specify the +// update interval (in milliseconds, can be changed using setUpdateInterval() ). +NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + timeClient.begin(); +} + +void loop() { + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/Basic/Basic.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/Basic/Basic.ino new file mode 100644 index 00000000..c0c129b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/Basic/Basic.ino @@ -0,0 +1,33 @@ +#include +// change next line to use with another board/shield +#include +//#include // for WiFi shield +//#include // for WiFi 101 shield or MKR1000 +#include + +const char *ssid = ""; +const char *password = ""; + +WiFiUDP ntpUDP; +NTPClient timeClient(ntpUDP); + +void setup() { + Serial.begin(115200); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + timeClient.begin(); +} + +void loop() { + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/IsTimeSet/IsTimeSet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/IsTimeSet/IsTimeSet.ino new file mode 100644 index 00000000..1d50db99 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/NTPClient/examples/IsTimeSet/IsTimeSet.ino @@ -0,0 +1,53 @@ +#include +// change next line to use with another board/shield +#include +//#include // for WiFi shield +//#include // for WiFi 101 shield or MKR1000 +#include + +const char *ssid = ""; +const char *password = ""; + +WiFiUDP ntpUDP; +// initialized to a time offset of 10 hours +NTPClient timeClient(ntpUDP, "pool.ntp.org", 36000, 60000); +// HH:MM:SS +// timeClient initializes to 10:00:00 if it does not receive an NTP packet +// before the 100ms timeout. +// without isTimeSet() the LED would be switched on, although the time +// was not yet set correctly. + +// blue LED on ESP-12F +const int led = 2; +const int hour = 10; +const int minute = 0; + +void setup() { + Serial.begin(115200); + + pinMode(led, OUTPUT); + // led is off when pin is high + digitalWrite(led, 1); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + timeClient.begin(); +} + +void loop() { + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + if (timeClient.isTimeSet()) { + if (hour == timeClient.getHours() && minute == timeClient.getMinutes()) { + digitalWrite(led, 0); + } + } + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/README.adoc new file mode 100644 index 00000000..e33e6b94 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: RTCZero + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The RTCZero library enables an Arduino Zero or MKR1000 board to take control of the internal RTC. + +For more information about this library please visit us at +http://arduino.cc/en/Reference/RTC diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/Epoch/Epoch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/Epoch/Epoch.ino new file mode 100644 index 00000000..b66e0568 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/Epoch/Epoch.ino @@ -0,0 +1,59 @@ +/* + Epoch time example for Arduino Zero and MKR1000 + + Demonstrates how to set time using epoch for the Arduino Zero and MKR1000 + + This example code is in the public domain + + created by Sandeep Mistry + 31 Dec 2015 + modified + 18 Feb 2016 +*/ + +#include + +/* Create an RTCZero object */ +RTCZero rtc; + +void setup() { + Serial.begin(9600); + + rtc.begin(); // initialize RTC + + rtc.setEpoch(1451606400); // Jan 1, 2016 +} + +void loop() { + Serial.print("Unix time = "); + Serial.println(rtc.getEpoch()); + + Serial.print("Seconds since Jan 1 2000 = "); + Serial.println(rtc.getY2kEpoch()); + + // Print date... + Serial.print(rtc.getDay()); + Serial.print("/"); + Serial.print(rtc.getMonth()); + Serial.print("/"); + Serial.print(rtc.getYear()); + Serial.print("\t"); + + // ...and time + print2digits(rtc.getHours()); + Serial.print(":"); + print2digits(rtc.getMinutes()); + Serial.print(":"); + print2digits(rtc.getSeconds()); + + Serial.println(); + + delay(1000); +} + +void print2digits(int number) { + if (number < 10) { + Serial.print("0"); + } + Serial.print(number); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SimpleRTC/SimpleRTC.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SimpleRTC/SimpleRTC.ino new file mode 100644 index 00000000..7d5a3b14 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SimpleRTC/SimpleRTC.ino @@ -0,0 +1,81 @@ +/* + Simple RTC for Arduino Zero and MKR1000 + + Demonstrates the use of the RTC library for the Arduino Zero and MKR1000 + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SimpleRTC + + created by Arturo Guadalupi + 15 Jun 2015 + modified + 18 Feb 2016 + modified by Andrea Richetta + 24 Aug 2016 +*/ + +#include + +/* Create an RTCZero object */ +RTCZero rtc; + +/* Change these values to set the current initial time */ +const byte seconds = 0; +const byte minutes = 0; +const byte hours = 16; + +/* Change these values to set the current initial date */ +const byte day = 15; +const byte month = 6; +const byte year = 15; + +void setup() { + Serial.begin(9600); + + rtc.begin(); // initialize RTC + + // Set the time + rtc.setHours(hours); + rtc.setMinutes(minutes); + rtc.setSeconds(seconds); + + // Set the date + rtc.setDay(day); + rtc.setMonth(month); + rtc.setYear(year); + + // you can use also + //rtc.setTime(hours, minutes, seconds); + //rtc.setDate(day, month, year); +} + +void loop() { + // Print date... + print2digits(rtc.getDay()); + Serial.print("/"); + print2digits(rtc.getMonth()); + Serial.print("/"); + print2digits(rtc.getYear()); + Serial.print(" "); + + // ...and time + print2digits(rtc.getHours()); + Serial.print(":"); + print2digits(rtc.getMinutes()); + Serial.print(":"); + print2digits(rtc.getSeconds()); + + Serial.println(); + + delay(1000); +} + + + +void print2digits(int number) { + if (number < 10) { + Serial.print("0"); // print a 0 before if the number is < than 10 + } + Serial.print(number); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SimpleRTCAlarm/SimpleRTCAlarm.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SimpleRTCAlarm/SimpleRTCAlarm.ino new file mode 100644 index 00000000..a093128f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SimpleRTCAlarm/SimpleRTCAlarm.ino @@ -0,0 +1,51 @@ +/* + Simple RTC Alarm for Arduino Zero and MKR1000 + + Demonstrates how to set an RTC alarm for the Arduino Zero and MKR1000 + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SimpleRTCAlarm + + created by Arturo Guadalupi + 25 Sept 2015 + + modified + 21 Oct 2015 +*/ + +#include + +/* Create an RTCZero object */ +RTCZero rtc; + +/* Change these values to set the current initial time */ +const byte seconds = 0; +const byte minutes = 0; +const byte hours = 16; + +/* Change these values to set the current initial date */ +const byte day = 25; +const byte month = 9; +const byte year = 15; + +void setup() { + Serial.begin(9600); + + rtc.begin(); // initialize RTC 24H format + + rtc.setTime(hours, minutes, seconds); + rtc.setDate(day, month, year); + + rtc.setAlarmTime(16, 0, 10); + rtc.enableAlarm(rtc.MATCH_HHMMSS); + + rtc.attachInterrupt(alarmMatch); +} + +void loop() { +} + +void alarmMatch() { + Serial.println("Alarm Match!"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SleepRTCAlarm/SleepRTCAlarm.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SleepRTCAlarm/SleepRTCAlarm.ino new file mode 100644 index 00000000..8c477fa5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RTCZero/examples/SleepRTCAlarm/SleepRTCAlarm.ino @@ -0,0 +1,59 @@ +/* + Sleep RTC Alarm for Arduino Zero + + Demonstrates the use of an alarm to wake up an Arduino Zero from Standby mode + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SleepRTCAlarm + + created by Arturo Guadalupi + 17 Nov 2015 + modified + 01 Mar 2016 + + NOTE: + If you use this sketch with a MKR1000 you will see no output on the serial monitor. + This happens because the USB clock is stopped so the USB connection is stopped too. + **To see again the USB port you have to double tap on the reset button!** +*/ + +#include + +/* Create an RTCZero object */ +RTCZero rtc; + +/* Change these values to set the current initial time */ +const byte seconds = 0; +const byte minutes = 00; +const byte hours = 17; + +/* Change these values to set the current initial date */ +const byte day = 17; +const byte month = 11; +const byte year = 15; + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + + rtc.begin(); + + rtc.setTime(hours, minutes, seconds); + rtc.setDate(day, month, year); + + rtc.setAlarmTime(17, 00, 10); + rtc.enableAlarm(rtc.MATCH_HHMMSS); + + rtc.attachInterrupt(alarmMatch); + + rtc.standbyMode(); +} + +void loop() { + rtc.standbyMode(); // Sleep until next alarm match +} + +void alarmMatch() { + digitalWrite(LED_BUILTIN, HIGH); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/LICENSE.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/LICENSE.md new file mode 100644 index 00000000..39465391 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/LICENSE.md @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) [year] [fullname] + +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/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/README.md new file mode 100644 index 00000000..e55e315e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/README.md @@ -0,0 +1,154 @@ +# Warning + +Documentation needs to be updated because of massive changes in API + +I have changed the original code to allow the library to be used with any network connection + +# RestClient for Arduino + +HTTP Request library for Arduino derived from https://github.com/csquared/arduino-restclient + +# Usage + +### Include + + + +```c++ +#include +#include +#include "RestClient.h" +``` + +### RestClient(host/ip, [port]) + +Constructor to create an RestClient object to make requests against. + +Use domain name and default to port 80: +```c++ +RestClient client = RestClient("arduino-http-lib-test.herokuapp.com"); +``` + +Use a local IP and an explicit port: +```c++ +RestClient client = RestClient("192.168.1.50",5000); +``` + +### dhcp() + +Sets up `EthernetClient` with a mac address of `DEADBEEFFEED` + +```c++ + client.dhcp() +``` + +Note: you can have multiple RestClient objects but only need to call +this once. + +Note: if you have multiple Arduinos on the same network, you'll need +to give each one a different mac address. + +### begin(byte mac[]) + +It just wraps the `EthernetClient` call to `begin` and DHCPs. +Use this if you need to explicitly set the mac address. + +```c++ + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + if (client.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + } +``` + +### Manual Ethernet Setup + +You can skip the above methods and just configure the EthernetClient yourself: + +```c++ + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + //the IP address for the shield: + byte ip[] = { 192, 168, 2, 11 }; + Ethernet.begin(mac,ip); +``` + +```c++ + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + Ethernet.begin(mac); +``` + +This is especially useful for debugging network connection issues. + +## RESTful methods + +All methods return an HTTP status code or 0 if there was an error. + +### `get(const char* path)` +### `get(const char* path, String* response)` + +Start making requests! + +```c++ +int statusCode = client.get("/")); +``` + +Pass in a string *by reference* for the response: +``` +String response = ""; +int statusCode = client.get("/", &response); +``` + +### post(const char* path, const char* body) +### post(const char* path, String* response) +### post(const char* path, const char* body, String* response) + +``` +String response = ""; +int statusCode = client.post("/", &response); +statusCode = client.post("/", "foo=bar"); +response = ""; +statusCode = client.post("/", "foo=bar", &response); +``` + +### put(const char* path, const char* body) +### put(const char* path, String* response) +### put(const char* path, const char* body, String* response) + +``` +String response = ""; +int statusCode = client.put("/", &response); +statusCode = client.put("/", "foo=bar"); +response = ""; +statusCode = client.put("/", "foo=bar", &response); +``` + +### del(const char* path) +### del(const char* path, const char* body) +### del(const char* path, String* response) +### del(const char* path, const char* body, String* response) + +``` +String response = ""; +int statusCode = client.del("/", &response); +``` + +## Full Example + +I test every way of calling the library (against a public heroku app)[https://github.com/csquared/arduino-http-test]. + +You can find the file in File->Examples->RestClient->full_test_suite + +## Debug Mode + +If you're having trouble, you can always open `RestClient.cpp` and throw at the top: + +```c++ +#define HTTP_DEBUG +``` + +Everything happening in the client will get printed to the Serial port. + +# Thanks + +[ricardochimal](https://github.com/ricardochimal) For all his c++ help. Couldn't have done this without you! + +[theycallmeswift](https://github.com/theycallmeswift) Helping incept and debug v1.0 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetGet/DweetGet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetGet/DweetGet.ino new file mode 100644 index 00000000..587d960f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetGet/DweetGet.ino @@ -0,0 +1,107 @@ +/* + Dweet.io GET client for RestClient library + Connects to dweet.io once every ten seconds, + sends a GET request and a request body. Uses SSL + + Shows how to use Strings to assemble path and parse content + from response. dweet.io expects: + https://dweet.io/get/latest/dweet/for/thingName + + For more on dweet.io, see https://dweet.io/play/ + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 15 Feb 2016 + updated 16 Feb 2016 + by Tom Igoe + + this example is in the public domain +*/ +#include +#include +#include "config.h" + +char serverAddress[] = "dweet.io"; // server address +int port = 80; +String dweetName = "scandalous-cheese-hoarder"; // use your own thing name here + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + // assemble the path for the POST message: + String path = "/get/latest/dweet/for/" + dweetName; + + // assemble the body of the POST message: + int sensorValue = analogRead(A0); + + Serial.println("making GET request"); + client.setContentType("application/json"); + statusCode = client.get(path); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + /* + Typical response is: + {"this":"succeeded", + "by":"getting", + "the":"dweets", + "with":[{"thing":"my-thing-name", + "created":"2016-02-16T05:10:36.589Z", + "content":{"sensorValue":456}}]} + + You want "content": numberValue + */ + // now parse the response looking for "content": + int labelStart = response.indexOf("content\":"); + // find the first { after "content": + int contentStart = response.indexOf("{", labelStart); + // find the following } and get what's between the braces: + int contentEnd = response.indexOf("}", labelStart); + String content = response.substring(contentStart + 1, contentEnd); + Serial.println(content); + + // now get the value after the colon, and convert to an int: + int valueStart = content.indexOf(":"); + String valueString = content.substring(valueStart + 1); + int number = valueString.toInt(); + Serial.print("Value string: "); + Serial.println(valueString); + Serial.print("Actual value: "); + Serial.println(number); + + Serial.println("Wait ten seconds\n"); + delay(10000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetPost/DweetPost.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetPost/DweetPost.ino new file mode 100644 index 00000000..e61b124c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetPost/DweetPost.ino @@ -0,0 +1,76 @@ +/* + Dweet.io POST client for RestClient library + Connects to dweet.io once every ten seconds, + sends a POST request and a request body. Uses SSL + + Shows how to use Strings to assemble path and body + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 15 Feb 2016 + by Tom Igoe + + this example is in the public domain +*/ +#include +#include +#include "config.h" + +char serverAddress[] = "dweet.io"; // server address +int port = 80; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + // assemble the path for the POST message: + String dweetName = "scandalous-cheese-hoarder"; + String path = "/dweet/for/" + dweetName; + + // assemble the body of the POST message: + int sensorValue = analogRead(A0); + String postData = "{\"sensorValue\":\""; + postData += sensorValue; + postData += "\"}"; + + Serial.println("making POST request"); + client.setContentType("application/json"); + statusCode = client.post(path, postData); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + Serial.println("Wait ten seconds\n"); + delay(10000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetPost/config.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetPost/config.h new file mode 100644 index 00000000..48ba0f13 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/DweetPost/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/HueBlink/HueBlink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/HueBlink/HueBlink.ino new file mode 100644 index 00000000..2ac01885 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/HueBlink/HueBlink.ino @@ -0,0 +1,92 @@ +/* HueBlink example for RestClient library + + Uses ResClient library to control Philips Hue + For more on Hue developer API see http://developer.meethue.com + + To control a light, the Hue expects a HTTP PUT request to: + + http://hue.hub.address/api/hueUserName/lights/lightNumber/state + + The body of the PUT request looks like this: + {"on": true} or {"on":false} + + This example shows how to concatenate Strings to assemble the + PUT request and the body of the request. + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + modified 15 Feb 2016 + by Tom Igoe (tigoe) to match new API +*/ + +#include +#include +#include +#include "config.h" + +int status = WL_IDLE_STATUS; // the Wifi radio's status +char hueHubIP[] = "192.168.0.3"; // IP address of the HUE bridge +String hueUserName = "huebridgeusername"; // hue bridge username + +// make a wifi instance and a RestClient instance: +WiFiClient wifi; +RestClient restClient = RestClient(wifi, hueHubIP); + + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) + ; // wait for serial port to connect. + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network IP = "); + IPAddress ip = WiFi.localIP(); + Serial.println(ip); +} + +void loop() { + sendRequest(3, "on", "true"); // turn light on + delay(2000); // wait 2 seconds + sendRequest(3, "on", "false"); // turn light off + delay(2000); // wait 2 seconds +} + +void sendRequest(int light, String cmd, String value) { + // make a String for the HTTP request path: + String request = "/api/" + hueUserName; + request += "/lights/"; + request += light; + request += "/state/"; + + // make a string for the JSON command: + String hueCmd = "{\"" + cmd; + hueCmd += "\":"; + hueCmd += value; + hueCmd += "}"; + // see what you assembled to send: + Serial.print("PUT request to server: "); + Serial.println(request); + Serial.print("JSON command to server: "); + + // make the PUT request to the hub: + int statusCode = restClient.put(request, hueCmd); + Serial.println(hueCmd); + Serial.print("Status code from server: "); + Serial.println(statusCode); + Serial.print("Server response: "); + Serial.println(restClient.readResponse()); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/HueBlink/config.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/HueBlink/config.h new file mode 100644 index 00000000..48ba0f13 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/HueBlink/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleDelete/SimpleDelete.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleDelete/SimpleDelete.ino new file mode 100644 index 00000000..e8f11fce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleDelete/SimpleDelete.ino @@ -0,0 +1,62 @@ +/* + Simple DELETE client for RestClient library + Connects to server once every five seconds, sends a DELETE request + and a request body + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 14 Feb 2016 + by Tom Igoe + + this example is in the public domain + */ +#include +#include +#include "config.h" + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + Serial.println("making DELETE request"); + String delData = "name=light&age=46"; + statusCode = client.del("/", delData); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + Serial.println("Wait five seconds"); + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleDelete/config.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleDelete/config.h new file mode 100644 index 00000000..48ba0f13 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleDelete/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleGet/SimpleGet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleGet/SimpleGet.ino new file mode 100644 index 00000000..f486273f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleGet/SimpleGet.ino @@ -0,0 +1,61 @@ +/* + Simple GET client for RestClient library + Connects to server once every five seconds, sends a GET request + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 14 Feb 2016 + by Tom Igoe + + this example is in the public domain + */ +#include +#include +#include "config.h" + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + statusCode = client.get("/"); +} + +void loop() { + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.println("making GET request"); + + statusCode = client.get("/"); + response = client.readResponse(); + Serial.print("Response: "); + Serial.println(response); + Serial.println("Wait five seconds"); + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleGet/config.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleGet/config.h new file mode 100644 index 00000000..48ba0f13 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimpleGet/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePost/SimplePost.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePost/SimplePost.ino new file mode 100644 index 00000000..89e1ec46 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePost/SimplePost.ino @@ -0,0 +1,62 @@ +/* + Simple POST client for RestClient library + Connects to server once every five seconds, sends a POST request + and a request body + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 14 Feb 2016 + by Tom Igoe + + this example is in the public domain + */ +#include +#include +#include "config.h" + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + Serial.println("making POST request"); + String postData = "name=Alice&age=12"; + statusCode = client.post("/", postData); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + Serial.println("Wait five seconds"); + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePost/config.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePost/config.h new file mode 100644 index 00000000..48ba0f13 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePost/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePut/SimplePut.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePut/SimplePut.ino new file mode 100644 index 00000000..53d1ce64 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePut/SimplePut.ino @@ -0,0 +1,62 @@ +/* + Simple PUT client for RestClient library + Connects to server once every five seconds, sends a PUT request + and a request body + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 14 Feb 2016 + by Tom Igoe + + this example is in the public domain + */ +#include +#include +#include "config.h" + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + Serial.println("making PUT request"); + String putData = "name=light&age=46"; + statusCode = client.put("/", putData); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + Serial.println("Wait five seconds"); + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePut/config.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePut/config.h new file mode 100644 index 00000000..48ba0f13 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/SimplePut/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/full_test_suite/config.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/full_test_suite/config.h new file mode 100644 index 00000000..48ba0f13 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/full_test_suite/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/full_test_suite/full_test_suite.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/full_test_suite/full_test_suite.ino new file mode 100644 index 00000000..d0aaf807 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/RestClient/examples/full_test_suite/full_test_suite.ino @@ -0,0 +1,189 @@ +/* RestClient full test suite + + Every REST method is called. + + by Chris Continanza (csquared) + modified by Massimo Banzi (mbanzi) to support more network devices + modified by Tom Igoe to match new API +*/ + +#include +#include +#include "config.h" + +int test_delay = 1000; //so we don't spam the API +bool describe_tests = true; + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + + +void test_status(int statusCode) { + delay(test_delay); + if (statusCode == 200) { + Serial.print("TEST RESULT: ok ("); + Serial.print(statusCode); + Serial.println(")"); + } else { + Serial.print("TEST RESULT: failure ("); + Serial.print(statusCode); + Serial.println(")"); + } +} + +void test_response(String response) { + //Serial.println(response); + if (response == "OK") { + Serial.println("TEST RESULT: ok (response body)"); + } else { + Serial.println("TEST RESULT: fail (response body = " + response + ")"); + } +} + +void describe(String description) { + if (describe_tests) Serial.println(description); +} + +//reusable test variables +String post_body = "POSTDATA"; + +void GET_tests() { + describe("Test GET with path"); + test_status(client.get("/get")); + + describe("Test GET with path and response"); + test_status(client.get("/get")); + test_response(client.readResponse()); + + describe("Test GET with path and query"); + test_status(client.get("/get?name=Bob&age=13")); + + + describe("Test GET with path and header"); + client.setHeader("X-Test-Header: true"); + test_status(client.get("/get-header")); + + describe("Test GET with path and header and response"); + client.setHeader("X-Test-Header: true"); + test_status(client.get("/get-header")); + test_response(client.readResponse()); + + describe("Test GET with 2 headers and response"); + client.setHeader("X-Test-Header1: one"); + client.setHeader("X-Test-Header2: two"); + test_status(client.get("/get-headers")); + test_response(client.readResponse()); +} + +void POST_tests() { + // POST TESTS + describe("Test POST with path and body"); + test_status(client.post("/data", post_body)); + + describe("Test POST with path and body and response"); + test_status(client.post("/data", post_body)); + test_response(client.readResponse()); + + describe("Test POST with path and body and header"); + client.setHeader("X-Test-Header: true"); + test_status(client.post("/data-header", post_body)); + + describe("Test POST with path and body and header and response"); + client.setHeader("X-Test-Header: true"); + test_status(client.post("/data-header", post_body)); + test_response(client.readResponse()); + + describe("Test POST with 2 headers and response"); + client.setHeader("X-Test-Header1: one"); + client.setHeader("X-Test-Header2: two"); + test_status(client.post("/data-headers", post_body)); + test_response(client.readResponse()); +} + +void PUT_tests() { + describe("Test PUT with path and body"); + test_status(client.put("/data", post_body)); + + describe("Test PUT with path and body and response"); + test_status(client.put("/data", post_body)); + test_response(client.readResponse()); + + describe("Test PUT with path and body and header"); + client.setHeader("X-Test-Header: true"); + test_status(client.put("/data-header", post_body)); + + describe("Test PUT with path and body and header and response"); + client.setHeader("X-Test-Header: true"); + test_status(client.put("/data-header", post_body)); + test_response(client.readResponse()); + + describe("Test PUT with 2 headers and response"); + client.setHeader("X-Test-Header1: one"); + client.setHeader("X-Test-Header2: two"); + test_status(client.put("/data-headers", post_body)); + test_response(client.readResponse()); +} + +void DELETE_tests() { + describe("Test DELETE with path"); + //note: requires a special endpoint + test_status(client.del("/del")); + + describe("Test DELETE with path and body"); + test_status(client.del("/data", post_body)); + + describe("Test DELETE with path and body and response"); + test_status(client.del("/data", post_body)); + test_response(client.readResponse()); + + describe("Test DELETE with path and body and header"); + client.setHeader("X-Test-Header: true"); + test_status(client.del("/data-header", post_body)); + + describe("Test DELETE with path and body and header and response"); + client.setHeader("X-Test-Header: true"); + test_status(client.del("/data-header", post_body)); + test_response(client.readResponse()); + + describe("Test DELETE with 2 headers and response"); + client.setHeader("X-Test-Header1: one"); + client.setHeader("X-Test-Header2: two"); + test_status(client.del("/data-headers", post_body)); + test_response(client.readResponse()); +} + + +// Run the tests! +void loop() { + GET_tests(); + POST_tests(); + PUT_tests(); + DELETE_tests(); + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/LICENSE.txt new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/LICENSE.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/README.adoc new file mode 100644 index 00000000..ab370cba --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: SD + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The SD library allows for reading from and writing to SD cards. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/CardInfo/CardInfo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/CardInfo/CardInfo.ino new file mode 100644 index 00000000..1c07fe6f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/CardInfo/CardInfo.ino @@ -0,0 +1,120 @@ +/* + SD card test + + This example shows how use the utility libraries on which the + SD library is based in order to get info about your SD card. + Very useful for testing a card when you're not sure whether its working or not. + Pin numbers reflect the default SPI pins for Uno and Nano models. + The circuit: + SD card attached to SPI bus as follows: + ** SDO - pin 11 on Arduino Uno/Duemilanove/Diecimila + ** SDI - pin 12 on Arduino Uno/Duemilanove/Diecimila + ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + + created 28 Mar 2011 + by Limor Fried + modified 24 July 2020 + by Tom Igoe +*/ +// include the SD library: +#include +#include + +// set up variables using the SD utility library functions: +Sd2Card card; +SdVolume volume; +SdFile root; + +// change this to match your SD shield or module; +// Default SPI on Uno and Nano: pin 10 +// Arduino Ethernet shield: pin 4 +// Adafruit SD shields and modules: pin 10 +// Sparkfun SD shield: pin 8 +// MKR Zero SD: SDCARD_SS_PIN +const int chipSelect = 10; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + Serial.print("\nInitializing SD card..."); + + // we'll use the initialization code from the utility libraries + // since we're just testing if the card is working! + if (!card.init(SPI_HALF_SPEED, chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("* is a card inserted?"); + Serial.println("* is your wiring correct?"); + Serial.println("* did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (1) + ; + } else { + Serial.println("Wiring is correct and a card is present."); + } + + // print the type of card + Serial.println(); + Serial.print("Card type: "); + switch (card.type()) { + case SD_CARD_TYPE_SD1: + Serial.println("SD1"); + break; + case SD_CARD_TYPE_SD2: + Serial.println("SD2"); + break; + case SD_CARD_TYPE_SDHC: + Serial.println("SDHC"); + break; + default: + Serial.println("Unknown"); + } + + // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 + if (!volume.init(card)) { + Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); + while (1) + ; + } + + Serial.print("Clusters: "); + Serial.println(volume.clusterCount()); + Serial.print("Blocks x Cluster: "); + Serial.println(volume.blocksPerCluster()); + + Serial.print("Total Blocks: "); + Serial.println(volume.blocksPerCluster() * volume.clusterCount()); + Serial.println(); + + // print the type and size of the first FAT-type volume + uint32_t volumesize; + Serial.print("Volume type is: FAT"); + Serial.println(volume.fatType(), DEC); + + volumesize = volume.blocksPerCluster(); // clusters are collections of blocks + volumesize *= volume.clusterCount(); // we'll have a lot of clusters + volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1 KB) + Serial.print("Volume size (KB): "); + Serial.println(volumesize); + Serial.print("Volume size (MB): "); + volumesize /= 1024; + Serial.println(volumesize); + Serial.print("Volume size (GB): "); + Serial.println((float)volumesize / 1024.0); + + Serial.println("\nFiles found on the card (name, date and size in bytes): "); + root.openRoot(volume); + + // list all files in the card with date and size + root.ls(LS_R | LS_DATE | LS_SIZE); + root.close(); +} + +void loop(void) { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/Datalogger/Datalogger.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/Datalogger/Datalogger.ino new file mode 100644 index 00000000..d239e2cc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/Datalogger/Datalogger.ino @@ -0,0 +1,81 @@ +/* + SD card datalogger + + This example shows how to log data from three analog sensors + to an SD card using the SD library. Pin numbers reflect the default + SPI pins for Uno and Nano models + + The circuit: + analog sensors on analog pins 0, 1, and 2 + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + created 24 Nov 2010 + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. + +*/ + +#include +#include + +const int chipSelect = 10; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial) + ; + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true) + ; + } + + Serial.println("initialization done."); +} + +void loop() { + // make a string for assembling the data to log: + String dataString = ""; + + // read three sensors and append to the string: + for (int analogPin = 0; analogPin < 3; analogPin++) { + int sensor = analogRead(analogPin); + dataString += String(sensor); + if (analogPin < 2) { + dataString += ","; + } + } + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + File dataFile = SD.open("datalog.txt", FILE_WRITE); + + // if the file is available, write to it: + if (dataFile) { + dataFile.println(dataString); + dataFile.close(); + // print to the serial port too: + Serial.println(dataString); + } + // if the file isn't open, pop up an error: + else { + Serial.println("error opening datalog.txt"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/DumpFile/DumpFile.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/DumpFile/DumpFile.ino new file mode 100644 index 00000000..cac3b959 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/DumpFile/DumpFile.ino @@ -0,0 +1,67 @@ +/* + SD card file dump + + This example shows how to read a file from the SD card using the + SD library and send it over the serial port. + Pin numbers reflect the default SPI pins for Uno and Nano models. + + The circuit: + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + created 22 December 2010 + by Limor Fried + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. +*/ +#include + +const int chipSelect = 10; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial) + ; + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true) + ; + } + + Serial.println("initialization done."); + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + File dataFile = SD.open("datalog.txt"); + + // if the file is available, write to it: + if (dataFile) { + while (dataFile.available()) { + Serial.write(dataFile.read()); + } + dataFile.close(); + } + // if the file isn't open, pop up an error: + else { + Serial.println("error opening datalog.txt"); + } +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/Files/Files.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/Files/Files.ino new file mode 100644 index 00000000..710e826c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/Files/Files.ino @@ -0,0 +1,78 @@ +/* + SD card basic file example + + This example shows how to create and destroy an SD card file. + The circuit. Pin numbers reflect the default + SPI pins for Uno and Nano models: + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + created Nov 2010 + by David A. Mellis + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. +*/ +#include + +const int chipSelect = 10; +File myFile; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial) + ; + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this serial monitor after fixing your issue!"); + while (1) + ; + } + Serial.println("initialization done."); + + if (SD.exists("example.txt")) { + Serial.println("example.txt exists."); + } else { + Serial.println("example.txt doesn't exist."); + } + + // open a new file and immediately close it: + Serial.println("Creating example.txt..."); + myFile = SD.open("example.txt", FILE_WRITE); + myFile.close(); + + // Check to see if the file exists: + if (SD.exists("example.txt")) { + Serial.println("example.txt exists."); + } else { + Serial.println("example.txt doesn't exist."); + } + + // delete the file: + Serial.println("Removing example.txt..."); + SD.remove("example.txt"); + + if (SD.exists("example.txt")) { + Serial.println("example.txt exists."); + } else { + Serial.println("example.txt doesn't exist."); + } +} + +void loop() { + // nothing happens after setup finishes. +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/NonBlockingWrite/NonBlockingWrite.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/NonBlockingWrite/NonBlockingWrite.ino new file mode 100644 index 00000000..9e1c7c0f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/NonBlockingWrite/NonBlockingWrite.ino @@ -0,0 +1,121 @@ +/* + Non-blocking Write + + This example demonstrates how to perform non-blocking writes + to a file on a SD card. The file will contain the current millis() + value every 10ms. If the SD card is busy, the data will be dataBuffered + in order to not block the sketch. + + If data is successfully written, the built in LED will flash. After a few + seconds, check the card for a file called datalog.txt + + NOTE: myFile.availableForWrite() will automatically sync the + file contents as needed. You may lose some unsynced data + still if myFile.sync() or myFile.close() is not called. + + Pin numbers reflect the default SPI pins for Uno and Nano models + Updated for clarity and uniformity with other examples + + The circuit: + analog sensors on analog ins 0, 1, and 2 + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. +*/ +#include + +const int chipSelect = 10; + +// file name to use for writing +const char filename[] = "datalog.txt"; + +// File object to represent file +File myFile; +// string to buffer output +String dataBuffer; +// last time data was written to card: +unsigned long lastMillis = 0; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // reserve 1 kB for String used as a dataBuffer + dataBuffer.reserve(1024); + + // set LED pin to output, used to blink when writing + pinMode(LED_BUILTIN, OUTPUT); + + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial) + ; + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true) + ; + } + + Serial.println("initialization done."); + + // If you want to start from an empty file, + // uncomment the next line: + // SD.remove(filename); + // try to open the file for writing + + myFile = SD.open(filename, FILE_WRITE); + if (!myFile) { + Serial.print("error opening "); + Serial.println(filename); + while (true) + ; + } + + // add some new lines to start + myFile.println(); + myFile.println("Hello World!"); + Serial.println("Starting to write to file..."); +} + +void loop() { + // check if it's been over 10 ms since the last line added + unsigned long now = millis(); + if ((now - lastMillis) >= 10) { + // add a new line to the dataBuffer + dataBuffer += "Hello "; + dataBuffer += now; + dataBuffer += "\r\n"; + // print the buffer length. This will change depending on when + // data is actually written to the SD card file: + Serial.print("Unsaved data buffer length (in bytes): "); + Serial.println(dataBuffer.length()); + // note the time that the last line was added to the string + lastMillis = now; + } + + // check if the SD card is available to write data without blocking + // and if the dataBuffered data is enough for the full chunk size + unsigned int chunkSize = myFile.availableForWrite(); + if (chunkSize && dataBuffer.length() >= chunkSize) { + // write to file and blink LED + digitalWrite(LED_BUILTIN, HIGH); + myFile.write(dataBuffer.c_str(), chunkSize); + digitalWrite(LED_BUILTIN, LOW); + // remove written data from dataBuffer + dataBuffer.remove(0, chunkSize); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/ReadWrite/ReadWrite.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/ReadWrite/ReadWrite.ino new file mode 100644 index 00000000..d4c7548c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/ReadWrite/ReadWrite.ino @@ -0,0 +1,82 @@ +/* + SD card read/write + + This example shows how to read and write data to and from an SD card file + The circuit. Pin numbers reflect the default + SPI pins for Uno and Nano models: + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - pin 4 (For For Uno, Nano: pin 10. For MKR Zero SD: SDCARD_SS_PIN) + + created Nov 2010 + by David A. Mellis + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. + +*/ +#include + +const int chipSelect = 10; +File myFile; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial) + ; + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true) + ; + } + + Serial.println("initialization done."); + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + myFile = SD.open("test.txt", FILE_WRITE); + + // if the file opened okay, write to it: + if (myFile) { + Serial.print("Writing to test.txt..."); + myFile.println("testing 1, 2, 3."); + // close the file: + myFile.close(); + Serial.println("done."); + } else { + // if the file didn't open, print an error: + Serial.println("error opening test.txt"); + } + + // re-open the file for reading: + myFile = SD.open("test.txt"); + if (myFile) { + Serial.println("test.txt:"); + + // read from the file until there's nothing else in it: + while (myFile.available()) { + Serial.write(myFile.read()); + } + // close the file: + myFile.close(); + } else { + // if the file didn't open, print an error: + Serial.println("error opening test.txt"); + } +} + +void loop() { + // nothing happens after setup +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/listfiles/listfiles.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/listfiles/listfiles.ino new file mode 100644 index 00000000..ba2e0696 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SD/examples/listfiles/listfiles.ino @@ -0,0 +1,88 @@ +/* + Listfiles + + This example shows how to print out the files in a + directory on a SD card. Pin numbers reflect the default + SPI pins for Uno and Nano models + + The circuit: + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + created Nov 2010 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + modified 2 Feb 2014 + by Scott Fitzgerald + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. + +*/ +#include + +const int chipSelect = 10; +File root; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial) + ; + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true) + ; + } + + Serial.println("initialization done."); + + root = SD.open("/"); + + printDirectory(root, 0); + + Serial.println("done!"); +} + +void loop() { + // nothing happens after setup finishes. +} + +void printDirectory(File dir, int numTabs) { + while (true) { + + File entry = dir.openNextFile(); + if (!entry) { + // no more files + break; + } + for (uint8_t i = 0; i < numTabs; i++) { + Serial.print('\t'); + } + Serial.print(entry.name()); + if (entry.isDirectory()) { + Serial.println("/"); + printDirectory(entry, numTabs + 1); + } else { + // files have sizes, directories do not + Serial.print("\t\t"); + Serial.println(entry.size(), DEC); + } + entry.close(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Scheduler/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Scheduler/README.adoc new file mode 100644 index 00000000..ddb56b07 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Scheduler/README.adoc @@ -0,0 +1,29 @@ +:repository-owner: arduino-libraries +:repository-name: Scheduler + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The Scheduler library enables the Arduino link:https://store.arduino.cc/arduino-due[Due], link:https://store.arduino.cc/arduino-zero[Zero], and link:https://store.arduino.cc/arduino-mkr1000-wifi[MKR1000] to run multiple functions at the same time. This allows tasks to happen without interrupting each other. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2012 The Android Open Source Project. All right reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino new file mode 100644 index 00000000..ffa32827 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino @@ -0,0 +1,81 @@ +/* + Multiple Blinks + + Demonstrates the use of the Scheduler library for the Arduino Due + + Hardware required : + * LEDs connected to pins 11, 12, and 13 + + created 8 Oct 2012 + by Cristian Maglie + Modified by + Scott Fitzgerald 19 Oct 2012 + + This example code is in the public domain + + http://www.arduino.cc/en/Tutorial/MultipleBlinks +*/ + +// Include Scheduler since we want to manage multiple tasks. +#include + +int led1 = 13; +int led2 = 12; +int led3 = 11; + +void setup() { + Serial.begin(9600); + + // Setup the 3 pins as OUTPUT + pinMode(led1, OUTPUT); + pinMode(led2, OUTPUT); + pinMode(led3, OUTPUT); + + // Add "loop2" and "loop3" to scheduling. + // "loop" is always started by default. + Scheduler.startLoop(loop2); + Scheduler.startLoop(loop3); +} + +// Task no.1: blink LED with 1 second delay. +void loop() { + digitalWrite(led1, HIGH); + + // IMPORTANT: + // When multiple tasks are running 'delay' passes control to + // other tasks while waiting and guarantees they get executed. + delay(1000); + + digitalWrite(led1, LOW); + delay(1000); +} + +// Task no.2: blink LED with 0.1 second delay. +void loop2() { + digitalWrite(led2, HIGH); + delay(100); + digitalWrite(led2, LOW); + delay(100); +} + +// Task no.3: accept commands from Serial port +// '0' turns off LED +// '1' turns on LED +void loop3() { + if (Serial.available()) { + char c = Serial.read(); + if (c == '0') { + digitalWrite(led3, LOW); + Serial.println("LED turned off!"); + } + if (c == '1') { + digitalWrite(led3, HIGH); + Serial.println("LED turned on!"); + } + } + + // IMPORTANT: + // We must call 'yield' at a regular basis to pass + // control to other tasks. + yield(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/README.adoc new file mode 100644 index 00000000..b16b16b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: Servo + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino board to control RC (hobby) servo motors. + +For more information about this library please visit us at +https://www.arduino.cc/reference/en/libraries/servo/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Knob/Knob.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Knob/Knob.ino new file mode 100644 index 00000000..2fb731f1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Knob/Knob.ino @@ -0,0 +1,26 @@ +/* + Controlling a servo position using a potentiometer (variable resistor) + by Michal Rinott + + modified on 8 Nov 2013 + by Scott Fitzgerald + http://www.arduino.cc/en/Tutorial/Knob +*/ + +#include + +Servo myservo; // create servo object to control a servo + +int potpin = A0; // analog pin used to connect the potentiometer +int val; // variable to read the value from the analog pin + +void setup() { + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + +void loop() { + val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) + val = map(val, 0, 1023, 0, 180); // scale it for use with the servo (value between 0 and 180) + myservo.write(val); // sets the servo position according to the scaled value + delay(15); // waits for the servo to get there +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Knob/readme.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Knob/readme.md new file mode 100644 index 00000000..7dc37ddb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Knob/readme.md @@ -0,0 +1,35 @@ +# Knob + +Control the position of a RC (hobby) [servo motor](http://en.wikipedia.org/wiki/Servo_motor#RC_servos) with your Arduino and a potentiometer. + +This example makes use of the Arduino `Servo` library. + +## Hardware Required + +* an Arduino board +* Servo motor +* 10k ohm potentiometer +* hook-up wires + +## Circuit + +Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow or orange and should be connected to pin 9 on the board. + +The potentiometer should be wired so that its two outer pins are connected to power (+5V) and ground, and its middle pin is connected to analog input 0 on the board. + +![](images/knob_BB.png) + +(Images developed using Fritzing. For more circuit examples, see the [Fritzing project page](http://fritzing.org/projects/)) + +## Schematic + +![](images/knob_schem.png) + +## See also + +* [attach()](/docs/api.md#attach) +* [write()](/docs/api.md#write) +* [map()](https://www.arduino.cc/en/Reference/Map) +* [analogRead()](https://www.arduino.cc/en/Reference/AnalogRead) +* [Servo library reference](/docs/readme.md) +* [Sweep](../Sweep) - Sweep the shaft of a servo motor back and forth diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Sweep/Sweep.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Sweep/Sweep.ino new file mode 100644 index 00000000..55deb0b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Sweep/Sweep.ino @@ -0,0 +1,31 @@ +/* Sweep + by BARRAGAN + This example code is in the public domain. + + modified 8 Nov 2013 + by Scott Fitzgerald + https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep +*/ + +#include + +Servo myservo; // create servo object to control a servo +// twelve servo objects can be created on most boards + +int pos = 0; // variable to store the servo position + +void setup() { + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + +void loop() { + for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees + // in steps of 1 degree + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15 ms for the servo to reach the position + } + for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15 ms for the servo to reach the position + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Sweep/readme.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Sweep/readme.md new file mode 100644 index 00000000..bb07d5a1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Servo/examples/Sweep/readme.md @@ -0,0 +1,29 @@ +# Sweep + +Sweeps the shaft of a RC [servo motor](http://en.wikipedia.org/wiki/Servo_motor#RC_servos) back and forth across 180 degrees. + +## Hardware Required + +* Arduino Board +* Servo Motor +* Hook-up wires + +## Circuit + +Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow, orange or white and should be connected to pin 9 on the board. + +![](images/sweep_bb.png) + +(Images developed using Fritzing. For more circuit examples, see the [Fritzing project page](http://fritzing.org/projects/)) + +## Schematic + +![](images/sweep_schem.png) + +## See also + +* [attach()](/docs/api.md#attach) +* [write()](/docs/api.md#write) +* [map()](https://www.arduino.cc/en/Reference/Map) +* [Servo library reference](/docs/readme.md) +* [Knob](../Knob) - Control the position of a servo with a potentiometer diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/README.md new file mode 100644 index 00000000..76c135ce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/README.md @@ -0,0 +1,154 @@ +# SigFox Library + +[![Check Arduino status](https://github.com/arduino-libraries/SigFox/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/SigFox/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/SigFox/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/spell-check.yml) + +## Description + +This library allows you to use the ATMEL SigFox transceiver (ATAB8520E) on the Arduino MKRFOX1200 board. For additional information on the Arduino MKR Fox 1200 board, see the [Getting Started page](https://www.arduino.cc/en/Guide/MKRFox1200) and the [product page](https://store.arduino.cc/arduino-mkr-fox-1200-1408). + +SigFox employs a cellular system that enables remote devices to connect using Ultra-Narrow Band (UNB) technology. It requires little energy, being termed Low-power Wide-area network (LPWAN). + +## Installation + +![image](https://user-images.githubusercontent.com/36513474/67494578-d9213100-f692-11e9-9cc2-e18e69ae7d3c.png) + +### First Method + +1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries +1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. +1. Then search for SigFox using the search bar. +1. Click on the text area and then select the specific version and install it. + +### Second Method + +1. Navigate to the Releases page. +1. Download the latest release. +1. Extract the zip file +1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library + +## Features + +- ### Ultra Narrowband + + This library enables remote devices to use UNB. The benefit of using ultra narrowband receiver is that it rejects noise and interference which may enter the receiver, enabling an acceptable signal-to-noise ratio to be achieved with a relatively weak received signal + +- ### LPWAN + + SigFox library requires Low Powered Wide Area Network. This technology connects low-bandwidth devices with low rate of bits over long ranges. + +- ### Good fit for small applications + + This library is a good fit for any application that needs to send small, infrequent bursts of data. Things like basic alarm systems, location monitoring, and simple metering are all examples of one-way systems that might make sense for this network. + +- ### Give back + + SigFox is free for everyone. The licensed document can be copied, redistributed and used in the projects, assignments or anywhere. + +- ### Licensed Document + + Library is licensed under GNU lesser General Public License. It's not allowed to make changes in the functions or anything. The user simply has to import the library in the project and can use any of its functions by just calling it. + +## Functions + +- begin() +- beginPacket() +- write() +- print() +- endPacket() +- parsePacket() +- statusCode() +- AtmVersion() +- SigVersion() +- ID() +- PAC() +- reset() +- internalTemperature() +- debug() +- noDebug() +- end() +- peek() +- available() +- read() + +For further functions description visit [SigFox](https://www.arduino.cc/en/Reference/SigFox) + +## Example + +There are many examples implemented where this library is used. You can find other examples from [Github-SigFox](https://github.com/arduino-libraries/SigFox/tree/master/examples) and [Arduino-Reference](https://www.arduino.cc/en/Reference/SigFox) + +- ### Send Boolean + + This sketch demonstrates how to send a simple binary data ( 0 or 1 ) using a MKR Fox 1200. If the application only needs to send one bit of information the transmission time (and thus power consumption) will be much lower than sending a full 12 bytes packet. + +``` C++ +#include + +bool value_to_send = true; + +#define DEBUG 1 + +void setup() { + + if (DEBUG){ + Serial.begin(9600); + while (!Serial) {}; + } + + if (!SigFox.begin()) { + if (DEBUG){ + Serial.println("Sigfox module unavailable !"); + } + return; + } + + if (DEBUG){ + SigFox.debug(); + Serial.println("ID = " + SigFox.ID()); + } + + delay(100); + + SigFox.beginPacket(); + SigFox.write(value_to_send); + int ret = SigFox.endPacket(); + + if (DEBUG){ + Serial.print("Status : "); + Serial.println(ret); + } +} + +void loop(){} +``` + +## Contributing + +If you want to contribute to this project: + +- Report bugs and errors +- Ask for enhancements +- Create issues and pull requests +- Tell others about this library +- Contribute new protocols + +Please read [CONTRIBUTING.md](https://github.com/arduino-libraries/SigFox/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. + +## Credits + +The Library created and maintained by Arduino LLC + +Based on previous work by: + +- M. Facchin +- N. Lesconnec +- N. Barcucci + +## Current stable version + +**version:** v1.0.4 + +## License + +This library is licensed under [GNU LGPL](https://www.gnu.org/licenses/lgpl-3.0.en.html). diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/EventTrigger/EventTrigger.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/EventTrigger/EventTrigger.ino new file mode 100644 index 00000000..b0e1513c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/EventTrigger/EventTrigger.ino @@ -0,0 +1,104 @@ +/* + SigFox Event Trigger tutorial + + This sketch demonstrates the usage of a MKR Fox 1200 + to build a battery-powered alarm sensor with email notifications + + A couple of sensors (normally open) should be wired between pins 1 and 2 and GND. + + This example code is in the public domain. +*/ + +#include +#include + +// Set debug to false to enable continuous mode +// and disable serial prints +int debug = true; + +volatile int alarm_source = 0; + +void setup() { + + if (debug == true) { + + // We are using Serial1 instead of Serial because we are going into standby + // and the USB port could get confused during wakeup. To read the debug prints, + // connect pins 13-14 (TX-RX) to a 3.3 V USB-to-serial converter + + Serial1.begin(115200); + while (!Serial1) {} + } + + if (!SigFox.begin()) { + //something is really wrong, try rebooting + reboot(); + } + + //Send module to standby until we need to send a message + SigFox.end(); + + if (debug == true) { + // Enable debug prints and LED indication if we are testing + SigFox.debug(); + } + + // attach pin 0 and 1 to a switch and enable the interrupt on voltage falling event + pinMode(0, INPUT_PULLUP); + LowPower.attachInterruptWakeup(0, alarmEvent1, FALLING); + + pinMode(1, INPUT_PULLUP); + LowPower.attachInterruptWakeup(1, alarmEvent2, FALLING); +} + +void loop() { + // Sleep until an event is recognized + LowPower.sleep(); + + // if we get here it means that an event was received + + SigFox.begin(); + + if (debug == true) { + Serial1.println("Alarm event on sensor " + String(alarm_source)); + } + delay(100); + + // 3 bytes (ALM) + 8 bytes (ID as String) + 1 byte (source) < 12 bytes + String to_be_sent = "ALM" + SigFox.ID() + String(alarm_source); + + SigFox.beginPacket(); + SigFox.print(to_be_sent); + int ret = SigFox.endPacket(); + + // shut down module, back to standby + SigFox.end(); + + if (debug == true) { + if (ret > 0) { + Serial1.println("No transmission"); + } else { + Serial1.println("Transmission ok"); + } + + Serial1.println(SigFox.status(SIGFOX)); + Serial1.println(SigFox.status(ATMEL)); + + // Loop forever if we are testing for a single event + while (1) {}; + } +} + +void alarmEvent1() { + alarm_source = 1; +} + +void alarmEvent2() { + alarm_source = 2; +} + +void reboot() { + NVIC_SystemReset(); + while (1) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/FirstConfiguration/FirstConfiguration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/FirstConfiguration/FirstConfiguration.ino new file mode 100644 index 00000000..dfc694d0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/FirstConfiguration/FirstConfiguration.ino @@ -0,0 +1,145 @@ +/* + SigFox First Configuration + + This sketch demonstrates the usage of MKR Fox 1200 Sigfox module. + Since the board is designed with low power in mind, it depends directly on the ArduinoLowPower library + + This example code is in the public domain. +*/ + +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial) {}; + + // Uncomment this line and comment begin() if you are working with a custom board + //if (!SigFox.begin(SPI1, 30, 31, 33, 28, LED_BUILTIN)) { + if (!SigFox.begin()) { + Serial.println("Shield error or not present!"); + return; + } + // Enable debug LED and disable automatic deep sleep + // Comment this line when shipping your project :) + SigFox.debug(); + + String version = SigFox.SigVersion(); + String ID = SigFox.ID(); + String PAC = SigFox.PAC(); + + // Display module information + Serial.println("MKR Fox 1200 Sigfox first configuration"); + Serial.println("SigFox FW version " + version); + Serial.println("ID = " + ID); + Serial.println("PAC = " + PAC); + + Serial.println(""); + + Serial.print("Module temperature: "); + Serial.println(SigFox.internalTemperature()); + + Serial.println("Register your board on https://buy.sigfox.com/activate with provided ID and PAC"); + Serial.println("The displayed PAC is the factory value. It is a throw-away value, which can only be used once for registration."); + Serial.println("If this device has already been registered, you can retrieve the updated PAC value on https://backend.sigfox.com/device/list"); + Serial.println("Join the Sigfox Builders Slack community to exchange with other developers, get help .. and find new ideas! https://builders.iotagency.sigfox.com/"); + delay(100); + + // Send the module to the deepest sleep + SigFox.end(); + + Serial.println("Type the message to be sent"); + while (!Serial.available()) + ; + + String message; + while (Serial.available()) { + message += (char)Serial.read(); + } + + // Every SigFox packet cannot exceed 12 bytes + // If the string is longer, only the first 12 bytes will be sent + + if (message.length() > 12) { + Serial.println("Message too long, only first 12 bytes will be sent"); + } + + Serial.println("Sending " + message); + + // Remove EOL + message.trim(); + + // Example of message that can be sent + // sendString(message); + + Serial.println("Getting the response will take up to 50 seconds"); + Serial.println("The LED will blink while the operation is ongoing"); + + // Example of send and read response + sendStringAndGetResponse(message); +} + +void loop() { +} + +void sendString(String str) { + // Start the module + SigFox.begin(); + // Wait at least 30mS after first configuration (100mS before) + delay(100); + // Clears all pending interrupts + SigFox.status(); + delay(1); + + SigFox.beginPacket(); + SigFox.print(str); + + int ret = SigFox.endPacket(); // send buffer to SIGFOX network + if (ret > 0) { + Serial.println("No transmission"); + } else { + Serial.println("Transmission ok"); + } + + Serial.println(SigFox.status(SIGFOX)); + Serial.println(SigFox.status(ATMEL)); + SigFox.end(); +} + +void sendStringAndGetResponse(String str) { + // Start the module + SigFox.begin(); + // Wait at least 30mS after first configuration (100mS before) + delay(100); + // Clears all pending interrupts + SigFox.status(); + delay(1); + + SigFox.beginPacket(); + SigFox.print(str); + + int ret = SigFox.endPacket(true); // send buffer to SIGFOX network and wait for a response + if (ret > 0) { + Serial.println("No transmission"); + } else { + Serial.println("Transmission ok"); + } + + Serial.println(SigFox.status(SIGFOX)); + Serial.println(SigFox.status(ATMEL)); + + if (SigFox.parsePacket()) { + Serial.println("Response from server:"); + while (SigFox.available()) { + Serial.print("0x"); + Serial.println(SigFox.read(), HEX); + } + } else { + Serial.println("Could not get any response from the server"); + Serial.println("Check the Sigfox coverage in your area"); + Serial.println("If you are indoor, check the 20 dB coverage or move near a window"); + } + Serial.println(); + + SigFox.end(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/SendBoolean/SendBoolean.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/SendBoolean/SendBoolean.ino new file mode 100644 index 00000000..adf4befc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/SendBoolean/SendBoolean.ino @@ -0,0 +1,55 @@ +/* + SigFox Send Boolean tutorial + + This sketch demonstrates how to send a simple binary data ( 0 or 1 ) using a MKR Fox 1200. + If the application only needs to send one bit of information the transmission time + (and thus power consumption) will be much lower than sending a full 12 bytes packet. + + This example code is in the public domain. +*/ + +#include + +// We want to send a Boolean value to signal a binary event +// like open/close or on/off + +bool value_to_send = true; + +#define DEBUG 1 + +void setup() { + + if (DEBUG) { + Serial.begin(9600); + while (!Serial) {}; + } + + // Initialize the Sigfox module + if (!SigFox.begin()) { + if (DEBUG) { + Serial.println("Sigfox module unavailable !"); + } + return; + } + + // If we want to to debug the application, print the device ID to easily find it in the backend + if (DEBUG) { + SigFox.debug(); + Serial.println("ID = " + SigFox.ID()); + } + + delay(100); + + // Compose a message as usual; the single bit transmission will be performed transparently + // if the data we want to send is suitable + SigFox.beginPacket(); + SigFox.write(value_to_send); + int ret = SigFox.endPacket(); + + if (DEBUG) { + Serial.print("Status : "); + Serial.println(ret); + } +} + +void loop() {} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitor/WeatherMonitor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitor/WeatherMonitor.ino new file mode 100644 index 00000000..6d877312 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitor/WeatherMonitor.ino @@ -0,0 +1,172 @@ +/* + SigFox Simple Weather Station + + This sketch demonstrates the usage of MKR Fox 1200 as a simple weather station. + It uses + the onboard temperature sensor + HTU21D I2C sensor to get humidity + Bosch BMP280 to get the barometric pressure + TSL2561 Light Sensor to get luminosity + + Download the needed libraries from the following links + http://librarymanager/all#BMP280&Adafruit + http://librarymanager/all#HTU21D&Adafruit + http://librarymanager/all#TSL2561&Adafruit + http://librarymanager/all#adafruit&sensor&abstraction + + Since the Sigfox network can send a maximum of 120 messages per day (depending on your plan) + we'll optimize the readings and send data in compact binary format + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include +#include +#include "conversions.h" + +// Set oneshot to false to trigger continuous mode when you finished setting up the whole flow +int oneshot = true; + +Adafruit_BMP280 bmp; +Adafruit_HTU21DF htu = Adafruit_HTU21DF(); +Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); + +#define STATUS_OK 0 +#define STATUS_BMP_KO 1 +#define STATUS_HTU_KO 2 +#define STATUS_TSL_KO 4 + +/* + ATTENTION - the structure we are going to send MUST + be declared "packed" otherwise we'll get padding mismatch + on the sent data - see http://www.catb.org/esr/structure-packing/#_structure_alignment_and_padding + for more details +*/ +typedef struct __attribute__((packed)) sigfox_message { + uint8_t status; + int16_t moduleTemperature; + int16_t bmpTemperature; + uint16_t bmpPressure; + uint16_t htuHumidity; + uint16_t tlsLight; + uint8_t lastMessageStatus; +} SigfoxMessage; + +// stub for message which will be sent +SigfoxMessage msg; + +void setup() { + + if (oneshot == true) { + // Wait for the serial + Serial.begin(115200); + while (!Serial) {} + } + + if (!SigFox.begin()) { + // Something is really wrong, try rebooting + // Reboot is useful if we are powering the board using an unreliable power source + // (eg. solar panels or other energy harvesting methods) + reboot(); + } + + //Send module to standby until we need to send a message + SigFox.end(); + + if (oneshot == true) { + // Enable debug prints and LED indication if we are testing + SigFox.debug(); + } + + // Configure the sensors and populate the status field + if (!bmp.begin()) { + msg.status |= STATUS_BMP_KO; + } else { + Serial.println("BMP OK"); + } + + if (!htu.begin()) { + msg.status |= STATUS_HTU_KO; + } else { + Serial.println("HTU OK"); + } + + if (!tsl.begin()) { + msg.status |= STATUS_TSL_KO; + } else { + Serial.println("TLS OK"); + tsl.enableAutoRange(true); + tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); + } +} + +void loop() { + // Every 15 minutes, read all the sensors and send them + // Let's try to optimize the data format + // Only use floats as intermediate representation, don't send them directly + + sensors_event_t event; + + float pressure = bmp.readPressure(); + msg.bmpPressure = convertoFloatToUInt16(pressure, 200000); + float temperature = bmp.readTemperature(); + msg.bmpTemperature = convertoFloatToInt16(temperature, 60, -60); + + tsl.getEvent(&event); + if (event.light) { + msg.tlsLight = convertoFloatToUInt16(event.light, 100000); + } + + float humidity = htu.readHumidity(); + msg.htuHumidity = convertoFloatToUInt16(humidity, 110); + + // Start the module + SigFox.begin(); + // Wait at least 30 ms after first configuration (100 ms before) + delay(100); + + // We can only read the module temperature before SigFox.end() + temperature = SigFox.internalTemperature(); + msg.moduleTemperature = convertoFloatToInt16(temperature, 60, -60); + + if (oneshot == true) { + Serial.println("Pressure: " + String(pressure)); + Serial.println("External temperature: " + String(temperature)); + Serial.println("Internal temp: " + String(temperature)); + Serial.println("Light: " + String(event.light)); + Serial.println("Humidity: " + String(humidity)); + } + + // Clears all pending interrupts + SigFox.status(); + delay(1); + + SigFox.beginPacket(); + SigFox.write((uint8_t*)&msg, 12); + + msg.lastMessageStatus = SigFox.endPacket(); + + if (oneshot == true) { + Serial.println("Status: " + String(msg.lastMessageStatus)); + } + + SigFox.end(); + + if (oneshot == true) { + // spin forever, so we can test that the backend is behaving correctly + while (1) {} + } + + //Sleep for 15 minutes + LowPower.sleep(15 * 60 * 1000); +} + +void reboot() { + NVIC_SystemReset(); + while (1) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitor/conversions.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitor/conversions.h new file mode 100644 index 00000000..9a13bb9f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitor/conversions.h @@ -0,0 +1,13 @@ + +#define UINT16_t_MAX 65536 +#define INT16_t_MAX UINT16_t_MAX / 2 + +int16_t convertoFloatToInt16(float value, long max, long min) { + float conversionFactor = (float)(INT16_t_MAX) / (float)(max - min); + return (int16_t)(value * conversionFactor); +} + +uint16_t convertoFloatToUInt16(float value, long max, long min = 0) { + float conversionFactor = (float)(UINT16_t_MAX) / (float)(max - min); + return (uint16_t)(value * conversionFactor); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/WeatherMonitorStream.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/WeatherMonitorStream.ino new file mode 100644 index 00000000..607f2eb7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/WeatherMonitorStream.ino @@ -0,0 +1,146 @@ +/* + SigFox Simple Weather Station + + This sketch demonstrates the usage of MKR Fox 1200 as a simple weather station. + It uses + the onboard temperature sensor + HTU21D I2C sensor to get humidity + Bosch BMP280 to get the barometric pressure + TSL2561 Light Sensor to get luminosity + + Download the needed libraries from the following links + http://librarymanager/all#BMP280&Adafruit + http://librarymanager/all#HTU21D&Adafruit + http://librarymanager/all#TSL2561&Adafruit + http://librarymanager/all#adafruit&sensor&abstraction + + Since the Sigfox network can send a maximum of 120 messages per day (depending on your plan) + we'll optimize the readings and send data in compact binary format + + This sketch shows how to use the Stream APIs of the library. + Refer to the WeatherMonitor sketch for an example using data structures. + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include +#include +#include "conversions.h" + +// Set oneshot to false to trigger continuous mode when you finished setting up the whole flow +int oneshot = true; + +Adafruit_BMP280 bmp; +Adafruit_HTU21DF htu = Adafruit_HTU21DF(); +Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); + +#define STATUS_OK 0 +#define STATUS_BMP_KO 1 +#define STATUS_HTU_KO 2 +#define STATUS_TSL_KO 4 + +byte status; + +void setup() { + + if (oneshot == true) { + // Wait for the serial + Serial.begin(115200); + while (!Serial) {} + } + + if (!SigFox.begin()) { + // Something is really wrong, try rebooting + // Reboot is useful if we are powering the board using an unreliable power source + // (eg. solar panels or other energy harvesting methods) + reboot(); + } + + //Send module to standby until we need to send a message + SigFox.end(); + + if (oneshot == true) { + // Enable debug prints and LED indication if we are testing + SigFox.debug(); + } + + // Configure the sensors and populate the status field + if (!bmp.begin()) { + status |= STATUS_BMP_KO; + } else { + Serial.println("BMP OK"); + } + + if (!htu.begin()) { + status |= STATUS_HTU_KO; + } else { + Serial.println("HTU OK"); + } + + if (!tsl.begin()) { + status |= STATUS_TSL_KO; + } else { + Serial.println("TLS OK"); + tsl.enableAutoRange(true); + tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); + } +} + +void loop() { + // Every 15 minutes, read all the sensors and send them + // Let's try to optimize the data format + // Only use floats as intermediate representation, don't send them directly + + sensors_event_t event; + + float pressure = bmp.readPressure(); + float temperature = bmp.readTemperature(); + float humidity = htu.readHumidity(); + + tsl.getEvent(&event); + float light = event.light; + + // Start the module + SigFox.begin(); + // Wait at least 30 ms after first configuration (100 ms before) + delay(100); + + // Prepare the packet using the Stream APIs + SigFox.beginPacket(); + SigFox.write((byte)status); + SigFox.write((short)convertoFloatToInt16(temperature, 60, -60)); + SigFox.write((unsigned short)convertoFloatToUInt16(pressure, 200000)); + SigFox.write((unsigned short)convertoFloatToUInt16(humidity, 110)); + SigFox.write((unsigned short)convertoFloatToUInt16(light, 100000)); + + int ret = SigFox.endPacket(); + + if (oneshot == true) { + Serial.println("Pressure: " + String(pressure)); + Serial.println("External temperature: " + String(temperature)); + Serial.println("Light: " + String(event.light)); + Serial.println("Humidity: " + String(humidity)); + Serial.println("Status: " + String(ret)); + } + + // Shut down the module + SigFox.end(); + + if (oneshot == true) { + // spin forever, so we can test that the backend is behaving correctly + while (1) {} + } + + //Sleep for 15 minutes + LowPower.sleep(15 * 60 * 1000); +} + +void reboot() { + NVIC_SystemReset(); + while (1) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/conversions.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/conversions.h new file mode 100644 index 00000000..9a13bb9f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/conversions.h @@ -0,0 +1,13 @@ + +#define UINT16_t_MAX 65536 +#define INT16_t_MAX UINT16_t_MAX / 2 + +int16_t convertoFloatToInt16(float value, long max, long min) { + float conversionFactor = (float)(INT16_t_MAX) / (float)(max - min); + return (int16_t)(value * conversionFactor); +} + +uint16_t convertoFloatToUInt16(float value, long max, long min = 0) { + float conversionFactor = (float)(UINT16_t_MAX) / (float)(max - min); + return (uint16_t)(value * conversionFactor); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/README.adoc new file mode 100644 index 00000000..55b91a88 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/README.adoc @@ -0,0 +1,33 @@ +:repository-owner: arduino-libraries +:repository-name: Stepper + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows you to control unipolar or bipolar stepper motors. To use it you will need a stepper motor, and the appropriate hardware to control it. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) Arduino LLC. All right reserved. +Copyright (c) Sebastian Gassner. All right reserved. +Copyright (c) Noah Shibley. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/MotorKnob/MotorKnob.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/MotorKnob/MotorKnob.ino new file mode 100644 index 00000000..d0141472 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/MotorKnob/MotorKnob.ino @@ -0,0 +1,39 @@ +/* + * MotorKnob + * + * A stepper motor follows the turns of a potentiometer + * (or other sensor) on analog input 0. + * + * https://docs.arduino.cc/learn/electronics/stepper-motors + * This example code is in the public domain. + */ + +#include + +// change this to the number of steps on your motor +#define STEPS 100 + +// create an instance of the Stepper class, specifying +// the number of steps of the motor and the pins it's +// attached to +Stepper stepper(STEPS, 8, 9, 10, 11); + +// the previous reading from the analog input +int previous = 0; + +void setup() { + // set the speed of the motor to 30 RPMs + stepper.setSpeed(30); +} + +void loop() { + // get the sensor value + int val = analogRead(0); + + // move a number of steps equal to the change in the + // sensor reading + stepper.step(val - previous); + + // remember the previous value of the sensor + previous = val; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino new file mode 100644 index 00000000..2567a791 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino @@ -0,0 +1,42 @@ +/* + Stepper Motor Control - one revolution + + This program drives a unipolar or bipolar stepper motor. + The motor is attached to digital pins 8 - 11 of the Arduino. + + The motor should revolve one revolution in one direction, then + one revolution in the other direction. + + + Created 11 Mar. 2007 + Modified 30 Nov. 2009 + by Tom Igoe + + */ + +#include + +const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution +// for your motor + +// initialize the Stepper library on pins 8 through 11: +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); + +void setup() { + // set the speed at 60 rpm: + myStepper.setSpeed(60); + // initialize the serial port: + Serial.begin(9600); +} + +void loop() { + // step one revolution in one direction: + Serial.println("clockwise"); + myStepper.step(stepsPerRevolution); + delay(500); + + // step one revolution in the other direction: + Serial.println("counterclockwise"); + myStepper.step(-stepsPerRevolution); + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino new file mode 100644 index 00000000..bd177b31 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino @@ -0,0 +1,42 @@ +/* + Stepper Motor Control - one step at a time + + This program drives a unipolar or bipolar stepper motor. + The motor is attached to digital pins 8 - 11 of the Arduino. + + The motor will step one step at a time, very slowly. You can use this to + test that you've got the four wires of your stepper wired to the correct + pins. If wired correctly, all steps should be in the same direction. + + Use this also to count the number of steps per revolution of your motor, + if you don't know it. Then plug that number into the oneRevolution + example to see if you got it right. + + Created 30 Nov. 2009 + by Tom Igoe + + */ + +#include + +const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution +// for your motor + +// initialize the Stepper library on pins 8 through 11: +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); + +int stepCount = 0; // number of steps the motor has taken + +void setup() { + // initialize the serial port: + Serial.begin(9600); +} + +void loop() { + // step one step: + myStepper.step(1); + Serial.print("steps:"); + Serial.println(stepCount); + stepCount++; + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino new file mode 100644 index 00000000..27a709a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino @@ -0,0 +1,45 @@ +/* + Stepper Motor Control - speed control + + This program drives a unipolar or bipolar stepper motor. + The motor is attached to digital pins 8 - 11 of the Arduino. + A potentiometer is connected to analog input 0. + + The motor will rotate in a clockwise direction. The higher the potentiometer value, + the faster the motor speed. Because setSpeed() sets the delay between steps, + you may notice the motor is less responsive to changes in the sensor value at + low speeds. + + Created 30 Nov. 2009 + Modified 28 Oct 2010 + by Tom Igoe + + */ + +#include + +const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution +// for your motor + + +// initialize the Stepper library on pins 8 through 11: +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); + +int stepCount = 0; // number of steps the motor has taken + +void setup() { + // nothing to do inside the setup +} + +void loop() { + // read the sensor value: + int sensorReading = analogRead(A0); + // map it to a range from 0 to 100: + int motorSpeed = map(sensorReading, 0, 1023, 0, 100); + // set the motor speed: + if (motorSpeed > 0) { + myStepper.setSpeed(motorSpeed); + // step 1/100 of a revolution: + myStepper.step(stepsPerRevolution / 100); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/README.adoc new file mode 100644 index 00000000..5cfb3d27 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: TFT + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library enables an Arduino board to communicate with the Arduino TFT LCD screen. It simplifies the process for drawing shapes, lines, images, and text to the screen. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/TFTLibrary diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino new file mode 100644 index 00000000..938af388 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino @@ -0,0 +1,108 @@ +/* + + Arduino TFT Bitmap Logo example + + This example reads an image file from a micro-SD card + and draws it on the screen, at random locations. + + In this sketch, the Arduino logo is read from a micro-SD card. + There is a .bmp file included with this sketch. + - open the sketch folder (Ctrl-K or Cmd-K) + - copy the "arduino.bmp" file to a micro-SD + - put the SD into the SD slot of the Arduino TFT module. + + This example code is in the public domain. + + Created 19 April 2013 by Enrico Gueli + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTBitmapLogo + + */ + +// include the necessary libraries +#include +#include +#include // Arduino LCD library + +// pin definitions for the Uno +#define sd_cs 4 +#define lcd_cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +//#define sd_cs 8 +//#define lcd_cs 7 +//#define dc 0 +//#define rst 1 + +TFT TFTscreen = TFT(lcd_cs, dc, rst); + +// this variable represents the image to be drawn on screen +PImage logo; + + +void setup() { + // initialize the GLCD and show a message + // asking the user to open the serial line + TFTscreen.begin(); + TFTscreen.background(255, 255, 255); + + TFTscreen.stroke(0, 0, 255); + TFTscreen.println(); + TFTscreen.println(F("Arduino TFT Bitmap Example")); + TFTscreen.stroke(0, 0, 0); + TFTscreen.println(F("Open Serial Monitor")); + TFTscreen.println(F("to run the sketch")); + + // initialize the serial port: it will be used to + // print some diagnostic info + Serial.begin(9600); + while (!Serial) { + // wait for serial port to connect. Needed for native USB port only + } + + // clear the GLCD screen before starting + TFTscreen.background(255, 255, 255); + + // try to access the SD card. If that fails (e.g. + // no card present), the setup process will stop. + Serial.print(F("Initializing SD card...")); + if (!SD.begin(sd_cs)) { + Serial.println(F("failed!")); + return; + } + Serial.println(F("OK!")); + + // initialize and clear the GLCD screen + TFTscreen.begin(); + TFTscreen.background(255, 255, 255); + + // now that the SD card can be accessed, try to load the + // image file. + logo = TFTscreen.loadImage("arduino.bmp"); + if (!logo.isValid()) { + Serial.println(F("error while loading arduino.bmp")); + } +} + +void loop() { + // don't do anything if the image wasn't loaded correctly. + if (logo.isValid() == false) { + return; + } + + Serial.println(F("drawing image")); + + // get a random location to draw the image at. + // To avoid the image being drawn outside the screen, + // take into account the image size. + int x = random(TFTscreen.width() - logo.width()); + int y = random(TFTscreen.height() - logo.height()); + + // draw the image to the screen + TFTscreen.image(logo, x, y); + + // wait a little bit before drawing again + delay(1500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino new file mode 100644 index 00000000..4e016a0e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino @@ -0,0 +1,64 @@ +/* + + TFT Color Picker + + This example for the Arduino screen reads the input of + potentiometers or analog sensors attached to A0, A1, + and A2 and uses the values to change the screen's color. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTColorPicker + + */ + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +#include // Arduino LCD library +#include + +TFT TFTscreen = TFT(cs, dc, rst); + +void setup() { + // begin serial communication + Serial.begin(9600); + + // initialize the display + TFTscreen.begin(); + + // set the background to white + TFTscreen.background(255, 255, 255); +} + +void loop() { + + // read the values from your sensors and scale them to 0-255 + int redVal = map(analogRead(A0), 0, 1023, 0, 255); + int greenVal = map(analogRead(A1), 0, 1023, 0, 255); + int blueVal = map(analogRead(A2), 0, 1023, 0, 255); + + // draw the background based on the mapped values + TFTscreen.background(redVal, greenVal, blueVal); + + // send the values to the Serial Monitor + Serial.print("background("); + Serial.print(redVal); + Serial.print(" , "); + Serial.print(greenVal); + Serial.print(" , "); + Serial.print(blueVal); + Serial.println(")"); + + // wait for a moment + delay(33); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino new file mode 100644 index 00000000..06a58c3a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino @@ -0,0 +1,73 @@ +/* + Arduino TFT text example + + This example demonstrates how to draw text on the + TFT with an Arduino. The Arduino reads the value + of an analog sensor attached to pin A0, and writes + the value to the LCD screen, updating every + quarter second. + + This example code is in the public domain + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTDisplayText + + */ + +#include // Arduino LCD library +#include + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); + +// char array to print to the screen +char sensorPrintout[4]; + +void setup() { + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // write the static text to the screen + // set the font color to white + TFTscreen.stroke(255, 255, 255); + // set the font size + TFTscreen.setTextSize(2); + // write the text to the top left corner of the screen + TFTscreen.text("Sensor Value :\n ", 0, 0); + // set the font size very large for the loop + TFTscreen.setTextSize(5); +} + +void loop() { + + // Read the value of the sensor on A0 + String sensorVal = String(analogRead(A0)); + + // convert the reading to a char array + sensorVal.toCharArray(sensorPrintout, 4); + + // set the font color + TFTscreen.stroke(255, 255, 255); + // print the sensor value + TFTscreen.text(sensorPrintout, 0, 20); + // wait for a moment + delay(250); + // erase the text you just wrote + TFTscreen.stroke(0, 0, 0); + TFTscreen.text(sensorPrintout, 0, 20); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino new file mode 100644 index 00000000..dcdf716e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino @@ -0,0 +1,83 @@ +/* + + TFT EtchASketch + + This example for the Arduino screen draws a white point + on the GLCD based on the values of 2 potentiometers. + To clear the screen, press a button attached to pin 2. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTEtchASketch + + */ + +#include // Arduino LCD library +#include + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +TFT TFTscreen = TFT(cs, dc, rst); + +// initial position of the cursor +int xPos = TFTscreen.width() / 2; +int yPos = TFTscreen.height() / 2; + +// pin the erase switch is connected to +int erasePin = 2; + +void setup() { + // declare inputs + pinMode(erasePin, INPUT); + // initialize the screen + TFTscreen.begin(); + // make the background black + TFTscreen.background(0, 0, 0); +} + +void loop() { + // read the potentiometers on A0 and A1 + int xValue = analogRead(A0); + int yValue = analogRead(A1); + + // map the values and update the position + xPos = xPos + (map(xValue, 0, 1023, 2, -2)); + yPos = yPos + (map(yValue, 0, 1023, -2, 2)); + + // don't let the point go past the screen edges + if (xPos > 159) { + (xPos = 159); + } + + if (xPos < 0) { + (xPos = 0); + } + if (yPos > 127) { + (yPos = 127); + } + + if (yPos < 0) { + (yPos = 0); + } + + // draw the point + TFTscreen.stroke(255, 255, 255); + TFTscreen.point(xPos, yPos); + + // read the value of the pin, and erase the screen if pressed + if (digitalRead(erasePin) == HIGH) { + TFTscreen.background(0, 0, 0); + } + + delay(33); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino new file mode 100644 index 00000000..84fa9d79 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino @@ -0,0 +1,69 @@ +/* + + TFT Graph + + This example for an Arduino screen reads + the value of an analog sensor on A0, and + graphs the values on the screen. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTGraph + + */ + +#include // Arduino LCD library +#include + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +TFT TFTscreen = TFT(cs, dc, rst); + +// position of the line on screen +int xPos = 0; + +void setup() { + // initialize the serial port + Serial.begin(9600); + + // initialize the display + TFTscreen.begin(); + + // clear the screen with a pretty color + TFTscreen.background(250, 16, 200); +} + +void loop() { + // read the sensor and map it to the screen height + int sensor = analogRead(A0); + int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height()); + + // print out the height to the Serial Monitor + Serial.println(drawHeight); + + // draw a line in a nice color + TFTscreen.stroke(250, 180, 10); + TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height()); + + // if the graph has reached the screen edge + // erase the screen and start again + if (xPos >= 160) { + xPos = 0; + TFTscreen.background(250, 16, 200); + } else { + // increment the horizontal position: + xPos++; + } + + delay(16); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino new file mode 100644 index 00000000..192838ac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino @@ -0,0 +1,131 @@ +/* + + TFT Pong + + This example for the Arduino screen reads the values + of 2 potentiometers to move a rectangular platform + on the x and y axes. The platform can intersect + with a ball causing it to bounce. + + This example code is in the public domain. + + Created by Tom Igoe December 2012 + Modified 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTPong + + */ + +#include // Arduino LCD library +#include + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +TFT TFTscreen = TFT(cs, dc, rst); + +// variables for the position of the ball and paddle +int paddleX = 0; +int paddleY = 0; +int oldPaddleX, oldPaddleY; +int ballDirectionX = 1; +int ballDirectionY = 1; + +int ballSpeed = 10; // lower numbers are faster + +int ballX, ballY, oldBallX, oldBallY; + +void setup() { + // initialize the display + TFTscreen.begin(); + // black background + TFTscreen.background(0, 0, 0); +} + +void loop() { + + // save the width and height of the screen + int myWidth = TFTscreen.width(); + int myHeight = TFTscreen.height(); + + // map the paddle's location to the position of the potentiometers + paddleX = map(analogRead(A0), 512, -512, 0, myWidth) - 20 / 2; + paddleY = map(analogRead(A1), 512, -512, 0, myHeight) - 5 / 2; + + // set the fill color to black and erase the previous + // position of the paddle if different from present + TFTscreen.fill(0, 0, 0); + + if (oldPaddleX != paddleX || oldPaddleY != paddleY) { + TFTscreen.rect(oldPaddleX, oldPaddleY, 20, 5); + } + + // draw the paddle on screen, save the current position + // as the previous. + TFTscreen.fill(255, 255, 255); + + TFTscreen.rect(paddleX, paddleY, 20, 5); + oldPaddleX = paddleX; + oldPaddleY = paddleY; + + // update the ball's position and draw it on screen + if (millis() % ballSpeed < 2) { + moveBall(); + } +} + +// this function determines the ball's position on screen +void moveBall() { + // if the ball goes offscreen, reverse the direction: + if (ballX > TFTscreen.width() || ballX < 0) { + ballDirectionX = -ballDirectionX; + } + + if (ballY > TFTscreen.height() || ballY < 0) { + ballDirectionY = -ballDirectionY; + } + + // check if the ball and the paddle occupy the same space on screen + if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) { + ballDirectionX = -ballDirectionX; + ballDirectionY = -ballDirectionY; + } + + // update the ball's position + ballX += ballDirectionX; + ballY += ballDirectionY; + + // erase the ball's previous position + TFTscreen.fill(0, 0, 0); + + if (oldBallX != ballX || oldBallY != ballY) { + TFTscreen.rect(oldBallX, oldBallY, 5, 5); + } + + + // draw the ball's current position + TFTscreen.fill(255, 255, 255); + TFTscreen.rect(ballX, ballY, 5, 5); + + oldBallX = ballX; + oldBallY = ballY; +} + +// this function checks the position of the ball +// to see if it intersects with the paddle +bool inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { + bool result = false; + + if ((x >= rectX && x <= (rectX + rectWidth)) && (y >= rectY && y <= (rectY + rectHeight))) { + result = true; + } + + return result; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino new file mode 100644 index 00000000..d8aa111a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino @@ -0,0 +1,100 @@ +/* + + Esplora TFT Bitmap Logos + + This example for the Arduino TFT screen is for use + with an Arduino Esplora. + + This example reads an image file from a micro-SD card + and draws it on the screen, at random locations. + + There is a .bmp file included with this sketch. + - open the sketch folder (Ctrl-K or Cmd-K) + - copy the "arduino.bmp" file to a micro-SD + - put the SD into the SD slot of the Arduino LCD module. + + This example code is in the public domain. + + Created 19 April 2013 by Enrico Gueli + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTBitmapLogo + + */ + +// include the necessary libraries +#include +#include +#include +#include // Arduino LCD library + +// the Esplora pin connected to the chip select line for SD card +#define SD_CS 8 + +// this variable represents the image to be drawn on screen +PImage logo; + +void setup() { + // initialize the GLCD and show a message + // asking the user to open the serial line + EsploraTFT.begin(); + EsploraTFT.background(255, 255, 255); + + EsploraTFT.stroke(0, 0, 255); + EsploraTFT.println(); + EsploraTFT.println(F("Arduino LCD Bitmap Example")); + EsploraTFT.stroke(0, 0, 0); + EsploraTFT.println(F("Open Serial Monitor")); + EsploraTFT.println(F("to run the sketch")); + + // initialize the serial port: it will be used to + // print some diagnostic info + Serial.begin(9600); + while (!Serial) { + // wait for serial port to connect. Needed for native USB port only + } + + // try to access the SD card. If that fails (e.g. + // no card present), the Esplora's LED will turn red. + Serial.print(F("Initializing SD card...")); + if (!SD.begin(SD_CS)) { + Serial.println(F("failed!")); + Esplora.writeRed(255); + return; + } + Serial.println("OK!"); + + // clear the GLCD screen before starting + EsploraTFT.background(255, 255, 255); + + // now that the SD card can be accessed, try to load the + // image file. The Esplora LED will turn green or red if + // the loading went OK or not. + Esplora.writeRGB(0, 0, 0); + logo = EsploraTFT.loadImage("arduino.bmp"); + if (logo.isValid()) { + Esplora.writeGreen(255); + } else { + Esplora.writeRed(255); + } +} + +void loop() { + // don't do anything if the image wasn't loaded correctly. + if (logo.isValid() == false) { + return; + } + + Serial.println(F("drawing image")); + + // get a random location to draw the image at. + // To avoid the image being drawn outside the screen, + // take into account the image size. + int x = random(EsploraTFT.width() - logo.width()); + int y = random(EsploraTFT.height() - logo.height()); + + // draw the image to the screen + EsploraTFT.image(logo, x, y); + + // wait a little bit before drawing again + delay(1500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino new file mode 100644 index 00000000..d088642f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino @@ -0,0 +1,51 @@ +/* + + Esplora TFT Color Picker + + This example for the Esplora with an Arduino TFT reads + the input of the joystick and slider, using the values + to change the screen's color. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTColorPicker + + */ + +#include +#include // Arduino LCD library +#include + +void setup() { + Serial.begin(9600); + + // initialize the LCD + EsploraTFT.begin(); + + // start out with a white screen + EsploraTFT.background(255, 255, 255); +} + +void loop() { + + // map the values from sensors + int xValue = map(Esplora.readJoystickX(), -512, 512, 0, 255); // read the joystick's X position + int yValue = map(Esplora.readJoystickY(), -512, 512, 0, 255); // read the joystick's Y position + int slider = map(Esplora.readSlider(), 0, 1023, 0, 255); // read the slider's position + + // change the background color based on the mapped values + EsploraTFT.background(xValue, yValue, slider); + + // print the mapped values to the Serial Monitor + Serial.print("background("); + Serial.print(xValue); + Serial.print(" , "); + Serial.print(yValue); + Serial.print(" , "); + Serial.print(slider); + Serial.println(")"); + + delay(33); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino new file mode 100644 index 00000000..43df1543 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino @@ -0,0 +1,79 @@ +/* + + Esplora TFT EtchASketch + + This example for the Arduino TFT and Esplora draws + a white line on the screen, based on the position + of the joystick. To clear the screen, shake the + Esplora, using the values from the accelerometer. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTEtchASketch + + */ + +#include +#include // Arduino LCD library +#include + +// initial position of the cursor +int xPos = EsploraTFT.width() / 2; +int yPos = EsploraTFT.height() / 2; + +void setup() { + // initialize the display + EsploraTFT.begin(); + + // clear the background + EsploraTFT.background(0, 0, 0); +} + +void loop() { + + int xAxis = Esplora.readJoystickX(); // read the X axis + int yAxis = Esplora.readJoystickY(); // read the Y axis + + // update the position of the line + // depending on the position of the joystick + if (xAxis < 10 && xAxis > -10) { + xPos = xPos; + } else { + xPos = xPos + (map(xAxis, -512, 512, 2, -2)); + } + if (yAxis < 10 && yAxis > -10) { + yAxis = yAxis; + } else { + yPos = yPos + (map(yAxis, -512, 512, -2, 2)); + } + + // don't let the point go past the screen edges + if (xPos > 159) { + (xPos = 159); + } + + if (xPos < 0) { + (xPos = 0); + } + if (yPos > 127) { + (yPos = 127); + } + + if (yPos < 0) { + (yPos = 0); + } + + // draw the point + EsploraTFT.stroke(255, 255, 255); + EsploraTFT.point(xPos, yPos); + + // check the accelerometer values and clear + // the screen if it is being shaken + if (abs(Esplora.readAccelerometer(X_AXIS)) > 200 || abs(Esplora.readAccelerometer(Y_AXIS)) > 200) { + EsploraTFT.background(0, 0, 0); + } + + delay(33); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino new file mode 100644 index 00000000..56fcd52f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino @@ -0,0 +1,55 @@ +/* + + Esplora TFT Graph + + This example for the Esplora with an Arduino TFT reads + the value of the light sensor, and graphs the values on + the screen. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTGraph + + */ + +#include +#include // Arduino LCD library +#include + +// position of the line on screen +int xPos = 0; + +void setup() { + + // initialize the screen + EsploraTFT.begin(); + + // clear the screen with a nice color + EsploraTFT.background(250, 16, 200); +} + +void loop() { + + // read the sensor value + int sensor = Esplora.readLightSensor(); + // map the sensor value to the height of the screen + int graphHeight = map(sensor, 0, 1023, 0, EsploraTFT.height()); + + // draw the line in a pretty color + EsploraTFT.stroke(250, 180, 10); + EsploraTFT.line(xPos, EsploraTFT.height() - graphHeight, xPos, EsploraTFT.height()); + + // if the graph reaches the edge of the screen + // erase it and start over from the other side + if (xPos >= 160) { + xPos = 0; + EsploraTFT.background(250, 16, 200); + } else { + // increment the horizontal position: + xPos++; + } + + delay(16); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino new file mode 100644 index 00000000..d32cb4ff --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino @@ -0,0 +1,62 @@ +/* + + Esplora TFT Horizon + + This example for the Arduino TFT and Esplora draws + a line on the screen that stays level with the ground + as you tilt the Esplora side to side + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTHorizon + + */ + +#include +#include // Arduino LCD library +#include + +// horizontal start and end positions +int yStart = EsploraTFT.height() / 2; +int yEnd = EsploraTFT.height() / 2; + +// previous start and end positions +int oldEndY; +int oldStartY; + +void setup() { + // initialize the display + EsploraTFT.begin(); + // make the background black + EsploraTFT.background(0, 0, 0); +} + +void loop() { + // read the x-axis of the accelerometer + int tilt = Esplora.readAccelerometer(X_AXIS); + + // the values are 100 when tilted to the left + // and -100 when tilted to the right + // map these values to the start and end points + yStart = map(tilt, -100, 100, EsploraTFT.height(), 0); + yEnd = map(tilt, -100, 100, 0, EsploraTFT.height()); + + // if the previous values are different than the current values + // erase the previous line + if (oldStartY != yStart || oldEndY != yEnd) { + EsploraTFT.stroke(0, 0, 0); + EsploraTFT.line(0, oldStartY, EsploraTFT.width(), oldEndY); + } + + // draw the line in magenta + EsploraTFT.stroke(255, 0, 255); + EsploraTFT.line(0, yStart, EsploraTFT.width(), yEnd); + + // save the current start and end points + // to compare in the next loop + oldStartY = yStart; + oldEndY = yEnd; + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino new file mode 100644 index 00000000..f69a2ddc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino @@ -0,0 +1,124 @@ +/* + + Esplora TFT Pong + + This example for the Esplora with an Arduino TFT screen reads + the value of the joystick to move a rectangular platform + on the x and y axes. The platform can intersect with a ball + causing it to bounce. The Esplora's slider adjusts the speed + of the ball. + + This example code is in the public domain. + + Created by Tom Igoe December 2012 + Modified 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTPong + + */ + +#include +#include // Arduino LCD library +#include + +// variables for the position of the ball and paddle +int paddleX = 0; +int paddleY = 0; +int oldPaddleX, oldPaddleY; +int ballDirectionX = 1; +int ballDirectionY = 1; + +int ballX, ballY, oldBallX, oldBallY; + +void setup() { + + Serial.begin(9600); + + // initialize the display + EsploraTFT.begin(); + // set the background to black + EsploraTFT.background(0, 0, 0); +} + +void loop() { + // save the width and height of the screen + int myWidth = EsploraTFT.width(); + int myHeight = EsploraTFT.height(); + + // map the paddle's location to the joystick's position + paddleX = map(Esplora.readJoystickX(), 512, -512, 0, myWidth) - 20 / 2; + paddleY = map(Esplora.readJoystickY(), -512, 512, 0, myHeight) - 5 / 2; + Serial.print(paddleX); + Serial.print(" "); + Serial.println(paddleY); + + // set the fill color to black and erase the previous + // position of the paddle if different from present + EsploraTFT.fill(0, 0, 0); + + if (oldPaddleX != paddleX || oldPaddleY != paddleY) { + EsploraTFT.rect(oldPaddleX, oldPaddleY, 20, 5); + } + + // draw the paddle on screen, save the current position + // as the previous. + EsploraTFT.fill(255, 255, 255); + EsploraTFT.rect(paddleX, paddleY, 20, 5); + oldPaddleX = paddleX; + oldPaddleY = paddleY; + + // read the slider to determine the speed of the ball + int ballSpeed = map(Esplora.readSlider(), 0, 1023, 0, 80) + 1; + if (millis() % ballSpeed < 2) { + moveBall(); + } +} + + +// this function determines the ball's position on screen +void moveBall() { + // if the ball goes offscreen, reverse the direction: + if (ballX > EsploraTFT.width() || ballX < 0) { + ballDirectionX = -ballDirectionX; + } + + if (ballY > EsploraTFT.height() || ballY < 0) { + ballDirectionY = -ballDirectionY; + } + + // check if the ball and the paddle occupy the same space on screen + if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) { + ballDirectionY = -ballDirectionY; + } + + // update the ball's position + ballX += ballDirectionX; + ballY += ballDirectionY; + + // erase the ball's previous position + EsploraTFT.fill(0, 0, 0); + + if (oldBallX != ballX || oldBallY != ballY) { + EsploraTFT.rect(oldBallX, oldBallY, 5, 5); + } + + // draw the ball's current position + EsploraTFT.fill(255, 255, 255); + + EsploraTFT.rect(ballX, ballY, 5, 5); + + oldBallX = ballX; + oldBallY = ballY; +} + +// this function checks the position of the ball +// to see if it intersects with the paddle +bool inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { + bool result = false; + + if ((x >= rectX && x <= (rectX + rectWidth)) && (y >= rectY && y <= (rectY + rectHeight))) { + result = true; + } + + return result; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino new file mode 100644 index 00000000..df3811ec --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino @@ -0,0 +1,64 @@ +/* + + Esplora TFT Temperature Display + + This example for the Arduino TFT screen is for use + with an Arduino Esplora. + + This example reads the temperature of the Esplora's + on board thermisistor and displays it on an attached + LCD screen, updating every second. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTTemp + + */ + +// include the necessary libraries +#include +#include // Arduino LCD library +#include + +char tempPrintout[3]; // array to hold the temperature data + +void setup() { + + // Put this line at the beginning of every sketch that uses the GLCD + EsploraTFT.begin(); + + // clear the screen with a black background + EsploraTFT.background(0, 0, 0); + + // set the text color to magenta + EsploraTFT.stroke(200, 20, 180); + // set the text to size 2 + EsploraTFT.setTextSize(2); + // start the text at the top left of the screen + // this text is going to remain static + EsploraTFT.text("Degrees in C :\n ", 0, 0); + + // set the text in the loop to size 5 + EsploraTFT.setTextSize(5); +} + +void loop() { + + // read the temperature in Celsius and store it in a String + String temperature = String(Esplora.readTemperature(DEGREES_C)); + + // convert the string to a char array + temperature.toCharArray(tempPrintout, 3); + + // set the text color to white + EsploraTFT.stroke(255, 255, 255); + // print the temperature one line below the static text + EsploraTFT.text(tempPrintout, 0, 30); + + delay(1000); + // erase the text for the next loop + EsploraTFT.stroke(0, 0, 0); + EsploraTFT.text(tempPrintout, 0, 30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/README.adoc new file mode 100644 index 00000000..36e6305d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/README.adoc @@ -0,0 +1,39 @@ +:repository-owner: arduino-libraries +:repository-name: Temboo + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino to connect to the Temboo service. + +== License == + +Copyright 2017, Temboo Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +either express or implied. See the License for the specific +language governing permissions and limitations under the License. + +This library includes elements of the Paho MQTT client, used +with permission under the Eclipse Public License - v1.0: + +http://www.eclipse.org/legal/epl-v10.html + +and the Eclipse Distribution License v1.0: + +http://www.eclipse.org/org/documents/edl-v10.php + +The Eclipse MQTT Paho client source is available here: + +http://www.eclipse.org/paho/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/GetYahooWeatherReport.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/GetYahooWeatherReport.ino new file mode 100644 index 00000000..9e2a8fb9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/GetYahooWeatherReport.ino @@ -0,0 +1,113 @@ +/* + GetYahooWeatherReport + + Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + + +// the address for which a weather forecast will be retrieved +String ADDRESS_FOR_FORECAST = "104 Franklin St., New York NY 10013"; + +int numRuns = 1; // execution count, so that this doesn't run forever +int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo should be run + + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) + ; + Bridge.begin(); +} + +void loop() { + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "..."); + + // create a TembooChoreo object to send a Choreo request to Temboo + TembooChoreo GetWeatherByAddressChoreo; + + // invoke the Temboo client + GetWeatherByAddressChoreo.begin(); + + // add your Temboo account info + GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT); + GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY); + + // set the name of the Choreo we want to run + GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress"); + + // set Choreo inputs; in this case, the address for which to retrieve weather data + // the Temboo client provides standardized calls to 100+ cloud APIs + GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST); + + // add an output filter to extract the name of the city. + GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response"); + + // add an output filter to extract the current temperature + GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response"); + + // add an output filter to extract the date and time of the last report. + GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response"); + + // run the Choreo + GetWeatherByAddressChoreo.run(); + + // when the Choreo results are available, print them to the Serial Monitor + while (GetWeatherByAddressChoreo.available()) { + + char c = GetWeatherByAddressChoreo.read(); + Serial.print(c); + } + GetWeatherByAddressChoreo.close(); + } + + Serial.println("Waiting..."); + Serial.println(""); + delay(30000); // wait 30 seconds between GetWeatherByAddress calls +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/ReadATweet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/ReadATweet.ino new file mode 100644 index 00000000..e9f38f82 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/ReadATweet.ino @@ -0,0 +1,172 @@ +/* + ReadATweet + + Demonstrates retrieving the most recent Tweet from a user's home timeline + using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + In order to run this sketch, you'll need to register an application using + the Twitter dev console at https://dev.twitter.com. After creating the + app, you'll find OAuth credentials for that application under the "OAuth Tool" tab. + Substitute these values for the placeholders below. + + This example assumes basic familiarity with Arduino sketches, and that your Yún + is connected to the Internet. + + Want to use another social API with your Arduino Yún? We've got Facebook, + Instagram, Tumblr and more in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. +const String TWITTER_ACCESS_TOKEN = "your-twitter-access-token"; +const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret"; +const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key"; +const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret"; + +int numRuns = 1; // execution count, so this doesn't run forever +int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo should run + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while (!Serial) + ; + Bridge.begin(); +} +void loop() { + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + Serial.println("Running ReadATweet - Run #" + String(numRuns++)); + + TembooChoreo HomeTimelineChoreo; + + // invoke the Temboo client. + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + HomeTimelineChoreo.begin(); + + // set Temboo account credentials + HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT); + HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + HomeTimelineChoreo.setAppKey(TEMBOO_APP_KEY); + + // tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline) + HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline"); + + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/ + // for complete details about the inputs for this Choreo + + HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request + HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); + HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); + HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); + + // next, we'll define two output filters that let us specify the + // elements of the response from Twitter that we want to receive. + // see the examples at http://www.temboo.com/arduino + // for more on using output filters + + // we want the text of the tweet + HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response"); + + // and the name of the author + HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response"); + + + // tell the Process to run and wait for the results. The + // return code will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = HomeTimelineChoreo.run(); + + // a response code of 0 means success; print the API response + if (returnCode == 0) { + + String author; // a String to hold the tweet author's name + String tweet; // a String to hold the text of the tweet + + + // Choreo outputs are returned as key/value pairs, delimited with + // newlines and record/field terminator characters, for example: + // Name1\n\x1F + // Value1\n\x1E + // Name2\n\x1F + // Value2\n\x1E + + // see the examples at http://www.temboo.com/arduino for more details + // we can read this format into separate variables, as follows: + + while (HomeTimelineChoreo.available()) { + // read the name of the output item + String name = HomeTimelineChoreo.readStringUntil('\x1F'); + name.trim(); + + // read the value of the output item + String data = HomeTimelineChoreo.readStringUntil('\x1E'); + data.trim(); + + // assign the value to the appropriate String + if (name == "tweet") { + tweet = data; + } else if (name == "author") { + author = data; + } + } + + Serial.println("@" + author + " - " + tweet); + + } else { + // there was an error + // print the raw output from the Choreo + while (HomeTimelineChoreo.available()) { + char c = HomeTimelineChoreo.read(); + Serial.print(c); + } + } + + HomeTimelineChoreo.close(); + } + + Serial.println("Waiting..."); + delay(90000); // wait 90 seconds between HomeTimeline calls +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/SendATweet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/SendATweet.ino new file mode 100644 index 00000000..d27e4701 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/SendATweet.ino @@ -0,0 +1,138 @@ +/* + SendATweet + + Demonstrates sending a tweet via a Twitter account using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + In order to run this sketch, you'll need to register an application using + the Twitter dev console at https://dev.twitter.com. Note that since this + sketch creates a new tweet, your application will need to be configured with + read+write permissions. After creating the app, you'll find OAuth credentials + for that application under the "OAuth Tool" tab. Substitute these values for + the placeholders below. + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Want to use another social API with your Arduino Yún? We've got Facebook, + Instagram, Tumblr and more in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. +const String TWITTER_ACCESS_TOKEN = "your-twitter-access-token"; +const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret"; +const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key"; +const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret"; + +int numRuns = 1; // execution count, so this sketch doesn't run forever +int maxRuns = 3; // the max number of times the Twitter Update Choreo should run + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) + ; + + Bridge.begin(); +} + +void loop() { + // only try to send the tweet if we haven't already sent it successfully + if (numRuns <= maxRuns) { + + Serial.println("Running SendATweet - Run #" + String(numRuns++) + "..."); + + // define the text of the tweet we want to send + String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds."); + + + TembooChoreo StatusesUpdateChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + StatusesUpdateChoreo.begin(); + + // set Temboo account credentials + StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT); + StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Twitter > Tweets > StatusesUpdate) + StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/ + // for complete details about the inputs for this Choreo + + // add the Twitter account information + StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); + StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); + StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); + + // and the tweet we want to send + StatusesUpdateChoreo.addInput("StatusUpdate", tweetText); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = StatusesUpdateChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! Tweet sent!"); + } else { + // a non-zero return code means there was an error + // read and print the error message + while (StatusesUpdateChoreo.available()) { + char c = StatusesUpdateChoreo.read(); + Serial.print(c); + } + } + StatusesUpdateChoreo.close(); + + // do nothing for the next 90 seconds + Serial.println("Waiting..."); + delay(90000); + } +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/SendAnEmail.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/SendAnEmail.ino new file mode 100644 index 00000000..cc74d583 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/SendAnEmail.ino @@ -0,0 +1,166 @@ +/* + SendAnEmail + + Demonstrates sending an email via a Google Gmail account using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and tutorials at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + Instructions: + + 1. Create a Temboo account: http://www.temboo.com + + 2. Retrieve your Temboo application details: http://www.temboo.com/account/applications + + 3. Replace the values in the TembooAccount.h tab with your Temboo application details + + 4. You'll also need a Gmail account. Update the placeholder Gmail address in the code + below with your own details. + + https://www.gmail.com + + 5. Once you have a Gmail account, turn on 2-step authentication, and create an application-specific + password to allow Temboo to access your Google account: https://www.google.com/landing/2step/. + + 6. After you've enabled 2-Step authentication, you'll need to create an App Password: + https://security.google.com/settings/security/apppasswords + + 7. In the "Select app" dropdown menu, choose "Other", and give your app a name (e.g., TembooApp). + + 8. Click "Generate". You'll be given a 16-digit passcode that can be used to access your Google Account from Temboo. + + 9. Copy and paste this password into the code below, updating the GMAIL_APP_PASSWORD variable + + 10. Upload the sketch to your Arduino Yún and open the Serial Monitor + + NOTE: You can test this Choreo and find the latest instructions on our website: + https://temboo.com/library/Library/Google/Gmail/SendEmail + + You can also find an in-depth version of this example here: + https://temboo.com/arduino/yun/send-an-email + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. + +// your Gmail username, formatted as a complete email address, eg "bob.smith@gmail.com" +const String GMAIL_USER_NAME = "xxxxxxxxxx"; + +// your application specific password (see instructions above) +const String GMAIL_APP_PASSWORD = "xxxxxxxxxx"; + +// the email address you want to send the email to, eg "jane.doe@temboo.com" +const String TO_EMAIL_ADDRESS = "xxxxxxxxxx"; + +// a flag to indicate whether we've tried to send the email yet or not +bool attempted = false; + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) + ; + + Bridge.begin(); +} + +void loop() { + // only try to send the email if we haven't already tried + if (!attempted) { + + Serial.println("Running SendAnEmail..."); + + TembooChoreo SendEmailChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + SendEmailChoreo.begin(); + + // set Temboo account credentials + SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); + SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SendEmailChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Google > Gmail > SendEmail) + SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); + + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/ + // for complete details about the inputs for this Choreo + + // the first input is your Gmail email address. + SendEmailChoreo.addInput("Username", GMAIL_USER_NAME); + // next is your application specific password + SendEmailChoreo.addInput("Password", GMAIL_APP_PASSWORD); + // who to send the email to + SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS); + // then a subject line + SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature"); + + // next comes the message body, the main content of the email + SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!"); + + // tell the Choreo to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SendEmailChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! Email sent!"); + } else { + // a non-zero return code means there was an error + // read and print the error message + while (SendEmailChoreo.available()) { + char c = SendEmailChoreo.read(); + Serial.print(c); + } + } + SendEmailChoreo.close(); + + // set the flag showing we've tried + attempted = true; + } +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/SendAnSMS.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/SendAnSMS.ino new file mode 100644 index 00000000..0f3340ef --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/SendAnSMS.ino @@ -0,0 +1,154 @@ +/* + SendAnSMS + + Demonstrates sending an SMS via Twilio using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + Since this sketch uses Twilio to send the SMS, you'll also need a valid + Twilio account. You can create one for free at https://www.twilio.com. + + The sketch needs your Twilio phone number, along with + the Account SID and Auth Token you get when you register with Twilio. + Make sure to use the Account SID and Auth Token from your Twilio Dashboard + (not your test credentials from the Dev Tools panel). + + Also note that if you're using a free Twilio account, you'll need to verify + the phone number to which messages are being sent by going to twilio.com and following + the instructions under the "Numbers > Verified Caller IDs" tab (this restriction + doesn't apply if you have a paid Twilio account). + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + + + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. + +// the Account SID from your Twilio account +const String TWILIO_ACCOUNT_SID = "xxxxxxxxxx"; + +// the Auth Token from your Twilio account +const String TWILIO_AUTH_TOKEN = "xxxxxxxxxx"; + +// your Twilio phone number, e.g., "+1 555-222-1212" +const String TWILIO_NUMBER = "xxxxxxxxxx"; + +// the number to which the SMS should be sent, e.g., "+1 555-222-1212" +const String RECIPIENT_NUMBER = "xxxxxxxxxx"; + +// a flag to indicate whether we've attempted to send the SMS yet or not +bool attempted = false; + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) + ; + + Bridge.begin(); +} + +void loop() { + // only try to send the SMS if we haven't already sent it successfully + if (!attempted) { + + Serial.println("Running SendAnSMS..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo SendSMSChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + SendSMSChoreo.begin(); + + // set Temboo account credentials + SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT); + SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SendSMSChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Twilio > SMSMessages > SendSMS) + SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/ + // for complete details about the inputs for this Choreo + + // the first input is a your AccountSID + SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID); + + // next is your Auth Token + SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN); + + // next is your Twilio phone number + SendSMSChoreo.addInput("From", TWILIO_NUMBER); + + // next, what number to send the SMS to + SendSMSChoreo.addInput("To", RECIPIENT_NUMBER); + + // finally, the text of the message to send + SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!"); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SendSMSChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! SMS sent!"); + } else { + // a non-zero return code means there was an error + // read and print the error message + while (SendSMSChoreo.available()) { + char c = SendSMSChoreo.read(); + Serial.print(c); + } + } + SendSMSChoreo.close(); + + // set the flag indicating we've tried once. + attempted = true; + } +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino new file mode 100644 index 00000000..11781fa8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino @@ -0,0 +1,200 @@ +/* + SendDataToGoogleSpreadsheet + + Demonstrates appending a row of data to a Google spreadsheet using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and tutorials at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + Instructions: + + 1. Create a Temboo account: http://www.temboo.com + + 2. Retrieve your Temboo application details: http://www.temboo.com/account/applications + + 3. Replace the values in the TembooAccount.h tab with your Temboo application details + + 4. You'll also need a Google Spreadsheet that includes a title in the first row + of each column that data will be written to. This example assumes there are two columns. + The first column is the time (in milliseconds) that the row was appended, and the second + column is a sensor value. In other words, your spreadsheet should look like: + + Time | Sensor Value | + ------+----------------- + | | + + 5. Google Spreadsheets requires you to authenticate via OAuth. Follow the steps + in the link below to find your ClientID, ClientSecret, and RefreshToken, and then + use those values to overwrite the placeholders in the code below. + + https://temboo.com/library/Library/Google/OAuth/ + + For the scope field, you need to use: https://www.googleapis.com/auth/spreadsheets + + Here's a video outlines how Temboo helps with the OAuth process: + + https://www.temboo.com/videos#oauthchoreos + + And here's a more in-depth version of this example on our website: + + https://temboo.com/arduino/yun/update-google-spreadsheet + + 6. Next, upload the sketch to your Arduino Yún and open the Serial Monitor + + Note: you can test this Choreo and find the latest instructions on our website: + https://temboo.com/library/Library/Google/Sheets/AppendValues/ + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. + +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information, + // as described in the footer comment below + + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. + +// the clientID found in Google's Developer Console under API Manager > Credentials +const String CLIENT_ID = "your-client-id"; + +// the clientSecret found in Google's Developer Console under API Manager > Credentials +const String CLIENT_SECRET = "your-client-secret"; + +// returned after running FinalizeOAuth +const String REFRESH_TOKEN = "your-oauth-refresh-token"; + +// The ID of the spreadsheet you want to send data to +// which can be found in the URL when viewing your spreadsheet at Google. For example, +// the ID in the URL below is: "1tvFW2n-xFFJCE1q5j0HTetOsDhhgw7_998_K4sFtk" +// Sample URL: https://docs.google.com/spreadsheets/d/1tvFW2n-xFFJCE1q5j0HTetOsDhhgw7_998_K4sFtk/edit +const String SPREADSHEET_ID = "your-spreadsheet-id"; + +const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds) + +// the last time we ran the Choreo +// (initialized to 60 seconds ago so the +// Choreo is run immediately when we start up) +unsigned long lastRun = (unsigned long)-60000; + +void setup() { + + // for debugging, wait until a serial console is connected + Serial.begin(9600); + delay(4000); + while (!Serial) + ; + + Serial.print("Initializing the bridge..."); + Bridge.begin(); + Serial.println("Done"); +} + +void loop() { + // get the number of milliseconds this sketch has been running + unsigned long now = millis(); + + // run again if it's been 60 seconds since we last ran + if (now - lastRun >= RUN_INTERVAL_MILLIS) { + + // remember 'now' as the last time we ran the Choreo + lastRun = now; + + Serial.println("Getting sensor value..."); + + // get the value we want to append to our spreadsheet + unsigned long sensorValue = getSensorValue(); + + Serial.println("Appending value to spreadsheet..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo AppendValuesChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + AppendValuesChoreo.begin(); + + // set Temboo account credentials + AppendValuesChoreo.setAccountName(TEMBOO_ACCOUNT); + AppendValuesChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + AppendValuesChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Google > Sheets > AppendValues) + AppendValuesChoreo.setChoreo("/Library/Google/Sheets/AppendValues"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Google/Sheets/AppendValues/ + // for complete details about the inputs for this Choreo + + // your Google application client ID + AppendValuesChoreo.addInput("ClientID", CLIENT_ID); + // your Google application client secret + AppendValuesChoreo.addInput("ClientSecret", CLIENT_SECRET); + // your Google OAuth refresh token + AppendValuesChoreo.addInput("RefreshToken", REFRESH_TOKEN); + + // the ID of the spreadsheet you want to append to + AppendValuesChoreo.addInput("SpreadsheetID", SPREADSHEET_ID); + + // convert the time and sensor values to a comma separated string + String rowData = "[[\"" + String(now) + "\", \"" + String(sensorValue) + "\"]]"; + + // add the RowData input item + AppendValuesChoreo.addInput("Values", rowData); + + // run the Choreo and wait for the results + // The return code (returnCode) will indicate success or failure + unsigned int returnCode = AppendValuesChoreo.run(); + + // return code of zero (0) means success + if (returnCode == 0) { + Serial.println("Success! Appended " + rowData); + Serial.println(""); + } else { + // return code of anything other than zero means failure + // read and display any error messages + while (AppendValuesChoreo.available()) { + char c = AppendValuesChoreo.read(); + Serial.print(c); + } + } + + AppendValuesChoreo.close(); + } +} + +// this function simulates reading the value of a sensor +unsigned long getSensorValue() { + return analogRead(A0); +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/TembooDeviceConfig/TembooDeviceConfig.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/TembooDeviceConfig/TembooDeviceConfig.ino new file mode 100644 index 00000000..9549dda4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/TembooDeviceConfig/TembooDeviceConfig.ino @@ -0,0 +1,97 @@ +// Copyright 2017, Temboo Inc. + +#include + +void setup() { + // initialize the Bridge + Bridge.begin(); + Serial.begin(9600); + Process p; + + //intro message + Serial.println("**** Temboo Cloud Controls ****\n"); + + // update the package list + Serial.print("Updating package listings..."); + p.runShellCommand("opkg update"); + int returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed. Make sure your device is connected to the internet properly."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + // upgrade the Temboo package + Serial.print("Updating Temboo..."); + p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/temboo_1.4.0-1_ar71xx.ipk"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // install python openssl to allow for SSL connections + Serial.print("Installing python-openssl..."); + p.runShellCommand("opkg install python-openssl"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // Installing twisted web to work with CoAP gateway + Serial.print("Installing twisted-web..."); + p.runShellCommand("opkg install twisted-web"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // Configuring zope + Serial.print("Configuring zope..."); + p.runShellCommand("touch /usr/lib/python2.7/site-packages/zope/__init__.py"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + Serial.println("Update Complete - your Yun is ready for Cloud Controls!"); +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino new file mode 100644 index 00000000..7f30041c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino @@ -0,0 +1,171 @@ +/* + ToxicFacilitiesSearch + + Demonstrates making a request to the Envirofacts API using Temboo from an Arduino Yún. + This example retrieves the names and addresses of EPA-regulated facilities in the + Toxins Release Inventory (TRI) database within a given zip code. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + +// the zip code to search for toxin-emitting facilities +String US_ZIP_CODE = "11215"; + +int numRuns = 1; // execution count, so that this doesn't run forever +int maxRuns = 10; // max number of times the Envirofacts FacilitiesSearch Choreo should be run + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while (!Serial) + ; + Bridge.begin(); +} + +void loop() { + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo FacilitiesSearchByZipChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + FacilitiesSearchByZipChoreo.begin(); + + // set Temboo account credentials + FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT); + FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip) + FacilitiesSearchByZipChoreo.setChoreo("/Library/EnviroFacts/Toxins/FacilitiesSearchByZip"); + + // set Choreo inputs; in this case, the US zip code for which to retrieve toxin release data + // the Temboo client provides standardized calls to 100+ cloud APIs + FacilitiesSearchByZipChoreo.addInput("Zip", US_ZIP_CODE); + + // specify two output filters, to help simplify the Envirofacts API results. + // see the tutorials on using Temboo SDK output filters at http://www.temboo.com/arduino + FacilitiesSearchByZipChoreo.addOutputFilter("fac", "FACILITY_NAME", "Response"); + + FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response"); + + // run the Choreo + unsigned int returnCode = FacilitiesSearchByZipChoreo.run(); + if (returnCode == 0) { + String facilities; + String addresses; + + // when the Choreo results are available, process them. + // the output filters we specified will return comma delimited + // lists containing the name and street address of the facilities + // located in the specified zip code. + while (FacilitiesSearchByZipChoreo.available()) { + String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F'); + name.trim(); + + String data = FacilitiesSearchByZipChoreo.readStringUntil('\x1E'); + data.trim(); + + if (name == "fac") { + facilities = data; + } else if (name == "addr") { + addresses = data; + } + } + FacilitiesSearchByZipChoreo.close(); + + // parse the comma delimited lists of facilities to join the + // name with the address and print it to the Serial Monitor + if (facilities.length() > 0) { + int i = -1; + int facilityStart = 0; + int addressStart = 0; + String facility; + String address; + do { + i = facilities.indexOf(',', facilityStart); + if (i >= 0) { + facility = facilities.substring(facilityStart, i); + facilityStart = i + 1; + } + + i = addresses.indexOf(',', addressStart); + if (i >= 0) { + address = addresses.substring(addressStart, i); + addressStart = i + 1; + } + + if (i >= 0) { + printResult(facility, address); + } + + } while (i >= 0); + facility = facilities.substring(facilityStart); + address = addresses.substring(addressStart); + printResult(facility, address); + } else { + Serial.println("No facilities found in zip code " + US_ZIP_CODE); + } + } else { + while (FacilitiesSearchByZipChoreo.available()) { + char c = FacilitiesSearchByZipChoreo.read(); + Serial.print(c); + } + } + } + Serial.println("Waiting..."); + Serial.println(""); + delay(30000); // wait 30 seconds between calls +} + +// a simple utility function, to output the facility name and address in the Serial Monitor. +void printResult(String facility, String address) { + Serial.print(facility); + Serial.print(" - "); + Serial.println(address); +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/UpdateFacebookStatus.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/UpdateFacebookStatus.ino new file mode 100644 index 00000000..08ac96cc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/UpdateFacebookStatus.ino @@ -0,0 +1,133 @@ +/* + UpdateFacebookStatus + + Demonstrates sending a Facebook status update using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + In order to run this sketch, you'll need to register an application using + the Facebook dev console at https://developers.facebook.com/apps -- after creating + the app, log in to Temboo and visit https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/ + to use our OAuth Wizard (or OAuth Choreos) to obtain a Facebook access token. + Substitute your access token for the placeholder value of FACEBOOK_ACCESS_TOKEN below. + + This example assumes basic familiarity with Arduino sketches, and that your Yún + is connected to the Internet. + + Want to use another social API with your Arduino Yún? We've got Twitter, + Instagram, Tumblr and more in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information, + // as described in the footer comment below + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use a #define statement to specify this value in a .h file. + +// the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos +const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx"; + + +int numRuns = 1; // execution count, so this sketch doesn't run forever +int maxRuns = 10; // the max number of times the Facebook SetStatus Choreo should run + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while (!Serial) + ; + Bridge.begin(); +} + +void loop() { + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "..."); + + // Define the status message we want to post on Facebook; since Facebook + // doesn't allow duplicate status messages, we'll include a changing value. + String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!"; + + // define the Process that will be used to call the "temboo" client + TembooChoreo SetStatusChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + SetStatusChoreo.begin(); + + // set Temboo account credentials + SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT); + SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SetStatusChoreo.setAppKey(TEMBOO_APP_KEY); + + // tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus) + SetStatusChoreo.setChoreo("/Library/Facebook/Publishing/SetStatus"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/ + // for complete details about the inputs for this Choreo + + SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN); + SetStatusChoreo.addInput("Message", statusMsg); + + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SetStatusChoreo.run(); + + // print the response code and API response. + Serial.println("Response code: " + String(returnCode)); + + // note that in this case, we're just printing the raw response from Facebook. + // see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino + // for information on how to filter this data + while (SetStatusChoreo.available()) { + char c = SetStatusChoreo.read(); + Serial.print(c); + } + + SetStatusChoreo.close(); + } + + Serial.println("Waiting..."); + Serial.println(""); + + delay(30000); // wait 30 seconds between SetStatus calls +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/TembooAccount.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/TembooAccount.h new file mode 100644 index 00000000..5261ed7a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/TembooAccount.h @@ -0,0 +1,3 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/UploadToDropbox.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/UploadToDropbox.ino new file mode 100644 index 00000000..48f1e8db --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/UploadToDropbox.ino @@ -0,0 +1,208 @@ +/* + UploadToDropbox + + Demonstrates uploading a file to a Dropbox account using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + You'll also need a valid Dropbox app and accompanying OAuth credentials. + To create a Dropbox app, visit https://www.dropbox.com/developers/apps and + do the following: + + 1. Create a "Dropbox API app" + 2. Select "Files and datastores" + 3. Select "Yes - my app only needs access to the files it creates." + + Once you've created your app, follow the instructions at + https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize + OAuth Choreos. These Choreos complete the OAuth handshake and retrieve your Dropbox OAuth access tokens. + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. + +// your Dropbox app key, available on the Dropbox developer console after registering an app +const String DROPBOX_APP_KEY = "xxxxxxxxxx"; + +// your Dropbox app secret, available on the Dropbox developer console after registering an app +const String DROPBOX_APP_SECRET = "xxxxxxxxxx"; + +// your Dropbox access token, which is returned by the FinalizeOAuth Choreo +const String DROPBOX_ACCESS_TOKEN = "xxxxxxxxxx"; + +// your Dropbox access token secret, which is returned by the FinalizeOAuth Choreo +const String DROPBOX_ACCESS_TOKEN_SECRET = "xxxxxxxxxx"; + + +bool success = false; // a flag to indicate whether we've uploaded the file yet + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while (!Serial) + ; + Bridge.begin(); +} + +void loop() { + // only try to upload the file if we haven't already done so + if (!success) { + + Serial.println("Base64 encoding data to upload..."); + + // base64 encode the data to upload + String base64EncodedData = base64Encode("Hello, Arduino!"); + + + Serial.println("Uploading data to Dropbox..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo UploadFileChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + UploadFileChoreo.begin(); + + // set Temboo account credentials + UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT); + UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + UploadFileChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Dropbox > FilesAndMetadata > UploadFile) + UploadFileChoreo.setChoreo("/Library/Dropbox/FilesAndMetadata/UploadFile"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/ + // for complete details about the inputs for this Choreo + + // first specify the name of the file to create/update on Dropbox + UploadFileChoreo.addInput("FileName", "ArduinoTest.txt"); + + // next, the root folder on Dropbox relative to which the file path is specified. + // to work with the Dropbox app you created earlier, this should be left as "sandbox" + // if your Dropbox app has full access to your files, specify "dropbox" + UploadFileChoreo.addInput("Root", "sandbox"); + + // next, the Base64 encoded file data to upload + UploadFileChoreo.addInput("FileContents", base64EncodedData); + + // finally, the Dropbox OAuth credentials defined above + UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET); + UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN); + UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET); + UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = UploadFileChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! File uploaded!"); + success = true; + } else { + // a non-zero return code means there was an error + Serial.println("Uh-oh! Something went wrong!"); + } + + // print out the full response to the Serial Monitor in all + // cases, just for debugging + while (UploadFileChoreo.available()) { + char c = UploadFileChoreo.read(); + Serial.print(c); + } + UploadFileChoreo.close(); + + Serial.println("Waiting..."); + } + + delay(30000); // wait 30 seconds between upload attempts +} + + +/* + A utility function to Base64 encode the specified string + by calling a Temboo Utilities Choreo. +*/ +String base64Encode(String toEncode) { + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo Base64EncodeChoreo; + + // invoke the Temboo client + Base64EncodeChoreo.begin(); + + // set Temboo account credentials + Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT); + Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Utilities > Encoding > Base64Encode) + Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode"); + + // set Choreo inputs + Base64EncodeChoreo.addInput("Text", toEncode); + + // run the Choreo + Base64EncodeChoreo.run(); + + // read in the Choreo results, and return the "Base64EncodedText" output value. + // see http://www.temboo.com/arduino for more details on using Choreo outputs. + while (Base64EncodeChoreo.available()) { + // read the name of the output item + String name = Base64EncodeChoreo.readStringUntil('\x1F'); + name.trim(); + + // read the value of the output item + String data = Base64EncodeChoreo.readStringUntil('\x1E'); + data.trim(); + + if (name == "Base64EncodedText") { + return data; + } + } +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/YunShield/TembooDeviceConfig/TembooDeviceConfig.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/YunShield/TembooDeviceConfig/TembooDeviceConfig.ino new file mode 100644 index 00000000..42b421e8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/Temboo/examples/YunShield/TembooDeviceConfig/TembooDeviceConfig.ino @@ -0,0 +1,99 @@ +// Copyright 2017, Temboo Inc. + +#include + +void setup() { + // initialize the Bridge + Bridge.begin(); + Serial.begin(9600); + Process p; + + //intro message + Serial.println("**** Temboo Cloud Controls ****\n"); + + // update the package list + Serial.print("Updating package listings..."); + p.runShellCommand("opkg update"); + int returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed. Make sure your device is connected to the internet properly."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + // upgrade the Temboo package + Serial.print("Updating Temboo..."); + p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/temboo_1.3.1-1_ar71xx.ipk --force-depends"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + Serial.println("Error number: " + String(returnCode)); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // install python openssl to allow for for SSL connections + Serial.print("Installing python-openssl..."); + p.runShellCommand("opkg install python-openssl"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // Installing twisted web to work with CoAP gateway + Serial.print("Installing twisted-web..."); + p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/twisted-web_2.5.0-1_ar71xx.ipk --force-depends"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // Configuring zope + Serial.print("Configuring zope..."); + p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/zope-interface_2.5.0-1_ar71xx.ipk --force-depends"); + returnCode = p.exitValue(); + if (returnCode == 0) { + p.runShellCommand("touch /usr/lib/python2.7/site-packages/zope/__init__.py"); + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while (p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + + Serial.println("Update Complete - your Yun is ready for Cloud Controls!"); +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/README.adoc new file mode 100644 index 00000000..9a06c1bf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/README.adoc @@ -0,0 +1,32 @@ +:repository-owner: arduino-libraries +:repository-name: USBHost + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The USBHost library allows an Arduino Due board to appear as a USB host, enabling it to communicate with peripherals like USB mice and keyboards. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2012 Arduino LLC. All right reserved. +Copyright (c) 2011 Circuits At Home, LTD. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino new file mode 100644 index 00000000..df5186bc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino @@ -0,0 +1,65 @@ +/* + + ADK Terminal Test + + This demonstrates USB Host connectivity between an + Android phone and an Arduino Due. + + The ADK for the Arduino Due is a work in progress + For additional information on the Arduino ADK visit + https://web.archive.org/web/20170503104018/http://labs.arduino.cc/ADK/Index + + created 27 June 2012 + by Cristian Maglie + +*/ + +#include "variant.h" +#include +#include + +// Accessory descriptor. It's how Arduino identifies itself to Android. +char applicationName[] = "Arduino_Terminal"; // the app on your phone +char accessoryName[] = "Arduino Due"; // your Arduino board +char companyName[] = "Arduino SA"; + +// Make up anything you want for these +char versionNumber[] = "1.0"; +char serialNumber[] = "1"; +char url[] = "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk"; + +USBHost Usb; +ADK adk(&Usb, companyName, applicationName, accessoryName, versionNumber, url, serialNumber); + +void setup() { + cpu_irq_enable(); + printf("\r\nADK demo start\r\n"); + delay(200); +} + +#define RCVSIZE 128 + +void loop() { + uint8_t buf[RCVSIZE]; + uint32_t nbread = 0; + char helloworld[] = "Hello World!\r\n"; + + Usb.Task(); + + if (adk.isReady()) { + /* Write hello string to ADK */ + adk.write(strlen(helloworld), (uint8_t *)helloworld); + + delay(1000); + + /* Read data from ADK and print to UART */ + adk.read(&nbread, RCVSIZE, buf); + if (nbread > 0) { + printf("RCV: "); + for (uint32_t i = 0; i < nbread; ++i) { + printf("%c", (char)buf[i]); + } + printf("\r\n"); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/KeyboardController/KeyboardController.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/KeyboardController/KeyboardController.ino new file mode 100644 index 00000000..667f2d46 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/KeyboardController/KeyboardController.ino @@ -0,0 +1,89 @@ +/* + Keyboard Controller Example + + Shows the output of a USB Keyboard connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + http://www.arduino.cc/en/Tutorial/KeyboardController + + This sample code is part of the public domain. + */ + + +// Require keyboard control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach keyboard controller to USB +KeyboardController keyboard(usb); + +// This function intercepts key press +void keyPressed() { + Serial.print("Pressed: "); + printKey(); +} + +// This function intercepts key release +void keyReleased() { + Serial.print("Released: "); + printKey(); +} + +void printKey() { + // getOemKey() returns the OEM-code associated with the key + Serial.print(" key:"); + Serial.print(keyboard.getOemKey()); + + // getModifiers() returns a bits field with the modifiers-keys + int mod = keyboard.getModifiers(); + Serial.print(" mod:"); + Serial.print(mod); + + Serial.print(" => "); + + if (mod & LeftCtrl) { + Serial.print("L-Ctrl "); + } + if (mod & LeftShift) { + Serial.print("L-Shift "); + } + if (mod & Alt) { + Serial.print("Alt "); + } + if (mod & LeftCmd) { + Serial.print("L-Cmd "); + } + if (mod & RightCtrl) { + Serial.print("R-Ctrl "); + } + if (mod & RightShift) { + Serial.print("R-Shift "); + } + if (mod & AltGr) { + Serial.print("AltGr "); + } + if (mod & RightCmd) { + Serial.print("R-Cmd "); + } + + // getKey() returns the ASCII translation of OEM key + // combined with modifiers. + Serial.write(keyboard.getKey()); + Serial.println(); +} + +void setup() { + Serial.begin(9600); + Serial.println("Program started"); + delay(200); +} + +void loop() { + // Process USB tasks + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/MouseController/MouseController.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/MouseController/MouseController.ino new file mode 100644 index 00000000..c1de6e68 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/USBHost/examples/MouseController/MouseController.ino @@ -0,0 +1,90 @@ +/* + Mouse Controller Example + + Shows the output of a USB Mouse connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + http://www.arduino.cc/en/Tutorial/MouseController + + This sample code is part of the public domain. + */ + +// Require mouse control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach mouse controller to USB +MouseController mouse(usb); + +// variables for mouse button states +bool leftButton = false; +bool middleButton = false; +bool rightButton = false; + +// This function intercepts mouse movements +void mouseMoved() { + Serial.print("Move: "); + Serial.print(mouse.getXChange()); + Serial.print(", "); + Serial.println(mouse.getYChange()); +} + +// This function intercepts mouse movements while a button is pressed +void mouseDragged() { + Serial.print("DRAG: "); + Serial.print(mouse.getXChange()); + Serial.print(", "); + Serial.println(mouse.getYChange()); +} + +// This function intercepts mouse button press +void mousePressed() { + Serial.print("Pressed: "); + if (mouse.getButton(LEFT_BUTTON)) { + Serial.print("L"); + leftButton = true; + } + if (mouse.getButton(MIDDLE_BUTTON)) { + Serial.print("M"); + middleButton = true; + } + if (mouse.getButton(RIGHT_BUTTON)) { + Serial.print("R"); + Serial.println(); + rightButton = true; + } +} + +// This function intercepts mouse button release +void mouseReleased() { + Serial.print("Released: "); + if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) { + Serial.print("L"); + leftButton = false; + } + if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) { + Serial.print("M"); + middleButton = false; + } + if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) { + Serial.print("R"); + rightButton = false; + } + Serial.println(); +} + +void setup() { + Serial.begin(9600); + Serial.println("Program started"); + delay(200); +} + +void loop() { + // Process USB tasks + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/README.adoc new file mode 100644 index 00000000..057e684b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/README.adoc @@ -0,0 +1,34 @@ +:repository-owner: arduino-libraries +:repository-name: WiFi + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +With the Arduino WiFi Shield, this library allows an Arduino board to connect to the internet. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2011-2014 Arduino LLC. All right reserved. +Copyright (C) 2006-2008, Atmel Corporation All rights reserved. +Copyright (c) 2001-2004 Swedish Institute of Computer Science. +Copyright (c) 2009-2010, H&D Wireless AB All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino new file mode 100644 index 00000000..f0d7c5d4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -0,0 +1,127 @@ +/* + + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +char ssid[] = "yourNetwork"; // the name of your network +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to open SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + Serial.print(mac[5], HEX); + Serial.print(":"); + Serial.print(mac[4], HEX); + Serial.print(":"); + Serial.print(mac[3], HEX); + Serial.print(":"); + Serial.print(mac[2], HEX); + Serial.print(":"); + Serial.print(mac[1], HEX); + Serial.print(":"); + Serial.println(mac[0], HEX); + + // print your subnet mask: + IPAddress subnet = WiFi.subnetMask(); + Serial.print("NetMask: "); + Serial.println(subnet); + + // print your gateway address: + IPAddress gateway = WiFi.gatewayIP(); + Serial.print("Gateway: "); + Serial.println(gateway); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5], HEX); + Serial.print(":"); + Serial.print(bssid[4], HEX); + Serial.print(":"); + Serial.print(bssid[3], HEX); + Serial.print(":"); + Serial.print(bssid[2], HEX); + Serial.print(":"); + Serial.print(bssid[1], HEX); + Serial.print(":"); + Serial.println(bssid[0], HEX); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino new file mode 100644 index 00000000..6b08513b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -0,0 +1,130 @@ +/* + + This example connects to a WEP-encrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + + If you use 40-bit WEP, you need a key that is 10 characters long, + and the characters must be hexadecimal (0-9 or A-F). + e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work + (too short) and ABBAISDEAF won't work (I and S are not + hexadecimal characters). + + For 128-bit, you need a string that is 26 characters long. + D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, + all in the 0-9, A-F range. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key +int keyIndex = 0; // your network key Index number +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WEP network, SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, keyIndex, key); + + // wait 10 seconds for connection: + delay(10000); + } + + // once you are connected : + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + Serial.print(mac[5], HEX); + Serial.print(":"); + Serial.print(mac[4], HEX); + Serial.print(":"); + Serial.print(mac[3], HEX); + Serial.print(":"); + Serial.print(mac[2], HEX); + Serial.print(":"); + Serial.print(mac[1], HEX); + Serial.print(":"); + Serial.println(mac[0], HEX); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5], HEX); + Serial.print(":"); + Serial.print(bssid[4], HEX); + Serial.print(":"); + Serial.print(bssid[3], HEX); + Serial.print(":"); + Serial.print(bssid[2], HEX); + Serial.print(":"); + Serial.print(bssid[1], HEX); + Serial.print(":"); + Serial.println(bssid[0], HEX); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino new file mode 100644 index 00000000..ea092cf6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -0,0 +1,120 @@ +/* + + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + Serial.print(mac[5], HEX); + Serial.print(":"); + Serial.print(mac[4], HEX); + Serial.print(":"); + Serial.print(mac[3], HEX); + Serial.print(":"); + Serial.print(mac[2], HEX); + Serial.print(":"); + Serial.print(mac[1], HEX); + Serial.print(":"); + Serial.println(mac[0], HEX); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5], HEX); + Serial.print(":"); + Serial.print(bssid[4], HEX); + Serial.print(":"); + Serial.print(bssid[3], HEX); + Serial.print(":"); + Serial.print(bssid[2], HEX); + Serial.print(":"); + Serial.print(bssid[1], HEX); + Serial.print(":"); + Serial.println(bssid[0], HEX); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino new file mode 100644 index 00000000..90799be6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino @@ -0,0 +1,118 @@ +/* + + This example prints the WiFi shield's MAC address, and + scans for available WiFi networks using the WiFi shield. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 21 Junn 2012 + by Tom Igoe and Jaymes Dec + */ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // Print WiFi MAC address: + printMacAddress(); +} + +void loop() { + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); + delay(10000); +} + +void printMacAddress() { + // the MAC address of your WiFi shield + byte mac[6]; + + // print your MAC address: + WiFi.macAddress(mac); + Serial.print("MAC: "); + Serial.print(mac[5], HEX); + Serial.print(":"); + Serial.print(mac[4], HEX); + Serial.print(":"); + Serial.print(mac[3], HEX); + Serial.print(":"); + Serial.print(mac[2], HEX); + Serial.print(":"); + Serial.print(mac[1], HEX); + Serial.print(":"); + Serial.println(mac[0], HEX); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) { + Serial.println("Couldn't get a WiFi connection"); + while (true) + ; + } + + // print the list of networks seen: + Serial.print("number of available networks:"); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet); + Serial.print(") "); + Serial.print(WiFi.SSID(thisNet)); + Serial.print("\tSignal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + } +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.println("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.println("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.println("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.println("None"); + break; + case ENC_TYPE_AUTO: + Serial.println("Auto"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino new file mode 100644 index 00000000..2d6ad2cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino @@ -0,0 +1,133 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will print the IP address of your WiFi Shield (once connected) + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 9. + + If the IP address of your shield is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi shield attached + * LED attached to pin 9 + + created 25 Nov 2012 + by Tom Igoe + */ +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + Serial.begin(9600); // initialize serial communication + pinMode(9, OUTPUT); // set the LED pin mode + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + while (true) + ; // don't continue + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); // start the web server on port 80 + printWifiStatus(); // you're connected now, so print out the status +} + + +void loop() { + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the Serial Monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on pin 9 on
"); + client.print("Click here turn the LED on pin 9 off
"); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(9, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(9, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino new file mode 100644 index 00000000..3b136c00 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino @@ -0,0 +1,116 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the Serial Monitor as well. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + + Circuit: + * WiFi shield attached + + created 18 Dec 2009 + by David A. Mellis + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) + +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(23); + +bool alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // start the server: + server.begin(); + // you're connected now, so print out the status: + printWifiStatus(); +} + + +void loop() { + // wait for a new client: + WiFiClient client = server.available(); + + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clear out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino new file mode 100644 index 00000000..43ee9c79 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -0,0 +1,173 @@ +/* + + UDP NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + This code is in the public domain. + + */ + +#include +#include +#include + +int status = WL_IDLE_STATUS; +char ssid[] = "mynetwork"; // your network SSID (name) +char pass[] = "mypassword"; // your network password +int keyIndex = 0; // your network key Index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) { + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino new file mode 100644 index 00000000..cb7db4ce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -0,0 +1,114 @@ +/* + WiFi UDP Send and Receive String + + This sketch wait an UDP packet on localPort using a WiFi shield. + When a packet is received an Acknowledge packet is sent to the client on port remotePort + + Circuit: + * WiFi shield attached + + created 30 December 2012 + by dlf (Metodo2 srl) + + */ + + +#include +#include +#include + +int status = WL_IDLE_STATUS; +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen on + +char packetBuffer[255]; //buffer to hold incoming packet +char ReplyBuffer[] = "acknowledged"; // a string to send back + +WiFiUDP Udp; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + Udp.begin(localPort); +} + +void loop() { + + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remoteIp = Udp.remoteIP(); + Serial.print(remoteIp); + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBufffer + int len = Udp.read(packetBuffer, 255); + if (len > 0) { + packetBuffer[len] = 0; + } + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply, to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino new file mode 100644 index 00000000..a0f8cdf8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino @@ -0,0 +1,122 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using a WiFi shield. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ + + +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true) + ; + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino new file mode 100644 index 00000000..eca94b09 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -0,0 +1,129 @@ +/* + Repeating WiFi Web Client + + This sketch connects to a a web server and makes a request + using an Arduino WiFi shield. + + Circuit: + * WiFi shield attached to pins SPI pins and pin 7 + + created 23 April 2012 + modified 31 May 2012 + by Tom Igoe + modified 13 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating + This code is in the public domain. + */ + +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +// Initialize the WiFi client library +WiFiClient client; + +// server address: +char server[] = "www.arduino.cc"; +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the WiFi shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP PUT request: + client.println("GET /latest.txt HTTP/1.1"); + client.println("Host: www.arduino.cc"); + client.println("User-Agent: ArduinoWiFi/1.1"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino new file mode 100644 index 00000000..b2ab9d33 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino @@ -0,0 +1,138 @@ +/* + WiFi Web Server + + A simple web server that shows the value of the analog input pins. + using a WiFi shield. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi shield attached + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); + // you're connected now, so print out the status: + printWifiStatus(); +} + + +void loop() { + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
"); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/README.adoc new file mode 100644 index 00000000..ec967410 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/README.adoc @@ -0,0 +1,33 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: WiFi101 + += {repository-name} library for for the Arduino WiFi Shield 101 and MKR1000 board = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library implements a network driver for devices based +on the ATMEL WINC1500 WiFi module. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino new file mode 100644 index 00000000..6bdca8d4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino @@ -0,0 +1,178 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will create a new access point (with no password). + It will then launch a new server and print out the IP address + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 13. + + If the IP address of your shield is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + created 25 Nov 2012 + by Tom Igoe + adapted to WiFi AP by Adafruit + */ + +#include +#include +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int led = LED_BUILTIN; +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Access Point Web Server"); + + pinMode(led, OUTPUT); // set the LED pin mode + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue + while (true) + ; + } + + // by default the local IP address of will be 192.168.1.1 + // you can override it with the following: + // WiFi.config(IPAddress(10, 0, 0, 1)); + + // print the network name (SSID); + Serial.print("Creating access point named: "); + Serial.println(ssid); + + // Create open network. Change this line if you want to create a WEP network: + status = WiFi.beginAP(ssid); + if (status != WL_AP_LISTENING) { + Serial.println("Creating access point failed"); + // don't continue + while (true) + ; + } + + // wait 10 seconds for connection: + delay(10000); + + // start the web server on port 80 + server.begin(); + + // you're connected now, so print out the status + printWiFiStatus(); +} + + +void loop() { + // compare the previous status to the current status + if (status != WiFi.status()) { + // it has changed, so update the variable + status = WiFi.status(); + + if (status == WL_AP_CONNECTED) { + byte remoteMac[6]; + + // a device has connected to the AP + Serial.print("Device connected to AP, MAC address: "); + WiFi.APClientMacAddress(remoteMac); + printMacAddress(remoteMac); + } else { + // a device has disconnected from the AP, and we are back in listening mode + Serial.println("Device disconnected from AP"); + } + } + + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there are bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on
"); + client.print("Click here turn the LED off
"); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(led, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(led, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/CheckWifi101FirmwareVersion/CheckWifi101FirmwareVersion.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/CheckWifi101FirmwareVersion/CheckWifi101FirmwareVersion.ino new file mode 100644 index 00000000..3be9c331 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/CheckWifi101FirmwareVersion/CheckWifi101FirmwareVersion.ino @@ -0,0 +1,66 @@ +/* + * This example checks if the firmware loaded on the WiFi101 + * shield is updated. + * + * Circuit: + * - WiFi 101 Shield attached + * + * Created 29 July 2015 by Cristian Maglie + * This code is in the public domain. + */ +#include +#include +#include + +void setup() { + // Initialize serial + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Print a welcome message + Serial.println("WiFi101 firmware check."); + Serial.println(); + + // Check for the presence of the shield + Serial.print("WiFi 101 Shield: "); + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("NOT PRESENT"); + return; // don't continue + } + Serial.println("DETECTED"); + + // Print firmware version on the shield + String fv = WiFi.firmwareVersion(); + String latestFv; + Serial.print("Firmware version installed: "); + Serial.println(fv); + + if (REV(GET_CHIPID()) >= REV_3A0) { + // model B + latestFv = WIFI_FIRMWARE_LATEST_MODEL_B; + } else { + // model A + latestFv = WIFI_FIRMWARE_LATEST_MODEL_A; + } + + // Print required firmware version + Serial.print("Latest firmware version available : "); + Serial.println(latestFv); + + // Check if the latest version is installed + Serial.println(); + if (fv >= latestFv) { + Serial.println("Check result: PASSED"); + } else { + Serial.println("Check result: NOT PASSED"); + Serial.println(" - The firmware version on the shield does not match the"); + Serial.println(" version required by the library, you may experience"); + Serial.println(" issues or failures."); + } +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/ConnectNoEncryption.ino new file mode 100644 index 00000000..17295663 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -0,0 +1,116 @@ +/* + + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi 101 Shield, + the IP address obtained, and other network details. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to open SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWiFiData() { + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); + + // print your subnet mask: + IPAddress subnet = WiFi.subnetMask(); + Serial.print("NetMask: "); + Serial.println(subnet); + + // print your gateway address: + IPAddress gateway = WiFi.gatewayIP(); + Serial.print("Gateway: "); + Serial.println(gateway); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/arduino_secrets.h new file mode 100644 index 00000000..07c11487 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_SSID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/ConnectWithWEP.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/ConnectWithWEP.ino new file mode 100644 index 00000000..33ef2563 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -0,0 +1,120 @@ +/* + + This example connects to a WEP-encrypted WiFi network. + Then it prints the MAC address of the WiFi 101 Shield, + the IP address obtained, and other network details. + + If you use 40-bit WEP, you need a key that is 10 characters long, + and the characters must be hexadecimal (0-9 or A-F). + e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work + (too short) and ABBAISDEAF won't work (I and S are not + hexadecimal characters). + + For 128-bit, you need a string that is 26 characters long. + D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, + all in the 0-9, A-F range. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char key[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WEP network, SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, keyIndex, key); + + // wait 10 seconds for connection: + delay(10000); + } + + // once you are connected : + Serial.print("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWiFiData() { + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/ConnectWithWPA.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/ConnectWithWPA.ino new file mode 100644 index 00000000..baa5e6b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -0,0 +1,110 @@ +/* + + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi 101 Shield, + the IP address obtained, and other network details. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWiFiData() { + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/Endianness.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/Endianness.ino new file mode 100644 index 00000000..7c84eae2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/Endianness.ino @@ -0,0 +1,65 @@ +/* + Endianness.ino - Network byte order conversion functions. + Copyright (c) 2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +bool isBigEndian() { + uint32_t test = 0x11223344; + uint8_t *pTest = reinterpret_cast(&test); + return pTest[0] == 0x11; +} + +uint32_t fromNetwork32(uint32_t from) { + static const bool be = isBigEndian(); + if (be) { + return from; + } else { + uint8_t *pFrom = reinterpret_cast(&from); + uint32_t to; + to = pFrom[0]; + to <<= 8; + to |= pFrom[1]; + to <<= 8; + to |= pFrom[2]; + to <<= 8; + to |= pFrom[3]; + return to; + } +} + +uint16_t fromNetwork16(uint16_t from) { + static bool be = isBigEndian(); + if (be) { + return from; + } else { + uint8_t *pFrom = reinterpret_cast(&from); + uint16_t to; + to = pFrom[0]; + to <<= 8; + to |= pFrom[1]; + return to; + } +} + +uint32_t toNetwork32(uint32_t to) { + return fromNetwork32(to); +} + +uint16_t toNetwork16(uint16_t to) { + return fromNetwork16(to); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/FirmwareUpdater.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/FirmwareUpdater.ino new file mode 100644 index 00000000..d5115241 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/FirmwareUpdater.ino @@ -0,0 +1,127 @@ +/* + FirmwareUpdate.h - Firmware Updater for WiFi101 / WINC1500. + Copyright (c) 2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include + +typedef struct __attribute__((__packed__)) { + uint8_t command; + uint32_t address; + uint32_t arg1; + uint16_t payloadLength; + + // payloadLength bytes of data follows... +} UartPacket; + +static const int MAX_PAYLOAD_SIZE = 1024; + +#define CMD_READ_FLASH 0x01 +#define CMD_WRITE_FLASH 0x02 +#define CMD_ERASE_FLASH 0x03 +#define CMD_MAX_PAYLOAD_SIZE 0x50 +#define CMD_HELLO 0x99 + +void setup() { + Serial.begin(115200); + + nm_bsp_init(); + if (m2m_wifi_download_mode() != M2M_SUCCESS) { + Serial.println(F("Failed to put the WiFi module in download mode")); + while (true) + ; + } +} + +void receivePacket(UartPacket *pkt, uint8_t *payload) { + // Read command + uint8_t *p = reinterpret_cast(pkt); + uint16_t l = sizeof(UartPacket); + while (l > 0) { + int c = Serial.read(); + if (c == -1) + continue; + *p++ = c; + l--; + } + + // Convert parameters from network byte order to cpu byte order + pkt->address = fromNetwork32(pkt->address); + pkt->arg1 = fromNetwork32(pkt->arg1); + pkt->payloadLength = fromNetwork16(pkt->payloadLength); + + // Read payload + l = pkt->payloadLength; + while (l > 0) { + int c = Serial.read(); + if (c == -1) + continue; + *payload++ = c; + l--; + } +} + +// Allocated statically so the compiler can tell us +// about the amount of used RAM +static UartPacket pkt; +static uint8_t payload[MAX_PAYLOAD_SIZE]; + +void loop() { + receivePacket(&pkt, payload); + + if (pkt.command == CMD_HELLO) { + if (pkt.address == 0x11223344 && pkt.arg1 == 0x55667788) + Serial.print("v10000"); + } + + if (pkt.command == CMD_MAX_PAYLOAD_SIZE) { + uint16_t res = toNetwork16(MAX_PAYLOAD_SIZE); + Serial.write(reinterpret_cast(&res), sizeof(res)); + } + + if (pkt.command == CMD_READ_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.arg1; + if (spi_flash_read(payload, address, len) != M2M_SUCCESS) { + Serial.println("ER"); + } else { + Serial.write(payload, len); + Serial.print("OK"); + } + } + + if (pkt.command == CMD_WRITE_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.payloadLength; + if (spi_flash_write(payload, address, len) != M2M_SUCCESS) { + Serial.print("ER"); + } else { + Serial.print("OK"); + } + } + + if (pkt.command == CMD_ERASE_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.arg1; + if (spi_flash_erase(address, len) != M2M_SUCCESS) { + Serial.print("ER"); + } else { + Serial.print("OK"); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/MDNS_WiFiWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/MDNS_WiFiWebServer.ino new file mode 100644 index 00000000..cd9a1981 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/MDNS_WiFiWebServer.ino @@ -0,0 +1,171 @@ +/* + MDNS WiFi Web Server + + A simple web server that shows the value of the analog input pins, + and exposes itself on the MDNS name 'wifi101.local'. + + On Linux (like Ubuntu 15.04) or OSX you can access the web page + on the device in a browser at 'http://wifi101.local/'. + + On Windows you'll first need to install the Bonjour Printer Services + from: + https://support.apple.com/kb/dl999?locale=en_US + Then you can access the device in a browser at 'http://wifi101.local/'. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi 101 Shield attached + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + modified 27 January 2016 + by Tony DiCola + +*/ + +#include +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +char mdnsName[] = "wifi101"; // the MDNS name that the board will respond to +// Note that the actual MDNS name will have '.local' after +// the name above, so "wifi101" will be accessible on +// the MDNS name "wifi101.local". + +int status = WL_IDLE_STATUS; + +// Create a MDNS responder to listen and respond to MDNS name requests. +WiFiMDNSResponder mdnsResponder; + +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + // you're connected now, so print out the status: + printWiFiStatus(); + + server.begin(); + + // Setup the MDNS responder to listen to the configured name. + // NOTE: You _must_ call this _after_ connecting to the WiFi network and + // being assigned an IP address. + if (!mdnsResponder.begin(mdnsName)) { + Serial.println("Failed to start MDNS responder!"); + while (1) + ; + } + + Serial.print("Server listening at http://"); + Serial.print(mdnsName); + Serial.println(".local/"); +} + + +void loop() { + // Call the update() function on the MDNS responder every loop iteration to + // make sure it can detect and respond to name requests. + mdnsResponder.poll(); + + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
"); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/Provisioning_WiFiWebServer/Provisioning_WiFiWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/Provisioning_WiFiWebServer/Provisioning_WiFiWebServer.ino new file mode 100644 index 00000000..ad1f85c1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/Provisioning_WiFiWebServer/Provisioning_WiFiWebServer.ino @@ -0,0 +1,167 @@ +/* + WiFi Web Server + + A simple web server that shows the value of the analog input pins. + using a WiFi 101 Shield. + + This example is written to configure the WiFi settings using provisioning mode. + It also sets up an mDNS server so the IP address of the board doesn't have to + be obtained via the serial monitor. + + Circuit: + WiFi 101 Shield attached + Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + +*/ + +#include +#include +#include + +const int ledPin = 6; // LED pin for connectivity status indicator + +char mdnsName[] = "wifi101"; // the MDNS name that the board will respond to + // after WiFi settings have been provisioned +// Note that the actual MDNS name will have '.local' after +// the name above, so "wifi101" will be accessible on +// the MDNS name "wifi101.local". + +WiFiServer server(80); + +// Create a MDNS responder to listen and respond to MDNS name requests. +WiFiMDNSResponder mdnsResponder; + +void setup() { + //Initialize serial: + Serial.begin(9600); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // configure the LED pin for output mode + pinMode(ledPin, OUTPUT); + + // Start in provisioning mode: + // 1) This will try to connect to a previously associated access point. + // 2) If this fails, an access point named "wifi101-XXXX" will be created, where XXXX + // is the last 4 digits of the boards MAC address. Once you are connected to the access point, + // you can configure an SSID and password by visiting http://wifi101/ + WiFi.beginProvision(); + + while (WiFi.status() != WL_CONNECTED) { + // wait while not connected + + // blink the led to show an unconnected status + digitalWrite(ledPin, HIGH); + delay(500); + digitalWrite(ledPin, LOW); + delay(500); + } + + // connected, make the LED stay on + digitalWrite(ledPin, HIGH); + + server.begin(); + + // Setup the MDNS responder to listen to the configured name. + // NOTE: You _must_ call this _after_ connecting to the WiFi network and + // being assigned an IP address. + if (!mdnsResponder.begin(mdnsName)) { + Serial.println("Failed to start MDNS responder!"); + while (1) + ; + } + + Serial.print("Server listening at http://"); + Serial.print(mdnsName); + Serial.println(".local/"); + + // you're connected now, so print out the status: + printWiFiStatus(); +} + + +void loop() { + // Call the update() function on the MDNS responder every loop iteration to + // make sure it can detect and respond to name requests. + mdnsResponder.poll(); + + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
"); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ScanNetworks/ScanNetworks.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ScanNetworks/ScanNetworks.ino new file mode 100644 index 00000000..415c6195 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ScanNetworks/ScanNetworks.ino @@ -0,0 +1,121 @@ +/* + + This example prints the WiFi 101 Shield's MAC address, and + scans for available WiFi networks using the WiFi 101 Shield. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 21 Junn 2012 + by Tom Igoe and Jaymes Dec + */ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // Print WiFi MAC address: + printMacAddress(); + + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void loop() { + delay(10000); + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void printMacAddress() { + // the MAC address of your WiFi 101 Shield + byte mac[6]; + + // print your MAC address: + WiFi.macAddress(mac); + Serial.print("MAC: "); + printMacAddress(mac); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) { + Serial.println("Couldn't get a WiFi connection"); + while (true) + ; + } + + // print the list of networks seen: + Serial.print("number of available networks:"); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet); + Serial.print(") "); + Serial.print(WiFi.SSID(thisNet)); + Serial.print("\tSignal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + Serial.flush(); + } +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.println("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.println("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.println("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.println("None"); + break; + case ENC_TYPE_AUTO: + Serial.println("Auto"); + break; + } +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino new file mode 100644 index 00000000..75b82734 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino @@ -0,0 +1,130 @@ +/* + + This example prints the WiFi 101 Shield or MKR1000 MAC address, and + scans for available WiFi networks using the WiFi 101 Shield or MKR1000 board. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + BSSID and WiFi channel are printed + + Circuit: + WiFi 101 Shield attached or MKR1000 board + + This example is based on ScanNetworks + + created 1 Mar 2017 + by Arturo Guadalupi +*/ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC: "); + printMacAddress(mac); + + // scan for existing networks: + Serial.println(); + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void loop() { + delay(10000); + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) { + Serial.println("Couldn't get a WiFi connection"); + while (true) + ; + } + + // print the list of networks seen: + Serial.print("number of available networks: "); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet + 1); + Serial.print(") "); + Serial.print("Signal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tChannel: "); + Serial.print(WiFi.channel(thisNet)); + byte bssid[6]; + Serial.print("\t\tBSSID: "); + printMacAddress(WiFi.BSSID(thisNet, bssid)); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + Serial.print("\t\tSSID: "); + Serial.println(WiFi.SSID(thisNet)); + Serial.flush(); + } + Serial.println(); +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.print("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.print("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.print("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.print("None"); + break; + case ENC_TYPE_AUTO: + Serial.print("Auto"); + break; + } +} + +void print2Digits(byte thisByte) { + if (thisByte < 0xF) { + Serial.print("0"); + } + Serial.print(thisByte, HEX); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino new file mode 100644 index 00000000..bca6e141 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino @@ -0,0 +1,130 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will print the IP address of your WiFi 101 Shield (once connected) + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 9. + + If the IP address of your shield is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi 101 Shield attached + * LED attached to pin 9 + + created 25 Nov 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + Serial.begin(9600); // initialize serial communication + pinMode(9, OUTPUT); // set the LED pin mode + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + while (true) + ; // don't continue + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); // start the web server on port 80 + printWiFiStatus(); // you're connected now, so print out the status +} + + +void loop() { + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there are bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on pin 9 on
"); + client.print("Click here turn the LED on pin 9 off
"); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(9, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(9, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/WiFiChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/WiFiChatServer.ino new file mode 100644 index 00000000..5171834e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/WiFiChatServer.ino @@ -0,0 +1,113 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + + Circuit: + * WiFi 101 Shield attached + + created 18 Dec 2009 + by David A. Mellis + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(23); + +bool alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // start the server: + server.begin(); + // you're connected now, so print out the status: + printWiFiStatus(); +} + + +void loop() { + // wait for a new client: + WiFiClient client = server.available(); + + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clead out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiPing/WiFiPing.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiPing/WiFiPing.ino new file mode 100644 index 00000000..4034c070 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiPing/WiFiPing.ino @@ -0,0 +1,133 @@ +/* + + This example connects to a encrypted WiFi network (WPA/WPA2). + Then it prints the MAC address of the WiFi 101 Shield, + the IP address obtained, and other network details. + Then it continuously pings given host specified by IP Address or name. + + Circuit: + WiFi 101 Shield attached / MKR1000 + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 09 June 2016 + by Petar Georgiev +*/ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +// Specify IP address or hostname +String hostName = "www.google.com"; +int pingResult; + +void setup() { + // Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 5 seconds for connection: + delay(5000); + } + + // you're connected now, so print out the data: + Serial.println("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + Serial.print("Pinging "); + Serial.print(hostName); + Serial.print(": "); + + pingResult = WiFi.ping(hostName); + + if (pingResult >= 0) { + Serial.print("SUCCESS! RTT = "); + Serial.print(pingResult); + Serial.println(" ms"); + } else { + Serial.print("FAILED! Error code: "); + Serial.println(pingResult); + } + + delay(5000); +} + +void printWiFiData() { + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP address : "); + Serial.println(ip); + + Serial.print("Subnet mask: "); + Serial.println((IPAddress)WiFi.subnetMask()); + + Serial.print("Gateway IP : "); + Serial.println((IPAddress)WiFi.gatewayIP()); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI): "); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type: "); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiPing/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiPing/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiPing/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/WiFiSSLClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/WiFiSSLClient.ino new file mode 100644 index 00000000..50ef0e5a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/WiFiSSLClient.ino @@ -0,0 +1,109 @@ +/* +This example creates a client object that connects and transfers +data using always SSL. + +It is compatible with the methods normally related to plain +connections, like client.connect(host, port). + +Written by Arturo Guadalupi +last revision November 2015 + +*/ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiSSLClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 443)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true) + ; + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino new file mode 100644 index 00000000..02e489d1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -0,0 +1,170 @@ +/* + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + This code is in the public domain. + + */ + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) { + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino new file mode 100644 index 00000000..c982bb2c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -0,0 +1,108 @@ +/* + WiFi UDP Send and Receive String + + This sketch waits for an UDP packet on localPort using a WiFi 101 Shield. + When a packet is received an Acknowledge packet is sent to the client on port remotePort + + Circuit: + * WiFi 101 Shield attached + + created 30 December 2012 + by dlf (Metodo2 srl) + + */ + + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen on + +char packetBuffer[255]; //buffer to hold incoming packet +char ReplyBuffer[] = "acknowledged"; // a string to send back + +WiFiUDP Udp; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + Udp.begin(localPort); +} + +void loop() { + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remoteIp = Udp.remoteIP(); + Serial.print(remoteIp); + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBufffer + int len = Udp.read(packetBuffer, 255); + if (len > 0) packetBuffer[len] = 0; + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply, to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/WiFiWebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/WiFiWebClient.ino new file mode 100644 index 00000000..3723639c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/WiFiWebClient.ino @@ -0,0 +1,118 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using a WiFi 101 Shield. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ + + +#include +#include +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true) + ; + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino new file mode 100644 index 00000000..c594d1be --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -0,0 +1,126 @@ +/* + Repeating WiFi Web Client + + This sketch connects to a a web server and makes a request + using an Arduino WiFi 101 Shield. + + Circuit: + * WiFi 101 Shield attached to pins SPI pins and pin 7 + + created 23 April 2012 + modified 31 May 2012 + by Tom Igoe + modified 13 Jan 2014 + by Federico Vanzati + + http://arduino.cc/en/Tutorial/WiFiWebClientRepeating + This code is in the public domain. + */ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +// Initialize the WiFi client library +WiFiClient client; + +// server address: +char server[] = "example.org"; +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + // you're connected now, so print out the status: + printWiFiStatus(); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before sending a new request. + // This will free the socket on the WiFi 101 Shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP PUT request: + client.println("GET / HTTP/1.1"); + client.println("Host: example.org"); + client.println("User-Agent: ArduinoWiFi/1.1"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/WiFiWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/WiFiWebServer.ino new file mode 100644 index 00000000..f0d6f238 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/WiFiWebServer.ino @@ -0,0 +1,135 @@ +/* + WiFi Web Server + + A simple web server that shows the value of the analog input pins. + using a WiFi 101 Shield. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi 101 Shield attached + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); + // you're connected now, so print out the status: + printWiFiStatus(); +} + + +void loop() { + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
"); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/README.adoc new file mode 100644 index 00000000..ca878e8b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/README.adoc @@ -0,0 +1,32 @@ +:repository-owner: arduino-libraries +:repository-name: WiFi101OTA + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows you to update sketches on your board over WiFi. +It requires an Arduino SAMD board like the Zero or MKR1000. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/WiFi101OTA + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/WiFi101_OTA.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/WiFi101_OTA.ino new file mode 100644 index 00000000..fb0ef0d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/WiFi101_OTA.ino @@ -0,0 +1,82 @@ +/* + + This example connects to an WPA encrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + It then polls for sketch updates over WiFi. Sketches + can be updated by selecting a network port from within + the Arduino IDE: Tools -> Port -> Network Ports ... + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + modified 16 January 2017 + by Sandeep Mistry + */ + +#include +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +/////// WiFi Settings /////// +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password + +int status = WL_IDLE_STATUS; + +void setup() { + //Initialize serial: + Serial.begin(9600); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + } + + // start the WiFi OTA library with internal (flash) based storage + WiFiOTA.begin("Arduino", "password", InternalStorage); + + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // check for WiFi OTA updates + WiFiOTA.poll(); + + // add your normal loop code below ... +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino new file mode 100644 index 00000000..0c648a7f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino @@ -0,0 +1,95 @@ +/* + + This example connects to an WPA encrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + It then polls for sketch updates over WiFi. Sketches + can be updated by selecting a network port from within + the Arduino IDE: Tools -> Port -> Network Ports ... + + Circuit: + * WiFi shield attached + * SD shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + modified 16 January 2017 + by Sandeep Mistry + */ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +/////// WiFi Settings /////// +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password + +int status = WL_IDLE_STATUS; + +void setup() { + //Initialize serial: + Serial.begin(9600); + + // setup SD card + Serial.print("Initializing SD card..."); + if (!SD.begin(SDCARD_SS_PIN)) { + Serial.println("initialization failed!"); + // don't continue: + while (true) + ; + } + Serial.println("initialization done."); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + } + + // start the WiFi OTA library with SD based storage + WiFiOTA.begin("Arduino", "password", SDStorage); + + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // check for WiFi OTA updates + WiFiOTA.poll(); + + // add your normal loop code below ... +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/README.adoc new file mode 100644 index 00000000..aaaf6e80 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/README.adoc @@ -0,0 +1,35 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: WiFiNINA + += {repository-name} library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Enables network connection (local and Internet) with the Arduino MKR WiFi 1010, Arduino MKR VIDOR 4000 and Arduino UNO WiFi Rev.2. + +With this library you can instantiate Servers, Clients and send/receive UDP packets through WiFi. The board can connect either to open or encrypted networks (WEP, WPA). The IP address can be assigned statically or through a DHCP. The library can also manage DNS. + +For more information about this library please visit us at +https://www.arduino.cc/reference/en/libraries/wifinina/ + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. +Copyright (c) 2011-2014 Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino new file mode 100644 index 00000000..eb2e854e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino @@ -0,0 +1,162 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will create a new access point (with no password). + It will then launch a new server and print out the IP address + to the Serial Monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 13. + + If the IP address of your board is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + created 25 Nov 2012 + by Tom Igoe + adapted to WiFi AP by Adafruit + */ + +#include +#include +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int led = LED_BUILTIN; +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Access Point Web Server"); + + pinMode(led, OUTPUT); // set the LED pin mode + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // by default the local IP address will be 192.168.4.1 + // you can override it with the following: + // WiFi.config(IPAddress(10, 0, 0, 1)); + + // print the network name (SSID); + Serial.print("Creating access point named: "); + Serial.println(ssid); + + // Create open network. Change this line if you want to create an WEP network: + status = WiFi.beginAP(ssid, pass); + if (status != WL_AP_LISTENING) { + Serial.println("Creating access point failed"); + // don't continue + while (true) + ; + } + + // wait 10 seconds for connection: + delay(10000); + + // start the web server on port 80 + server.begin(); + + // you're connected now, so print out the status + printWiFiStatus(); +} + + +void loop() { + // compare the previous status to the current status + if (status != WiFi.status()) { + // it has changed update the variable + status = WiFi.status(); + + if (status == WL_AP_CONNECTED) { + // a device has connected to the AP + Serial.println("Device connected to AP"); + } else { + // a device has disconnected from the AP, and we are back in listening mode + Serial.println("Device disconnected from AP"); + } + } + + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + delayMicroseconds(10); // This is required for the Arduino Nano RP2040 Connect - otherwise it will loop so fast that SPI will never be served. + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on
"); + client.print("Click here turn the LED off
"); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(led, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(led, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/arduino_secrets.h new file mode 100644 index 00000000..493b719c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/arduino_secrets.h @@ -0,0 +1,3 @@ +// Both SSID and password must be 8 characters or longer +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/ConnectNoEncryption.ino new file mode 100644 index 00000000..bca292e6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -0,0 +1,117 @@ +/* + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the board, + the IP address obtained, and other network details. + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to open SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); + + // print your subnet mask: + IPAddress subnet = WiFi.subnetMask(); + Serial.print("NetMask: "); + Serial.println(subnet); + + // print your gateway address: + IPAddress gateway = WiFi.gatewayIP(); + Serial.print("Gateway: "); + Serial.println(gateway); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/arduino_secrets.h new file mode 100644 index 00000000..07c11487 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_SSID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/ConnectWithWEP.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/ConnectWithWEP.ino new file mode 100644 index 00000000..e068a533 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -0,0 +1,121 @@ +/* + This example connects to a WEP-encrypted WiFi network. + Then it prints the MAC address of the WiFi module, + the IP address obtained, and other network details. + + If you use 40-bit WEP, you need a key that is 10 characters long, + and the characters must be hexadecimal (0-9 or A-F). + e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work + (too short) and ABBAISDEAF won't work (I and S are not + hexadecimal characters). + + For 128-bit, you need a string that is 26 characters long. + D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, + all in the 0-9, A-F range. + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WEP network, SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, keyIndex, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // once you are connected : + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/ConnectWithWPA.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/ConnectWithWPA.ino new file mode 100644 index 00000000..3d5fcd80 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -0,0 +1,111 @@ +/* + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi module, + the IP address obtained, and other network details. + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino new file mode 100644 index 00000000..faa29b86 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino @@ -0,0 +1,110 @@ +/* + This example connects to a WPA2 Enterprise WiFi network. + Then it prints the MAC address of the WiFi module, + the IP address obtained, and other network details. + + Based on ConnectWithWPA.ino by dlf (Metodo2 srl) and Tom Igoe +*/ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your WPA2 enterprise network SSID (name) +char user[] = SECRET_USER; // your WPA2 enterprise username +char pass[] = SECRET_PASS; // your WPA2 enterprise password +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA2 enterprise network: + // - You can optionally provide additional identity and CA cert (string) parameters if your network requires them: + // WiFi.beginEnterprise(ssid, user, pass, identity, caCert) + status = WiFi.beginEnterprise(ssid, user, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/arduino_secrets.h new file mode 100644 index 00000000..d1310bbd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/arduino_secrets.h @@ -0,0 +1,3 @@ +#define SECRET_SSID "" +#define SECRET_USER "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ScanNetworks/ScanNetworks.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ScanNetworks/ScanNetworks.ino new file mode 100644 index 00000000..f201b57b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ScanNetworks/ScanNetworks.ino @@ -0,0 +1,118 @@ +/* + This example prints the board's MAC address, and + scans for available WiFi networks using the NINA module. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 21 Junn 2012 + by Tom Igoe and Jaymes Dec + */ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC: "); + printMacAddress(mac); +} + +void loop() { + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); + delay(10000); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) { + Serial.println("Couldn't get a WiFi connection"); + while (true) + ; + } + + // print the list of networks seen: + Serial.print("number of available networks:"); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet); + Serial.print(") "); + Serial.print(WiFi.SSID(thisNet)); + Serial.print("\tSignal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + } +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.println("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.println("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.println("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.println("None"); + break; + case ENC_TYPE_AUTO: + Serial.println("Auto"); + break; + case ENC_TYPE_UNKNOWN: + default: + Serial.println("Unknown"); + break; + } +} + + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino new file mode 100644 index 00000000..b4607eb1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino @@ -0,0 +1,138 @@ +/* + This example prints the board's MAC address, and + scans for available WiFi networks using the NINA module. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + BSSID and WiFi channel are printed + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + This example is based on ScanNetworks + + created 1 Mar 2017 + by Arturo Guadalupi +*/ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC: "); + printMacAddress(mac); + + // scan for existing networks: + Serial.println(); + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void loop() { + delay(10000); + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) { + Serial.println("Couldn't get a WiFi connection"); + while (true) + ; + } + + // print the list of networks seen: + Serial.print("number of available networks: "); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet + 1); + Serial.print(") "); + Serial.print("Signal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tChannel: "); + Serial.print(WiFi.channel(thisNet)); + byte bssid[6]; + Serial.print("\t\tBSSID: "); + printMacAddress(WiFi.BSSID(thisNet, bssid)); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + Serial.print("\t\tSSID: "); + Serial.println(WiFi.SSID(thisNet)); + Serial.flush(); + } + Serial.println(); +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.print("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.print("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.print("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.print("None"); + break; + case ENC_TYPE_AUTO: + Serial.print("Auto"); + break; + case ENC_TYPE_UNKNOWN: + default: + Serial.print("Unknown"); + break; + } +} + +void print2Digits(byte thisByte) { + if (thisByte < 0xF) { + Serial.print("0"); + } + Serial.print(thisByte, HEX); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino new file mode 100644 index 00000000..076996b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino @@ -0,0 +1,136 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will print the IP address of your WiFi module (once connected) + to the Serial Monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 9. + + If the IP address of your board is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + * LED attached to pin 9 + + created 25 Nov 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + Serial.begin(9600); // initialize serial communication + pinMode(9, OUTPUT); // set the LED pin mode + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); // start the web server on port 80 + printWifiStatus(); // you're connected now, so print out the status +} + + +void loop() { + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on pin 9 on
"); + client.print("Click here turn the LED on pin 9 off
"); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(LED_BUILTIN, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino new file mode 100644 index 00000000..406be849 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino @@ -0,0 +1,59 @@ +/* + * This example checks if the firmware loaded on the NINA module + * is updated. + * + * Circuit: + * - Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + * + * Created 17 October 2018 by Riccardo Rosario Rizzo + * This code is in the public domain. + */ +#include +#include + +void setup() { + // Initialize serial + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Print a welcome message + Serial.println("WiFiNINA firmware check."); + Serial.println(); + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + // Print firmware version on the module + String fv = WiFi.firmwareVersion(); + String latestFv; + Serial.print("Firmware version installed: "); + Serial.println(fv); + + latestFv = WIFI_FIRMWARE_LATEST_VERSION; + + // Print required firmware version + Serial.print("Latest firmware version available : "); + Serial.println(latestFv); + + // Check if the latest version is installed + Serial.println(); + if (fv >= latestFv) { + Serial.println("Check result: PASSED"); + } else { + Serial.println("Check result: NOT PASSED"); + Serial.println(" - The firmware version on the module does not match the"); + Serial.println(" version required by the library, you may experience"); + Serial.println(" issues or failures."); + } +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.cpp new file mode 100644 index 00000000..0447f42a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.cpp @@ -0,0 +1,324 @@ +/* + ESP32BootROM - part of the Firmware Updater for the + Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. + + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifdef ARDUINO_SAMD_MKRVIDOR4000 +#include + +#define NINA_GPIO0 FPGA_NINA_GPIO0 +#define NINA_RESETN FPGA_SPIWIFI_RESET +#endif + + +#include "ESP32BootROM.h" + +ESP32BootROMClass::ESP32BootROMClass(HardwareSerial& serial, int gpio0Pin, int resetnPin) + : _serial(&serial), + _gpio0Pin(gpio0Pin), + _resetnPin(resetnPin) { +} + +int ESP32BootROMClass::begin(unsigned long baudrate) { +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.begin(); + + _serial->begin(119400); + + FPGA.pinMode(_gpio0Pin, OUTPUT); + FPGA.pinMode(_resetnPin, OUTPUT); + + FPGA.digitalWrite(_gpio0Pin, LOW); + + FPGA.digitalWrite(_resetnPin, LOW); + delay(10); + FPGA.digitalWrite(_resetnPin, HIGH); + delay(100); + +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) + _serial->begin(119400); + + pinMode(_gpio0Pin, OUTPUT); + pinMode(_resetnPin, OUTPUT); + + digitalWrite(_gpio0Pin, LOW); + + digitalWrite(_resetnPin, LOW); + delay(100); + digitalWrite(_resetnPin, HIGH); + delay(100); + digitalWrite(_resetnPin, LOW); +#else + _serial->begin(115200); + + pinMode(_gpio0Pin, OUTPUT); + pinMode(_resetnPin, OUTPUT); + + digitalWrite(_gpio0Pin, LOW); + + digitalWrite(_resetnPin, HIGH); + delay(10); + digitalWrite(_resetnPin, LOW); + delay(100); +#if defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_NANO_RP2040_CONNECT) + digitalWrite(_resetnPin, HIGH); + delay(100); +#endif +#endif + + int synced = 0; + + for (int retries = 0; !synced && (retries < 5); retries++) { + synced = sync(); + } + + if (!synced) { + return 0; + } + +#if defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_NANO_RP2040_CONNECT) + (void)baudrate; +#else + if (baudrate != 115200) { + if (!changeBaudrate(baudrate)) { + return 0; + } + + delay(100); + + _serial->end(); + _serial->begin(baudrate); + } +#endif + + if (!spiAttach()) { + return 0; + } + + return 1; +} + +void ESP32BootROMClass::end() { + _serial->end(); +} + +int ESP32BootROMClass::sync() { + const uint8_t data[] = { + 0x07, 0x07, 0x12, 0x20, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 + }; + + command(0x08, data, sizeof(data)); + + int results[8]; + + for (int i = 0; i < 8; i++) { + results[i] = response(0x08, 100); + } + + return (results[0] == 0); +} + +int ESP32BootROMClass::changeBaudrate(unsigned long baudrate) { + const uint32_t data[2] = { + baudrate, + 0 + }; + + command(0x0f, data, sizeof(data)); + + return (response(0x0f, 3000) == 0); +} + +int ESP32BootROMClass::spiAttach() { + const uint8_t data[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + command(0x0d, data, sizeof(data)); + + return (response(0x0d, 3000) == 0); +} + +int ESP32BootROMClass::beginFlash(uint32_t offset, uint32_t size, uint32_t chunkSize) { + const uint32_t data[4] = { + size, + size / chunkSize, + chunkSize, + offset + }; + + command(0x02, data, sizeof(data)); + + _flashSequenceNumber = 0; + _chunkSize = chunkSize; + + return (response(0x02, 120000) == 0); +} + +int ESP32BootROMClass::dataFlash(const void* data, uint32_t length) { + uint32_t cmdData[4 + (_chunkSize / 4)]; + + cmdData[0] = length; + cmdData[1] = _flashSequenceNumber++; + cmdData[2] = 0; + cmdData[3] = 0; + + memcpy(&cmdData[4], data, length); + + if (length < _chunkSize) { + memset(&cmdData[4 + (length / 4)], 0xff, _chunkSize - length); + } + + command(0x03, cmdData, sizeof(cmdData)); + + return (response(0x03, 3000) == 0); +} + +int ESP32BootROMClass::endFlash(uint32_t reboot) { + const uint32_t data[1] = { + reboot + }; + + command(0x04, data, sizeof(data)); + + return (response(0x04, 3000) == 0); +} + +int ESP32BootROMClass::md5Flash(uint32_t offset, uint32_t size, uint8_t* result) { + const uint32_t data[4] = { + offset, + size, + 0, + 0 + }; + + command(0x13, data, sizeof(data)); + + uint8_t asciiResult[32]; + + if (response(0x13, 3000, asciiResult) != 0) { + return 0; + } + + char temp[3] = { 0, 0, 0 }; + + for (int i = 0; i < 16; i++) { + temp[0] = asciiResult[i * 2]; + temp[1] = asciiResult[i * 2 + 1]; + + result[i] = strtoul(temp, NULL, 16); + } + + return 1; +} + +void ESP32BootROMClass::command(int opcode, const void* data, uint16_t length) { + uint32_t checksum = 0; + + if (opcode == 0x03) { + checksum = 0xef; // seed + + for (uint16_t i = 16; i < length; i++) { + checksum ^= ((const uint8_t*)data)[i]; + } + } + + _serial->write(0xc0); + _serial->write((uint8_t)0x00); // direction + _serial->write(opcode); + _serial->write((uint8_t*)&length, sizeof(length)); + writeEscapedBytes((uint8_t*)&checksum, sizeof(checksum)); + writeEscapedBytes((uint8_t*)data, length); + _serial->write(0xc0); +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + // _serial->flush(); // doesn't work! +#else + _serial->flush(); +#endif +} + +int ESP32BootROMClass::response(int opcode, unsigned long timeout, void* body) { + uint8_t data[10 + 256]; + uint16_t index = 0; + + uint8_t responseLength = 4; + + for (unsigned long start = millis(); (index < (uint16_t)(10 + responseLength)) && (millis() - start) < timeout;) { + if (_serial->available()) { + data[index] = _serial->read(); + + if (index == 3) { + responseLength = data[index]; + } + + index++; + } + } + +#ifdef DEBUG + if (index) { + for (int i = 0; i < index; i++) { + byte b = data[i]; + + if (b < 0x10) { + Serial.print('0'); + } + + Serial.print(b, HEX); + Serial.print(' '); + } + Serial.println(); + } +#endif + + if (index != (uint16_t)(10 + responseLength)) { + return -1; + } + + if (data[0] != 0xc0 || data[1] != 0x01 || data[2] != opcode || data[responseLength + 5] != 0x00 || data[responseLength + 6] != 0x00 || data[responseLength + 9] != 0xc0) { + return -1; + } + + if (body) { + memcpy(body, &data[9], responseLength - 4); + } + + return data[responseLength + 5]; +} + +void ESP32BootROMClass::writeEscapedBytes(const uint8_t* data, uint16_t length) { + uint16_t written = 0; + + while (written < length) { + uint8_t b = data[written++]; + + if (b == 0xdb) { + _serial->write(0xdb); + _serial->write(0xdd); + } else if (b == 0xc0) { + _serial->write(0xdb); + _serial->write(0xdc); + } else { + _serial->write(b); + } + } +} + +ESP32BootROMClass ESP32BootROM(SerialNina, NINA_GPIO0, NINA_RESETN); diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.h new file mode 100644 index 00000000..0b6f0e2b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.h @@ -0,0 +1,56 @@ +/* + ESP32BootROM - part of the Firmware Updater for the + Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. + + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include + +class ESP32BootROMClass { +public: + ESP32BootROMClass(HardwareSerial& hwSerial, int gpio0Pin, int resetnPin); + + int begin(unsigned long baudrate); + void end(); + + int beginFlash(uint32_t offset, uint32_t size, uint32_t chunkSize); + int dataFlash(const void* data, uint32_t length); + int endFlash(uint32_t reboot); + + int md5Flash(uint32_t offset, uint32_t size, uint8_t* result); + +private: + int sync(); + int changeBaudrate(unsigned long baudrate); + int spiAttach(); + + void command(int opcode, const void* data, uint16_t length); + int response(int opcode, unsigned long timeout, void* body = NULL); + + void writeEscapedBytes(const uint8_t* data, uint16_t length); + +private: + HardwareSerial* _serial; + int _gpio0Pin; + int _resetnPin; + + uint32_t _flashSequenceNumber; + uint32_t _chunkSize; +}; + +extern ESP32BootROMClass ESP32BootROM; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/Endianess.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/Endianess.ino new file mode 100644 index 00000000..7fde2500 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/Endianess.ino @@ -0,0 +1,64 @@ +/* + Endianess.ino - Network byte order conversion functions. + Copyright (c) 2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +bool isBigEndian() { + uint32_t test = 0x11223344; + uint8_t *pTest = reinterpret_cast(&test); + return pTest[0] == 0x11; +} + +uint32_t fromNetwork32(uint32_t from) { + static const bool be = isBigEndian(); + if (be) { + return from; + } else { + uint8_t *pFrom = reinterpret_cast(&from); + uint32_t to; + to = pFrom[0]; + to <<= 8; + to |= pFrom[1]; + to <<= 8; + to |= pFrom[2]; + to <<= 8; + to |= pFrom[3]; + return to; + } +} + +uint16_t fromNetwork16(uint16_t from) { + static bool be = isBigEndian(); + if (be) { + return from; + } else { + uint8_t *pFrom = reinterpret_cast(&from); + uint16_t to; + to = pFrom[0]; + to <<= 8; + to |= pFrom[1]; + return to; + } +} + +uint32_t toNetwork32(uint32_t to) { + return fromNetwork32(to); +} + +uint16_t toNetwork16(uint16_t to) { + return fromNetwork16(to); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/FirmwareUpdater.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/FirmwareUpdater.ino new file mode 100644 index 00000000..c412bb4f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/FirmwareUpdater.ino @@ -0,0 +1,143 @@ +/* + FirmwareUpdater - Firmware Updater for the + Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. + + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "ESP32BootROM.h" + +typedef struct __attribute__((__packed__)) { + uint8_t command; + uint32_t address; + uint32_t arg1; + uint16_t payloadLength; + + // payloadLength bytes of data follows... +} UartPacket; + +static const int MAX_PAYLOAD_SIZE = 1024; + +#define CMD_READ_FLASH 0x01 +#define CMD_WRITE_FLASH 0x02 +#define CMD_ERASE_FLASH 0x03 +#define CMD_MD5_FLASH 0x04 +#define CMD_MAX_PAYLOAD_SIZE 0x50 +#define CMD_HELLO 0x99 + +void setup() { + Serial.begin(1000000); + + if (!ESP32BootROM.begin(921600)) { + Serial.println("Unable to communicate with ESP32 boot ROM!"); + while (1) + ; + } +} + +void receivePacket(UartPacket *pkt, uint8_t *payload) { + // Read command + uint8_t *p = reinterpret_cast(pkt); + uint16_t l = sizeof(UartPacket); + while (l > 0) { + int c = Serial.read(); + if (c == -1) + continue; + *p++ = c; + l--; + } + + // Convert parameters from network byte order to cpu byte order + pkt->address = fromNetwork32(pkt->address); + pkt->arg1 = fromNetwork32(pkt->arg1); + pkt->payloadLength = fromNetwork16(pkt->payloadLength); + + // Read payload + l = pkt->payloadLength; + while (l > 0) { + int c = Serial.read(); + if (c == -1) + continue; + *payload++ = c; + l--; + } +} + +// Allocated statically so the compiler can tell us +// about the amount of used RAM +static UartPacket pkt; +static uint8_t payload[MAX_PAYLOAD_SIZE]; + +void loop() { + receivePacket(&pkt, payload); + + if (pkt.command == CMD_HELLO) { + if (pkt.address == 0x11223344 && pkt.arg1 == 0x55667788) + Serial.print("v10000"); + } + + if (pkt.command == CMD_MAX_PAYLOAD_SIZE) { + uint16_t res = toNetwork16(MAX_PAYLOAD_SIZE); + Serial.write(reinterpret_cast(&res), sizeof(res)); + } + + if (pkt.command == CMD_READ_FLASH) { + // not supported! + Serial.println("ER"); + } + + if (pkt.command == CMD_WRITE_FLASH) { + uint32_t len = pkt.payloadLength; + if (!ESP32BootROM.dataFlash(payload, len)) { + Serial.print("ER"); + } else { + Serial.print("OK"); + } + } + + if (pkt.command == CMD_ERASE_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.arg1; + if (!ESP32BootROM.beginFlash(address, len, MAX_PAYLOAD_SIZE)) { + Serial.print("ER"); + } else { + Serial.print("OK"); + } + } + + if (pkt.command == CMD_MD5_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.arg1; + + if (!ESP32BootROM.endFlash(1)) { + Serial.print("ER"); + } else { + ESP32BootROM.end(); + + uint8_t md5[16]; + + if (!ESP32BootROM.begin(921600)) { + Serial.print("ER"); + } else if (!ESP32BootROM.md5Flash(address, len, md5)) { + Serial.print("ER"); + } else { + Serial.print("OK"); + Serial.write(md5, sizeof(md5)); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/SerialNINAPassthrough/SerialNINAPassthrough.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/SerialNINAPassthrough/SerialNINAPassthrough.ino new file mode 100644 index 00000000..acfd078c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/Tools/SerialNINAPassthrough/SerialNINAPassthrough.ino @@ -0,0 +1,105 @@ +/* + SerialNINAPassthrough - Use esptool to flash the u-blox NINA (ESP32) module + Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. + + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifdef ARDUINO_SAMD_MKRVIDOR4000 +#include + +unsigned long baud = 119400; +#else +unsigned long baud = 115200; +#endif + +int rts = -1; +int dtr = -1; + +void setup() { + Serial.begin(baud); + +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.begin(); +#endif + + SerialNina.begin(baud); + +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.pinMode(FPGA_NINA_GPIO0, OUTPUT); + FPGA.pinMode(FPGA_SPIWIFI_RESET, OUTPUT); +#else + pinMode(NINA_GPIO0, OUTPUT); + pinMode(NINA_RESETN, OUTPUT); +#endif + +#ifdef ARDUINO_AVR_UNO_WIFI_REV2 + // manually put the NINA in upload mode + digitalWrite(NINA_GPIO0, LOW); + + digitalWrite(NINA_RESETN, LOW); + delay(100); + digitalWrite(NINA_RESETN, HIGH); + delay(100); + digitalWrite(NINA_RESETN, LOW); +#endif +} + +void loop() { +#ifndef ARDUINO_AVR_UNO_WIFI_REV2 + if (rts != Serial.rts()) { +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.digitalWrite(FPGA_SPIWIFI_RESET, (Serial.rts() == 1) ? LOW : HIGH); +#elif defined(ARDUINO_SAMD_NANO_33_IOT) + digitalWrite(NINA_RESETN, Serial.rts() ? LOW : HIGH); +#else + digitalWrite(NINA_RESETN, Serial.rts()); +#endif + rts = Serial.rts(); + } + + if (dtr != Serial.dtr()) { +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.digitalWrite(FPGA_NINA_GPIO0, (Serial.dtr() == 1) ? HIGH : LOW); +#else + digitalWrite(NINA_GPIO0, (Serial.dtr() == 0) ? HIGH : LOW); +#endif + dtr = Serial.dtr(); + } +#endif + + if (Serial.available()) { + SerialNina.write(Serial.read()); + } + + if (SerialNina.available()) { + Serial.write(SerialNina.read()); + } + +#ifndef ARDUINO_AVR_UNO_WIFI_REV2 + // check if the USB virtual serial wants a new baud rate + if (Serial.baud() != baud) { + rts = -1; + dtr = -1; + + baud = Serial.baud(); +#ifndef ARDUINO_SAMD_MKRVIDOR4000 + SerialNina.begin(baud); +#endif + } +#endif +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/WiFiChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/WiFiChatServer.ino new file mode 100644 index 00000000..8c103bbb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/WiFiChatServer.ino @@ -0,0 +1,118 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 18 Dec 2009 + by David A. Mellis + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(23); + +boolean alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // start the server: + server.begin(); + // you're connected now, so print out the status: + printWifiStatus(); +} + + +void loop() { + // wait for a new client: + WiFiClient client = server.available(); + + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clear out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/WiFiPing.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/WiFiPing.ino new file mode 100644 index 00000000..423b1f56 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/WiFiPing.ino @@ -0,0 +1,136 @@ +/* + This example connects to an encrypted WiFi network (WPA/WPA2). + Then it prints the MAC address of the board, + the IP address obtained, and other network details. + Then it continuously pings given host specified by IP Address or name. + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 09 June 2016 + by Petar Georgiev +*/ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +// Specify IP address or hostname +String hostName = "www.google.com"; +int pingResult; + +void setup() { + // Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 5 seconds for connection: + delay(5000); + } + + // you're connected now, so print out the data: + Serial.println("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + Serial.print("Pinging "); + Serial.print(hostName); + Serial.print(": "); + + pingResult = WiFi.ping(hostName); + + if (pingResult >= 0) { + Serial.print("SUCCESS! RTT = "); + Serial.print(pingResult); + Serial.println(" ms"); + } else { + Serial.print("FAILED! Error code: "); + Serial.println(pingResult); + } + + delay(5000); +} + +void printWiFiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP address : "); + Serial.println(ip); + + Serial.print("Subnet mask: "); + Serial.println((IPAddress)WiFi.subnetMask()); + + Serial.print("Gateway IP : "); + Serial.println((IPAddress)WiFi.gatewayIP()); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI): "); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type: "); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/WiFiSSLClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/WiFiSSLClient.ino new file mode 100644 index 00000000..c2aedb6b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/WiFiSSLClient.ino @@ -0,0 +1,114 @@ +/* +This example creates a client object that connects and transfers +data using always SSL. + +It is compatible with the methods normally related to plain +connections, like client.connect(host, port). + +Written by Arturo Guadalupi +last revision November 2015 + +*/ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiSSLClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 443)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true) + ; + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiStorage/WiFiStorage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiStorage/WiFiStorage.ino new file mode 100644 index 00000000..2c6070e5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiStorage/WiFiStorage.ino @@ -0,0 +1,43 @@ +/* + This example shows how to interact with NINA internal memory partition + APIs are modeled on SerialFlash library (not on SD) to speedup operations and avoid buffers. +*/ + +#include + +void setup() { + + Serial.begin(115200); + while (!Serial) + ; + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + WiFiStorageFile file = WiFiStorage.open("/fs/testfile"); + + if (file) { + file.erase(); + } + + String test = "Cantami o Diva del pelide Achille"; + file.write(test.c_str(), test.length()); + + if (file) { + file.seek(0); + while (file.available()) { + uint8_t buf[128]; + int ret = file.read(buf, 128); + Serial.write(buf, ret); + } + } +} + +void loop() { + // put your main code here, to run repeatedly: +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino new file mode 100644 index 00000000..5a35e756 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -0,0 +1,174 @@ +/* + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + This code is in the public domain. + + */ + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(162, 159, 200, 123); // pool.ntp.org NTP server + +const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) { + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino new file mode 100644 index 00000000..6b0f2945 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -0,0 +1,113 @@ +/* + WiFi UDP Send and Receive String + + This sketch waits for a UDP packet on localPort using the WiFi module. + When a packet is received an Acknowledge packet is sent to the client on port remotePort + + created 30 December 2012 + by dlf (Metodo2 srl) + + */ + + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen on + +char packetBuffer[256]; //buffer to hold incoming packet +char ReplyBuffer[] = "acknowledged"; // a string to send back + +WiFiUDP Udp; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + Udp.begin(localPort); +} + +void loop() { + + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remoteIp = Udp.remoteIP(); + Serial.print(remoteIp); + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBufffer + int len = Udp.read(packetBuffer, 255); + if (len > 0) { + packetBuffer[len] = 0; + } + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply, to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/WiFiWebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/WiFiWebClient.ino new file mode 100644 index 00000000..6831c0a6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/WiFiWebClient.ino @@ -0,0 +1,124 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using the WiFi module. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ + + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true) + ; + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino new file mode 100644 index 00000000..ed8256af --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -0,0 +1,128 @@ +/* + Repeating WiFi Web Client + + This sketch connects to a a web server and makes a request + using a WiFi equipped Arduino board. + + created 23 April 2012 + modified 31 May 2012 + by Tom Igoe + modified 13 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating + This code is in the public domain. + */ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +// Initialize the WiFi client library +WiFiClient client; + +// server address: +char server[] = "example.org"; +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the NINA module + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET / HTTP/1.1"); + client.println("Host: example.org"); + client.println("User-Agent: ArduinoWiFi/1.1"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/WiFiWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/WiFiWebServer.ino new file mode 100644 index 00000000..b3b9e1cd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/WiFiWebServer.ino @@ -0,0 +1,138 @@ +/* + WiFi Web Server + + A simple web server that shows the value of the analog input pins. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); + // you're connected now, so print out the status: + printWifiStatus(); +} + + +void loop() { + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
"); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/README.adoc new file mode 100644 index 00000000..26a5c0e9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/README.adoc @@ -0,0 +1,12 @@ += Arduino Cloud Provider Examples = + +Examples of how to connect various Arduino boards to cloud providers. + +Related tutorials on Arduino Project Hub: + +* AWS: +** https://create.arduino.cc/projecthub/132016/securely-connecting-an-arduino-mkr-wifi-1010-to-aws-iot-core-a9f365[Securely connecting an Arduino MKR WiFi 1010 to AWS IoT Core] +* Azure +** https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-nb-1500-to-azure-iot-hub-af6470[Securely Connecting an Arduino NB 1500 to Azure IoT Hub] +* Google Cloud +** https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-mkr-gsm-1400-to-gcp-iot-core-b8b628[Securely Connecting an Arduino MKR GSM 1400 to GCP IoT Core] diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/AWS_IoT_GSM.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/AWS_IoT_GSM.ino new file mode 100644 index 00000000..f4acb234 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/AWS_IoT_GSM.ino @@ -0,0 +1,159 @@ +/* + AWS IoT GSM + + This sketch securely connects to an AWS IoT using MQTT over GSM/3G. + It uses a private key stored in the ATECC508A and a public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to arduino/outgoing + topic and subscribes to messages on the arduino/incoming + topic. + + The circuit: + - MKR GSM 1400 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char gprs_apn[] = SECRET_GPRS_APN; +const char gprs_login[] = SECRET_GPRS_LOGIN; +const char gprs_password[] = SECRET_GPRS_PASSWORD; +const char broker[] = SECRET_BROKER; +const char* certificate = SECRET_CERTIFICATE; + +GSM gsmAccess; +GPRS gprs; + +GSMClient gsmClient; // Used for the TCP socket connection +BearSSLClient sslClient(gsmClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, certificate); + + // Optional, set the client id used for MQTT, + // each device that is connected to the broker + // must have a unique client id. The MQTTClient will generate + // a client id for you based on the millis() value if not set + // + // mqttClient.setId("clientId"); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (gsmAccess.status() != GSM_READY || gprs.status() != GPRS_READY) { + connectGSM(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the GSM module + return gsmAccess.getTime(); +} + +void connectGSM() { + Serial.println("Attempting to connect to the cellular network"); + + while ((gsmAccess.begin(pinnumber) != GSM_READY) || (gprs.attachGPRS(gprs_apn, gprs_login, gprs_password) != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("arduino/incoming"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("arduino/outgoing"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/arduino_secrets.h new file mode 100644 index 00000000..1906a18a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/arduino_secrets.h @@ -0,0 +1,15 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + +// Fill in the hostname of your AWS IoT broker +#define SECRET_BROKER "xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com" + +// Fill in the boards public certificate +const char SECRET_CERTIFICATE[] = R"( +-----BEGIN CERTIFICATE----- + +-----END CERTIFICATE----- +)"; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/AWS_IoT_NB.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/AWS_IoT_NB.ino new file mode 100644 index 00000000..e37910b4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/AWS_IoT_NB.ino @@ -0,0 +1,156 @@ +/* + AWS IoT NB + + This sketch securely connects to an AWS IoT using MQTT over NB IoT/LTE Cat M1. + It uses a private key stored in the ATECC508A and a public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to arduino/outgoing + topic and subscribes to messages on the arduino/incoming + topic. + + The circuit: + - MKR NB 1500 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char broker[] = SECRET_BROKER; +const char* certificate = SECRET_CERTIFICATE; + +NB nbAccess; +GPRS gprs; + +NBClient nbClient; // Used for the TCP socket connection +BearSSLClient sslClient(nbClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, certificate); + + // Optional, set the client id used for MQTT, + // each device that is connected to the broker + // must have a unique client id. The MQTTClient will generate + // a client id for you based on the millis() value if not set + // + // mqttClient.setId("clientId"); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (nbAccess.status() != NB_READY || gprs.status() != GPRS_READY) { + connectNB(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the NB module + return nbAccess.getTime(); +} + +void connectNB() { + Serial.println("Attempting to connect to the cellular network"); + + while ((nbAccess.begin(pinnumber) != NB_READY) || (gprs.attachGPRS() != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("arduino/incoming"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("arduino/outgoing"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/arduino_secrets.h new file mode 100644 index 00000000..0ab9288f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/arduino_secrets.h @@ -0,0 +1,12 @@ +// NB settings +#define SECRET_PINNUMBER "" + +// Fill in the hostname of your AWS IoT broker +#define SECRET_BROKER "xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com" + +// Fill in the boards public certificate +const char SECRET_CERTIFICATE[] = R"( +-----BEGIN CERTIFICATE----- + +-----END CERTIFICATE----- +)"; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/AWS_IoT_WiFi.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/AWS_IoT_WiFi.ino new file mode 100644 index 00000000..dd081738 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/AWS_IoT_WiFi.ino @@ -0,0 +1,159 @@ +/* + AWS IoT WiFi + + This sketch securely connects to an AWS IoT using MQTT over WiFi. + It uses a private key stored in the ATECC508A and a public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to arduino/outgoing + topic and subscribes to messages on the arduino/incoming + topic. + + The circuit: + - Arduino MKR WiFi 1010 or MKR1000 + + The following tutorial on Arduino Project Hub can be used + to setup your AWS account and the MKR board: + + https://create.arduino.cc/projecthub/132016/securely-connecting-an-arduino-mkr-wifi-1010-to-aws-iot-core-a9f365 + + This example code is in the public domain. +*/ + +#include +#include +#include +#include // change to #include for MKR1000 + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char ssid[] = SECRET_SSID; +const char pass[] = SECRET_PASS; +const char broker[] = SECRET_BROKER; +const char* certificate = SECRET_CERTIFICATE; + +WiFiClient wifiClient; // Used for the TCP socket connection +BearSSLClient sslClient(wifiClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, certificate); + + // Optional, set the client id used for MQTT, + // each device that is connected to the broker + // must have a unique client id. The MQTTClient will generate + // a client id for you based on the millis() value if not set + // + // mqttClient.setId("clientId"); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (WiFi.status() != WL_CONNECTED) { + connectWiFi(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void connectWiFi() { + Serial.print("Attempting to connect to SSID: "); + Serial.print(ssid); + Serial.print(" "); + + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("arduino/incoming"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("arduino/outgoing"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/arduino_secrets.h new file mode 100644 index 00000000..c89feb07 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/arduino_secrets.h @@ -0,0 +1,13 @@ +// Fill in your WiFi networks SSID and password +#define SECRET_SSID "" +#define SECRET_PASS "" + +// Fill in the hostname of your AWS IoT broker +#define SECRET_BROKER "xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com" + +// Fill in the boards public certificate +const char SECRET_CERTIFICATE[] = R"( +-----BEGIN CERTIFICATE----- + +-----END CERTIFICATE----- +)"; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/Azure_IoT_Hub_GSM.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/Azure_IoT_Hub_GSM.ino new file mode 100644 index 00000000..ddb66c4e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/Azure_IoT_Hub_GSM.ino @@ -0,0 +1,172 @@ +/* + Azure IoT Hub GSM + + This sketch securely connects to an Azure IoT Hub using MQTT over GSM/3G. + It uses a private key stored in the ATECC508A and a self signed public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to "devices/{deviceId}/messages/events/" topic + and subscribes to messages on the "devices/{deviceId}/messages/devicebound/#" + topic. + + The circuit: + - MKR GSM 1400 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char gprs_apn[] = SECRET_GPRS_APN; +const char gprs_login[] = SECRET_GPRS_LOGIN; +const char gprs_password[] = SECRET_GPRS_PASSWORD; +const char broker[] = SECRET_BROKER; +String deviceId = SECRET_DEVICE_ID; + +GSM gsmAccess; +GPRS gprs; + +GSMClient gsmClient; // Used for the TCP socket connection +BearSSLClient sslClient(gsmClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // reconstruct the self signed cert + ECCX08SelfSignedCert.beginReconstruction(0, 8); + ECCX08SelfSignedCert.setCommonName(ECCX08.serialNumber()); + ECCX08SelfSignedCert.endReconstruction(); + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, ECCX08SelfSignedCert.bytes(), ECCX08SelfSignedCert.length()); + + // Set the client id used for MQTT as the device id + mqttClient.setId(deviceId); + + // Set the username to "//api-version=2018-06-30" and empty password + String username; + + username += broker; + username += "/"; + username += deviceId; + username += "/api-version=2018-06-30"; + + mqttClient.setUsernamePassword(username, ""); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (gsmAccess.status() != GSM_READY || gprs.status() != GPRS_READY) { + connectGSM(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the cellular module + return gsmAccess.getTime(); +} + +void connectGSM() { + Serial.println("Attempting to connect to the cellular network"); + + while ((gsmAccess.begin(pinnumber) != GSM_READY) || (gprs.attachGPRS(gprs_apn, gprs_login, gprs_password) != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + Serial.println(mqttClient.connectError()); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/#"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("devices/" + deviceId + "/messages/events/"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/arduino_secrets.h new file mode 100644 index 00000000..a7532a33 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/arduino_secrets.h @@ -0,0 +1,11 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + +// Fill in the hostname of your Azure IoT Hub broker +#define SECRET_BROKER ".azure-devices.net" + +// Fill in the device id +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/Azure_IoT_Hub_NB.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/Azure_IoT_Hub_NB.ino new file mode 100644 index 00000000..707ec378 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/Azure_IoT_Hub_NB.ino @@ -0,0 +1,174 @@ +/* + Azure IoT Hub NB + + This sketch securely connects to an Azure IoT Hub using MQTT over NB IoT/LTE Cat M1. + It uses a private key stored in the ATECC508A and a self signed public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to "devices/{deviceId}/messages/events/" topic + and subscribes to messages on the "devices/{deviceId}/messages/devicebound/#" + topic. + + The circuit: + - MKR NB 1500 board + - Antenna + - SIM card with a data plan + - LiPo battery + + The following tutorial on Arduino Project Hub can be used + to setup your Azure account and the MKR board: + + https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-nb-1500-to-azure-iot-hub-af6470 + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char broker[] = SECRET_BROKER; +String deviceId = SECRET_DEVICE_ID; + +NB nbAccess; +GPRS gprs; + +NBClient nbClient; // Used for the TCP socket connection +BearSSLClient sslClient(nbClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // reconstruct the self signed cert + ECCX08SelfSignedCert.beginReconstruction(0, 8); + ECCX08SelfSignedCert.setCommonName(ECCX08.serialNumber()); + ECCX08SelfSignedCert.endReconstruction(); + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, ECCX08SelfSignedCert.bytes(), ECCX08SelfSignedCert.length()); + + // Set the client id used for MQTT as the device id + mqttClient.setId(deviceId); + + // Set the username to "//api-version=2018-06-30" and empty password + String username; + + username += broker; + username += "/"; + username += deviceId; + username += "/api-version=2018-06-30"; + + mqttClient.setUsernamePassword(username, ""); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (nbAccess.status() != NB_READY || gprs.status() != GPRS_READY) { + connectNB(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the cellular module + return nbAccess.getTime(); +} + +void connectNB() { + Serial.println("Attempting to connect to the cellular network"); + + while ((nbAccess.begin(pinnumber) != NB_READY) || (gprs.attachGPRS() != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + Serial.println(mqttClient.connectError()); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/#"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("devices/" + deviceId + "/messages/events/"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/arduino_secrets.h new file mode 100644 index 00000000..6dbe391d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/arduino_secrets.h @@ -0,0 +1,8 @@ +// NB settings +#define SECRET_PINNUMBER "" + +// Fill in the hostname of your Azure IoT Hub broker +#define SECRET_BROKER ".azure-devices.net" + +// Fill in the device id +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/Azure_IoT_Hub_WiFi.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/Azure_IoT_Hub_WiFi.ino new file mode 100644 index 00000000..bd873805 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/Azure_IoT_Hub_WiFi.ino @@ -0,0 +1,167 @@ +/* + Azure IoT Hub WiFi + + This sketch securely connects to an Azure IoT Hub using MQTT over WiFi. + It uses a private key stored in the ATECC508A and a self signed public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to "devices/{deviceId}/messages/events/" topic + and subscribes to messages on the "devices/{deviceId}/messages/devicebound/#" + topic. + + The circuit: + - Arduino MKR WiFi 1010 or MKR1000 + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include // change to #include for MKR1000 + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char ssid[] = SECRET_SSID; +const char pass[] = SECRET_PASS; +const char broker[] = SECRET_BROKER; +String deviceId = SECRET_DEVICE_ID; + +WiFiClient wifiClient; // Used for the TCP socket connection +BearSSLClient sslClient(wifiClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // reconstruct the self signed cert + ECCX08SelfSignedCert.beginReconstruction(0, 8); + ECCX08SelfSignedCert.setCommonName(ECCX08.serialNumber()); + ECCX08SelfSignedCert.endReconstruction(); + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, ECCX08SelfSignedCert.bytes(), ECCX08SelfSignedCert.length()); + + // Set the client id used for MQTT as the device id + mqttClient.setId(deviceId); + + // Set the username to "//api-version=2018-06-30" and empty password + String username; + + username += broker; + username += "/"; + username += deviceId; + username += "/api-version=2018-06-30"; + + mqttClient.setUsernamePassword(username, ""); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (WiFi.status() != WL_CONNECTED) { + connectWiFi(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void connectWiFi() { + Serial.print("Attempting to connect to SSID: "); + Serial.print(ssid); + Serial.print(" "); + + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + Serial.println(mqttClient.connectError()); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/#"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("devices/" + deviceId + "/messages/events/"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/arduino_secrets.h new file mode 100644 index 00000000..41732b36 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/arduino_secrets.h @@ -0,0 +1,9 @@ +// Fill in your WiFi networks SSID and password +#define SECRET_SSID "" +#define SECRET_PASS "" + +// Fill in the hostname of your Azure IoT Hub broker +#define SECRET_BROKER ".azure-devices.net" + +// Fill in the device id +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/GCP_IoT_Core_GSM.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/GCP_IoT_Core_GSM.ino new file mode 100644 index 00000000..2a6f1b4b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/GCP_IoT_Core_GSM.ino @@ -0,0 +1,200 @@ +/* + GCP (Google Cloud Platform) IoT Core GSM + + This sketch securely connects to GCP IoT Core using MQTT over GSM/3G. + It uses a private key stored in the ATECC508A and a JSON Web Token (JWT) with + a JSON Web Signature (JWS). + + It publishes a message every 5 seconds to "/devices/{deviceId}/state" topic + and subscribes to messages on the "/devices/{deviceId}/config" and + "/devices/{deviceId}/commands/#" topics. + + The circuit: + - MKR GSM 1400 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char gprs_apn[] = SECRET_GPRS_APN; +const char gprs_login[] = SECRET_GPRS_LOGIN; +const char gprs_password[] = SECRET_GPRS_PASSWORD; + +const char projectId[] = SECRET_PROJECT_ID; +const char cloudRegion[] = SECRET_CLOUD_REGION; +const char registryId[] = SECRET_REGISTRY_ID; +const String deviceId = SECRET_DEVICE_ID; + +const char broker[] = "mqtt.googleapis.com"; + +GSM gsmAccess; +GPRS gprs; + +GSMSSLClient gsmSslClient; +MqttClient mqttClient(gsmSslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // Calculate and set the client id used for MQTT + String clientId = calculateClientId(); + + mqttClient.setId(clientId); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (gsmAccess.status() != GSM_READY || gprs.status() != GPRS_READY) { + connectGSM(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the cellular module + return gsmAccess.getTime(); +} + +void connectGSM() { + Serial.println("Attempting to connect to the cellular network"); + + while ((gsmAccess.begin(pinnumber) != GSM_READY) || (gprs.attachGPRS(gprs_apn, gprs_login, gprs_password) != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to connect to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connected()) { + // Calculate the JWT and assign it as the password + String jwt = calculateJWT(); + + mqttClient.setUsernamePassword("", jwt); + + if (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to topics + mqttClient.subscribe("/devices/" + deviceId + "/config", 1); + mqttClient.subscribe("/devices/" + deviceId + "/commands/#"); +} + +String calculateClientId() { + String clientId; + + // Format: + // + // projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id} + // + + clientId += "projects/"; + clientId += projectId; + clientId += "/locations/"; + clientId += cloudRegion; + clientId += "/registries/"; + clientId += registryId; + clientId += "/devices/"; + clientId += deviceId; + + return clientId; +} + +String calculateJWT() { + unsigned long now = getTime(); + + // calculate the JWT, based on: + // https://cloud.google.com/iot/docs/how-tos/credentials/jwts + JSONVar jwtHeader; + JSONVar jwtClaim; + + jwtHeader["alg"] = "ES256"; + jwtHeader["typ"] = "JWT"; + + jwtClaim["aud"] = projectId; + jwtClaim["iat"] = now; + jwtClaim["exp"] = now + (24L * 60L * 60L); // expires in 24 hours + + return ECCX08JWS.sign(0, JSON.stringify(jwtHeader), JSON.stringify(jwtClaim)); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("/devices/" + deviceId + "/state"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/arduino_secrets.h new file mode 100644 index 00000000..fa4ba479 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/arduino_secrets.h @@ -0,0 +1,11 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + +// Fill in your Google Cloud Platform - IoT Core info +#define SECRET_PROJECT_ID "" +#define SECRET_CLOUD_REGION "" +#define SECRET_REGISTRY_ID "" +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/GCP_IoT_Core_NB.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/GCP_IoT_Core_NB.ino new file mode 100644 index 00000000..67ab6d1e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/GCP_IoT_Core_NB.ino @@ -0,0 +1,197 @@ +/* + GCP (Google Cloud Platform) IoT Core NB + + This sketch securely connects to GCP IoT Core using MQTT over NB IoT/LTE Cat M1. + It uses a private key stored in the ATECC508A and a JSON Web Token (JWT) with + a JSON Web Signature (JWS). + + It publishes a message every 5 seconds to "/devices/{deviceId}/state" topic + and subscribes to messages on the "/devices/{deviceId}/config" and + "/devices/{deviceId}/commands/#" topics. + + The circuit: + - MKR NB 1500 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; + +const char projectId[] = SECRET_PROJECT_ID; +const char cloudRegion[] = SECRET_CLOUD_REGION; +const char registryId[] = SECRET_REGISTRY_ID; +const String deviceId = SECRET_DEVICE_ID; + +const char broker[] = "mqtt.googleapis.com"; + +NB nbAccess; +GPRS gprs; + +NBSSLClient nbSslClient; +MqttClient mqttClient(nbSslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // Calculate and set the client id used for MQTT + String clientId = calculateClientId(); + + mqttClient.setId(clientId); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (nbAccess.status() != NB_READY || gprs.status() != GPRS_READY) { + connectNB(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the cellular module + return nbAccess.getTime(); +} + +void connectNB() { + Serial.println("Attempting to connect to the cellular network"); + + while ((nbAccess.begin(pinnumber) != NB_READY) || (gprs.attachGPRS() != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to connect to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connected()) { + // Calculate the JWT and assign it as the password + String jwt = calculateJWT(); + + mqttClient.setUsernamePassword("", jwt); + + if (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to topics + mqttClient.subscribe("/devices/" + deviceId + "/config", 1); + mqttClient.subscribe("/devices/" + deviceId + "/commands/#"); +} + +String calculateClientId() { + String clientId; + + // Format: + // + // projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id} + // + + clientId += "projects/"; + clientId += projectId; + clientId += "/locations/"; + clientId += cloudRegion; + clientId += "/registries/"; + clientId += registryId; + clientId += "/devices/"; + clientId += deviceId; + + return clientId; +} + +String calculateJWT() { + unsigned long now = getTime(); + + // calculate the JWT, based on: + // https://cloud.google.com/iot/docs/how-tos/credentials/jwts + JSONVar jwtHeader; + JSONVar jwtClaim; + + jwtHeader["alg"] = "ES256"; + jwtHeader["typ"] = "JWT"; + + jwtClaim["aud"] = projectId; + jwtClaim["iat"] = now; + jwtClaim["exp"] = now + (24L * 60L * 60L); // expires in 24 hours + + return ECCX08JWS.sign(0, JSON.stringify(jwtHeader), JSON.stringify(jwtClaim)); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("/devices/" + deviceId + "/state"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/arduino_secrets.h new file mode 100644 index 00000000..8d059b86 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/arduino_secrets.h @@ -0,0 +1,8 @@ +// NB settings +#define SECRET_PINNUMBER "" + +// Fill in your Google Cloud Platform - IoT Core info +#define SECRET_PROJECT_ID "" +#define SECRET_CLOUD_REGION "" +#define SECRET_REGISTRY_ID "" +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/GCP_IoT_Core_WiFi.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/GCP_IoT_Core_WiFi.ino new file mode 100644 index 00000000..ba846880 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/GCP_IoT_Core_WiFi.ino @@ -0,0 +1,195 @@ +/* + GCP (Google Cloud Platform) IoT Core WiFi + + This sketch securely connects to GCP IoT Core using MQTT over WiFi. + It uses a private key stored in the ATECC508A and a JSON Web Token (JWT) with + a JSON Web Signature (JWS). + + It publishes a message every 5 seconds to "/devices/{deviceId}/state" topic + and subscribes to messages on the "/devices/{deviceId}/config" and + "/devices/{deviceId}/commands/#" topics. + + The circuit: + - Arduino MKR WiFi 1010 or MKR1000 + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include // change to #include for MKR1000 + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char ssid[] = SECRET_SSID; +const char pass[] = SECRET_PASS; + +const char projectId[] = SECRET_PROJECT_ID; +const char cloudRegion[] = SECRET_CLOUD_REGION; +const char registryId[] = SECRET_REGISTRY_ID; +const String deviceId = SECRET_DEVICE_ID; + +const char broker[] = "mqtt.googleapis.com"; + +WiFiSSLClient wifiSslClient; +MqttClient mqttClient(wifiSslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1) + ; + } + + // Calculate and set the client id used for MQTT + String clientId = calculateClientId(); + + mqttClient.setId(clientId); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (WiFi.status() != WL_CONNECTED) { + connectWiFi(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void connectWiFi() { + Serial.print("Attempting to connect to SSID: "); + Serial.print(ssid); + Serial.print(" "); + + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to connect to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connected()) { + // Calculate the JWT and assign it as the password + String jwt = calculateJWT(); + + mqttClient.setUsernamePassword("", jwt); + + if (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to topics + mqttClient.subscribe("/devices/" + deviceId + "/config", 1); + mqttClient.subscribe("/devices/" + deviceId + "/commands/#"); +} + +String calculateClientId() { + String clientId; + + // Format: + // + // projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id} + // + + clientId += "projects/"; + clientId += projectId; + clientId += "/locations/"; + clientId += cloudRegion; + clientId += "/registries/"; + clientId += registryId; + clientId += "/devices/"; + clientId += deviceId; + + return clientId; +} + +String calculateJWT() { + unsigned long now = getTime(); + + // calculate the JWT, based on: + // https://cloud.google.com/iot/docs/how-tos/credentials/jwts + JSONVar jwtHeader; + JSONVar jwtClaim; + + jwtHeader["alg"] = "ES256"; + jwtHeader["typ"] = "JWT"; + + jwtClaim["aud"] = projectId; + jwtClaim["iat"] = now; + jwtClaim["exp"] = now + (24L * 60L * 60L); // expires in 24 hours + + return ECCX08JWS.sign(0, JSON.stringify(jwtHeader), JSON.stringify(jwtClaim)); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("/devices/" + deviceId + "/state"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/arduino_secrets.h new file mode 100644 index 00000000..ce296c87 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/arduino_secrets.h @@ -0,0 +1,9 @@ +// Fill in your WiFi networks SSID and password +#define SECRET_SSID "" +#define SECRET_PASS "" + +// Fill in your Google Cloud Platform - IoT Core info +#define SECRET_PROJECT_ID "" +#define SECRET_CLOUD_REGION "" +#define SECRET_REGISTRY_ID "" +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/README.md new file mode 100644 index 00000000..42a1f043 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/README.md @@ -0,0 +1,8 @@ +# Arduino AVR Boards + +[![Check Arduino status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/compile-platform-examples.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/compile-platform-examples.yml) +[![Spell Check status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/spell-check.yml) + +This repository contains the source code and configuration files of the Arduino AVR Boards +[platform](https://arduino.github.io/arduino-cli/latest/platform-specification/). diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/README.md new file mode 100644 index 00000000..9ca761d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/README.md @@ -0,0 +1,139 @@ +## **EEPROM Library V2.0** for Arduino + +**Written by:** _Christopher Andrews_. + +### **What is the EEPROM library.** + +Th EEPROM library provides an easy to use interface to interact with the internal non-volatile storage found in AVR based Arduino boards. This library will work on many AVR devices like ATtiny and ATmega chips. + +### **How to use it** +The EEPROM library is included in your IDE download. To add its functionality to your sketch you'll need to reference the library header file. You do this by adding an include directive to the top of your sketch. + +```Arduino +#include + +void setup(){ + +} + +void loop(){ + +} + +``` + +The library provides a global variable named `EEPROM`, you use this variable to access the library functions. The methods provided in the EEPROM class are listed below. + +You can view all the examples [here](examples/). + +### **Library functions** + +#### **`EEPROM.read( address )`** [[_example_]](examples/eeprom_read/eeprom_read.ino) + +This function allows you to read a single byte of data from the eeprom. +Its only parameter is an `int` which should be set to the address you wish to read. + +The function returns an `unsigned char` containing the value read. + +#### **`EEPROM.write( address, value )`** [[_example_]](examples/eeprom_write/eeprom_write.ino) + +The `write()` method allows you to write a single byte of data to the EEPROM. +Two parameters are needed. The first is an `int` containing the address that is to be written, and the second is a the data to be written (`unsigned char`). + +This function does not return any value. + +#### **`EEPROM.update( address, value )`** [[_example_]](examples/eeprom_update/eeprom_update.ino) + +This function is similar to `EEPROM.write()` however this method will only write data if the cell contents pointed to by `address` is different to `value`. This method can help prevent unnecessary wear on the EEPROM cells. + +This function does not return any value. + +#### **`EEPROM.get( address, object )`** [[_example_]](examples/eeprom_get/eeprom_get.ino) + +This function will retrieve any object from the EEPROM. +Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to read. + +This function returns a reference to the `object` passed in. It does not need to be used and is only returned for convenience. + +#### **`EEPROM.put( address, object )`** [[_example_]](examples/eeprom_put/eeprom_put.ino) + +This function will write any object to the EEPROM. +Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to write. + +This function uses the _update_ method to write its data, and therefore only rewrites changed cells. + +This function returns a reference to the `object` passed in. It does not need to be used and is only returned for convenience. + +#### **Subscript operator: `EEPROM[address]`** [[_example_]](examples/eeprom_crc/eeprom_crc.ino) + +This operator allows using the identifier `EEPROM` like an array. +EEPROM cells can be read _and_ **_written_** directly using this method. + +This operator returns a reference to the EEPROM cell. + +```c++ +unsigned char val; + +//Read first EEPROM cell. +val = EEPROM[ 0 ]; + +//Write first EEPROM cell. +EEPROM[ 0 ] = val; + +//Compare contents +if( val == EEPROM[ 0 ] ){ + //Do something... +} +``` + +#### **`EEPROM.length()`** + +This function returns an `unsigned int` containing the number of cells in the EEPROM. + +--- + +### **Advanced features** + +This library uses a component based approach to provide its functionality. This means you can also use these components to design a customized approach. Two background classes are available for use: `EERef` & `EEPtr`. + +#### **`EERef` class** + +This object references an EEPROM cell. +Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM. +This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell. + +```C++ +EERef ref = EEPROM[ 10 ]; //Create a reference to 11th cell. + +ref = 4; //write to EEPROM cell. + +unsigned char val = ref; //Read referenced cell. +``` + +#### **`EEPtr` class** + +This object is a bidirectional pointer to EEPROM cells represented by `EERef` objects. +Just like a normal pointer type, this type can be dereferenced and repositioned using +increment/decrement operators. + +```C++ +EEPtr ptr = 10; //Create a pointer to 11th cell. + +*ptr = 4; //dereference and write to EEPROM cell. + +unsigned char val = *ptr; //dereference and read. + +ptr++; //Move to next EEPROM cell. +``` + +#### **`EEPROM.begin()`** + +This function returns an `EEPtr` pointing to the first cell in the EEPROM. +This is useful for STL objects, custom iteration and C++11 style ranged for loops. + +#### **`EEPROM.end()`** + +This function returns an `EEPtr` pointing at the location after the last EEPROM cell. +Used with `begin()` to provide custom iteration. + +**Note:** The `EEPtr` returned is invalid as it is out of range. In fact the hardware causes wrapping of the address (overflow) and `EEPROM.end()` actually references the first EEPROM cell. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino new file mode 100644 index 00000000..9d277f5e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino @@ -0,0 +1,39 @@ +/* + * EEPROM Clear + * + * Sets all of the bytes of the EEPROM to 0. + * Please see eeprom_iteration for a more in depth + * look at how to traverse the EEPROM. + * + * This example code is in the public domain. + */ + +#include + +void setup() { + // initialize the LED pin as an output. + pinMode(13, OUTPUT); + + /*** + Iterate through each byte of the EEPROM storage. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduino Duemilanove: 512 B EEPROM storage. + - Arduino Uno: 1 kB EEPROM storage. + - Arduino Mega: 4 kB EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + + for (int i = 0; i < EEPROM.length(); i++) { + EEPROM.write(i, 0); + } + + // turn the LED on when we're done + digitalWrite(13, HIGH); +} + +void loop() { + /** Empty loop. **/ +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino new file mode 100644 index 00000000..893a54dc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino @@ -0,0 +1,52 @@ +/*** + Written by Christopher Andrews. + CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). + + A CRC is a simple way of checking whether data has changed or become corrupted. + This example calculates a CRC value directly on the EEPROM values. + The purpose of this example is to highlight how the EEPROM object can be used just like an array. +***/ + +#include +#include + +void setup() { + + //Start serial + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + //Print length of data to run CRC on. + Serial.print("EEPROM length: "); + Serial.println(EEPROM.length()); + + //Print the result of calling eeprom_crc() + Serial.print("CRC32 of EEPROM data: 0x"); + Serial.println(eeprom_crc(), HEX); + Serial.print("\n\nDone!"); +} + +void loop() { + /* Empty loop */ +} + +unsigned long eeprom_crc(void) { + + const unsigned long crc_table[16] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, + 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, + 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c + }; + + unsigned long crc = ~0L; + + for (int index = 0; index < EEPROM.length(); ++index) { + crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4); + crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4); + crc = ~crc; + } + return crc; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino new file mode 100644 index 00000000..4db5a6db --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino @@ -0,0 +1,68 @@ +/*** + eeprom_get example. + + This shows how to use the EEPROM.get() method. + + To pre-set the EEPROM data, run the example sketch eeprom_put. + This sketch will run without it, however, the values shown + will be shown from what ever is already on the EEPROM. + + This may cause the serial object to print out a large string + of garbage if there is no null character inside one of the strings + loaded. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + float f = 0.00f; //Variable to store data read from EEPROM. + int eeAddress = 0; //EEPROM address to start reading from + + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.print("Read float from EEPROM: "); + + //Get the float data from the EEPROM at position 'eeAddress' + EEPROM.get(eeAddress, f); + Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. + + /*** + As get also returns a reference to 'f', you can use it inline. + E.g: Serial.print( EEPROM.get( eeAddress, f ) ); + ***/ + + /*** + Get can be used with custom structures too. + I have separated this into an extra function. + ***/ + + secondTest(); //Run the next test. +} + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +void secondTest() { + int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. + + MyObject customVar; //Variable to store custom object read from EEPROM. + EEPROM.get(eeAddress, customVar); + + Serial.println("Read custom object from EEPROM: "); + Serial.println(customVar.field1); + Serial.println(customVar.field2); + Serial.println(customVar.name); +} + +void loop() { + /* Empty loop */ +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino new file mode 100644 index 00000000..bd157c04 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -0,0 +1,57 @@ +/*** + eeprom_iteration example. + + A set of example snippets highlighting the + simplest methods for traversing the EEPROM. + + Running this sketch is not necessary, this is + simply highlighting certain programming methods. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + /*** + Iterate the EEPROM using a for loop. + ***/ + + for (int index = 0; index < EEPROM.length(); index++) { + + //Add one to each cell in the EEPROM + EEPROM[index] += 1; + } + + /*** + Iterate the EEPROM using a while loop. + ***/ + + int index = 0; + + while (index < EEPROM.length()) { + + //Add one to each cell in the EEPROM + EEPROM[index] += 1; + index++; + } + + /*** + Iterate the EEPROM using a do-while loop. + ***/ + + int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. + + do { + + //Add one to each cell in the EEPROM + EEPROM[idx] += 1; + idx++; + } while (idx < EEPROM.length()); + + +} //End of setup function. + +void loop() {} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino new file mode 100644 index 00000000..434468ba --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino @@ -0,0 +1,58 @@ +/*** + eeprom_put example. + + This shows how to use the EEPROM.put() method. + Also, this sketch will pre-set the EEPROM data for the + example sketch eeprom_get. + + Note, unlike the single byte version EEPROM.write(), + the put method will use update semantics. As in a byte + will only be written to the EEPROM if the data is actually + different. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +void setup() { + + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + float f = 123.456f; //Variable to store in EEPROM. + int eeAddress = 0; //Location we want the data to be put. + + + //One simple call, with the address first and the object second. + EEPROM.put(eeAddress, f); + + Serial.println("Written float data type!"); + + /** Put is designed for use with custom structures also. **/ + + //Data to store. + MyObject customVar = { + 3.14f, + 65, + "Working!" + }; + + eeAddress += sizeof(float); //Move address to the next byte after float 'f'. + + EEPROM.put(eeAddress, customVar); + Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); +} + +void loop() { + /* Empty loop */ +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino new file mode 100644 index 00000000..2d3bffbd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @@ -0,0 +1,56 @@ +/* + * EEPROM Read + * + * Reads the value of each byte of the EEPROM and prints it + * to the computer. + * This example code is in the public domain. + */ + +#include + +// start reading from the first byte (address 0) of the EEPROM +int address = 0; +byte value; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } +} + +void loop() { + // read a byte from the current address of the EEPROM + value = EEPROM.read(address); + + Serial.print(address); + Serial.print("\t"); + Serial.print(value, DEC); + Serial.println(); + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduino Duemilanove: 512 B EEPROM storage. + - Arduino Uno: 1 kB EEPROM storage. + - Arduino Mega: 4 kB EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + address = address + 1; + if (address == EEPROM.length()) { + address = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++address &= EEPROM.length() - 1; + ***/ + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino new file mode 100644 index 00000000..f5b0c0c7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino @@ -0,0 +1,71 @@ +/*** + EEPROM Update method + + Stores values read from analog input 0 into the EEPROM. + These values will stay in the EEPROM when the board is + turned off and may be retrieved later by another sketch. + + If a value has not changed in the EEPROM, it is not overwritten + which would reduce the life span of the EEPROM unnecessarily. + + Released using MIT licence. + ***/ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int address = 0; + +void setup() { + /** Empty setup **/ +} + +void loop() { + /*** + need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + int val = analogRead(0) / 4; + + /*** + Update the particular EEPROM cell. + these values will remain there when the board is + turned off. + ***/ + EEPROM.update(address, val); + + /*** + The function EEPROM.update(address, val) is equivalent to the following: + + if( EEPROM.read(address) != val ){ + EEPROM.write(address, val); + } + ***/ + + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduino Duemilanove: 512 B EEPROM storage. + - Arduino Uno: 1 kB EEPROM storage. + - Arduino Mega: 4 kB EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + address = address + 1; + if (address == EEPROM.length()) { + address = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++address &= EEPROM.length() - 1; + ***/ + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino new file mode 100644 index 00000000..64e835cd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino @@ -0,0 +1,60 @@ +/* + * EEPROM Write + * + * Stores values read from analog input 0 into the EEPROM. + * These values will stay in the EEPROM when the board is + * turned off and may be retrieved later by another sketch. + */ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int addr = 0; + +void setup() { + /** Empty setup. **/ +} + +void loop() { + /*** + Need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + + int val = analogRead(0) / 4; + + /*** + Write the value to the appropriate byte of the EEPROM. + these values will remain there when the board is + turned off. + ***/ + + EEPROM.write(addr, val); + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduino Duemilanove: 512 B EEPROM storage. + - Arduino Uno: 1 kB EEPROM storage. + - Arduino Mega: 4 kB EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + addr = addr + 1; + if (addr == EEPROM.length()) { + addr = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++addr &= EEPROM.length() - 1; + ***/ + + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino new file mode 100644 index 00000000..935440cf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -0,0 +1,142 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + */ + +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initialize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 00000000..f0153650 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -0,0 +1,72 @@ +/* + Digital Pot Control + + This example controls an Analog Devices AD5206 digital potentiometer. + The AD5206 has 6 potentiometer channels. Each channel's pins are labeled + A - connect this to voltage + W - this is the pot's wiper, which changes when you set it + B - connect this to ground. + + The AD5206 is SPI-compatible,and to command it, you send two bytes, + one with the channel number (0 - 5) and one with the resistance value for the + channel (0 - 255). + + The circuit: + * All A pins of AD5206 connected to +5V + * All B pins of AD5206 connected to ground + * An LED and a 220-ohm resistor in series connected from each W pin to ground + * CS - to digital pin 10 (SS pin) + * SDI - to digital pin 11 (MOSI pin) + * CLK - to digital pin 13 (SCK pin) + + created 10 Aug 2010 + by Tom Igoe + + Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 + +*/ + + +// include the SPI library: +#include + + +// set pin 10 as the slave select for the digital pot: +const int slaveSelectPin = 10; + +void setup() { + // set the slaveSelectPin as an output: + pinMode(slaveSelectPin, OUTPUT); + // initialize SPI: + SPI.begin(); +} + +void loop() { + // go through the six channels of the digital pot: + for (int channel = 0; channel < 6; channel++) { + // change the resistance on this channel from min to max: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, level); + delay(10); + } + // wait a second at the top: + delay(100); + // change the resistance on this channel from max to min: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, 255 - level); + delay(10); + } + } +} + +void digitalPotWrite(int address, int value) { + // take the SS pin low to select the chip: + digitalWrite(slaveSelectPin, LOW); + delay(100); + // send in the address and value via SPI: + SPI.transfer(address); + SPI.transfer(value); + delay(100); + // take the SS pin high to de-select the chip: + digitalWrite(slaveSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino new file mode 100644 index 00000000..7a484f4a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -0,0 +1,54 @@ +/* + Software serial multiple serial test + + Receives from the hardware serial, sends to software serial. + Receives from software serial, sends to hardware serial. + + The circuit: + * RX is digital pin 10 (connect to TX of other device) + * TX is digital pin 11 (connect to RX of other device) + + Note: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: + 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + + Not all pins on the Leonardo and Micro support change interrupts, + so only the following can be used for RX: + 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). + + created back in the mists of time + modified 25 May 2012 + by Tom Igoe + based on Mikal Hart's example + + This example code is in the public domain. + + */ +#include + +SoftwareSerial mySerial(10, 11); // RX, TX + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(57600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + Serial.println("Goodnight moon!"); + + // set the data rate for the SoftwareSerial port + mySerial.begin(4800); + mySerial.println("Hello, world?"); +} + +void loop() { // run over and over + if (mySerial.available()) { + Serial.write(mySerial.read()); + } + if (Serial.available()) { + mySerial.write(Serial.read()); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino new file mode 100644 index 00000000..94b0a210 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -0,0 +1,85 @@ +/* + Software serial multiple serial test + + Receives from the two software serial ports, + sends to the hardware serial port. + + In order to listen on a software port, you call port.listen(). + When using two software serial ports, you have to switch ports + by listen()ing on each one in turn. Pick a logical time to switch + ports, like the end of an expected transmission, or when the + buffer is empty. This example switches ports when there is nothing + more to read from a port + + The circuit: + Two devices which communicate serially are needed. + * First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX) + * Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX) + + Note: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: + 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + + Not all pins on the Leonardo support change interrupts, + so only the following can be used for RX: + 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). + + created 18 Apr. 2011 + modified 19 March 2016 + by Tom Igoe + based on Mikal Hart's twoPortRXExample + + This example code is in the public domain. + + */ + +#include +// software serial #1: RX = digital pin 10, TX = digital pin 11 +SoftwareSerial portOne(10, 11); + +// software serial #2: RX = digital pin 8, TX = digital pin 9 +// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega +SoftwareSerial portTwo(8, 9); + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + // Start each software serial port + portOne.begin(9600); + portTwo.begin(9600); +} + +void loop() { + // By default, the last initialized port is listening. + // when you want to listen on a port, explicitly select it: + portOne.listen(); + Serial.println("Data from port one:"); + // while there is data coming in, read it + // and send to the hardware serial port: + while (portOne.available() > 0) { + char inByte = portOne.read(); + Serial.write(inByte); + } + + // blank line to separate data from the two ports: + Serial.println(); + + // Now listen on the second port + portTwo.listen(); + // while there is data coming in, read it + // and send to the hardware serial port: + Serial.println("Data from port two:"); + while (portTwo.available() > 0) { + char inByte = portTwo.read(); + Serial.write(inByte); + } + + // blank line to separate data from the two ports: + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino new file mode 100644 index 00000000..dca8cc35 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -0,0 +1,84 @@ +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// by Nicholas Zambetti +// and James Tichenor + +// Demonstrates use of the Wire library reading data from the +// Devantech Ultrasonic Rangers SFR08 and SFR10 + +// Created 29 April 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join I2C bus (address optional for master) + Serial.begin(9600); // start serial communication at 9600 bps +} + +int reading = 0; + +void loop() { + // step 1: instruct sensor to read echoes + Wire.beginTransmission(112); // transmit to device #112 (0x70) + // the address specified in the datasheet is 224 (0xE0) + // but I2C addressing uses the high 7 bits so it's 112 + Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) + Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds + Wire.endTransmission(); // stop transmitting + + // step 2: wait for readings to happen + delay(70); // datasheet suggests at least 65 milliseconds + + // step 3: instruct sensor to return a particular echo reading + Wire.beginTransmission(112); // transmit to device #112 + Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + + // step 4: request reading from sensor + Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 + + // step 5: receive reading from sensor + if (2 <= Wire.available()) { // if two bytes were received + reading = Wire.read(); // receive high byte (overwrites previous reading) + reading = reading << 8; // shift high byte to be high 8 bits + reading |= Wire.read(); // receive low byte as lower 8 bits + Serial.println(reading); // print the reading + } + + delay(250); // wait a bit since people have to read the output :) +} + + +/* + +// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) +// usage: changeAddress(0x70, 0xE6); + +void changeAddress(byte oldAddress, byte newAddress) +{ + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA0)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xAA)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA5)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(newAddress); + Wire.endTransmission(); +} + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino new file mode 100644 index 00000000..5e64b751 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -0,0 +1,33 @@ +// I2C Digital Potentiometer +// by Nicholas Zambetti +// and Shawn Bonkowski + +// Demonstrates use of the Wire library +// Controls AD5171 digital potentiometer via I2C/TWI + +// Created 31 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join I2C bus (address optional for master) +} + +byte val = 0; + +void loop() { + Wire.beginTransmission(44); // transmit to device #44 (0x2c) + // device address is specified in datasheet + Wire.write(byte(0x00)); // sends instruction byte + Wire.write(val); // sends potentiometer value byte + Wire.endTransmission(); // stop transmitting + + val++; // increment value + if (val == 64) { // if reached 64th position (max) + val = 0; // start over from lowest value + } + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino new file mode 100644 index 00000000..b0061452 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino @@ -0,0 +1,76 @@ +// -------------------------------------- +// i2c_scanner +// +// Version 1 +// This program (or code that looks like it) +// can be found in many places. +// For example on the Arduino.cc forum. +// The original author is not known. +// Version 2, Juni 2012, Using Arduino 1.0.1 +// Adapted to be as simple as possible by Arduino.cc user Krodal +// Version 3, Feb 26 2013 +// V3 by louarnold +// Version 4, March 3, 2013, Using Arduino 1.0.3 +// by Arduino.cc user Krodal. +// Changes by louarnold removed. +// Scanning addresses changed from 0...127 to 1...119, +// according to the i2c scanner by Nick Gammon +// https://www.gammon.com.au/forum/?id=10896 +// Version 5, March 28, 2013 +// As version 4, but address scans now to 127. +// A sensor seems to use address 120. +// Version 6, November 27, 2015. +// Added waiting for the Leonardo serial communication. +// +// +// This sketch tests the standard 7-bit addresses +// Devices with higher bit address might not be seen properly. +// + +#include + +void setup() { + Wire.begin(); + + Serial.begin(9600); + while (!Serial) + ; // Leonardo: wait for Serial Monitor + Serial.println("\nI2C Scanner"); +} + +void loop() { + int nDevices = 0; + + Serial.println("Scanning..."); + + for (byte address = 1; address < 127; ++address) { + // The i2c_scanner uses the return value of + // the Wire.endTransmission to see if + // a device did acknowledge to the address. + Wire.beginTransmission(address); + byte error = Wire.endTransmission(); + + if (error == 0) { + Serial.print("I2C device found at address 0x"); + if (address < 16) { + Serial.print("0"); + } + Serial.print(address, HEX); + Serial.println(" !"); + + ++nDevices; + } else if (error == 4) { + Serial.print("Unknown error at address 0x"); + if (address < 16) { + Serial.print("0"); + } + Serial.println(address, HEX); + } + } + if (nDevices == 0) { + Serial.println("No I2C devices found\n"); + } else { + Serial.println("done\n"); + } + delay(5000); // Wait 5 seconds for next scan +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_reader/master_reader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_reader/master_reader.ino new file mode 100644 index 00000000..2408ac51 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_reader/master_reader.ino @@ -0,0 +1,29 @@ +// Wire Master Reader +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Reads data from an I2C/TWI slave device +// Refer to the "Wire Slave Sender" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join I2C bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() { + Wire.requestFrom(8, 6); // request 6 bytes from slave device #8 + + while (Wire.available()) { // slave may send less than requested + char c = Wire.read(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_writer/master_writer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_writer/master_writer.ino new file mode 100644 index 00000000..6f2a8c72 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_writer/master_writer.ino @@ -0,0 +1,29 @@ +// Wire Master Writer +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Writes data to an I2C/TWI slave device +// Refer to the "Wire Slave Receiver" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join I2C bus (address optional for master) +} + +byte x = 0; + +void loop() { + Wire.beginTransmission(8); // transmit to device #8 + Wire.write("x is "); // sends five bytes + Wire.write(x); // sends one byte + Wire.endTransmission(); // stop transmitting + + x++; + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino new file mode 100644 index 00000000..113aa471 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -0,0 +1,34 @@ +// Wire Slave Receiver +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI slave device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(8); // join I2C bus with address #8 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() { + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) { + while (1 < Wire.available()) { // loop through all but the last + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_sender/slave_sender.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_sender/slave_sender.ino new file mode 100644 index 00000000..ed83c0a7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -0,0 +1,29 @@ +// Wire Slave Sender +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Sends data as an I2C/TWI slave device +// Refer to the "Wire Master Reader" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(8); // join I2C bus with address #8 + Wire.onRequest(requestEvent); // register event +} + +void loop() { + delay(100); +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() { + Wire.write("hello "); // respond with message of 6 bytes + // as expected by master +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/README.md new file mode 100644 index 00000000..381bad63 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/README.md @@ -0,0 +1,116 @@ +# Arduino Core for mbed enabled devices + +The repository contains the Arduino APIs and IDE integration files targeting a generic mbed-enabled board + +## FAQ +### Source-Code Level Debugging +**Question**: "I want to debug my ArduinoCore-mbed based sketch using traditional debugging tools, i.e. gdb via SWD interface. However, the debugger is unable to locate the sources for all files, particular the mbed-os files." + +**Answer**: This is due to the fact that we pre-compile the mbed-os code into a static library `libmbed.a`. Information on how to recompile `libmbed.a` for source code debugging can be found [here](#recompiling-libmbed-with-source-level-debug-support). The [Arduino Documentation](https://docs.arduino.cc/) also contains articles explaining how to debug via [Segger J-Link](https://docs.arduino.cc/tutorials/portenta-breakout/breakout-jlink-setup) and [Lauterbach TRACE32](https://docs.arduino.cc/tutorials/portenta-h7/lauterbach-debugger). + +## Installation + +### Clone the repository in `$sketchbook/hardware/arduino-git` + +```bash +mkdir -p $sketchbook/hardware/arduino-git +cd $sketchbook/hardware/arduino-git +git clone git@github.com:arduino/ArduinoCore-mbed mbed +``` + +### Clone https://github.com/arduino/ArduinoCore-API into a directory of your choice. + +```bash +git clone git@github.com:arduino/ArduinoCore-API +``` + +### Update the `api` symlink + +Create a symlink to `ArduinoCore-API/api` in `$sketchbook/hardware/arduino-git/mbed/cores/arduino`. + +### Test things out + +Open the Arduino IDE. + +You should now see three new targets under the `MBED boards` label. + +*This procedure does not automatically install the required ARM compiler toolchain.* + +If the toolchain is missing, you'll see errors like this when you try to build for an mbed-os enabled board.: + +``` +fork/exec /bin/arm-none-eabi-g++: no such file or directory +``` +To install ARM build tools, use the `Boards Manager` option in the Arduino IDE to add the `Arduino mbed-enabled Boards` package. + +## mbed-os-to-arduino script + +The backbone of the packaging process is the https://github.com/arduino/ArduinoCore-mbed/blob/master/mbed-os-to-arduino script. It basically compiles a blank Mbed OS project for any supported target board, recovering the files that will be needed at compile time and copying them to the right location. + +It can be used for a variety of tasks including: + +### Recompiling libmbed with source level debug support + +``` +cd $sketchbook/hardware/arduino-git/mbed +./mbed-os-to-arduino -a -g PORTENTA_H7_M7:PORTENTA_H7_M7 +``` + +In this case `-a` applies all the patches from `patches` folder into a mainline `mbed-os` tree, and `-g` restores the debug info. + +### Selecting a different optimization profile + +``` +cd $sketchbook/hardware/arduino-git/mbed +PROFILE=release ./mbed-os-to-arduino -a NANO_RP2040_CONNECT:NANO_RP2040_CONNECT +``` + +The `PROFILE` environment variable tunes the compilation profiles (defaults to `DEVELOP`). Other available profiles are `DEBUG` and `RELEASE`. + +### Selecting a different Mbed OS tree + +``` +cd $sketchbook/hardware/arduino-git/mbed +./mbed-os-to-arduino -r /path/to/my/mbed-os-fork NICLA_VISION:NICLA_VISION +``` + +`-r` flag allows using a custom `mbed-os` fork in place of the mainline one; useful during new target development. + +### Adding a new target ([core variant](https://arduino.github.io/arduino-cli/latest/platform-specification/#core-variants)) + +Adding a target is a mostly automatic procedure. + +For boards already supported by Mbed OS, the bare minimum is: + +``` +cd $sketchbook/hardware/arduino-git/mbed +mkdir -p variants/$ALREADY_SUPPORTED_BOARD_NAME/{libs,conf} +./mbed-os-to-arduino $ALREADY_SUPPORTED_BOARD_NAME:$ALREADY_SUPPORTED_BOARD_NAME +# for example, to create a core for LPC546XX +# mkdir -p variants/LPC546XX/{libs,conf} +# ./mbed-os-to-arduino LPC546XX:LPC546XX +``` + +This will produce almost all the files needed. To complete the port, add the board specifications to [`boards.txt`](https://arduino.github.io/arduino-cli/latest/platform-specification/#boardstxt) (giving it a unique ID) and provide `pins_arduino.h` and `variants.cpp` in `variants/$ALREADY_SUPPORTED_BOARD_NAME` folder. +Feel free to take inspirations from the existing variants :) + +For boards not supported by mainline Mbed OS, the same applies but you should provide the path of your Mbed OS fork + +``` +cd $sketchbook/hardware/arduino-git/mbed +mkdir -p variants/$BRAND_NEW_BOARD_NAME/{libs,conf} +./mbed-os-to-arduino -r /path/to/mbed-os/fork/that/supports/new/board $BRAND_NEW_BOARD_NAME:$BRAND_NEW_BOARD_NAME +``` + +### Customizing Mbed OS build without modifying the code + +Most Mbed OS defines can be tuned using a project file called `mbed_app.json` . In case you need to tune a build you can add that file to your variant's `conf` folder. One example is https://github.com/arduino/ArduinoCore-mbed/blob/master/variants/PORTENTA_H7_M7/conf/mbed_app.json . +Providing an invalid json or replacing a non-existing property will make the build fail silently, so it's always better to validate that file with a standard Mbed OS project. + + +## Using this core as an mbed library + +You can use this core as a standard mbed library; all APIs are under `arduino` namespace (so they must be called like `arduino::digitalWrite()` ) + +The opposite is working as well; from any sketch you can call mbed APIs by prepending `mbed::` namespace. + diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino new file mode 100644 index 00000000..56d1814f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino @@ -0,0 +1,65 @@ +#include "camera.h" + +#ifdef ARDUINO_NICLA_VISION +#include "gc2145.h" +GC2145 galaxyCore; +Camera cam(galaxyCore); +#define IMAGE_MODE CAMERA_RGB565 +#else +#include "himax.h" +HM01B0 himax; +Camera cam(himax); +#define IMAGE_MODE CAMERA_GRAYSCALE +#endif + +/* +Other buffer instantiation options: + FrameBuffer fb(0x30000000); + FrameBuffer fb(320,240,2); +*/ +FrameBuffer fb; + +unsigned long lastUpdate = 0; + + +void blinkLED(uint32_t count = 0xFFFFFFFF) { + pinMode(LED_BUILTIN, OUTPUT); + while (count--) { + digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level) + delay(50); // wait for a second + digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW + delay(50); // wait for a second + } +} + +void setup() { + // Init the cam QVGA, 30FPS + if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) { + blinkLED(); + } + + blinkLED(5); +} + +void loop() { + if (!Serial) { + Serial.begin(921600); + while (!Serial) + ; + } + + // Time out after 2 seconds and send new data + bool timeoutDetected = millis() - lastUpdate > 2000; + + // Wait for sync byte. + if (!timeoutDetected && Serial.read() != 1) return; + + lastUpdate = millis(); + + // Grab frame and write to serial + if (cam.grabFrame(fb, 3000) == 0) { + Serial.write(fb.getBuffer(), cam.frameSize()); + } else { + blinkLED(20); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraMotionDetect/CameraMotionDetect.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraMotionDetect/CameraMotionDetect.ino new file mode 100644 index 00000000..84605d4b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraMotionDetect/CameraMotionDetect.ino @@ -0,0 +1,61 @@ +#include "camera.h" +#include "himax.h" +HM01B0 himax; +Camera cam(himax); + +#ifdef ARDUINO_NICLA_VISION +#error "GalaxyCore camera module does not support Motion Detection" +#endif + +bool motion_detected = false; + +void blinkLED(uint32_t count = 0xFFFFFFFF) { + pinMode(LED_BUILTIN, OUTPUT); + while (count--) { + digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level) + delay(50); // wait for a second + digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW + delay(50); // wait for a second + } +} + +void on_motion() { + motion_detected = true; +} + +void setup() { + Serial.begin(115200); + + pinMode(LEDB, OUTPUT); + digitalWrite(LEDB, HIGH); + + // Init the cam QVGA, 30FPS + if (!cam.begin(CAMERA_R320x240, CAMERA_GRAYSCALE, 30)) { + blinkLED(); + } + + // Set motion detection threshold (0 -> 255). + // The lower the threshold the higher the sensitivity. + cam.setMotionDetectionThreshold(0); + + // Set motion detection window/ROI. + cam.setMotionDetectionWindow(0, 0, 320, 240); + + // The detection can also be enabled without any callback + cam.enableMotionDetection(on_motion); +} + +void loop() { + + if (motion_detected) { + Serial.println("Motion Detected!"); + digitalWrite(LEDB, LOW); + delay(500); + + // Clear the detection flag + cam.motionDetected(); + motion_detected = false; + digitalWrite(LEDB, HIGH); + } + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/README.adoc new file mode 100644 index 00000000..1301ec2e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/README.adoc @@ -0,0 +1,24 @@ += Ethernet Library for Arduino = + +Enable Ethernet connectivity for Arduino Portenta and a shield/carrier with Ethernet connector. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/Ethernet + +== License == + +Copyright (c) 2020 Arduino SA. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino new file mode 100644 index 00000000..ebe13f86 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino @@ -0,0 +1,109 @@ +/* + Advanced Chat Server + + A more advanced server that distributes any incoming messages + to all connected clients but the client the message comes from. + To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + redesigned to make use of operator== 25 Nov 2013 + by Norbert Truchsess + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 255, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); + +EthernetClient clients[8]; + +void setup() { + + // initialize the Ethernet device + Ethernet.begin(ip, myDns, gateway, subnet); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // check for any new client connecting, and say hello (before any incoming data) + EthernetClient newClient = server.available(); + if (newClient) { + for (byte i = 0; i < 8; i++) { + if (!clients[i]) { + Serial.print("We have a new client #"); + Serial.println(i); + newClient.print("Hello, client number: "); + newClient.println(i); + // Once we "accept", the client is no longer tracked by EthernetServer + // so we must store it into our list of clients + clients[i] = newClient; + break; + } + } + } + + // check for incoming data from all clients + for (byte i = 0; i < 8; i++) { + if (clients[i] && clients[i].available() > 0) { + // read bytes from a client + byte buffer[80]; + int count = clients[i].read(buffer, 80); + // write the bytes to all other connected clients + for (byte j = 0; j < 8; j++) { + if (j != i && clients[j].connected()) { + clients[j].write(buffer, count); + } + } + } + } + + // stop any clients which disconnect + for (byte i = 0; i < 8; i++) { + if (clients[i] && !clients[i].connected()) { + Serial.print("disconnect client #"); + Serial.println(i); + clients[i].stop(); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino new file mode 100644 index 00000000..075eed04 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino @@ -0,0 +1,235 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Serves the output of a Barometric Pressure Sensor as a web page. + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + TODO: this hardware is long obsolete. This example program should + be rewritten to use https://www.sparkfun.com/products/9721 + + Circuit: + SCP1000 sensor attached to pins 6,7, and 11 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + by Tom Igoe + */ + +#include +#include +// the sensor communicates using SPI, so include the library: +#include + + +// assign an IP address for the controller: +IPAddress ip(192, 168, 1, 20); + + +// Initialize the Ethernet server library +// with the IP address and port you want to use +// (port 80 is default for HTTP): +EthernetServer server(80); + + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading + +// pins used for the connection with the sensor +// the others you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +float temperature = 0.0; +long pressure = 0; +long lastReadingTime = 0; + +void setup() { + + // start the SPI library: + SPI.begin(); + + // start the Ethernet connection + Ethernet.begin(ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + // initalize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + + // give the sensor and Ethernet shield time to set up: + delay(1000); + + //Set the sensor to high resolution mode tp start readings: + writeRegister(0x03, 0x0A); +} + +void loop() { + // check for a reading no more than once a second. + if (millis() - lastReadingTime > 1000) { + // if there's a reading ready, read it: + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + getData(); + // timestamp the last time you got a reading: + lastReadingTime = millis(); + } + } + + // listen for incoming Ethernet connections: + listenForEthernetClients(); +} + + +void getData() { + Serial.println("Getting reading"); + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + temperature = (float)tempData / 20.0; + + //Read the pressure data highest 3 bits: + byte pressureDataHigh = readRegister(0x1F, 1); + pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressureDataLow = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4; + + Serial.print("Temperature: "); + Serial.print(temperature); + Serial.println(" degrees C"); + Serial.print("Pressure: " + String(pressure)); + Serial.println(" Pa"); +} + +void listenForEthernetClients() { + // listen for incoming clients + EthernetClient client = server.available(); + if (client) { + Serial.println("Got a client"); + // an http request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the http request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println(); + // print the current readings, in HTML format: + client.print("Temperature: "); + client.print(temperature); + client.print(" degrees C"); + client.println("
"); + client.print("Pressure: " + String(pressure)); + client.print(" Pa"); + client.println("
"); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + } +} + + +//Send a write command to SCP1000 +void writeRegister(byte registerName, byte registerValue) { + // SCP1000 expects the register name in the upper 6 bits + // of the byte: + registerName <<= 2; + // command (read or write) goes in the lower two bits: + registerName |= 0b00000010; //Write command + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(registerName); //Send register location + SPI.transfer(registerValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} + + +//Read register from the SCP1000: +unsigned int readRegister(byte registerName, int numBytes) { + byte inByte = 0; // incoming from the SPI read + unsigned int result = 0; // result to return + + // SCP1000 expects the register name in the upper 6 bits + // of the byte: + registerName <<= 2; + // command (read or write) goes in the lower two bits: + registerName &= 0b11111100; //Read command + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + int command = SPI.transfer(registerName); + // send a value of 0 to read the first byte returned: + inByte = SPI.transfer(0x00); + + result = inByte; + // if there's more than one byte returned, + // shift the first byte then get the second byte: + if (numBytes > 1) { + result = inByte << 8; + inByte = SPI.transfer(0x00); + result = result | inByte; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/ChatServer/ChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/ChatServer/ChatServer.ino new file mode 100644 index 00000000..ad6805aa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -0,0 +1,94 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); +boolean alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet + + // initialize the ethernet device + Ethernet.begin(ip, myDns, gateway, subnet); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clear out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino new file mode 100644 index 00000000..b64cc786 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino @@ -0,0 +1,79 @@ +/* + DHCP-based IP printer + + This sketch uses the DHCP extensions to the Ethernet library + to get an IP address via DHCP and print the address obtained. + using an Arduino Wiznet Ethernet shield. + + Circuit: + Ethernet shield attached to pins 10, 11, 12, 13 + + created 12 April 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include +#include + +void setup() { + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // no point in carrying on, so do nothing forevermore: + while (true) { + delay(1); + } + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); +} + +void loop() { + if (Ethernet.status() != 0) { + Serial.println(Ethernet.status()); + connectEth(); + } +} + +void connectEth() { + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + + Serial.println("You're connected to the network"); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino new file mode 100644 index 00000000..2b8b7618 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -0,0 +1,90 @@ +/* + DHCP Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino Wiznet Ethernet shield. + + THis version attempts to get an IP address using DHCP + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 21 May 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + Based on ChatServer example by David A. Mellis + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + +// telnet defaults to port 23 +EthernetServer server(23); +boolean gotAMessage = false; // whether or not you got a message from the client yet + +void setup() { + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Trying to get an IP address using DHCP"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // initialize the Ethernet device not using DHCP: + Ethernet.begin(ip, myDns, gateway, subnet); + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + + // start listening for clients + server.begin(); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!gotAMessage) { + Serial.println("We have a new client"); + client.println("Hello, client!"); + gotAMessage = true; + } + + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.print(thisChar); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/LinkStatus/LinkStatus.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/LinkStatus/LinkStatus.ino new file mode 100644 index 00000000..b0397b7d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/LinkStatus/LinkStatus.ino @@ -0,0 +1,36 @@ +/* + Link Status + This sketch prints the ethernet link status. When the + ethernet cable is connected the link status should go to "ON". + NOTE: Only WizNet W5200 and W5500 are capable of reporting + the link status. W5100 will report "Unknown". + Hardware: + - Ethernet shield or equivalent board/shield with WizNet 5200/5500 + Written by Cristian Maglie + This example is public domain. +*/ + +#include +#include +#include + +void setup() { + Serial.begin(9600); +} + +void loop() { + auto link = Ethernet.linkStatus(); + Serial.print("Link status: "); + switch (link) { + case Unknown: + Serial.println("Unknown"); + break; + case LinkON: + Serial.println("ON"); + break; + case LinkOFF: + Serial.println("OFF"); + break; + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino new file mode 100644 index 00000000..7bdd27ae --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -0,0 +1,99 @@ +/* + Telnet client + + This sketch connects to a a telnet server (http://www.google.com) + using an Arduino Wiznet Ethernet shield. You'll need a telnet server + to test this with. + Processing's ChatServer example (part of the network library) works well, + running on port 10002. It can be found as part of the examples + in the Processing application, available at + http://processing.org/ + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 14 Sep 2010 + modified 9 Apr 2012 + by Tom Igoe + */ + +#include +#include +#include + +// The IP address will be dependent on your local network: +IPAddress ip(192, 168, 1, 177); + +// Enter the IP address of the server you're connecting to: +IPAddress server(1, 1, 1, 1); + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 23 is default for telnet; +// if you're using Processing's ChatServer, use port 10002): +EthernetClient client; + +void setup() { + + // start the Ethernet connection: + Ethernet.begin(ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + while (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + delay(500); + } + + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, 10002)) { + Serial.println("connected"); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // as long as there are bytes in the serial queue, + // read them and send them out the socket if it's open: + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (client.connected()) { + client.print(inChar); + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + // do nothing: + while (true) { + delay(1); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino new file mode 100644 index 00000000..cb876693 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino @@ -0,0 +1,126 @@ +/* + UDPSendReceiveString: + This sketch receives UDP message strings, prints them to the serial port + and sends an "acknowledge" string back to the sender + + A Processing sketch is included at the end of file that can be used to send + and received messages for testing with a computer. + + created 21 Aug 2010 + by Michael Margolis + + This code is in the public domain. + */ + +#include +#include +#include + +// The IP address will be dependent on your local network: +IPAddress ip(192, 168, 1, 177); + +unsigned int localPort = 8888; // local port to listen on + +// buffers for receiving and sending data +char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet, +char ReplyBuffer[] = "acknowledged"; // a string to send back + +// An EthernetUDP instance to let us send and receive packets over UDP +EthernetUDP Udp; + +void setup() { + + // start the Ethernet + Ethernet.begin(ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start UDP + Udp.begin(localPort); +} + +void loop() { + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remote = Udp.remoteIP(); + for (int i = 0; i < 4; i++) { + Serial.print(remote[i], DEC); + if (i < 3) { + Serial.print("."); + } + } + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBufffer + Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } + delay(10); +} + + +/* + Processing sketch to run with this example + ===================================================== + + // Processing UDP example to send and receive string data from Arduino + // press any key to send the "Hello Arduino" message + + + import hypermedia.net.*; + + UDP udp; // define the UDP object + + + void setup() { + udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000 + //udp.log( true ); // <-- printout the connection activity + udp.listen( true ); // and wait for incoming message + } + + void draw() + { + } + + void keyPressed() { + String ip = "192.168.1.177"; // the remote IP address + int port = 8888; // the destination port + + udp.send("Hello World", ip, port ); // the message to send + + } + + void receive( byte[] data ) { // <-- default handler + //void receive( byte[] data, String ip, int port ) { // <-- extended handler + + for(int i=0; i < data.length; i++) + print(char(data[i])); + println(); + } + */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino new file mode 100644 index 00000000..505ba625 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -0,0 +1,161 @@ +/* + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + This code is in the public domain. + + */ + +#include +#include +#include +#include + +unsigned int localPort = 8888; // local port to listen for UDP packets + +const char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +EthernetUDP Udp; + +void setup() { + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start Ethernet and UDP + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // no point in carrying on, so do nothing forevermore: + while (true) { + delay(1); + } + } + Udp.begin(localPort); +} + +void loop() { + if (Ethernet.status() != 0) { + Serial.println(Ethernet.status()); + connectEth(); + } + sendNTPpacket(timeServer); // send an NTP packet to a time server + + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + // the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +void sendNTPpacket(const char* address) { + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); // NTP requests are to port 123 + Udp.write(packetBuffer, NTP_PACKET_SIZE); + Udp.endPacket(); +} + +void connectEth() { + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(nullptr) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + + Serial.println("You're connected to the network"); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClient/WebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClient/WebClient.ino new file mode 100644 index 00000000..c996224f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClient/WebClient.ino @@ -0,0 +1,131 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe, based on work by Adrian McEwen + + */ + +#include +#include +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +// byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 2, 177); +IPAddress myDns(192, 168, 2, 1); + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +EthernetClient client; + +// Variables to measure the speed +unsigned long beginMicros, endMicros; +unsigned long byteCount = 0; +bool printWebData = true; // set to false for better speed measurement + +void setup() { + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to congifure using IP address instead of DHCP: + Ethernet.begin(ip, myDns); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.print("connecting to "); + Serial.print(server); + Serial.println("..."); + + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.print("connected to "); + Serial.println(client.remoteIP()); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } + beginMicros = micros(); +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + int len = client.available(); + if (len > 0) { + byte buffer[80]; + if (len > 80) + len = 80; + client.read(buffer, len); + if (printWebData) { + Serial.write(buffer, len); // show in the serial monitor (slows some boards) + } + byteCount = byteCount + len; + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + endMicros = micros(); + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + Serial.print("Received "); + Serial.print(byteCount); + Serial.print(" bytes in "); + float seconds = (float)(endMicros - beginMicros) / 1000000.0; + Serial.print(seconds, 4); + float rate = (float)byteCount / seconds / 1000.0; + Serial.print(", rate = "); + Serial.print(rate); + Serial.print(" kbytes/second"); + Serial.println(); + + // do nothing forevermore: + while (true) { + delay(1); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino new file mode 100644 index 00000000..b70547e6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino @@ -0,0 +1,115 @@ +/* + Repeating Web client + + This sketch connects to a a web server and makes a request + using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or + the Adafruit Ethernet shield, either one will work, as long as it's got + a Wiznet Ethernet module on board. + + This example uses DNS, by assigning the Ethernet client with a MAC address, + IP address, and DNS address. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 19 Apr 2012 + by Tom Igoe + modified 21 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WebClientRepeating + This code is in the public domain. + + */ + +#include +#include +#include + +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 0, 177); +IPAddress myDns(192, 168, 0, 1); + +// initialize the library instance: +EthernetClient client; + +char server[] = "www.arduino.cc"; // also change the Host line in httpRequest() +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds + +void setup() { + + + // start serial port: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to congifure using IP address instead of DHCP: + Ethernet.begin(ip, myDns); + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + if (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the WiFi shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET /latest.txt HTTP/1.1"); + client.println("Host: www.arduino.cc"); + client.println("User-Agent: arduino-ethernet"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingManual/WebClientRepeatingManual.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingManual/WebClientRepeatingManual.ino new file mode 100644 index 00000000..e88cf7a5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingManual/WebClientRepeatingManual.ino @@ -0,0 +1,143 @@ +/* + Repeating Web client + + This sketch connects to a a web server and makes a request + using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or + the Adafruit Ethernet shield, either one will work, as long as it's got + a Wiznet Ethernet module on board. + + This example uses DNS, by assigning the Ethernet client with a MAC address, + IP address, and DNS address. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 19 Apr 2012 + by Tom Igoe + modified 21 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WebClientRepeating + This code is in the public domain. + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network. +// DNS, gateway and subnet are optional: +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + +// initialize the library instance: +EthernetClient client; + +char server[] = "www.arduino.cc"; // also change the Host line in httpRequest() +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds + +void setup() { + // start serial port: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + delay(2500); + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with Static IP Address:"); + if (Ethernet.begin(ip, myDns, gateway, subnet) == 0) { + Serial.println("Failed to configure Ethernet with Static IP Address"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + } + + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to congifure using IP address instead of DHCP: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + Serial.print("My Gateway IP address: "); + Serial.println(Ethernet.gatewayIP()); + Serial.print("My DNS Server IP address: "); + Serial.println(Ethernet.dnsServerIP()); + // give the Ethernet shield a second to initialize: + delay(2500); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + if (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the WiFi shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET /latest.txt HTTP/1.1"); + client.println("Host: www.arduino.cc"); + client.println("User-Agent: arduino-ethernet"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + +void connectEth() { + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(nullptr) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + + Serial.println("You're connected to the network"); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingSSL/WebClientRepeatingSSL.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingSSL/WebClientRepeatingSSL.ino new file mode 100644 index 00000000..6959e6e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingSSL/WebClientRepeatingSSL.ino @@ -0,0 +1,97 @@ +/* + Repeating TLS/SSL Ethernet Web client. + + Remeber to update the CA certificates using WiFiFirmwareUpdater sketch + before using this sketch. + + */ + +#include +#include +#include + +// initialize the library instance: +EthernetSSLClient client; + +char server[] = "www.arduino.cc"; +int port = 443; +// IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds + +void setup() { + + // start serial port: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to congifure using IP address instead of DHCP: + Ethernet.begin(ip, myDns); + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + if (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the WiFi shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, port)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET /latest.txt HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("User-Agent: arduino-ethernet"); + client.println("Accept: *"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebServer/WebServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebServer/WebServer.ino new file mode 100644 index 00000000..38d12be3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -0,0 +1,112 @@ +/* + Web Server + + A simple web server that shows the value of the analog input pins. + using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + * Analog inputs attached to pins A0 through A5 (optional) + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network: +IPAddress ip(192, 168, 1, 177); + +// Initialize the Ethernet server library +// with the IP address and port you want to use +// (port 80 is default for HTTP): +EthernetServer server(80); + +void setup() { + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.println("Ethernet WebServer Example"); + + // start the Ethernet connection and the server: + Ethernet.begin(ip); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start the server + server.begin(); + Serial.print("server is at "); + Serial.println(Ethernet.localIP()); +} + + +void loop() { + // listen for incoming clients + EthernetClient client = server.available(); + if (client) { + Serial.println("new client"); + // an http request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the http request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
"); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/GNSSClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/GNSSClient.ino new file mode 100644 index 00000000..9bceeca4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/GNSSClient.ino @@ -0,0 +1,37 @@ +#include +#include + +#include "arduino_secrets.h" +char pin[] = SECRET_PIN; +char apn[] = SECRET_APN; +char username[] = SECRET_USERNAME; +char pass[] = SECRET_PASSWORD; + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + Serial.println("Starting Carrier Network registration"); + if (!GSM.begin(pin, apn, username, pass, CATNB)) { + Serial.println("The board was not able to register to the network..."); + // do nothing forevermore: + while (1) + ; + } + Serial.println("\nEnable GNSS Engine..."); + // GPS.begin() start and eanble the GNSS engine + GPS.begin(); + Serial.println("\nGNSS Engine enabled..."); +} + +void loop() { + // Print out raw NMEA strings. + // For parsed output look at the MicroNMEA_integration example. + if (GPS.available()) { + Serial.print((char)GPS.read()); + delay(1); + } + // After geting valid packet GPS.end() can be used to stop and + // disable the GNSS engine + // GPS.end(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/arduino_secrets.h new file mode 100644 index 00000000..8c5842fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_USERNAME "" +#define SECRET_PASSWORD "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/GSMClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/GSMClient.ino new file mode 100644 index 00000000..11e9eb68 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/GSMClient.ino @@ -0,0 +1,61 @@ +#include + +REDIRECT_STDOUT_TO(Serial); + +#include "arduino_secrets.h" +char pin[] = SECRET_PIN; +char apn[] = SECRET_APN; +char username[] = SECRET_USERNAME; +char pass[] = SECRET_PASSWORD; + +const char server[] = "www.example.com"; +const char* ip_address; +int port = 80; + +GSMClient client; + +void setup() { + Serial.begin(115200); + while (!Serial) {} + Serial.println("Starting Carrier Network registration"); + if (!GSM.begin(pin, apn, username, pass, CATNB)) { + Serial.println("The board was not able to register to the network..."); + // do nothing forevermore: + while (1) + ; + } + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET / HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + Serial.println("unable to connect to server"); + } +} + +void loop() { + + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true) + ; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/arduino_secrets.h new file mode 100644 index 00000000..8c5842fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_USERNAME "" +#define SECRET_PASSWORD "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/MicroNMEA_integration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/MicroNMEA_integration.ino new file mode 100644 index 00000000..c817d7b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/MicroNMEA_integration.ino @@ -0,0 +1,122 @@ +#include +#include +#include + +#include "arduino_secrets.h" +constexpr auto pin{ SECRET_PIN }; +constexpr auto apn{ SECRET_APN }; +constexpr auto username{ SECRET_USERNAME }; +constexpr auto pass{ SECRET_PASSWORD }; + +char nmeaBuffer[100]; +MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); + +// Keep track of NMEA string processing +auto nmeaProcessStatus{ false }; + +// Check for valid fix every checkValidInterval ms +constexpr unsigned long checkValidInterval{ 5000 }; +unsigned long checkValidNow{}; + +void setup() { + Serial.begin(115200); + for (const auto timeout = millis() + 2500; !Serial && millis() < timeout; delay(250)) + ; + + // GSM.debug(Serial); + delay(1000); + + Serial.println("Starting Carrier Network registration"); + if (!GSM.begin(pin, apn, username, pass, CATNB)) { + Serial.println("The board was not able to register to the network..."); + // do nothing forevermore: + while (1) + ; + } + Serial.println("Enable GNSS Engine..."); + // GPS.begin() start and eanble the GNSS engine + GPS.begin(); + Serial.println("GNSS Engine enabled..."); + Serial.println("Waiting for a valid fix."); + + checkValidNow = millis(); +} + +void loop() { + while (GPS.available()) { + char c = GPS.read(); + // process is true when a valid NMEA string has been processed + nmeaProcessStatus = nmea.process(c); + } + + if (nmeaProcessStatus && millis() > checkValidNow) { + checkValidNow = millis() + checkValidInterval; + + // Output GPS information from previous second + Serial.print("Valid fix: "); + Serial.println(nmea.isValid() ? "yes" : "no"); + + if (!nmea.isValid()) + return; + + String navSystem; + switch (nmea.getNavSystem()) { + case 'N': + navSystem = "GNSS"; + break; + case 'P': + navSystem = "GPS"; + break; + case 'L': + navSystem = "GLONASS"; + break; + case 'A': + navSystem = "Galileo"; + break; + default: + break; + } + Serial.print("Nav. system: "); + Serial.println(navSystem); + + Serial.print("Num. satellites: "); + Serial.println(nmea.getNumSatellites()); + + Serial.print("HDOP: "); + Serial.println(nmea.getHDOP() / 10., 1); + + Serial.print("Date/time: "); + Serial.print(nmea.getYear()); + Serial.print('-'); + Serial.print(int(nmea.getMonth())); + Serial.print('-'); + Serial.print(int(nmea.getDay())); + Serial.print('T'); + Serial.print(int(nmea.getHour())); + Serial.print(':'); + Serial.print(int(nmea.getMinute())); + Serial.print(':'); + Serial.println(int(nmea.getSecond())); + + long latitude_mdeg = nmea.getLatitude(); + long longitude_mdeg = nmea.getLongitude(); + Serial.print("Latitude (deg): "); + Serial.println(latitude_mdeg / 1000000., 6); + + Serial.print("Longitude (deg): "); + Serial.println(longitude_mdeg / 1000000., 6); + + long alt; + Serial.print("Altitude (m): "); + if (nmea.getAltitude(alt)) + Serial.println(alt / 1000., 3); + else + Serial.println("not available"); + + Serial.print("Speed: "); + Serial.println(nmea.getSpeed() / 1000., 3); + Serial.print("Course: "); + Serial.println(nmea.getCourse() / 1000., 3); + nmea.clear(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/arduino_secrets.h new file mode 100644 index 00000000..8c5842fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_USERNAME "" +#define SECRET_PASSWORD "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/KernelDebug/examples/KernelDebug/KernelDebug.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/KernelDebug/examples/KernelDebug/KernelDebug.ino new file mode 100644 index 00000000..bb9c6b3a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/KernelDebug/examples/KernelDebug/KernelDebug.ino @@ -0,0 +1,20 @@ +/* This example demonstrates how to utilize the KernelDebug library which + allows kernel debugging of the Portenta H7 with GDB over a UART serial + connection. + + To connect to the target, launch gdb with the following parameters + + arm-none-eabi-gdb -ex "set pagination off" --baud {230400} -ex "set target-charset ASCII" -ex "target remote {debug.port}" {project_name}.elf + + The baud rate needs to match the one provided in KernelDebug constructor, while {debug.port} depends on the operating system (eg. /dev/ttyUSB0 or COM15) +*/ + +#include + +KernelDebug kernelDebug(SERIAL1_TX, SERIAL1_RX, USART1_IRQn, 230400, DEBUG_BREAK_IN_SETUP); + +void setup() { +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MCUboot/examples/confirmSketch/confirmSketch.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MCUboot/examples/confirmSketch/confirmSketch.ino new file mode 100644 index 00000000..ecb0abd4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MCUboot/examples/confirmSketch/confirmSketch.ino @@ -0,0 +1,27 @@ +/* + This example shows how to confirm an update Sketch after a swap + using MCUboot library. + + Circuit: + - Arduino Portenta H7 board + + This example code is in the public domain. +*/ + +#include + +// the setup function runs once when you press reset or power the board +void setup() { + // initialize digital pin LED_BUILTIN as an output. + pinMode(LED_BUILTIN, OUTPUT); + // set confirmed flag to avoid MCUboot reverts to previous application at next reset + MCUboot::confirmSketch(); +} + +// the loop function runs over and over again forever +void loop() { + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(100); // wait 100ms + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(100); // wait 100ms +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_DataLogger_FIFO/NiclaVision_DataLogger_FIFO.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_DataLogger_FIFO/NiclaVision_DataLogger_FIFO.ino new file mode 100644 index 00000000..7d123666 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_DataLogger_FIFO/NiclaVision_DataLogger_FIFO.ino @@ -0,0 +1,264 @@ +/* + This example exposes the second MB of Nicla Vision flash as a USB disk. + The user can interact with this disk as a bidirectional communication with the board + For example, the board could save data in a file to be retrieved later with a drag and drop. + If the user does a double tap, the firmware goes to datalogger mode (green led on). + Now the user can do another double tap to start a recording of the IMU data + (green led blinking). With another double tap the recording will be stopped (green led on). + Now the user can start/stop other recordings of the IMU data using again the double tap. + The log files are saved in flash with an increasing number suffix data_0.txt, data_1.txt, etc. + If you want to transfer the log files to the PC, you can reset the board and + wait for 10 seconds (blue led blinking). +*/ + +#include "PluggableUSBMSD.h" +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "FATFileSystem.h" +#include "LSM6DSOXSensor.h" + +#define INT_1 LSM6DS_INT +#define SENSOR_ODR 104.0f // In Hertz +#define ACC_FS 2 // In g +#define GYR_FS 2000 // In dps +#define MEASUREMENT_TIME_INTERVAL (1000.0f / SENSOR_ODR) // In ms +#define FIFO_SAMPLE_THRESHOLD 199 +#define FLASH_BUFF_LEN 8192 + +typedef enum { + DATA_STORAGE_STATE, + DATA_LOGGER_IDLE_STATE, + DATA_LOGGER_RUNNING_STATE +} demo_state_e; + +volatile demo_state_e demo_state = DATA_STORAGE_STATE; +volatile int mems_event = 0; +uint32_t file_count = 0; +unsigned long timestamp_count = 0; +bool acc_available = false; +bool gyr_available = false; +int32_t acc_value[3]; +int32_t gyr_value[3]; +char buff[FLASH_BUFF_LEN]; +uint32_t pos = 0; + +QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); +// Partition 1 is allocated to WiFi +mbed::MBRBlockDevice lsm_data(&root, 2); +static mbed::FATFileSystem lsm_fs("lsm"); + +LSM6DSOXSensor AccGyr(&SPI1, PIN_SPI_SS1); + +USBMSD MassStorage(&root); + +rtos::Thread acquisition_th; + +FILE *f = nullptr; + +void INT1Event_cb() { + mems_event = 1; +} + +void USBMSD::begin() { + int err = lsm_fs.mount(&lsm_data); + if (err) { + Serial.println("mount failed"); + err = lsm_fs.reformat(&lsm_data); + if (err) { + Serial.println("Reformat failed"); + return; + } + } +} + +mbed::FATFileSystem &USBMSD::getFileSystem() { + static mbed::FATFileSystem fs("lsm"); + return fs; +} + +void led_green_thd() { + while (1) { + if (demo_state == DATA_LOGGER_RUNNING_STATE) { + digitalWrite(LEDG, LOW); + delay(100); + digitalWrite(LEDG, HIGH); + delay(100); + } + } +} + +void Read_FIFO_Data(uint16_t samples_to_read) { + uint16_t i; + + for (i = 0; i < samples_to_read; i++) { + uint8_t tag; + // Check the FIFO tag + AccGyr.Get_FIFO_Tag(&tag); + switch (tag) { + // If we have a gyro tag, read the gyro data + case LSM6DSOX_GYRO_NC_TAG: + { + AccGyr.Get_FIFO_G_Axes(gyr_value); + gyr_available = true; + break; + } + // If we have an acc tag, read the acc data + case LSM6DSOX_XL_NC_TAG: + { + AccGyr.Get_FIFO_X_Axes(acc_value); + acc_available = true; + break; + } + // We can discard other tags + default: + { + break; + } + } + // If we have the measurements of both acc and gyro, we can store them with timestamp + if (acc_available && gyr_available) { + int num_bytes; + num_bytes = snprintf(&buff[pos], (FLASH_BUFF_LEN - pos), "%lu %d %d %d %d %d %d\n", (unsigned long)((float)timestamp_count * MEASUREMENT_TIME_INTERVAL), (int)acc_value[0], (int)acc_value[1], (int)acc_value[2], (int)gyr_value[0], (int)gyr_value[1], (int)gyr_value[2]); + pos += num_bytes; + timestamp_count++; + acc_available = false; + gyr_available = false; + } + } + // We can add the termination character to the string, so we are ready to save it in flash + buff[pos] = '\0'; + pos = 0; +} + +void setup() { + Serial.begin(115200); + MassStorage.begin(); + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + + // Initialize SPI1 bus. + SPI1.begin(); + + //Interrupts. + attachInterrupt(INT_1, INT1Event_cb, RISING); + + // Initialize IMU. + AccGyr.begin(); + AccGyr.Enable_X(); + AccGyr.Enable_G(); + // Configure ODR and FS of the acc and gyro + AccGyr.Set_X_ODR(SENSOR_ODR); + AccGyr.Set_X_FS(ACC_FS); + AccGyr.Set_G_ODR(SENSOR_ODR); + AccGyr.Set_G_FS(GYR_FS); + // Enable the Double Tap event + AccGyr.Enable_Double_Tap_Detection(LSM6DSOX_INT1_PIN); + // Configure FIFO BDR for acc and gyro + AccGyr.Set_FIFO_X_BDR(SENSOR_ODR); + AccGyr.Set_FIFO_G_BDR(SENSOR_ODR); + // Start Led blinking thread + acquisition_th.start(led_green_thd); +} + +void loop() { + + if (mems_event) { + mems_event = 0; + LSM6DSOX_Event_Status_t status; + AccGyr.Get_X_Event_Status(&status); + if (status.DoubleTapStatus) { + switch (demo_state) { + case DATA_STORAGE_STATE: + { + // Go to DATA_LOGGER_IDLE_STATE state + demo_state = DATA_LOGGER_IDLE_STATE; + digitalWrite(LEDG, LOW); + Serial.println("From DATA_STORAGE_STATE To DATA_LOGGER_IDLE_STATE"); + break; + } + case DATA_LOGGER_IDLE_STATE: + { + char filename[32]; + // Go to DATA_LOGGER_RUNNING_STATE state + snprintf(filename, 32, "/lsm/data_%lu.txt", file_count); + Serial.print("Start writing file "); + Serial.println(filename); + // open a file to write some data + // w+ means overwrite, so every time the board is rebooted the file will be overwritten + f = fopen(filename, "w+"); + if (f != nullptr) { + // write header + fprintf(f, "Timestamp[ms] A_X [mg] A_Y [mg] A_Z [mg] G_X [mdps] G_Y [mdps] G_Z [mdps]\n"); + fflush(f); + Serial.println("From DATA_LOGGER_IDLE_STATE To DATA_LOGGER_RUNNING_STATE"); + demo_state = DATA_LOGGER_RUNNING_STATE; + digitalWrite(LEDG, HIGH); + timestamp_count = 0; + pos = 0; + acc_available = false; + gyr_available = false; + // Set FIFO in Continuous mode + AccGyr.Set_FIFO_Mode(LSM6DSOX_STREAM_MODE); + } + break; + } + case DATA_LOGGER_RUNNING_STATE: + { + // Empty the FIFO + uint16_t fifo_samples; + AccGyr.Get_FIFO_Num_Samples(&fifo_samples); + Read_FIFO_Data(fifo_samples); + // Store the string in flash + fprintf(f, "%s", buff); + fflush(f); + + // Close the log file and increase the counter + fclose(f); + file_count++; + // Set FIFO in Bypass mode + AccGyr.Set_FIFO_Mode(LSM6DSOX_BYPASS_MODE); + // Go to DATA_LOGGER_IDLE_STATE state + demo_state = DATA_LOGGER_IDLE_STATE; + // Wait for the led thread ends the blinking + delay(250); + digitalWrite(LEDG, LOW); + Serial.println("From DATA_LOGGER_RUNNING_STATE To DATA_LOGGER_IDLE_STATE"); + break; + } + default: + Serial.println("Error! Invalid state"); + } + } + } + + if (demo_state == DATA_LOGGER_RUNNING_STATE) { + uint16_t fifo_samples; + + // Check the number of samples inside FIFO + AccGyr.Get_FIFO_Num_Samples(&fifo_samples); + + // If we reach the threshold we can empty the FIFO + if (fifo_samples > FIFO_SAMPLE_THRESHOLD) { + // Empty the FIFO + Read_FIFO_Data(fifo_samples); + // Store the string in flash + fprintf(f, "%s", buff); + fflush(f); + } + } + + if (demo_state == DATA_STORAGE_STATE && millis() > 10000) { + // Disable the sensor and go to Mass Storage mode + AccGyr.Disable_Double_Tap_Detection(); + AccGyr.Disable_X(); + AccGyr.Disable_G(); + while (1) { + digitalWrite(LEDB, LOW); + delay(100); + digitalWrite(LEDB, HIGH); + delay(100); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/NiclaVision_MLC_Motion_Intensity.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/NiclaVision_MLC_Motion_Intensity.ino new file mode 100644 index 00000000..cdc73cb7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/NiclaVision_MLC_Motion_Intensity.ino @@ -0,0 +1,130 @@ +/* + This example shows how to load the MLC bytecode for Motion Intensity on LSM6DSOX + of the Arduino Nicla Vision. +*/ + +// Includes +#include "LSM6DSOXSensor.h" +#include "lsm6dsox_motion_intensity.h" + +#define INT_1 LSM6DS_INT + +//Interrupts. +volatile int mems_event = 0; + +// Components +LSM6DSOXSensor AccGyr(&SPI1, PIN_SPI_SS1); + +// MLC +ucf_line_t *ProgramPointer; +int32_t LineCounter; +int32_t TotalNumberOfLine; + +void INT1Event_cb(); +void printMLCStatus(uint8_t status); + +void setup() { + // Led. + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDR, OUTPUT); + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + + // Initialize serial for output. + Serial.begin(115200); + + // Initialize I2C bus. + SPI1.begin(); + + AccGyr.begin(); + + /* Feed the program to Machine Learning Core */ + /* Motion Intensity Default program */ + ProgramPointer = (ucf_line_t *)lsm6dsox_motion_intensity; + TotalNumberOfLine = sizeof(lsm6dsox_motion_intensity) / sizeof(ucf_line_t); + Serial.println("Motion Intensity for LSM6DSOX MLC"); + Serial.print("UCF Number Line="); + Serial.println(TotalNumberOfLine); + + for (LineCounter = 0; LineCounter < TotalNumberOfLine; LineCounter++) { + if (AccGyr.Write_Reg(ProgramPointer[LineCounter].address, ProgramPointer[LineCounter].data)) { + Serial.print("Error loading the Program to LSM6DSOX at line: "); + Serial.println(LineCounter); + while (1) { + // Led blinking. + digitalWrite(LED_BUILTIN, LOW); + delay(250); + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + } + } + } + + Serial.println("Program loaded inside the LSM6DSOX MLC"); + + AccGyr.Enable_X(); + AccGyr.Set_X_ODR(104.0f); + AccGyr.Set_X_FS(2); + + //Interrupts. + pinMode(INT_1, INPUT); + attachInterrupt(INT_1, INT1Event_cb, RISING); +} + +void loop() { + if (mems_event) { + mems_event = 0; + LSM6DSOX_MLC_Status_t status; + AccGyr.Get_MLC_Status(&status); + if (status.is_mlc1) { + uint8_t mlc_out[8]; + AccGyr.Get_MLC_Output(mlc_out); + printMLCStatus(mlc_out[0]); + } + } +} + +void INT1Event_cb() { + mems_event = 1; +} + +void printMLCStatus(uint8_t status) { + switch (status) { + case 1: + // Reset leds status + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + // LEDB On + digitalWrite(LEDB, LOW); + Serial.println("Stationary"); + break; + case 4: + // Reset leds status + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + // LEDG On + digitalWrite(LEDG, LOW); + Serial.println("Medium Intensity"); + break; + case 8: + // Reset leds status + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + // LEDR On + digitalWrite(LEDR, LOW); + Serial.println("High Intensity"); + break; + default: + // Reset leds status + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + Serial.println("Unknown"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h new file mode 100644 index 00000000..392d7053 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h @@ -0,0 +1,357 @@ +/* + ****************************************************************************** + * @file lsm6dsox_motion_intensity.h + * @author Sensors Software Solution Team + * @brief This file contains the configuration for lsm6dsox_motion_intensity. + * + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef LSM6DSOX_MOTION_INTENSITY_H +#define LSM6DSOX_MOTION_INTENSITY_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +#ifndef MEMS_UCF_SHARED_TYPES +#define MEMS_UCF_SHARED_TYPES + + /** Common data block definition **/ + typedef struct { + uint8_t address; + uint8_t data; + } ucf_line_t; + +#endif /* MEMS_UCF_SHARED_TYPES */ + + /** Configuration array generated from Unico Tool **/ + const ucf_line_t lsm6dsox_motion_intensity[] = { + { + .address = 0x10, + .data = 0x00, + }, + { + .address = 0x11, + .data = 0x00, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x04, + .data = 0x00, + }, + { + .address = 0x05, + .data = 0x00, + }, + { + .address = 0x17, + .data = 0x40, + }, + { + .address = 0x02, + .data = 0x11, + }, + { + .address = 0x08, + .data = 0xEA, + }, + { + .address = 0x09, + .data = 0x46, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x09, + .data = 0x50, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x0A, + }, + { + .address = 0x02, + .data = 0x11, + }, + { + .address = 0x08, + .data = 0xF2, + }, + { + .address = 0x09, + .data = 0x34, + }, + { + .address = 0x02, + .data = 0x11, + }, + { + .address = 0x08, + .data = 0xFA, + }, + { + .address = 0x09, + .data = 0x3C, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x09, + .data = 0x52, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x09, + .data = 0x5E, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x02, + .data = 0x31, + }, + { + .address = 0x08, + .data = 0x3C, + }, + { + .address = 0x09, + .data = 0x3F, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x01, + }, + { + .address = 0x09, + .data = 0x10, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x1F, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x02, + .data = 0x31, + }, + { + .address = 0x08, + .data = 0x52, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x01, + .data = 0x00, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x17, + .data = 0x40, + }, + { + .address = 0x02, + .data = 0x31, + }, + { + .address = 0x08, + .data = 0x5E, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x2C, + }, + { + .address = 0x09, + .data = 0x80, + }, + { + .address = 0x09, + .data = 0xA0, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x41, + }, + { + .address = 0x09, + .data = 0xE0, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x17, + .data = 0x00, + }, + { + .address = 0x04, + .data = 0x00, + }, + { + .address = 0x05, + .data = 0x10, + }, + { + .address = 0x02, + .data = 0x01, + }, + { + .address = 0x01, + .data = 0x00, + }, + { + .address = 0x5E, + .data = 0x02, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x0D, + .data = 0x01, + }, + { + .address = 0x60, + .data = 0x35, + }, + { + .address = 0x01, + .data = 0x00, + }, + { + .address = 0x10, + .data = 0x40, + }, + { + .address = 0x11, + .data = 0x00, + } + }; + +#ifdef __cplusplus +} +#endif + +#endif /* LSM6DSOX_MOTION_INTENSITY_H */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_DataLogger_FIFO/RP2040_DataLogger_FIFO.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_DataLogger_FIFO/RP2040_DataLogger_FIFO.ino new file mode 100644 index 00000000..727ed81f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_DataLogger_FIFO/RP2040_DataLogger_FIFO.ino @@ -0,0 +1,257 @@ +/* + This example exposes the first MB of Rp2040 flash as a USB disk. + The user can interact with this disk as a bidirectional communication with the board + For example, the board could save data in a file to be retrieved later with a drag and drop. + If the user does a double tap, the firmware goes to datalogger mode (green led on). + Now the user can do another double tap to start a recording of the IMU data + (green led blinking). With another double tap the recording will be stopped (green led on). + Now the user can start/stop other recordings of the IMU data using again the double tap. + The log files are saved in flash with an increasing number suffix data_0.txt, data_1.txt, etc. + If you want to transfer the log files to the PC, you can reset the board and + wait for 10 seconds (blue led blinking). + You can find the video tutorial on LSM6DSOX MLC at: https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-imu-advanced +*/ + +#include "PluggableUSBMSD.h" +#include "FlashIAPBlockDevice.h" +#include "WiFiNINA.h" +#include "LSM6DSOXSensor.h" + +#define INT_1 INT_IMU +#define SENSOR_ODR 104.0f // In Hertz +#define ACC_FS 2 // In g +#define GYR_FS 2000 // In dps +#define MEASUREMENT_TIME_INTERVAL (1000.0f / SENSOR_ODR) // In ms +#define FIFO_SAMPLE_THRESHOLD 199 +#define FLASH_BUFF_LEN 8192 + +typedef enum { + DATA_STORAGE_STATE, + DATA_LOGGER_IDLE_STATE, + DATA_LOGGER_RUNNING_STATE +} demo_state_e; + +volatile demo_state_e demo_state = DATA_STORAGE_STATE; +volatile int mems_event = 0; +uint32_t file_count = 0; +unsigned long timestamp_count = 0; +bool acc_available = false; +bool gyr_available = false; +int32_t acc_value[3]; +int32_t gyr_value[3]; +char buff[FLASH_BUFF_LEN]; +uint32_t pos = 0; + +static FlashIAPBlockDevice bd(XIP_BASE + 0x100000, 0x100000); + +LSM6DSOXSensor AccGyr(&Wire, LSM6DSOX_I2C_ADD_L); + +USBMSD MassStorage(&bd); + +rtos::Thread acquisition_th; + +FILE *f = nullptr; + +void INT1Event_cb() { + mems_event = 1; +} + +void USBMSD::begin() { + int err = getFileSystem().mount(&bd); + if (err) { + err = getFileSystem().reformat(&bd); + } +} + +mbed::FATFileSystem &USBMSD::getFileSystem() { + static mbed::FATFileSystem fs("fs"); + return fs; +} + +void led_green_thd() { + while (1) { + if (demo_state == DATA_LOGGER_RUNNING_STATE) { + digitalWrite(LEDG, HIGH); + delay(100); + digitalWrite(LEDG, LOW); + delay(100); + } + } +} + +void Read_FIFO_Data(uint16_t samples_to_read) { + uint16_t i; + + for (i = 0; i < samples_to_read; i++) { + uint8_t tag; + // Check the FIFO tag + AccGyr.Get_FIFO_Tag(&tag); + switch (tag) { + // If we have a gyro tag, read the gyro data + case LSM6DSOX_GYRO_NC_TAG: + { + AccGyr.Get_FIFO_G_Axes(gyr_value); + gyr_available = true; + break; + } + // If we have an acc tag, read the acc data + case LSM6DSOX_XL_NC_TAG: + { + AccGyr.Get_FIFO_X_Axes(acc_value); + acc_available = true; + break; + } + // We can discard other tags + default: + { + break; + } + } + // If we have the measurements of both acc and gyro, we can store them with timestamp + if (acc_available && gyr_available) { + int num_bytes; + num_bytes = snprintf(&buff[pos], (FLASH_BUFF_LEN - pos), "%lu %d %d %d %d %d %d\n", (unsigned long)((float)timestamp_count * MEASUREMENT_TIME_INTERVAL), (int)acc_value[0], (int)acc_value[1], (int)acc_value[2], (int)gyr_value[0], (int)gyr_value[1], (int)gyr_value[2]); + pos += num_bytes; + timestamp_count++; + acc_available = false; + gyr_available = false; + } + } + // We can add the termination character to the string, so we are ready to save it in flash + buff[pos] = '\0'; + pos = 0; +} + +void setup() { + Serial.begin(115200); + MassStorage.begin(); + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + + // Initialize I2C bus. + Wire.begin(); + Wire.setClock(400000); + + //Interrupts. + attachInterrupt(INT_1, INT1Event_cb, RISING); + + // Initialize IMU. + AccGyr.begin(); + AccGyr.Enable_X(); + AccGyr.Enable_G(); + // Configure ODR and FS of the acc and gyro + AccGyr.Set_X_ODR(SENSOR_ODR); + AccGyr.Set_X_FS(ACC_FS); + AccGyr.Set_G_ODR(SENSOR_ODR); + AccGyr.Set_G_FS(GYR_FS); + // Enable the Double Tap event + AccGyr.Enable_Double_Tap_Detection(LSM6DSOX_INT1_PIN); + // Configure FIFO BDR for acc and gyro + AccGyr.Set_FIFO_X_BDR(SENSOR_ODR); + AccGyr.Set_FIFO_G_BDR(SENSOR_ODR); + // Start Led blinking thread + acquisition_th.start(led_green_thd); +} + +void loop() { + + if (mems_event) { + mems_event = 0; + LSM6DSOX_Event_Status_t status; + AccGyr.Get_X_Event_Status(&status); + if (status.DoubleTapStatus) { + switch (demo_state) { + case DATA_STORAGE_STATE: + { + // Go to DATA_LOGGER_IDLE_STATE state + demo_state = DATA_LOGGER_IDLE_STATE; + digitalWrite(LEDG, HIGH); + Serial.println("From DATA_STORAGE_STATE To DATA_LOGGER_IDLE_STATE"); + break; + } + case DATA_LOGGER_IDLE_STATE: + { + char filename[32]; + // Go to DATA_LOGGER_RUNNING_STATE state + snprintf(filename, 32, "/fs/data_%lu.txt", file_count); + Serial.print("Start writing file "); + Serial.println(filename); + // open a file to write some data + // w+ means overwrite, so every time the board is rebooted the file will be overwritten + f = fopen(filename, "w+"); + if (f != nullptr) { + // write header + fprintf(f, "Timestamp[ms] A_X [mg] A_Y [mg] A_Z [mg] G_X [mdps] G_Y [mdps] G_Z [mdps]\n"); + fflush(f); + Serial.println("From DATA_LOGGER_IDLE_STATE To DATA_LOGGER_RUNNING_STATE"); + demo_state = DATA_LOGGER_RUNNING_STATE; + digitalWrite(LEDG, LOW); + timestamp_count = 0; + pos = 0; + acc_available = false; + gyr_available = false; + // Set FIFO in Continuous mode + AccGyr.Set_FIFO_Mode(LSM6DSOX_STREAM_MODE); + } + break; + } + case DATA_LOGGER_RUNNING_STATE: + { + // Empty the FIFO + uint16_t fifo_samples; + AccGyr.Get_FIFO_Num_Samples(&fifo_samples); + Read_FIFO_Data(fifo_samples); + // Store the string in flash + fprintf(f, "%s", buff); + fflush(f); + + // Close the log file and increase the counter + fclose(f); + file_count++; + // Set FIFO in Bypass mode + AccGyr.Set_FIFO_Mode(LSM6DSOX_BYPASS_MODE); + // Go to DATA_LOGGER_IDLE_STATE state + demo_state = DATA_LOGGER_IDLE_STATE; + // Wait for the led thread ends the blinking + delay(250); + digitalWrite(LEDG, HIGH); + Serial.println("From DATA_LOGGER_RUNNING_STATE To DATA_LOGGER_IDLE_STATE"); + break; + } + default: + Serial.println("Error! Invalid state"); + } + } + } + + if (demo_state == DATA_LOGGER_RUNNING_STATE) { + uint16_t fifo_samples; + + // Check the number of samples inside FIFO + AccGyr.Get_FIFO_Num_Samples(&fifo_samples); + + // If we reach the threshold we can empty the FIFO + if (fifo_samples > FIFO_SAMPLE_THRESHOLD) { + // Empty the FIFO + Read_FIFO_Data(fifo_samples); + // Store the string in flash + fprintf(f, "%s", buff); + fflush(f); + } + } + + if (demo_state == DATA_STORAGE_STATE && millis() > 10000) { + // Disable the sensor and go to Mass Storage mode + AccGyr.Disable_Double_Tap_Detection(); + AccGyr.Disable_X(); + AccGyr.Disable_G(); + while (1) { + digitalWrite(LEDB, HIGH); + delay(100); + digitalWrite(LEDB, LOW); + delay(100); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/RP2040_MLC_Motion_Intensity.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/RP2040_MLC_Motion_Intensity.ino new file mode 100644 index 00000000..3b0e502f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/RP2040_MLC_Motion_Intensity.ino @@ -0,0 +1,132 @@ +/* + This example shows how to load the MLC bytecode for Motion Intensity on LSM6DSOX + of the Arduino Nano RP2040 Connect. + You can find the video tutorial on LSM6DSOX MLC at: https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-imu-advanced +*/ + +// Includes +#include "WiFiNINA.h" +#include "LSM6DSOXSensor.h" +#include "lsm6dsox_motion_intensity.h" + +#define INT_1 INT_IMU + +//Interrupts. +volatile int mems_event = 0; + +// Components +LSM6DSOXSensor AccGyr(&Wire, LSM6DSOX_I2C_ADD_L); + +// MLC +ucf_line_t *ProgramPointer; +int32_t LineCounter; +int32_t TotalNumberOfLine; + +void INT1Event_cb(); +void printMLCStatus(uint8_t status); + +void setup() { + // Led. + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDR, OUTPUT); + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + + // Initialize serial for output. + Serial.begin(115200); + + // Initialize I2C bus. + Wire.begin(); + + AccGyr.begin(); + + /* Feed the program to Machine Learning Core */ + /* Motion Intensity Default program */ + ProgramPointer = (ucf_line_t *)lsm6dsox_motion_intensity; + TotalNumberOfLine = sizeof(lsm6dsox_motion_intensity) / sizeof(ucf_line_t); + Serial.println("Motion Intensity for LSM6DSOX MLC"); + Serial.print("UCF Number Line="); + Serial.println(TotalNumberOfLine); + + for (LineCounter = 0; LineCounter < TotalNumberOfLine; LineCounter++) { + if (AccGyr.Write_Reg(ProgramPointer[LineCounter].address, ProgramPointer[LineCounter].data)) { + Serial.print("Error loading the Program to LSM6DSOX at line: "); + Serial.println(LineCounter); + while (1) { + // Led blinking. + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + digitalWrite(LED_BUILTIN, LOW); + delay(250); + } + } + } + + Serial.println("Program loaded inside the LSM6DSOX MLC"); + + AccGyr.Enable_X(); + AccGyr.Set_X_ODR(104.0f); + AccGyr.Set_X_FS(2); + + //Interrupts. + pinMode(INT_1, INPUT); + attachInterrupt(INT_1, INT1Event_cb, RISING); +} + +void loop() { + if (mems_event) { + mems_event = 0; + LSM6DSOX_MLC_Status_t status; + AccGyr.Get_MLC_Status(&status); + if (status.is_mlc1) { + uint8_t mlc_out[8]; + AccGyr.Get_MLC_Output(mlc_out); + printMLCStatus(mlc_out[0]); + } + } +} + +void INT1Event_cb() { + mems_event = 1; +} + +void printMLCStatus(uint8_t status) { + switch (status) { + case 1: + // Reset leds status + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + // LEDB On + digitalWrite(LEDB, HIGH); + Serial.println("Stationary"); + break; + case 4: + // Reset leds status + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + // LEDG On + digitalWrite(LEDG, HIGH); + Serial.println("Medium Intensity"); + break; + case 8: + // Reset leds status + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + // LEDR On + digitalWrite(LEDR, HIGH); + Serial.println("High Intensity"); + break; + default: + // Reset leds status + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + Serial.println("Unknown"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h new file mode 100644 index 00000000..bb8adc74 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h @@ -0,0 +1,365 @@ +/* + ****************************************************************************** + * @file lsm6dsox_motion_intensity.h + * @author Sensors Software Solution Team + * @brief This file contains the configuration for lsm6dsox_motion_intensity. + * + ****************************************************************************** + * @attention + * + *

© Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

+ * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef LSM6DSOX_MOTION_INTENSITY_H +#define LSM6DSOX_MOTION_INTENSITY_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +#ifndef MEMS_UCF_SHARED_TYPES +#define MEMS_UCF_SHARED_TYPES + + /** Common data block definition **/ + typedef struct { + uint8_t address; + uint8_t data; + } ucf_line_t; + +#endif /* MEMS_UCF_SHARED_TYPES */ + + /** Configuration array generated from Unico Tool **/ + const ucf_line_t lsm6dsox_motion_intensity[] = { + { + .address = 0x10, + .data = 0x00, + }, + { + .address = 0x11, + .data = 0x00, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x04, + .data = 0x00, + }, + { + .address = 0x05, + .data = 0x00, + }, + { + .address = 0x17, + .data = 0x40, + }, + { + .address = 0x02, + .data = 0x11, + }, + { + .address = 0x08, + .data = 0xEA, + }, + { + .address = 0x09, + .data = 0x46, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x09, + .data = 0x50, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x0A, + }, + { + .address = 0x02, + .data = 0x11, + }, + { + .address = 0x08, + .data = 0xF2, + }, + { + .address = 0x09, + .data = 0x34, + }, + { + .address = 0x02, + .data = 0x11, + }, + { + .address = 0x08, + .data = 0xFA, + }, + { + .address = 0x09, + .data = 0x3C, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x09, + .data = 0x52, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x09, + .data = 0x5E, + }, + { + .address = 0x09, + .data = 0x03, + }, + { + .address = 0x02, + .data = 0x31, + }, + { + .address = 0x08, + .data = 0x3C, + }, + { + .address = 0x09, + .data = 0x3F, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x01, + }, + { + .address = 0x09, + .data = 0x10, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x1F, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x02, + .data = 0x31, + }, + { + .address = 0x08, + .data = 0x52, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x01, + .data = 0x00, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x17, + .data = 0x40, + }, + { + .address = 0x02, + .data = 0x31, + }, + { + .address = 0x08, + .data = 0x5E, + }, + { + .address = 0x09, + .data = 0x00, + }, + { + .address = 0x09, + .data = 0x18, + }, + { + .address = 0x09, + .data = 0x11, + }, + { + .address = 0x09, + .data = 0xC0, + }, + { + .address = 0x09, + .data = 0xC8, + }, + { + .address = 0x09, + .data = 0x32, + }, + { + .address = 0x09, + .data = 0x84, + }, + { + .address = 0x09, + .data = 0xE0, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x17, + .data = 0x00, + }, + { + .address = 0x04, + .data = 0x00, + }, + { + .address = 0x05, + .data = 0x10, + }, + { + .address = 0x02, + .data = 0x01, + }, + { + .address = 0x01, + .data = 0x00, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x60, + .data = 0x35, + }, + { + .address = 0x01, + .data = 0x00, + }, + { + .address = 0x10, + .data = 0x40, + }, + { + .address = 0x11, + .data = 0x00, + }, + { + .address = 0x5E, + .data = 0x02, + }, + { + .address = 0x01, + .data = 0x80, + }, + { + .address = 0x0D, + .data = 0x01, + }, + { + .address = 0x01, + .data = 0x00, + } + }; + +#ifdef __cplusplus +} +#endif + +#endif /* LSM6DSOX_MOTION_INTENSITY_H */ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Nano33BLE_System/examples/Nano33_updateBLandSoftDevice/Nano33_updateBLandSoftDevice.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Nano33BLE_System/examples/Nano33_updateBLandSoftDevice/Nano33_updateBLandSoftDevice.ino new file mode 100644 index 00000000..08dfd072 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Nano33BLE_System/examples/Nano33_updateBLandSoftDevice/Nano33_updateBLandSoftDevice.ino @@ -0,0 +1,239 @@ +/* + * This sketch allows to support Soft Devices on the Arduino Nano 33 BLE (Sense). + * + * To be able to support Soft Devices, the bootloader first needs to be updated. + * The new bootloader is fully backwards compatible with standard sketches. + * ----------------------------------------------------------------------- + * + * INSTRUCTIONS + * + * 1) Upload this sketch on the Nano 33 BLE to download the new bootloader into the flash. + * You can choose whether to update only the bootloader or the bootloader plus SoftDevice. + * Make a choice through the Serial monitor. + * + * 2) After flashing the bootloader the sketch asks if you want to upload the SoftDevice. + * This is required for the OpenMV firmware to work. + * After completion, the board will reboot and enter the bootloader mode. + * + * 3) Now you can upload a sketch that uses the SoftDevice at 0x26000, using the following bossac command + * + * /path/to/bossac -d --port=yourPort --offset=0x16000 -U -i -e -w /path/to/sketch.bin -R + * + * Or you can still upload a standard sketch from the IDE at 0x10000. This will of course overwrite the SoftDevice. + * So if you want to run a SoftDevice-related sketch, always remember to upload this sketch before and re-flash the SoftDevice. + * + * To create a custom SoftDevice follow this procedure: + * + * 1) Convert your SoftDevice binary to a SoftDevice.h . + * The nRF5-SDK website provides a SoftDevice.hex, so run the following commands: + * + * objcopy --input-target=ihex --output-target=binary --gap-fill 0xff SoftDevice.hex SoftDevice.bin + * xxd -i SoftDevice.bin > SoftDevice.h + * + * 2) Copy the content of the generated header file to SoftDevice.h + * + * 3) Run this sketch again and flash the SoftDevice. + */ + +#include "FlashIAP.h" +#include "MBR.h" +#include "bootloader.h" +#include "nrf_nvmc.h" +#include "SoftDevice.h" + +#define SOFTDEVICE_ADDR (0xA0000) +#define SOFTDEVICE_INFO_ADDR (0xFF000) +#define MBR_ADDR (0x0) +#define BOOTLOADER_ADDR (0xE0000) +#define UICR_BOOT_ADDR (0x10001014) + +#define BOOTLOADER_SIZE nano33_bootloader_hex_len +const unsigned int magic = 0x5f27a93d; + +mbed::FlashIAP flash; + +bool hasLatestBootloader() { + //Check if the CRC32 of the flashed bootloader + //matches the CRC32 of the provided bootloader binary + return getCurrentBootloaderCrc() == getTargetBootloaderCrc(); +} + +bool getUserConfirmation() { + while (true) { + if (Serial.available()) { + char choice = Serial.read(); + switch (choice) { + case 'y': + case 'Y': + return true; + case 'n': + case 'N': + return false; + default: + continue; + } + } + } +} + +void applyUpdate(uint32_t address, const unsigned char payload[], long len, uint32_t bin_pointer = 0) { + uint32_t flash_pointer = 0; + const uint32_t page_size = flash.get_page_size(); + char *page_buffer = new char[page_size]; + uint32_t addr = address; + + uint32_t sector_size = flash.get_sector_size(addr); + uint32_t next_sector = addr + sector_size; + bool sector_erased = false; + size_t pages_flashed = 0; + uint32_t percent_done = 0; + + while (true) { + + if (flash_pointer >= len) { + break; + } + + flash.erase(addr + flash_pointer, sector_size); + + if ((len - flash_pointer) < sector_size) { + sector_size = len - flash_pointer; + } + + // Program page + flash.program(&payload[bin_pointer], addr + flash_pointer, sector_size); + Serial.print("Flash Address = "); + Serial.println(addr + flash_pointer, HEX); + + bin_pointer = bin_pointer + sector_size; + flash_pointer = flash_pointer + sector_size; + + uint32_t percent_done = flash_pointer * 100 / len; + Serial.println("Flashed " + String(percent_done) + "%"); + } + Serial.println(); + + delete[] page_buffer; +} + +void updateBootloader() { + Serial.println("This sketch modifies the Nano33 bootloader to support Soft Devices."); + Serial.println(); + + flash.init(); + + Serial.println("Flashing MBR..."); + applyUpdate(MBR_ADDR, MBR_bin, MBR_bin_len); + + Serial.println("Flashing bootloader..."); + applyUpdate(BOOTLOADER_ADDR, nano33_bootloader_hex, nano33_bootloader_hex_len); + + Serial.print("Bootloader 32bit CRC is: "); + uint32_t crc32 = getTargetBootloaderCrc(); + Serial.println(crc32, HEX); + + Serial.println("Writing in UICR memory the address of the new bootloader..."); + nrf_nvmc_write_word(UICR_BOOT_ADDR, BOOTLOADER_ADDR); + + flash.deinit(); + + Serial.println(); + Serial.println("Bootloader update successfully completed!\n"); +} + +void updateSoftDevice() { + flash.init(); + + Serial.println("Storing SoftDevice length info at 0xFF000..."); + writeSoftDeviceLen(SOFTDEVICE_INFO_ADDR); + + Serial.println("Flashing SoftDevice..."); + applyUpdate(SOFTDEVICE_ADDR, Softdevice_bin, Softdevice_bin_len - 4096, 4096); + + flash.deinit(); + + Serial.println(); + Serial.println("SoftDevice update complete! The board is restarting..."); + NVIC_SystemReset(); +} + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + if (!hasLatestBootloader()) { + Serial.println("Your bootloader version is outdated (update required for Soft Device support)."); + Serial.println("Would you like to update it? Y/N"); + + if (getUserConfirmation()) { + updateBootloader(); + } + } + + if (hasLatestBootloader()) { + Serial.println("Would you like to install the Soft Device (required for OpenMV)? Y/N"); + if (getUserConfirmation()) { + updateSoftDevice(); + } + } + + Serial.println("Done. You may now disconnect the board."); +} + +uint32_t getTargetBootloaderCrc() { + uint32_t mask = 0; + uint32_t crc = 0xFFFFFFFF; + uint32_t b = 0; + uint8_t bootByte = 0; + + int iterations = BOOTLOADER_SIZE; + + for (int i = 0; i < iterations; i = i + 4) { + b = 0; + for (int j = 0; j < 4; j++) { + mask = 0; + bootByte = nano33_bootloader_hex[i + j]; + mask = mask + (uint32_t)bootByte; + mask = mask << 8 * j; + b = b | mask; + } + crc = crc ^ b; + } + return crc; +} + +uint32_t getCurrentBootloaderCrc() { + uint32_t b = 0; + uint32_t crc = 0xFFFFFFFF; + + int iterations = ceil(BOOTLOADER_SIZE / 4); + + int addr = BOOTLOADER_ADDR; + + for (int i = 0; i < iterations; i++) { + //Read 32 bit from flash + flash.read(&b, addr, sizeof(b)); + //Serial.println(b, HEX); + //Update crc + crc = crc ^ b; + //Update pointer + addr = addr + 4; + } + return crc; +} + +void writeSoftDeviceLen(uint32_t address) { + uint32_t sd_addr = SOFTDEVICE_ADDR; + flash.erase(address, 16); + //Write flag to let Bootloader understand that SoftDevice binary must be moved + flash.program(&magic, address, 4); + //Write address where the SoftDevice binary has been written + flash.program(&sd_addr, address + 4, 4); + //Write SoftDevice binary length + unsigned int sd_len = Softdevice_bin_len - 4096; + flash.program(&sd_len, address + 8, 4); +} + +void loop() { + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Nicla_System/examples/Blink_Nicla/Blink_Nicla.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Nicla_System/examples/Blink_Nicla/Blink_Nicla.ino new file mode 100644 index 00000000..a9313f35 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Nicla_System/examples/Blink_Nicla/Blink_Nicla.ino @@ -0,0 +1,13 @@ +#include "Nicla_System.h" + +void setup() { + nicla::begin(); + nicla::leds.begin(); +} + +void loop() { + nicla::leds.setColor(green); + delay(1000); + nicla::leds.setColor(off); + delay(1000); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino new file mode 100644 index 00000000..4e7c613f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/PDM/examples/PDMSerialPlotter/PDMSerialPlotter.ino @@ -0,0 +1,85 @@ +/* + This example reads audio data from the on-board PDM microphones, and prints + out the samples to the Serial console. The Serial Plotter built into the + Arduino IDE can be used to plot the audio data (Tools -> Serial Plotter) + + Circuit: + - Arduino Nano 33 BLE board, or + - Arduino Nano RP2040 Connect, or + - Arduino Portenta H7 board plus Portenta Vision Shield + + This example code is in the public domain. +*/ + +#include + +// default number of output channels +static const char channels = 1; + +// default PCM output frequency +static const int frequency = 16000; + +// Buffer to read samples into, each sample is 16-bits +short sampleBuffer[512]; + +// Number of audio samples read +volatile int samplesRead; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // Configure the data receive callback + PDM.onReceive(onPDMdata); + + // Optionally set the gain + // Defaults to 20 on the BLE Sense and 24 on the Portenta Vision Shield + // PDM.setGain(30); + + // Initialize PDM with: + // - one channel (mono mode) + // - a 16 kHz sample rate for the Arduino Nano 33 BLE Sense + // - a 32 kHz or 64 kHz sample rate for the Arduino Portenta Vision Shield + if (!PDM.begin(channels, frequency)) { + Serial.println("Failed to start PDM!"); + while (1) + ; + } +} + +void loop() { + // Wait for samples to be read + if (samplesRead) { + + // Print samples to the serial monitor or plotter + for (int i = 0; i < samplesRead; i++) { + if (channels == 2) { + Serial.print("L:"); + Serial.print(sampleBuffer[i]); + Serial.print(" R:"); + i++; + } + Serial.println(sampleBuffer[i]); + } + + // Clear the read count + samplesRead = 0; + } +} + +/** + * Callback function to process the data from the PDM microphone. + * NOTE: This callback is executed as part of an ISR. + * Therefore using `Serial` to print messages inside this function isn't supported. + * */ +void onPDMdata() { + // Query the number of available bytes + int bytesAvailable = PDM.available(); + + // Read into the sample buffer + PDM.read(sampleBuffer, bytesAvailable); + + // 16-bit, 2 bytes per sample + samplesRead = bytesAvailable / 2; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDCARD/examples/TestSDCARD/TestSDCARD.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDCARD/examples/TestSDCARD/TestSDCARD.ino new file mode 100644 index 00000000..67eb8dac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDCARD/examples/TestSDCARD/TestSDCARD.ino @@ -0,0 +1,62 @@ +/* + Portenta - TestSDCARD + + The sketch shows how to mount an SDCARD and list its content. + + The circuit: + - Portenta H7 + Vision Shield + - Portenta H7 + Portenta Breakout + + This example code is in the public domain. +*/ +#include "SDMMCBlockDevice.h" +#include "FATFileSystem.h" + +SDMMCBlockDevice block_device; +mbed::FATFileSystem fs("fs"); + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + Serial.println("Mounting SDCARD..."); + int err = fs.mount(&block_device); + if (err) { + // Reformat if we can't mount the filesystem + // this should only happen on the first boot + Serial.println("No filesystem found, formatting... "); + err = fs.reformat(&block_device); + } + if (err) { + Serial.println("Error formatting SDCARD "); + while (1) + ; + } + + DIR *dir; + struct dirent *ent; + int dirIndex = 0; + + Serial.println("List SDCARD content: "); + if ((dir = opendir("/fs")) != NULL) { + // Print all the files and directories within directory (not recursively) + while ((ent = readdir(dir)) != NULL) { + Serial.println(ent->d_name); + dirIndex++; + } + closedir(dir); + } else { + // Could not open directory + Serial.println("Error opening SDCARD\n"); + while (1) + ; + } + if (dirIndex == 0) { + Serial.println("Empty SDCARD"); + } +} + +void loop() { + // Empty +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDRAM/examples/SDRAM_operations/SDRAM_operations.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDRAM/examples/SDRAM_operations/SDRAM_operations.ino new file mode 100644 index 00000000..f30d98c4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDRAM/examples/SDRAM_operations/SDRAM_operations.ino @@ -0,0 +1,69 @@ +/* + How to interact with external SDRAM on Portenta H7 + + The board comes with an hefty 8MB of external fast RAM, which can be used: + - as a framebuffer (raw mode) + - as an expansion of on-chip RAM to store "standard" data + + This example shows both the usages +*/ + +#include "SDRAM.h" + +REDIRECT_STDOUT_TO(Serial); + +void nonFrameBuffer() { + // Initilize SDRAM for non-framebuffer operations + SDRAM.begin(); // is the same as SDRAM.begin(SDRAM_START_ADDRESS); + + // Now we can malloc() and free() in the whole RAM space + // For example, let's create a 7MB array + uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024); + + // and a small one + uint8_t* mySmallArray = (uint8_t*)SDRAM.malloc(128); + + // and use then as usual + for (int i = 0; i < 128; i++) { + myVeryBigArray[i] = i; + mySmallArray[i] = i * 2; + } + + // free the memory when you don't need them anymore + SDRAM.free(myVeryBigArray); +} + +void frameBuffer() { + // In case we want a framebuffer-like area at the beginning of the flash, + // simply initialize the memory as + + SDRAM.begin(SDRAM_START_ADDRESS + 2 * 1024 * 1024); + // 2MB of contiguous memory available at the beginning + + uint32_t* framebuffer = (uint32_t*)SDRAM_START_ADDRESS; + + // We can't allocate anymore the huge 7MB array + + uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024); + if (myVeryBigArray == NULL) { + Serial.println("Oops, too big :)"); + } +} + +void setup() { + Serial.begin(115200); + while (!Serial) + ; + + frameBuffer(); + // Uncomment to test the other functionality + // nonFrameBuffer(); + + // Sort of memtest for stability, useful for testing when overclocking + if (SDRAM.test()) { + Serial.println("SDRAM completely functional"); + } +} + +void loop() { +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_Video/examples/ArduinoLogo/ArduinoLogo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_Video/examples/ArduinoLogo/ArduinoLogo.ino new file mode 100644 index 00000000..6a83ada4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_Video/examples/ArduinoLogo/ArduinoLogo.ino @@ -0,0 +1,27 @@ +#include "Portenta_lvgl.h" +#include "Portenta_Video.h" +#include "image.h" + +// Alternatively, any raw RGB565 image can be included on demand using this macro +/* +#define INCBIN_PREFIX +#include "incbin.h" +INCBIN(test, "/home/user/Downloads/test.bin"); +*/ + +int offset; + +void setup() { + portenta_init_video(); + + stm32_LCD_Clear(0); + stm32_LCD_Clear(0); + + offset = ((stm32_getXSize() - 300)) + (stm32_getXSize() * (stm32_getYSize() - 300) / 2) * sizeof(uint16_t); +} + +void loop() { + // Replace texture_raw with testData if using the INCBIN method + // Also, replace 300x300 resolution with the actual one + stm32_LCD_DrawImage((void *)texture_raw, (void *)(getNextFrameBuffer() + offset), 300, 300, DMA2D_INPUT_RGB565); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/KeyboardMouseController_rpc_m4/KeyboardMouseController_rpc_m4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/KeyboardMouseController_rpc_m4/KeyboardMouseController_rpc_m4.ino new file mode 100644 index 00000000..2b2bf655 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/KeyboardMouseController_rpc_m4/KeyboardMouseController_rpc_m4.ino @@ -0,0 +1,112 @@ +#include "USBHost.h" +#include "RPC.h" + +#ifndef CORE_CM4 +#error "This sketch should be compiled for Portenta (M4 core)" +#endif + +USBHost usb; + +#define MOD_CTRL (0x01 | 0x10) +#define MOD_SHIFT (0x02 | 0x20) +#define MOD_ALT (0x04 | 0x40) +#define MOD_WIN (0x08 | 0x80) + +#define LED_NUM_LOCK 1 +#define LED_CAPS_LOCK 2 +#define LED_SCROLL_LOCK 4 + +static uint8_t key_leds; +static const char knum[] = "1234567890"; +static const char ksign[] = "!@#$%^&*()"; +static const char tabA[] = "\t -=[]\\#;'`,./"; +static const char tabB[] = "\t _+{}|~:\"~<>?"; +// route the key event to stdin + +static void stdin_recvchar(char ch) { + RPC.call("on_key", ch); +} + +static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) { + uint8_t modify = keys[0]; + uint8_t key = keys[2]; + uint8_t last_leds = key_leds; + if (key >= KEY_A && key <= KEY_Z) { + char ch = 'A' + key - KEY_A; + if ((!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK))) { + ch += 'a' - 'A'; + } + stdin_recvchar(ch); + } else if (key >= KEY_1 && key <= KEY_0) { + if (modify & MOD_SHIFT) { + stdin_recvchar(ksign[key - KEY_1]); + } else { + stdin_recvchar(knum[key - KEY_1]); + } + } else if (key >= KEY_TAB && key <= KEY_SLASH) { + if (modify & MOD_SHIFT) { + stdin_recvchar(tabB[key - KEY_TAB]); + } else { + stdin_recvchar(tabA[key - KEY_TAB]); + } + } else if (key == KEY_ENTER) { + stdin_recvchar('\r'); + } else if (key == KEY_CAPSLOCK) { + key_leds ^= LED_CAPS_LOCK; + } else if (key == KEY_NUMLOCK) { + key_leds ^= LED_NUM_LOCK; + } else if (key == KEY_SCROLLLOCK) { + key_leds ^= LED_SCROLL_LOCK; + } + + if (key_leds != last_leds) { + tusbh_set_keyboard_led(ep, key_leds); + } + return 0; +} + +static int process_mouse(tusbh_ep_info_t* ep, const uint8_t* mouse) { + uint8_t btn = mouse[0]; + int8_t x = ((int8_t*)mouse)[1]; + int8_t y = ((int8_t*)mouse)[2]; + RPC.call("on_mouse", btn, x, y); +} + +static const tusbh_boot_key_class_t cls_boot_key = { + .backend = &tusbh_boot_keyboard_backend, + .on_key = process_key +}; + +static const tusbh_boot_mouse_class_t cls_boot_mouse = { + .backend = &tusbh_boot_mouse_backend, + .on_mouse = process_mouse +}; + +static const tusbh_hid_class_t cls_hid = { + .backend = &tusbh_hid_backend, + //.on_recv_data = process_hid_recv, + //.on_send_done = process_hid_sent, +}; + +static const tusbh_hub_class_t cls_hub = { + .backend = &tusbh_hub_backend, +}; + +static const tusbh_class_reg_t class_table[] = { + (tusbh_class_reg_t)&cls_boot_key, + (tusbh_class_reg_t)&cls_boot_mouse, + (tusbh_class_reg_t)&cls_hub, + (tusbh_class_reg_t)&cls_hid, + 0, +}; + +void setup() { + Serial1.begin(115200); + RPC.begin(); + usb.Init(USB_CORE_ID_HS, class_table); + //usb.Init(USB_CORE_ID_FS, class_table); +} + +void loop() { + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/Portenta_lvgl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/Portenta_lvgl.ino new file mode 100644 index 00000000..5cdbc6ae --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/Portenta_lvgl.ino @@ -0,0 +1,15 @@ +#include "Portenta_lvgl.h" +#include "lv_demo_widgets.h" + +void setup() { + portenta_init_video(); + lv_demo_widgets(); +} + +void loop() { +#if LVGL_VERSION_MAJOR > 7 + lv_timer_handler(); +#else + lv_task_handler(); +#endif +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/lv_demo_widgets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/lv_demo_widgets.h new file mode 100644 index 00000000..1c3bbe1b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/lv_demo_widgets.h @@ -0,0 +1,38 @@ +/** + * @file lv_demo_widgets.h + * + */ + +#ifndef LV_DEMO_WIDGETS_H +#define LV_DEMO_WIDGETS_H + +#ifdef __cplusplus +extern "C" { +#endif + + /********************* + * INCLUDES + *********************/ + + /********************* + * DEFINES + *********************/ + + /********************** + * TYPEDEFS + **********************/ + + /********************** + * GLOBAL PROTOTYPES + **********************/ + void lv_demo_widgets(void); + + /********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DEMO_WIDGETS_H*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/lvgl_rpc_usb_mouse/lvgl_rpc_usb_mouse.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/lvgl_rpc_usb_mouse/lvgl_rpc_usb_mouse.ino new file mode 100644 index 00000000..b39292fb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/lvgl_rpc_usb_mouse/lvgl_rpc_usb_mouse.ino @@ -0,0 +1,110 @@ +#include "Portenta_lvgl.h" +#include "RPC.h" +#include "USBHost.h" + +int16_t touchpad_x = 0; +int16_t touchpad_y = 0; +uint8_t button = 0; +static lv_indev_drv_t indev_drv_mouse; +static lv_indev_drv_t indev_drv_btn; +static lv_obj_t* myCustomLabel; + +void btn_event_cb(lv_obj_t* myCustomLabel, lv_event_t event) { + if (event == LV_EVENT_CLICKED) { + lv_label_set_text(myCustomLabel, "ButtonClicked"); + } +} + +void on_mouse(uint8_t btn, int8_t x, int8_t y) { + Serial1.print("Mouse: "); + Serial1.print(btn); + Serial1.print(" "); + Serial1.print(x); + Serial1.print(" "); + Serial1.println(y); + touchpad_x += x; + touchpad_y += y; + if (touchpad_x < 0) { + touchpad_x = 0; + } + if (touchpad_y < 0) { + touchpad_y = 0; + } + button = btn; +} + +void on_key(char ch) { + Serial1.print("Keyboard: "); + Serial1.println(ch); +} + +bool my_input_read(lv_indev_drv_t* drv, lv_indev_data_t* data) { + data->point.x = touchpad_x; + data->point.y = touchpad_y; + data->state = LV_INDEV_STATE_REL; + return false; /*No buffering now so no more data read*/ +} + +bool button_read(lv_indev_drv_t* drv, lv_indev_data_t* data) { + static uint32_t last_btn = 0; /*Store the last pressed button*/ + int btn_pr = button - 1; /*Get the ID (0,1,2...) of the pressed button*/ + if (btn_pr >= 0) { /*Is there a button press? (E.g. -1 indicated no button was pressed)*/ + last_btn = btn_pr; /*Save the ID of the pressed button*/ + data->state = LV_INDEV_STATE_PR; /*Set the pressed state*/ + } else { + data->state = LV_INDEV_STATE_REL; /*Set the released state*/ + } + + data->btn_id = last_btn; /*Save the last button*/ + + return false; /*No buffering now so no more data read*/ +} +void setup() { + // put your setup code here, to run once: + RPC.begin(); + Serial1.begin(115200); + RPC.bind("on_mouse", on_mouse); + RPC.bind("on_key", on_key); + portenta_init_video(); + + // Mouse pointer init + lv_indev_drv_init(&indev_drv_mouse); /*Basic initialization*/ + indev_drv_mouse.type = LV_INDEV_TYPE_POINTER; + indev_drv_mouse.read_cb = my_input_read; + lv_indev_t* my_indev_mouse = lv_indev_drv_register(&indev_drv_mouse); + + // Mouse pointer + lv_obj_t* cursor_obj = lv_img_create(lv_scr_act(), NULL); //create object + lv_label_set_text(cursor_obj, "Sys layer"); + lv_indev_set_cursor(my_indev_mouse, cursor_obj); // connect the object to the driver + + // Mouse press + lv_indev_drv_init(&indev_drv_btn); /*Basic initialization*/ + indev_drv_btn.type = LV_INDEV_TYPE_BUTTON; + indev_drv_btn.read_cb = button_read; + lv_indev_t* my_indev_btn = lv_indev_drv_register(&indev_drv_btn); + + //Set your objects + myCustomLabel = lv_label_create(lv_scr_act(), NULL); + lv_obj_align(myCustomLabel, NULL, LV_ALIGN_CENTER, 0, 0); + lv_label_set_text(myCustomLabel, "Button"); + + /*Assign buttons to points on the screen*/ + static const lv_point_t btn_points[1] = { + { 720 / 2, 480 / 2 }, /*Button 0 -> x:10; y:10*/ + }; + lv_indev_set_button_points(my_indev_btn, btn_points); + + + //Create a task + //lv_task_create(label_refresher_task, 1000, LV_TASK_PRIO_MID, NULL); + + //Assign a callback to the button + lv_obj_set_event_cb(myCustomLabel, btn_event_cb); +} + +void loop() { + // put your main code here, to run repeatedly: + lv_task_handler(); + //delay(3); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/BootM4_from_SDRAM/BootM4_from_SDRAM.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/BootM4_from_SDRAM/BootM4_from_SDRAM.ino new file mode 100644 index 00000000..71b422fe --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/BootM4_from_SDRAM/BootM4_from_SDRAM.ino @@ -0,0 +1,85 @@ +#ifdef CORE_CM7 + +#include "SDRAM.h" +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "FATFileSystem.h" +#include "PluggableUSBMSD.h" + +QSPIFBlockDevice root; +mbed::MBRBlockDevice ota_data(&root, 2); +mbed::FATFileSystem ota_data_fs("fs"); + +void USBMSD::begin() { +} + +USBMSD MassStorage(&root); + +long getFileSize(FILE* fp) { + fseek(fp, 0, SEEK_END); + int size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + return size; +} + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial) + ; + + SDRAM.begin(0); + + int err = ota_data_fs.mount(&ota_data); + if (err) { + Serial.println("Please run WiFiFirmwareUpdater once"); + while (1) { + delay(10000); + } + } + + // Copy M4 firmware to SDRAM + FILE* fw = fopen("/fs/fw.bin", "r"); + if (fw == NULL) { + Serial.println("Please copy a firmware for M4 core in the PORTENTA mass storage"); + Serial.println("When done, please unmount the mass storage and reset the board"); + MassStorage.begin(); + while (1) { + delay(10000); + } + } + fread((uint8_t*)CM4_BINARY_START, getFileSize(fw), 1, fw); + fclose(fw); + + bootM4(); +} + +void loop() { + // put your main code here, to run repeatedly: + delay(10000); +} + +#elif defined(CORE_CM4) + +#warning "Compiling a Blink, change the delay or the colour and then copy the .bin into PORTENTA mass storage as fw.bin" + +int led = LEDB; +int delay_ms = 1000; + +void setup() { + pinMode(led, OUTPUT); +} + +void loop() { + digitalWrite(led, HIGH); + delay(delay_ms); + digitalWrite(led, LOW); + delay(delay_ms); +} + +#else + +#error Wrong target selected + +#endif \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/PortentaX8_EchoServer/PortentaX8_EchoServer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/PortentaX8_EchoServer/PortentaX8_EchoServer.ino new file mode 100644 index 00000000..628fe706 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/PortentaX8_EchoServer/PortentaX8_EchoServer.ino @@ -0,0 +1,42 @@ +#include "RPC.h" +#include "SerialRPC.h" + +/* + * This sketch demonstrates how to interact with the Portenta X8 Serial port (over USB) + * On the board, launch both 'proxy' and 'example' binaries (from https://github.com/arduino/portentax8-m4-proxy) + * The M4 provides the 'subtract' API (which will be invoked by 'example' + * It also provides a full duplex Serial-like interface that is proxies through the serial monitor + * Last but not leas, when you write 'echo' the corresponding function in 'example' will be triggered + */ + +int subtract(int a, int b) { + return a - b; +} + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + RPC.bind("subtract", subtract); + delay(1000); +} + +int i = 0; +void loop() { + + //RPC.print("hello"); + //RPC.send("echo", "test"); + //auto res = RPC.call("add", 5, 8).as(); + //RPC.send("echo", String(res).c_str()); + + String str = ""; + while (Serial.available()) { + str += (char)Serial.read(); + } + if (str != "") { + Serial.print(str); + } + if (str.startsWith("echo")) { + delay(100); + RPC.send("echo", "test"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/RPC_m4/RPC_m4.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/RPC_m4/RPC_m4.ino new file mode 100644 index 00000000..d9777973 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/RPC_m4/RPC_m4.ino @@ -0,0 +1,109 @@ +#include "Arduino.h" +#include "RPC.h" + +using namespace rtos; + +Thread subtractThread; + +/** + * Returns the CPU that's currently running the sketch (M7 or M4) + * Note that the sketch has to be uploaded to both cores. + **/ +String currentCPU() { + if (HAL_GetCurrentCPUID() == CM7_CPUID) { + return "M7"; + } else { + return "M4"; + } +} + +/** + * Adds two numbers and returns the sum + **/ +int addOnM7(int a, int b) { + Serial.println(currentCPU() + ": executing add with " + String(a) + " and " + String(b)); + delay(700); // Simulate work + return a + b; +} + +/** + * Subtracts two numbers and returns the difference + **/ +int subtractOnM7(int a, int b) { + Serial.println(currentCPU() + ": executing subtract with " + String(a) + " and " + String(b)); + delay(700); // Simulate work + return a - b; +} + +void callSubstractFromM4() { + while (true) { + delay(700); // Wait 700ms with the next calculation + int a = random(100); // Generate a random number + int b = random(100); // Generate a random number + RPC.println(currentCPU() + ": calling subtract with " + String(a) + " and " + String(b)); + + auto result = RPC.call("remoteSubtract", a, b).as(); + // Prints the result of the calculation + RPC.println(currentCPU() + ": Result is " + String(a) + " - " + String(b) + " = " + String(result)); + } +} + +void setup() { + + pinMode(LED_BUILTIN, OUTPUT); + + // Initialize RPC library; this also boots the M4 core + RPC.begin(); + Serial.begin(115200); + //while (!Serial) {} // Uncomment this to wait until the Serial connection is ready + + // Both CPUs will execute this instruction, just at different times + randomSeed(analogRead(A0)); // Initializes the pseudo-random number generator + + if (currentCPU() == "M7") { + // M7 CPU becomes the server, so it makes two functions available under the defined names + RPC.bind("remoteAdd", addOnM7); + RPC.bind("remoteSubtract", subtractOnM7); + } + + if (currentCPU() == "M4") { + // M4 CPU becomes the client, so spawns a thread that will call subtractOnM7() every 700ms + subtractThread.start(callSubstractFromM4); + } +} + +void loop() { + + if (currentCPU() == "M4") { + // On M4 let's blink an LED. While it's blinking, the callSubstractFromM4() thread is running, + // so it will execute roughly 3 times (2000 / 700 ms) + digitalWrite(LED_BUILTIN, LOW); + delay(1000); + digitalWrite(LED_BUILTIN, HIGH); + delay(1000); + + int a = random(100); + int b = random(100); + // PRC.print works like a Serial port, but it needs a receiver (in this case the M7) + // to actually print the strings to the Serial port + RPC.println(currentCPU() + ": calling add with " + String(a) + " and " + String(b)); + // Let's invoke addOnM7() and wait for a result. + // This will be delayed by the forced delay() in addOnM7() function + // Exercise: if you are not interested in the result of the operation, what operation would you invoke? + auto result = RPC.call("remoteAdd", a, b).as(); + RPC.println(currentCPU() + ": Result is " + String(a) + " + " + String(b) + " = " + String(result)); + } + + if (currentCPU() == "M7") { + // On M7, let's print everything that is received over the RPC1 stream interface + // Buffer it, otherwise all characters will be interleaved by other prints + String buffer = ""; + while (RPC.available()) { + buffer += (char)RPC.read(); // Fill the buffer with characters + } + + if (buffer.length() > 0) { + Serial.print(buffer); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino new file mode 100644 index 00000000..38cf7d33 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino @@ -0,0 +1,24 @@ +#include "Arduino.h" +#include "RPC.h" + +void setup() { + Serial.begin(115200); + RPC.begin(); +} + +void loop() { + String data = ""; + while (RPC.available()) { + data += (char)RPC.read(); + } + if (data != "") { + Serial.write(data.c_str(), data.length()); + } + data = ""; + while (Serial.available()) { + data += (char)Serial.read(); + } + if (data != "") { + RPC.write(data.c_str(), data.length()); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XImportPublicKey/SE05XImportPublicKey.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XImportPublicKey/SE05XImportPublicKey.ino new file mode 100644 index 00000000..560300b6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XImportPublicKey/SE05XImportPublicKey.ino @@ -0,0 +1,87 @@ +/* + SE05X ImportAndVerify + + This sketch uses the SE05X to generate a new EC NIST P-256 keypair + and store it with id 999, then input buffer SHA256 is signed with the private + key. The public key is imported with another id 899 into SE05X and the + signature is checked using the imported public key. + + Circuit: + - Portenta + - Nicla Vision +*/ + +#include + +const byte input[64] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f +}; + +void printBufferHex(const byte input[], size_t inputLength) { + for (int i = 0; i < inputLength; i++) { + Serial.print(input[i] >> 4, HEX); + Serial.print(input[i] & 0x0f, HEX); + } + Serial.println(); +} + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!SE05X.begin()) { + Serial.println("Failed to communicate with SE05X!"); + while (1) + ; + } + + const int privKeyId = 999; + const int publKeyId = 899; + byte derBuf[256]; + size_t derSize; + + SE05X.generatePrivateKey(privKeyId, derBuf, sizeof(derBuf), &derSize); + + // print the input + Serial.print("Input is: "); + printBufferHex(input, sizeof(input)); + + //calculate the input SHA256 + byte sha256[256]; + size_t sha256Len; + SE05X.SHA256(input, sizeof(input), sha256, sizeof(sha256), &sha256Len); + Serial.print("Input SHA256 is: "); + printBufferHex(sha256, sha256Len); + + // calculate the signature, input MUST be SHA256 + byte signature[256]; + size_t signatureLen; + SE05X.Sign(privKeyId, sha256, sha256Len, signature, sizeof(signature), &signatureLen); + + // print the signature + Serial.print("Signature using KeyId "); + Serial.print(privKeyId); + Serial.print(" is: "); + printBufferHex(signature, signatureLen); + + Serial.println(); + + SE05X.importPublicKey(publKeyId, derBuf, derSize); + + // To make the signature verifcation fail, uncomment the next line: + // signature[0] = 0x00; + + // validate the signature + if (SE05X.Verify(publKeyId, sha256, sha256Len, signature, signatureLen)) { + Serial.println("Verified signature successfully :D"); + } else { + Serial.println("oh no! failed to verify signature :("); + } +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XPrivateKey/SE05XPrivateKey.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XPrivateKey/SE05XPrivateKey.ino new file mode 100644 index 00000000..fe845708 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XPrivateKey/SE05XPrivateKey.ino @@ -0,0 +1,42 @@ +/* + SE05X Private Key + + This sketch uses the SE05X to generate a new EC NIST P-256 keypair + and store it with id 999, then the public key is printed in DER format. + + Circuit: + - Portenta + - Nicla Vision +*/ + +#include + +void printBufferHex(const byte input[], size_t inputLength) { + for (int i = 0; i < inputLength; i++) { + Serial.print(input[i] >> 4, HEX); + Serial.print(input[i] & 0x0f, HEX); + } + Serial.println(); +} + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!SE05X.begin()) { + Serial.println("Failed to communicate with SE05X!"); + while (1) + ; + } + + const int KeyId = 999; + byte derBuf[256]; + size_t derSize; + + SE05X.generatePrivateKey(KeyId, derBuf, sizeof(derBuf), &derSize); + printBufferHex(derBuf, derSize); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XRandomNumber/SE05XRandomNumber.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XRandomNumber/SE05XRandomNumber.ino new file mode 100644 index 00000000..49bb366a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XRandomNumber/SE05XRandomNumber.ino @@ -0,0 +1,31 @@ +/* + SE05X Random Number + + This sketch uses the SE05X to generate a random number + every second and print it to the Serial monitor + + Circuit: + - Portenta + - Nicla Vision +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!SE05X.begin()) { + Serial.println("Failed to communicate with SE05X!"); + while (1) + ; + } +} + +void loop() { + Serial.print("Random number = "); + Serial.println(SE05X.random(65535)); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XSignAndVerify/SE05XSignAndVerify.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XSignAndVerify/SE05XSignAndVerify.ino new file mode 100644 index 00000000..33175765 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XSignAndVerify/SE05XSignAndVerify.ino @@ -0,0 +1,83 @@ +/* + SE05X SignAndVerify + + This sketch uses the SE05X to generate a new EC NIST P-256 keypair + and store it with id 999, then input buffer SHA256 is signed with the private + key and verified with the public key. + + Circuit: + - Portenta + - Nicla Vision +*/ + +#include + +const byte input[64] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f +}; + +void printBufferHex(const byte input[], size_t inputLength) { + for (int i = 0; i < inputLength; i++) { + Serial.print(input[i] >> 4, HEX); + Serial.print(input[i] & 0x0f, HEX); + } + Serial.println(); +} + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!SE05X.begin()) { + Serial.println("Failed to communicate with SE05X!"); + while (1) + ; + } + + const int KeyId = 999; + byte derBuf[256]; + size_t derSize; + + SE05X.generatePrivateKey(KeyId, derBuf, sizeof(derBuf), &derSize); + + // print the input + Serial.print("Input is: "); + printBufferHex(input, sizeof(input)); + + //calculate the input SHA256 + byte sha256[256]; + size_t sha256Len; + SE05X.SHA256(input, sizeof(input), sha256, sizeof(sha256), &sha256Len); + Serial.print("Input SHA256 is: "); + printBufferHex(sha256, sha256Len); + + // calculate the signature, input MUST be SHA256 + byte signature[256]; + size_t signatureLen; + SE05X.Sign(KeyId, sha256, sha256Len, signature, sizeof(signature), &signatureLen); + + // print the signature + Serial.print("Signature using KeyId "); + Serial.print(KeyId); + Serial.print(" is: "); + printBufferHex(signature, signatureLen); + + Serial.println(); + + // To make the signature verifcation fail, uncomment the next line: + // signature[0] = 0x00; + + // validate the signature + if (SE05X.Verify(KeyId, sha256, sha256Len, signature, signatureLen)) { + Serial.println("Verified signature successfully :D"); + } else { + Serial.println("oh no! failed to verify signature :("); + } +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFReadPartitions/QSPIFReadPartitions.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFReadPartitions/QSPIFReadPartitions.ino new file mode 100644 index 00000000..b88a3acf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFReadPartitions/QSPIFReadPartitions.ino @@ -0,0 +1,127 @@ +#include + +struct __attribute__((packed)) mbrEntry { + uint8_t status; + uint8_t chsStart[3]; + uint8_t type; + uint8_t chsStop[3]; + uint32_t lbaOffset; + uint32_t lbaSize; +}; + +struct __attribute__((packed)) mbrTable { + mbrEntry entries[4]; + uint8_t signature[2]; +}; + +using namespace mbed; + +unsigned long allocatedSpace{}; + +void setup() { + Serial.begin(115200); + for (const auto timeout = millis() + 2500; !Serial && millis() < timeout; delay(250)) + ; + + auto bd = BlockDevice::get_default_instance(); + auto ret = bd->init(); + if (ret) { + Serial.println("ERROR! Unable to read the Block Device."); + while (true) + ; + } + + // Allocate smallest buffer necessary to write MBR + auto buffer_size = std::max(bd->get_program_size(), sizeof(mbrTable)); + + // Prevent alignment issues + if (buffer_size % bd->get_program_size() != 0) { + buffer_size += bd->get_program_size() - (buffer_size % bd->get_program_size()); + } + + auto buffer = new uint8_t[buffer_size]; + + // Check for existing MBR + ret = bd->read(buffer, 512 - buffer_size, buffer_size); + if (ret) { + Serial.println("ERROR! Unable to read the Master Boot Record"); + + delete[] buffer; + while (true) + ; + } + + auto table_start_offset = buffer_size - sizeof(mbrTable); + auto table = reinterpret_cast(&buffer[table_start_offset]); + + Serial.println(); + Serial.print("Looking for Partitions on the Flash Memory... "); + + if (table->signature[0] != 0x55 || table->signature[1] != 0xAA) { + Serial.println("MBR Not Found"); + Serial.println("Flash Memory doesn't have partitions."); + } else { + + Serial.println("MBR Found"); + Serial.print("Boot Signature: 0x"); + Serial.print(table->signature[0], HEX); + Serial.println(table->signature[1], HEX); + + Serial.println(); + Serial.println("Printing Partitions Table and Info..."); + + auto part{ 1u }; + for (auto const& entry : table->entries) { + Serial.println("================================"); + Serial.print("Partition: "); + Serial.println(part++); + + Serial.print("Bootable: "); + Serial.println(entry.status == 0 ? "No" : "Yes"); + + Serial.print("Type: 0x"); + if (entry.type < 0x10) + Serial.print(0); + Serial.println(entry.type, HEX); + + if (entry.type == 0x00) + continue; + + Serial.print("Size [KBytes]: "); + Serial.println((entry.lbaSize * 4096) >> 10); + + allocatedSpace += entry.lbaSize * 4096; + + Serial.print("Start [C/H/S]: "); + Serial.print(entry.chsStart[0]); + Serial.print("/"); + Serial.print(entry.chsStart[1]); + Serial.print("/"); + Serial.println(entry.chsStart[2]); + + Serial.print("Stop [C/H/S]: "); + Serial.print(entry.chsStop[0]); + Serial.print("/"); + Serial.print(entry.chsStop[1]); + Serial.print("/"); + Serial.println(entry.chsStop[2]); + + Serial.println(); + } + + Serial.println(); + Serial.println("No more partitions are present."); + } + + Serial.println(); + Serial.print("Total Space [KBytes]: "); + Serial.println(bd->size() >> 10); + Serial.print("Allocated Space [KBytes]: "); + Serial.println(allocatedSpace >> 10); + Serial.print("Unallocated Space [KBytes]: "); + Serial.println((bd->size() - allocatedSpace) >> 10); +} + +void loop() { + delay(10000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino new file mode 100644 index 00000000..0456a77f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -0,0 +1,109 @@ +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "LittleFileSystem.h" +#include "FATFileSystem.h" + +#ifndef CORE_CM7 +#error Format QSPI flash by uploading the sketch to the M7 core instead of the M4 core. +#endif + + +QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); +mbed::MBRBlockDevice wifi_data(&root, 1); +mbed::MBRBlockDevice ota_data(&root, 2); +mbed::MBRBlockDevice user_data(&root, 3); +mbed::FATFileSystem wifi_data_fs("wlan"); +mbed::FATFileSystem ota_data_fs("fs"); +mbed::FileSystem* user_data_fs; + +bool waitResponse() { + bool confirmation = false; + while (confirmation == false) { + if (Serial.available()) { + char choice = Serial.read(); + switch (choice) { + case 'y': + case 'Y': + confirmation = true; + return true; + break; + case 'n': + case 'N': + confirmation = true; + return false; + break; + default: + continue; + } + } + } +} + +void setup() { + + Serial.begin(115200); + while (!Serial) + ; + + Serial.println("Available partition schemes:"); + Serial.println("\nPartition scheme 1"); + Serial.println("Partition 1: WiFi firmware and certificates 1MB"); + Serial.println("Partition 2: OTA and user data 13MB"); + Serial.println("\nPartition scheme 2"); + Serial.println("Partition 1: WiFi firmware and certificates 1MB"); + Serial.println("Partition 2: OTA 5MB"); + Serial.println("Partition 3: User data 8MB"), + Serial.println("\nDo you want to use partition scheme 1? Y/[n]"); + Serial.println("If No, partition scheme 2 will be used."); + bool default_scheme = waitResponse(); + + Serial.println("\nWARNING! Running the sketch all the content of the QSPI flash will be erased."); + Serial.println("Do you want to proceed? Y/[n]"); + + if (true == waitResponse()) { + mbed::MBRBlockDevice::partition(&root, 1, 0x0B, 0, 1024 * 1024); + if (default_scheme) { + mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 14 * 1024 * 1024, 14 * 1024 * 1024); + mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1024 * 1024, 14 * 1024 * 1024); + // use space from 15.5MB to 16 MB for another fw, memory mapped + } else { + mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1024 * 1024, 6 * 1024 * 1024); + mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 6 * 1024 * 1024, 14 * 1024 * 1024); + // use space from 15.5MB to 16 MB for another fw, memory mapped + } + + int err = wifi_data_fs.reformat(&wifi_data); + if (err) { + Serial.println("Error formatting WiFi partition"); + } + + err = ota_data_fs.reformat(&ota_data); + if (err) { + Serial.println("Error formatting OTA partition"); + } + + if (!default_scheme) { + Serial.println("\nDo you want to use LittleFS to format user data partition? Y/[n]"); + Serial.println("If No, FatFS will be used to format user partition."); + + if (true == waitResponse()) { + Serial.println("Formatting user partition with LittleFS."); + user_data_fs = new mbed::LittleFileSystem("user"); + } else { + Serial.println("Formatting user partition with FatFS."); + user_data_fs = new mbed::FATFileSystem("user"); + } + + err = user_data_fs->reformat(&user_data); + if (err) { + Serial.println("Error formatting user partition"); + } + } + Serial.println("\nQSPI Flash formatted!"); + } + + Serial.println("It's now safe to reboot or disconnect your board."); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_getBootloaderInfo/STM32H747_getBootloaderInfo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_getBootloaderInfo/STM32H747_getBootloaderInfo.ino new file mode 100644 index 00000000..8ab547b7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_getBootloaderInfo/STM32H747_getBootloaderInfo.ino @@ -0,0 +1,61 @@ +uint8_t* bootloader_data = (uint8_t*)(0x801F000); +uint8_t* bootloader_identification = (uint8_t*)(0x80002F0); + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + uint8_t currentBootloaderVersion = bootloader_data[1]; + String currentBootloaderIdentifier = String(bootloader_identification, 15); + + if (!currentBootloaderIdentifier.equals("MCUboot Arduino")) { + currentBootloaderIdentifier = "Arduino loader"; + } + + Serial.println(currentBootloaderIdentifier); + Serial.println("Magic Number (validation): " + String(bootloader_data[0], HEX)); + Serial.println("Bootloader version: " + String(bootloader_data[1])); + Serial.println("Clock source: " + getClockSource(bootloader_data[2])); + Serial.println("USB Speed: " + getUSBSpeed(bootloader_data[3])); + Serial.println("Has Ethernet: " + String(bootloader_data[4] == 1 ? "Yes" : "No")); + Serial.println("Has WiFi module: " + String(bootloader_data[5] == 1 ? "Yes" : "No")); + Serial.println("RAM size: " + getRAMSize(bootloader_data[6])); + Serial.println("QSPI size: " + String(bootloader_data[7]) + " MB"); + Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No")); + Serial.println("Has Crypto chip: " + String(bootloader_data[9] == 1 ? "Yes" : "No")); +} + +String getUSBSpeed(uint8_t flag) { + switch (flag) { + case 1: + return "USB 2.0/Hi-Speed (480 Mbps)"; + case 2: + return "USB 1.1/Full-Speed (12 Mbps)"; + default: + return "N/A"; + } +} + +String getClockSource(uint8_t flag) { + switch (flag) { + case 0x8: + return "External oscillator"; + case 0x4: + return "External crystal"; + case 0x2: + return "Internal clock"; + default: + return "N/A"; + } +} + +String getRAMSize(uint8_t flag) { + if (flag == 0) { + return "N/A"; + } + return (String(flag) + "MB"); +} + +void loop() { + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino new file mode 100644 index 00000000..5a48bd70 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino @@ -0,0 +1,325 @@ +#include "FlashIAP.h" +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "LittleFileSystem.h" +#include "FATFileSystem.h" +#if defined(ARDUINO_PORTENTA_H7_M7) +#include "portenta_bootloader.h" +#include "portenta_lite_bootloader.h" +#include "portenta_lite_connected_bootloader.h" +#include "mcuboot_bootloader.h" +#include "ecdsa-p256-encrypt-key.h" +#include "ecdsa-p256-signing-key.h" +#elif defined(ARDUINO_NICLA_VISION) +#include "nicla_vision_bootloader.h" +#endif + +#ifndef CORE_CM7 +#error Update the bootloader by uploading the sketch to the M7 core instead of the M4 core. +#endif + +#define BOOTLOADER_ADDR (0x8000000) +#define SIGNING_KEY_ADDR (0x8000300) +#define ENCRYPT_KEY_ADDR (0x8000400) +#define ENCRYPT_KEY_SIZE (0x0000100) +#define SIGNING_KEY_SIZE (0x0000100) + +mbed::FlashIAP flash; +QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); + +bool writeLoader = false; +bool writeKeys = false; +bool video_available = false; +bool wifi_available = false; +bool MCUboot = false; + +uint32_t bootloader_data_offset = 0x1F000; +uint8_t* bootloader_data = (uint8_t*)(BOOTLOADER_ADDR + bootloader_data_offset); + +uint32_t bootloader_identification_offset = 0x2F0; +uint8_t* bootloader_identification = (uint8_t*)(BOOTLOADER_ADDR + bootloader_identification_offset); + +const unsigned char* bootloader_ptr = &bootloader_mbed_bin[0]; +long bootloader_len = bootloader_mbed_bin_len; + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + uint8_t currentBootloaderVersion = bootloader_data[1]; + String currentBootloaderIdentifier = String(bootloader_identification, 15); + + if (!currentBootloaderIdentifier.equals("MCUboot Arduino")) { + currentBootloaderIdentifier = "Arduino loader"; + } + + Serial.println(currentBootloaderIdentifier); + Serial.println("Magic Number (validation): " + String(bootloader_data[0], HEX)); + Serial.println("Bootloader version: " + String(currentBootloaderVersion)); + Serial.println("Clock source: " + getClockSource(bootloader_data[2])); + Serial.println("USB Speed: " + getUSBSpeed(bootloader_data[3])); + Serial.println("Has Ethernet: " + String(bootloader_data[4] == 1 ? "Yes" : "No")); + Serial.println("Has WiFi module: " + String(bootloader_data[5] == 1 ? "Yes" : "No")); + Serial.println("RAM size: " + getRAMSize(bootloader_data[6])); + Serial.println("QSPI size: " + String(bootloader_data[7]) + " MB"); + Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No")); + Serial.println("Has Crypto chip: " + String(bootloader_data[9] == 1 ? "Yes" : "No")); + + video_available = bootloader_data[8]; + wifi_available = bootloader_data[5]; + +#if defined(ARDUINO_PORTENTA_H7_M7) + Serial.println("\nDo you want to install/update the default Arduino bootloader? Y/[n]"); + Serial.println("Choosing \"No\", will install/update the MCUboot bootloader."); + if (!waitResponse()) { + Serial.println("\nMCUboot has been selected. Do you want to proceed? Y/[n]"); + if (waitResponse()) { + MCUboot = true; + bootloader_ptr = &mcuboot_bin[0]; + bootloader_len = mcuboot_bin_len; + } else { + Serial.println("\nProceeding with the default Arduino bootloader..."); + } + } + if (!MCUboot) { + bootloader_ptr = &bootloader_mbed_bin[0]; + bootloader_len = bootloader_mbed_bin_len; + if (!video_available) { + if (wifi_available) { + bootloader_ptr = &bootloader_mbed_lite_connected_bin[0]; + bootloader_len = bootloader_mbed_lite_connected_bin_len; + } else { + bootloader_ptr = &bootloader_mbed_lite_bin[0]; + bootloader_len = bootloader_mbed_lite_bin_len; + } + } + } +#endif + + uint8_t availableBootloaderVersion = (bootloader_ptr + bootloader_data_offset)[1]; + String availableBootloaderIdentifier = String(bootloader_ptr + bootloader_identification_offset, 15); + + if (!availableBootloaderIdentifier.equals("MCUboot Arduino")) { + availableBootloaderIdentifier = "Arduino loader"; + } + + if (currentBootloaderIdentifier == availableBootloaderIdentifier) { + if (bootloader_data[0] != 0xA0) { + Serial.println("\nA new bootloader version (v" + String(availableBootloaderVersion) + ") is available."); + Serial.println("Do you want to update the bootloader? Y/[n]"); + } else { + if (availableBootloaderVersion > currentBootloaderVersion) { + Serial.print("\nA new bootloader version is available: v" + String(availableBootloaderVersion)); + Serial.println(" (Your version: v" + String(currentBootloaderVersion) + ")"); + Serial.println("Do you want to update the bootloader? Y/[n]"); + } else if (availableBootloaderVersion < currentBootloaderVersion) { + Serial.println("\nA newer bootloader version is already installed: v" + String(currentBootloaderVersion)); + Serial.println("Do you want to downgrade the bootloader to v" + String(availableBootloaderVersion) + "? Y/[n]"); + } else { + Serial.println("\nThe latest version of the bootloader is already installed (v" + String(currentBootloaderVersion) + ")."); + Serial.println("Do you want to update the bootloader anyway? Y/[n]"); + } + } + } else { + Serial.println("\nA different bootloader type is available: v" + String(availableBootloaderVersion)); + Serial.println("Do you want to update the bootloader? Y/[n]"); + } + writeLoader = waitResponse(); + + if (writeLoader) { + if (availableBootloaderIdentifier.equals("MCUboot Arduino")) { + setupMCUBootOTAData(); + + Serial.println("\nThe bootloader comes with a set of default keys to evaluate signing and encryption process"); + Serial.println("If you load the keys, you will need to upload the future sketches with Security Settings -> Signing + Encryption."); + Serial.println("If you select Security Settings -> None, the sketches will not be executed."); + Serial.println("Do you want to load the keys? Y/[n]"); + if (waitResponse()) { + Serial.println("\nPlease notice that loading the keys will enable MCUboot Sketch swap. This will increase the sketch update time after the upload."); + Serial.println("A violet LED will blink until the sketch is ready to run."); + Serial.println("Do you want to proceed loading the default keys? Y/[n]"); + } + writeKeys = waitResponse(); + } + applyUpdate(BOOTLOADER_ADDR); + } else { + Serial.println("It's now safe to reboot or disconnect your board."); + } +} + +String getUSBSpeed(uint8_t flag) { + switch (flag) { + case 1: + return "USB 2.0/Hi-Speed (480 Mbps)"; + case 2: + return "USB 1.1/Full-Speed (12 Mbps)"; + default: + return "N/A"; + } +} + +String getClockSource(uint8_t flag) { + switch (flag) { + case 0x8: + return "External oscillator"; + case 0x4: + return "External crystal"; + case 0x2: + return "Internal clock"; + default: + return "N/A"; + } +} + +String getRAMSize(uint8_t flag) { + if (flag == 0) { + return "N/A"; + } + return (String(flag) + "MB"); +} + +void printProgress(uint32_t offset, uint32_t size, uint32_t threshold, bool reset) { + static int percent_done = 0; + if (reset == true) { + percent_done = 0; + Serial.println("Flashed " + String(percent_done) + "%"); + } else { + uint32_t percent_done_new = offset * 100 / size; + if (percent_done_new >= percent_done + threshold) { + percent_done = percent_done_new; + Serial.println("Flashed " + String(percent_done) + "%"); + } + } +} + +bool waitResponse() { + bool confirmation = false; + while (confirmation == false) { + if (Serial.available()) { + char choice = Serial.read(); + switch (choice) { + case 'y': + case 'Y': + confirmation = true; + return true; + break; + case 'n': + case 'N': + confirmation = true; + return false; + break; + default: + continue; + } + } + } +} + +void setupMCUBootOTAData() { + mbed::MBRBlockDevice ota_data(&root, 2); + mbed::FATFileSystem ota_data_fs("fs"); + + int err = ota_data_fs.reformat(&ota_data); + if (err) { + Serial.println("Error creating MCUboot files in OTA partition."); + Serial.println("Run QSPIformat.ino sketch to format the QSPI flash and fix the issue."); + } + + FILE* fp = fopen("/fs/scratch.bin", "wb"); + const int scratch_file_size = 128 * 1024; + const char buffer[128] = { 0xFF }; + int size = 0; + + Serial.println("\nCreating scratch file"); + printProgress(size, scratch_file_size, 10, true); + while (size < scratch_file_size) { + int ret = fwrite(buffer, sizeof(buffer), 1, fp); + if (ret != 1) { + Serial.println("Error writing scratch file"); + break; + } + size += sizeof(buffer); + printProgress(size, scratch_file_size, 10, false); + } + fclose(fp); + + fp = fopen("/fs/update.bin", "wb"); + const int update_file_size = 15 * 128 * 1024; + size = 0; + + Serial.println("\nCreating update file"); + printProgress(size, update_file_size, 10, true); + while (size < update_file_size) { + int ret = fwrite(buffer, sizeof(buffer), 1, fp); + if (ret != 1) { + Serial.println("Error writing scratch file"); + break; + } + size += sizeof(buffer); + printProgress(size, update_file_size, 5, false); + } + + fclose(fp); +} + +void applyUpdate(uint32_t address) { + long len = bootloader_len; + + flash.init(); + + const uint32_t page_size = flash.get_page_size(); + char* page_buffer = new char[page_size]; + uint32_t addr = address; + uint32_t next_sector = addr + flash.get_sector_size(addr); + bool sector_erased = false; + size_t pages_flashed = 0; + uint32_t percent_done = 0; + + while (true) { + + if (page_size * pages_flashed > len) { + break; + } + + // Erase this page if it hasn't been erased + if (!sector_erased) { + flash.erase(addr, flash.get_sector_size(addr)); + sector_erased = true; + } + + // Program page + flash.program(&bootloader_ptr[page_size * pages_flashed], addr, page_size); + + addr += page_size; + if (addr >= next_sector) { + next_sector = addr + flash.get_sector_size(addr); + sector_erased = false; + } + + if (++pages_flashed % 3 == 0) { + uint32_t percent_done_new = page_size * pages_flashed * 100 / len; + if (percent_done != percent_done_new) { + percent_done = percent_done_new; + Serial.println("Flashed " + String(percent_done) + "%"); + } + } + } + +#if defined(ARDUINO_PORTENTA_H7_M7) + if (writeKeys) { + flash.program(&enc_priv_key, ENCRYPT_KEY_ADDR, ENCRYPT_KEY_SIZE); + flash.program(&ecdsa_pub_key, SIGNING_KEY_ADDR, SIGNING_KEY_SIZE); + } +#endif + + Serial.println("Flashed 100%"); + + delete[] page_buffer; + + flash.deinit(); + Serial.println("\nBootloader update complete. It's now safe to reboot or disconnect your board."); +} + +void loop() { + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-encrypt-key.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-encrypt-key.h new file mode 100644 index 00000000..7a83d569 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-encrypt-key.h @@ -0,0 +1,141 @@ +const unsigned char enc_priv_key[]{ + 0x30, + 0x81, + 0x87, + 0x02, + 0x01, + 0x00, + 0x30, + 0x13, + 0x06, + 0x07, + 0x2a, + 0x86, + 0x48, + 0xce, + 0x3d, + 0x02, + 0x01, + 0x06, + 0x08, + 0x2a, + 0x86, + 0x48, + 0xce, + 0x3d, + 0x03, + 0x01, + 0x07, + 0x04, + 0x6d, + 0x30, + 0x6b, + 0x02, + 0x01, + 0x01, + 0x04, + 0x20, + 0x79, + 0x72, + 0xb6, + 0xf3, + 0x62, + 0x91, + 0x09, + 0xbb, + 0x35, + 0x22, + 0xb8, + 0x54, + 0x32, + 0x3b, + 0xfe, + 0x1c, + 0x9f, + 0xa7, + 0x10, + 0x6f, + 0xba, + 0xaf, + 0x73, + 0x64, + 0xd3, + 0xf5, + 0x31, + 0xbc, + 0x28, + 0xe7, + 0xc9, + 0x72, + 0xa1, + 0x44, + 0x03, + 0x42, + 0x00, + 0x04, + 0x6a, + 0xc9, + 0x20, + 0x4c, + 0x96, + 0xd6, + 0x89, + 0xe8, + 0xd1, + 0x6e, + 0x51, + 0x04, + 0x02, + 0x86, + 0xe8, + 0x95, + 0x0b, + 0x22, + 0xc4, + 0xc9, + 0x95, + 0x06, + 0x4f, + 0xf5, + 0x1b, + 0xf6, + 0xd0, + 0xe3, + 0x83, + 0xd9, + 0xd1, + 0x81, + 0x66, + 0x6e, + 0xf2, + 0x07, + 0x3b, + 0x03, + 0xdb, + 0xe4, + 0xd1, + 0xde, + 0x7c, + 0x43, + 0x70, + 0x8d, + 0xa2, + 0x89, + 0xeb, + 0x1b, + 0xfa, + 0xbe, + 0x02, + 0x5e, + 0x5c, + 0xa0, + 0x12, + 0xdc, + 0x23, + 0x31, + 0xc1, + 0xe0, + 0x37, + 0xb0, +}; +const unsigned int enc_priv_key_len = 138; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-signing-key.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-signing-key.h new file mode 100644 index 00000000..0b3c66db --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-signing-key.h @@ -0,0 +1,94 @@ +const unsigned char ecdsa_pub_key[]{ + 0x30, + 0x59, + 0x30, + 0x13, + 0x06, + 0x07, + 0x2a, + 0x86, + 0x48, + 0xce, + 0x3d, + 0x02, + 0x01, + 0x06, + 0x08, + 0x2a, + 0x86, + 0x48, + 0xce, + 0x3d, + 0x03, + 0x01, + 0x07, + 0x03, + 0x42, + 0x00, + 0x04, + 0xd5, + 0x16, + 0x35, + 0x26, + 0xc3, + 0x3b, + 0xad, + 0x4d, + 0x67, + 0x8e, + 0x43, + 0x24, + 0xc4, + 0x98, + 0xe9, + 0x6b, + 0x2e, + 0xbe, + 0x0d, + 0xa3, + 0xf1, + 0xf4, + 0x97, + 0x80, + 0x7b, + 0x31, + 0x32, + 0x07, + 0xd9, + 0x95, + 0xa7, + 0x17, + 0x57, + 0x69, + 0x43, + 0x7b, + 0xe9, + 0xc8, + 0xaa, + 0xd0, + 0x0a, + 0x0c, + 0x86, + 0x0b, + 0xe3, + 0x7f, + 0x99, + 0x88, + 0x51, + 0xc4, + 0xf9, + 0x22, + 0x98, + 0xbe, + 0x5e, + 0xaa, + 0xfd, + 0x90, + 0x3c, + 0xa2, + 0x74, + 0x18, + 0x49, + 0x05, +}; +const unsigned int ecdsa_pub_key_len = 91; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/WiFiFirmwareUpdater/WiFiFirmwareUpdater.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/WiFiFirmwareUpdater/WiFiFirmwareUpdater.ino new file mode 100644 index 00000000..0c8f3556 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/WiFiFirmwareUpdater/WiFiFirmwareUpdater.ino @@ -0,0 +1,159 @@ +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "FATFileSystem.h" +#include "wiced_resource.h" +#include "certificates.h" + +#ifndef CORE_CM7 +#error Update the WiFi firmware by uploading the sketch to the M7 core instead of the M4 core. +#endif + +QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); +mbed::MBRBlockDevice wifi_data(&root, 1); +mbed::FATFileSystem wifi_data_fs("wlan"); + +long getFileSize(FILE *fp) { + fseek(fp, 0, SEEK_END); + int size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + return size; +} + +void printProgress(uint32_t offset, uint32_t size, uint32_t threshold, bool reset) { + static int percent_done = 0; + if (reset == true) { + percent_done = 0; + Serial.println("Flashed " + String(percent_done) + "%"); + } else { + uint32_t percent_done_new = offset * 100 / size; + if (percent_done_new >= percent_done + threshold) { + percent_done = percent_done_new; + Serial.println("Flashed " + String(percent_done) + "%"); + } + } +} + +void setup() { + + Serial.begin(115200); + while (!Serial) + ; + + mbed::MBRBlockDevice::partition(&root, 1, 0x0B, 0, 1024 * 1024); + // use space from 15.5MB to 16 MB for another fw, memory mapped + + int err = wifi_data_fs.mount(&wifi_data); + if (err) { + // Reformat if we can't mount the filesystem + // this should only happen on the first boot + Serial.println("No filesystem containing the WiFi firmware was found."); + Serial.println("Usually that means that the WiFi firmware has not been installed yet" + " or was overwritten with another firmware.\n"); + Serial.println("Formatting the filsystem to install the firmware and certificates...\n"); + err = wifi_data_fs.reformat(&wifi_data); + } + + DIR *dir; + struct dirent *ent; + + if ((dir = opendir("/wlan")) != NULL) { + /* print all the files and directories within directory */ + while ((ent = readdir(dir)) != NULL) { + Serial.println("Searching for WiFi firmware file " + String(ent->d_name) + " ..."); + String fullname = "/wlan/" + String(ent->d_name); + if (fullname == "/wlan/4343WA1.BIN") { + Serial.println("A WiFi firmware is already installed. " + "Do you want to install the firmware anyway? Y/[n]"); + while (1) { + if (Serial.available()) { + int c = Serial.read(); + if (c == 'Y' || c == 'y') { + wifi_data_fs.reformat(&wifi_data); + break; + } + if (c == 'N' || c == 'n') { + return; + } + } + } + } + } + closedir(dir); + } + + extern const unsigned char wifi_firmware_image_data[]; + extern const resource_hnd_t wifi_firmware_image; + FILE *fp = fopen("/wlan/4343WA1.BIN", "wb"); + const int file_size = 421098; + int chunck_size = 1024; + int byte_count = 0; + + Serial.println("Flashing /wlan/4343WA1.BIN file"); + printProgress(byte_count, file_size, 10, true); + while (byte_count < file_size) { + if (byte_count + chunck_size > file_size) + chunck_size = file_size - byte_count; + int ret = fwrite(&wifi_firmware_image_data[byte_count], chunck_size, 1, fp); + if (ret != 1) { + Serial.println("Error writing firmware data"); + break; + } + byte_count += chunck_size; + printProgress(byte_count, file_size, 10, false); + } + fclose(fp); + + chunck_size = 1024; + byte_count = 0; + const uint32_t offset = 15 * 1024 * 1024 + 1024 * 512; + + Serial.println("Flashing memory mapped firmware"); + printProgress(byte_count, file_size, 10, true); + while (byte_count < file_size) { + if (byte_count + chunck_size > file_size) + chunck_size = file_size - byte_count; + int ret = root.program(wifi_firmware_image_data, offset + byte_count, chunck_size); + if (ret != 0) { + Serial.println("Error writing firmware data"); + break; + } + byte_count += chunck_size; + printProgress(byte_count, file_size, 10, false); + } + + chunck_size = 128; + byte_count = 0; + fp = fopen("/wlan/cacert.pem", "wb"); + + Serial.println("Flashing certificates"); + printProgress(byte_count, cacert_pem_len, 10, true); + while (byte_count < cacert_pem_len) { + if (byte_count + chunck_size > cacert_pem_len) + chunck_size = cacert_pem_len - byte_count; + int ret = fwrite(&cacert_pem[byte_count], chunck_size, 1, fp); + if (ret != 1) { + Serial.println("Error writing certificates"); + break; + } + byte_count += chunck_size; + printProgress(byte_count, cacert_pem_len, 10, false); + } + fclose(fp); + + fp = fopen("/wlan/cacert.pem", "rb"); + char buffer[128]; + int ret = fread(buffer, 1, 128, fp); + Serial.write(buffer, ret); + while (ret == 128) { + ret = fread(buffer, 1, 128, fp); + Serial.write(buffer, ret); + } + fclose(fp); + + Serial.println("\nFirmware and certificates updated!"); + Serial.println("It's now safe to reboot or disconnect your board."); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/README.adoc new file mode 100644 index 00000000..aef62e82 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/README.adoc @@ -0,0 +1,22 @@ += Scheduler Library for Arduino = + +The Scheduler library enables the Arduino Due to run multiple functions at the same time. This allows tasks to happen without interrupting each other. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/Scheduler + +== License == + +Copyright (c) 2012 The Android Open Source Project. All right reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino new file mode 100644 index 00000000..a1ebd86e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino @@ -0,0 +1,109 @@ +/* + Multiple Blinks + + Demonstrates the use of the Scheduler library for the boards: + + - Arduino Nano 33 BLE, or + - Arduino Portenta H7, or + - Arduino Nano RP2040 Connect + + Hardware required : + * None (LEDs are already conencted to RGB LED) + + ATTENTION: LEDs polarity is reversed (so loop3 will turn the LED off by writing 1) + + created 8 Oct 2012 + by Cristian Maglie + Modified by + Scott Fitzgerald 19 Oct 2012 + + This example code is in the public domain + + http://www.arduino.cc/en/Tutorial/MultipleBlinks +*/ + +// Include Scheduler since we want to manage multiple tasks. +#include + +// On Nano RP2040 Connect, RGB leds are connected to the wifi module +// The user APIs are the same, but we can't convert to int, so use defines +#if defined(ARDUINO_NANO_RP2040_CONNECT) + +#include "WiFiNINA.h" +#define led1 LEDR +#define led2 LEDG +#define led3 LEDB + +// On Nicla Sense ME, RGB leds are connected via an I2C module +// The user APIs are the same, but we can't convert to int, so use defines +#elif defined(ARDUINO_NICLA) + +#include "Nicla_System.h" +#define led1 LEDR +#define led2 LEDG +#define led3 LEDB + +#else + +int led1 = LEDR; +int led2 = LEDG; +int led3 = LEDB; + +#endif + +void setup() { + Serial.begin(9600); + + // Setup the 3 pins as OUTPUT + pinMode(led1, OUTPUT); + pinMode(led2, OUTPUT); + pinMode(led3, OUTPUT); + + // Add "loop2" and "loop3" to scheduling. + // "loop" is always started by default. + Scheduler.startLoop(loop2); + Scheduler.startLoop(loop3); +} + +// Task no.1: blink LED with 1 second delay. +void loop() { + digitalWrite(led1, HIGH); + + // IMPORTANT: + // When multiple tasks are running 'delay' passes control to + // other tasks while waiting and guarantees they get executed. + delay(1000); + + digitalWrite(led1, LOW); + delay(1000); +} + +// Task no.2: blink LED with 0.1 second delay. +void loop2() { + digitalWrite(led2, HIGH); + delay(100); + digitalWrite(led2, LOW); + delay(100); +} + +// Task no.3: accept commands from Serial port +// '0' turns off LED +// '1' turns on LED +void loop3() { + if (Serial.available()) { + char c = Serial.read(); + if (c == '0') { + digitalWrite(led3, LOW); + Serial.println("Led turned off!"); + } + if (c == '1') { + digitalWrite(led3, HIGH); + Serial.println("Led turned on!"); + } + } + + // IMPORTANT: + // We must call 'yield' at a regular basis to pass + // control to other tasks. + yield(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/ThreadDebug/examples/ThreadDebug/ThreadDebug.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/ThreadDebug/examples/ThreadDebug/ThreadDebug.ino new file mode 100644 index 00000000..16fd5989 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/ThreadDebug/examples/ThreadDebug/ThreadDebug.ino @@ -0,0 +1,25 @@ +/* This example demonstrates how to include the ThreadMRI library which allows debugging of the Portenta H7 and Nano 33 BLE [Sense] + with GDB via a serial interface. + + To connect to the target, launch gdb with the following parameters + + arm-none-eabi-gdb -ex "set pagination off" --baud {230400} -ex "set target-charset ASCII" -ex "target remote {debug.port}" {project_name}.elf + + The baud rate needs to match the one provided in UartDebugCommInterface constructor, while {debug.port} depends on the operating system (eg. /dev/ttyUSB0 or COM15). + + If UsbDebugCommInterface is being used you can specify any baudrate. +*/ + +#include + +//UartDebugCommInterface debugComm(SERIAL1_TX, SERIAL1_RX, 230400); +//ThreadDebug threadDebug(&debugComm, DEBUG_BREAK_IN_SETUP); + +UsbDebugCommInterface debugComm(&SerialUSB); +ThreadDebug threadDebug(&debugComm, DEBUG_BREAK_IN_SETUP); + +void setup() { +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Keyboard/Keyboard.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Keyboard/Keyboard.ino new file mode 100644 index 00000000..ce6876a5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Keyboard/Keyboard.ino @@ -0,0 +1,14 @@ +#include "PluggableUSBHID.h" +#include "USBKeyboard.h" + +USBKeyboard Keyboard; + +void setup() { + // put your setup code here, to run once: +} + +void loop() { + // put your main code here, to run repeatedly: + delay(1000); + Keyboard.printf("Hello world\n\r"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Mouse/Mouse.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Mouse/Mouse.ino new file mode 100644 index 00000000..64e8299d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Mouse/Mouse.ino @@ -0,0 +1,16 @@ +#include "PluggableUSBHID.h" +#include "USBMouse.h" + +USBMouse Mouse; + +void setup() { + // put your setup code here, to run once: +} + +void loop() { + // put your main code here, to run repeatedly: + delay(1000); + Mouse.move(100, 100); + delay(1000); + Mouse.move(-100, -100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/KeyboardController/KeyboardController.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/KeyboardController/KeyboardController.ino new file mode 100644 index 00000000..37775869 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/KeyboardController/KeyboardController.ino @@ -0,0 +1,159 @@ +/* + _______ _ _ _____ ____ + |__ __| | | | |/ ____| _ \ + | | ___ ___ _ __ _ _| | | | (___ | |_) | + | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < + | | __/ __/ | | | |_| | |__| |____) | |_) | + |_|\___|\___|_| |_|\__, |\____/|_____/|____/ + __/ | + |___/ + + TeenyUSB - light weight usb stack for STM32 micro controllers + + Copyright (c) 2019 XToolBox - admin@xtoolbox.org + www.tusb.org + + 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. +*/ + +#include "USBHost.h" + +USBHost usb; + +static int process_key(tusbh_ep_info_t* ep, const uint8_t* key); + +static const tusbh_boot_key_class_t cls_boot_key = { + .backend = &tusbh_boot_keyboard_backend, + //.on_key = process_key +}; + +static const tusbh_boot_mouse_class_t cls_boot_mouse = { + .backend = &tusbh_boot_mouse_backend, + // .on_mouse = process_mouse +}; + +static const tusbh_hid_class_t cls_hid = { + .backend = &tusbh_hid_backend, + //.on_recv_data = process_hid_recv, + //.on_send_done = process_hid_sent, +}; + +static const tusbh_hub_class_t cls_hub = { + .backend = &tusbh_hub_backend, +}; + +static const tusbh_vendor_class_t cls_vendor = { + .backend = &tusbh_vendor_backend, + //.transfer_done = process_vendor_xfer_done +}; + +int msc_ff_mount(tusbh_interface_t* interface, int max_lun, const tusbh_block_info_t* blocks); +int msc_ff_unmount(tusbh_interface_t* interface); + +static const tusbh_msc_class_t cls_msc_bot = { + .backend = &tusbh_msc_bot_backend, + // .mount = msc_ff_mount, + // .unmount = msc_ff_unmount, +}; + +static const tusbh_cdc_acm_class_t cls_cdc_acm = { + .backend = &tusbh_cdc_acm_backend, +}; + +static const tusbh_cdc_rndis_class_t cls_cdc_rndis = { + .backend = &tusbh_cdc_rndis_backend, +}; + +static const tusbh_class_reg_t class_table[] = { + (tusbh_class_reg_t)&cls_boot_key, + (tusbh_class_reg_t)&cls_boot_mouse, + (tusbh_class_reg_t)&cls_hub, + (tusbh_class_reg_t)&cls_msc_bot, + (tusbh_class_reg_t)&cls_cdc_acm, + (tusbh_class_reg_t)&cls_cdc_rndis, + (tusbh_class_reg_t)&cls_hid, + (tusbh_class_reg_t)&cls_vendor, + 0, +}; + +void setup() { + Serial1.begin(115200); + usb.Init(USB_CORE_ID_HS, class_table); + //usb.Init(USB_CORE_ID_FS, class_table); +} + +void loop() { + //usb.Task(); +} + +#define MOD_CTRL (0x01 | 0x10) +#define MOD_SHIFT (0x02 | 0x20) +#define MOD_ALT (0x04 | 0x40) +#define MOD_WIN (0x08 | 0x80) + +#define LED_NUM_LOCK 1 +#define LED_CAPS_LOCK 2 +#define LED_SCROLL_LOCK 4 + +#define stdin_recvchar Serial1.write + +static uint8_t key_leds; +static const char knum[] = "1234567890"; +static const char ksign[] = "!@#$%^&*()"; +static const char tabA[] = "\t -=[]\\#;'`,./"; +static const char tabB[] = "\t _+{}|~:\"~<>?"; +// route the key event to stdin +static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) { + printf("\n"); + uint8_t modify = keys[0]; + uint8_t key = keys[2]; + uint8_t last_leds = key_leds; + if (key >= KEY_A && key <= KEY_Z) { + char ch = 'A' + key - KEY_A; + if ((!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK))) { + ch += 'a' - 'A'; + } + stdin_recvchar(ch); + } else if (key >= KEY_1 && key <= KEY_0) { + if (modify & MOD_SHIFT) { + stdin_recvchar(ksign[key - KEY_1]); + } else { + stdin_recvchar(knum[key - KEY_1]); + } + } else if (key >= KEY_TAB && key <= KEY_SLASH) { + if (modify & MOD_SHIFT) { + stdin_recvchar(tabB[key - KEY_TAB]); + } else { + stdin_recvchar(tabA[key - KEY_TAB]); + } + } else if (key == KEY_ENTER) { + stdin_recvchar('\r'); + } else if (key == KEY_CAPSLOCK) { + key_leds ^= LED_CAPS_LOCK; + } else if (key == KEY_NUMLOCK) { + key_leds ^= LED_NUM_LOCK; + } else if (key == KEY_SCROLLLOCK) { + key_leds ^= LED_SCROLL_LOCK; + } + + if (key_leds != last_leds) { + tusbh_set_keyboard_led(ep, key_leds); + } + return 0; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/Shell.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/Shell.ino new file mode 100644 index 00000000..00ad3432 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/Shell.ino @@ -0,0 +1,457 @@ +/* + _______ _ _ _____ ____ + |__ __| | | | |/ ____| _ \ + | | ___ ___ _ __ _ _| | | | (___ | |_) | + | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < + | | __/ __/ | | | |_| | |__| |____) | |_) | + |_|\___|\___|_| |_|\__, |\____/|_____/|____/ + __/ | + |___/ + + TeenyUSB - light weight usb stack for STM32 micro controllers + + Copyright (c) 2019 XToolBox - admin@xtoolbox.org + www.tusb.org + + 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. +*/ + +#include "USBHost.h" +#include "USB251xB.h" + +extern "C" { +#include "teeny_usb.h" +#include "class/host/tusbh.h" +#include "class/host/tusbh_vendor.h" +#include "class/host/tusbh_hub.h" +#include "class/host/tusbh_hid.h" +#include "class/host/tusbh_msc.h" +#include "class/host/tusbh_cdc_acm.h" +#include "class/host/tusbh_cdc_rndis.h" +#include "string.h" +#include "class/host/usb_key_code.h" +} + +#include "mbed.h" + +#define TEENYUSB_LOGO \ + " _______ _ _ _____ ____ \n" \ + "|__ __| | | | |/ ____| _ \\ \n" \ + " | | ___ ___ _ __ _ _| | | | (___ | |_) |\n" \ + " | |/ _ \\/ _ \\ '_ \\| | | | | | |\\___ \\| _ < \n" \ + " | | __/ __/ | | | |_| | |__| |____) | |_) |\n" \ + " |_|\\___|\\___|_| |_|\\__, |\\____/|_____/|____/ \n" \ + " __/ | \n" \ + " |___/ \n" + + +static int process_key(tusbh_ep_info_t* ep, const uint8_t* key); + +static tusbh_root_hub_t root_fs; +static tusbh_root_hub_t root_hs; +static const tusbh_boot_key_class_t cls_boot_key = { + .backend = &tusbh_boot_keyboard_backend, + //.on_key = process_key +}; + +static const tusbh_boot_mouse_class_t cls_boot_mouse = { + .backend = &tusbh_boot_mouse_backend, + // .on_mouse = process_mouse +}; + +static const tusbh_hid_class_t cls_hid = { + .backend = &tusbh_hid_backend, + //.on_recv_data = process_hid_recv, + //.on_send_done = process_hid_sent, +}; + +static const tusbh_hub_class_t cls_hub = { + .backend = &tusbh_hub_backend, +}; + +static const tusbh_vendor_class_t cls_vendor = { + .backend = &tusbh_vendor_backend, + //.transfer_done = process_vendor_xfer_done +}; + +int msc_ff_mount(tusbh_interface_t* interface, int max_lun, const tusbh_block_info_t* blocks); +int msc_ff_unmount(tusbh_interface_t* interface); + +static const tusbh_msc_class_t cls_msc_bot = { + .backend = &tusbh_msc_bot_backend, + // .mount = msc_ff_mount, + // .unmount = msc_ff_unmount, +}; + +static const tusbh_cdc_acm_class_t cls_cdc_acm = { + .backend = &tusbh_cdc_acm_backend, +}; + +static const tusbh_cdc_rndis_class_t cls_cdc_rndis = { + .backend = &tusbh_cdc_rndis_backend, +}; + +static const tusbh_class_reg_t class_table[] = { + (tusbh_class_reg_t)&cls_boot_key, + (tusbh_class_reg_t)&cls_boot_mouse, + (tusbh_class_reg_t)&cls_hub, + (tusbh_class_reg_t)&cls_msc_bot, + (tusbh_class_reg_t)&cls_cdc_acm, + (tusbh_class_reg_t)&cls_cdc_rndis, + (tusbh_class_reg_t)&cls_hid, + (tusbh_class_reg_t)&cls_vendor, + 0, +}; + + +static tusb_host_t* fs; +static tusb_host_t* hs; + +void show_memory(char* argv[], int argc); +void cmd_lsusb(char* argv[], int argc) { + if (fs) ls_usb(fs); + if (hs) ls_usb(hs); +} + +void cmd_ls(char* argv[], int argc); +void cmd_mkdir(char* argv[], int argc); +void cmd_mv(char* argv[], int argc); +void cmd_cat(char* argv[], int argc); +void cmd_cp(char* argv[], int argc); +void cmd_rm(char* argv[], int argc); +void cmd_append(char* argv[], int argc); + +static tusbh_interface_t* find_cdc(tusbh_device_t* dev) { + if (!dev) return 0; + for (int i = 0; i < dev->interface_num; i++) { + tusbh_interface_t* itf = &dev->interfaces[i]; + if (itf->cls == (tusbh_class_reg_t)&cls_cdc_acm) { + return itf; + } + } + for (int i = 0; i < TUSBH_MAX_CHILD; i++) { + tusbh_device_t* child = dev->children[i]; + if (child) { + return find_cdc(child); + } + } + return 0; +} + +__ALIGN_BEGIN static uint8_t test_cdc_data[64] __ALIGN_END = { + 0x00, + 0x01, + 0x02, + 0x03, + 0x04, + 0x05, + 0x06, + 0x07, + 0x08, + 0x09, + 0x0a, + 0x0b, + 0x0c, + 0x0d, + 0x0e, + 0x0f, + 0x10, + 0x11, + 0x12, + 0x13, + 0x14, + 0x15, + 0x16, + 0x17, + 0x18, + 0x19, + 0x1a, + 0x1b, + 0x1c, + 0x1d, + 0x1e, + 0x1f, +}; + + +void cmd_cdc_test(char* argv[], int argc) { + tusbh_interface_t* cdc = 0; + if (fs) { + cdc = find_cdc(((tusbh_root_hub_t*)fs->user_data)->children[0]); + } + + if (!cdc && hs) { + cdc = find_cdc(((tusbh_root_hub_t*)hs->user_data)->children[0]); + } + + if (!cdc) { + printf("No CDC interface attached\n"); + } + + int r = tusbh_cdc_send_data(cdc, test_cdc_data, 32, 2000); + printf("Send data result = %d\n", r); + if (r < 0) return; + r = tusbh_cdc_recv_data(cdc, test_cdc_data + 32, 32, 2000); + printf("Recv data result = %d\n", r); + for (int i = 0; i < r; i++) { + printf("%02x ", test_cdc_data[32 + i]); + } + printf("\n"); +} + + +typedef struct _cli { + const char* cmd; + const char* desc; + void (*action)(char* argv[], int argc); +} cli_t; + + + +const cli_t commands[] = { + { "lsusb", "list usb devices", cmd_lsusb }, + { "testcdc", "testcdc test cdc loopback interface", cmd_cdc_test }, +}; + +static void process_command(char* cmd) { +#define MAX_ARGC 8 + char* argv[MAX_ARGC]; + for (int i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) { + const cli_t* c = &commands[i]; + if (strstr(cmd, c->cmd) == cmd && c->action) { + int argc = 1; + argv[0] = cmd; + while (*cmd) { + if (*cmd == ' ') { + while (*cmd && *cmd == ' ') { + *cmd = 0; + cmd++; + } + if (*cmd) { + if (argc < MAX_ARGC) { + argv[argc] = cmd; + argc++; + } + cmd++; + } + } else { + cmd++; + } + } + c->action(argv, argc); + return; + } + } + printf("Unkown command: %s\n", cmd); +} + +#define PROMPT "TeenyUSB > " + +static char cmd_buf[256]; +static int cmd_len; +static void command_loop(void) { + if (Serial1.available()) { + int ch = Serial1.read(); + if (ch == '\r') { + cmd_buf[cmd_len] = 0; + if (cmd_buf[0]) { + process_command(cmd_buf); + } + cmd_len = 0; + printf(PROMPT); + } else if (ch == '\t') { + printf("\n"); + for (int i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) { + const cli_t* c = &commands[i]; + printf("%-10s - %s\n", c->cmd, c->desc ? c->desc : ""); + } + printf(PROMPT); + cmd_len = 0; + } else { + if (cmd_len < sizeof(cmd_buf) - 1) { + cmd_buf[cmd_len] = ch; + cmd_len++; + } + } + } +} + +#include "usb_phy_api.h" +#include "Wire.h" + +tusbh_msg_q_t* mq; + +void setup() { + Serial1.begin(115200); + printf("\n" TEENYUSB_LOGO PROMPT); + + //get_usb_phy()->deinit(); + + mq = tusbh_mq_create(); + tusbh_mq_init(mq); + +#if defined(USB_CORE_ID_FS) + fs = tusb_get_host(USB_CORE_ID_FS); + HOST_PORT_POWER_ON_FS(); + root_fs.mq = mq; + root_fs.id = "FS"; + root_fs.support_classes = class_table; + tusb_host_init(fs, &root_fs); + tusb_open_host(fs); +#else + (void)root_fs; + fs = 0; +#endif + +#if defined(USB_CORE_ID_HS) + hs = tusb_get_host(USB_CORE_ID_HS); + HOST_PORT_POWER_ON_HS(); + root_hs.mq = mq; + root_hs.id = "HS"; + root_hs.support_classes = class_table; + tusb_host_init(hs, &root_hs); + tusb_open_host(hs); +#else + (void)root_hs; + hs = 0; +#endif + + start_hub(); + + //usb_fakeirq.start(mbed::callback(usb_irq_thread)); + + //NVIC_DisableIRQ(OTG_HS_IRQn); + + cmd_len = 0; +} + +bool once = true; + +void loop() { + if (millis() > 5000 && once) { + //cmd_lsusb(NULL, 0); + once = false; + } + //command_loop(); + + // there is only one message q for every thing + tusbh_msg_loop(mq); +} + +#define MOD_CTRL (0x01 | 0x10) +#define MOD_SHIFT (0x02 | 0x20) +#define MOD_ALT (0x04 | 0x40) +#define MOD_WIN (0x08 | 0x80) + +#define LED_NUM_LOCK 1 +#define LED_CAPS_LOCK 2 +#define LED_SCROLL_LOCK 4 + +#define stdin_recvchar Serial1.write + +static uint8_t key_leds; +static const char knum[] = "1234567890"; +static const char ksign[] = "!@#$%^&*()"; +static const char tabA[] = "\t -=[]\\#;'`,./"; +static const char tabB[] = "\t _+{}|~:\"~<>?"; +// route the key event to stdin +static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) { + printf("\n"); + uint8_t modify = keys[0]; + uint8_t key = keys[2]; + uint8_t last_leds = key_leds; + if (key >= KEY_A && key <= KEY_Z) { + char ch = 'A' + key - KEY_A; + if ((!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK))) { + ch += 'a' - 'A'; + } + stdin_recvchar(ch); + } else if (key >= KEY_1 && key <= KEY_0) { + if (modify & MOD_SHIFT) { + stdin_recvchar(ksign[key - KEY_1]); + } else { + stdin_recvchar(knum[key - KEY_1]); + } + } else if (key >= KEY_TAB && key <= KEY_SLASH) { + if (modify & MOD_SHIFT) { + stdin_recvchar(tabB[key - KEY_TAB]); + } else { + stdin_recvchar(tabA[key - KEY_TAB]); + } + } else if (key == KEY_ENTER) { + stdin_recvchar('\r'); + } else if (key == KEY_CAPSLOCK) { + key_leds ^= LED_CAPS_LOCK; + } else if (key == KEY_NUMLOCK) { + key_leds ^= LED_NUM_LOCK; + } else if (key == KEY_SCROLLLOCK) { + key_leds ^= LED_SCROLL_LOCK; + } + + if (key_leds != last_leds) { + tusbh_set_keyboard_led(ep, key_leds); + } + return 0; +} + + + +#if 1 + +extern "C" { + +#define LOG_SIZE 1024 + static int hc_log_index; + static channel_state_t hc_log_buf[LOG_SIZE]; + static USB_OTG_HostChannelTypeDef hc_info; + static USB_OTG_HostChannelTypeDef* hc_reg; + static tusb_hc_data_t* hc_data; + static uint8_t hc_no; + void hc_log_begin(tusb_host_t* host, uint8_t hc_num) { + USB_OTG_GlobalTypeDef* USBx = GetUSB(host); + USB_OTG_HostChannelTypeDef* HC = USBx_HC(hc_num); + tusb_hc_data_t* hc = &host->hc[hc_num]; + hc_reg = HC; + hc_data = hc; + hc_no = hc_num; + hc_info.HCCHAR = HC->HCCHAR; + hc_info.HCSPLT = HC->HCSPLT; + hc_info.HCINTMSK = HC->HCINTMSK; + hc_info.HCTSIZ = HC->HCTSIZ; + hc_info.HCDMA = HC->HCDMA; + hc_log_index = 0; + //printf("hc_no %x\n", hc_num); + //printf("hc_info.HCCHAR %x\n", HC->HCCHAR); + //printf("hc_info.HCSPLT %x\n", HC->HCSPLT); + //printf("hc_info.HCINTMSK %x\n", HC->HCINTMSK); + //printf("hc_info.HCTSIZ %x\n", HC->HCTSIZ); + //printf("hc_info.HCDMA %x\n", HC->HCDMA); + } + + void hc_log_data(tusb_host_t* host, uint8_t hc_num, uint32_t data) { + if (hc_log_index < LOG_SIZE) { + hc_log_buf[hc_log_index] = (channel_state_t)data; + hc_log_index++; + } + } + + void hc_log_end(tusb_host_t* host, uint8_t hc_num) { + } +} +#endif diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/readme.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/readme.md new file mode 100644 index 00000000..b49ca901 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/readme.md @@ -0,0 +1,108 @@ +# 无RTOS的主机例程 + +host demo without RTOS + +通过串口进行简单的交互,默认串口配置为115200 N 8 1,当USB口接入键盘时,可以通过USB键盘做为Console的输入,不支持ANSI转义字符输入(即不支持退格键、方向键)。 + +A simple terminal through serial port with default setting "115200 N 8 1". The terminal input could be a USB keyboard. ANSI escape character is not support. + +## 简易命令行 Simple Terminal + +按下Tab键显示支持的命令。 Press Tab to show supported commands. + +``` + _______ _ _ _____ ____ +|__ __| | | | |/ ____| _ \ + | | ___ ___ _ __ _ _| | | | (___ | |_) | + | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < + | | __/ __/ | | | |_| | |__| |____) | |_) | + |_|\___|\___|_| |_|\__, |\____/|_____/|____/ + __/ | + |___/ +TeenyUSB > +lsusb - list usb devices +showmem - show memory usage +ls - ls list dir +mkdir - mkdir create dir +mv - mv move file +cat - cat display file +cp - cp copy file +rm - rm remove file or path +append - append [data data ...] add data to file +TeenyUSB > +``` + +### 显示连接的设备 list attached device +``` +TeenyUSB > lsusb +Device of FS root hub + Device VID:058f PID:9254, Parent: ROOT FS:0 + Interface 0: HUB + Device VID:10c4 PID:ea60, Parent: Dev 01:3 + Interface 0: vendor class +Device of HS root hub + Device VID:0930 PID:6545, Parent: ROOT HS:0 + Interface 0: Mass Storage +TeenyUSB > +``` +### 显示内存使用情况 list memory usage +``` +TeenyUSB > showmem + Memory used 176, max 176 + MQ used 1 + Device used 3 + Event used 3 +TeenyUSB > +``` +### 文件操作 File operation +当连接U盘时文件操作才有效。 Effective when USB mass storage device connected. + +下面是一个mount在[0:]上的U盘例子。 A sample MSC device mount on [0:]. + +通过日志可以看到第一次获取Capacity失败,读取Sense信息后第二次获取成功。 +``` +TeenyUSB > RHUB HS:0 Connect +RHUB HS:0 Enable +DEV HS.00 Allocate pipe, in = 0, out = 1 +DEV HS.01 Re-allocate pipe, in = 0, out = 1 +DEV HS.01 HS device, VID:0930 PID:6545 +ITF HS.01.0-0 MSC lun(0) Kingston - DataTraveler G3 - PMAP +ITF HS.01.0-0 MSC ep 81 stall +ITF HS.01.0-0 MSC stall CSW res = 13, residue 8, status 1 +ITF HS.01.0-0 MSC xfer fail, res = -6, residue 8, status 1 +ITF HS.01.0-0 MSC Sense: SENSE_UNIT_ATTENTION, MEDIUM_HAVE_CHANGED, qua 0 +ITF HS.01.0-0 MSC lun(0) Block Count:7669824 Size:512 +MSC mount [0:] r = 0 +ITF HS.01.0-0 MSC interface init +DEV HS.01 Device has 1 interfaces +``` +使用文件操作U盘中的文件。 +``` +TeenyUSB > ls 0: +0:/T1 +0:/T2 +0:/T3 +0:/SYSTEM~1/WPSETT~1.DAT +0:/SYSTEM~1/INDEXE~1 +TeenyUSB > cat t1 +112233 + +TeenyUSB > cp t1 r1 +TeenyUSB > cat r1 +112233 + +TeenyUSB > mv r1 r2 +TeenyUSB > cat r2 +112233 + +TeenyUSB > append ff test_data +TeenyUSB > cat ff +test_data + +TeenyUSB > append ff 123123123 +TeenyUSB > cat ff +test_data +123123123 + +TeenyUSB > +``` diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/readme.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/readme.md new file mode 100644 index 00000000..9da40f89 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/readme.md @@ -0,0 +1,63 @@ +TeenyUSB Stack +========== + +# 设备接口函数 Device API + +普通函数 Normal function + +| function name | description | +|-------------------|-------------------------------| +|tusb_get_device | Get chip USB device handle | +|tusb_open | Open USB Device, Connect | +|tusb_close | Close USB device, Disconnect | +|tusb_send_data | Send endpoint data | +|tusb_set_rx_buffer | Set OUT endpoint recv buffer | +|tusb_set_rx_valid | Set OUT endpoint valid | + +回调函数,用户实现 Callback function + +| function name | description | +|---------------------------|-------------------------------| +|tusb_reconfig | Config endpoint here | +|tusb_class_request | Class request | +|tusb_on_rx_done | Data received | +|tusb_on_tx_done | Data send finish | +|tusb_get_report_descriptor | Report descriptor request | + +# Host API + +普通函数 Normal function + +| function name | description | +|-----------------------|--------------------------------------| +|tusb_get_host | Get chip USB host handle | +|tusb_open_host | Open USB host | +|tusb_close_host | Close USB host | +|tusb_host_port_reset | Set host port reset state | +|tusb_pipe_open | Open/allocate pipe for data transfer | +|tusb_pipe_close | Close/free pipe | +|tusb_pipe_setup | Transfer setup packet | +|tusb_pipe_xfer_data | Transfer data packet | +|tusb_pipe_wait | Wait/Get pipe transfer state | + +回调函数,用户实现 Callback function + +| function name | description | +|---------------------------|----------------------| +|tusb_host_port_changed | Port state changed | +|tusb_on_channel_event | Changed event | + +# 函数处理流程 + +## USB FS模块 + +![usb_fs_api](../images/usb_fs_api.png) + +## USB OTG模块设备模式 Device + +![otg_device_api](../images/otg_device_api.png) + +## USB OTG模块主机模式 Host + +![otg_host_api](../images/otg_host_api.png) + diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/AccessFlashAsUSBDisk/AccessFlashAsUSBDisk.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/AccessFlashAsUSBDisk/AccessFlashAsUSBDisk.ino new file mode 100644 index 00000000..8af447cf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/AccessFlashAsUSBDisk/AccessFlashAsUSBDisk.ino @@ -0,0 +1,62 @@ +/* + QSPI as USB Mass Storage + This example shows how to expose a QSPIF BlockDevice (16MB external flash on the Portenta H7) + as an USB stick. It can be adapted to any kind of BlockDevice (FlashIAP or either RAM via HeapBlockDevice) + Before loading this example, make sure you execute WiFiFirmwareUpdater sketch + to create and format the proper partitions. +*/ + +#include "PluggableUSBMSD.h" +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "FATFileSystem.h" + +static QSPIFBlockDevice root; +mbed::MBRBlockDevice wifi_data(&root, 1); +mbed::MBRBlockDevice ota_data(&root, 2); +static mbed::FATFileSystem wifi("wifi"); +static mbed::FATFileSystem ota("ota"); + +void USBMSD::begin() { + int err = wifi.mount(&wifi_data); + if (err) { + while (!Serial) + ; + Serial.println("Please run WiFiFirmwareUpdater before"); + return; + } + ota.mount(&ota_data); +} + + +USBMSD MassStorage(&root); + +void setup() { + Serial.begin(115200); + MassStorage.begin(); +} + +void printDirectory(char *name) { + DIR *d; + struct dirent *p; + + d = opendir(name); + if (d != NULL) { + while ((p = readdir(d)) != NULL) { + Serial.println(p->d_name); + } + } + closedir(d); +} + +void loop() { + if (MassStorage.media_removed()) { + // list the content of the partitions + // you may need to restart the board for the list to update if you copied new files + Serial.println("Content of WiFi partition:"); + printDirectory("/wifi"); + Serial.println("Content of OTA partition:"); + printDirectory("/ota"); + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/Nano33BLE_FlashMassStorage/Nano33BLE_FlashMassStorage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/Nano33BLE_FlashMassStorage/Nano33BLE_FlashMassStorage.ino new file mode 100644 index 00000000..ca201e87 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/Nano33BLE_FlashMassStorage/Nano33BLE_FlashMassStorage.ino @@ -0,0 +1,24 @@ +/* + This example exposes the second half (512KB) of Nano 33 BLE flash + as a USB disk. + The user can interact with this disk as a bidirectional communication with the board + For example, the board could save data in a file to be retrieved later with a drag and drop +*/ + +#include "PluggableUSBMSD.h" + +void setup() { + Serial.begin(115200); + MassStorage.begin(); + + // write a file with some data + // a+ means append, so every time the board is rebooted the file will grow by a new line + FILE *f = fopen("/fs/data.txt", "a+"); + String hello = "Hello from Nano33BLE Filesystem\n"; + fwrite(hello.c_str(), hello.length(), 1, f); + fclose(f); +} + +void loop() { + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino new file mode 100644 index 00000000..c0086a81 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino @@ -0,0 +1,110 @@ +/* + Web client + + This sketch connects to a website (http://example.com) using the WiFi module. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the Wifi.begin() call accordingly. + + Circuit: + * Arduino Portenta H7 + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ + +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +// IPAddress server(93,184,216,34); // IP address for example.com (no DNS) +char server[] = "example.com"; // host name for example.com (using DNS) + +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true) + ; + } + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 3 seconds for connection: + delay(3000); + } + Serial.println("Connected to wifi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /index.html HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true) + ; + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/doom/examples/Doom/Doom.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/doom/examples/Doom/Doom.ino new file mode 100644 index 00000000..ff84727e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-mbed/libraries/doom/examples/Doom/Doom.ino @@ -0,0 +1,56 @@ +/* + Arduino wrapper for DoomGeneric + Mouse and keyboard controls are not implemented at the moment. + + To use the internal QSPI flash as storage, run WiFiFirmwareUpdater + sketch once to create the partitions, AccessFlashAsUSBDisk to expose the QSPI flash + as a USB disk, copy DOOM1.WAD in the biggest partition, flash this sketch and you are ready to go :) +*/ + +#include "QSPIFBlockDevice.h" +#include "FATFileSystem.h" +#include "MBRBlockDevice.h" +#include "doomgeneric.h" + +QSPIFBlockDevice block_device; +// Comment previous line and uncomment these two if you want to store DOOM.WAD in an external SD card (FAT32 formatted) +// #include "SDMMCBlockDevice.h" +// SDMMCBlockDevice block_device; + +mbed::MBRBlockDevice fs_data(&block_device, 2); +static mbed::FATFileSystem fs("fs"); + +extern "C" int main_wrapper(int argc, char **argv); +char *argv[] = { "/fs/doom", "-iwad", "/fs/DOOM1.WAD" }; + +void setup() { + int err = fs.mount(&fs_data); + if (err) { + printf("No filesystem found, please run AccessFlashAsUSBDisk sketch and copy DOOM1.WAD in the big partition"); + pinMode(LEDB, OUTPUT); + while (1) { + digitalWrite(LEDB, LOW); + delay(100); + digitalWrite(LEDB, HIGH); + delay(100); + } + } + DIR *dir; + struct dirent *ent; + printf("try to open dir\n"); + if ((dir = opendir("/fs")) != NULL) { + /* print all the files and directories within directory */ + while ((ent = readdir(dir)) != NULL) { + printf("%s\n", ent->d_name); + } + closedir(dir); + } else { + /* could not open directory */ + printf("error\n"); + } + main_wrapper(3, argv); +} + +void loop() { + // put your main code here, to run repeatedly: +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/README.md new file mode 100644 index 00000000..4090cd7e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/README.md @@ -0,0 +1,65 @@ +# Arduino Core for ATMEGA4809 CPU + +[![Compile MuxTO status](https://github.com/arduino/ArduinoCore-megaavr/actions/workflows/compile-muxto.yml/badge.svg)](https://github.com/arduino/ArduinoCore-megaavr/actions/workflows/compile-muxto.yml) + +This repository contains the source code and configuration files of the Arduino Core +for Microchip's ATMEGA4809 processor (used on the Arduino Uno WiFi Rev2 boards). + +## Installation on Arduino IDE + +This core is available as a package in the Arduino IDE cores manager. +Just open the "Boards Manager" and install the package called: + +"Arduino megaAVR Boards" + +## Support + +There is a dedicated section of the Arduino Forum for general discussion and project assistance: + +http://forum.arduino.cc/index.php?board=126.0 + +## Bugs or Issues + +If you find a bug you can submit an issue here on github: + +https://github.com/arduino/ArduinoCore-megaavr/issues + +Before posting a new issue, please check if the same problem has been already reported by someone else +to avoid duplicates. + +## Contributions + +Contributions are always welcome. The preferred way to receive code cotribution is by submitting a +Pull Request on github. + +## Developing + +1. Create an `/hardware/arduino` folder. Where `` is the location of your + Arduino sketchbook. +1. Change directories: `cd /hardware/arduino` +1. Clone this repo: `git clone https://github.com/arduino/ArduinoCore-megaavr.git megaavr` +1. Change directories: `cd megaavr/cores/arduino` +1. Copy or symlink the `api` folder from the [ArduinoCore-API](https://github.com/arduino/ArduinoCore-API) repo. +1. Restart the IDE + +## License and credits + +This core has been developed by Arduino SA in collaboration with Microchip. + +``` + Copyright (c) 2018 Arduino SA. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +``` \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/README.md new file mode 100644 index 00000000..a6241361 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/README.md @@ -0,0 +1,139 @@ +## **EEPROM Library V2.0** for Arduino + +**Written by:** _Christopher Andrews_. + +### **What is the EEPROM library.** + +Th EEPROM library provides an easy to use interface to interact with the internal non-volatile storage found in AVR based Arduino boards. This library will work on many AVR devices like ATtiny and ATmega chips. + +### **How to use it** +The EEPROM library is included in your IDE download. To add its functionality to your sketch you'll need to reference the library header file. You do this by adding an include directive to the top of your sketch. + +```Arduino +#include + +void setup(){ + +} + +void loop(){ + +} + +``` + +The library provides a global variable named `EEPROM`, you use this variable to access the library functions. The methods provided in the EEPROM class are listed below. + +You can view all the examples [here](examples/). + +### **Library functions** + +#### **`EEPROM.read( address )`** [[_example_]](examples/eeprom_read/eeprom_read.ino) + +This function allows you to read a single byte of data from the eeprom. +Its only parameter is an `int` which should be set to the address you wish to read. + +The function returns an `unsigned char` containing the value read. + +#### **`EEPROM.write( address, value )`** [[_example_]](examples/eeprom_write/eeprom_write.ino) + +The `write()` method allows you to write a single byte of data to the EEPROM. +Two parameters are needed. The first is an `int` containing the address that is to be written, and the second is a the data to be written (`unsigned char`). + +This function does not return any value. + +#### **`EEPROM.update( address, value )`** [[_example_]](examples/eeprom_update/eeprom_update.ino) + +This function is similar to `EEPROM.write()` however this method will only write data if the cell contents pointed to by `address` is different to `value`. This method can help prevent unnecessary wear on the EEPROM cells. + +This function does not return any value. + +#### **`EEPROM.get( address, object )`** [[_example_]](examples/eeprom_get/eeprom_get.ino) + +This function will retrieve any object from the EEPROM. +Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to read. + +This function returns a reference to the `object` passed in. It does not need to be used and is only returned for conveience. + +#### **`EEPROM.put( address, object )`** [[_example_]](examples/eeprom_put/eeprom_put.ino) + +This function will write any object to the EEPROM. +Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to write. + +This function uses the _update_ method to write its data, and therefore only rewrites changed cells. + +This function returns a reference to the `object` passed in. It does not need to be used and is only returned for conveience. + +#### **Subscript operator: `EEPROM[address]`** [[_example_]](examples/eeprom_crc/eeprom_crc.ino) + +This operator allows using the identifier `EEPROM` like an array. +EEPROM cells can be read _and_ **_written_** directly using this method. + +This operator returns a reference to the EEPROM cell. + +```c++ +unsigned char val; + +//Read first EEPROM cell. +val = EEPROM[ 0 ]; + +//Write first EEPROM cell. +EEPROM[ 0 ] = val; + +//Compare contents +if( val == EEPROM[ 0 ] ){ + //Do something... +} +``` + +#### **`EEPROM.length()`** + +This function returns an `unsigned int` containing the number of cells in the EEPROM. + +--- + +### **Advanced features** + +This library uses a component based approach to provide its functionality. This means you can also use these components to design a customized approach. Two background classes are available for use: `EERef` & `EEPtr`. + +#### **`EERef` class** + +This object references an EEPROM cell. +Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM. +This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell. + +```C++ +EERef ref = EEPROM[ 10 ]; //Create a reference to 11th cell. + +ref = 4; //write to EEPROM cell. + +unsigned char val = ref; //Read referenced cell. +``` + +#### **`EEPtr` class** + +This object is a bidirectional pointer to EEPROM cells represented by `EERef` objects. +Just like a normal pointer type, this type can be dereferenced and repositioned using +increment/decrement operators. + +```C++ +EEPtr ptr = 10; //Create a pointer to 11th cell. + +*ptr = 4; //dereference and write to EEPROM cell. + +unsigned char val = *ptr; //dereference and read. + +ptr++; //Move to next EEPROM cell. +``` + +#### **`EEPROM.begin()`** + +This function returns an `EEPtr` pointing to the first cell in the EEPROM. +This is useful for STL objects, custom iteration and C++11 style ranged for loops. + +#### **`EEPROM.end()`** + +This function returns an `EEPtr` pointing at the location after the last EEPROM cell. +Used with `begin()` to provide custom iteration. + +**Note:** The `EEPtr` returned is invalid as it is out of range. Infact the hardware causes wrapping of the address (overflow) and `EEPROM.end()` actually references the first EEPROM cell. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino new file mode 100644 index 00000000..5b17db3b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino @@ -0,0 +1,39 @@ +/* + * EEPROM Clear + * + * Sets all of the bytes of the EEPROM to 0. + * Please see eeprom_iteration for a more in depth + * look at how to traverse the EEPROM. + * + * This example code is in the public domain. + */ + +#include + +void setup() { + // initialize the LED pin as an output. + pinMode(13, OUTPUT); + + /*** + Iterate through each byte of the EEPROM storage. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + + for (int i = 0; i < EEPROM.length(); i++) { + EEPROM.write(i, 0); + } + + // turn the LED on when we're done + digitalWrite(13, HIGH); +} + +void loop() { + /** Empty loop. **/ +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino new file mode 100644 index 00000000..893a54dc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino @@ -0,0 +1,52 @@ +/*** + Written by Christopher Andrews. + CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). + + A CRC is a simple way of checking whether data has changed or become corrupted. + This example calculates a CRC value directly on the EEPROM values. + The purpose of this example is to highlight how the EEPROM object can be used just like an array. +***/ + +#include +#include + +void setup() { + + //Start serial + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + //Print length of data to run CRC on. + Serial.print("EEPROM length: "); + Serial.println(EEPROM.length()); + + //Print the result of calling eeprom_crc() + Serial.print("CRC32 of EEPROM data: 0x"); + Serial.println(eeprom_crc(), HEX); + Serial.print("\n\nDone!"); +} + +void loop() { + /* Empty loop */ +} + +unsigned long eeprom_crc(void) { + + const unsigned long crc_table[16] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, + 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, + 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c + }; + + unsigned long crc = ~0L; + + for (int index = 0; index < EEPROM.length(); ++index) { + crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4); + crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4); + crc = ~crc; + } + return crc; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino new file mode 100644 index 00000000..4db5a6db --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino @@ -0,0 +1,68 @@ +/*** + eeprom_get example. + + This shows how to use the EEPROM.get() method. + + To pre-set the EEPROM data, run the example sketch eeprom_put. + This sketch will run without it, however, the values shown + will be shown from what ever is already on the EEPROM. + + This may cause the serial object to print out a large string + of garbage if there is no null character inside one of the strings + loaded. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + float f = 0.00f; //Variable to store data read from EEPROM. + int eeAddress = 0; //EEPROM address to start reading from + + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.print("Read float from EEPROM: "); + + //Get the float data from the EEPROM at position 'eeAddress' + EEPROM.get(eeAddress, f); + Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. + + /*** + As get also returns a reference to 'f', you can use it inline. + E.g: Serial.print( EEPROM.get( eeAddress, f ) ); + ***/ + + /*** + Get can be used with custom structures too. + I have separated this into an extra function. + ***/ + + secondTest(); //Run the next test. +} + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +void secondTest() { + int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. + + MyObject customVar; //Variable to store custom object read from EEPROM. + EEPROM.get(eeAddress, customVar); + + Serial.println("Read custom object from EEPROM: "); + Serial.println(customVar.field1); + Serial.println(customVar.field2); + Serial.println(customVar.name); +} + +void loop() { + /* Empty loop */ +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino new file mode 100644 index 00000000..8f48c1d9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -0,0 +1,57 @@ +/*** + eeprom_iteration example. + + A set of example snippets highlighting the + simplest methods for traversing the EEPROM. + + Running this sketch is not necessary, this is + simply highlighting certain programming methods. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + /*** + Iterate the EEPROM using a for loop. + ***/ + + for (int index = 0; index < EEPROM.length(); index++) { + + //Add one to each cell in the EEPROM + EEPROM[index] += 1; + } + + /*** + Iterate the EEPROM using a while loop. + ***/ + + int index = 0; + + while (index < EEPROM.length()) { + + //Add one to each cell in the EEPROM + EEPROM[index] += 1; + index++; + } + + /*** + Iterate the EEPROM using a do-while loop. + ***/ + + int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. + + do { + + //Add one to each cell in the EEPROM + EEPROM[idx] += 1; + idx++; + } while (idx < EEPROM.length()); + + +} //End of setup function. + +void loop() {} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino new file mode 100644 index 00000000..434468ba --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino @@ -0,0 +1,58 @@ +/*** + eeprom_put example. + + This shows how to use the EEPROM.put() method. + Also, this sketch will pre-set the EEPROM data for the + example sketch eeprom_get. + + Note, unlike the single byte version EEPROM.write(), + the put method will use update semantics. As in a byte + will only be written to the EEPROM if the data is actually + different. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +void setup() { + + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + float f = 123.456f; //Variable to store in EEPROM. + int eeAddress = 0; //Location we want the data to be put. + + + //One simple call, with the address first and the object second. + EEPROM.put(eeAddress, f); + + Serial.println("Written float data type!"); + + /** Put is designed for use with custom structures also. **/ + + //Data to store. + MyObject customVar = { + 3.14f, + 65, + "Working!" + }; + + eeAddress += sizeof(float); //Move address to the next byte after float 'f'. + + EEPROM.put(eeAddress, customVar); + Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); +} + +void loop() { + /* Empty loop */ +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino new file mode 100644 index 00000000..27d2299f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @@ -0,0 +1,56 @@ +/* + * EEPROM Read + * + * Reads the value of each byte of the EEPROM and prints it + * to the computer. + * This example code is in the public domain. + */ + +#include + +// start reading from the first byte (address 0) of the EEPROM +int address = 0; +byte value; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } +} + +void loop() { + // read a byte from the current address of the EEPROM + value = EEPROM.read(address); + + Serial.print(address); + Serial.print("\t"); + Serial.print(value, DEC); + Serial.println(); + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + address = address + 1; + if (address == EEPROM.length()) { + address = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++address &= EEPROM.length() - 1; + ***/ + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino new file mode 100644 index 00000000..5e3db5b4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino @@ -0,0 +1,71 @@ +/*** + EEPROM Update method + + Stores values read from analog input 0 into the EEPROM. + These values will stay in the EEPROM when the board is + turned off and may be retrieved later by another sketch. + + If a value has not changed in the EEPROM, it is not overwritten + which would reduce the life span of the EEPROM unnecessarily. + + Released using MIT licence. + ***/ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int address = 0; + +void setup() { + /** EMpty setup **/ +} + +void loop() { + /*** + need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + int val = analogRead(0) / 4; + + /*** + Update the particular EEPROM cell. + these values will remain there when the board is + turned off. + ***/ + EEPROM.update(address, val); + + /*** + The function EEPROM.update(address, val) is equivalent to the following: + + if( EEPROM.read(address) != val ){ + EEPROM.write(address, val); + } + ***/ + + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + address = address + 1; + if (address == EEPROM.length()) { + address = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++address &= EEPROM.length() - 1; + ***/ + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino new file mode 100644 index 00000000..f9bea641 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino @@ -0,0 +1,60 @@ +/* + * EEPROM Write + * + * Stores values read from analog input 0 into the EEPROM. + * These values will stay in the EEPROM when the board is + * turned off and may be retrieved later by another sketch. + */ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int addr = 0; + +void setup() { + /** Empty setup. **/ +} + +void loop() { + /*** + Need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + + int val = analogRead(0) / 4; + + /*** + Write the value to the appropriate byte of the EEPROM. + these values will remain there when the board is + turned off. + ***/ + + EEPROM.write(addr, val); + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + addr = addr + 1; + if (addr == EEPROM.length()) { + addr = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++addr &= EEPROM.length() - 1; + ***/ + + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino new file mode 100644 index 00000000..7254403a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -0,0 +1,142 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + */ + +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initalize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 00000000..6dd5e492 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -0,0 +1,72 @@ +/* + Digital Pot Control + + This example controls an Analog Devices AD5206 digital potentiometer. + The AD5206 has 6 potentiometer channels. Each channel's pins are labeled + A - connect this to voltage + W - this is the pot's wiper, which changes when you set it + B - connect this to ground. + + The AD5206 is SPI-compatible,and to command it, you send two bytes, + one with the channel number (0 - 5) and one with the resistance value for the + channel (0 - 255). + + The circuit: + * All A pins of AD5206 connected to +5V + * All B pins of AD5206 connected to ground + * An LED and a 220-ohm resisor in series connected from each W pin to ground + * CS - to digital pin 10 (SS pin) + * SDI - to digital pin 11 (MOSI pin) + * CLK - to digital pin 13 (SCK pin) + + created 10 Aug 2010 + by Tom Igoe + + Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 + +*/ + + +// inslude the SPI library: +#include + + +// set pin 10 as the slave select for the digital pot: +const int slaveSelectPin = 10; + +void setup() { + // set the slaveSelectPin as an output: + pinMode(slaveSelectPin, OUTPUT); + // initialize SPI: + SPI.begin(); +} + +void loop() { + // go through the six channels of the digital pot: + for (int channel = 0; channel < 6; channel++) { + // change the resistance on this channel from min to max: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, level); + delay(10); + } + // wait a second at the top: + delay(100); + // change the resistance on this channel from max to min: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, 255 - level); + delay(10); + } + } +} + +void digitalPotWrite(int address, int value) { + // take the SS pin low to select the chip: + digitalWrite(slaveSelectPin, LOW); + delay(100); + // send in the address and value via SPI: + SPI.transfer(address); + SPI.transfer(value); + delay(100); + // take the SS pin high to de-select the chip: + digitalWrite(slaveSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino new file mode 100644 index 00000000..e2865244 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -0,0 +1,54 @@ +/* + Software serial multple serial test + + Receives from the hardware serial, sends to software serial. + Receives from software serial, sends to hardware serial. + + The circuit: + * RX is digital pin 10 (connect to TX of other device) + * TX is digital pin 11 (connect to RX of other device) + + Note: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: + 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + + Not all pins on the Leonardo and Micro support change interrupts, + so only the following can be used for RX: + 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). + + created back in the mists of time + modified 25 May 2012 + by Tom Igoe + based on Mikal Hart's example + + This example code is in the public domain. + + */ +#include + +SoftwareSerial mySerial(10, 11); // RX, TX + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(57600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + Serial.println("Goodnight moon!"); + + // set the data rate for the SoftwareSerial port + mySerial.begin(4800); + mySerial.println("Hello, world?"); +} + +void loop() { // run over and over + if (mySerial.available()) { + Serial.write(mySerial.read()); + } + if (Serial.available()) { + mySerial.write(Serial.read()); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino new file mode 100644 index 00000000..90be53cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -0,0 +1,85 @@ +/* + Software serial multple serial test + + Receives from the two software serial ports, + sends to the hardware serial port. + + In order to listen on a software port, you call port.listen(). + When using two software serial ports, you have to switch ports + by listen()ing on each one in turn. Pick a logical time to switch + ports, like the end of an expected transmission, or when the + buffer is empty. This example switches ports when there is nothing + more to read from a port + + The circuit: + Two devices which communicate serially are needed. + * First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX) + * Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX) + + Note: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: + 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + + Not all pins on the Leonardo support change interrupts, + so only the following can be used for RX: + 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). + + created 18 Apr. 2011 + modified 19 March 2016 + by Tom Igoe + based on Mikal Hart's twoPortRXExample + + This example code is in the public domain. + + */ + +#include +// software serial #1: RX = digital pin 10, TX = digital pin 11 +SoftwareSerial portOne(10, 11); + +// software serial #2: RX = digital pin 8, TX = digital pin 9 +// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega +SoftwareSerial portTwo(8, 9); + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + // Start each software serial port + portOne.begin(9600); + portTwo.begin(9600); +} + +void loop() { + // By default, the last intialized port is listening. + // when you want to listen on a port, explicitly select it: + portOne.listen(); + Serial.println("Data from port one:"); + // while there is data coming in, read it + // and send to the hardware serial port: + while (portOne.available() > 0) { + char inByte = portOne.read(); + Serial.write(inByte); + } + + // blank line to separate data from the two ports: + Serial.println(); + + // Now listen on the second port + portTwo.listen(); + // while there is data coming in, read it + // and send to the hardware serial port: + Serial.println("Data from port two:"); + while (portTwo.available() > 0) { + char inByte = portTwo.read(); + Serial.write(inByte); + } + + // blank line to separate data from the two ports: + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino new file mode 100644 index 00000000..795df980 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -0,0 +1,84 @@ +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// by Nicholas Zambetti +// and James Tichenor + +// Demonstrates use of the Wire library reading data from the +// Devantech Utrasonic Rangers SFR08 and SFR10 + +// Created 29 April 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial communication at 9600bps +} + +int reading = 0; + +void loop() { + // step 1: instruct sensor to read echoes + Wire.beginTransmission(112); // transmit to device #112 (0x70) + // the address specified in the datasheet is 224 (0xE0) + // but i2c adressing uses the high 7 bits so it's 112 + Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) + Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds + Wire.endTransmission(); // stop transmitting + + // step 2: wait for readings to happen + delay(70); // datasheet suggests at least 65 milliseconds + + // step 3: instruct sensor to return a particular echo reading + Wire.beginTransmission(112); // transmit to device #112 + Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + + // step 4: request reading from sensor + Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 + + // step 5: receive reading from sensor + if (2 <= Wire.available()) { // if two bytes were received + reading = Wire.read(); // receive high byte (overwrites previous reading) + reading = reading << 8; // shift high byte to be high 8 bits + reading |= Wire.read(); // receive low byte as lower 8 bits + Serial.println(reading); // print the reading + } + + delay(250); // wait a bit since people have to read the output :) +} + + +/* + +// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) +// usage: changeAddress(0x70, 0xE6); + +void changeAddress(byte oldAddress, byte newAddress) +{ + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA0)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xAA)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA5)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(newAddress); + Wire.endTransmission(); +} + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino new file mode 100644 index 00000000..803d0fa1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -0,0 +1,33 @@ +// I2C Digital Potentiometer +// by Nicholas Zambetti +// and Shawn Bonkowski + +// Demonstrates use of the Wire library +// Controls AD5171 digital potentiometer via I2C/TWI + +// Created 31 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) +} + +byte val = 0; + +void loop() { + Wire.beginTransmission(44); // transmit to device #44 (0x2c) + // device address is specified in datasheet + Wire.write(byte(0x00)); // sends instruction byte + Wire.write(val); // sends potentiometer value byte + Wire.endTransmission(); // stop transmitting + + val++; // increment value + if (val == 64) { // if reached 64th position (max) + val = 0; // start over from lowest value + } + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_reader/master_reader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_reader/master_reader.ino new file mode 100644 index 00000000..5b5351eb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_reader/master_reader.ino @@ -0,0 +1,29 @@ +// Wire Master Reader +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Reads data from an I2C/TWI slave device +// Refer to the "Wire Slave Sender" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() { + Wire.requestFrom(8, 6); // request 6 bytes from slave device #8 + + while (Wire.available()) { // slave may send less than requested + char c = Wire.read(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_writer/master_writer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_writer/master_writer.ino new file mode 100644 index 00000000..2639d41d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_writer/master_writer.ino @@ -0,0 +1,29 @@ +// Wire Master Writer +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Writes data to an I2C/TWI slave device +// Refer to the "Wire Slave Receiver" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) +} + +byte x = 0; + +void loop() { + Wire.beginTransmission(8); // transmit to device #8 + Wire.write("x is "); // sends five bytes + Wire.write(x); // sends one byte + Wire.endTransmission(); // stop transmitting + + x++; + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_receiver/slave_receiver.ino new file mode 100644 index 00000000..b28aa581 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -0,0 +1,34 @@ +// Wire Slave Receiver +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI slave device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(8); // join i2c bus with address #8 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() { + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) { + while (1 < Wire.available()) { // loop through all but the last + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_sender/slave_sender.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_sender/slave_sender.ino new file mode 100644 index 00000000..b7b2c0b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -0,0 +1,29 @@ +// Wire Slave Sender +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Sends data as an I2C/TWI slave device +// Refer to the "Wire Master Reader" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(8); // join i2c bus with address #8 + Wire.onRequest(requestEvent); // register event +} + +void loop() { + delay(100); +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() { + Wire.write("hello "); // respond with message of 6 bytes + // as expected by master +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/LICENSE new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/README.md new file mode 100644 index 00000000..b8bcac19 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/README.md @@ -0,0 +1,71 @@ +# Arduino Core for SAMD21 CPU + +This repository contains the source code and configuration files of the Arduino Core +for Atmel's SAMD21 processor (used on the Arduino/Genuino Zero, MKR1000 and MKRZero boards). + +## Installation on Arduino IDE + +This core is available as a package in the Arduino IDE cores manager. +Just open the "Boards Manager" and install the package called: + +"Arduino SAMD Boards (32-bit ARM Cortex-M0+)" + +## Support + +There is a dedicated section of the Arduino Forum for general discussion and project assistance: + +http://forum.arduino.cc/index.php?board=98.0 + +## Bugs or Issues + +If you find a bug you can submit an issue here on github: + +https://github.com/arduino/ArduinoCore-samd/issues + +Before posting a new issue, please check if the same problem has been already reported by someone else +to avoid duplicates. + +## Contributions + +Contributions are always welcome. The preferred way to receive code contribution is by submitting a +Pull Request on github. + +## Hourly builds + +This repository is under a Continuous Integration system that every hour checks if there are updates and +builds a release for testing (the so called "Hourly builds"). + +The hourly builds are available through Boards Manager. If you want to install them: + 1. Open the **Preferences** of the Arduino IDE. + 2. Add this URL `http://downloads.arduino.cc/Hourly/samd/package_samd-hourly-build_index.json` in the **Additional Boards Manager URLs** field, and click OK. + 3. Open the **Boards Manager** (menu Tools->Board->Board Manager...) + 4. Install **Arduino SAMD core - Hourly build** + 5. Select one of the boards under **SAMD Hourly build XX** in Tools->Board menu + 6. Compile/Upload as usual + +If you already installed an hourly build and you want to update it with the latest: + 1. Open the **Boards Manager** (menu Tools->Board->Board Manager...) + 2. Remove **Arduino SAMD core - Hourly build** + 3. Install again **Arduino SAMD core - Hourly build**, the Board Manager will download the latest build replacing the old one. + +## License and credits + +This core has been developed by Arduino LLC in collaboration with Atmel. + +``` + Copyright (c) 2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +``` diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino new file mode 100644 index 00000000..7448f6a8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino @@ -0,0 +1,47 @@ +/* + This example reads audio data from an Invensense's ICS43432 I2S microphone + breakout board, and prints out the samples to the Serial console. The + Serial Plotter built into the Arduino IDE can be used to plot the audio + data (Tools -> Serial Plotter) + + Circuit: + * Arduino/Genuino Zero, MKR family and Nano 33 IoT + * ICS43432: + * GND connected GND + * 3.3V connected to 3.3V (Zero, Nano) or VCC (MKR) + * WS connected to pin 0 (Zero) or 3 (MKR) or A2 (Nano) + * CLK connected to pin 1 (Zero) or 2 (MKR) or A3 (Nano) + * SD connected to pin 9 (Zero) or A6 (MKR) or 4 (Nano) + + created 17 November 2016 + by Sandeep Mistry + */ + +#include + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start I2S at 8 kHz with 32-bits per sample + if (!I2S.begin(I2S_PHILIPS_MODE, 8000, 32)) { + Serial.println("Failed to initialize I2S!"); + while (1) + ; // do nothing + } +} + +void loop() { + // read a sample + int sample = I2S.read(); + + if (sample) { + // if it's non-zero print value to serial + Serial.println(sample); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/SimpleTone/SimpleTone.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/SimpleTone/SimpleTone.ino new file mode 100644 index 00000000..b42eef2a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/SimpleTone/SimpleTone.ino @@ -0,0 +1,54 @@ +/* + This example generates a square wave based tone at a specified frequency + and sample rate. Then outputs the data using the I2S interface to a + MAX08357 I2S Amp Breakout board. + + Circuit: + * Arduino/Genuino Zero, MKR family and Nano 33 IoT + * MAX08357: + * GND connected GND + * VIN connected 5V + * LRC connected to pin 0 (Zero) or 3 (MKR) or A2 (Nano) + * BCLK connected to pin 1 (Zero) or 2 (MKR) or A3 (Nano) + * DIN connected to pin 9 (Zero) or A6 (MKR) or 4 (Nano) + + created 17 November 2016 + by Sandeep Mistry + */ + +#include + +const int frequency = 440; // frequency of square wave in Hz +const int amplitude = 500; // amplitude of square wave +const int sampleRate = 8000; // sample rate in Hz + +const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave + +short sample = amplitude; // current sample value +int count = 0; + +void setup() { + Serial.begin(9600); + Serial.println("I2S simple tone"); + + // start I2S at the sample rate with 16-bits per sample + if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16)) { + Serial.println("Failed to initialize I2S!"); + while (1) + ; // do nothing + } +} + +void loop() { + if (count % halfWavelength == 0) { + // invert the sample every half wavelength count multiple to generate square wave + sample = -1 * sample; + } + + // write the same sample twice, once for left and once for the right channel + I2S.write(sample); + I2S.write(sample); + + // increment the counter for the next sample + count++; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SAMD_AnalogCorrection/examples/CorrectADCResponse/CorrectADCResponse.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SAMD_AnalogCorrection/examples/CorrectADCResponse/CorrectADCResponse.ino new file mode 100644 index 00000000..0ed52972 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SAMD_AnalogCorrection/examples/CorrectADCResponse/CorrectADCResponse.ino @@ -0,0 +1,196 @@ +/* + This sketch easily and quickly finds the right ADC correction values for a particular Arduino ZERO board. + The correction values that are found are only valid for the board where the sketch is executed. + + This example code is in the public domain. + + Written 6 May 2015 by Claudio Indellicati +*/ + +/* + How to use this sketch + + 1) Remove any connection cable, shield or jumper from your Arduino ZERO + 2) Connect pin A1 to the nearest GND pin using the shortest jumper possible + 3) Connect pin A2 to the 3.3V pin using the shortest jumper possible + 4) Connect the Arduino ZERO to your PC using a USB cable plugged in the USB programming port of the board + 5) Upload this sketch and leave the board powered on for at least one minute + 6) Open the Serial Monitor and press the reset button on the Arduino ZERO + 7) At the and of the procedure you can find logged + - the offset and gain values for the board where the sketch has been just executed + - the code to copy/paste in sketches using this library +*/ + +#include "SAMD_AnalogCorrection.h" + +#define ADC_GND_PIN A1 +#define ADC_3V3_PIN A2 + +#define ADC_READS_SHIFT 8 +#define ADC_READS_COUNT (1 << ADC_READS_SHIFT) + +#define ADC_MIN_GAIN 0x0400 +#define ADC_UNITY_GAIN 0x0800 +#define ADC_MAX_GAIN (0x1000 - 1) +#define ADC_RESOLUTION_BITS 12 // do not change. This library only supports 12 bit resolution. +#define ADC_RANGE (1 << ADC_RESOLUTION_BITS) +#define ADC_TOP_VALUE (ADC_RANGE - 1) + +#define MAX_TOP_VALUE_READS 10 + +void setup() { + Serial.begin(9600); + + Serial.println("\r\nCalibrating ADC with factory values"); + + analogReadResolution(ADC_RESOLUTION_BITS); + + Serial.println("\r\nReading GND and 3.3V ADC levels"); + Serial.print(" "); + readGndLevel(); + Serial.print(" "); + read3V3Level(); + + int offsetCorrectionValue = 0; + uint16_t gainCorrectionValue = ADC_UNITY_GAIN; + + Serial.print("\r\nOffset correction (@gain = "); + Serial.print(gainCorrectionValue); + Serial.println(" (unity gain))"); + + // Set default correction values and enable correction + analogReadCorrection(offsetCorrectionValue, gainCorrectionValue); + + for (int offset = 0; offset < (int)(ADC_OFFSETCORR_MASK >> 1); ++offset) { + analogReadCorrection(offset, gainCorrectionValue); + + Serial.print(" Offset = "); + Serial.print(offset); + Serial.print(", "); + + if (readGndLevel() == 0) { + offsetCorrectionValue = offset; + break; + } + } + + Serial.println("\r\nGain correction"); + + uint8_t topValueReadsCount = 0U; + + uint16_t minGain = 0U, + maxGain = 0U; + + analogReadCorrection(offsetCorrectionValue, gainCorrectionValue); + Serial.print(" Gain = "); + Serial.print(gainCorrectionValue); + Serial.print(", "); + uint16_t highLevelRead = read3V3Level(); + + if (highLevelRead < ADC_TOP_VALUE) { + for (uint16_t gain = ADC_UNITY_GAIN + 1; gain <= ADC_MAX_GAIN; ++gain) { + analogReadCorrection(offsetCorrectionValue, gain); + + Serial.print(" Gain = "); + Serial.print(gain); + Serial.print(", "); + highLevelRead = read3V3Level(); + + if (highLevelRead == ADC_TOP_VALUE) { + if (minGain == 0U) + minGain = gain; + + if (++topValueReadsCount >= MAX_TOP_VALUE_READS) { + maxGain = minGain; + break; + } + + maxGain = gain; + } + + if (highLevelRead > ADC_TOP_VALUE) + break; + } + } else if (highLevelRead >= ADC_TOP_VALUE) { + if (highLevelRead == ADC_TOP_VALUE) + maxGain = ADC_UNITY_GAIN; + + for (uint16_t gain = ADC_UNITY_GAIN - 1; gain >= ADC_MIN_GAIN; --gain) { + analogReadCorrection(offsetCorrectionValue, gain); + + Serial.print(" Gain = "); + Serial.print(gain); + Serial.print(", "); + highLevelRead = read3V3Level(); + + if (highLevelRead == ADC_TOP_VALUE) { + if (maxGain == 0U) + maxGain = gain; + + minGain = gain; + } + + if (highLevelRead < ADC_TOP_VALUE) + break; + } + } + + gainCorrectionValue = (minGain + maxGain) >> 1; + + analogReadCorrection(offsetCorrectionValue, gainCorrectionValue); + + Serial.println("\r\nReadings after corrections"); + Serial.print(" "); + readGndLevel(); + Serial.print(" "); + read3V3Level(); + + Serial.println("\r\n=================="); + Serial.println("\r\nCorrection values:"); + Serial.print(" Offset = "); + Serial.println(offsetCorrectionValue); + Serial.print(" Gain = "); + Serial.println(gainCorrectionValue); + Serial.println("\r\nAdd the next lines to your sketch:"); + Serial.println(" analogReadResolution(12);"); + Serial.print(" analogReadCorrection("); + Serial.print(offsetCorrectionValue); + Serial.print(", "); + Serial.print(gainCorrectionValue); + Serial.println(");"); + Serial.println("\r\n=================="); +} + +void loop() { +} + +uint16_t readGndLevel() { + uint32_t readAccumulator = 0; + + for (int i = 0; i < ADC_READS_COUNT; ++i) + readAccumulator += analogRead(ADC_GND_PIN); + + uint16_t readValue = readAccumulator >> ADC_READS_SHIFT; + + Serial.print("ADC(GND) = "); + Serial.println(readValue); + + return readValue; +} + +uint16_t read3V3Level() { + uint32_t readAccumulator = 0; + + for (int i = 0; i < ADC_READS_COUNT; ++i) + readAccumulator += analogRead(ADC_3V3_PIN); + + uint16_t readValue = readAccumulator >> ADC_READS_SHIFT; + + if (readValue < (ADC_RANGE >> 1)) + readValue += ADC_RANGE; + + Serial.print("ADC(3.3V) = "); + Serial.println(readValue); + + return readValue; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SAMD_BootloaderUpdater/examples/UpdateBootloader/UpdateBootloader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SAMD_BootloaderUpdater/examples/UpdateBootloader/UpdateBootloader.ino new file mode 100644 index 00000000..67f4b504 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SAMD_BootloaderUpdater/examples/UpdateBootloader/UpdateBootloader.ino @@ -0,0 +1,89 @@ +/* + Update Bootloader + + This sketch checks if your Arduino SAMD board is running the latest bootloader. + + If it is not, it prompts you to update it. + + Circuit: + - MKR Vidor 4000 + + This example code is in the public domain. +*/ + + +#include + +void setup() { + + Serial.begin(9600); + while (!Serial) + ; + + Serial.println("Welcome to the Arduino SAMD bootloader updater"); + Serial.println("----------------------------------------------"); + Serial.println(); + +retry: + Serial.print("Checking if bootloader requires an update ... "); + if (SAMD_BootloaderUpdater.needsUpdate()) { + Serial.println("bootloader is already the latest version"); + Serial.println(); + Serial.println("Update is not required :)"); + + while (1) + ; + } + + Serial.println("bootloader is NOT running the latest"); + Serial.println(); + Serial.println(); + Serial.println("Would you like to proceed with updating it? (y/N)"); + Serial.println(); + + + while (Serial.available() == 0) { + delay(100); + } + char in = Serial.read(); + if (in != 'y' && in != 'Y') { + Serial.println("That's all folks!"); + while (1) + ; + } + + pinMode(LED_BUILTIN, OUTPUT); + + Serial.println("WARNING: DO NOT UNPLUG the USB cable during the update!!!"); + Serial.println(); + Serial.println("Updating bootloader ..."); + Serial.println(); + + if (!SAMD_BootloaderUpdater.update(onUpdateProgress)) { + Serial.println("oh no! the bootloader failed to update :("); + Serial.println(); + goto retry; + } + + Serial.println(); + Serial.println("The bootloader was successfully updated \\o/"); + Serial.println(); + Serial.println("Your board will now start blinking in joy :)"); +} + +void onUpdateProgress(float percentage) { + // toggle the LED + digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ? LOW : HIGH); + + // print out the percentage + Serial.print(percentage); + Serial.println("%"); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(100); + + digitalWrite(LED_BUILTIN, LOW); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadBinary/SBU_LoadBinary.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadBinary/SBU_LoadBinary.ino new file mode 100644 index 00000000..ccb6ea01 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadBinary/SBU_LoadBinary.ino @@ -0,0 +1,92 @@ +#include +#include + +static char const BINARY[] = { +#include "Binary.h" +}; + +static char const CHECK_FILE[] = { + "OK" +}; + +static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK"; + +NBFileUtils fileUtils; +bool update_available = false; + +void setup() { + Serial.begin(9600); + while (!Serial) {} + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) {}; + + Serial.print("Accessing SARA Filesystem... "); + if (!fileUtils.begin(false)) { + Serial.println("failed."); + return; + } + Serial.println("OK"); + Serial.print("Writing \"UPDATE.BIN\" ... "); + + uint32_t bytes_to_write = sizeof(BINARY); + Serial.print("Size of BINARY: "); + Serial.println(bytes_to_write); + int index = 0; + bool append = false; + int new_bytes = 0; + //int bytes_written = 0; + + for (int i = 0; i < (bytes_to_write / 512); i++) { + auto new_bytes = fileUtils.downloadFile("UPDATE.BIN", BINARY + index, 512, append); + if (new_bytes != 512) { + Serial.print("New_bytes = "); + Serial.print(new_bytes); + Serial.println(" != 512"); + } + index = index + new_bytes; + append = true; + } + if ((bytes_to_write % 512) != 0) { + auto new_bytes = fileUtils.downloadFile("UPDATE.BIN", BINARY + index, bytes_to_write % 512, append); + if (new_bytes != bytes_to_write % 512) { + Serial.print("Last bytes read = "); + Serial.print(new_bytes); + Serial.print(". They should have been "); + Serial.println(bytes_to_write % 512); + } + index = index + new_bytes; + } + + if (index != bytes_to_write) { + Serial.print("Written only "); + Serial.println(index); //bytes_written + Serial.print(bytes_to_write); + Serial.println(" should have been written. System is restarting..."); + delay(100); + NVIC_SystemReset(); + + } else { + Serial.print("Download complete! "); + Serial.print(index); + Serial.println(" bytes written"); + + auto status = 0; + while (status != 2) { + status = fileUtils.createFile(CHECK_FILE_NAME, CHECK_FILE, 2); + delay(100); + } + + Serial.println("Please type \"restart\" to apply the update"); + update_available = true; + } +} + +void loop() { + if (update_available == true) { + String command = Serial.readStringUntil('\n'); + if (command.indexOf("restart") >= 0) { + NVIC_SystemReset(); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/SBU_LoadLZSS.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/SBU_LoadLZSS.ino new file mode 100644 index 00000000..49c23ccd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/SBU_LoadLZSS.ino @@ -0,0 +1,70 @@ +#include +#include + +#include "lzssEncode.h" + +static char const BINARY[] = { +#include "Binary.h" +}; + +static char const CHECK_FILE[] = { + "OK" +}; + +static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK"; +const char* UPDATE_FILE_NAME_LZSS = "UPDATE.BIN.LZSS"; + +NBFileUtils fileUtils; +bool update_available = false; + +void setup() { + Serial.begin(9600); + while (!Serial) {} + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) {}; + + Serial.print("Accessing SARA Filesystem... "); + if (!fileUtils.begin(false)) { + Serial.println("failed."); + return; + } + Serial.println("OK"); + + uint32_t bytes_to_write = sizeof(BINARY); + Serial.print("Size of BINARY.H: "); + Serial.println(bytes_to_write); + + Serial.print("Encoding \"BINARY.H\" into \"UPDATE.BIN.LZSS\" and writing it into the Sara-R410M module ... "); + + //Encode into .lzss and write to the Sara modem + int bytes_written = lzss_encode(BINARY, bytes_to_write); + + if (bytes_written == 0) { + Serial.println("something went wrong!"); + } else { + Serial.println("OK!"); + } + + Serial.print("Size of UPDATE.BIN.LZSS: "); + Serial.println(bytes_written); + + auto status = 0; + while (status != 2) { + status = fileUtils.createFile(CHECK_FILE_NAME, CHECK_FILE, 2); + delay(100); + } + + Serial.println("Please type \"restart\" to apply the update"); + update_available = true; +} + + +void loop() { + if (update_available == true) { + String command = Serial.readStringUntil('\n'); + if (command.indexOf("restart") >= 0) { + NVIC_SystemReset(); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp new file mode 100644 index 00000000..6d08a492 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp @@ -0,0 +1,190 @@ +/************************************************************************************** + INCLUDE + **************************************************************************************/ + +#include "lzssEncode.h" + +#include +#include + +#include + +/************************************************************************************** + DEFINE + **************************************************************************************/ + +#define EI 11 /* typically 10..13 */ +#define EJ 4 /* typically 4..5 */ +#define P 1 /* If match length <= P then output one character */ +#define N (1 << EI) /* buffer size */ +#define F ((1 << EJ) + 1) /* lookahead buffer size */ + +#define LZSS_EOF (-1) + +#define FPUTC_BUF_SIZE (512) +#define FGETC_BUF_SIZE (512) + +/************************************************************************************** + GLOBAL VARIABLES + **************************************************************************************/ + +extern NBFileUtils fileUtils; +extern const char* UPDATE_FILE_NAME_LZSS; + +int bit_buffer = 0, bit_mask = 128; +unsigned long textcount = 0; +unsigned char buffer[N * 2]; + +static char write_buf[FPUTC_BUF_SIZE]; +static size_t write_buf_num_bytes = 0; +static size_t bytes_written_fputc = 0; + +bool append = false; +bool endOfFile = false; + +/************************************************************************************** + PUBLIC FUNCTIONS + **************************************************************************************/ + +void lzss_flush() { + bytes_written_fputc += write_buf_num_bytes; + + fileUtils.downloadFile(UPDATE_FILE_NAME_LZSS, write_buf, write_buf_num_bytes, append); //UPDATE.BIN.LZSS + append = true; + + write_buf_num_bytes = 0; +} + +/************************************************************************************** + PRIVATE FUNCTIONS + **************************************************************************************/ + +void lzss_fputc(int const c) { + /* Buffer the compressed data into a buffer so + * we can perform block writes and don't need to + * write every byte singly on the modem + */ + write_buf[write_buf_num_bytes] = static_cast(c); + write_buf_num_bytes++; + + /* The write buffer is full of compressed + * data, write it to the modem now. + */ + if (write_buf_num_bytes == FPUTC_BUF_SIZE || endOfFile) + lzss_flush(); +} + +/************************************************************************************** + LZSS FUNCTIONS + **************************************************************************************/ + +void putbit1(void) { + bit_buffer |= bit_mask; + if ((bit_mask >>= 1) == 0) { + lzss_fputc(bit_buffer); + bit_buffer = 0; + bit_mask = 128; + } +} + +void putbit0(void) { + if ((bit_mask >>= 1) == 0) { + lzss_fputc(bit_buffer); + bit_buffer = 0; + bit_mask = 128; + } +} + +void flush_bit_buffer(void) { + if (bit_mask != 128) { + lzss_fputc(bit_buffer); + } +} + +void output1(int c) { + int mask; + + putbit1(); + mask = 256; + while (mask >>= 1) { + if (c & mask) putbit1(); + else + putbit0(); + } +} + +void output2(int x, int y) { + int mask; + + putbit0(); + mask = N; + while (mask >>= 1) { + if (x & mask) putbit1(); + else + putbit0(); + } + mask = (1 << EJ); + while (mask >>= 1) { + if (y & mask) putbit1(); + else + putbit0(); + } +} + +int lzss_encode(const char buf_in[], uint32_t size) { + int i, j, f1, x, y, r, s, bufferend, c; + + for (i = 0; i < N - F; i++) buffer[i] = ' '; + for (i = N - F; i < N * 2; i++) { + if (textcount >= size) { + endOfFile = true; + break; + } else { + buffer[i] = buf_in[textcount]; + textcount++; + } + } + bufferend = i; + r = N - F; + s = 0; + while (r < bufferend) { + f1 = (F <= bufferend - r) ? F : bufferend - r; + x = 0; + y = 1; + c = buffer[r]; + for (i = r - 1; i >= s; i--) + if (buffer[i] == c) { + for (j = 1; j < f1; j++) + if (buffer[i + j] != buffer[r + j]) break; + if (j > y) { + x = i; + y = j; + } + } + if (y <= P) { + y = 1; + output1(c); + } else + output2(x & (N - 1), y - 2); + r += y; + s += y; + if (r >= N * 2 - F) { + for (i = 0; i < N; i++) buffer[i] = buffer[i + N]; + bufferend -= N; + r -= N; + s -= N; + while (bufferend < N * 2) { + if (textcount >= size) { + endOfFile = true; + break; + } else { + buffer[bufferend++] = buf_in[textcount]; + textcount++; + } + } + } + } + flush_bit_buffer(); + + return bytes_written_fputc; +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.h new file mode 100644 index 00000000..2212c82b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.h @@ -0,0 +1,17 @@ +#ifndef SBU_LZSS_H_ +#define SBU_LZSS_H_ + +/************************************************************************************** + INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + FUNCTION DEFINITION + **************************************************************************************/ + +void lzss_flush(); +int lzss_encode(const char buf_in[], uint32_t size); + +#endif /* SBU_LZSS_H_ */ \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_Usage/SBU_Usage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_Usage/SBU_Usage.ino new file mode 100644 index 00000000..8316ee09 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_Usage/SBU_Usage.ino @@ -0,0 +1,46 @@ +/* + Usage + This example demonstrates how to use the SAMD SBU library to update a + sketch on any Arduino MKR board via the storage on the SARA-R410M module. + This sketch prints out the current date and time. + Steps to update sketch: + 1) Upload this sketch or another sketch that includes the SBU library + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time. + 3) In the IDE select: Sketch -> Export compiled Binary + 4) Open the location of the sketch and convert the .bin file to a C byte array. + cat SKETCH.bin | xxd --include > Binary.h + 5) Copy Binary.h file from the sketch's folder to the SBU_LoadBinary sketch + and load it to the SARA-R410M via SBU_LoadBinary sketch. +*/ + +/* + Include the SBU library + + This will add some code to the sketch before setup() is called + to check if UPDATE.BIN and UPDATE.OK are present on the storage of + the SARA-R410M module. If this check is positive UPDATE.BIN is used to update + the sketch running on the board. + After this UPDATE.BIN and UPDATE.OK are deleted from the flash. +*/ + + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) {} + // wait a bit + delay(1000); + String message; + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + // print out the sketch compile date and time on the serial port + Serial.println(message); +} + +void loop() { + // add you own code here +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SDU/examples/Usage/Usage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SDU/examples/Usage/Usage.ino new file mode 100644 index 00000000..466c3d6f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SDU/examples/Usage/Usage.ino @@ -0,0 +1,72 @@ +/* + Usage + This example demonstrates how to use the SAMD SDU library to update a + sketch on an Arduino/Genuino Zero, MKRZero or MKR1000 board using an + SD card. It prints out the date and time the sketch was compiled at + to both Serial and Serial1. + + Circuit: + * Arduino MKRZero board with SD card + OR + * Arduino/Genuino Zero or MKR1000 board + * SD shield or breakout connected with CS pin of 4 + * SD card + + Non-Arduino/Genuino Zero, MKRZero or MKR1000 board are NOT supported. + + Steps to update sketch via SD card: + + 1) Upload this sketch or another sketch that includes the SDU library + via #include + + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time so no updates are needed. + + 3) In the IDE select: Sketch -> Export compiled Binary + + 4) Copy the .bin file from the sketch's folder to the SD card and rename + the file to UPDATE.bin. Eject the SD card from your PC. + + 5) Insert the SD card into the board, shield or breakout and press the + reset button or power cycle the board. The SDU library will then update + the sketch on the board with the contents of UPDATE.bin + + created 23 March 2017 + by Sandeep Mistry +*/ + +/* + Include the SDU library + + This will add some code to the sketch before setup() is called + to check if an SD card is present and UPDATE.bin exists on the + SD card. + + If UPDATE.bin is present, the file is used to update the sketch + running on the board. After this UPDATE.bin is deleted from the + SD card. +*/ +#include + +String message; + +void setup() { + Serial.begin(9600); + Serial1.begin(9600); + + // wait a bit + delay(1000); + + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + + // print out the sketch compile date and time on the serial port + Serial.println(message); + Serial1.println(message); +} + +void loop() { + // add you own code here +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/Binary.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/Binary.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/SFU_LoadBinary.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/SFU_LoadBinary.ino new file mode 100644 index 00000000..7575ff60 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/SFU_LoadBinary.ino @@ -0,0 +1,67 @@ +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static uint8_t const BINARY[] = { +#include "Binary.h" +}; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) {}; + + flash.begin(); + + Serial.print("Mounting ... "); + if (SPIFFS_OK != filesystem.mount()) { + Serial.println("mount() failed with error code "); + Serial.println(filesystem.err()); + return; + } + Serial.println("OK"); + + + Serial.print("Checking ... "); + if (SPIFFS_OK != filesystem.check()) { + Serial.println("check() failed with error code "); + Serial.println(filesystem.err()); + return; + } + Serial.println("OK"); + + + Serial.print("Writing \"UPDATE.BIN\" ... "); + File file = filesystem.open("UPDATE.BIN", CREATE | READ_WRITE | TRUNCATE); + + int const bytes_to_write = sizeof(BINARY); + int const bytes_written = file.write((void *)BINARY, bytes_to_write); + + if (bytes_written != bytes_to_write) { + Serial.println("write() failed with error code "); + Serial.println(filesystem.err()); + return; + } else { + Serial.print("OK ("); + Serial.print(bytes_written); + Serial.println(" bytes written)"); + } + + Serial.print("Unmounting ... "); + filesystem.unmount(); + Serial.println("OK"); +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_Usage/SFU_Usage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_Usage/SFU_Usage.ino new file mode 100644 index 00000000..af08616d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_Usage/SFU_Usage.ino @@ -0,0 +1,54 @@ +/* + Usage + This example demonstrates how to use the SAMD SFU library to update a + sketch on any Arduino MKR board connected to a MKRMEM Shield. This sketch + prints out the date and time the sketch was compiled. + + Steps to update sketch via MKRMEM shield: + + 1) Upload this sketch or another sketch that includes the SFU library + via #include + + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time so no updates are needed. + + 3) In the IDE select: Sketch -> Export compiled Binary + + 4) Open the location of the sketch and convert the .bin file to a C byte array. + cat SKETCH.bin | xxd --include > Binary.h + + 5) Copy Binary.h file from the sketch's folder to the SFU_LoadBinary sketch + and load it to the MKRMEM via SFU_LoadBinary sketch. +*/ + +/* + Include the SFU library + + This will add some code to the sketch before setup() is called + to check if UPDATE.bin is present on the flash chip of the MKRMEM + shield. If this theck is positive the file is used to update the sketch + running on the board. After this UPDATE.BIN is deleted from the flash. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) {} + + // wait a bit + delay(1000); + + String message; + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + + // print out the sketch compile date and time on the serial port + Serial.println(message); +} + +void loop() { + // add you own code here +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/Usage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/Usage.ino new file mode 100644 index 00000000..8537b3d9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/Usage.ino @@ -0,0 +1,107 @@ +/* + Usage + This example demonstrates how to use the SAMD SNU library to update a + sketch on an Arduino MKRWiFi1010 board using the board and nothing else. + It prints out the date and time the sketch was compiled at + to both Serial and Serial1. + + Arduino MKRWiFi1010 board + + Steps to update sketch via NINA WiFi/BT module: + + 1) Upload this sketch or another sketch that includes the SNU library + via #include + + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time so no updates are needed. + + 3) In the IDE select: Sketch -> Export compiled Binary + + 4) Use WiFiStorage.download(url, "UPDATE.BIN") function to download the + new binary from a remote webserver. + + 5) Reboot the board; the update will be applied seamlessly + + created 14 December 2018 + by Martino Facchin +*/ + +/* + Include the SNU library + + This will add some code to the sketch before setup() is called + to check if the WiFi module is present and UPDATE.bin exists. + + If UPDATE.bin is present, the file is used to update the sketch + running on the board. After this UPDATE.bin is deleted from NINA memory. +*/ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +/////// Wifi Settings /////// +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password +char url[] = SECRET_OTA_URL; + +int status = WL_IDLE_STATUS; + +String message; + +void setup() { + Serial.begin(9600); + Serial1.begin(9600); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true) + ; + } + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + } + + // wait a bit + delay(1000); + + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + + // print out the sketch compile date and time on the serial port + Serial.println(message); + Serial1.println(message); + + Serial.println("Type \"download\" in the Serial Monitor to start downloading the update"); +} + +void loop() { + String command = Serial.readStringUntil('\n'); + + if (command.indexOf("download") >= 0) { + + Serial.println("Downloading update file"); + WiFiStorage.download(url, "UPDATE.BIN"); + + WiFiStorageFile update = WiFiStorage.open("/fs/UPDATE.BIN"); + if (update.available()) { + Serial.println("Download complete, please restart or type \"restart\" to apply the update"); + Serial.println("Filesize: " + String(update.available())); + } else { + Serial.println("Download failed, please retry :("); + } + } + + if (command.indexOf("restart") >= 0) { + NVIC_SystemReset(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/arduino_secrets.h new file mode 100644 index 00000000..6b57ebd7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/arduino_secrets.h @@ -0,0 +1,3 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" +#define SECRET_OTA_URL "http://downloads.arduino.cc/misc/WiFi1010_blinkRBG.bin" diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino new file mode 100644 index 00000000..7254403a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -0,0 +1,142 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + */ + +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initalize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 00000000..6dd5e492 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -0,0 +1,72 @@ +/* + Digital Pot Control + + This example controls an Analog Devices AD5206 digital potentiometer. + The AD5206 has 6 potentiometer channels. Each channel's pins are labeled + A - connect this to voltage + W - this is the pot's wiper, which changes when you set it + B - connect this to ground. + + The AD5206 is SPI-compatible,and to command it, you send two bytes, + one with the channel number (0 - 5) and one with the resistance value for the + channel (0 - 255). + + The circuit: + * All A pins of AD5206 connected to +5V + * All B pins of AD5206 connected to ground + * An LED and a 220-ohm resisor in series connected from each W pin to ground + * CS - to digital pin 10 (SS pin) + * SDI - to digital pin 11 (MOSI pin) + * CLK - to digital pin 13 (SCK pin) + + created 10 Aug 2010 + by Tom Igoe + + Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 + +*/ + + +// inslude the SPI library: +#include + + +// set pin 10 as the slave select for the digital pot: +const int slaveSelectPin = 10; + +void setup() { + // set the slaveSelectPin as an output: + pinMode(slaveSelectPin, OUTPUT); + // initialize SPI: + SPI.begin(); +} + +void loop() { + // go through the six channels of the digital pot: + for (int channel = 0; channel < 6; channel++) { + // change the resistance on this channel from min to max: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, level); + delay(10); + } + // wait a second at the top: + delay(100); + // change the resistance on this channel from max to min: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, 255 - level); + delay(10); + } + } +} + +void digitalPotWrite(int address, int value) { + // take the SS pin low to select the chip: + digitalWrite(slaveSelectPin, LOW); + delay(100); + // send in the address and value via SPI: + SPI.transfer(address); + SPI.transfer(value); + delay(100); + // take the SS pin high to de-select the chip: + digitalWrite(slaveSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/SSU_HttpOta.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/SSU_HttpOta.ino new file mode 100644 index 00000000..a96d06f0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/SSU_HttpOta.ino @@ -0,0 +1,224 @@ +/* + Small example sketch demonstrating how to perform OTA via HTTP/S + utilizing a MKRGSM 1400 and the storage on the integrated + SARA U-201 GSM module. + + Please, be careful because no verification is done on the + received OTA file, apart size verification of the transmitted + bytes using the HTTP Content-Length header. + + For production-grade OTA procedure you might want to implement + a content verification procedure using a CRC calculation + or an hash (eg. MD5 or SHA256) comparison. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + Steps to update a sketch: + + 1) Create a new sketch or update an existing one to be updated over-the-air. + The sketch needs to contain also the code below for future OTAs. + The sketch must include the SSU library via + #include + + 2) In the IDE select: Sketch -> Export compiled Binary. + + 3) Open the location of the sketch (Sketch -> Show Sketch Folder) and upload + the .bin file to your HTTP/S server. + + 4) Upload this sketch after configuring the server, port and filename variables. + + The sketch will download the OTA file, store it into the U-201 storage, and + will reset the board to trigger the SSU update procedure. + + + created 25 June 2020 + by Giampaolo Mancini +*/ + +#include + +// This includes triggers the firmware update procedure +// in the bootloader after reset. +#include + +// Do not change! SSU will look for these files! +constexpr char UPDATE_FILE_NAME[] = "UPDATE.BIN"; +static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK"; + +#include "arduino_secrets.h" +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// Change to GSMClient for non-SSL/TLS connection. +// Not recommended. +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; + +GSMFileUtils fileUtils; + +bool isHeaderComplete = false; +String httpHeader; + +bool isDownloadComplete = false; +unsigned int fileSize = 0; +unsigned int totalWritten = 0; + +constexpr char server[] = "example.org"; +constexpr int port = 443; + +// Name of the new firmware file to be updated. +constexpr char filename[] = "update.bin"; + + +void setup() { + unsigned long timeout = millis(); + + Serial.begin(9600); + while (!Serial && millis() - timeout < 5000) + ; + + Serial.println("Starting OTA Update via HTTP and Arduino SSU."); + Serial.println(); + + bool connected = false; + + Serial.print("Connecting to cellular network... "); + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected."); + Serial.println(); + + // Modem has already been initialized in the sketch: + // begin FileUtils without MODEM initialization. + fileUtils.begin(false); + + Serial.print("Connecting to "); + Serial.print(server); + Serial.print(":"); + Serial.print(port); + Serial.print("... "); + if (client.connect(server, port)) { + Serial.println("Connected."); + Serial.print("Downloading "); + Serial.println(filename); + Serial.print("... "); + // Make the HTTP request: + client.print("GET /"); + client.print(filename); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + Serial.println("Connection failed"); + } +} + +void loop() { + while (client.available()) { + // Skip the HTTP header + if (!isHeaderComplete) { + const char c = client.read(); + httpHeader += c; + if (httpHeader.endsWith("\r\n\r\n")) { + isHeaderComplete = true; + + // Get the size of the OTA file from the + // HTTP Content-Length header. + fileSize = getContentLength(); + + Serial.println(); + Serial.print("HTTP header complete. "); + Serial.print("OTA file size is "); + Serial.print(fileSize); + Serial.println(" bytes."); + if (fileSize == 0) { + Serial.println("Unable to get OTA file size."); + while (true) + ; + } + } + } else { + // Read the OTA file in len-bytes blocks to preserve RAM. + constexpr size_t len{ 512 }; + char buf[len]{ 0 }; + + // Read len bytes from HTTP client... + uint32_t read = client.readBytes(buf, len); + // and append them to the update file. + uint32_t written = fileUtils.appendFile(UPDATE_FILE_NAME, buf, read); + + if (written != read) { + Serial.println("Error while saving data."); + while (true) + ; + } + + // Update the received byte counter + totalWritten += written; + + // Check for full file received and stored + isDownloadComplete = totalWritten == fileSize; + + Serial.print("Received: "); + Serial.print(totalWritten); + Serial.print("/"); + Serial.println(fileSize); + } + } + if (isDownloadComplete) { + Serial.println(); + Serial.println("Download complete."); + Serial.println("Enabling checkpoint."); + Serial.println(); + + // Create the checkpoint file: will be removed by SSU + // after successful update. + auto status = fileUtils.downloadFile(CHECK_FILE_NAME, { 0 }, 1); + if (status != 1) { + Serial.println("Unable to create checkpoint file."); + while (true) + ; + } + + Serial.println("Resetting MCU in order to trigger SSU..."); + Serial.println(); + delay(500); + NVIC_SystemReset(); + } +} + +int getContentLength() { + const String contentLengthHeader = "Content-Length:"; + const auto contentLengthHeaderLen = contentLengthHeader.length(); + + auto indexContentLengthStart = httpHeader.indexOf(contentLengthHeader); + if (indexContentLengthStart < 0) { + Serial.println("Unable to find Content-Length header (Start)"); + return 0; + } + auto indexContentLengthStop = httpHeader.indexOf("\r\n", indexContentLengthStart); + if (indexContentLengthStart < 0) { + Serial.println("Unable to find Content-Length header (Stop)"); + return 0; + } + auto contentLength = httpHeader.substring(indexContentLengthStart + contentLengthHeaderLen + 1, indexContentLengthStop); + + contentLength.trim(); + return contentLength.toInt(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/arduino_secrets.h new file mode 100644 index 00000000..bb566c76 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/SSU_LZSS_HttpOta.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/SSU_LZSS_HttpOta.ino new file mode 100644 index 00000000..654f7a9f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/SSU_LZSS_HttpOta.ino @@ -0,0 +1,227 @@ +/* + Small example sketch demonstrating how to perform OTA via HTTP/S + utilizing a MKRGSM 1400 and the storage on the integrated + SARA U-201 GSM module. + + Please, be careful because no verification is done on the + received OTA file, apart size verification of the transmitted + bytes using the HTTP Content-Length header. + + For production-grade OTA procedure you might want to implement + a content verification procedure using a CRC calculation + or an hash (eg. MD5 or SHA256) comparison. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + Steps to update a sketch: + + 1) Create a new sketch or update an existing one to be updated over-the-air. + The sketch needs to contain also the code below for future OTAs. + The sketch must include the SSU library via + #include + + 2) In the IDE select: Sketch -> Export compiled Binary. + + 3) Open the location of the sketch (Sketch -> Show Sketch Folder) and compress it + with a lzss tool + (eg. https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/extras/tools/lzss.py). + + 4) Upload the .lzss file to your HTTP/S server. + + 5) Upload this sketch after configuring the server, port and filename variables. + + The sketch will download the OTA file, store it into the U-201 storage, and + will reset the board to trigger the SSU update procedure. + + + created 25 June 2020 + by Giampaolo Mancini +*/ + +#include + +// This includes triggers the firmware update procedure +// in the bootloader after reset. +#include + +// Do not change! SSU will look for these files! +constexpr char UPDATE_FILE_NAME[] = "UPDATE.BIN.LZSS"; +static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK"; + +#include "arduino_secrets.h" +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// Change to GSMClient for non-SSL/TLS connection. +// Not recommended. +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; + +GSMFileUtils fileUtils; + +bool isHeaderComplete = false; +String httpHeader; + +bool isDownloadComplete = false; +unsigned int fileSize = 0; +unsigned int totalWritten = 0; + +constexpr char server[] = "example.org"; +constexpr int port = 443; + +// Name of the new firmware file to be updated. +constexpr char filename[] = "update.lzss"; + + +void setup() { + unsigned long timeout = millis(); + + Serial.begin(9600); + while (!Serial && millis() - timeout < 5000) + ; + + Serial.println("Starting OTA Update via HTTP and Arduino SSU."); + Serial.println(); + + bool connected = false; + + Serial.print("Connecting to cellular network... "); + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected."); + Serial.println(); + + // Modem has already been initialized in the sketch: + // begin FileUtils without MODEM initialization. + fileUtils.begin(false); + + Serial.print("Connecting to "); + Serial.print(server); + Serial.print(":"); + Serial.print(port); + Serial.print("... "); + if (client.connect(server, port)) { + Serial.println("Connected."); + Serial.print("Downloading "); + Serial.println(filename); + Serial.print("... "); + // Make the HTTP request: + client.print("GET /"); + client.print(filename); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + Serial.println("Connection failed"); + } +} + +void loop() { + while (client.available()) { + // Skip the HTTP header + if (!isHeaderComplete) { + const char c = client.read(); + httpHeader += c; + if (httpHeader.endsWith("\r\n\r\n")) { + isHeaderComplete = true; + + // Get the size of the OTA file from the + // HTTP Content-Length header. + fileSize = getContentLength(); + + Serial.println(); + Serial.print("HTTP header complete. "); + Serial.print("OTA file size is "); + Serial.print(fileSize); + Serial.println(" bytes."); + if (fileSize == 0) { + Serial.println("Unable to get OTA file size."); + while (true) + ; + } + } + } else { + // Read the OTA file in len-bytes blocks to preserve RAM. + constexpr size_t len{ 512 }; + char buf[len]{ 0 }; + + // Read len bytes from HTTP client... + uint32_t read = client.readBytes(buf, len); + // and append them to the update file. + uint32_t written = fileUtils.appendFile(UPDATE_FILE_NAME, buf, read); + + if (written != read) { + Serial.println("Error while saving data."); + while (true) + ; + } + + // Update the received byte counter + totalWritten += written; + + // Check for full file received and stored + isDownloadComplete = totalWritten == fileSize; + + Serial.print("Received: "); + Serial.print(totalWritten); + Serial.print("/"); + Serial.println(fileSize); + } + } + if (isDownloadComplete) { + Serial.println(); + Serial.println("Download complete."); + Serial.println("Enabling checkpoint."); + Serial.println(); + + // Create the checkpoint file: will be removed by SSU + // after successful update. + auto status = fileUtils.downloadFile(CHECK_FILE_NAME, { 0 }, 1); + if (status != 1) { + Serial.println("Unable to create checkpoint file."); + while (true) + ; + } + + Serial.println("Resetting MCU in order to trigger SSU..."); + Serial.println(); + delay(500); + NVIC_SystemReset(); + } +} + +int getContentLength() { + const String contentLengthHeader = "Content-Length:"; + const auto contentLengthHeaderLen = contentLengthHeader.length(); + + auto indexContentLengthStart = httpHeader.indexOf(contentLengthHeader); + if (indexContentLengthStart < 0) { + Serial.println("Unable to find Content-Length header (Start)"); + return 0; + } + auto indexContentLengthStop = httpHeader.indexOf("\r\n", indexContentLengthStart); + if (indexContentLengthStart < 0) { + Serial.println("Unable to find Content-Length header (Stop)"); + return 0; + } + auto contentLength = httpHeader.substring(indexContentLengthStart + contentLengthHeaderLen + 1, indexContentLengthStop); + + contentLength.trim(); + return contentLength.toInt(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/arduino_secrets.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/arduino_secrets.h new file mode 100644 index 00000000..bb566c76 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/Binary.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/Binary.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/SSU_LoadBinary.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/SSU_LoadBinary.ino new file mode 100644 index 00000000..7825e401 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/SSU_LoadBinary.ino @@ -0,0 +1,56 @@ +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + + +#include + + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static char const BINARY[] = + + { +#include "Binary.h" + }; + + +GSMFileUtils fileUtils; + + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) {}; + + Serial.print("Accessing SARA U-201 Filesystem... "); + if (!fileUtils.begin()) { + Serial.println("failed."); + return; + } + Serial.println("OK"); + Serial.print("Writing \"UPDATE.BIN\" ... "); + + uint32_t bytes_to_write = sizeof(BINARY); + auto bytes_written = fileUtils.downloadFile("UPDATE.BIN", BINARY, bytes_to_write); + + if (bytes_written != bytes_to_write) { + Serial.println("downloadFile failed."); + return; + + } else { + Serial.print("OK ("); + Serial.print(bytes_written); + Serial.println(" bytes written)"); + } +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_Usage/SSU_Usage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_Usage/SSU_Usage.ino new file mode 100644 index 00000000..c4eb4d50 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_Usage/SSU_Usage.ino @@ -0,0 +1,47 @@ +/* + Usage + This example demonstrates how to use the SAMD SSU library to update a + sketch on any Arduino MKR board via the storage on the SARA U-201 GSM module. + This sketch prints out the date and time the sketch was compiled. + Steps to update sketch: + 1) Upload this sketch or another sketch that includes the SSU library + via #include + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time so no updates are needed. + 3) In the IDE select: Sketch -> Export compiled Binary + 4) Open the location of the sketch and convert the .bin file to a C byte array. + cat SKETCH.bin | xxd --include > Binary.h + 5) Copy Binary.h file from the sketch's folder to the SSU_LoadBinary sketch + and load it to the U-201 via SSU_LoadBinary sketch. +*/ + +/* + Include the SSU library + + This will add some code to the sketch before setup() is called + to check if UPDATE.BIN and UPDATE.OK are present on the storage of + the U-201 module. If this theck is positive UPDATE.BIN is used to update + the sketch running on the board. + After this UPDATE.BIN and UPDATE.OK are deleted from the flash. +*/ + + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) {} + // wait a bit + delay(1000); + String message; + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + // print out the sketch compile date and time on the serial port + Serial.println(message); +} + +void loop() { + // add you own code here +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino new file mode 100644 index 00000000..6129eaca --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino @@ -0,0 +1,72 @@ +/* + Copyright (c) 2012 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#define ARDUINO_MAIN +//#include "variant.h" +#include "Arduino.h" +#include +#include + + +USBHost usb; +ADK adk(&usb, "Arduino SA", + "Arduino_Terminal", + "Arduino Terminal for Android", + "1.0", + "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk", + "1"); + +void setup(void) { + SERIAL_PORT_MONITOR.begin(115200); + while (!SERIAL_PORT_MONITOR) + ; // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("\r\nADK demo start"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay(20); +} + +#define RCVSIZE 128 + +void loop(void) { + uint8_t buf[RCVSIZE]; + uint32_t nbread = 0; + char helloworld[] = "Hello World!\r\n"; + + usb.Task(); + + if (adk.isReady() == false) { + return; + } + /* Write hello string to ADK */ + adk.SndData(strlen(helloworld), (uint8_t *)helloworld); + + delay(1000); + + /* Read data from ADK and print to UART */ + adk.RcvData((uint8_t *)&nbread, buf); + if (nbread > 0) { + SERIAL_PORT_MONITOR.print("RCV: "); + for (uint32_t i = 0; i < nbread; ++i) { + SERIAL_PORT_MONITOR.print((char)buf[i]); + } + SERIAL_PORT_MONITOR.print("\r\n"); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/KeyboardController/KeyboardController.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/KeyboardController/KeyboardController.ino new file mode 100644 index 00000000..70460e23 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/KeyboardController/KeyboardController.ino @@ -0,0 +1,88 @@ +/* + Keyboard Controller Example + + Shows the output of a USB Keyboard connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + https://www.arduino.cc/en/Tutorial/KeyboardController + + This sample code is part of the public domain. + */ + +// Require keyboard control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach keyboard controller to USB +KeyboardController keyboard(usb); + +void printKey(); + +// This function intercepts key press +void keyPressed() { + SERIAL_PORT_MONITOR.print("Pressed: "); + printKey(); +} + +// This function intercepts key release +void keyReleased() { + SERIAL_PORT_MONITOR.print("Released: "); + printKey(); +} + +void printKey() { + // getOemKey() returns the OEM-code associated with the key + SERIAL_PORT_MONITOR.print(" key:"); + SERIAL_PORT_MONITOR.print(keyboard.getOemKey()); + + // getModifiers() returns a bits field with the modifiers-keys + int mod = keyboard.getModifiers(); + SERIAL_PORT_MONITOR.print(" mod:"); + SERIAL_PORT_MONITOR.print(mod); + + SERIAL_PORT_MONITOR.print(" => "); + + if (mod & LeftCtrl) + SERIAL_PORT_MONITOR.print("L-Ctrl "); + if (mod & LeftShift) + SERIAL_PORT_MONITOR.print("L-Shift "); + if (mod & Alt) + SERIAL_PORT_MONITOR.print("Alt "); + if (mod & LeftCmd) + SERIAL_PORT_MONITOR.print("L-Cmd "); + if (mod & RightCtrl) + SERIAL_PORT_MONITOR.print("R-Ctrl "); + if (mod & RightShift) + SERIAL_PORT_MONITOR.print("R-Shift "); + if (mod & AltGr) + SERIAL_PORT_MONITOR.print("AltGr "); + if (mod & RightCmd) + SERIAL_PORT_MONITOR.print("R-Cmd "); + + // getKey() returns the ASCII translation of OEM key + // combined with modifiers. + SERIAL_PORT_MONITOR.write(keyboard.getKey()); + SERIAL_PORT_MONITOR.println(); +} + +void setup() { + SERIAL_PORT_MONITOR.begin(115200); + while (!SERIAL_PORT_MONITOR) + ; // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Keyboard Controller Program started"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay(20); +} + +void loop() { + // Process USB tasks + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/MouseController/MouseController.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/MouseController/MouseController.ino new file mode 100644 index 00000000..86502e4b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/MouseController/MouseController.ino @@ -0,0 +1,96 @@ +/* + Mouse Controller Example + + Shows the output of a USB Mouse connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + https://www.arduino.cc/en/Tutorial/MouseController + + This sample code is part of the public domain. + */ + +// Require mouse control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach mouse controller to USB +MouseController mouse(usb); + +// variables for mouse button states +bool leftButton = false; +bool middleButton = false; +bool rightButton = false; + +// This function intercepts mouse movements +void mouseMoved() { + SERIAL_PORT_MONITOR.print("Move: "); + SERIAL_PORT_MONITOR.print(mouse.getXChange()); + SERIAL_PORT_MONITOR.print(", "); + SERIAL_PORT_MONITOR.println(mouse.getYChange()); +} + +// This function intercepts mouse movements while a button is pressed +void mouseDragged() { + SERIAL_PORT_MONITOR.print("DRAG: "); + SERIAL_PORT_MONITOR.print(mouse.getXChange()); + SERIAL_PORT_MONITOR.print(", "); + SERIAL_PORT_MONITOR.println(mouse.getYChange()); +} + +// This function intercepts mouse button press +void mousePressed() { + SERIAL_PORT_MONITOR.print("Pressed: "); + if (mouse.getButton(LEFT_BUTTON)) { + SERIAL_PORT_MONITOR.print("L"); + leftButton = true; + } + if (mouse.getButton(MIDDLE_BUTTON)) { + SERIAL_PORT_MONITOR.print("M"); + middleButton = true; + } + if (mouse.getButton(RIGHT_BUTTON)) { + SERIAL_PORT_MONITOR.print("R"); + rightButton = true; + } + SERIAL_PORT_MONITOR.println(); +} + +// This function intercepts mouse button release +void mouseReleased() { + SERIAL_PORT_MONITOR.print("Released: "); + if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) { + SERIAL_PORT_MONITOR.print("L"); + leftButton = false; + } + if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) { + SERIAL_PORT_MONITOR.print("M"); + middleButton = false; + } + if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) { + SERIAL_PORT_MONITOR.print("R"); + rightButton = false; + } + SERIAL_PORT_MONITOR.println(); +} + +void setup() { + SERIAL_PORT_MONITOR.begin(115200); + while (!SERIAL_PORT_MONITOR) + ; // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Mouse Controller Program started"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay(20); +} + +void loop() { + // Process USB tasks + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino new file mode 100644 index 00000000..817dd429 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino @@ -0,0 +1,373 @@ + + +#include "Arduino.h" +#include +#include "pgmstrings.h" +// Satisfy IDE, which only needs to see the include statment in the ino. +#ifdef dobogusinclude +#include +#endif + +USBHost usb; +//USBHub Hub1(&Usb); +//USBHub Hub2(&Usb); +//USBHub Hub3(&Usb); +//USBHub Hub4(&Usb); +//USBHub Hub5(&Usb); +//USBHub Hub6(&Usb); +//USBHub Hub7(&Usb); + +uint32_t next_time; + +void print_hex(int v, int num_places); +void printintfdescr(uint8_t* descr_ptr); +byte getconfdescr(byte addr, byte conf); +void printconfdescr(uint8_t* descr_ptr); +void printunkdescr(uint8_t* descr_ptr); +void printepdescr(uint8_t* descr_ptr); +void printProgStr(const prog_char str[]); +void printHIDdescr(uint8_t* descr_ptr); + +void PrintAllAddresses(UsbDeviceDefinition* pdev) { + UsbDeviceAddress adr; + adr.devAddress = pdev->address.devAddress; + SERIAL_PORT_MONITOR.print("\r\nAddr:"); + SERIAL_PORT_MONITOR.print(adr.devAddress, HEX); + SERIAL_PORT_MONITOR.print("("); + SERIAL_PORT_MONITOR.print(adr.bmHub, HEX); + SERIAL_PORT_MONITOR.print("."); + SERIAL_PORT_MONITOR.print(adr.bmParent, HEX); + SERIAL_PORT_MONITOR.print("."); + SERIAL_PORT_MONITOR.print(adr.bmAddress, HEX); + SERIAL_PORT_MONITOR.println(")"); +} + +void PrintAddress(uint8_t addr) { + UsbDeviceAddress adr; + adr.devAddress = addr; + SERIAL_PORT_MONITOR.print("\r\nADDR:\t"); + SERIAL_PORT_MONITOR.println(adr.devAddress, HEX); + SERIAL_PORT_MONITOR.print("DEV:\t"); + SERIAL_PORT_MONITOR.println(adr.bmAddress, HEX); + SERIAL_PORT_MONITOR.print("PRNT:\t"); + SERIAL_PORT_MONITOR.println(adr.bmParent, HEX); + SERIAL_PORT_MONITOR.print("HUB:\t"); + SERIAL_PORT_MONITOR.println(adr.bmHub, HEX); +} + +void setup() { + SERIAL_PORT_MONITOR.begin(115200); + while (!Serial) + ; // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Start USB Desc"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay(20); + + next_time = millis() + 10000; +} + +byte getdevdescr(byte addr, byte& num_conf); + +void PrintDescriptors(uint8_t addr) { + uint8_t rcode = 0; + byte num_conf = 0; + + rcode = getdevdescr((byte)addr, num_conf); + if (rcode) { + printProgStr(Gen_Error_str); + print_hex(rcode, 8); + } + SERIAL_PORT_MONITOR.print("\r\n"); + + for (int i = 0; i < num_conf; i++) { + rcode = getconfdescr(addr, i); // get configuration descriptor + if (rcode) { + printProgStr(Gen_Error_str); + print_hex(rcode, 8); + } + SERIAL_PORT_MONITOR.println("\r\n"); + } +} + +void PrintAllDescriptors(UsbDeviceDefinition* pdev) { + SERIAL_PORT_MONITOR.println("\r\n"); + print_hex(pdev->address.devAddress, 8); + SERIAL_PORT_MONITOR.println("\r\n--"); + PrintDescriptors(pdev->address.devAddress); +} + +void loop() { + usb.Task(); + + if (usb.getUsbTaskState() == USB_STATE_RUNNING) { + //if (millis() >= next_time) + { + usb.ForEachUsbDevice(&PrintAllDescriptors); + usb.ForEachUsbDevice(&PrintAllAddresses); + + while (1) + ; //stop + } + } +} + +byte getdevdescr(byte addr, byte& num_conf) { + USB_DEVICE_DESCRIPTOR buf; + byte rcode; + rcode = usb.getDevDescr(addr, 0, 0x12, (uint8_t*)&buf); + if (rcode) { + return (rcode); + } + printProgStr(Dev_Header_str); + printProgStr(Dev_Length_str); + print_hex(buf.bLength, 8); + printProgStr(Dev_Type_str); + print_hex(buf.bDescriptorType, 8); + printProgStr(Dev_Version_str); + print_hex(buf.bcdUSB, 16); + printProgStr(Dev_Class_str); + print_hex(buf.bDeviceClass, 8); + printProgStr(Dev_Subclass_str); + print_hex(buf.bDeviceSubClass, 8); + printProgStr(Dev_Protocol_str); + print_hex(buf.bDeviceProtocol, 8); + printProgStr(Dev_Pktsize_str); + print_hex(buf.bMaxPacketSize0, 8); + printProgStr(Dev_Vendor_str); + print_hex(buf.idVendor, 16); + printProgStr(Dev_Product_str); + print_hex(buf.idProduct, 16); + printProgStr(Dev_Revision_str); + print_hex(buf.bcdDevice, 16); + printProgStr(Dev_Mfg_str); + print_hex(buf.iManufacturer, 8); + printProgStr(Dev_Prod_str); + print_hex(buf.iProduct, 8); + printProgStr(Dev_Serial_str); + print_hex(buf.iSerialNumber, 8); + printProgStr(Dev_Nconf_str); + print_hex(buf.bNumConfigurations, 8); + num_conf = buf.bNumConfigurations; + return (0); +} + +void printhubdescr(uint8_t* descrptr, uint8_t addr) { + HubDescriptor* pHub = (HubDescriptor*)descrptr; + uint8_t len = *((uint8_t*)descrptr); + + printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n")); + printProgStr(PSTR("bDescLength:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bDescLength, HEX); + + printProgStr(PSTR("bDescriptorType:\t")); + SERIAL_PORT_MONITOR.println(pHub->bDescriptorType, HEX); + + printProgStr(PSTR("bNbrPorts:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bNbrPorts, HEX); + + printProgStr(PSTR("LogPwrSwitchMode:\t")); + SERIAL_PORT_MONITOR.println(pHub->LogPwrSwitchMode, BIN); + + printProgStr(PSTR("CompoundDevice:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->CompoundDevice, BIN); + + printProgStr(PSTR("OverCurrentProtectMode:\t")); + SERIAL_PORT_MONITOR.println(pHub->OverCurrentProtectMode, BIN); + + printProgStr(PSTR("TTThinkTime:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->TTThinkTime, BIN); + + printProgStr(PSTR("PortIndicatorsSupported:")); + SERIAL_PORT_MONITOR.println(pHub->PortIndicatorsSupported, BIN); + + printProgStr(PSTR("Reserved:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->Reserved, HEX); + + printProgStr(PSTR("bPwrOn2PwrGood:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bPwrOn2PwrGood, HEX); + + printProgStr(PSTR("bHubContrCurrent:\t")); + SERIAL_PORT_MONITOR.println(pHub->bHubContrCurrent, HEX); + + for (uint8_t i = 7; i < len; i++) + print_hex(descrptr[i], 8); + + //for (uint8_t i=1; i<=pHub->bNbrPorts; i++) + // PrintHubPortStatus(&Usb, addr, i, 1); +} + +byte getconfdescr(byte addr, byte conf) { + uint8_t buf[BUFSIZE]; + uint8_t* buf_ptr = buf; + byte rcode; + byte descr_length; + byte descr_type; + uint16_t total_length; + rcode = usb.getConfDescr(addr, 0, 4, conf, buf); //get total length + LOBYTE(total_length) = buf[2]; + HIBYTE(total_length) = buf[3]; + if (total_length > sizeof(buf)) { //check if total length is larger than buffer + printProgStr(Conf_Trunc_str); + total_length = sizeof(buf); + } + rcode = usb.getConfDescr(addr, 0, total_length, conf, buf); //get the whole descriptor + while (buf_ptr < buf + total_length) { //parsing descriptors + descr_length = *(buf_ptr); + descr_type = *(buf_ptr + 1); + switch (descr_type) { + case (USB_DESCRIPTOR_CONFIGURATION): + printconfdescr(buf_ptr); + break; + case (USB_DESCRIPTOR_INTERFACE): + printintfdescr(buf_ptr); + break; + case (USB_DESCRIPTOR_ENDPOINT): + printepdescr(buf_ptr); + break; + case 0x21: // HID Descriptor + printHIDdescr(buf_ptr); + break; + case 0x29: + printhubdescr(buf_ptr, addr); + break; + default: + printunkdescr(buf_ptr); + break; + } //switch( descr_type + buf_ptr = (buf_ptr + descr_length); //advance buffer pointer + } //while( buf_ptr <=... + return (0); +} +/* prints hex numbers with leading zeroes */ +// copyright, Peter H Anderson, Baltimore, MD, Nov, '07 +// source: http://www.phanderson.com/arduino/arduino_display.html +void print_hex(int v, int num_places) { + int mask = 0, n, num_nibbles, digit; + + for (n = 1; n <= num_places; n++) { + mask = (mask << 1) | 0x0001; + } + v = v & mask; // truncate v to specified number of places + + num_nibbles = num_places / 4; + if ((num_places % 4) != 0) { + ++num_nibbles; + } + do { + digit = ((v >> (num_nibbles - 1) * 4)) & 0x0f; + SERIAL_PORT_MONITOR.print(digit, HEX); + } while (--num_nibbles); +} +/* function to print configuration descriptor */ +void printconfdescr(uint8_t* descr_ptr) { + USB_CONFIGURATION_DESCRIPTOR* conf_ptr = (USB_CONFIGURATION_DESCRIPTOR*)descr_ptr; + printProgStr(Conf_Header_str); + printProgStr(Conf_Totlen_str); + print_hex(conf_ptr->wTotalLength, 16); + printProgStr(Conf_Nint_str); + print_hex(conf_ptr->bNumInterfaces, 8); + printProgStr(Conf_Value_str); + print_hex(conf_ptr->bConfigurationValue, 8); + printProgStr(Conf_String_str); + print_hex(conf_ptr->iConfiguration, 8); + printProgStr(Conf_Attr_str); + print_hex(conf_ptr->bmAttributes, 8); + printProgStr(Conf_Pwr_str); + print_hex(conf_ptr->bMaxPower, 8); + return; +} +/* function to print interface descriptor */ +void printintfdescr(uint8_t* descr_ptr) { + USB_INTERFACE_DESCRIPTOR* intf_ptr = (USB_INTERFACE_DESCRIPTOR*)descr_ptr; + printProgStr(Int_Header_str); + printProgStr(Int_Number_str); + print_hex(intf_ptr->bInterfaceNumber, 8); + printProgStr(Int_Alt_str); + print_hex(intf_ptr->bAlternateSetting, 8); + printProgStr(Int_Endpoints_str); + print_hex(intf_ptr->bNumEndpoints, 8); + printProgStr(Int_Class_str); + print_hex(intf_ptr->bInterfaceClass, 8); + printProgStr(Int_Subclass_str); + print_hex(intf_ptr->bInterfaceSubClass, 8); + printProgStr(Int_Protocol_str); + print_hex(intf_ptr->bInterfaceProtocol, 8); + printProgStr(Int_String_str); + print_hex(intf_ptr->iInterface, 8); + return; +} + +/* function to print HID descriptor */ +void printHIDdescr(uint8_t* descr_ptr) { + USB_HID_DESCRIPTOR* ep_ptr = (USB_HID_DESCRIPTOR*)descr_ptr; + + printProgStr(PSTR("\r\n\r\nHID Descriptor:\r\n")); + printProgStr(PSTR("HID Class Release:\t")); + print_hex(ep_ptr->bcdHID, 16); + printProgStr(PSTR("\r\nCountry Code:\t\t")); + print_hex(ep_ptr->bCountryCode, 8); + printProgStr(PSTR("\r\nNumb Class Descriptor:\t")); + print_hex(ep_ptr->bNumDescriptors, 8); + printProgStr(PSTR("\r\nDescriptor Type:\t")); + if (ep_ptr->bDescrType == 0x22) + printProgStr(PSTR("REPORT DESCRIPTOR")); + else + print_hex(ep_ptr->bDescrType, 8); + printProgStr(PSTR("\r\nCSize Report Descr:\t")); + print_hex(ep_ptr->wDescriptorLength, 16); +} + +/* function to print endpoint descriptor */ +void printepdescr(uint8_t* descr_ptr) { + uint8_t transfer_type; + + USB_ENDPOINT_DESCRIPTOR* ep_ptr = (USB_ENDPOINT_DESCRIPTOR*)descr_ptr; + printProgStr(End_Header_str); + printProgStr(End_Address_str); + if (0x80 & ep_ptr->bEndpointAddress) printProgStr(PSTR("IN\t\t")); + else + printProgStr(PSTR("OUT\t\t")); + print_hex((ep_ptr->bEndpointAddress & 0xF), 8); + printProgStr(End_Attr_str); + transfer_type = ep_ptr->bmAttributes & bmUSB_TRANSFER_TYPE; + if (transfer_type == USB_TRANSFER_TYPE_INTERRUPT) printProgStr(PSTR("INTERRUPT\t")); + else if (transfer_type == USB_TRANSFER_TYPE_BULK) + printProgStr(PSTR("BULK\t")); + else if (transfer_type == USB_TRANSFER_TYPE_ISOCHRONOUS) + printProgStr(PSTR("ISO\t")); + print_hex(ep_ptr->bmAttributes, 8); + printProgStr(End_Pktsize_str); + print_hex(ep_ptr->wMaxPacketSize, 16); + printProgStr(End_Interval_str); + print_hex(ep_ptr->bInterval, 8); + + return; +} +/*function to print unknown descriptor */ +void printunkdescr(uint8_t* descr_ptr) { + byte length = *descr_ptr; + byte i; + printProgStr(Unk_Header_str); + printProgStr(Unk_Length_str); + print_hex(*descr_ptr, 8); + printProgStr(Unk_Type_str); + print_hex(*(descr_ptr + 1), 8); + printProgStr(Unk_Contents_str); + descr_ptr += 2; + for (i = 0; i < length; i++) { + print_hex(*descr_ptr, 8); + descr_ptr++; + } +} + + +/* Print a string from Program Memory directly to save RAM */ +void printProgStr(const prog_char str[]) { + char c; + if (!str) return; + while ((c = pgm_read_byte(str++))) + SERIAL_PORT_MONITOR.print(c); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/pgmstrings.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/pgmstrings.h new file mode 100644 index 00000000..05157a04 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/pgmstrings.h @@ -0,0 +1,52 @@ +#if !defined(__PGMSTRINGS_H__) +#define __PGMSTRINGS_H__ + +#define LOBYTE(x) ((char*)(&(x)))[0] +#define HIBYTE(x) ((char*)(&(x)))[1] +#define BUFSIZE 256 //buffer size + + +/* Print strings in Program Memory */ +const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; +const char Dev_Header_str[] PROGMEM = "\r\nDevice descriptor: "; +const char Dev_Length_str[] PROGMEM = "\r\nDescriptor Length:\t"; +const char Dev_Type_str[] PROGMEM = "\r\nDescriptor type:\t"; +const char Dev_Version_str[] PROGMEM = "\r\nUSB version:\t\t"; +const char Dev_Class_str[] PROGMEM = "\r\nDevice class:\t\t"; +const char Dev_Subclass_str[] PROGMEM = "\r\nDevice Subclass:\t"; +const char Dev_Protocol_str[] PROGMEM = "\r\nDevice Protocol:\t"; +const char Dev_Pktsize_str[] PROGMEM = "\r\nMax.packet size:\t"; +const char Dev_Vendor_str[] PROGMEM = "\r\nVendor ID:\t\t"; +const char Dev_Product_str[] PROGMEM = "\r\nProduct ID:\t\t"; +const char Dev_Revision_str[] PROGMEM = "\r\nRevision ID:\t\t"; +const char Dev_Mfg_str[] PROGMEM = "\r\nMfg.string index:\t"; +const char Dev_Prod_str[] PROGMEM = "\r\nProd.string index:\t"; +const char Dev_Serial_str[] PROGMEM = "\r\nSerial number index:\t"; +const char Dev_Nconf_str[] PROGMEM = "\r\nNumber of conf.:\t"; +const char Conf_Trunc_str[] PROGMEM = "Total length truncated to 256 bytes"; +const char Conf_Header_str[] PROGMEM = "\r\nConfiguration descriptor:"; +const char Conf_Totlen_str[] PROGMEM = "\r\nTotal length:\t\t"; +const char Conf_Nint_str[] PROGMEM = "\r\nNum.intf:\t\t"; +const char Conf_Value_str[] PROGMEM = "\r\nConf.value:\t\t"; +const char Conf_String_str[] PROGMEM = "\r\nConf.string:\t\t"; +const char Conf_Attr_str[] PROGMEM = "\r\nAttr.:\t\t\t"; +const char Conf_Pwr_str[] PROGMEM = "\r\nMax.pwr:\t\t"; +const char Int_Header_str[] PROGMEM = "\r\n\r\nInterface descriptor:"; +const char Int_Number_str[] PROGMEM = "\r\nIntf.number:\t\t"; +const char Int_Alt_str[] PROGMEM = "\r\nAlt.:\t\t\t"; +const char Int_Endpoints_str[] PROGMEM = "\r\nEndpoints:\t\t"; +const char Int_Class_str[] PROGMEM = "\r\nIntf. Class:\t\t"; +const char Int_Subclass_str[] PROGMEM = "\r\nIntf. Subclass:\t\t"; +const char Int_Protocol_str[] PROGMEM = "\r\nIntf. Protocol:\t\t"; +const char Int_String_str[] PROGMEM = "\r\nIntf.string:\t\t"; +const char End_Header_str[] PROGMEM = "\r\n\r\nEndpoint descriptor:"; +const char End_Address_str[] PROGMEM = "\r\nEndpoint address:\t"; +const char End_Attr_str[] PROGMEM = "\r\nAttr.:\t\t\t"; +const char End_Pktsize_str[] PROGMEM = "\r\nMax.pkt size:\t\t"; +const char End_Interval_str[] PROGMEM = "\r\nPolling interval:\t"; +const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; +const char Unk_Length_str[] PROGMEM = "\r\nLength:\t\t"; +const char Unk_Type_str[] PROGMEM = "\r\nType:\t\t"; +const char Unk_Contents_str[] PROGMEM = "\r\nContents:\t"; + +#endif // __PGMSTRINGS_H__ \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino new file mode 100644 index 00000000..9cfadc74 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -0,0 +1,85 @@ +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// by Nicholas Zambetti +// and James Tichenor + +// Demonstrates use of the Wire library reading data from the +// Devantech Utrasonic Rangers SFR08 and SFR10 + +// Created 29 April 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial communication at 9600bps +} + +int reading = 0; + +void loop() { + // step 1: instruct sensor to read echoes + Wire.beginTransmission(112); // transmit to device #112 (0x70) + // the address specified in the datasheet is 224 (0xE0) + // but i2c adressing uses the high 7 bits so it's 112 + Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) + Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds + Wire.endTransmission(); // stop transmitting + + // step 2: wait for readings to happen + delay(70); // datasheet suggests at least 65 milliseconds + + // step 3: instruct sensor to return a particular echo reading + Wire.beginTransmission(112); // transmit to device #112 + Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + + // step 4: request reading from sensor + Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 + + // step 5: receive reading from sensor + if (2 <= Wire.available()) // if two bytes were received + { + reading = Wire.read(); // receive high byte (overwrites previous reading) + reading = reading << 8; // shift high byte to be high 8 bits + reading |= Wire.read(); // receive low byte as lower 8 bits + Serial.println(reading); // print the reading + } + + delay(250); // wait a bit since people have to read the output :) +} + + +/* + +// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) +// usage: changeAddress(0x70, 0xE6); + +void changeAddress(byte oldAddress, byte newAddress) +{ + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA0)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xAA)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA5)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(newAddress); + Wire.endTransmission(); +} + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino new file mode 100644 index 00000000..4757c9ca --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -0,0 +1,36 @@ +// I2C Digital Potentiometer +// by Nicholas Zambetti +// and Shawn Bonkowski + +// Demonstrates use of the Wire library +// Controls AD5171 digital potentiometer via I2C/TWI + +// Created 31 March 2006 + +// This example code is in the public domain. + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) +} + +byte val = 0; + +void loop() { + Wire.beginTransmission(44); // transmit to device #44 (0x2c) + // device address is specified in datasheet + Wire.write(byte(0x00)); // sends instruction byte + Wire.write(val); // sends potentiometer value byte + Wire.endTransmission(); // stop transmitting + + val++; // increment value + if (val == 64) // if reached 64th position (max) + { + val = 0; // start over from lowest value + } + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_reader/master_reader.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_reader/master_reader.ino new file mode 100644 index 00000000..92a0d96f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_reader/master_reader.ino @@ -0,0 +1,30 @@ +// Wire Master Reader +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Reads data from an I2C/TWI slave device +// Refer to the "Wire Slave Sender" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() { + Wire.requestFrom(2, 6); // request 6 bytes from slave device #2 + + while (Wire.available()) // slave may send less than requested + { + char c = Wire.read(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_writer/master_writer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_writer/master_writer.ino new file mode 100644 index 00000000..461a8d3f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_writer/master_writer.ino @@ -0,0 +1,29 @@ +// Wire Master Writer +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Writes data to an I2C/TWI slave device +// Refer to the "Wire Slave Receiver" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) +} + +byte x = 0; + +void loop() { + Wire.beginTransmission(4); // transmit to device #4 + Wire.write("x is "); // sends five bytes + Wire.write(x); // sends one byte + Wire.endTransmission(); // stop transmitting + + x++; + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_receiver/slave_receiver.ino new file mode 100644 index 00000000..85b7d46a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -0,0 +1,35 @@ +// Wire Slave Receiver +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI slave device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(4); // join i2c bus with address #4 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() { + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) { + while (1 < Wire.available()) // loop through all but the last + { + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_sender/slave_sender.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_sender/slave_sender.ino new file mode 100644 index 00000000..c74bff54 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -0,0 +1,29 @@ +// Wire Slave Sender +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Sends data as an I2C/TWI slave device +// Refer to the "Wire Master Reader" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(2); // join i2c bus with address #2 + Wire.onRequest(requestEvent); // register event +} + +void loop() { + delay(100); +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() { + Wire.write("hello "); // respond with message of 6 bytes + // as expected by master +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/README.md new file mode 100644 index 00000000..32a6a5ef --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/README.md @@ -0,0 +1,4 @@ +# FruitToEmoji + +Classifies fruit using the RGB color and proximity sensors of the Arduino Nano 33 BLE Sense, using a TensorFlow Lite Micro model trained on data captured from the same hardware + diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_capture/object_color_capture.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_capture/object_color_capture.ino new file mode 100644 index 00000000..4788a481 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_capture/object_color_capture.ino @@ -0,0 +1,55 @@ +/* + Object color sampler + -------------------- + Samples the color of objects and outputs CSV logfile to serial console + + Hardware: Arduino Nano 33 BLE Sense board. + + Usage: Place object of interest to the color sensor + + This example code is in the public domain. +*/ + +#include + +void setup() { + + Serial.begin(9600); + while (!Serial) {}; + + if (!APDS.begin()) { + Serial.println("Error initializing APDS9960 sensor."); + } + + // print the header + Serial.println("Red,Green,Blue"); +} + +void loop() { + int r, g, b, c, p; + float sum; + + // wait for proximity and color sensor data + while (!APDS.colorAvailable() || !APDS.proximityAvailable()) {} + + // read the color and proximity data + APDS.readColor(r, g, b, c); + sum = r + g + b; + p = APDS.readProximity(); + + // if object is close and well enough illumated + if (p == 0 && c > 10 && sum > 0) { + + float redRatio = r / sum; + float greenRatio = g / sum; + float blueRatio = b / sum; + + // print the data in CSV format + Serial.print(redRatio, 3); + Serial.print(','); + Serial.print(greenRatio, 3); + Serial.print(','); + Serial.print(blueRatio, 3); + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_classify/object_color_classify.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_classify/object_color_classify.ino new file mode 100644 index 00000000..0be008a6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_classify/object_color_classify.ino @@ -0,0 +1,135 @@ +/* + Object classifier by color + -------------------------- + + Uses RGB color sensor input to Neural Network to classify objects + Outputs object class to serial using unicode emojis + + Note: The direct use of C/C++ pointers, namespaces, and dynamic memory is generally + discouraged in Arduino examples, and in the future the TensorFlowLite library + might change to make the sketch simpler. + + Hardware: Arduino Nano 33 BLE Sense board. + + Created by Don Coleman, Sandeep Mistry + Adapted by Dominic Pajak + + This example code is in the public domain. +*/ + +// Arduino_TensorFlowLite - Version: 0.alpha.precompiled +#include + +#include +#include +#include +#include +#include +#include +#include "model.h" + +// global variables used for TensorFlow Lite (Micro) +tflite::MicroErrorReporter tflErrorReporter; + +// pull in all the TFLM ops, you can remove this line and +// only pull in the TFLM ops you need, if would like to reduce +// the compiled size of the sketch. +tflite::AllOpsResolver tflOpsResolver; + +const tflite::Model* tflModel = nullptr; +tflite::MicroInterpreter* tflInterpreter = nullptr; +TfLiteTensor* tflInputTensor = nullptr; +TfLiteTensor* tflOutputTensor = nullptr; + +// Create a static memory buffer for TFLM, the size may need to +// be adjusted based on the model you are using +constexpr int tensorArenaSize = 8 * 1024; +byte tensorArena[tensorArenaSize]; + +// array to map gesture index to a name +const char* CLASSES[] = { + "Apple", // u8"\U0001F34E", // Apple + "Banana", // u8"\U0001F34C", // Banana + "Orange" // u8"\U0001F34A" // Orange +}; + +#define NUM_CLASSES (sizeof(CLASSES) / sizeof(CLASSES[0])) + +void setup() { + Serial.begin(9600); + while (!Serial) {}; + + Serial.println("Object classification using RGB color sensor"); + Serial.println("--------------------------------------------"); + Serial.println("Arduino Nano 33 BLE Sense running TensorFlow Lite Micro"); + Serial.println(""); + + if (!APDS.begin()) { + Serial.println("Error initializing APDS9960 sensor."); + } + + // get the TFL representation of the model byte array + tflModel = tflite::GetModel(model); + if (tflModel->version() != TFLITE_SCHEMA_VERSION) { + Serial.println("Model schema mismatch!"); + while (1) + ; + } + + // Create an interpreter to run the model + tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter); + + // Allocate memory for the model's input and output tensors + tflInterpreter->AllocateTensors(); + + // Get pointers for the model's input and output tensors + tflInputTensor = tflInterpreter->input(0); + tflOutputTensor = tflInterpreter->output(0); +} + +void loop() { + int r, g, b, p, c; + float sum; + + // check if both color and proximity data is available to sample + while (!APDS.colorAvailable() || !APDS.proximityAvailable()) {} + + // read the color and proximity sensor + APDS.readColor(r, g, b, c); + p = APDS.readProximity(); + sum = r + g + b; + + // check if there's an object close and well illuminated enough + if (p == 0 && c > 10 && sum > 0) { + + float redRatio = r / sum; + float greenRatio = g / sum; + float blueRatio = b / sum; + + // input sensor data to model + tflInputTensor->data.f[0] = redRatio; + tflInputTensor->data.f[1] = greenRatio; + tflInputTensor->data.f[2] = blueRatio; + + // Run inferencing + TfLiteStatus invokeStatus = tflInterpreter->Invoke(); + if (invokeStatus != kTfLiteOk) { + Serial.println("Invoke failed!"); + while (1) + ; + return; + } + + // Output results + for (int i = 0; i < NUM_CLASSES; i++) { + Serial.print(CLASSES[i]); + Serial.print(" "); + Serial.print(int(tflOutputTensor->data.f[i] * 100)); + Serial.print("%\n"); + } + Serial.println(); + + // Wait for the object to be moved away + while (!APDS.proximityAvailable() || (APDS.readProximity() == 0)) {} + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/Emoji_Button/Emoji_Button.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/Emoji_Button/Emoji_Button.ino new file mode 100644 index 00000000..ff350d28 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/Emoji_Button/Emoji_Button.ino @@ -0,0 +1,92 @@ +/* + Emoji Button + + This example sends an emoji character over USB HID when the button is pressed. + + Note: Only macOS and Linux as supported at this time, and the use of + #define is generally discouraged in Arduino examples + + The circuit: + - Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board. + - Button connected to pin 3 and GND. + + Created by Don Coleman, Sandeep Mistry + + This example code is in the public domain. +*/ + +#include +#include + +// Select an OS: +//#define MACOS // You'll need to enable and select the unicode keyboard: System Preferences -> Input Sources -> + -> Others -> Unicode Hex Input +//#define LINUX + +#if !defined(MACOS) && !defined(LINUX) +#error "Please select an OS!" +#endif + +// use table: https://apps.timwhitlock.info/emoji/tables/unicode +const int bicep = 0x1f4aa; +const int punch = 0x1f44a; + +const int buttonPin = 3; + +USBKeyboard keyboard; + +int previousButtonState = HIGH; + +void setup() { + pinMode(buttonPin, INPUT_PULLUP); +} + +void loop() { + int buttonState = digitalRead(buttonPin); + + if (buttonState != previousButtonState) { + if (buttonState == LOW) { + // pressed + sentUtf8(bicep); + } else { + // released + } + + previousButtonState = buttonState; + } +} + +void sentUtf8(unsigned long c) { + String s; + +#if defined(MACOS) + // https://apple.stackexchange.com/questions/183045/how-can-i-type-unicode-characters-without-using-the-mouse + + s = String(utf8ToUtf16(c), HEX); + + for (int i = 0; i < s.length(); i++) { + keyboard.key_code(s[i], KEY_ALT); + } +#elif defined(LINUX) + s = String(c, HEX); + + keyboard.key_code('u', KEY_CTRL | KEY_SHIFT); + + for (int i = 0; i < s.length(); i++) { + keyboard.key_code(s[i]); + } +#endif + keyboard.key_code(' '); +} + +// based on https://stackoverflow.com/a/6240819/2020087 +unsigned long utf8ToUtf16(unsigned long in) { + unsigned long result; + + in -= 0x10000; + + result |= (in & 0x3ff); + result |= (in << 6) & 0x03ff0000; + result |= 0xd800dc00; + + return result; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/HardwareTest/HardwareTest.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/HardwareTest/HardwareTest.ino new file mode 100644 index 00000000..3cf67e3b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/HardwareTest/HardwareTest.ino @@ -0,0 +1,67 @@ +/* + Hardware Test + + This example performs a basic hardware test of the board which includes + testing the on-board IMU, LED and external button. + + When the button is pressed the on-board LED will turn on. + + The circuit: + - Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board. + - Button connected to pin 3 and GND. + + Created by Don Coleman, Sandeep Mistry + + This example code is in the public domain. +*/ + +#include + +const int buttonPin = 3; +const int ledPin = LED_BUILTIN; + +int buttonState = LOW; +int previousButtonState = HIGH; + +void setup() { + Serial.begin(9600); + //while (!Serial); + Serial.println("Arduino ML Workshop Hardware Test"); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1) + ; + } + + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize the push button pin as an input with (internal) pullup: + pinMode(buttonPin, INPUT_PULLUP); +} + +void loop() { + // read the state of the push button pin: + buttonState = digitalRead(buttonPin); + + // HIGH and LOW are opposite because of we are using an internal pullup resistor. + // LOW is pressed. HIGH is released. + + if (buttonState == LOW) { + // Button is pressed, turn the LED on + digitalWrite(ledPin, HIGH); + if (buttonState != previousButtonState) { + Serial.println("LED is ON"); + } + } else { + // Button is released, turn the LED off + digitalWrite(ledPin, LOW); + if (buttonState != previousButtonState) { + Serial.println("LED is OFF"); + } + } + + // save the previous state of the button since we only print + // the LED status when the state changes + previousButtonState = buttonState; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Capture/IMU_Capture.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Capture/IMU_Capture.ino new file mode 100644 index 00000000..0fd2088d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Capture/IMU_Capture.ino @@ -0,0 +1,94 @@ +/* + IMU Capture + + This example uses the on-board IMU to start reading acceleration and gyroscope + data from on-board IMU and prints it to the Serial Monitor for one second + when the significant motion is detected. + + You can also use the Serial Plotter to graph the data. + + The circuit: + - Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board. + + Created by Don Coleman, Sandeep Mistry + Modified by Dominic Pajak, Sandeep Mistry + + This example code is in the public domain. +*/ + +#include + +const float accelerationThreshold = 2.5; // threshold of significant in G's +const int numSamples = 119; + +int samplesRead = numSamples; + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1) + ; + } + + // print the header + Serial.println("aX,aY,aZ,gX,gY,gZ"); +} + +void loop() { + float aX, aY, aZ, gX, gY, gZ; + + // wait for significant motion + while (samplesRead == numSamples) { + if (IMU.accelerationAvailable()) { + // read the acceleration data + IMU.readAcceleration(aX, aY, aZ); + + // sum up the absolutes + float aSum = fabs(aX) + fabs(aY) + fabs(aZ); + + // check if it's above the threshold + if (aSum >= accelerationThreshold) { + // reset the sample read count + samplesRead = 0; + break; + } + } + } + + // check if the all the required samples have been read since + // the last time the significant motion was detected + while (samplesRead < numSamples) { + // check if both new acceleration and gyroscope data is + // available + if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) { + // read the acceleration and gyroscope data + IMU.readAcceleration(aX, aY, aZ); + IMU.readGyroscope(gX, gY, gZ); + + samplesRead++; + + // print the data in CSV format + Serial.print(aX, 3); + Serial.print(','); + Serial.print(aY, 3); + Serial.print(','); + Serial.print(aZ, 3); + Serial.print(','); + Serial.print(gX, 3); + Serial.print(','); + Serial.print(gY, 3); + Serial.print(','); + Serial.print(gZ, 3); + Serial.println(); + + if (samplesRead == numSamples) { + // add an empty line if it's the last sample + Serial.println(); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/IMU_Classifier.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/IMU_Classifier.ino new file mode 100644 index 00000000..02000fc5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/IMU_Classifier.ino @@ -0,0 +1,165 @@ +/* + IMU Classifier + + This example uses the on-board IMU to start reading acceleration and gyroscope + data from on-board IMU, once enough samples are read, it then uses a + TensorFlow Lite (Micro) model to try to classify the movement as a known gesture. + + Note: The direct use of C/C++ pointers, namespaces, and dynamic memory is generally + discouraged in Arduino examples, and in the future the TensorFlowLite library + might change to make the sketch simpler. + + The circuit: + - Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board. + + Created by Don Coleman, Sandeep Mistry + Modified by Dominic Pajak, Sandeep Mistry + + This example code is in the public domain. +*/ + +#include + +#include +#include +#include +#include +#include +#include + +#include "model.h" + +const float accelerationThreshold = 2.5; // threshold of significant in G's +const int numSamples = 119; + +int samplesRead = numSamples; + +// global variables used for TensorFlow Lite (Micro) +tflite::MicroErrorReporter tflErrorReporter; + +// pull in all the TFLM ops, you can remove this line and +// only pull in the TFLM ops you need, if would like to reduce +// the compiled size of the sketch. +tflite::AllOpsResolver tflOpsResolver; + +const tflite::Model* tflModel = nullptr; +tflite::MicroInterpreter* tflInterpreter = nullptr; +TfLiteTensor* tflInputTensor = nullptr; +TfLiteTensor* tflOutputTensor = nullptr; + +// Create a static memory buffer for TFLM, the size may need to +// be adjusted based on the model you are using +constexpr int tensorArenaSize = 8 * 1024; +byte tensorArena[tensorArenaSize] __attribute__((aligned(16))); + +// array to map gesture index to a name +const char* GESTURES[] = { + "punch", + "flex" +}; + +#define NUM_GESTURES (sizeof(GESTURES) / sizeof(GESTURES[0])) + +void setup() { + Serial.begin(9600); + while (!Serial) + ; + + // initialize the IMU + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1) + ; + } + + // print out the samples rates of the IMUs + Serial.print("Accelerometer sample rate = "); + Serial.print(IMU.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.print("Gyroscope sample rate = "); + Serial.print(IMU.gyroscopeSampleRate()); + Serial.println(" Hz"); + + Serial.println(); + + // get the TFL representation of the model byte array + tflModel = tflite::GetModel(model); + if (tflModel->version() != TFLITE_SCHEMA_VERSION) { + Serial.println("Model schema mismatch!"); + while (1) + ; + } + + // Create an interpreter to run the model + tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter); + + // Allocate memory for the model's input and output tensors + tflInterpreter->AllocateTensors(); + + // Get pointers for the model's input and output tensors + tflInputTensor = tflInterpreter->input(0); + tflOutputTensor = tflInterpreter->output(0); +} + +void loop() { + float aX, aY, aZ, gX, gY, gZ; + + // wait for significant motion + while (samplesRead == numSamples) { + if (IMU.accelerationAvailable()) { + // read the acceleration data + IMU.readAcceleration(aX, aY, aZ); + + // sum up the absolutes + float aSum = fabs(aX) + fabs(aY) + fabs(aZ); + + // check if it's above the threshold + if (aSum >= accelerationThreshold) { + // reset the sample read count + samplesRead = 0; + break; + } + } + } + + // check if the all the required samples have been read since + // the last time the significant motion was detected + while (samplesRead < numSamples) { + // check if new acceleration AND gyroscope data is available + if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) { + // read the acceleration and gyroscope data + IMU.readAcceleration(aX, aY, aZ); + IMU.readGyroscope(gX, gY, gZ); + + // normalize the IMU data between 0 to 1 and store in the model's + // input tensor + tflInputTensor->data.f[samplesRead * 6 + 0] = (aX + 4.0) / 8.0; + tflInputTensor->data.f[samplesRead * 6 + 1] = (aY + 4.0) / 8.0; + tflInputTensor->data.f[samplesRead * 6 + 2] = (aZ + 4.0) / 8.0; + tflInputTensor->data.f[samplesRead * 6 + 3] = (gX + 2000.0) / 4000.0; + tflInputTensor->data.f[samplesRead * 6 + 4] = (gY + 2000.0) / 4000.0; + tflInputTensor->data.f[samplesRead * 6 + 5] = (gZ + 2000.0) / 4000.0; + + samplesRead++; + + if (samplesRead == numSamples) { + // Run inferencing + TfLiteStatus invokeStatus = tflInterpreter->Invoke(); + if (invokeStatus != kTfLiteOk) { + Serial.println("Invoke failed!"); + while (1) + ; + return; + } + + // Loop through the output tensor values from the model + for (int i = 0; i < NUM_GESTURES; i++) { + Serial.print(GESTURES[i]); + Serial.print(": "); + Serial.println(tflOutputTensor->data.f[i], 6); + } + Serial.println(); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/model.h b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/model.h new file mode 100644 index 00000000..8f3216f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/model.h @@ -0,0 +1,3 @@ +const unsigned char model[] = { + +}; diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/README.md new file mode 100644 index 00000000..56a060ba --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/README.md @@ -0,0 +1,24 @@ +# Machine Learning on Arduino +## TensorFlow Lite gesture training tutorial + +In this tutorial we will teach a board to recognise gestures! We'll capture motion data from the [Arduino Nano 33 BLE Sense](https://store.arduino.cc/arduino-nano-33-ble-sense) board, import it into TensorFlow to train a model, and deploy a classifier onto the board using [TensorFlow Lite for microcontrollers](https://www.tensorflow.org/lite/microcontrollers/overview). + +### Credits + +This tutorial is adapted from the [workshop](https://github.com/sandeepmistry/aimldevfest-workshop-2019) Sandeep Mistry, Arduino and Don Coleman, Chariot Solutions presented at AI/ML Devfest in September 2019. + + + + +## Exercises + +* [Exercise 1: Development Environment](exercises/exercise1.md) +* [Exercise 2: Connecting the Board](exercises/exercise2.md) +* [Exercise 3: Visualizing the IMU Data](exercises/exercise3.md) +* [Exercise 4: Gather the Training Data](exercises/exercise4.md) +* [Exercise 5: Machine Learning](exercises/exercise5.md) +* [Exercise 6: Classifying IMU Data](exercises/exercise6.md) +* [Exercise 7: Gesture Controlled USB Emoji Keyboard](exercises/exercise7.md) +* [Exercise 8: Next Steps](exercises/exercise8.md) + + diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/README.md new file mode 100644 index 00000000..faa83359 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/ArduinoTensorFlowLiteTutorials/README.md @@ -0,0 +1,11 @@ +# Machine Learning on Arduino +## Arduino TensorFlow Lite Tutorials + +[![Compile Sketches status](https://github.com/arduino/ArduinoTensorFlowLiteTutorials/actions/workflows/compile-sketches.yml/badge.svg)](https://github.com/arduino/ArduinoTensorFlowLiteTutorials/actions/workflows/compile-sketches.yml) + +This Github repo contains tutorials for using TensorFlow Lite on Arduino hardware. + +* [GestureToEmoji](GestureToEmoji/) + * Use the Arduino Nano 33 BLE Sense to convert motion gestures to emojis +* [FruitToEmoji](FruitToEmoji/) + * Use the Arduino Nano 33 BLE Sense to classify fruit using the RGB color and proximity sensors diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/LICENSE b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/LICENSE new file mode 100644 index 00000000..001b337a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/LICENSE @@ -0,0 +1,674 @@ +GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/README.md b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/README.md new file mode 100644 index 00000000..ac18e10d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/README.md @@ -0,0 +1,301 @@ +# Education Introduction Library - a.k.a. EduIntro + +## Description + +Arduino library for short introduction training workshops run by Arduino Education. This library is originally made for TinkerKit. It simplifies the use of sensors and actuators when connected to an Arduino board. The goal is to plan and conduct a simple one or two hours of training workshop where users will still have the opportunity to model meaningful interactions using discrete electronic components. It consists of already implemented basic functions for electronic components. In order to use its functions, it only requires to import this library and then call its functions. + +## Installation + +### First Method + +1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries +1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. +1. Then search for EduIntro using the search bar. +1. Click on the text area and then select the specific version and install it. + +### Second Method + +1. Navigate to the Releases page. +1. Download the latest release. +1. Extract the zip file +1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library + +## Features + +- ### Self contained + + EduIntro doesn’t depend on any library. + +- ### Easy to use + + It is simple, basic and very easy to understand. The user only needs to import the library in his code and start using its functions. + +- ### Complete package for small workshops + + Basic functions of discrete electronic components have already been implemented in this library. For a small one or two hours workshop, the user does not have to implement all the basic functions for the electronic component from scratch. + +- ### Function calls + + Basic functions of the electronic components have been implemented in this library. There's no need to re-implement these basic functions from scratch. The user simply has to import the library in the project and can use any of its functions by just calling it. + +- ### Intuitive syntax + + EduIntro has a simple and intuitive syntax to handle variables and functions. + +- ### Give back + + EduIntro is free for everyone. Everyone can download and use it in their projects, assignments or anywhere for free. + +## Components and functions + +- ### Button + + - readSwitch() + - pressed() + - released() + - held() + - *Note: construct a button with Button NAME(PIN) or Button NAME(PIN,PULL_UP | PULL_DOWN), by default buttons are considered to use internal pull-ups* + +- ### DHT11 + + - update() + - readCelsius() + - readFahrenheit() + - readHumidity() + +- ### Generic + + - ### For analog inputs + + - readX() + - readY() + - readZ() + - read() + - increasing() + - decreasing() + + - ### For digital inputs + + - read() + + - ### For outputs (this extends to LEDs) + + - isPWM() + - write() + - on() + - off() + - blink() + - state() + - *Note: construct an output with e.g. Led NAME(PIN) or Led NAME(PIN,NORMAL | INVERTED), this helps with common cathode LEDs* + +- ### IMU + + - begin() + - readAcceleration() + - readGyroscope() + - read() + +- ### LED (besides all of the output functions) + + - brightness() + +- ### LM35 + + - readCelsius() + - readFahrenheit() + +- ### PIR + + - update() + - hadActivity() + - resetActivity() + - readSwitch() + - activated() + - deactivated() + - active() + +- ### Piezo + + - beep() + - noBeep() + - play() + - getMelodySize() + +- ### Potentiometer + + - read() + - readRange() + - readStep() + +- ### ServoMotor + + - write() + +- ### Thermistor + + - readCelsius() + - readFahrenheit() + +- ### WiFiComm + + - init() + - getSSID() + - getIP() + - getStatus() + - getClient() + +## Examples + +There are many examples implemented in this library. Below are shown some of the examples. + + - ### Blink + Turns on an LED on for one second, then off for one second, repeatedly + +``` C++ +#include + +Led led(D10); + +void loop() +{ + led.on(); + delay(1000); + led.off(); + delay(1000); +} +``` + + - ### Button + Changes the behavior between on and off an LED when pressing a button. + +``` C++ +#include + +Button button(D7); +Led led(D10); + +void loop() +{ + if (button.readSwitch() == LOW) { + led.on(); + } + else { + led.off(); + } +} +``` + +## Versions + +### v0.0.16 (Current stable version) + +#### November, 2021 + +* Fixed an issue with the Potentiometer class in mbed (Nano 33 BLE Sense) +* Added readRange() method for the Potentiometer +* Added inverted logic for outputs and the constructor to have e.g. *Led led(PIN, NORMAL | INVERTED)* + +### v0.0.13 + +#### April, 2021 + +* Eliminated delays in button handling +* Added second constructor for Button, choose pull_up or down + +### v0.0.12 + +#### December 16, 2019 + +* Added library dependencies + +### v0.0.11 + +#### December 9, 2019 + +* Added Nano Every by separating the two possible MEGAAVR boards (Nano Every + Uno WiFi rev2). +* Included a noBeep() function +* Added the new README with basic API description + +### v0.0.10 + +#### August 28, 2019 + +The previous release included a non-functional WiFiComm file. It has been revised and made beautification in some of the code. It has been made sure that the Classic boards work fine as it got broken in the previous release. + +### v0.0.9 + +#### August 27, 2019 + +Added support for the WiFi REV2 board and fixed the incompatibilities with servo and piezo. + +### v0.0.8 + +#### May 01, 2019 + +All classes were separated to allow adding new classes by simply copy-pasting and modifying template examples. + +### v0.0.7 + +#### April 17, 2019 + +General bug fixing: servo library not-two-servos fixed, added a new two-melodies example, fixed the button-pressed-by-default bug. Thanks to D. Spikol for bug catching and S. Mistry for reminding me that C++ inheritance is not always doing the things you expect. + +### v0.0.6 + +#### February 10, 2019 + +For a course at Aalborg University, CPH, we added the humidity and temperature sensor DHT11, the LM35 temperature sensor, a PIR sensor, and a couple more examples to the courseware. + +### v0.0.5 + +#### January 27, 2019 + +Sabas came all the way from Mexico to Malmo and made a fresh pull request. Now the library works with MKR boards! + +### v0.0.4 + +#### January 25, 2019 + +See possible results of the workshop [here](https://photos.app.goo.gl/G9B4KmBHX7FQGdYNA) + +## Contributing + +If you want to contribute to this project: + +- Report bugs and errors +- Ask for enhancements +- Create issues and pull requests +- Tell others about this library +- Contribute new protocols + +Please read [CONTRIBUTING.md](https://github.com/arduino/EduIntro/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. + +## Credits + +The Library created and maintained by D. Cuartielles, Malmo, 2018 - 2019 +WiFi REV2 compatibility by C. Rodriguez (IMU + WiFi), and D. Cuartielles (servo), Malmo, 2019 +MKR compatibility by A. Sabas, Malmo, 2019 + +Based on previous work by: + +- D. Mellis, Milano, 2006 +- T. Igoe, New York, 2008 - 2010 +- S. Fitzgerald, New York, 2010 +- D. Gomba, Torino, 2010 +- F. Vanzati, Torino, 2011 +- M. Loglio, London, 2013 +- G. Hadjikyriacou (DHT11 lib originator), ?? +- SimKard (DHT11), 2010 +- R. Tillaart (DHT11), 2011 - 2013 +- A. Dalton (DHT11), 2013 +- [Arduino community](https://www.arduino.cc) + +## Current stable version + +**number:** v0.0.16 + +**codename:** ananas + +## License + +This library is licensed under [GPLv3](https://www.gnu.org/licenses/quick-guide-gplv3.html). diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/IMU/IMU.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/IMU/IMU.ino new file mode 100644 index 00000000..c7d974f3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/IMU/IMU.ino @@ -0,0 +1,55 @@ +/* + Inertia Meassurement Unit (IMU) A.K.A. Motion + + IMPORTANT: This example is using the Arduino_LSM6DS3 library in the backed. You + need to have it installed before testing this code. If you are on + Arduino Create (the online IDE) the library will already be there. + + This example uses the embeded IMU unit in the Arduino UNO Wifi Rev2. + + The IMU captures values from the accelerometer and the gyroscope. + These values can be accesable with: + + acc_x: Returns the X value of the accelerometer. + acc_y: Returns the Y value of the accelerometer. + acc_z: Returns the Z value of the accelerometer. + gyro_x: Returns the X value of the gyroscope. + gyro_y: Returns the Y value of the gyroscope. + gyro_z: Returns the Z value of the gyroscope. + + This example code is in the public domain. + + created in Aug 2019 by C. Rodriguez + based on work by D. Cuartielles (2019), F. Vanzati (2011) and M. Loglio (2013) +*/ + +// include the EduIntro library +#include + +Motion imu; //Create the object to access the IMU unit + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); + + // initialize the IMU, if failed, stay here + if (!imu.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1) + ; + } +} + +void loop() { + // read all data from the IMU and store it in local variables + if (imu.read()) { + + // print the collected data in a row on the Serial Monitor + // or use the Serial Plotter to better understand the values + Serial.print(imu.acc_x); + Serial.print('\t'); + Serial.print(imu.acc_y); + Serial.print('\t'); + Serial.println(imu.acc_z); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/WebLed/WebLed.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/WebLed/WebLed.ino new file mode 100644 index 00000000..875e9a5b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/WebLed/WebLed.ino @@ -0,0 +1,129 @@ +/* + WebLed + + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will create a new access point (with no password). + It will then launch a new server and print out the IP address + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 13. + + If the IP address of your board is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + Adapted to EduIntro by C. Rodriguez, and D. Cuartielles (2019) + + Created by Tom Igoe (2012) +*/ + +#include + +// network related info +const char ssid[] = "ArduinoWiFi"; // your network SSID (name). Must have 8 or more characters. +const char pass[] = ""; // your network password (use for WPA, or use as key for WEP). optional, but if set, must have 8 or more characters. +int keyIndex = 0; // your network key Index number (needed only for WEP) + +// misc variables +WiFiComm MyWiFi; +int led = LED_BUILTIN; +int status = WL_IDLE_STATUS; +boolean firstTime = true; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) {}; + + MyWiFi.init(led, ssid, pass); + + // you're connected now, so print out the status + printWiFiStatus(); + Serial.print("\t SSID:"); + Serial.println(MyWiFi.getSSID()); +} + +void loop() { + // compare the previous status to the current status + if (status != MyWiFi.getStatus()) { + // it has changed update the variable + status = MyWiFi.getStatus(); + + if (status == WL_AP_CONNECTED) { + // a device has connected to the AP + Serial.println("Device connected to AP"); + } else { + if (!firstTime) { + // a device has disconnected from the AP, and we are back in listening mode + Serial.println("Device disconnected from AP"); + } + } + } + + WiFiClient client = MyWiFi.getClient(); // listen for incoming clients + + if (client) { // if you get a client, + firstTime = false; + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on
"); + client.print("Click here turn the LED off
"); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(led, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(led, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(MyWiFi.getSSID()); + + // print your WiFi shield's IP address: + IPAddress ip = MyWiFi.getIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Blink/Blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Blink/Blink.ino new file mode 100644 index 00000000..af8d9444 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Blink/Blink.ino @@ -0,0 +1,27 @@ +/* + Blink + + based on Blink, Arduino's "Hello World!" + Turns on an LED on for one second, then off for one second, repeatedly. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Led led(D10); // creating the object 'led' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + led.on(); // set the LED on + delay(1000); // wait for a second + led.off(); // set the LED off + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Button/Button.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Button/Button.ino new file mode 100644 index 00000000..50533a90 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Button/Button.ino @@ -0,0 +1,35 @@ +/* + Button + + Changes the behavior between on and off an LED when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + // check the switchState of the button + // each time it is pressed, it toggles the LED + // when LOW, light should go on + if (button.readSwitch() == LOW) { + led.on(); + } else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ButtonStates/ButtonStates.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ButtonStates/ButtonStates.ino new file mode 100644 index 00000000..75bfccc4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ButtonStates/ButtonStates.ino @@ -0,0 +1,35 @@ +/* + ButtonStates + + Test the different Button methods: pressed, released, held + and getSwitch. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +Button btn(D7); + +void setup() { + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() { + if (btn.pressed()) + Serial.println("pressed"); + if (btn.held()) + Serial.println("held"); + if (btn.released()) { + Serial.println("released"); + Serial.print("switch: "); + Serial.println(btn.readSwitch()); + } + + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/DHT11/DHT11.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/DHT11/DHT11.ino new file mode 100644 index 00000000..6af178f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/DHT11/DHT11.ino @@ -0,0 +1,43 @@ +/* +DHT11 + +This example reads a DHT11 sensor hooked up on pin D7. Reads both +temperature and humidity and sends it to the Serial port + +created in Feb 2019 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +DHT11 dht11(D7); // creating the object sensor on pin 'D7' + +int C; // temperature C readings are integers +float F; // temperature F readings are returned in float format +int H; // humidity readings are integers + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + dht11.update(); + + C = dht11.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = dht11.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + H = dht11.readHumidity(); // Reading the humidity index + + // Print the collected data in a row on the Serial Monitor + Serial.print("H: "); + Serial.print(H); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Empty/Empty.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Empty/Empty.ino new file mode 100644 index 00000000..654f8bb1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Empty/Empty.ino @@ -0,0 +1,8 @@ +#include + +void setup() { + //Serial.begin(9600); +} + +void loop() { +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/LM35/LM35.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/LM35/LM35.ino new file mode 100644 index 00000000..9a58477d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/LM35/LM35.ino @@ -0,0 +1,42 @@ +/* +LM35 + +This example uses an LM35 (or equivalent) sensor hooked up on pin A0. + +Three values are displayed on the Serial Monitor every second: +- the value between 0 and 1023 that represent the Analog Input reading +- the temperature expressed in Celsius degrees +- the temperature expressed in Fahrenheit dedegrees + +created in Feb 2019 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +LM35 lm35(A0); // creating the object 'lm35' on pin A0 + +float C, F; // temperature readings are returned in float format + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + C = lm35.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = lm35.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + + // Print the collected data in a row on the Serial Monitor + Serial.print("Analog reading: "); // Reading the analog value from the thermistor + Serial.print(lm35.read()); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/LightSensor/LightSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/LightSensor/LightSensor.ino new file mode 100644 index 00000000..b24b538b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/LightSensor/LightSensor.ino @@ -0,0 +1,42 @@ +/* + Read values from an LDR Analog Sensor connected to A0, + then uses the result to set the brightness on an LED + connected on D9. Also prints the values on the + serial monitor. + + created in Aug 2018 by D. Cuartielles + based on work by T. Igoe (2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +#include + +LightSensor ldr(A0); //create the "ldr" object on pin A0 + +Led led(D10); //create the "led" object on pin D10 + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // store the ldr values into a variable called brightnessVal + int brightnessVal = ldr.read(); + + // set the led brightness + led.brightness(brightnessVal); + + //to have it at full brightness + //when it's dark, uncomment this line: + //led.brightness(1023 - brightnessVal); + + // print the results to the serial monitor: + Serial.print("brightness = "); + Serial.println(brightnessVal); + + + // wait 10 milliseconds before the next loop + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Melody/Melody.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Melody/Melody.ino new file mode 100644 index 00000000..f008da3c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Melody/Melody.ino @@ -0,0 +1,35 @@ +/* + Melody + + Plays a song stored in an array, repeatedly. You should connect + a speaker to pin D10 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + piezo.play(melody); // play the song + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MelodyButton/MelodyButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MelodyButton/MelodyButton.ino new file mode 100644 index 00000000..0185d5ea --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MelodyButton/MelodyButton.ino @@ -0,0 +1,39 @@ +/* + MelodyButton + + Plays a song stored in an array, when pressing a button. You should connect + a speaker to pin D10 and a button to pin D7 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Button button(D7); // creating the object 'button' on pin D7 + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play(melody); // play the song + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino new file mode 100644 index 00000000..d5dc872f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino @@ -0,0 +1,45 @@ +/* + MelodyButtonTwoSounds + + Plays a song stored in an array, when pressing a button, a different one + when releasing the button. You should connect a speaker to pin D10 and a + button to pin D7. Melodies are stored in arrays ending with NULL + + created in Apr 2019 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc. +// add the NULL to signify the end of the array +int melody1[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + SILENCE, 4, NULL }; + +int melody2[] = { NOTE_D4, 4, + NOTE_C3, 8, + NOTE_F3, 8, + SILENCE, 4, NULL }; + +Button button(D7); // creating the object 'button' on pin D7 + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play(melody1); + } + if (button.released()) { + piezo.play(melody2); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MosFet/MosFet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MosFet/MosFet.ino new file mode 100644 index 00000000..92669367 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/MosFet/MosFet.ino @@ -0,0 +1,27 @@ +/* +Write a signal to a MosFet transistor using a Potentiometer. + +created in Aug 2018 by D. Cuartielles +based on work by M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +MosFet mos(D3); //create the mos object on pin D3 +Potentiometer pot(A0); //create the pot object on pin A0 + +void setup() { + //nothing here +} + +void loop() { + int val = pot.read(); //assign to a "val" variable + //the potentiometer values + + mos.write(val); //assign the values to the mosfet + + delay(10); //rest for 10 milliseconds. +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PIR/PIR.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PIR/PIR.ino new file mode 100644 index 00000000..85459815 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PIR/PIR.ino @@ -0,0 +1,34 @@ +/* + PIR + + Changes the behavior between on and off an LED when a PIR sensor is activated. + Assumes the use of a PIR sensor that needs no pull-up + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + */ + +// include the EduIntro library +#include + +PIR pir(D7); // creating the object 'pir' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + // check the state of the PIR sensor + // if you just want to detect the turn from not active to active + // use pir.activated() instead + if (pir.active() == HIGH) { + led.on(); + } else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PIRStates/PIRStates.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PIRStates/PIRStates.ino new file mode 100644 index 00000000..e6c43f06 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PIRStates/PIRStates.ino @@ -0,0 +1,40 @@ +/* + PIRStates + + Test the different PIR methods: activated, deactivated, active, + readSwitch, hadActivity, and resetActivity + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +PIR pir(D7); + +void setup() { + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() { + if (pir.activated()) + Serial.println("activited"); + if (pir.active()) + Serial.println("still active"); + if (pir.deactivated()) { + Serial.println("deactivated"); + Serial.print("switch: "); + Serial.println(pir.readSwitch()); + } + if (!pir.activated() && pir.hadActivity()) { + Serial.print("had activity: "); + Serial.println(pir.hadActivity()); + pir.resetActivity(); + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PhysicalPixel/PhysicalPixel.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PhysicalPixel/PhysicalPixel.ino new file mode 100644 index 00000000..bb1f5ef5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/PhysicalPixel/PhysicalPixel.ino @@ -0,0 +1,51 @@ +/* +Physical Pixel + +An example of using the Arduino board to receive data from the computer. In +this case, the Arduino boards turns on an LED when it receives the character +'H', and turns off the LED when it receives the character 'L'. + +The data can be sent from the Arduino Serial Monitor, or another program like +Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. + +The circuit: +- LED connected from digital pin 13 to ground + + created in Aug 2018 by D. Cuartielles + based on work by D. Mellis (2006), T. Igoe and S. Fitzgerald (2011) + + This example code is in the public domain. + */ + +#include + +Led led(D13); + +int incomingByte; // a variable to read incoming serial data + +void setup() { + Serial.begin(9600); +} + + +void loop() { + // see if there's incoming serial data: + if (Serial.available() > 0) { + + // read the oldest byte in the serial buffer: + incomingByte = Serial.read(); + + // if it's a capital H (ASCII 72), turn on the LED: + if (incomingByte == 'H') { + led.on(); + } + // if it's an L (ASCII 76) turn off the LED: + if (incomingByte == 'L') { + led.off(); + } + + if (incomingByte == 'S') { + Serial.println(led.state(), DEC); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Potentiometer/Potentiometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Potentiometer/Potentiometer.ino new file mode 100644 index 00000000..d3c21f91 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Potentiometer/Potentiometer.ino @@ -0,0 +1,40 @@ +/* + Read the value of a Potentiometer connected to A0, + then uses the results to write the brightness on + an LED connected on D10. Also prints the values + on the serial monitor. + + created in Aug 2018 by D. Cuartielles + based on work by T. Igoe (2008, 2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +Led led(D10); // creating the object 'led' on pin D10 + +int brightnessVal = 0; // value read from the pot + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // read the potentiometer's value: + brightnessVal = pot.read(); + + // set the led brightness + led.brightness(brightnessVal); + + // print the results to the serial monitor: + Serial.print("brightness = "); + Serial.println(brightnessVal); + + + // wait 10 milliseconds before the next loop + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Relay/Relay.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Relay/Relay.ino new file mode 100644 index 00000000..8f5bf226 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Relay/Relay.ino @@ -0,0 +1,33 @@ +/* + Relay + + Turns on and off a Relay connected to D10, when pressing a + Button attached to D7. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Button btn(D7); // creating the object 'button' on pin D7 + +Relay relay(D10); // creating the object 'relay' on pin D10 + +void setup() { + // nothing to add here +} + +void loop() { + // check the switch state + if (btn.readSwitch() == HIGH) { + relay.on(); + } else { + relay.off(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/RisingDecreasing/RisingDecreasing.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/RisingDecreasing/RisingDecreasing.ino new file mode 100644 index 00000000..29c8a138 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/RisingDecreasing/RisingDecreasing.ino @@ -0,0 +1,30 @@ +/* +Increasing & Decreasing + + this sketch shows how to use increasing() and + decreasing() on analog inputs. + + increasing() returns HIGH when values are rising, + decreasing() is HIGH when values are decreasing + + created in Aug 2018 by D. Cuartielles + based on work by M. Loglio (2013) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Thermistor therm(A0); // creating the object 'therm' on pin A0 + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + if (therm.increasing()) Serial.println("increasing"); + if (therm.decreasing()) Serial.println("decreasing"); + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Servo/Servo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Servo/Servo.ino new file mode 100644 index 00000000..b3c27edf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Servo/Servo.ino @@ -0,0 +1,28 @@ +/* + Servo + + Makes a Servo change angle after some time. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + servo.write(90); + delay(1000); // wait for a second + servo.write(0); + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoButton/ServoButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoButton/ServoButton.ino new file mode 100644 index 00000000..8c998f5f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoButton/ServoButton.ino @@ -0,0 +1,32 @@ +/* + Makes a Servo change angle when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + // check the switchState of the button + // each time it is pressed, it toggles the servo's position + // when LOW, light should go on + if (button.readSwitch() == LOW) { + servo.write(90); + } else { + servo.write(0); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoKnob/ServoKnob.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoKnob/ServoKnob.ino new file mode 100644 index 00000000..95f0532d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoKnob/ServoKnob.ino @@ -0,0 +1,44 @@ +/* + Makes a Servo change angle when turning a potentiometer. + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + + based on https://www.arduino.cc/en/tutorial/knob + */ + +// include the EduIntro library +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + +int potVal = 0; // value read from the pot +int angleVal = 0; // value of the angle to set the servo + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // read the potentiometer's value: + potVal = pot.read(); + + // map the data from the sensor (0..1023) to + // one the servo can take (0..180) + angleVal = map(potVal, 0, 1023, 0, 180); + + // set the led brightness + servo.write(angleVal); + + // print the results to the serial monitor: + Serial.print("angle = "); + Serial.println(angleVal); + + + // wait 100 milliseconds before the next loop + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoKnobContinuous/ServoKnobContinuous.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoKnobContinuous/ServoKnobContinuous.ino new file mode 100644 index 00000000..fc94f1de --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/ServoKnobContinuous/ServoKnobContinuous.ino @@ -0,0 +1,53 @@ +/* + Makes a Continuous Servo change speed when turning a potentiometer. + Prints the different motor states to the serial port. + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + + based on https://www.arduino.cc/en/tutorial/knob + */ + +// include the EduIntro library +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + +int potVal = 0; // value read from the pot +int angleVal = 0; // value of the angle to set the servo + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // read the potentiometer's value: + potVal = pot.read(); + + // map the data from the sensor (0..1023) to + // one the servo can take (0..180) + angleVal = map(potVal, 0, 1023, 0, 180); + + // set the led brightness + servo.write(angleVal); + + // Signify it different events for the motor + if (angleVal == 90) + Serial.println("Motor Stop"); + if (angleVal <= 1) + Serial.println("Motor Max clockwise"); + if (angleVal >= 179) + Serial.println("Motor Max counter clockwise"); + + // print the results to the serial monitor: + Serial.print("angle = "); + Serial.println(angleVal); + + + // wait 100 milliseconds before the next loop + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Thermistor/Thermistor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Thermistor/Thermistor.ino new file mode 100644 index 00000000..4a136b41 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_board/all/Thermistor/Thermistor.ino @@ -0,0 +1,40 @@ +/* +Thermistor hooked up on pin A0. + +Three values are displayed on the Serial Monitor every second: +- the value between 0 and 1023 that represent the Analog Input reading +- the temperature expressed in Celsius degrees +- the temperature expressed in Fahrenheit dedegrees + +created in Aug 2018 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +Thermistor therm(A0); // creating the object 'therm' on pin A0 + +float C, F; // temperature readings are returned in float format + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + C = therm.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = therm.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + + // Print the collected data in a row on the Serial Monitor + Serial.print("Analog reading: "); // Reading the analog value from the thermistor + Serial.print(therm.read()); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Blink/Blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Blink/Blink.ino new file mode 100644 index 00000000..af8d9444 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Blink/Blink.ino @@ -0,0 +1,27 @@ +/* + Blink + + based on Blink, Arduino's "Hello World!" + Turns on an LED on for one second, then off for one second, repeatedly. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Led led(D10); // creating the object 'led' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + led.on(); // set the LED on + delay(1000); // wait for a second + led.off(); // set the LED off + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Button/Button.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Button/Button.ino new file mode 100644 index 00000000..50533a90 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Button/Button.ino @@ -0,0 +1,35 @@ +/* + Button + + Changes the behavior between on and off an LED when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + // check the switchState of the button + // each time it is pressed, it toggles the LED + // when LOW, light should go on + if (button.readSwitch() == LOW) { + led.on(); + } else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ButtonStates/ButtonStates.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ButtonStates/ButtonStates.ino new file mode 100644 index 00000000..75bfccc4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ButtonStates/ButtonStates.ino @@ -0,0 +1,35 @@ +/* + ButtonStates + + Test the different Button methods: pressed, released, held + and getSwitch. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +Button btn(D7); + +void setup() { + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() { + if (btn.pressed()) + Serial.println("pressed"); + if (btn.held()) + Serial.println("held"); + if (btn.released()) { + Serial.println("released"); + Serial.print("switch: "); + Serial.println(btn.readSwitch()); + } + + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/DHT11/DHT11.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/DHT11/DHT11.ino new file mode 100644 index 00000000..6af178f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/DHT11/DHT11.ino @@ -0,0 +1,43 @@ +/* +DHT11 + +This example reads a DHT11 sensor hooked up on pin D7. Reads both +temperature and humidity and sends it to the Serial port + +created in Feb 2019 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +DHT11 dht11(D7); // creating the object sensor on pin 'D7' + +int C; // temperature C readings are integers +float F; // temperature F readings are returned in float format +int H; // humidity readings are integers + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + dht11.update(); + + C = dht11.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = dht11.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + H = dht11.readHumidity(); // Reading the humidity index + + // Print the collected data in a row on the Serial Monitor + Serial.print("H: "); + Serial.print(H); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Empty/Empty.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Empty/Empty.ino new file mode 100644 index 00000000..654f8bb1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Empty/Empty.ino @@ -0,0 +1,8 @@ +#include + +void setup() { + //Serial.begin(9600); +} + +void loop() { +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/LM35/LM35.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/LM35/LM35.ino new file mode 100644 index 00000000..9a58477d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/LM35/LM35.ino @@ -0,0 +1,42 @@ +/* +LM35 + +This example uses an LM35 (or equivalent) sensor hooked up on pin A0. + +Three values are displayed on the Serial Monitor every second: +- the value between 0 and 1023 that represent the Analog Input reading +- the temperature expressed in Celsius degrees +- the temperature expressed in Fahrenheit dedegrees + +created in Feb 2019 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +LM35 lm35(A0); // creating the object 'lm35' on pin A0 + +float C, F; // temperature readings are returned in float format + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + C = lm35.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = lm35.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + + // Print the collected data in a row on the Serial Monitor + Serial.print("Analog reading: "); // Reading the analog value from the thermistor + Serial.print(lm35.read()); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/LightSensor/LightSensor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/LightSensor/LightSensor.ino new file mode 100644 index 00000000..b24b538b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/LightSensor/LightSensor.ino @@ -0,0 +1,42 @@ +/* + Read values from an LDR Analog Sensor connected to A0, + then uses the result to set the brightness on an LED + connected on D9. Also prints the values on the + serial monitor. + + created in Aug 2018 by D. Cuartielles + based on work by T. Igoe (2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +#include + +LightSensor ldr(A0); //create the "ldr" object on pin A0 + +Led led(D10); //create the "led" object on pin D10 + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // store the ldr values into a variable called brightnessVal + int brightnessVal = ldr.read(); + + // set the led brightness + led.brightness(brightnessVal); + + //to have it at full brightness + //when it's dark, uncomment this line: + //led.brightness(1023 - brightnessVal); + + // print the results to the serial monitor: + Serial.print("brightness = "); + Serial.println(brightnessVal); + + + // wait 10 milliseconds before the next loop + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Melody/Melody.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Melody/Melody.ino new file mode 100644 index 00000000..f008da3c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Melody/Melody.ino @@ -0,0 +1,35 @@ +/* + Melody + + Plays a song stored in an array, repeatedly. You should connect + a speaker to pin D10 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + piezo.play(melody); // play the song + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MelodyButton/MelodyButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MelodyButton/MelodyButton.ino new file mode 100644 index 00000000..0185d5ea --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MelodyButton/MelodyButton.ino @@ -0,0 +1,39 @@ +/* + MelodyButton + + Plays a song stored in an array, when pressing a button. You should connect + a speaker to pin D10 and a button to pin D7 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Button button(D7); // creating the object 'button' on pin D7 + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play(melody); // play the song + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino new file mode 100644 index 00000000..d5dc872f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino @@ -0,0 +1,45 @@ +/* + MelodyButtonTwoSounds + + Plays a song stored in an array, when pressing a button, a different one + when releasing the button. You should connect a speaker to pin D10 and a + button to pin D7. Melodies are stored in arrays ending with NULL + + created in Apr 2019 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc. +// add the NULL to signify the end of the array +int melody1[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + SILENCE, 4, NULL }; + +int melody2[] = { NOTE_D4, 4, + NOTE_C3, 8, + NOTE_F3, 8, + SILENCE, 4, NULL }; + +Button button(D7); // creating the object 'button' on pin D7 + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play(melody1); + } + if (button.released()) { + piezo.play(melody2); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MosFet/MosFet.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MosFet/MosFet.ino new file mode 100644 index 00000000..92669367 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/MosFet/MosFet.ino @@ -0,0 +1,27 @@ +/* +Write a signal to a MosFet transistor using a Potentiometer. + +created in Aug 2018 by D. Cuartielles +based on work by M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +MosFet mos(D3); //create the mos object on pin D3 +Potentiometer pot(A0); //create the pot object on pin A0 + +void setup() { + //nothing here +} + +void loop() { + int val = pot.read(); //assign to a "val" variable + //the potentiometer values + + mos.write(val); //assign the values to the mosfet + + delay(10); //rest for 10 milliseconds. +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PIR/PIR.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PIR/PIR.ino new file mode 100644 index 00000000..85459815 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PIR/PIR.ino @@ -0,0 +1,34 @@ +/* + PIR + + Changes the behavior between on and off an LED when a PIR sensor is activated. + Assumes the use of a PIR sensor that needs no pull-up + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + */ + +// include the EduIntro library +#include + +PIR pir(D7); // creating the object 'pir' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + // check the state of the PIR sensor + // if you just want to detect the turn from not active to active + // use pir.activated() instead + if (pir.active() == HIGH) { + led.on(); + } else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PIRStates/PIRStates.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PIRStates/PIRStates.ino new file mode 100644 index 00000000..e6c43f06 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PIRStates/PIRStates.ino @@ -0,0 +1,40 @@ +/* + PIRStates + + Test the different PIR methods: activated, deactivated, active, + readSwitch, hadActivity, and resetActivity + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +PIR pir(D7); + +void setup() { + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() { + if (pir.activated()) + Serial.println("activited"); + if (pir.active()) + Serial.println("still active"); + if (pir.deactivated()) { + Serial.println("deactivated"); + Serial.print("switch: "); + Serial.println(pir.readSwitch()); + } + if (!pir.activated() && pir.hadActivity()) { + Serial.print("had activity: "); + Serial.println(pir.hadActivity()); + pir.resetActivity(); + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PhysicalPixel/PhysicalPixel.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PhysicalPixel/PhysicalPixel.ino new file mode 100644 index 00000000..bb1f5ef5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/PhysicalPixel/PhysicalPixel.ino @@ -0,0 +1,51 @@ +/* +Physical Pixel + +An example of using the Arduino board to receive data from the computer. In +this case, the Arduino boards turns on an LED when it receives the character +'H', and turns off the LED when it receives the character 'L'. + +The data can be sent from the Arduino Serial Monitor, or another program like +Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. + +The circuit: +- LED connected from digital pin 13 to ground + + created in Aug 2018 by D. Cuartielles + based on work by D. Mellis (2006), T. Igoe and S. Fitzgerald (2011) + + This example code is in the public domain. + */ + +#include + +Led led(D13); + +int incomingByte; // a variable to read incoming serial data + +void setup() { + Serial.begin(9600); +} + + +void loop() { + // see if there's incoming serial data: + if (Serial.available() > 0) { + + // read the oldest byte in the serial buffer: + incomingByte = Serial.read(); + + // if it's a capital H (ASCII 72), turn on the LED: + if (incomingByte == 'H') { + led.on(); + } + // if it's an L (ASCII 76) turn off the LED: + if (incomingByte == 'L') { + led.off(); + } + + if (incomingByte == 'S') { + Serial.println(led.state(), DEC); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Potentiometer/Potentiometer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Potentiometer/Potentiometer.ino new file mode 100644 index 00000000..d3c21f91 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Potentiometer/Potentiometer.ino @@ -0,0 +1,40 @@ +/* + Read the value of a Potentiometer connected to A0, + then uses the results to write the brightness on + an LED connected on D10. Also prints the values + on the serial monitor. + + created in Aug 2018 by D. Cuartielles + based on work by T. Igoe (2008, 2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +Led led(D10); // creating the object 'led' on pin D10 + +int brightnessVal = 0; // value read from the pot + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // read the potentiometer's value: + brightnessVal = pot.read(); + + // set the led brightness + led.brightness(brightnessVal); + + // print the results to the serial monitor: + Serial.print("brightness = "); + Serial.println(brightnessVal); + + + // wait 10 milliseconds before the next loop + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Relay/Relay.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Relay/Relay.ino new file mode 100644 index 00000000..8f5bf226 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Relay/Relay.ino @@ -0,0 +1,33 @@ +/* + Relay + + Turns on and off a Relay connected to D10, when pressing a + Button attached to D7. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Button btn(D7); // creating the object 'button' on pin D7 + +Relay relay(D10); // creating the object 'relay' on pin D10 + +void setup() { + // nothing to add here +} + +void loop() { + // check the switch state + if (btn.readSwitch() == HIGH) { + relay.on(); + } else { + relay.off(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/RisingDecreasing/RisingDecreasing.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/RisingDecreasing/RisingDecreasing.ino new file mode 100644 index 00000000..29c8a138 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/RisingDecreasing/RisingDecreasing.ino @@ -0,0 +1,30 @@ +/* +Increasing & Decreasing + + this sketch shows how to use increasing() and + decreasing() on analog inputs. + + increasing() returns HIGH when values are rising, + decreasing() is HIGH when values are decreasing + + created in Aug 2018 by D. Cuartielles + based on work by M. Loglio (2013) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Thermistor therm(A0); // creating the object 'therm' on pin A0 + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + if (therm.increasing()) Serial.println("increasing"); + if (therm.decreasing()) Serial.println("decreasing"); + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Servo/Servo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Servo/Servo.ino new file mode 100644 index 00000000..b3c27edf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Servo/Servo.ino @@ -0,0 +1,28 @@ +/* + Servo + + Makes a Servo change angle after some time. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + servo.write(90); + delay(1000); // wait for a second + servo.write(0); + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoButton/ServoButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoButton/ServoButton.ino new file mode 100644 index 00000000..8c998f5f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoButton/ServoButton.ino @@ -0,0 +1,32 @@ +/* + Makes a Servo change angle when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + // check the switchState of the button + // each time it is pressed, it toggles the servo's position + // when LOW, light should go on + if (button.readSwitch() == LOW) { + servo.write(90); + } else { + servo.write(0); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoKnob/ServoKnob.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoKnob/ServoKnob.ino new file mode 100644 index 00000000..95f0532d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoKnob/ServoKnob.ino @@ -0,0 +1,44 @@ +/* + Makes a Servo change angle when turning a potentiometer. + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + + based on https://www.arduino.cc/en/tutorial/knob + */ + +// include the EduIntro library +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + +int potVal = 0; // value read from the pot +int angleVal = 0; // value of the angle to set the servo + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // read the potentiometer's value: + potVal = pot.read(); + + // map the data from the sensor (0..1023) to + // one the servo can take (0..180) + angleVal = map(potVal, 0, 1023, 0, 180); + + // set the led brightness + servo.write(angleVal); + + // print the results to the serial monitor: + Serial.print("angle = "); + Serial.println(angleVal); + + + // wait 100 milliseconds before the next loop + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoKnobContinuous/ServoKnobContinuous.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoKnobContinuous/ServoKnobContinuous.ino new file mode 100644 index 00000000..fc94f1de --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/ServoKnobContinuous/ServoKnobContinuous.ino @@ -0,0 +1,53 @@ +/* + Makes a Continuous Servo change speed when turning a potentiometer. + Prints the different motor states to the serial port. + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + + based on https://www.arduino.cc/en/tutorial/knob + */ + +// include the EduIntro library +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + +int potVal = 0; // value read from the pot +int angleVal = 0; // value of the angle to set the servo + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // read the potentiometer's value: + potVal = pot.read(); + + // map the data from the sensor (0..1023) to + // one the servo can take (0..180) + angleVal = map(potVal, 0, 1023, 0, 180); + + // set the led brightness + servo.write(angleVal); + + // Signify it different events for the motor + if (angleVal == 90) + Serial.println("Motor Stop"); + if (angleVal <= 1) + Serial.println("Motor Max clockwise"); + if (angleVal >= 179) + Serial.println("Motor Max counter clockwise"); + + // print the results to the serial monitor: + Serial.print("angle = "); + Serial.println(angleVal); + + + // wait 100 milliseconds before the next loop + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Thermistor/Thermistor.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Thermistor/Thermistor.ino new file mode 100644 index 00000000..4a136b41 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/by_topic/Thermistor/Thermistor.ino @@ -0,0 +1,40 @@ +/* +Thermistor hooked up on pin A0. + +Three values are displayed on the Serial Monitor every second: +- the value between 0 and 1023 that represent the Analog Input reading +- the temperature expressed in Celsius degrees +- the temperature expressed in Fahrenheit dedegrees + +created in Aug 2018 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +Thermistor therm(A0); // creating the object 'therm' on pin A0 + +float C, F; // temperature readings are returned in float format + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + C = therm.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = therm.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + + // Print the collected data in a row on the Serial Monitor + Serial.print("Analog reading: "); // Reading the analog value from the thermistor + Serial.print(therm.read()); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/cardboardKeyboard/ButtonStatesKeyboard/ButtonStatesKeyboard.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/cardboardKeyboard/ButtonStatesKeyboard/ButtonStatesKeyboard.ino new file mode 100644 index 00000000..248c697d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/cardboardKeyboard/ButtonStatesKeyboard/ButtonStatesKeyboard.ino @@ -0,0 +1,56 @@ +/* + ButtonStates for Cardboard Keyboard + + This example code is in the public domain. + + created in Jan 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include +#include + +// reconfigure these pins to be the ones where you plug your wires +byte btnPins[] = { D9, D10, D11, D12 }; + +// which are the keys you will be using ... ? +byte key[] = { 'a', 'd', KEY_UP_ARROW, ' ' }; + +// array to control the buttons +Button btn[] = { + Button(btnPins[0]), + Button(btnPins[1]), + Button(btnPins[2]), + Button(btnPins[3]), +}; + +void setup() { + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); + + // initialize the keyboard controller + Keyboard.begin(); +} + +void loop() { + for (int i; i < 4; i++) { + if (btn[i].pressed()) { + Serial.print("pressed pin: "); + Serial.println(btnPins[i]); + Keyboard.press(key[i]); + } + if (btn[i].held()) + Serial.print("held pin: "); + Serial.println(btnPins[i]); + if (btn[i].released()) { + Serial.print("released pin: "); + Serial.println(btnPins[i]); + Serial.print("switch pin "); + Serial.print(btnPins[i]); + Serial.print(": "); + Serial.println(btn[i].readSwitch()); + Keyboard.release(key[i]); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Blink/Blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Blink/Blink.ino new file mode 100644 index 00000000..af8d9444 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Blink/Blink.ino @@ -0,0 +1,27 @@ +/* + Blink + + based on Blink, Arduino's "Hello World!" + Turns on an LED on for one second, then off for one second, repeatedly. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Led led(D10); // creating the object 'led' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + led.on(); // set the LED on + delay(1000); // wait for a second + led.off(); // set the LED off + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Button/Button.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Button/Button.ino new file mode 100644 index 00000000..50533a90 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Button/Button.ino @@ -0,0 +1,35 @@ +/* + Button + + Changes the behavior between on and off an LED when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + // check the switchState of the button + // each time it is pressed, it toggles the LED + // when LOW, light should go on + if (button.readSwitch() == LOW) { + led.on(); + } else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/ButtonStates/ButtonStates.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/ButtonStates/ButtonStates.ino new file mode 100644 index 00000000..75bfccc4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/ButtonStates/ButtonStates.ino @@ -0,0 +1,35 @@ +/* + ButtonStates + + Test the different Button methods: pressed, released, held + and getSwitch. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +Button btn(D7); + +void setup() { + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() { + if (btn.pressed()) + Serial.println("pressed"); + if (btn.held()) + Serial.println("held"); + if (btn.released()) { + Serial.println("released"); + Serial.print("switch: "); + Serial.println(btn.readSwitch()); + } + + delay(50); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Empty/Empty.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Empty/Empty.ino new file mode 100644 index 00000000..654f8bb1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Empty/Empty.ino @@ -0,0 +1,8 @@ +#include + +void setup() { + //Serial.begin(9600); +} + +void loop() { +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Melody/Melody.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Melody/Melody.ino new file mode 100644 index 00000000..f008da3c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Melody/Melody.ino @@ -0,0 +1,35 @@ +/* + Melody + + Plays a song stored in an array, repeatedly. You should connect + a speaker to pin D10 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + piezo.play(melody); // play the song + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/MelodyButton/MelodyButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/MelodyButton/MelodyButton.ino new file mode 100644 index 00000000..0185d5ea --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/MelodyButton/MelodyButton.ino @@ -0,0 +1,39 @@ +/* + MelodyButton + + Plays a song stored in an array, when pressing a button. You should connect + a speaker to pin D10 and a button to pin D7 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Button button(D7); // creating the object 'button' on pin D7 + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() { + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play(melody); // play the song + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Servo/Servo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Servo/Servo.ino new file mode 100644 index 00000000..b3c27edf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/Servo/Servo.ino @@ -0,0 +1,28 @@ +/* + Servo + + Makes a Servo change angle after some time. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + servo.write(90); + delay(1000); // wait for a second + servo.write(0); + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/ServoButton/ServoButton.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/ServoButton/ServoButton.ino new file mode 100644 index 00000000..8c998f5f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/EduIntro/examples/courseware/workshop_1h/ServoButton/ServoButton.ino @@ -0,0 +1,32 @@ +/* + Makes a Servo change angle when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { + //nothing here +} + +void loop() { + // check the switchState of the button + // each time it is pressed, it toggles the servo's position + // when LOW, light should go on + if (button.readSwitch() == LOW) { + servo.write(90); + } else { + servo.write(0); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/LICENSE.txt b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/LICENSE.txt new file mode 100644 index 00000000..0e259d42 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/LICENSE.txt @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/README.adoc b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/README.adoc new file mode 100644 index 00000000..9ec43131 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/README.adoc @@ -0,0 +1,13 @@ += Built-in Examples = + +image:https://github.com/arduino/arduino-examples/workflows/Compile%20Examples/badge.svg["Compile Examples Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Compile+Examples"] +image:https://github.com/arduino/arduino-examples/workflows/Code%20Formatting%20Check/badge.svg["Code Formatting Check Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Code+Formatting+Check"] +image:https://github.com/arduino/arduino-examples/workflows/Spell%20Check/badge.svg["Spell Check Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Spell+Check"] + +These are the example Arduino sketches built in to the Arduino IDE. + +They were originally hosted at `https://github.com/arduino/Arduino/tree/master/build/shared` + +For more information about these examples please visit their tutorials at + +https://www.arduino.cc/en/Tutorial/BuiltInExamples + diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino new file mode 100644 index 00000000..d1dd3210 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino @@ -0,0 +1,26 @@ +/* + AnalogReadSerial + + Reads an analog input on pin 0, prints the result to the Serial Monitor. + Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). + Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogReadSerial +*/ + +// the setup routine runs once when you press reset: +void setup() { + // initialize serial communication at 9600 bits per second: + Serial.begin(9600); +} + +// the loop routine runs over and over again forever: +void loop() { + // read the input on analog pin 0: + int sensorValue = analogRead(A0); + // print out the value you read: + Serial.println(sensorValue); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/BareMinimum/BareMinimum.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/BareMinimum/BareMinimum.ino new file mode 100644 index 00000000..ab623210 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/BareMinimum/BareMinimum.ino @@ -0,0 +1,7 @@ +void setup() { + // put your setup code here, to run once: +} + +void loop() { + // put your main code here, to run repeatedly: +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/Blink/Blink.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/Blink/Blink.ino new file mode 100644 index 00000000..9f8b4724 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/Blink/Blink.ino @@ -0,0 +1,37 @@ +/* + Blink + + Turns an LED on for one second, then off for one second, repeatedly. + + Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO + it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to + the correct LED pin independent of which board is used. + If you want to know what pin the on-board LED is connected to on your Arduino + model, check the Technical Specs of your board at: + https://www.arduino.cc/en/Main/Products + + modified 8 May 2014 + by Scott Fitzgerald + modified 2 Sep 2016 + by Arturo Guadalupi + modified 8 Sep 2016 + by Colby Newman + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink +*/ + +// the setup function runs once when you press reset or power the board +void setup() { + // initialize digital pin LED_BUILTIN as an output. + pinMode(LED_BUILTIN, OUTPUT); +} + +// the loop function runs over and over again forever +void loop() { + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino new file mode 100644 index 00000000..3456f2f5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino @@ -0,0 +1,29 @@ +/* + DigitalReadSerial + + Reads a digital input on pin 2, prints the result to the Serial Monitor + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/DigitalReadSerial +*/ + +// digital pin 2 has a pushbutton attached to it. Give it a name: +int pushButton = 2; + +// the setup routine runs once when you press reset: +void setup() { + // initialize serial communication at 9600 bits per second: + Serial.begin(9600); + // make the pushbutton's pin an input: + pinMode(pushButton, INPUT); +} + +// the loop routine runs over and over again forever: +void loop() { + // read the input pin: + int buttonState = digitalRead(pushButton); + // print out the state of the button: + Serial.println(buttonState); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/Fade/Fade.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/Fade/Fade.ino new file mode 100644 index 00000000..4637979b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/Fade/Fade.ino @@ -0,0 +1,40 @@ +/* + Fade + + This example shows how to fade an LED on pin 9 using the analogWrite() + function. + + The analogWrite() function uses PWM, so if you want to change the pin you're + using, be sure to use another PWM capable pin. On most Arduino, the PWM pins + are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11. + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade +*/ + +int led = 9; // the PWM pin the LED is attached to +int brightness = 0; // how bright the LED is +int fadeAmount = 5; // how many points to fade the LED by + +// the setup routine runs once when you press reset: +void setup() { + // declare pin 9 to be an output: + pinMode(led, OUTPUT); +} + +// the loop routine runs over and over again forever: +void loop() { + // set the brightness of pin 9: + analogWrite(led, brightness); + + // change the brightness for next time through the loop: + brightness = brightness + fadeAmount; + + // reverse the direction of the fading at the ends of the fade: + if (brightness <= 0 || brightness >= 255) { + fadeAmount = -fadeAmount; + } + // wait for 30 milliseconds to see the dimming effect + delay(30); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino new file mode 100644 index 00000000..26e91e52 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino @@ -0,0 +1,27 @@ +/* + ReadAnalogVoltage + + Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor. + Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). + Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ReadAnalogVoltage +*/ + +// the setup routine runs once when you press reset: +void setup() { + // initialize serial communication at 9600 bits per second: + Serial.begin(9600); +} + +// the loop routine runs over and over again forever: +void loop() { + // read the input on analog pin 0: + int sensorValue = analogRead(A0); + // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): + float voltage = sensorValue * (5.0 / 1023.0); + // print out the value you read: + Serial.println(voltage); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino new file mode 100644 index 00000000..d266349a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @@ -0,0 +1,71 @@ +/* + Blink without Delay + + Turns on and off a light emitting diode (LED) connected to a digital pin, + without using the delay() function. This means that other code can run at the + same time without being interrupted by the LED code. + + The circuit: + - Use the onboard LED. + - Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA + and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN + is set to the correct LED pin independent of which board is used. + If you want to know what pin the on-board LED is connected to on your + Arduino model, check the Technical Specs of your board at: + https://www.arduino.cc/en/Main/Products + + created 2005 + by David A. Mellis + modified 8 Feb 2010 + by Paul Stoffregen + modified 11 Nov 2013 + by Scott Fitzgerald + modified 9 Jan 2017 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay +*/ + +// constants won't change. Used here to set a pin number: +const int ledPin = LED_BUILTIN; // the number of the LED pin + +// Variables will change: +int ledState = LOW; // ledState used to set the LED + +// Generally, you should use "unsigned long" for variables that hold time +// The value will quickly become too large for an int to store +unsigned long previousMillis = 0; // will store last time LED was updated + +// constants won't change: +const long interval = 1000; // interval at which to blink (milliseconds) + +void setup() { + // set the digital pin as output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // here is where you'd put code that needs to be running all the time. + + // check to see if it's time to blink the LED; that is, if the difference + // between the current time and last time you blinked the LED is bigger than + // the interval at which you want to blink the LED. + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time you blinked the LED + previousMillis = currentMillis; + + // if the LED is off turn it on and vice-versa: + if (ledState == LOW) { + ledState = HIGH; + } else { + ledState = LOW; + } + + // set the LED with the ledState of the variable: + digitalWrite(ledPin, ledState); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/Button/Button.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/Button/Button.ino new file mode 100644 index 00000000..e041c314 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/Button/Button.ino @@ -0,0 +1,51 @@ +/* + Button + + Turns on and off a light emitting diode(LED) connected to digital pin 13, + when pressing a pushbutton attached to pin 2. + + The circuit: + - LED attached from pin 13 to ground through 220 ohm resistor + - pushbutton attached to pin 2 from +5V + - 10K resistor attached to pin 2 from ground + + - Note: on most Arduinos there is already an LED on the board + attached to pin 13. + + created 2005 + by DojoDave + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button +*/ + +// constants won't change. They're used here to set pin numbers: +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin + +// variables will change: +int buttonState = 0; // variable for reading the pushbutton status + +void setup() { + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize the pushbutton pin as an input: + pinMode(buttonPin, INPUT); +} + +void loop() { + // read the state of the pushbutton value: + buttonState = digitalRead(buttonPin); + + // check if the pushbutton is pressed. If it is, the buttonState is HIGH: + if (buttonState == HIGH) { + // turn LED on: + digitalWrite(ledPin, HIGH); + } else { + // turn LED off: + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/Debounce/Debounce.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/Debounce/Debounce.ino new file mode 100644 index 00000000..6460d903 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/Debounce/Debounce.ino @@ -0,0 +1,86 @@ +/* + Debounce + + Each time the input pin goes from LOW to HIGH (e.g. because of a push-button + press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's a + minimum delay between toggles to debounce the circuit (i.e. to ignore noise). + + The circuit: + - LED attached from pin 13 to ground through 220 ohm resistor + - pushbutton attached from pin 2 to +5V + - 10 kilohm resistor attached from pin 2 to ground + + - Note: On most Arduino boards, there is already an LED on the board connected + to pin 13, so you don't need any extra components for this example. + + created 21 Nov 2006 + by David A. Mellis + modified 30 Aug 2011 + by Limor Fried + modified 28 Dec 2012 + by Mike Walters + modified 30 Aug 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Debounce +*/ + +// constants won't change. They're used here to set pin numbers: +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin + +// Variables will change: +int ledState = HIGH; // the current state of the output pin +int buttonState; // the current reading from the input pin +int lastButtonState = LOW; // the previous reading from the input pin + +// the following variables are unsigned longs because the time, measured in +// milliseconds, will quickly become a bigger number than can be stored in an int. +unsigned long lastDebounceTime = 0; // the last time the output pin was toggled +unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers + +void setup() { + pinMode(buttonPin, INPUT); + pinMode(ledPin, OUTPUT); + + // set initial LED state + digitalWrite(ledPin, ledState); +} + +void loop() { + // read the state of the switch into a local variable: + int reading = digitalRead(buttonPin); + + // check to see if you just pressed the button + // (i.e. the input went from LOW to HIGH), and you've waited long enough + // since the last press to ignore any noise: + + // If the switch changed, due to noise or pressing: + if (reading != lastButtonState) { + // reset the debouncing timer + lastDebounceTime = millis(); + } + + if ((millis() - lastDebounceTime) > debounceDelay) { + // whatever the reading is at, it's been there for longer than the debounce + // delay, so take it as the actual current state: + + // if the button state has changed: + if (reading != buttonState) { + buttonState = reading; + + // only toggle the LED if the new button state is HIGH + if (buttonState == HIGH) { + ledState = !ledState; + } + } + } + + // set the LED: + digitalWrite(ledPin, ledState); + + // save the reading. Next time through the loop, it'll be the lastButtonState: + lastButtonState = reading; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino new file mode 100644 index 00000000..0f0eea15 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino @@ -0,0 +1,45 @@ +/* + Input Pull-up Serial + + This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a digital + input on pin 2 and prints the results to the Serial Monitor. + + The circuit: + - momentary switch attached from pin 2 to ground + - built-in LED on pin 13 + + Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal + 20K-ohm resistor is pulled to 5V. This configuration causes the input to read + HIGH when the switch is open, and LOW when it is closed. + + created 14 Mar 2012 + by Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/InputPullupSerial +*/ + +void setup() { + //start serial connection + Serial.begin(9600); + //configure pin 2 as an input and enable the internal pull-up resistor + pinMode(2, INPUT_PULLUP); + pinMode(13, OUTPUT); +} + +void loop() { + //read the pushbutton value into a variable + int sensorVal = digitalRead(2); + //print out the value of the pushbutton + Serial.println(sensorVal); + + // Keep in mind the pull-up means the pushbutton's logic is inverted. It goes + // HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the + // button's pressed, and off when it's not: + if (sensorVal == HIGH) { + digitalWrite(13, LOW); + } else { + digitalWrite(13, HIGH); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino new file mode 100644 index 00000000..5205e17c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino @@ -0,0 +1,78 @@ +/* + State change detection (edge detection) + + Often, you don't need to know the state of a digital input all the time, but + you just need to know when the input changes from one state to another. + For example, you want to know when a button goes from OFF to ON. This is called + state change detection, or edge detection. + + This example shows how to detect when a button or button changes from off to on + and on to off. + + The circuit: + - pushbutton attached to pin 2 from +5V + - 10 kilohm resistor attached to pin 2 from ground + - LED attached from pin 13 to ground through 220 ohm resistor (or use the + built-in LED on most Arduino boards) + + created 27 Sep 2005 + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StateChangeDetection +*/ + +// this constant won't change: +const int buttonPin = 2; // the pin that the pushbutton is attached to +const int ledPin = 13; // the pin that the LED is attached to + +// Variables will change: +int buttonPushCounter = 0; // counter for the number of button presses +int buttonState = 0; // current state of the button +int lastButtonState = 0; // previous state of the button + +void setup() { + // initialize the button pin as a input: + pinMode(buttonPin, INPUT); + // initialize the LED as an output: + pinMode(ledPin, OUTPUT); + // initialize serial communication: + Serial.begin(9600); +} + + +void loop() { + // read the pushbutton input pin: + buttonState = digitalRead(buttonPin); + + // compare the buttonState to its previous state + if (buttonState != lastButtonState) { + // if the state has changed, increment the counter + if (buttonState == HIGH) { + // if the current state is HIGH then the button went from off to on: + buttonPushCounter++; + Serial.println("on"); + Serial.print("number of button pushes: "); + Serial.println(buttonPushCounter); + } else { + // if the current state is LOW then the button went from on to off: + Serial.println("off"); + } + // Delay a little bit to avoid bouncing + delay(50); + } + // save the current state as the last state, for next time through the loop + lastButtonState = buttonState; + + + // turns on the LED every four button pushes by checking the modulo of the + // button push counter. the modulo function gives you the remainder of the + // division of two numbers: + if (buttonPushCounter % 4 == 0) { + digitalWrite(ledPin, HIGH); + } else { + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/pitches.h new file mode 100644 index 00000000..a0d69acd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/toneKeyboard.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/toneKeyboard.ino new file mode 100644 index 00000000..c8e73c64 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/toneKeyboard.ino @@ -0,0 +1,43 @@ +/* + Keyboard + + Plays a pitch that changes based on a changing analog input + + circuit: + - three force-sensing resistors from +5V to analog in 0 through 5 + - three 10 kilohm resistors from analog in 0 through 5 to ground + - 8 ohm speaker on digital pin 8 + + created 21 Jan 2010 + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneKeyboard +*/ + +#include "pitches.h" + +const int threshold = 10; // minimum reading of the sensors that generates a note + +// notes to play, corresponding to the 3 sensors: +int notes[] = { + NOTE_A4, NOTE_B4, NOTE_C3 +}; + +void setup() { +} + +void loop() { + for (int thisSensor = 0; thisSensor < 3; thisSensor++) { + // get a sensor reading: + int sensorReading = analogRead(thisSensor); + + // if the sensor is pressed hard enough: + if (sensorReading > threshold) { + // play the note corresponding to this sensor: + tone(8, notes[thisSensor], 20); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/pitches.h b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/pitches.h new file mode 100644 index 00000000..a0d69acd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/toneMelody.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/toneMelody.ino new file mode 100644 index 00000000..22022dce --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/toneMelody.ino @@ -0,0 +1,50 @@ +/* + Melody + + Plays a melody + + circuit: + - 8 ohm speaker on digital pin 8 + + created 21 Jan 2010 + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMelody +*/ + +#include "pitches.h" + +// notes in the melody: +int melody[] = { + NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 +}; + +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations[] = { + 4, 8, 8, 4, 4, 4, 4, 4 +}; + +void setup() { + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < 8; thisNote++) { + + // to calculate the note duration, take one second divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 1000 / noteDurations[thisNote]; + tone(8, melody[thisNote], noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.30; + delay(pauseBetweenNotes); + // stop the tone playing: + noTone(8); + } +} + +void loop() { + // no need to repeat the melody. +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMultiple/toneMultiple.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMultiple/toneMultiple.ino new file mode 100644 index 00000000..8d97fa7f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/toneMultiple/toneMultiple.ino @@ -0,0 +1,39 @@ +/* + Multiple tone player + + Plays multiple tones on multiple pins in sequence + + circuit: + - three 8 ohm speakers on digital pins 6, 7, and 8 + + created 8 Mar 2010 + by Tom Igoe + based on a snippet from Greg Borenstein + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMultiple +*/ + +void setup() { +} + +void loop() { + // turn off tone function for pin 8: + noTone(8); + // play a note on pin 6 for 200 ms: + tone(6, 440, 200); + delay(200); + + // turn off tone function for pin 6: + noTone(6); + // play a note on pin 7 for 500 ms: + tone(7, 494, 500); + delay(500); + + // turn off tone function for pin 7: + noTone(7); + // play a note on pin 8 for 300 ms: + tone(8, 523, 300); + delay(300); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino new file mode 100644 index 00000000..592f671c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino @@ -0,0 +1,39 @@ +/* + Pitch follower + + Plays a pitch that changes based on a changing analog input + + circuit: + - 8 ohm speaker on digital pin 9 + - photoresistor on analog 0 to 5V + - 4.7 kilohm resistor on analog 0 to ground + + created 21 Jan 2010 + modified 31 May 2012 + by Tom Igoe, with suggestion from Michael Flynn + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/tonePitchFollower +*/ + +void setup() { + // initialize serial communications (for debugging only): + Serial.begin(9600); +} + +void loop() { + // read the sensor: + int sensorReading = analogRead(A0); + // print the sensor reading so you know its range + Serial.println(sensorReading); + // map the analog input range (in this case, 400 - 1000 from the photoresistor) + // to the output pitch range (120 - 1500Hz) + // change the minimum and maximum input numbers below depending on the range + // your sensor's giving: + int thisPitch = map(sensorReading, 400, 1000, 120, 1500); + + // play the pitch: + tone(9, thisPitch, 10); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino new file mode 100644 index 00000000..851342df --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino @@ -0,0 +1,52 @@ +/* + Analog input, analog output, serial output + + Reads an analog input pin, maps the result to a range from 0 to 255 and uses + the result to set the pulse width modulation (PWM) of an output pin. + Also prints the results to the Serial Monitor. + + The circuit: + - potentiometer connected to analog pin 0. + Center pin of the potentiometer goes to the analog pin. + side pins of the potentiometer go to +5V and ground + - LED connected from digital pin 9 to ground through 220 ohm resistor + + created 29 Dec. 2008 + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInOutSerial +*/ + +// These constants won't change. They're used to give names to the pins used: +const int analogInPin = A0; // Analog input pin that the potentiometer is attached to +const int analogOutPin = 9; // Analog output pin that the LED is attached to + +int sensorValue = 0; // value read from the pot +int outputValue = 0; // value output to the PWM (analog out) + +void setup() { + // initialize serial communications at 9600 bps: + Serial.begin(9600); +} + +void loop() { + // read the analog in value: + sensorValue = analogRead(analogInPin); + // map it to the range of the analog out: + outputValue = map(sensorValue, 0, 1023, 0, 255); + // change the analog out value: + analogWrite(analogOutPin, outputValue); + + // print the results to the Serial Monitor: + Serial.print("sensor = "); + Serial.print(sensorValue); + Serial.print("\t output = "); + Serial.println(outputValue); + + // wait 2 milliseconds before the next loop for the analog-to-digital + // converter to settle after the last reading: + delay(2); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogInput/AnalogInput.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogInput/AnalogInput.ino new file mode 100644 index 00000000..735a8b53 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogInput/AnalogInput.ino @@ -0,0 +1,50 @@ +/* + Analog Input + + Demonstrates analog input by reading an analog sensor on analog pin 0 and + turning on and off a light emitting diode(LED) connected to digital pin 13. + The amount of time the LED will be on and off depends on the value obtained + by analogRead(). + + The circuit: + - potentiometer + center pin of the potentiometer to the analog input 0 + one side pin (either one) to ground + the other side pin to +5V + - LED + anode (long leg) attached to digital output 13 through 220 ohm resistor + cathode (short leg) attached to ground + + - Note: because most Arduinos have a built-in LED attached to pin 13 on the + board, the LED is optional. + + created by David Cuartielles + modified 30 Aug 2011 + By Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput +*/ + +int sensorPin = A0; // select the input pin for the potentiometer +int ledPin = 13; // select the pin for the LED +int sensorValue = 0; // variable to store the value coming from the sensor + +void setup() { + // declare the ledPin as an OUTPUT: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // read the value from the sensor: + sensorValue = analogRead(sensorPin); + // turn the ledPin on + digitalWrite(ledPin, HIGH); + // stop the program for milliseconds: + delay(sensorValue); + // turn the ledPin off: + digitalWrite(ledPin, LOW); + // stop the program for for milliseconds: + delay(sensorValue); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino new file mode 100644 index 00000000..9d938d27 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino @@ -0,0 +1,46 @@ +/* + Mega analogWrite() test + + This sketch fades LEDs up and down one at a time on digital pins 2 through 13. + This sketch was written for the Arduino Mega, and will not work on other boards. + + The circuit: + - LEDs attached from pins 2 through 13 to ground. + + created 8 Feb 2009 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogWriteMega +*/ + +// These constants won't change. They're used to give names to the pins used: +const int lowestPin = 2; +const int highestPin = 13; + + +void setup() { + // set pins 2 through 13 as outputs: + for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // iterate over the pins: + for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { + // fade the LED on thisPin from off to brightest: + for (int brightness = 0; brightness < 255; brightness++) { + analogWrite(thisPin, brightness); + delay(2); + } + // fade the LED on thisPin from brightest to off: + for (int brightness = 255; brightness >= 0; brightness--) { + analogWrite(thisPin, brightness); + delay(2); + } + // pause between LEDs: + delay(100); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Calibration/Calibration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Calibration/Calibration.ino new file mode 100644 index 00000000..e0f639bb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Calibration/Calibration.ino @@ -0,0 +1,75 @@ +/* + Calibration + + Demonstrates one technique for calibrating sensor input. The sensor readings + during the first five seconds of the sketch execution define the minimum and + maximum of expected values attached to the sensor pin. + + The sensor minimum and maximum initial values may seem backwards. Initially, + you set the minimum high and listen for anything lower, saving it as the new + minimum. Likewise, you set the maximum low and listen for anything higher as + the new maximum. + + The circuit: + - analog sensor (potentiometer will do) attached to analog input 0 + - LED attached from digital pin 9 to ground through 220 ohm resistor + + created 29 Oct 2008 + by David A Mellis + modified 30 Aug 2011 + by Tom Igoe + modified 07 Apr 2017 + by Zachary J. Fields + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Calibration +*/ + +// These constants won't change: +const int sensorPin = A0; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to + +// variables: +int sensorValue = 0; // the sensor value +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value + + +void setup() { + // turn on LED to signal the start of the calibration period: + pinMode(13, OUTPUT); + digitalWrite(13, HIGH); + + // calibrate during the first five seconds + while (millis() < 5000) { + sensorValue = analogRead(sensorPin); + + // record the maximum sensor value + if (sensorValue > sensorMax) { + sensorMax = sensorValue; + } + + // record the minimum sensor value + if (sensorValue < sensorMin) { + sensorMin = sensorValue; + } + } + + // signal the end of the calibration period + digitalWrite(13, LOW); +} + +void loop() { + // read the sensor: + sensorValue = analogRead(sensorPin); + + // in case the sensor value is outside the range seen during calibration + sensorValue = constrain(sensorValue, sensorMin, sensorMax); + + // apply the calibration to the sensor reading + sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); + + // fade the LED using the calibrated value: + analogWrite(ledPin, sensorValue); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Fading/Fading.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Fading/Fading.ino new file mode 100644 index 00000000..7923546b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Fading/Fading.ino @@ -0,0 +1,41 @@ +/* + Fading + + This example shows how to fade an LED using the analogWrite() function. + + The circuit: + - LED attached from digital pin 9 to ground through 220 ohm resistor. + + created 1 Nov 2008 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fading +*/ + +int ledPin = 9; // LED connected to digital pin 9 + +void setup() { + // nothing happens in setup +} + +void loop() { + // fade in from min to max in increments of 5 points: + for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5) { + // sets the value (range from 0 to 255): + analogWrite(ledPin, fadeValue); + // wait for 30 milliseconds to see the dimming effect + delay(30); + } + + // fade out from max to min in increments of 5 points: + for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) { + // sets the value (range from 0 to 255): + analogWrite(ledPin, fadeValue); + // wait for 30 milliseconds to see the dimming effect + delay(30); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Smoothing/Smoothing.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Smoothing/Smoothing.ino new file mode 100644 index 00000000..15c0f1a8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/03.Analog/Smoothing/Smoothing.ino @@ -0,0 +1,64 @@ +/* + Smoothing + + Reads repeatedly from an analog input, calculating a running average and + printing it to the computer. Keeps ten readings in an array and continually + averages them. + + The circuit: + - analog sensor (potentiometer will do) attached to analog input 0 + + created 22 Apr 2007 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Smoothing +*/ + +// Define the number of samples to keep track of. The higher the number, the +// more the readings will be smoothed, but the slower the output will respond to +// the input. Using a constant rather than a normal variable lets us use this +// value to determine the size of the readings array. +const int numReadings = 10; + +int readings[numReadings]; // the readings from the analog input +int readIndex = 0; // the index of the current reading +int total = 0; // the running total +int average = 0; // the average + +int inputPin = A0; + +void setup() { + // initialize serial communication with computer: + Serial.begin(9600); + // initialize all the readings to 0: + for (int thisReading = 0; thisReading < numReadings; thisReading++) { + readings[thisReading] = 0; + } +} + +void loop() { + // subtract the last reading: + total = total - readings[readIndex]; + // read from the sensor: + readings[readIndex] = analogRead(inputPin); + // add the reading to the total: + total = total + readings[readIndex]; + // advance to the next position in the array: + readIndex = readIndex + 1; + + // if we're at the end of the array... + if (readIndex >= numReadings) { + // ...wrap around to the beginning: + readIndex = 0; + } + + // calculate the average: + average = total / numReadings; + // send it to the computer as ASCII digits + Serial.println(average); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/ASCIITable/ASCIITable.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/ASCIITable/ASCIITable.ino new file mode 100644 index 00000000..f7fc4d48 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/ASCIITable/ASCIITable.ino @@ -0,0 +1,77 @@ +/* + ASCII table + + Prints out byte values in all possible formats: + - as raw binary values + - as ASCII-encoded decimal, hex, octal, and binary values + + For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII + + The circuit: No external hardware needed. + + created 2006 + by Nicholas Zambetti + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ASCIITable +*/ + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // prints title with ending line break + Serial.println("ASCII Table ~ Character Map"); +} + +// first visible ASCIIcharacter '!' is number 33: +int thisByte = 33; +// you can also write ASCII characters in single quotes. +// for example, '!' is the same as 33, so you could also use this: +// int thisByte = '!'; + +void loop() { + // prints value unaltered, i.e. the raw binary version of the byte. + // The Serial Monitor interprets all bytes as ASCII, so 33, the first number, + // will show up as '!' + Serial.write(thisByte); + + Serial.print(", dec: "); + // prints value as string as an ASCII-encoded decimal (base 10). + // Decimal is the default format for Serial.print() and Serial.println(), + // so no modifier is needed: + Serial.print(thisByte); + // But you can declare the modifier for decimal if you want to. + // this also works if you uncomment it: + + // Serial.print(thisByte, DEC); + + + Serial.print(", hex: "); + // prints value as string in hexadecimal (base 16): + Serial.print(thisByte, HEX); + + Serial.print(", oct: "); + // prints value as string in octal (base 8); + Serial.print(thisByte, OCT); + + Serial.print(", bin: "); + // prints value as string in binary (base 2) also prints ending line break: + Serial.println(thisByte, BIN); + + // if printed last visible character '~' or 126, stop: + if (thisByte == 126) { // you could also use if (thisByte == '~') { + // This loop loops forever and does nothing + while (true) { + continue; + } + } + // go on to the next character + thisByte++; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Dimmer/Dimmer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Dimmer/Dimmer.ino new file mode 100644 index 00000000..2f82344c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Dimmer/Dimmer.ino @@ -0,0 +1,114 @@ +/* + Dimmer + + Demonstrates sending data from the computer to the Arduino board, in this case + to control the brightness of an LED. The data is sent in individual bytes, + each of which ranges from 0 to 255. Arduino reads these bytes and uses them to + set the brightness of the LED. + + The circuit: + - LED attached from digital pin 9 to ground through 220 ohm resistor. + - Serial connection to Processing, Max/MSP, or another serial application + + created 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe and Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Dimmer +*/ + +const int ledPin = 9; // the pin that the LED is attached to + +void setup() { + // initialize the serial communication: + Serial.begin(9600); + // initialize the ledPin as an output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + byte brightness; + + // check if data has been sent from the computer: + if (Serial.available()) { + // read the most recent byte (which will be from 0 to 255): + brightness = Serial.read(); + // set the brightness of the LED: + analogWrite(ledPin, brightness); + } +} + +/* Processing code for this example + + // Dimmer - sends bytes over a serial port + + // by David A. Mellis + // This example code is in the public domain. + + import processing.serial.*; + Serial port; + + void setup() { + size(256, 150); + + println("Available serial ports:"); + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // Uses the first port in this list (number 0). Change this to select the port + // corresponding to your Arduino board. The last parameter (e.g. 9600) is the + // speed of the communication. It has to correspond to the value passed to + // Serial.begin() in your Arduino sketch. + port = new Serial(this, Serial.list()[0], 9600); + + // If you know the name of the port used by the Arduino board, you can specify + // it directly like this. + //port = new Serial(this, "COM1", 9600); + } + + void draw() { + // draw a gradient from black to white + for (int i = 0; i < 256; i++) { + stroke(i); + line(i, 0, i, 150); + } + + // write the current X-position of the mouse to the serial port as + // a single byte + port.write(mouseX); + } + +*/ + +/* Max/MSP v5 patch for this example + + ----------begin_max5_patcher---------- + 1008.3ocuXszaiaCD9r8uhA5rqAeHIa0aAMaAVf1S6hdoYQAsDiL6JQZHQ2M + YWr+2KeX4vjnjXKKkKhhiGQ9MeyCNz+X9rnMp63sQvuB+MLa1OlOalSjUvrC + ymEUytKuh05TKJWUWyk5nE9eSyuS6jesvHu4F4MxOuUzB6X57sPKWVzBLXiP + xZtGj6q2vafaaT0.BzJfjj.p8ZPukazsQvpfcpFs8mXR3plh8BoBxURIOWyK + rxspZ0YI.eTCEh5Vqp+wGtFXZMKe6CZc3yWZwTdCmYW.BBkdiby8v0r+ST.W + sD9SdUkn8FYspPbqvnBNFtZWiUyLmleJWo0vuKzeuj2vpJLaWA7YiE7wREui + FpDFDp1KcbAFcP5sJoVxp4NB5Jq40ougIDxJt1wo3GDZHiNocKhiIExx+owv + AdOEAksDs.RRrOoww1Arc.9RvN2J9tamwjkcqknvAE0l+8WnjHqreNet8whK + z6mukIK4d+Xknv3jstvJs8EirMMhxsZIusET25jXbX8xczIl5xPVxhPcTGFu + xNDu9rXtUCg37g9Q8Yc+EuofIYmg8QdkPCrOnXsaHwYs3rWx9PGsO+pqueG2 + uNQBqWFh1X7qQG+3.VHcHrfO1nyR2TlqpTM9MDsLKNCQVz6KO.+Sfc5j1Ykj + jzkn2jwNDRP7LVb3d9LtoWBAOnvB92Le6yRmZ4UF7YpQhiFi7A5Ka8zXhKdA + 4r9TRGG7V4COiSbAJKdXrWNhhF0hNUh7uBa4Mba0l7JUK+omjDMwkSn95Izr + TOwkdp7W.oPRmNRQsiKeu4j3CkfVgt.NYPEYqMGvvJ48vIlPiyzrIuZskWIS + xGJPcmPiWOfLodybH3wjPbMYwlbFIMNHPHFOtLBNaLSa9sGk1TxMzCX5KTa6 + WIH2ocxSdngM0QPqFRxyPHFsprrhGc9Gy9xoBjz0NWdR2yW9DUa2F85jG2v9 + FgTO4Q8qiC7fzzQNpmNpsY3BrYPVJBMJQ1uVmoItRhw9NrVGO3NMNzYZ+zS7 + 3WTvTOnUydG5kHMKLqAOjTe7fN2bGSxOZDkMrBrGQ9J1gONBEy0k4gVo8qHc + cxmfxVihWz6a3yqY9NazzUYkua9UnynadOtogW.JfsVGRVNEbWF8I+eHtcwJ + +wLXqZeSdWLo+FQF6731Tva0BISKTx.cLwmgJsUTTvkg1YsnXmxDge.CDR7x + D6YmX6fMznaF7kdczmJXwm.XSOOrdoHhNA7GMiZYLZZR.+4lconMaJP6JOZ8 + ftCs1YWHZI3o.sIXezX5ihMSuXzZtk3ai1mXRSczoCS32hAydeyXNEu5SHyS + xqZqbd3ZLdera1iPqYxOm++v7SUSz + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Graph/Graph.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Graph/Graph.ino new file mode 100644 index 00000000..b50ca372 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Graph/Graph.ino @@ -0,0 +1,152 @@ +/* + Graph + + A simple example of communication from the Arduino board to the computer: The + value of analog input 0 is sent out the serial port. We call this "serial" + communication because the connection appears to both the Arduino and the + computer as a serial port, even though it may actually use a USB cable. Bytes + are sent one after another (serially) from the Arduino to the computer. + + You can use the Arduino Serial Monitor to view the sent data, or it can be + read by Processing, PD, Max/MSP, or any other program capable of reading data + from a serial port. The Processing code below graphs the data received so you + can see the value of the analog input changing over time. + + The circuit: + - any analog input sensor attached to analog in pin 0 + + created 2006 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe and Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Graph +*/ + +void setup() { + // initialize the serial communication: + Serial.begin(9600); +} + +void loop() { + // send the value of analog input 0: + Serial.println(analogRead(A0)); + // wait a bit for the analog-to-digital converter to stabilize after the last + // reading: + delay(2); +} + +/* Processing code for this example + + // Graphing sketch + + // This program takes ASCII-encoded strings from the serial port at 9600 baud + // and graphs them. It expects values in the range 0 to 1023, followed by a + // newline, or newline and carriage return + + // created 20 Apr 2005 + // updated 24 Nov 2015 + // by Tom Igoe + // This example code is in the public domain. + + import processing.serial.*; + + Serial myPort; // The serial port + int xPos = 1; // horizontal position of the graph + float inByte = 0; + + void setup () { + // set the window size: + size(400, 300); + + // List all the available serial ports + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // I know that the first port in the serial list on my Mac is always my + // Arduino, so I open Serial.list()[0]. + // Open whatever port is the one you're using. + myPort = new Serial(this, Serial.list()[0], 9600); + + // don't generate a serialEvent() unless you get a newline character: + myPort.bufferUntil('\n'); + + // set initial background: + background(0); + } + + void draw () { + // draw the line: + stroke(127, 34, 255); + line(xPos, height, xPos, height - inByte); + + // at the edge of the screen, go back to the beginning: + if (xPos >= width) { + xPos = 0; + background(0); + } else { + // increment the horizontal position: + xPos++; + } + } + + void serialEvent (Serial myPort) { + // get the ASCII string: + String inString = myPort.readStringUntil('\n'); + + if (inString != null) { + // trim off any whitespace: + inString = trim(inString); + // convert to an int and map to the screen height: + inByte = float(inString); + println(inByte); + inByte = map(inByte, 0, 1023, 0, height); + } + } + +*/ + +/* Max/MSP v5 patch for this example + + ----------begin_max5_patcher---------- + 1591.3oc0YszbaaCD9r7uBL5RalQUAO3CvdyS5zVenWZxs5NcfHgjPCIfJIT + RTxj+6AOHkoTDooroUs0AQPR73a+1cwtK3WtZxzEpOwqlB9YveAlL4KWMYh6 + Q1GLo99ISKXeJMmU451zTUQAWpmNy+NM+SZ2y+sR1l02JuU9t0hJvFlNcMPy + dOuBv.U5Rgb0LPpRpYBooM3529latArTUVvzZdFPtsXAuDrrTU.f.sBffXxL + vGE50lIHkUVJXq3fRtdaoDvjYfbgjujaFJSCzq4.tLaN.bi1tJefWpqbO0uz + 1IjIABoluxrJ1guxh2JfPO2B5zRNyBCLDFcqbwNvuv9fHCb8bvevyyEU2JKT + YhkBSWPAfq2TZ6YhqmuMUo0feUn+rYpY4YtY+cFw3lUJdCMYAapZqzwUHX8S + crjAd+SIOU6UBAwIygy.Q1+HAA1KH6EveWOFQlitUK92ehfal9kFhUxJ3tWc + sgpxadigWExbt1o7Ps5dk3yttivyg20W0VcSmg1G90qtx92rAZbH4ez.ruy1 + nhmaDPidE07J+5n2sg6E6oKXxUSmc20o6E3SPRDbrkXnPGUYE.i5nCNB9TxQ + jG.G0kCTZtH88f07Rt0ZMMWUw8VvbKVAaTk6GyoraPdZff7rQTejBN54lgyv + HE0Ft7AvIvvgvIwO23jBdUkYOuSvIFSiNcjFhiSsUBwsUCh1AgfNSBAeNDBZ + DIDqY.f8.YjfjV1HAn9XDTxyNFYatVTkKx3kcK9GraZpI5jv7GOx+Z37Xh82 + LSKHIDmDXaESoXRngIZQDKVkpxUkMCyXCQhcCK1z.G457gi3TzMz4RFD515F + G3bIQQwcP3SOF0zlkGhiCBQ1kOHHFFlXaEBQIQnCwv9QF1LxPZ.A4jR5cyQs + vbvHMJsLll01We+rE2LazX6zYmCraRrsPFwKg1ANBZFY.IAihr8Ox.aH0oAL + hB8nQVw0FSJiZeunOykbT6t3r.NP8.iL+bnwNiXuVMNJH9H9YCm89CFXPBER + bz422p8.O4dg6kRxdyjDqRwMIHTbT3QFLskxJ8tbmQK4tm0XGeZWF7wKKtYY + aTAF.XPNFaaQBinQMJ4QLF0aNHF0JtYuHSxoUZfZY6.UU2ejJTb8lQw8Fo5k + Rv6e2PI+fOM71o2ecY1VgTYdCSxxUqLokuYq9jYJi6lxPgD2NIPePLB0mwbG + YA9Rgxdiu1k5xiLlSU6JVnx6wzg3sYHwTesB8Z5D7RiGZpXyvDNJY.DQX3.H + hvmcUN4bP1yCkhpTle2P37jtBsKrLWcMScEmltOPv22ZfAqQAdKr9HzATQwZ + q18PrUGt6Tst2XMCRUfGuhXs6ccn23YloomMqcTiC5iMGPsHsHRWhWFlaenV + XcqwgCQiGGJzptyS2ZMODBz6fGza0bzmXBj7+DA94bvpR01MffAlueO7HwcI + pWCwmzJdvi9ILgflLAFmyXB6O7ML0YbD26lenmcGxjVsZUN+A6pUK7AtTrPg + M+eRYG0qD9j4I7eEbco8Xh6WcO.or9XDC6UCiewbXHkh6xm5LiPEkzpJDRTu + mEB44Fgz4NCtJvX.SM1vo2SlTCZGAe7GZu6ahdRyzFOhYZ+mbVVSYptBw.K1 + tboIkatIA7c1cTKD1u.honLYV04VkluHsXe0szv9pQCE9Ro3jaVB1o15pz2X + zYoBvO5KXCAe0LCYJybE8ZODf4fV8t9qW0zYxq.YJfTosj1bv0xc.SaC0+AV + 9V9L.KKyV3SyTcRtmzi6rO.O16USvts4B5xe9EymDvebK0eMfW6+NIsNlE2m + eqRyJ0utRq13+RjmqYKN1e.4d61jjdsauXe3.2p6jgi9hsNIv97CoyJ01xzl + c3ZhUCtSHx3UZgjoEJYqNY+hYs5zZQVFW19L3JDYaTlMLqAAt1G2yXlnFg9a + 53L1FJVcv.cOX0dh7mCVGCLce7GFcQwDdH5Ta3nyAS0pQbHxegr+tGIZORgM + RnMj5vGl1Fs16drnk7Tf1XOLgv1n0d2iEsCxR.eQsNOZ4FGF7whofgfI3kES + 1kCeOX5L2rifbdu0A9ae2X.V33B1Z+.Bj1FrP5iFrCYCG5EUWSG.hhunHJd. + HJ5hhnng3h9HPj4lud02.1bxGw. + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Midi/Midi.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Midi/Midi.ino new file mode 100644 index 00000000..0602bf0a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/Midi/Midi.ino @@ -0,0 +1,46 @@ +/* + MIDI note player + + This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data. + If this circuit is connected to a MIDI synth, it will play the notes + F#-0 (0x1E) to F#-5 (0x5A) in sequence. + + The circuit: + - digital in 1 connected to MIDI jack pin 5 + - MIDI jack pin 2 connected to ground + - MIDI jack pin 4 connected to +5V through 220 ohm resistor + - Attach a MIDI cable to the jack, then to a MIDI synth, and play music. + + created 13 Jun 2006 + modified 13 Aug 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Midi +*/ + +void setup() { + // Set MIDI baud rate: + Serial.begin(31250); +} + +void loop() { + // play notes from F#-0 (0x1E) to F#-5 (0x5A): + for (int note = 0x1E; note < 0x5A; note++) { + //Note on channel 1 (0x90), some note value (note), middle velocity (0x45): + noteOn(0x90, note, 0x45); + delay(100); + //Note on channel 1 (0x90), some note value (note), silent velocity (0x00): + noteOn(0x90, note, 0x00); + delay(100); + } +} + +// plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that +// data values are less than 127: +void noteOn(int cmd, int pitch, int velocity) { + Serial.write(cmd); + Serial.write(pitch); + Serial.write(velocity); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/MultiSerial/MultiSerial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/MultiSerial/MultiSerial.ino new file mode 100644 index 00000000..20fc4417 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/MultiSerial/MultiSerial.ino @@ -0,0 +1,43 @@ +/* + Multiple Serial test + + Receives from the main serial port, sends to the others. + Receives from serial port 1, sends to the main serial (Serial 0). + + This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc. + + The circuit: + - any serial device attached to Serial port 1 + - Serial Monitor open on Serial port 0 + + created 30 Dec 2008 + modified 20 May 2012 + by Tom Igoe & Jed Roach + modified 27 Nov 2015 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/MultiSerialMega +*/ + + +void setup() { + // initialize both serial ports: + Serial.begin(9600); + Serial1.begin(9600); +} + +void loop() { + // read from port 1, send to port 0: + if (Serial1.available()) { + int inByte = Serial1.read(); + Serial.write(inByte); + } + + // read from port 0, send to port 1: + if (Serial.available()) { + int inByte = Serial.read(); + Serial1.write(inByte); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino new file mode 100644 index 00000000..cff02ef1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino @@ -0,0 +1,161 @@ +/* + Physical Pixel + + An example of using the Arduino board to receive data from the computer. In + this case, the Arduino boards turns on an LED when it receives the character + 'H', and turns off the LED when it receives the character 'L'. + + The data can be sent from the Arduino Serial Monitor, or another program like + Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. + + The circuit: + - LED connected from digital pin 13 to ground through 220 ohm resistor + + created 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe and Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/PhysicalPixel +*/ + +const int ledPin = 13; // the pin that the LED is attached to +int incomingByte; // a variable to read incoming serial data into + +void setup() { + // initialize serial communication: + Serial.begin(9600); + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // see if there's incoming serial data: + if (Serial.available() > 0) { + // read the oldest byte in the serial buffer: + incomingByte = Serial.read(); + // if it's a capital H (ASCII 72), turn on the LED: + if (incomingByte == 'H') { + digitalWrite(ledPin, HIGH); + } + // if it's an L (ASCII 76) turn off the LED: + if (incomingByte == 'L') { + digitalWrite(ledPin, LOW); + } + } +} + +/* Processing code for this example + + // Mouse over serial + + // Demonstrates how to send data to the Arduino I/O board, in order to turn ON + // a light if the mouse is over a square and turn it off if the mouse is not. + + // created 2003-4 + // based on examples by Casey Reas and Hernando Barragan + // modified 30 Aug 2011 + // by Tom Igoe + // This example code is in the public domain. + + import processing.serial.*; + + float boxX; + float boxY; + int boxSize = 20; + boolean mouseOverBox = false; + + Serial port; + + void setup() { + size(200, 200); + boxX = width / 2.0; + boxY = height / 2.0; + rectMode(RADIUS); + + // List all the available serial ports in the output pane. + // You will need to choose the port that the Arduino board is connected to + // from this list. The first port in the list is port #0 and the third port + // in the list is port #2. + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // Open the port that the Arduino board is connected to (in this case #0) + // Make sure to open the port at the same speed Arduino is using (9600bps) + port = new Serial(this, Serial.list()[0], 9600); + } + + void draw() { + background(0); + + // Test if the cursor is over the box + if (mouseX > boxX - boxSize && mouseX < boxX + boxSize && + mouseY > boxY - boxSize && mouseY < boxY + boxSize) { + mouseOverBox = true; + // draw a line around the box and change its color: + stroke(255); + fill(153); + // send an 'H' to indicate mouse is over square: + port.write('H'); + } + else { + // return the box to its inactive state: + stroke(153); + fill(153); + // send an 'L' to turn the LED off: + port.write('L'); + mouseOverBox = false; + } + + // Draw the box + rect(boxX, boxY, boxSize, boxSize); + } + +*/ + +/* Max/MSP version 5 patch to run with this example: + + ----------begin_max5_patcher---------- + 1672.3oc2ZszaaiCD9ryuBBebQVCQRYao8xhf1cQCPVfBzh8RRQ.sDsM2HSZ + HQmlzh9eu7gjsjsEk7y0oWjiHoHm4aluYHGlueUmtiDuPy5B9Cv8fNc99Uc5 + XZR2Pm726zcF4knDRlYXciDylQ4xtWa6SReQZZ+iSeMiEQR.ej8BM4A9C7OO + kkAlSjQSAYTdbFfvA27o2c6sfO.Doqd6NfXgDHmRUCKkolg4hT06BfbQJGH3 + 5Qd2e8d.QJIQSow5tzebZ7BFW.FIHow8.2JAQpVIIYByxo9KIMkSjL9D0BRT + sbGHZJIkDoZOSMuQT.8YZ5qpgGI3locF4IpQRzq2nDF+odZMIJkRjpEF44M3 + A9nWAum7LKFbSOv+PSRXYOvmIhYiYpg.8A2LOUOxPyH+TjPJA+MS9sIzTRRr + QP9rXF31IBZAHpVHkHrfaPRHLuUCzoj9GSoQRqIB52y6Z.tu8o4EX+fddfuj + +MrXiwPL5+9cXwrOVvkbxLpomazHbQO7EyX7DpzXYgkFdF6algCQpkX4XUlo + hA6oa7GWck9w0Gnmy6RXQOoQeCfWwlzsdnHLTq8n9PCHLv7Cxa6PAN3RCKjh + ISRVZ+sSl704Tqt0kocE9R8J+P+RJOZ4ysp6gN0vppBbOTEN8qp0YCq5bq47 + PUwfA5e766z7NbGMuncw7VgNRSyQhbnPMGrDsGaFSvKM5NcWoIVdZn44.eOi + 9DTRUT.7jDQzSTiF4UzXLc7tLGh4T9pwaFQkGUGIiOOkpBSJUwGsBd40krHQ + 9XEvwq2V6eLIhV6GuzP7uzzXBmzsXPSRYwBtVLp7s5lKVv6UN2VW7xRtYDbx + 7s7wRgHYDI8YVFaTBshkP49R3rYpH3RlUhTQmK5jMadJyF3cYaTNQMGSyhRE + IIUlJaOOukdhoOyhnekEKmZlqU3UkLrk7bpPrpztKBVUR1uorLddk6xIOqNt + lBOroRrNVFJGLrDxudpET4kzkstNp2lzuUHVMgk5TDZx9GWumnoQTbhXsEtF + tzCcM+z0QKXsngCUtTOEIN0SX2iHTTIIz968.Kf.uhfzUCUuAd3UKd.OKt.N + HTynxTQyjpQD9jlwEXeKQxfHCBahUge6RprSa2V4m3aYOMyaP6gah2Yf1zbD + jVwZVGFZHHxINFxpjr5CiTS9JiZn6e6nTlXQZTAFj6QCppQwzL0AxVtoi6WE + QXsANkEGWMEuwNvhmKTnat7A9RqLq6pXuEwY6xM5xRraoTiurj51J1vKLzFs + CvM7HI14Mpje6YRxHOSieTsJpvJORjxT1nERK6s7YTN7sr6rylNwf5zMiHI4 + meZ4rTYt2PpVettZERbjJ6PjfqN2loPSrUcusH01CegsGEE5467rnCdqT1ES + QxtCvFq.cvGz+BaAHXKzRSfP+2Jf.KCvj5ZLJRAhwi+SWHvPyN3vXiaPn6JR + 3eoA.0TkFhTvpsDMIrL20nAkCI4EoYfSHAuiPBdmJRyd.IynYYjIzMvjOTKf + 3DLvnvRLDLpWeEOYXMfAZqfQ0.qsnlUdmA33t8CNJ7MZEb.u7fiZHLYzDkJp + R7CqEVLGN75U+1JXxFUY.xEEBcRCqhOEkz2bENEWnh4pbh0wY25EefbD6EmW + UA6Ip8wFLyuFXx+Wrp8m6iff1B86W7bqJO9+mx8er4E3.abCLrYdA16sBuHx + vKT6BlpIGQIhL55W7oicf3ayv3ixQCm4aQuY1HZUPQWY+cASx2WZ3f1fICuz + vj5R5ZbM1y8gXYN4dIXaYGq4NhQvS5MmcDADy+S.j8CQ78vk7Q7gtPDX3kFh + 3NGaAsYBUAO.8N1U4WKycxbQdrWxJdXd10gNIO+hkUMmm.CZwknu7JbNUYUq + 0sOsTsI1QudDtjw0t+xZ85wWZd80tMCiiMADNX4UzrcSeK23su87IANqmA7j + tiRzoXi2YRh67ldAk79gPmTe3YKuoY0qdEDV3X8xylCJMTN45JIakB7uY8XW + uVr3PO8wWwEoTW8lsfraX7ZqzZDDXCRqNkztHsGCYpIDDAOqxDpMVUMKcOrp + 942acPvx2NPocMC1wQZ8glRn3myTykVaEUNLoEeJjVaAevA4EAZnsNgkeyO+ + 3rEZB7f0DTazDcQTNmdt8aACGi1QOWnMmd+.6YjMHH19OB5gKsMF877x8wsJ + hN97JSnSfLUXGUoj6ujWXd6Pk1SAC+Pkogm.tZ.1lX1qL.pe6PE11DPeMMZ2 + .P0K+3peBt3NskC + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino new file mode 100644 index 00000000..1cab997c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino @@ -0,0 +1,68 @@ +/* + Reading a serial ASCII-encoded string. + + This sketch demonstrates the Serial parseInt() function. + It looks for an ASCII string of comma-separated values. + It parses them into ints, and uses those to fade an RGB LED. + + Circuit: Common-Cathode RGB LED wired like so: + - red anode: digital pin 3 through 220 ohm resistor + - green anode: digital pin 5 through 220 ohm resistor + - blue anode: digital pin 6 through 220 ohm resistor + - cathode: GND + + created 13 Apr 2012 + by Tom Igoe + modified 14 Mar 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ReadASCIIString +*/ + +// pins for the LEDs: +const int redPin = 3; +const int greenPin = 5; +const int bluePin = 6; + +void setup() { + // initialize serial: + Serial.begin(9600); + // make the pins outputs: + pinMode(redPin, OUTPUT); + pinMode(greenPin, OUTPUT); + pinMode(bluePin, OUTPUT); +} + +void loop() { + // if there's any serial available, read it: + while (Serial.available() > 0) { + + // look for the next valid integer in the incoming serial stream: + int red = Serial.parseInt(); + // do it again: + int green = Serial.parseInt(); + // do it again: + int blue = Serial.parseInt(); + + // look for the newline. That's the end of your sentence: + if (Serial.read() == '\n') { + // constrain the values to 0 - 255 and invert + // if you're using a common-cathode LED, just use "constrain(color, 0, 255);" + red = 255 - constrain(red, 0, 255); + green = 255 - constrain(green, 0, 255); + blue = 255 - constrain(blue, 0, 255); + + // fade the red, green, and blue legs of the LED: + analogWrite(redPin, red); + analogWrite(greenPin, green); + analogWrite(bluePin, blue); + + // print the three numbers in one string as hexadecimal: + Serial.print(red, HEX); + Serial.print(green, HEX); + Serial.println(blue, HEX); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino new file mode 100644 index 00000000..b7787740 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino @@ -0,0 +1,237 @@ +/* + Serial Call and Response + Language: Wiring/Arduino + + This program sends an ASCII A (byte of value 65) on startup and repeats that + until it gets some data in. Then it waits for a byte in the serial port, and + sends three sensor values whenever it gets a byte in. + + The circuit: + - potentiometers attached to analog inputs 0 and 1 + - pushbutton attached to digital I/O 2 + + created 26 Sep 2005 + by Tom Igoe + modified 24 Apr 2012 + by Tom Igoe and Scott Fitzgerald + Thanks to Greg Shakar and Scott Fitzgerald for the improvements + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialCallResponse +*/ + +int firstSensor = 0; // first analog sensor +int secondSensor = 0; // second analog sensor +int thirdSensor = 0; // digital sensor +int inByte = 0; // incoming serial byte + +void setup() { + // start serial port at 9600 bps: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + pinMode(2, INPUT); // digital sensor is on digital pin 2 + establishContact(); // send a byte to establish contact until receiver responds +} + +void loop() { + // if we get a valid byte, read analog ins: + if (Serial.available() > 0) { + // get incoming byte: + inByte = Serial.read(); + // read first analog input, divide by 4 to make the range 0-255: + firstSensor = analogRead(A0) / 4; + // delay 10ms to let the ADC recover: + delay(10); + // read second analog input, divide by 4 to make the range 0-255: + secondSensor = analogRead(1) / 4; + // read switch, map it to 0 or 255L + thirdSensor = map(digitalRead(2), 0, 1, 0, 255); + // send sensor values: + Serial.write(firstSensor); + Serial.write(secondSensor); + Serial.write(thirdSensor); + } +} + +void establishContact() { + while (Serial.available() <= 0) { + Serial.print('A'); // send a capital A + delay(300); + } +} + +/* Processing sketch to run with this example: + + // This example code is in the public domain. + + import processing.serial.*; + + int bgcolor; // Background color + int fgcolor; // Fill color + Serial myPort; // The serial port + int[] serialInArray = new int[3]; // Where we'll put what we receive + int serialCount = 0; // A count of how many bytes we receive + int xpos, ypos; // Starting position of the ball + boolean firstContact = false; // Whether we've heard from the microcontroller + + void setup() { + size(256, 256); // Stage size + noStroke(); // No border on the next thing drawn + + // Set the starting position of the ball (middle of the stage) + xpos = width / 2; + ypos = height / 2; + + // Print a list of the serial ports for debugging purposes + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // I know that the first port in the serial list on my Mac is always my FTDI + // adaptor, so I open Serial.list()[0]. + // On Windows machines, this generally opens COM1. + // Open whatever port is the one you're using. + String portName = Serial.list()[0]; + myPort = new Serial(this, portName, 9600); + } + + void draw() { + background(bgcolor); + fill(fgcolor); + // Draw the shape + ellipse(xpos, ypos, 20, 20); + } + + void serialEvent(Serial myPort) { + // read a byte from the serial port: + int inByte = myPort.read(); + // if this is the first byte received, and it's an A, clear the serial + // buffer and note that you've had first contact from the microcontroller. + // Otherwise, add the incoming byte to the array: + if (firstContact == false) { + if (inByte == 'A') { + myPort.clear(); // clear the serial port buffer + firstContact = true; // you've had first contact from the microcontroller + myPort.write('A'); // ask for more + } + } + else { + // Add the latest byte from the serial port to array: + serialInArray[serialCount] = inByte; + serialCount++; + + // If we have 3 bytes: + if (serialCount > 2 ) { + xpos = serialInArray[0]; + ypos = serialInArray[1]; + fgcolor = serialInArray[2]; + + // print the values (for debugging purposes only): + println(xpos + "\t" + ypos + "\t" + fgcolor); + + // Send a capital A to request new sensor readings: + myPort.write('A'); + // Reset serialCount: + serialCount = 0; + } + } + } + +*/ + +/* Max/MSP version 5 patch to run with this example: + + ----------begin_max5_patcher---------- + 3908.3oc6ckziiaiE9b0+J3XjCIXpp.WzZNMURv.jCInQ5fYNjNngrDssRKK + 4nkp6JA4+973hrkrsjncKu0SRiXasQ83G+dKj7QV+4qtaxzrOxKlf9Zzuft6 + t+7U2cm7ThSbm936lrL3igIAExaaRJ+CYS+sI2qtTI+ikxSuBMKNojm+N3D4 + Aua5KkPwpuoUAkgKhSm+tbdXo5cQXVOhuGwrohuHD4WT7iXzupen3HY4BuqG + rH0kzrrzxzfkb4kdJONHo9JoUKiSS3kRgjt4jYUk0mkznPJh+CYgHewpSqty + xWVwUh3jIqkEYEfmqQEMr.ETbB+YddQbVZix+tIAqV03z203QDX4ukIKHm6W + ep3T0ovqOUN+435m2Rcx+5U0E+FTzVBh9xOsHXIh5YuADg1x4IYgumG0r3mj + shmFmtJmWvSKCJ0um0WNhOKnJo7c6GmZe8YAg7Ne381Rc2j44wQYoBgn0SJN + c8qCHH1RhQqJi7NRCVsmGt.pGUESCxE31zDdCV.PRyxRZeo0MU.WOHMdYPIu + LVIrT75BMd4p73zxVuHdZ.TFKJByyRRZUTpq77dtRDzZFx+PbT4BYY0DJgaO + dUcSvj0XTT7bdQY6yUFLun8YZo71jl0TIt042RYNLa4RfCTWfsznKWDWfJpl + tJHrbgV6t.AZInfzWP.4INpJHA8za91u+6QN1nk7hh.PpQwonxEbTAWzpilV + MimilkmsDtPbo3TPiUdY0pGa9ZShS4gYUJz1pwE1iwCpxbAgJI9DGGwWNzFT + ksLf3z7M0MybG6Hj1WngsD7VEXS8j5q7Wu5U0+39ir8QJJS5GMHdtRimL4m1 + 0e1EVX0YsE2YssINriYRoFRyWVMoRRUGQvnkmms3pnXDYHbBKMPpIOL5i1s8 + 3rMPwFcRCsGRyPH780.8HBnpWz.vlEQBWJ+0CSunehJSmJxiIZRtNGhhDYrU + jt3ZQyA2fHJhZDifXIQHUHH8oGYgOREI5nqHIzhFWUndPyBdB3VzHJGwUhkV + rgvRl2UCVNMHcd234lf1DN16HFEIdHt99A5hrp7v5WWMSBQZgMP.Tkwoqig8 + W1.Sn1f3h3nn1wLpBypPDzlJ7XinEGkLiMPloWOhrgR7dpZWJQV1faDy35Qj + MThMFkWFGsJChQPqrQp8iorV6Q28HBVF4nMVDJj7f1xyYACFScisg.ruLHOW + uMUS4Am4pI4PTnHi.6bi02HNzSYnDBe4cgAgKzRk1jc8PJLoH3Ydz6.Q.7K8 + tfxx73oUkJq1MGuCy5TpAi.POWZ3AenidLOOIaZPhdjZVW3sdk6LXEGzHb7p + Mfr7SEy3SXHyBSxJ3J2ncNNYVJsXG6Me10nj4cfCRFdTFjLo7q3SiCpjjEDM + .nvra.GN39.E2CDTHWXPo8.xzfqrHCHKnf5QUYUVdoZPUjCSC7LU8.XtTUXl + X8vr51GjwFGLC2AlMdLkU4RiaRrnmJuiudnDk0ZW+9p6TuKBe433JUCzp6fU + iOF0SUk2UQYUPNTEkiZubvKa1tsmgL5SCTXGHnnG0CceLpkpR9Rs28IUESWl + EwWNKfHlg.zj6Ee7S+nE8A+m9F7Cu40u9gMm+aRp3kYYkKd3GDOz5y+c7b96 + K9gfvuIK68uNO6g2vUUL80WxihCVFD9vlB30e2SOrmxUb527RZ3nZNrljGrR + 70vs1J9suWuZ3zaHVdG3RIJLgGj2Gfn6TcGcstEfvtH.hpFLlnBndjOLGQAI + z98BXc6yQxghmOn6gZqj0ShPOXhynLOjzCESt+XwE8TxrCvrdXo16rqnLgvb + HaFmbh29QD+K0DyNdjDwvzQL.NXpoMvoOBxkger0HwMRQbpbCh91fjjG9Idw + prTH9SzaSea5a.GQEPnnh43WNefMlsOgx18n.vgUNO.tKl7tDyI3iHzafJHZ + VVNedVEbGgYIY42i93prB0i7B7KT1LnnCiyAiinpBnsPV7OG.tYKfBsrJOkG + UG5aq26iJw6GyJ4eM5mEgEKaNQPMEBUp.t8.krplOVTlZdJAW27bjvGK7p2p + HQPgLOSJDYv4E9gQBYBjMUselRxDy+4WplIzm9JQAWOEmfb.E364B43CAwp5 + uRRDEv8hWXprjADMUOYpOg9.bVQpEfhKgGCnAnk.rghBJCdTVICA3sDvAhE5 + oU4hf67ea5zWPuILqrD8uiK+i477fjHIt9y.V88yy3uMsZUj7wnxGKNAdPx5 + fAZMErDZOcJU4M01WFQokix.pKa+JE1WacmnKFeYd7b.0PeIzB8Kk+5WIZpB + Ejt34KJeHgOCh4HK8Y3QiAkAfs8TRhhOkG7AAGQf0qxyfmQxa+PLb8Ex.2PS + 4BdO5GB9Hvg+cfJCMofAIMu9Qz+UPCjckqVJlEmyA8Bf.rC6.3hAEuG8TdTU + bZljQ0nr1ayIqmTwQYfyRGafZhur5vfuyMSqYNWmtAPwWHalDSuUgT0Bosh. + JpAR89Y6Ez5QEfPTQO4J0DHLInIliz8BZV2JfV3Bd36qsQwAVVXbr1BGXp6s + Sd5sSDruo74wofx.HxUgxQwTnMLqTXvRmiGh2PUZr5pBynKChjl6feNUjSRn + hEUfRPT1GfG9Ik4TQBm.hEZZ.bc38HjAMKGzDRijEm1ifx1dbgzQyKh6FZc3 + wOCkRJH+KUh0daWs6wzltWx1puXxlWW6NZWY2JiTBzzILRIANku02NourySM + VI1VJTvQZff32AJr+dS9e34QAoA6EGXlGFH9yk7yyQAlVd3SR94g+TxOu1sU + Flgd6ICI96LzazyPu1cgqsZ8r74SgF.65+efbMf4pGHT7lgHh30Sha3N5Ia. + oqjMf7nsuMwycf7iYDybiAAVr3eC.oTMjpzEr8GDRc9bFRGHYXDrzg.Tlx+q + NW8TY1IkzCfZ2IftkQstbB08HUezoDS+oFyI.cWIhWBaDiUo7qIrDO7f.L6n + AXqCmyNT9act.z+Iv.GR0uES0ZXfjdz.IczAxQOUR+zvRsUTigRxmyPYeNlj + yXv8Peef2ZFzuLzWPPeAE8ELzWXYlhe8WzAcUg+b1UkIoCLzIH60zwASGXau + a1Dq2nUY.sox4vng+m0nACePngC9lEMLZMBPodOxf+yx5d4uMCTHm3kJvIIG + jcLMedEQldkjpoBkQyjY1Hk.hmSY95Iwos8NDb9VSlIWOIntqgxryUjL6bCJ + y1lli5tWWxrQ7YmqGYlc6shK1iY2dr0wtNjYxgHyzaq0OznY235awCr8zSz6 + EGd1QNUKf.74dADTBbTbeotjpW95IolY0WpKYONY8M83Rx2MChx3fL+iG5Mm + tXpdmvXj8uTvaAL1WjbbarQD4Z6kXBpnm6a69oKV2PY9WY174IbC3CaRQ9iK + Q4sYGQpwdtZ5wFrc7n569.M83OOR5ydSB1ZcAWCxdbKuavz9LILxfD.wWO.W + Nq+Zu4Es+AP6s5p9jDWH8ET+c85+XbW0.N1nDCTD7U4DGc6ohnU019fS7kQ0 + o43luuOGjv5agHp0DT.CysOfgLR3xXlXTUKm16RivRsn3z0O6cl3YScAvtrb + hwekGB7BZuqESUzBJWmCvK7t9HF8Ts6cUAPoFWso3aP8ApWyJ3wqOPo2pJDC + BQ0NI0Pj8QCQ2r1L5vKaU5lDRYX7yRur1UYYZmJQ9iDHwN9dndB5n5ejflmm + UsBwLHnDkKXWRuAkb3NeuzqRstiQGP.fCQFdHNzaE.8u58Nz9svFE9SGIE1X + kv9Iwfl1BdNWjA7xcThsWCS847loyFD8pZq2E2F04lYULzBTDYhrFSDDJdjo + fisN2NUN26e4xRu51zD5ZseJ4HC63WyIX6jRqsp0jangBnK.Qlo58PCpWevt + ahzqK7fbKsdX6R64aao8LmWhBPh9jKVAPMzb5a2cV6opdWHneMmqMEmAGsPh + ieigIjV+4gF1GgbMNXg+NH44YaRYyd..S1ThHzKhFwwGRaWVITqyj9FvPqMT + d0pDuSqDrOGF.Uogf.juCFi9WAUkYR+rFPanDcPG8SbrtjyG03ZQ8m3AqC5H + NcUUoXSwVrqXKVcZu.5ZnkwIfIVdXVZTwAuTTUiYuxwjZDK6ZgnRtYV8tJmP + hEcuXgz2Goxyaiw35UkaWbpqtfzD02oUkkYqi.YQbZqIIWrIljFolsdmMKFR + wCJ2+DTn.9QlkOld+d9Qy9IJdpLfy05Ik2b8GsG9h8rdm1ZFx1FrmmlA2snw + qI9Mcdi2nr6q3Gc87nLawurbw1dda+tMyGJ9HaQmlkGwy6davisMgrkM65oz + eulfYCzG46am8tSDK144xV4cEvVMTRXq9CIX8+ALNWb6sttKNkiZetnbz+lx + cQnb1Nds2C0tvLNe14hwQtxYbxhqc17qHfamUcZZ3NYSWqjJuiDoizZ+ud2j + naRK4k3346IIVdR1kKiQjM39adMamvc6n+Xp36Yf3SIGh3uKbquqs1JksTII + kuJ7RrZSFb2Cn9j5a6DT8cMo0iczU+lsYaU8YNVh5k5uzJLU26ZcfuJE6XLY + 0mcRp9NTCp+L+Ap+in7Xf3b9jFQBLtIY06PbrGhcrU6N00Qlaf9N0+QPo9nS + P6qsI7aYNLSNOHpsAxis0ggnZLjYqyyFkdSqinVsPaqSDZaYBZ6c93uLCjGm + iCroJVLzU45iNE.pIUfs3TWb.0FejHp9uANr0GcJPTroFDNOHpkIweLnI1QT + dHl3P7LhOF3Ahd9rnvLwAMy5JSdNezGlsIsW9mW44r26js+alhxjlkdhN0YE + YqiH5MTeWo6D4Qm.ieLS7OynmuVGSbmbFUlnWWhiQlhOeN+Yl35bq.tGo9JR + cj8AVqdz7nSgVB9zNj.FTOU68o5d9KO5TUOGxVMw+jTO8T6wqD0hEiHsOJO5 + TTOMoS.zlqN0SpZjz6GcH05ylVM0jwuidlkmAif374ih5M5QPfccr8Hqifff + otN8pt3hUcaWu8nosBhwmD0Epw5KmoF.poxy4YHbnjqfPJqcM3Y2vun7nS.i + f3eETiqcRX2LR.4QmhZrkoCSGwzZrqKHrVR8caari+55d2caPqmq5n.ywe8Q + WrZL9fpwVXeaogMByE6y1SMdjk+gbavbN7fYvVtt1C2XwHJSzpk+tidUO25H + UB9onw9mlFQ10fhpZBaDatcMTTEGcJpwzqg92qqiVtM6Cu0IRQ0ndEdfCAqV + l0qYAUmPrctbxO4XCuPMa1asYzKDks1D52ZCne6Mednz9qW8+.vfqkDA + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino new file mode 100644 index 00000000..e5b02cd3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -0,0 +1,223 @@ +/* + Serial Call and Response in ASCII + Language: Wiring/Arduino + + This program sends an ASCII A (byte of value 65) on startup and repeats that + until it gets some data in. Then it waits for a byte in the serial port, and + sends three ASCII-encoded, comma-separated sensor values, truncated by a + linefeed and carriage return, whenever it gets a byte in. + + The circuit: + - potentiometers attached to analog inputs 0 and 1 + - pushbutton attached to digital I/O 2 + + created 26 Sep 2005 + by Tom Igoe + modified 24 Apr 2012 + by Tom Igoe and Scott Fitzgerald + Thanks to Greg Shakar and Scott Fitzgerald for the improvements + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialCallResponseASCII +*/ + +int firstSensor = 0; // first analog sensor +int secondSensor = 0; // second analog sensor +int thirdSensor = 0; // digital sensor +int inByte = 0; // incoming serial byte + +void setup() { + // start serial port at 9600 bps and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + pinMode(2, INPUT); // digital sensor is on digital pin 2 + establishContact(); // send a byte to establish contact until receiver responds +} + +void loop() { + // if we get a valid byte, read analog ins: + if (Serial.available() > 0) { + // get incoming byte: + inByte = Serial.read(); + // read first analog input: + firstSensor = analogRead(A0); + // read second analog input: + secondSensor = analogRead(A1); + // read switch, map it to 0 or 255 + thirdSensor = map(digitalRead(2), 0, 1, 0, 255); + // send sensor values: + Serial.print(firstSensor); + Serial.print(","); + Serial.print(secondSensor); + Serial.print(","); + Serial.println(thirdSensor); + } +} + +void establishContact() { + while (Serial.available() <= 0) { + Serial.println("0,0,0"); // send an initial string + delay(300); + } +} + +/* Processing code to run with this example: + + // This example code is in the public domain. + + import processing.serial.*; // import the Processing serial library + Serial myPort; // The serial port + + float bgcolor; // Background color + float fgcolor; // Fill color + float xpos, ypos; // Starting position of the ball + + void setup() { + size(640, 480); + + // List all the available serial ports + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // I know that the first port in the serial list on my Mac is always my + // Arduino board, so I open Serial.list()[0]. + // Change the 0 to the appropriate number of the serial port that your + // microcontroller is attached to. + myPort = new Serial(this, Serial.list()[0], 9600); + + // read bytes into a buffer until you get a linefeed (ASCII 10): + myPort.bufferUntil('\n'); + + // draw with smooth edges: + smooth(); + } + + void draw() { + background(bgcolor); + fill(fgcolor); + // Draw the shape + ellipse(xpos, ypos, 20, 20); + } + + // serialEvent method is run automatically by the Processing applet whenever + // the buffer reaches the byte value set in the bufferUntil() + // method in the setup(): + + void serialEvent(Serial myPort) { + // read the serial buffer: + String myString = myPort.readStringUntil('\n'); + // if you got any bytes other than the linefeed: + myString = trim(myString); + + // split the string at the commas and convert the sections into integers: + int sensors[] = int(split(myString, ',')); + + // print out the values you got: + for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { + print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); + } + // add a linefeed after all the sensor values are printed: + println(); + if (sensors.length > 1) { + xpos = map(sensors[0], 0, 1023, 0, width); + ypos = map(sensors[1], 0, 1023, 0, height); + fgcolor = sensors[2]; + } + // send a byte to ask for more data: + myPort.write("A"); + } + +*/ + +/* Max/MSP version 5 patch to run with this example: + + ----------begin_max5_patcher---------- + 3640.3oc6cs0jZajE94Y9UzKkeHoVloTeSHkm1II0VkeHIthSs6C1obIjZ.E + KjHRhY7jT4+9d5KBj.jTCAXfoV6x.sj5VmyWet127ed6MCFm8EQw.z2f9.5l + a9yau4F0kjW3FS4aFLO3KgIAEpGaPX174hzxAC02qT7kR80mkkUHPAnBQdbP + BZQVdIZRd1bT4r3BDTmkU0YQPY3r3zoeJWDVpe2ttr6cFhvXt7KhyH8W26f9 + USkhiTulrw+1czQUszjrzxzf4B0sdP9dqtS5x4woIhREQiWewrkkUW0oViTD + +GpFASt2Qd0+51akeLzRPIU7DPXagIFnH.4653f9WAKKyxVHRQNcfDXlih2w + puvbdWHAlcTPBRKHg4x5mr74EBMINHV1+iFL.8qG.VMWTTDLUrs.TBH+zAvP + nTEhvvxun9pBd6FWH38DWH6DWv6ItbX.RKBOJ7XbP5ztvDesvhBLb6VTwcOg + DmiBjnXfiIrjjED0CpP490PEmtPExwQA5EGUVjK.CKQJqtcYl0nCMRAJi76D + Z7dQflCCVV1i+ENiTy3AwYaghEA4.KVJx+jHMXbhntJPceO3iBpPOPKtZqtU + jUoXtw28fkEimmEIlOI.3Q4iMT9wO+iLxc9O7sN28928t6Ve8uMYo.7EUN6t + ePVoUW+6E4hOW7CAgeaV1meWd1cuWnYLy8mKhhClGDd25F3ce+C2si1Ud42+ + bZ3IQJOXg7q96t80e50YvDjqHw7VvkRTXhHHuKEerRwmqfBFsS.g9h.HZN3X + hJf5Qd+xHZHgzc.mrqeYjbn4E84evfIDUjDtjNwD2iRHV6anmGdbmsfKxTTJ + dd93rjtBJ2U42foCwZDqKfYzKkrh4VgYIY4FxVRmN2646f8ck+xw7KrjzOlZ + ZYAVfdZgKlaWn29FzA8nfdR2quj.3ejflBJnKr.Dwpf13cZBm85P0rPj.rOB + 6fvztPFGkVI0SAPi5NKHmih7E8Ph2e35uOtYN6x6JEQtJVWpV7gRtm2dZy9W + +YMCxLHrEvAknQktDVdY7v82SFosgmSGHO56BRRt6mEEKxRKDnGd+2812h9X + 5GSeODOcAJ.M9YHHAfjPkyD0GIugn.Ht6bQ.7TTS8DoPtCQCQxWobX+jYPUJ + hPn3zgnx7kogphieFZ2j3TwDgH5dzaUscJ77kEnIY4hoYKglVYzcH5KKxJzu + qmgegxl.0MLNGBNDsr.5IUz0iAPZFE.0TtLOEdClQYrAAeORwW+XVo3aP+hb + DHUBCH.mfbEKfGOPyjQhGiCAdNUUBRcQjij4X.u5MZRDzHSyTDQFbcYdHHIM + AzlF1lnoLjKG8UZH5guV1vEkA4kKWbOPGPC9YgjNdJHVy+ZJQ1.Cq.FUWQpA + ke.8DbUwi.YEWBUCDhPyAXCEETFbuhICg9EIRiYnGVjKyt0+io.r+9vrxRz+ + Nt7OlJxCRhT35u.X0amlI9X5xEQppQwneJrLarPVU7JkGYWVHz2njevz1UoX + XkoEWOkxDWO9kXYocoTwuzF611zXJyimB3F5qf9nOT9qesryJTJ1EOcV4cIh + IPVWYoOBUMFTl.4sGRRzRT4AOIkRjn8h7LnNJI2mhg6OSk5JZrPJ4i9gfu.R + w+NHLCcpfAMij88n+qTPPMt4UTwj3bAnY.h.aIe.RiAEeF8Pdzx3zLkLUs1Z + mcmczah0FH4ZmpLcp.rVbX3d0zalKhSiKAxBZ9BU2zTP3uPobgL1Q.U0.kl+ + jcBZj1AMOpzsJYjdz0n53QXsfYrqELKblH7yUFoDfPVXbrwDGXqCjwjviT7a + rXZbpxOvxzXvpOnPH0GlTJMZog8l2UZJcdPjxjG7ywIYgeFULaInFDk8jpxZ + apvMA4cv9X.7.vaRRGFAcPYHMR0dF2BZC7wEJ2TOKeZnCRD+HzJo.OLWSW6r + qk2wfI6pGf.pdjC4rpfL2YeK8JYloVf93.ocJEvocv9wAcEiMQgBtl.lb0y9 + heKnvtGRs+iHOJHM3uaZbN1jDrhED4FfwfLPCEmH8jV.BB0Z+aF.Vkqc4apU + EIb9a5zAcGt5Rf3WdsNJ3R4PXDU0mouHzIca0MWO.KpQjT8oq1SIyqV3mP24 + ToxfHpdyOPNqgwoK.W.fxfRNtwsiDSBVlT9ociSMu+jfPQqUtk9paFLMONJK + URFMpq7xUuvOXF1HBuN6ndhzfE6nxPXQkKKFGjKQNyHtSptYYVVRyaspyBD3 + CRiA0YQYrlbgHdptY77E4wZk5UWSOf9yJByyRRZzT5673NtiNrvmhiJmoZq5 + fI73wKp5DFrBihhmBNxadsxfoEMuRiIbutfVcM4FWuyr.2bvrlNF5.3U+q9C + sKaa5jkMt70iSd8bC2ZbEFUuAa0DWqYF0tJ91p43649br2nZ2usLGuoxrnQq + 6TArNx+1CjRLPpVWf62Kj59ZFRa38Y6D0kRo8AnT8b0g0e4p8+f6.P4sBnaX + TqMmPsOdOcjG+dMtOmdzcgLdIGqjX0J+FAVrmSu.L8fAX19Ky1C.e1.z+IB2 + qpeCIUV+.I4fARxQGH0i.9ECVZrhZMTheMCkc4XRMsoCgbef2ZFjaF5MXzaH + n2PQugYmhe0WjdcU47Z1Ukhb6CwFISy2HNtcvtaNRWdshHNVgHcNMUlopRm4 + tJByyLXfI0UN6GM7eUiFTm8BMbctZQC8atOegDu6oveXrgpeaGnfaETvsBJN + 6AKuNsT4n+zRVXJtQd+ciEEYKyCq.8ptRTSdBRQrLNcUd5eXcjoa7fyhihZl + UrNQxBYZo5g.vpdt8klkJi1QyPvdH7UFMStbvYu8Amu1nY7ECMKGXBqnY2KH + Z18Jjl4aYNnEYiQWVzrUxytWNzL0VZ14xglI6isN5kAMi2GZlbYPyNma6FqC + aJRs9qEogO+ovfvYFxxjGV07cLnH3QQzm.R.BG7SAkk4wiWVpC2p9jwX23ka + 0zSz4M6e1QZY.8mljMNHwLURqZ9FuzslMk8ZJXtcMPeblVut1XYDhdMCpmjZ + 8BAqsU9DezKxJAa8Hmbbfi+wccuVv7c0qELrEHB+UAhHWzCfCbKPEyBki24Z + clythVwfkYSmlHrPdX8tC5v1iPb5ArPuOWc8NVrRZspq24UxhE0wBcAsMyt2 + 2LLuqvkKZRXjEq5CM6S3tq9Zm6HD+8Prm0F+jDWn1paUe+2ZuF259kxkiR5W + Qf6vzKBtMm+gFrMeuWsKW.6B61VyWOFjz0Zsmwza+.ikxQcAL3iDtbLWMTKm + OtyMEFcjWM9iu0rMa81D8kUl3v2ewcHWP5B2HX6kK7t7DL5fs6JVIrO0Z1l3 + bEpOP3zih9.gbspPzKDYbRVAQ7CFhtZsYzhW1ko0WEJcG3oAC0aRIyxKsUEI + +iDPwOLfp0uNA68MmtSUSmRuNb8d1ttWya7sVWf5Iwf.1LQtZUnqNvT1bS6z + E5o2vfqNSH5bufQbuZV09M.E04Mj8XBUiBqNGl5FSt3NGlZaGRpV6wc4kiWi + q0twaaORhul1jjsIi7cMjQlJJUaQuhR495nlfRQWRJXkrgmMGXWjKM4jdGJH + yovkl4HUetutzWuY5tjFHneGn77rtG3iJ92whCVJxKhBwgGtRaFIzabfNrRn + WThd9q24vsZjf9JvHwOKBhprFDmtXYIZ7xISjaO1GE4OK2V9yiS.qFhvrznh + 8cKyMZs7EVepT01FlCe0rIC0lUk6NX4N9syCyAE660+ovE9hyGqjaGurrLak + G0YwoMlFO4YMSZjd9DcWucsjUr1Yqgy8TluCY3N9Q8.+k0JCD3ZTS0CW8Qyb + s19nOxrgjw7VFU+3ooYviK66pCfimt8AAxHOOBkK+EajC2yayWtciMzgdvpM + NKORj29YyGcS4wFVlql0wcZTg1yw5wvMNiTpuUzpu.Y0miRlgO0w7wpZI2Em + SUBGayVM5eqU4C+rV4ZSPkvXqLJbAHlR3mKwT5ISL8+Kv0k.GWEKwpP3ewk3 + 7omKIN7EtDmp4ZtHk0BfatXgLhgasHgZrVYaY8AIO7fq8Pas1fFzjd4ibwpd + XO4GXOeOG+lcyasNh1R+wVx2yBxeTOT+wiZFYA0P48PNyiiVjAhJlNT4Qvpb + uj3aN2qYqJcBfSWhMbf+YCPcsfbNeTC2l9WNc+5eIlkST0RJgupzIn+kysgC + X6GGXnYpdYfP0GP6MKQXM3N1Ih6XVvcLuym7B0B5w8v.ahqBI49qJcJ.TaX. + N+xBP4NGHhhqYfkRNM9q1f3ZweqyYCQYdGCSZGQ5wBx47o.Ssw+CkcgQOmud + KZic4QKzCw+7ROm8nY2LfMsEDtdfeMKSn5Ev95IQhorcqJcBrzPsQUhRNe8M + 1X6lhOezC4Bidv1nKcFs8YimJ9n8RWZXiO7aSCxDRLdjd91qU5TnmXCeRvmR + 9jnm7b15RmJ9rO4Kr+IgO04BfczyOpqx9npzofOsIlaR8Mo0IUMR48i0mYly + lVMwlw6gbloGRezy4yKEw6BHBBWik.eRi3DNM5KDahS.SOE1EjmXl7Uyqo9T + AtQAO8fG3oLX3cZFxKh0FLNSRfDaoG74gdvW.ZDU9FMGSdFMBt+IQh.6eIvw + FujTkJREGKKcJ3X2WtXf7Ub1HywEqxh2tJnE.FcZhMByrcXQw1x+bOWJYjpy + lv8oq55aEHLcwD8hJjxbVU5EigcNtL7Ql76KVVp69Huhcb87vpoCkRYT+96v + Hd5Ay1rofMqm+FkLYvv0+GL3FkL6bLp21kL6QFNV8BNM48foWBV4zt1wXm5V + 4jkNEbL45dtNw13Iltmi9sAyY0S0l8BR+3yWjVXax7eOmKrp4m0QKIal6VYo + SAf5XQxSrCa5l0qk45k5kAzqEgMNgzkz9FmL5abpnu4IhNzZ+0s+OKCSg0. + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialEvent/SerialEvent.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialEvent/SerialEvent.ino new file mode 100644 index 00000000..13c5630a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialEvent/SerialEvent.ino @@ -0,0 +1,58 @@ +/* + Serial Event example + + When new serial data arrives, this sketch adds it to a String. + When a newline is received, the loop prints the string and clears it. + + A good test for this is to try it with a GPS receiver that sends out + NMEA 0183 sentences. + + NOTE: The serialEvent() feature is not available on the Leonardo, Micro, or + other ATmega32U4 based boards. + + created 9 May 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialEvent +*/ + +String inputString = ""; // a String to hold incoming data +bool stringComplete = false; // whether the string is complete + +void setup() { + // initialize serial: + Serial.begin(9600); + // reserve 200 bytes for the inputString: + inputString.reserve(200); +} + +void loop() { + // print the string when a newline arrives: + if (stringComplete) { + Serial.println(inputString); + // clear the string: + inputString = ""; + stringComplete = false; + } +} + +/* + SerialEvent occurs whenever a new data comes in the hardware serial RX. This + routine is run between each time loop() runs, so using delay inside loop can + delay response. Multiple bytes of data may be available. +*/ +void serialEvent() { + while (Serial.available()) { + // get the new byte: + char inChar = (char)Serial.read(); + // add it to the inputString: + inputString += inChar; + // if the incoming character is a newline, set a flag so the main loop can + // do something about it: + if (inChar == '\n') { + stringComplete = true; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino new file mode 100644 index 00000000..8f46bbe7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino @@ -0,0 +1,40 @@ +/* + SerialPassthrough sketch + + Some boards, like the Arduino 101, the MKR1000, Zero, or the Micro, have one + hardware serial port attached to Digital pins 0-1, and a separate USB serial + port attached to the IDE Serial Monitor. This means that the "serial + passthrough" which is possible with the Arduino UNO (commonly used to interact + with devices/shields that require configuration via serial AT commands) will + not work by default. + + This sketch allows you to emulate the serial passthrough behaviour. Any text + you type in the IDE Serial monitor will be written out to the serial port on + Digital pins 0 and 1, and vice-versa. + + On the 101, MKR1000, Zero, and Micro, "Serial" refers to the USB Serial port + attached to the Serial Monitor, and "Serial1" refers to the hardware serial + port attached to pins 0 and 1. This sketch will emulate Serial passthrough + using those two Serial ports on the boards mentioned above, but you can change + these names to connect any two serial ports on a board that has multiple ports. + + created 23 May 2016 + by Erik Nyquist + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialPassthrough +*/ + +void setup() { + Serial.begin(9600); + Serial1.begin(9600); +} + +void loop() { + if (Serial.available()) { // If anything comes in Serial (USB), + Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1) + } + + if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1) + Serial.write(Serial1.read()); // read it and send it out Serial (USB) + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino new file mode 100644 index 00000000..6ffd934a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino @@ -0,0 +1,129 @@ +/* + This example reads three analog sensors (potentiometers are easiest) and sends + their values serially. The Processing and Max/MSP programs at the bottom take + those three values and use them to change the background color of the screen. + + The circuit: + - potentiometers attached to analog inputs 0, 1, and 2 + + created 2 Dec 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe and Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/VirtualColorMixer +*/ + +const int redPin = A0; // sensor to control red color +const int greenPin = A1; // sensor to control green color +const int bluePin = A2; // sensor to control blue color + +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.print(analogRead(redPin)); + Serial.print(","); + Serial.print(analogRead(greenPin)); + Serial.print(","); + Serial.println(analogRead(bluePin)); +} + +/* Processing code for this example + + // This example code is in the public domain. + + import processing.serial.*; + + float redValue = 0; // red value + float greenValue = 0; // green value + float blueValue = 0; // blue value + + Serial myPort; + + void setup() { + size(200, 200); + + // List all the available serial ports + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // I know that the first port in the serial list on my Mac is always my + // Arduino, so I open Serial.list()[0]. + // Open whatever port is the one you're using. + myPort = new Serial(this, Serial.list()[0], 9600); + // don't generate a serialEvent() unless you get a newline character: + myPort.bufferUntil('\n'); + } + + void draw() { + // set the background color with the color values: + background(redValue, greenValue, blueValue); + } + + void serialEvent(Serial myPort) { + // get the ASCII string: + String inString = myPort.readStringUntil('\n'); + + if (inString != null) { + // trim off any whitespace: + inString = trim(inString); + // split the string on the commas and convert the resulting substrings + // into an integer array: + float[] colors = float(split(inString, ",")); + // if the array has at least three elements, you know you got the whole + // thing. Put the numbers in the color variables: + if (colors.length >= 3) { + // map them to the range 0-255: + redValue = map(colors[0], 0, 1023, 0, 255); + greenValue = map(colors[1], 0, 1023, 0, 255); + blueValue = map(colors[2], 0, 1023, 0, 255); + } + } + } + +*/ + +/* Max/MSP patch for this example + + ----------begin_max5_patcher---------- + 1512.3oc4Z00aaaCE8YmeED9ktB35xOjrj1aAsXX4g8xZQeYoXfVh1gqRjdT + TsIsn+2K+PJUovVVJ1VMdCAvxThV7bO7b48dIyWtXxzkxaYkSA+J3u.Sl7kK + lLwcK6MlT2dxzB5so4zRW2lJXeRt7elNy+HM6Vs61uDDzbOYkNmo02sg4euS + 4BSede8S2P0o2vEq+aEKU66PPP7b3LPHDauPvyCmAvv4v6+M7L2XXF2WfCaF + lURgVPKbCxzKUbZdySDUEbgABN.ia08R9mccGYGn66qGutNir27qWbg8iY+7 + HDRx.Hjf+OPHCQgPdpQHoxhBlwB+QF4cbkthlCRk4REnfeKScs3ZwaugWBbj + .PS+.qDPAkZkgPlY5oPS4By2A5aTLFv9pounjsgpnZVF3x27pqtBrRpJnZaa + C3WxTkfUJYA.BzR.BhIy.ehquw7dSoJCsrlATLckR.nhLPNWvVwL+Vp1LHL. + SjMG.tRaG7OxT5R2c8Hx9B8.wLCxVaGI6qnpj45Ug84kL+6YIM8CqUxJyycF + 7bqsBRULGvwfWyRMyovElat7NvqoejaLm4f+fkmyKuVTHy3q3ldhB.WtQY6Z + x0BSOeSpTqA+FW+Yy3SyybH3sFy8p0RVCmaMpTyX6HdDZ2JsPbfSogbBMueH + JLd6RMBdfRMzPjZvimuWIK2XgFA.ZmtfKoh0Sm88qc6OF4bDQ3P6kEtF6xej + .OkjD4H5OllyS+.3FlhY0so4xRlWqyrXErQpt+2rsnXgQNZHZgmMVzEofW7T + S4zORQtgIdDbRHrObRzSMNofUVZVcbKbhQZrSOo934TqRHIN2ncr7BF8TKR1 + tHDqL.PejLRRPKMR.pKFAkbtDa+UOvsYsIFH0DYsTCjqZ66T1CmGeDILLpSm + myk0SdkOKh5LUr4GbWwRYdW7fm.BvDmzHnSdH3biGpSbxxDNJoGDAD1ChH7L + I0DaloOTBLvkO7zPs5HJnKNoGAXbol5eytUhfyiSfnjE1uAq+Fp0a+wygGwR + q3ZI8.psJpkpJnyPzwmXBj7Sh.+bNvVZxlcKAm0OYHIxcIjzEKdRChgO5UMf + LkMPNN0MfiS7Ev6TYQct.F5IWcCZ4504rGsiVswGWWSYyma01QcZgmL+f+sf + oU18Hn6o6dXkMkFF14TL9rIAWE+6wvGV.p.TPqz3HK5L+VxYxl4UmBKEjr.B + 6zinuKI3C+D2Y7azIM6N7QL6t+jQyZxymK1ToAKqVsxjlGyjz2c1kTK3180h + kJEYkacWpv6lyp2VJTjWK47wHA6fyBOWxH9pUf6jUtZkLpNKW.9EeUBH3ymY + XSQlaqGrkQMGzp20adYSmIOGjIABo1xZyAWJtCX9tg6+HMuhMCPyx76ao+Us + UxmzUE79H8d2ZB1m1ztbnOa1mGeAq0awyK8a9UqBUc6pZolpzurTK232e5gp + aInVw8QIIcpaiNSJfY4Z+92Cs+Mc+mgg2cEsvGlLY6V+1kMuioxnB5VM+fsY + 9vSu4WI1PMBGXye6KXvNuzmZTh7U9h5j6vvASdngPdgOFxycNL6ia1axUMmT + JIzebXcQCn3SKMf+4QCMmOZung+6xBCPLfwO8ngcEI52YJ1y7mx3CN9xKUYU + bg7Y1yXjlKW6SrZnguQdsSfOSSDItqv2jwJFjavc1vO7OigyBr2+gDYorRk1 + HXZpVFfu2FxXkZtfp4RQqNkX5y2sya3YYL2iavWAOaizH+pw.Ibg8f1I9h3Z + 2B79sNeOHvBOtfEalWsvyu0KMf015.AaROvZ7vv5AhnndfHLbTgjcCK1KlHv + gOk5B26OqrXjcJ005.QqCHn8fVTxnxfj93SfQiJlv8YV0VT9fVUwOOhSV3uD + eeqCUClbBPa.j3vWDoMZssNTzRNEnE6gYPXazZaMF921syaLWyAeBXvCESA8 + ASi6Zyw8.RQi65J8ZsNx3ho93OhGWENtWpowepae4YhCFeLErOLENtXJrOSc + iadi39rf4hwc8xdhHz3gn3dBI7iDRlFe8huAfIZhq + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/Arrays/Arrays.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/Arrays/Arrays.ino new file mode 100644 index 00000000..75d59eee --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/Arrays/Arrays.ino @@ -0,0 +1,55 @@ +/* + Arrays + + Demonstrates the use of an array to hold pin numbers in order to iterate over + the pins in a sequence. Lights multiple LEDs in sequence, then in reverse. + + Unlike the For Loop tutorial, where the pins have to be contiguous, here the + pins can be in any random order. + + The circuit: + - LEDs from pins 2 through 7 to ground + + created 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Arrays +*/ + +int timer = 100; // The higher the number, the slower the timing. +int ledPins[] = { + 2, 7, 4, 6, 5, 3 +}; // an array of pin numbers to which LEDs are attached +int pinCount = 6; // the number of pins (i.e. the length of the array) + +void setup() { + // the array elements are numbered from 0 to (pinCount - 1). + // use a for loop to initialize each pin as an output: + for (int thisPin = 0; thisPin < pinCount; thisPin++) { + pinMode(ledPins[thisPin], OUTPUT); + } +} + +void loop() { + // loop from the lowest pin to the highest: + for (int thisPin = 0; thisPin < pinCount; thisPin++) { + // turn the pin on: + digitalWrite(ledPins[thisPin], HIGH); + delay(timer); + // turn the pin off: + digitalWrite(ledPins[thisPin], LOW); + } + + // loop from the highest pin to the lowest: + for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { + // turn the pin on: + digitalWrite(ledPins[thisPin], HIGH); + delay(timer); + // turn the pin off: + digitalWrite(ledPins[thisPin], LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/ForLoopIteration/ForLoopIteration.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/ForLoopIteration/ForLoopIteration.ino new file mode 100644 index 00000000..e6b40e7d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/ForLoopIteration/ForLoopIteration.ino @@ -0,0 +1,47 @@ +/* + For Loop Iteration + + Demonstrates the use of a for() loop. + Lights multiple LEDs in sequence, then in reverse. + + The circuit: + - LEDs from pins 2 through 7 to ground + + created 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ForLoopIteration +*/ + +int timer = 100; // The higher the number, the slower the timing. + +void setup() { + // use a for loop to initialize each pin as an output: + for (int thisPin = 2; thisPin < 8; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // loop from the lowest pin to the highest: + for (int thisPin = 2; thisPin < 8; thisPin++) { + // turn the pin on: + digitalWrite(thisPin, HIGH); + delay(timer); + // turn the pin off: + digitalWrite(thisPin, LOW); + } + + // loop from the highest pin to the lowest: + for (int thisPin = 7; thisPin >= 2; thisPin--) { + // turn the pin on: + digitalWrite(thisPin, HIGH); + delay(timer); + // turn the pin off: + digitalWrite(thisPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/IfStatementConditional/IfStatementConditional.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/IfStatementConditional/IfStatementConditional.ino new file mode 100644 index 00000000..ac6041a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/IfStatementConditional/IfStatementConditional.ino @@ -0,0 +1,53 @@ +/* + Conditionals - If statement + + This example demonstrates the use of if() statements. + It reads the state of a potentiometer (an analog input) and turns on an LED + only if the potentiometer goes above a certain threshold level. It prints the + analog value regardless of the level. + + The circuit: + - potentiometer + Center pin of the potentiometer goes to analog pin 0. + Side pins of the potentiometer go to +5V and ground. + - LED connected from digital pin 13 to ground through 220 ohm resistor + + - Note: On most Arduino boards, there is already an LED on the board connected + to pin 13, so you don't need any extra components for this example. + + created 17 Jan 2009 + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ifStatementConditional +*/ + +// These constants won't change: +const int analogPin = A0; // pin that the sensor is attached to +const int ledPin = 13; // pin that the LED is attached to +const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input + +void setup() { + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize serial communications: + Serial.begin(9600); +} + +void loop() { + // read the value of the potentiometer: + int analogValue = analogRead(analogPin); + + // if the analog value is high enough, turn on the LED: + if (analogValue > threshold) { + digitalWrite(ledPin, HIGH); + } else { + digitalWrite(ledPin, LOW); + } + + // print the analog value: + Serial.println(analogValue); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino new file mode 100644 index 00000000..0a36341d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino @@ -0,0 +1,87 @@ +/* + Conditionals - while statement + + This example demonstrates the use of while() statements. + + While the pushbutton is pressed, the sketch runs the calibration routine. + The sensor readings during the while loop define the minimum and maximum of + expected values from the photoresistor. + + This is a variation on the calibrate example. + + The circuit: + - photoresistor connected from +5V to analog in pin 0 + - 10 kilohm resistor connected from ground to analog in pin 0 + - LED connected from digital pin 9 to ground through 220 ohm resistor + - pushbutton attached from pin 2 to +5V + - 10 kilohm resistor attached from pin 2 to ground + + created 17 Jan 2009 + modified 30 Aug 2011 + by Tom Igoe + modified 20 Jan 2017 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/WhileStatementConditional +*/ + + +// These constants won't change: +const int sensorPin = A0; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to +const int indicatorLedPin = 13; // pin that the built-in LED is attached to +const int buttonPin = 2; // pin that the button is attached to + + +// These variables will change: +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value +int sensorValue = 0; // the sensor value + + +void setup() { + // set the LED pins as outputs and the switch pin as input: + pinMode(indicatorLedPin, OUTPUT); + pinMode(ledPin, OUTPUT); + pinMode(buttonPin, INPUT); +} + +void loop() { + // while the button is pressed, take calibration readings: + while (digitalRead(buttonPin) == HIGH) { + calibrate(); + } + // signal the end of the calibration period + digitalWrite(indicatorLedPin, LOW); + + // read the sensor: + sensorValue = analogRead(sensorPin); + + // apply the calibration to the sensor reading + sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); + + // in case the sensor value is outside the range seen during calibration + sensorValue = constrain(sensorValue, 0, 255); + + // fade the LED using the calibrated value: + analogWrite(ledPin, sensorValue); +} + +void calibrate() { + // turn on the indicator LED to indicate that calibration is happening: + digitalWrite(indicatorLedPin, HIGH); + // read the sensor: + sensorValue = analogRead(sensorPin); + + // record the maximum sensor value + if (sensorValue > sensorMax) { + sensorMax = sensorValue; + } + + // record the minimum sensor value + if (sensorValue < sensorMin) { + sensorMin = sensorValue; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/switchCase/switchCase.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/switchCase/switchCase.ino new file mode 100644 index 00000000..f964b611 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/switchCase/switchCase.ino @@ -0,0 +1,56 @@ +/* + Switch statement + + Demonstrates the use of a switch statement. The switch statement allows you + to choose from among a set of discrete values of a variable. It's like a + series of if statements. + + To see this sketch in action, put the board and sensor in a well-lit room, + open the Serial Monitor, and move your hand gradually down over the sensor. + + The circuit: + - photoresistor from analog in 0 to +5V + - 10K resistor from analog in 0 to ground + + created 1 Jul 2009 + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase +*/ + +// these constants won't change. They are the lowest and highest readings you +// get from your sensor: +const int sensorMin = 0; // sensor minimum, discovered through experiment +const int sensorMax = 600; // sensor maximum, discovered through experiment + +void setup() { + // initialize serial communication: + Serial.begin(9600); +} + +void loop() { + // read the sensor: + int sensorReading = analogRead(A0); + // map the sensor range to a range of four options: + int range = map(sensorReading, sensorMin, sensorMax, 0, 3); + + // do something different depending on the range value: + switch (range) { + case 0: // your hand is on the sensor + Serial.println("dark"); + break; + case 1: // your hand is close to the sensor + Serial.println("dim"); + break; + case 2: // your hand is a few inches from the sensor + Serial.println("medium"); + break; + case 3: // your hand is nowhere near the sensor + Serial.println("bright"); + break; + } + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/switchCase2/switchCase2.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/switchCase2/switchCase2.ino new file mode 100644 index 00000000..48cbaa48 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/05.Control/switchCase2/switchCase2.ino @@ -0,0 +1,65 @@ +/* + Switch statement with serial input + + Demonstrates the use of a switch statement. The switch statement allows you + to choose from among a set of discrete values of a variable. It's like a + series of if statements. + + To see this sketch in action, open the Serial monitor and send any character. + The characters a, b, c, d, and e, will turn on LEDs. Any other character will + turn the LEDs off. + + The circuit: + - five LEDs attached to digital pins 2 through 6 through 220 ohm resistors + + created 1 Jul 2009 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase2 +*/ + +void setup() { + // initialize serial communication: + Serial.begin(9600); + // initialize the LED pins: + for (int thisPin = 2; thisPin < 7; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // read the sensor: + if (Serial.available() > 0) { + int inByte = Serial.read(); + // do something different depending on the character received. + // The switch statement expects single number values for each case; in this + // example, though, you're using single quotes to tell the controller to get + // the ASCII value for the character. For example 'a' = 97, 'b' = 98, + // and so forth: + + switch (inByte) { + case 'a': + digitalWrite(2, HIGH); + break; + case 'b': + digitalWrite(3, HIGH); + break; + case 'c': + digitalWrite(4, HIGH); + break; + case 'd': + digitalWrite(5, HIGH); + break; + case 'e': + digitalWrite(6, HIGH); + break; + default: + // turn all the LEDs off: + for (int thisPin = 2; thisPin < 7; thisPin++) { + digitalWrite(thisPin, LOW); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/ADXL3xx/ADXL3xx.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/ADXL3xx/ADXL3xx.ino new file mode 100644 index 00000000..b9dbf646 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/ADXL3xx/ADXL3xx.ino @@ -0,0 +1,60 @@ +/* + ADXL3xx + + Reads an Analog Devices ADXL3xx accelerometer and communicates the + acceleration to the computer. The pins used are designed to be easily + compatible with the breakout boards from SparkFun, available from: + https://www.sparkfun.com/categories/80 + + The circuit: + - analog 0: accelerometer self test + - analog 1: z-axis + - analog 2: y-axis + - analog 3: x-axis + - analog 4: ground + - analog 5: vcc + + created 2 Jul 2008 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ADXL3xx +*/ + +// these constants describe the pins. They won't change: +const int groundpin = 18; // analog input pin 4 -- ground +const int powerpin = 19; // analog input pin 5 -- voltage +const int xpin = A3; // x-axis of the accelerometer +const int ypin = A2; // y-axis +const int zpin = A1; // z-axis (only on 3-axis models) + +void setup() { + // initialize the serial communications: + Serial.begin(9600); + + // Provide ground and power by using the analog inputs as normal digital pins. + // This makes it possible to directly connect the breakout board to the + // Arduino. If you use the normal 5V and GND pins on the Arduino, + // you can remove these lines. + pinMode(groundpin, OUTPUT); + pinMode(powerpin, OUTPUT); + digitalWrite(groundpin, LOW); + digitalWrite(powerpin, HIGH); +} + +void loop() { + // print the sensor values: + Serial.print(analogRead(xpin)); + // print a tab between values: + Serial.print("\t"); + Serial.print(analogRead(ypin)); + // print a tab between values: + Serial.print("\t"); + Serial.print(analogRead(zpin)); + Serial.println(); + // delay before next reading: + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Knock/Knock.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Knock/Knock.ino new file mode 100644 index 00000000..0e21486d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Knock/Knock.ino @@ -0,0 +1,54 @@ +/* + Knock Sensor + + This sketch reads a piezo element to detect a knocking sound. + It reads an analog pin and compares the result to a set threshold. + If the result is greater than the threshold, it writes "knock" to the serial + port, and toggles the LED on pin 13. + + The circuit: + - positive connection of the piezo attached to analog in 0 + - negative connection of the piezo attached to ground + - 1 megohm resistor attached from analog in 0 to ground + + created 25 Mar 2007 + by David Cuartielles + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Knock +*/ + + +// these constants won't change: +const int ledPin = 13; // LED connected to digital pin 13 +const int knockSensor = A0; // the piezo is connected to analog pin 0 +const int threshold = 100; // threshold value to decide when the detected sound is a knock or not + + +// these variables will change: +int sensorReading = 0; // variable to store the value read from the sensor pin +int ledState = LOW; // variable used to store the last LED status, to toggle the light + +void setup() { + pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT + Serial.begin(9600); // use the serial port +} + +void loop() { + // read the sensor and store it in the variable sensorReading: + sensorReading = analogRead(knockSensor); + + // if the sensor reading is greater than the threshold: + if (sensorReading >= threshold) { + // toggle the status of the ledPin: + ledState = !ledState; + // update the LED pin itself: + digitalWrite(ledPin, ledState); + // send the string "Knock!" back to the computer, followed by newline + Serial.println("Knock!"); + } + delay(100); // delay to avoid overloading the serial port buffer +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Memsic2125/Memsic2125.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Memsic2125/Memsic2125.ino new file mode 100644 index 00000000..006306b7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Memsic2125/Memsic2125.ino @@ -0,0 +1,60 @@ +/* + Memsic2125 + + Read the Memsic 2125 two-axis accelerometer. Converts the pulses output by the + 2125 into milli-g's (1/1000 of Earth's gravity) and prints them over the + serial connection to the computer. + + The circuit: + - X output of accelerometer to digital pin 2 + - Y output of accelerometer to digital pin 3 + - +V of accelerometer to +5V + - GND of accelerometer to ground + + created 6 Nov 2008 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Memsic2125 +*/ + +// these constants won't change: +const int xPin = 2; // X output of the accelerometer +const int yPin = 3; // Y output of the accelerometer + +void setup() { + // initialize serial communications: + Serial.begin(9600); + // initialize the pins connected to the accelerometer as inputs: + pinMode(xPin, INPUT); + pinMode(yPin, INPUT); +} + +void loop() { + // variables to read the pulse widths: + int pulseX, pulseY; + // variables to contain the resulting accelerations + int accelerationX, accelerationY; + + // read pulse from x- and y-axes: + pulseX = pulseIn(xPin, HIGH); + pulseY = pulseIn(yPin, HIGH); + + // convert the pulse width into acceleration + // accelerationX and accelerationY are in milli-g's: + // Earth's gravity is 1000 milli-g's, or 1 g. + accelerationX = ((pulseX / 10) - 500) * 8; + accelerationY = ((pulseY / 10) - 500) * 8; + + // print the acceleration + Serial.print(accelerationX); + // print a tab character: + Serial.print("\t"); + Serial.print(accelerationY); + Serial.println(); + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Ping/Ping.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Ping/Ping.ino new file mode 100644 index 00000000..2d9a0da3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/06.Sensors/Ping/Ping.ino @@ -0,0 +1,79 @@ +/* + Ping))) Sensor + + This sketch reads a PING))) ultrasonic rangefinder and returns the distance + to the closest object in range. To do this, it sends a pulse to the sensor to + initiate a reading, then listens for a pulse to return. The length of the + returning pulse is proportional to the distance of the object from the sensor. + + The circuit: + - +V connection of the PING))) attached to +5V + - GND connection of the PING))) attached to ground + - SIG connection of the PING))) attached to digital pin 7 + + created 3 Nov 2008 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Ping +*/ + +// this constant won't change. It's the pin number of the sensor's output: +const int pingPin = 7; + +void setup() { + // initialize serial communication: + Serial.begin(9600); +} + +void loop() { + // establish variables for duration of the ping, and the distance result + // in inches and centimeters: + long duration, inches, cm; + + // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. + // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: + pinMode(pingPin, OUTPUT); + digitalWrite(pingPin, LOW); + delayMicroseconds(2); + digitalWrite(pingPin, HIGH); + delayMicroseconds(5); + digitalWrite(pingPin, LOW); + + // The same pin is used to read the signal from the PING))): a HIGH pulse + // whose duration is the time (in microseconds) from the sending of the ping + // to the reception of its echo off of an object. + pinMode(pingPin, INPUT); + duration = pulseIn(pingPin, HIGH); + + // convert the time into a distance + inches = microsecondsToInches(duration); + cm = microsecondsToCentimeters(duration); + + Serial.print(inches); + Serial.print("in, "); + Serial.print(cm); + Serial.print("cm"); + Serial.println(); + + delay(100); +} + +long microsecondsToInches(long microseconds) { + // According to Parallax's datasheet for the PING))), there are 73.746 + // microseconds per inch (i.e. sound travels at 1130 feet per second). + // This gives the distance travelled by the ping, outbound and return, + // so we divide by 2 to get the distance of the obstacle. + // See: https://www.parallax.com/package/ping-ultrasonic-distance-sensor-downloads/ + return microseconds / 74 / 2; +} + +long microsecondsToCentimeters(long microseconds) { + // The speed of sound is 340 m/s or 29 microseconds per centimeter. + // The ping travels out and back, so to find the distance of the object we + // take half of the distance travelled. + return microseconds / 29 / 2; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/07.Display/RowColumnScanning/RowColumnScanning.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/07.Display/RowColumnScanning/RowColumnScanning.ino new file mode 100644 index 00000000..0fb04c57 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/07.Display/RowColumnScanning/RowColumnScanning.ino @@ -0,0 +1,108 @@ +/* + Row-Column Scanning an 8x8 LED matrix with X-Y input + + This example controls an 8x8 LED matrix using two analog inputs. + + This example works for the Lumex LDM-24488NI Matrix. See + https://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf + for the pin connections. + + For other LED cathode column matrixes, you should only need to change the pin + numbers in the row[] and column[] arrays. + + rows are the anodes + cols are the cathodes + --------- + + Pin numbers: + Matrix: + - digital pins 2 through 13, + - analog pins 2 through 5 used as digital 16 through 19 + Potentiometers: + - center pins are attached to analog pins 0 and 1, respectively + - side pins attached to +5V and ground, respectively + + created 27 May 2009 + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/RowColumnScanning +*/ + +// 2-dimensional array of row pin numbers: +const int row[8] = { + 2, 7, 19, 5, 13, 18, 12, 16 +}; + +// 2-dimensional array of column pin numbers: +const int col[8] = { + 6, 11, 10, 3, 17, 4, 8, 9 +}; + +// 2-dimensional array of pixels: +int pixels[8][8]; + +// cursor position: +int x = 5; +int y = 5; + +void setup() { + // initialize the I/O pins as outputs iterate over the pins: + for (int thisPin = 0; thisPin < 8; thisPin++) { + // initialize the output pins: + pinMode(col[thisPin], OUTPUT); + pinMode(row[thisPin], OUTPUT); + // take the col pins (i.e. the cathodes) high to ensure that the LEDS are off: + digitalWrite(col[thisPin], HIGH); + } + + // initialize the pixel matrix: + for (int x = 0; x < 8; x++) { + for (int y = 0; y < 8; y++) { + pixels[x][y] = HIGH; + } + } +} + +void loop() { + // read input: + readSensors(); + + // draw the screen: + refreshScreen(); +} + +void readSensors() { + // turn off the last position: + pixels[x][y] = HIGH; + // read the sensors for X and Y values: + x = 7 - map(analogRead(A0), 0, 1023, 0, 7); + y = map(analogRead(A1), 0, 1023, 0, 7); + // set the new pixel position low so that the LED will turn on in the next + // screen refresh: + pixels[x][y] = LOW; +} + +void refreshScreen() { + // iterate over the rows (anodes): + for (int thisRow = 0; thisRow < 8; thisRow++) { + // take the row pin (anode) high: + digitalWrite(row[thisRow], HIGH); + // iterate over the cols (cathodes): + for (int thisCol = 0; thisCol < 8; thisCol++) { + // get the state of the current pixel; + int thisPixel = pixels[thisRow][thisCol]; + // when the row is HIGH and the col is LOW, + // the LED where they meet turns on: + digitalWrite(col[thisCol], thisPixel); + // turn the pixel off: + if (thisPixel == LOW) { + digitalWrite(col[thisCol], HIGH); + } + } + // take the row pin low to turn off the whole row: + digitalWrite(row[thisRow], LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/07.Display/barGraph/barGraph.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/07.Display/barGraph/barGraph.ino new file mode 100644 index 00000000..b15f840c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/07.Display/barGraph/barGraph.ino @@ -0,0 +1,57 @@ +/* + LED bar graph + + Turns on a series of LEDs based on the value of an analog sensor. + This is a simple way to make a bar graph display. Though this graph uses 10 + LEDs, you can use any number by changing the LED count and the pins in the + array. + + This method can be used to control any series of digital outputs that depends + on an analog input. + + The circuit: + - LEDs from pins 2 through 11 to ground + + created 4 Sep 2010 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/BarGraph +*/ + +// these constants won't change: +const int analogPin = A0; // the pin that the potentiometer is attached to +const int ledCount = 10; // the number of LEDs in the bar graph + +int ledPins[] = { + 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +}; // an array of pin numbers to which LEDs are attached + + +void setup() { + // loop over the pin array and set them all to output: + for (int thisLed = 0; thisLed < ledCount; thisLed++) { + pinMode(ledPins[thisLed], OUTPUT); + } +} + +void loop() { + // read the potentiometer: + int sensorReading = analogRead(analogPin); + // map the result to a range from 0 to the number of LEDs: + int ledLevel = map(sensorReading, 0, 1023, 0, ledCount); + + // loop over the LED array: + for (int thisLed = 0; thisLed < ledCount; thisLed++) { + // if the array element's index is less than ledLevel, + // turn the pin for this element on: + if (thisLed < ledLevel) { + digitalWrite(ledPins[thisLed], HIGH); + } + // turn off all pins higher than the ledLevel: + else { + digitalWrite(ledPins[thisLed], LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino new file mode 100644 index 00000000..40d68a5c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -0,0 +1,85 @@ +/* + Character analysis operators + + Examples using the character analysis operators. + Send any byte and the sketch will tell you about it. + + created 29 Nov 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/CharacterAnalysis +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("send any byte and I'll tell you everything I can about it"); + Serial.println(); +} + +void loop() { + // get any incoming bytes: + if (Serial.available() > 0) { + int thisChar = Serial.read(); + + // say what was sent: + Serial.print("You sent me: \'"); + Serial.write(thisChar); + Serial.print("\' ASCII Value: "); + Serial.println(thisChar); + + // analyze what was sent: + if (isAlphaNumeric(thisChar)) { + Serial.println("it's alphanumeric"); + } + if (isAlpha(thisChar)) { + Serial.println("it's alphabetic"); + } + if (isAscii(thisChar)) { + Serial.println("it's ASCII"); + } + if (isWhitespace(thisChar)) { + Serial.println("it's whitespace"); + } + if (isControl(thisChar)) { + Serial.println("it's a control character"); + } + if (isDigit(thisChar)) { + Serial.println("it's a numeric digit"); + } + if (isGraph(thisChar)) { + Serial.println("it's a printable character that's not whitespace"); + } + if (isLowerCase(thisChar)) { + Serial.println("it's lower case"); + } + if (isPrintable(thisChar)) { + Serial.println("it's printable"); + } + if (isPunct(thisChar)) { + Serial.println("it's punctuation"); + } + if (isSpace(thisChar)) { + Serial.println("it's a space character"); + } + if (isUpperCase(thisChar)) { + Serial.println("it's upper case"); + } + if (isHexadecimalDigit(thisChar)) { + Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)"); + } + + // add some space and ask for another byte: + Serial.println(); + Serial.println("Give me another byte:"); + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino new file mode 100644 index 00000000..4763acfd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -0,0 +1,68 @@ +/* + Adding Strings together + + Examples of how to add Strings together + You can also add several different data types to String, as shown here: + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringAdditionOperator +*/ + +// declare three Strings: +String stringOne, stringTwo, stringThree; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + stringOne = String("You added "); + stringTwo = String("this string"); + stringThree = String(); + // send an intro: + Serial.println("\n\nAdding Strings together (concatenation):"); + Serial.println(); +} + +void loop() { + // adding a constant integer to a String: + stringThree = stringOne + 123; + Serial.println(stringThree); // prints "You added 123" + + // adding a constant long integer to a String: + stringThree = stringOne + 123456789; + Serial.println(stringThree); // prints "You added 123456789" + + // adding a constant character to a String: + stringThree = stringOne + 'A'; + Serial.println(stringThree); // prints "You added A" + + // adding a constant string to a String: + stringThree = stringOne + "abc"; + Serial.println(stringThree); // prints "You added abc" + + stringThree = stringOne + stringTwo; + Serial.println(stringThree); // prints "You added this string" + + // adding a variable integer to a String: + int sensorValue = analogRead(A0); + stringOne = "Sensor value: "; + stringThree = stringOne + sensorValue; + Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has + + // adding a variable long integer to a String: + stringOne = "millis() value: "; + stringThree = stringOne + millis(); + Serial.println(stringThree); // prints "The millis: 345345" or whatever value millis() has + + // do nothing while true: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino new file mode 100644 index 00000000..4846cf41 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino @@ -0,0 +1,73 @@ +/* + Appending to Strings using the += operator and concat() + + Examples of how to append different data types to Strings + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringAppendOperator +*/ + +String stringOne, stringTwo; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + stringOne = String("Sensor "); + stringTwo = String("value"); + // send an intro: + Serial.println("\n\nAppending to a String:"); + Serial.println(); +} + +void loop() { + Serial.println(stringOne); // prints "Sensor " + + // adding a string to a String: + stringOne += stringTwo; + Serial.println(stringOne); // prints "Sensor value" + + // adding a constant string to a String: + stringOne += " for input "; + Serial.println(stringOne); // prints "Sensor value for input" + + // adding a constant character to a String: + stringOne += 'A'; + Serial.println(stringOne); // prints "Sensor value for input A" + + // adding a constant integer to a String: + stringOne += 0; + Serial.println(stringOne); // prints "Sensor value for input A0" + + // adding a constant string to a String: + stringOne += ": "; + Serial.println(stringOne); // prints "Sensor value for input" + + // adding a variable integer to a String: + stringOne += analogRead(A0); + Serial.println(stringOne); // prints "Sensor value for input A0: 456" or whatever analogRead(A0) is + + Serial.println("\n\nchanging the Strings' values"); + stringOne = "A long integer: "; + stringTwo = "The millis(): "; + + // adding a constant long integer to a String: + stringOne += 123456789; + Serial.println(stringOne); // prints "A long integer: 123456789" + + // using concat() to add a long variable to a String: + stringTwo.concat(millis()); + Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is + + // do nothing while true: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino new file mode 100644 index 00000000..52d4de8b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino @@ -0,0 +1,44 @@ +/* + String Case changes + + Examples of how to change the case of a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringCaseChanges +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString case changes:"); + Serial.println(); +} + +void loop() { + // toUpperCase() changes all letters to upper case: + String stringOne = ""; + Serial.println(stringOne); + stringOne.toUpperCase(); + Serial.println(stringOne); + + // toLowerCase() changes all letters to lower case: + String stringTwo = ""; + Serial.println(stringTwo); + stringTwo.toLowerCase(); + Serial.println(stringTwo); + + + // do nothing while true: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringCharacters/StringCharacters.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringCharacters/StringCharacters.ino new file mode 100644 index 00000000..6c64b57e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringCharacters/StringCharacters.ino @@ -0,0 +1,46 @@ +/* + String charAt() and setCharAt() + + Examples of how to get and set characters of a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringCharacters +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("\n\nString charAt() and setCharAt():"); +} + +void loop() { + // make a String to report a sensor reading: + String reportString = "SensorReading: 456"; + Serial.println(reportString); + + // the reading's most significant digit is at position 15 in the reportString: + char mostSignificantDigit = reportString.charAt(15); + + String message = "Most significant digit of the sensor reading is: "; + Serial.println(message + mostSignificantDigit); + + // add blank space: + Serial.println(); + + // you can also set the character of a String. Change the : to a = character + reportString.setCharAt(13, '='); + Serial.println(reportString); + + // do nothing while true: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino new file mode 100644 index 00000000..4e574698 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -0,0 +1,126 @@ +/* + Comparing Strings + + Examples of how to compare Strings using the comparison operators + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringComparisonOperators +*/ + +String stringOne, stringTwo; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + stringOne = String("this"); + stringTwo = String("that"); + // send an intro: + Serial.println("\n\nComparing Strings:"); + Serial.println(); +} + +void loop() { + // two Strings equal: + if (stringOne == "this") { + Serial.println("StringOne == \"this\""); + } + // two Strings not equal: + if (stringOne != stringTwo) { + Serial.println(stringOne + " =! " + stringTwo); + } + + // two Strings not equal (case sensitivity matters): + stringOne = "This"; + stringTwo = "this"; + if (stringOne != stringTwo) { + Serial.println(stringOne + " =! " + stringTwo); + } + // you can also use equals() to see if two Strings are the same: + if (stringOne.equals(stringTwo)) { + Serial.println(stringOne + " equals " + stringTwo); + } else { + Serial.println(stringOne + " does not equal " + stringTwo); + } + + // or perhaps you want to ignore case: + if (stringOne.equalsIgnoreCase(stringTwo)) { + Serial.println(stringOne + " equals (ignoring case) " + stringTwo); + } else { + Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo); + } + + // a numeric String compared to the number it represents: + stringOne = "1"; + int numberOne = 1; + if (stringOne.toInt() == numberOne) { + Serial.println(stringOne + " = " + numberOne); + } + + + + // two numeric Strings compared: + stringOne = "2"; + stringTwo = "1"; + if (stringOne >= stringTwo) { + Serial.println(stringOne + " >= " + stringTwo); + } + + // comparison operators can be used to compare Strings for alphabetic sorting too: + stringOne = String("Brown"); + if (stringOne < "Charles") { + Serial.println(stringOne + " < Charles"); + } + + if (stringOne > "Adams") { + Serial.println(stringOne + " > Adams"); + } + + if (stringOne <= "Browne") { + Serial.println(stringOne + " <= Browne"); + } + + + if (stringOne >= "Brow") { + Serial.println(stringOne + " >= Brow"); + } + + // the compareTo() operator also allows you to compare Strings + // it evaluates on the first character that's different. + // if the first character of the String you're comparing to comes first in + // alphanumeric order, then compareTo() is greater than 0: + stringOne = "Cucumber"; + stringTwo = "Cucuracha"; + if (stringOne.compareTo(stringTwo) < 0) { + Serial.println(stringOne + " comes before " + stringTwo); + } else { + Serial.println(stringOne + " comes after " + stringTwo); + } + + delay(10000); // because the next part is a loop: + + // compareTo() is handy when you've got Strings with numbers in them too: + + while (true) { + stringOne = "Sensor: "; + stringTwo = "Sensor: "; + + stringOne += analogRead(A0); + stringTwo += analogRead(A5); + + if (stringOne.compareTo(stringTwo) < 0) { + Serial.println(stringOne + " comes before " + stringTwo); + } else { + Serial.println(stringOne + " comes after " + stringTwo); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringConstructors/StringConstructors.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringConstructors/StringConstructors.ino new file mode 100644 index 00000000..36ff78a3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringConstructors/StringConstructors.ino @@ -0,0 +1,80 @@ +/* + String constructors + + Examples of how to create Strings from other data types + + created 27 Jul 2010 + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringConstructors +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString Constructors:"); + Serial.println(); +} + +void loop() { + // using a constant String: + String stringOne = "Hello String"; + Serial.println(stringOne); // prints "Hello String" + + // converting a constant char into a String: + stringOne = String('a'); + Serial.println(stringOne); // prints "a" + + // converting a constant string into a String object: + String stringTwo = String("This is a string"); + Serial.println(stringTwo); // prints "This is a string" + + // concatenating two strings: + stringOne = String(stringTwo + " with more"); + // prints "This is a string with more": + Serial.println(stringOne); + + // using a constant integer: + stringOne = String(13); + Serial.println(stringOne); // prints "13" + + // using an int and a base: + stringOne = String(analogRead(A0), DEC); + // prints "453" or whatever the value of analogRead(A0) is + Serial.println(stringOne); + + // using an int and a base (hexadecimal): + stringOne = String(45, HEX); + // prints "2d", which is the hexadecimal version of decimal 45: + Serial.println(stringOne); + + // using an int and a base (binary) + stringOne = String(255, BIN); + // prints "11111111" which is the binary value of 255 + Serial.println(stringOne); + + // using a long and a base: + stringOne = String(millis(), DEC); + // prints "123456" or whatever the value of millis() is: + Serial.println(stringOne); + + // using a float and the right decimal places: + stringOne = String(5.698, 3); + Serial.println(stringOne); + + // using a float and less decimal places to use rounding: + stringOne = String(5.698, 2); + Serial.println(stringOne); + + // do nothing while true: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringIndexOf/StringIndexOf.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringIndexOf/StringIndexOf.ino new file mode 100644 index 00000000..cf1f8167 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -0,0 +1,66 @@ +/* + String indexOf() and lastIndexOf() functions + + Examples of how to evaluate, look for, and replace characters in a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringIndexOf +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString indexOf() and lastIndexOf() functions:"); + Serial.println(); +} + +void loop() { + // indexOf() returns the position (i.e. index) of a particular character in a + // String. For example, if you were parsing HTML tags, you could use it: + String stringOne = ""; + int firstClosingBracket = stringOne.indexOf('>'); + Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket); + + stringOne = ""; + int secondOpeningBracket = firstClosingBracket + 1; + int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket); + Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket); + + // you can also use indexOf() to search for Strings: + stringOne = ""; + int bodyTag = stringOne.indexOf(""); + Serial.println("The index of the body tag in the string " + stringOne + " is " + bodyTag); + + stringOne = "
  • item
  • item
  • item
"; + int firstListItem = stringOne.indexOf("
  • "); + int secondListItem = stringOne.indexOf("
  • ", firstListItem + 1); + Serial.println("The index of the second list tag in the string " + stringOne + " is " + secondListItem); + + // lastIndexOf() gives you the last occurrence of a character or string: + int lastOpeningBracket = stringOne.lastIndexOf('<'); + Serial.println("The index of the last < in the string " + stringOne + " is " + lastOpeningBracket); + + int lastListItem = stringOne.lastIndexOf("
  • "); + Serial.println("The index of the last list tag in the string " + stringOne + " is " + lastListItem); + + + // lastIndexOf() can also search for a string: + stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; + int lastParagraph = stringOne.lastIndexOf(" 0) { + char inChar = Serial.read(); + txtMsg += inChar; + } + + // print the message and a notice if it's changed: + if (txtMsg.length() != lastStringLength) { + Serial.println(txtMsg); + Serial.println(txtMsg.length()); + // if the String's longer than 140 characters, complain: + if (txtMsg.length() < 140) { + Serial.println("That's a perfectly acceptable text message"); + } else { + Serial.println("That's too long for a text message."); + } + // note the length for next time through the loop: + lastStringLength = txtMsg.length(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino new file mode 100644 index 00000000..bdef83ac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -0,0 +1,43 @@ +/* + String length() and trim() + + Examples of how to use length() and trim() in a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringLengthTrim +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString length() and trim():"); + Serial.println(); +} + +void loop() { + // here's a String with empty spaces at the end (called white space): + String stringOne = "Hello! "; + Serial.print(stringOne); + Serial.print("<--- end of string. Length: "); + Serial.println(stringOne.length()); + + // trim the white space off the string: + stringOne.trim(); + Serial.print(stringOne); + Serial.print("<--- end of trimmed string. Length: "); + Serial.println(stringOne.length()); + + // do nothing while true: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringReplace/StringReplace.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringReplace/StringReplace.ino new file mode 100644 index 00000000..6fa9ba13 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/08.Strings/StringReplace/StringReplace.ino @@ -0,0 +1,51 @@ +/* + String replace() + + Examples of how to replace characters or substrings of a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringReplace +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString replace:\n"); + Serial.println(); +} + +void loop() { + String stringOne = ""; + Serial.println(stringOne); + // replace() changes all instances of one substring with another: + // first, make a copy of the original string: + String stringTwo = stringOne; + // then perform the replacements: + stringTwo.replace("<", " 0) { + int inChar = Serial.read(); + if (isDigit(inChar)) { + // convert the incoming byte to a char and add it to the string: + inString += (char)inChar; + } + // if you get a newline, print the string, then the string's value: + if (inChar == '\n') { + Serial.print("Value:"); + Serial.println(inString.toInt()); + Serial.print("String: "); + Serial.println(inString); + // clear the string for new input: + inString = ""; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino new file mode 100644 index 00000000..c44c5099 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino @@ -0,0 +1,90 @@ +/* + Keyboard logout + + This sketch demonstrates the Keyboard library. + + When you connect pin 2 to ground, it performs a logout. + It uses keyboard combinations to do this, as follows: + + On Windows, CTRL-ALT-DEL followed by ALT-l + On Ubuntu, CTRL-ALT-DEL, and ENTER + On OSX, CMD-SHIFT-q + + To wake: Spacebar. + + Circuit: + - Arduino Leonardo or Micro + - wire to connect D2 to ground + + created 6 Mar 2012 + modified 27 Mar 2012 + by Tom Igoe + + This example is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardLogout +*/ + +#define OSX 0 +#define WINDOWS 1 +#define UBUNTU 2 + +#include "Keyboard.h" + +// change this to match your platform: +int platform = OSX; + +void setup() { + // make pin 2 an input and turn on the pull-up resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + Keyboard.begin(); +} + +void loop() { + while (digitalRead(2) == HIGH) { + // do nothing until pin 2 goes low + delay(500); + } + delay(1000); + + switch (platform) { + case OSX: + Keyboard.press(KEY_LEFT_GUI); + // Shift-Q logs out: + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press('Q'); + delay(100); + Keyboard.releaseAll(); + // enter: + Keyboard.write(KEY_RETURN); + break; + case WINDOWS: + // CTRL-ALT-DEL: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_DELETE); + delay(100); + Keyboard.releaseAll(); + // ALT-l: + delay(2000); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press('l'); + Keyboard.releaseAll(); + break; + case UBUNTU: + // CTRL-ALT-DEL: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_DELETE); + delay(1000); + Keyboard.releaseAll(); + // Enter to confirm logout: + Keyboard.write(KEY_RETURN); + break; + } + + // do nothing: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino new file mode 100644 index 00000000..fbf4adb1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -0,0 +1,52 @@ +/* + Keyboard Message test + + For the Arduino Leonardo and Micro. + + Sends a text string when a button is pressed. + + The circuit: + - pushbutton attached from pin 4 to +5V + - 10 kilohm resistor attached from pin 4 to ground + + created 24 Oct 2011 + modified 27 Mar 2012 + by Tom Igoe + modified 11 Nov 2013 + by Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardMessage +*/ + +#include "Keyboard.h" + +const int buttonPin = 4; // input pin for pushbutton +int previousButtonState = HIGH; // for checking the state of a pushButton +int counter = 0; // button push counter + +void setup() { + // make the pushButton pin an input: + pinMode(buttonPin, INPUT); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + // read the pushbutton: + int buttonState = digitalRead(buttonPin); + // if the button state has changed, + if ((buttonState != previousButtonState) + // and it's currently pressed: + && (buttonState == HIGH)) { + // increment the button counter + counter++; + // type out a message + Keyboard.print("You pressed the button "); + Keyboard.print(counter); + Keyboard.println(" times."); + } + // save the current button state for comparison next time: + previousButtonState = buttonState; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino new file mode 100644 index 00000000..94efe8c3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -0,0 +1,104 @@ +/* + Arduino Programs Blink + + This sketch demonstrates the Keyboard library. + + For Leonardo and Due boards only. + + When you connect pin 2 to ground, it creates a new window with a key + combination (CTRL-N), then types in the Blink sketch, then auto-formats the + text using another key combination (CTRL-T), then uploads the sketch to the + currently selected Arduino using a final key combination (CTRL-U). + + Circuit: + - Arduino Leonardo, Micro, Due, LilyPad USB, or Yún + - wire to connect D2 to ground + + created 5 Mar 2012 + modified 29 Mar 2012 + by Tom Igoe + modified 3 May 2014 + by Scott Fitzgerald + + This example is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardReprogram +*/ + +#include "Keyboard.h" + +// use this option for OSX. +// Comment it out if using Windows or Linux: +char ctrlKey = KEY_LEFT_GUI; +// use this option for Windows and Linux. +// leave commented out if using OSX: +// char ctrlKey = KEY_LEFT_CTRL; + + +void setup() { + // make pin 2 an input and turn on the pull-up resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + while (digitalRead(2) == HIGH) { + // do nothing until pin 2 goes low + delay(500); + } + delay(1000); + // new document: + Keyboard.press(ctrlKey); + Keyboard.press('n'); + delay(100); + Keyboard.releaseAll(); + // wait for new window to open: + delay(1000); + + // versions of the Arduino IDE after 1.5 pre-populate new sketches with + // setup() and loop() functions let's clear the window before typing anything new + // select all + Keyboard.press(ctrlKey); + Keyboard.press('a'); + delay(500); + Keyboard.releaseAll(); + // delete the selected text + Keyboard.write(KEY_BACKSPACE); + delay(500); + + // Type out "blink": + Keyboard.println("void setup() {"); + Keyboard.println("pinMode(13, OUTPUT);"); + Keyboard.println("}"); + Keyboard.println(); + Keyboard.println("void loop() {"); + Keyboard.println("digitalWrite(13, HIGH);"); + Keyboard.print("delay(3000);"); + // 3000 ms is too long. Delete it: + for (int keystrokes = 0; keystrokes < 6; keystrokes++) { + delay(500); + Keyboard.write(KEY_BACKSPACE); + } + // make it 1000 instead: + Keyboard.println("1000);"); + Keyboard.println("digitalWrite(13, LOW);"); + Keyboard.println("delay(1000);"); + Keyboard.println("}"); + // tidy up: + Keyboard.press(ctrlKey); + Keyboard.press('t'); + delay(100); + Keyboard.releaseAll(); + delay(3000); + // upload code: + Keyboard.press(ctrlKey); + Keyboard.press('u'); + delay(100); + Keyboard.releaseAll(); + + // wait for the sweet oblivion of reprogramming: + while (true) + ; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino new file mode 100644 index 00000000..050bb18c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino @@ -0,0 +1,39 @@ +/* + Keyboard test + + For the Arduino Leonardo, Micro or Due + + Reads a byte from the serial port, sends a keystroke back. + The sent keystroke is one higher than what's received, e.g. if you send a, + you get b, send A you get B, and so forth. + + The circuit: + - none + + created 21 Oct 2011 + modified 27 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardSerial +*/ + +#include "Keyboard.h" + +void setup() { + // open the serial port: + Serial.begin(9600); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + // check for incoming serial data: + if (Serial.available() > 0) { + // read incoming serial data: + char inChar = Serial.read(); + // Type the next ASCII value from what you received: + Keyboard.write(inChar + 1); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino new file mode 100644 index 00000000..3b1a280f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino @@ -0,0 +1,92 @@ +/* + KeyboardAndMouseControl + + Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due. + + Hardware: + - five pushbuttons attached to D2, D3, D4, D5, D6 + + The mouse movement is always relative. This sketch reads four pushbuttons, and + uses them to set the movement of the mouse. + + WARNING: When you use the Mouse.move() command, the Arduino takes over your + mouse! Make sure you have control before you use the mouse commands. + + created 15 Mar 2012 + modified 27 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardAndMouseControl +*/ + +#include "Keyboard.h" +#include "Mouse.h" + +// set pin numbers for the five buttons: +const int upButton = 2; +const int downButton = 3; +const int leftButton = 4; +const int rightButton = 5; +const int mouseButton = 6; + +void setup() { // initialize the buttons' inputs: + pinMode(upButton, INPUT); + pinMode(downButton, INPUT); + pinMode(leftButton, INPUT); + pinMode(rightButton, INPUT); + pinMode(mouseButton, INPUT); + + Serial.begin(9600); + // initialize mouse control: + Mouse.begin(); + Keyboard.begin(); +} + +void loop() { + // use serial input to control the mouse: + if (Serial.available() > 0) { + char inChar = Serial.read(); + + switch (inChar) { + case 'u': + // move mouse up + Mouse.move(0, -40); + break; + case 'd': + // move mouse down + Mouse.move(0, 40); + break; + case 'l': + // move mouse left + Mouse.move(-40, 0); + break; + case 'r': + // move mouse right + Mouse.move(40, 0); + break; + case 'm': + // perform mouse left click + Mouse.click(MOUSE_LEFT); + break; + } + } + + // use the pushbuttons to control the keyboard: + if (digitalRead(upButton) == HIGH) { + Keyboard.write('u'); + } + if (digitalRead(downButton) == HIGH) { + Keyboard.write('d'); + } + if (digitalRead(leftButton) == HIGH) { + Keyboard.write('l'); + } + if (digitalRead(rightButton) == HIGH) { + Keyboard.write('r'); + } + if (digitalRead(mouseButton) == HIGH) { + Keyboard.write('m'); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino new file mode 100644 index 00000000..c27ef70f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino @@ -0,0 +1,84 @@ +/* + ButtonMouseControl + + For Leonardo and Due boards only. + + Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due. + + Hardware: + - five pushbuttons attached to D2, D3, D4, D5, D6 + + The mouse movement is always relative. This sketch reads four pushbuttons, + and uses them to set the movement of the mouse. + + WARNING: When you use the Mouse.move() command, the Arduino takes over your + mouse! Make sure you have control before you use the mouse commands. + + created 15 Mar 2012 + modified 27 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ButtonMouseControl +*/ + +#include "Mouse.h" + +// set pin numbers for the five buttons: +const int upButton = 2; +const int downButton = 3; +const int leftButton = 4; +const int rightButton = 5; +const int mouseButton = 6; + +int range = 5; // output range of X or Y movement; affects movement speed +int responseDelay = 10; // response delay of the mouse, in ms + + +void setup() { + // initialize the buttons' inputs: + pinMode(upButton, INPUT); + pinMode(downButton, INPUT); + pinMode(leftButton, INPUT); + pinMode(rightButton, INPUT); + pinMode(mouseButton, INPUT); + // initialize mouse control: + Mouse.begin(); +} + +void loop() { + // read the buttons: + int upState = digitalRead(upButton); + int downState = digitalRead(downButton); + int rightState = digitalRead(rightButton); + int leftState = digitalRead(leftButton); + int clickState = digitalRead(mouseButton); + + // calculate the movement distance based on the button states: + int xDistance = (leftState - rightState) * range; + int yDistance = (upState - downState) * range; + + // if X or Y is non-zero, move: + if ((xDistance != 0) || (yDistance != 0)) { + Mouse.move(xDistance, yDistance, 0); + } + + // if the mouse button is pressed: + if (clickState == HIGH) { + // if the mouse is not pressed, press it: + if (!Mouse.isPressed(MOUSE_LEFT)) { + Mouse.press(MOUSE_LEFT); + } + } + // else the mouse button is not pressed: + else { + // if the mouse is pressed, release it: + if (Mouse.isPressed(MOUSE_LEFT)) { + Mouse.release(MOUSE_LEFT); + } + } + + // a delay so the mouse doesn't move too fast: + delay(responseDelay); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino new file mode 100644 index 00000000..266ba61f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino @@ -0,0 +1,120 @@ +/* + JoystickMouseControl + + Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due. + Uses a pushbutton to turn on and off mouse control, and a second pushbutton + to click the left mouse button. + + Hardware: + - 2-axis joystick connected to pins A0 and A1 + - pushbuttons connected to pin D2 and D3 + + The mouse movement is always relative. This sketch reads two analog inputs + that range from 0 to 1023 (or less on either end) and translates them into + ranges of -6 to 6. + The sketch assumes that the joystick resting values are around the middle of + the range, but that they vary within a threshold. + + WARNING: When you use the Mouse.move() command, the Arduino takes over your + mouse! Make sure you have control before you use the command. This sketch + includes a pushbutton to toggle the mouse control state, so you can turn on + and off mouse control. + + created 15 Sep 2011 + updated 28 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/JoystickMouseControl +*/ + +#include "Mouse.h" + +// set pin numbers for switch, joystick axes, and LED: +const int switchPin = 2; // switch to turn on and off mouse control +const int mouseButton = 3; // input pin for the mouse pushButton +const int xAxis = A0; // joystick X axis +const int yAxis = A1; // joystick Y axis +const int ledPin = 5; // Mouse control LED + +// parameters for reading the joystick: +int range = 12; // output range of X or Y movement +int responseDelay = 5; // response delay of the mouse, in ms +int threshold = range / 4; // resting threshold +int center = range / 2; // resting position value + +bool mouseIsActive = false; // whether or not to control the mouse +int lastSwitchState = LOW; // previous switch state + +void setup() { + pinMode(switchPin, INPUT); // the switch pin + pinMode(ledPin, OUTPUT); // the LED pin + // take control of the mouse: + Mouse.begin(); +} + +void loop() { + // read the switch: + int switchState = digitalRead(switchPin); + // if it's changed and it's high, toggle the mouse state: + if (switchState != lastSwitchState) { + if (switchState == HIGH) { + mouseIsActive = !mouseIsActive; + // turn on LED to indicate mouse state: + digitalWrite(ledPin, mouseIsActive); + } + } + // save switch state for next comparison: + lastSwitchState = switchState; + + // read and scale the two axes: + int xReading = readAxis(A0); + int yReading = readAxis(A1); + + // if the mouse control state is active, move the mouse: + if (mouseIsActive) { + Mouse.move(xReading, yReading, 0); + } + + // read the mouse button and click or not click: + // if the mouse button is pressed: + if (digitalRead(mouseButton) == HIGH) { + // if the mouse is not pressed, press it: + if (!Mouse.isPressed(MOUSE_LEFT)) { + Mouse.press(MOUSE_LEFT); + } + } + // else the mouse button is not pressed: + else { + // if the mouse is pressed, release it: + if (Mouse.isPressed(MOUSE_LEFT)) { + Mouse.release(MOUSE_LEFT); + } + } + + delay(responseDelay); +} + +/* + reads an axis (0 or 1 for x or y) and scales the analog input range to a range + from 0 to +*/ + +int readAxis(int thisAxis) { + // read the analog input: + int reading = analogRead(thisAxis); + + // map the reading from the analog input range to the output range: + reading = map(reading, 0, 1023, 0, range); + + // if the output reading is outside from the rest position threshold, use it: + int distance = reading - center; + + if (abs(distance) < threshold) { + distance = 0; + } + + // return the distance for this axis: + return distance; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.txt b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.txt new file mode 100644 index 00000000..55fa2bc4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.txt @@ -0,0 +1 @@ +Controls a computer's cursor movement with a Joystick when a button is pressed. \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino new file mode 100644 index 00000000..255d1009 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino @@ -0,0 +1,63 @@ +/* + Arduino Starter Kit example + Project 2 - Spaceship Interface + + This sketch is written to accompany Project 2 in the Arduino Starter Kit + + Parts required: + - one green LED + - two red LEDs + - pushbutton + - 10 kilohm resistor + - three 220 ohm resistors + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// Create a global variable to hold the state of the switch. This variable is +// persistent throughout the program. Whenever you refer to switchState, you’re +// talking about the number it holds +int switchstate = 0; + +void setup() { + // declare the LED pins as outputs + pinMode(3, OUTPUT); + pinMode(4, OUTPUT); + pinMode(5, OUTPUT); + + // declare the switch pin as an input + pinMode(2, INPUT); +} + +void loop() { + + // read the value of the switch + // digitalRead() checks to see if there is voltage on the pin or not + switchstate = digitalRead(2); + + // if the button is not pressed turn on the green LED and off the red LEDs + if (switchstate == LOW) { + digitalWrite(3, HIGH); // turn the green LED on pin 3 on + digitalWrite(4, LOW); // turn the red LED on pin 4 off + digitalWrite(5, LOW); // turn the red LED on pin 5 off + } + // this else is part of the above if() statement. + // if the switch is not LOW (the button is pressed) turn off the green LED and + // blink alternatively the red LEDs + else { + digitalWrite(3, LOW); // turn the green LED on pin 3 off + digitalWrite(4, LOW); // turn the red LED on pin 4 off + digitalWrite(5, HIGH); // turn the red LED on pin 5 on + // wait for a quarter second before changing the light + delay(250); + digitalWrite(4, HIGH); // turn the red LED on pin 4 on + digitalWrite(5, LOW); // turn the red LED on pin 5 off + // wait for a quarter second before changing the light + delay(250); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino new file mode 100644 index 00000000..e8390a39 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino @@ -0,0 +1,81 @@ +/* + Arduino Starter Kit example + Project 3 - Love-O-Meter + + This sketch is written to accompany Project 3 in the Arduino Starter Kit + + Parts required: + - one TMP36 temperature sensor + - three red LEDs + - three 220 ohm resistors + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// named constant for the pin the sensor is connected to +const int sensorPin = A0; +// room temperature in Celsius +const float baselineTemp = 20.0; + +void setup() { + // open a serial connection to display values + Serial.begin(9600); + // set the LED pins as outputs + // the for() loop saves some extra coding + for (int pinNumber = 2; pinNumber < 5; pinNumber++) { + pinMode(pinNumber, OUTPUT); + digitalWrite(pinNumber, LOW); + } +} + +void loop() { + // read the value on AnalogIn pin 0 and store it in a variable + int sensorVal = analogRead(sensorPin); + + // send the 10-bit sensor value out the serial port + Serial.print("sensor Value: "); + Serial.print(sensorVal); + + // convert the ADC reading to voltage + float voltage = (sensorVal / 1024.0) * 5.0; + + // Send the voltage level out the Serial port + Serial.print(", Volts: "); + Serial.print(voltage); + + // convert the voltage to temperature in degrees C + // the sensor changes 10 mV per degree + // the datasheet says there's a 500 mV offset + // ((voltage - 500 mV) times 100) + Serial.print(", degrees C: "); + float temperature = (voltage - .5) * 100; + Serial.println(temperature); + + // if the current temperature is lower than the baseline turn off all LEDs + if (temperature < baselineTemp + 2) { + digitalWrite(2, LOW); + digitalWrite(3, LOW); + digitalWrite(4, LOW); + } // if the temperature rises 2-4 degrees, turn an LED on + else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) { + digitalWrite(2, HIGH); + digitalWrite(3, LOW); + digitalWrite(4, LOW); + } // if the temperature rises 4-6 degrees, turn a second LED on + else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) { + digitalWrite(2, HIGH); + digitalWrite(3, HIGH); + digitalWrite(4, LOW); + } // if the temperature rises more than 6 degrees, turn all LEDs on + else if (temperature >= baselineTemp + 6) { + digitalWrite(2, HIGH); + digitalWrite(3, HIGH); + digitalWrite(4, HIGH); + } + delay(1); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino new file mode 100644 index 00000000..8efc4110 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino @@ -0,0 +1,96 @@ +/* + Arduino Starter Kit example + Project 4 - Color Mixing Lamp + + This sketch is written to accompany Project 3 in the Arduino Starter Kit + + Parts required: + - one RGB LED + - three 10 kilohm resistors + - three 220 ohm resistors + - three photoresistors + - red green and blue colored gels + + created 13 Sep 2012 + modified 14 Nov 2012 + by Scott Fitzgerald + Thanks to Federico Vanzati for improvements + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +const int greenLEDPin = 9; // LED connected to digital pin 9 +const int redLEDPin = 10; // LED connected to digital pin 10 +const int blueLEDPin = 11; // LED connected to digital pin 11 + +const int redSensorPin = A0; // pin with the photoresistor with the red gel +const int greenSensorPin = A1; // pin with the photoresistor with the green gel +const int blueSensorPin = A2; // pin with the photoresistor with the blue gel + +int redValue = 0; // value to write to the red LED +int greenValue = 0; // value to write to the green LED +int blueValue = 0; // value to write to the blue LED + +int redSensorValue = 0; // variable to hold the value from the red sensor +int greenSensorValue = 0; // variable to hold the value from the green sensor +int blueSensorValue = 0; // variable to hold the value from the blue sensor + +void setup() { + // initialize serial communications at 9600 bps: + Serial.begin(9600); + + // set the digital pins as outputs + pinMode(greenLEDPin, OUTPUT); + pinMode(redLEDPin, OUTPUT); + pinMode(blueLEDPin, OUTPUT); +} + +void loop() { + // Read the sensors first: + + // read the value from the red-filtered photoresistor: + redSensorValue = analogRead(redSensorPin); + // give the ADC a moment to settle + delay(5); + // read the value from the green-filtered photoresistor: + greenSensorValue = analogRead(greenSensorPin); + // give the ADC a moment to settle + delay(5); + // read the value from the blue-filtered photoresistor: + blueSensorValue = analogRead(blueSensorPin); + + // print out the values to the Serial Monitor + Serial.print("raw sensor Values \t red: "); + Serial.print(redSensorValue); + Serial.print("\t green: "); + Serial.print(greenSensorValue); + Serial.print("\t Blue: "); + Serial.println(blueSensorValue); + + /* + In order to use the values from the sensor for the LED, you need to do some + math. The ADC provides a 10-bit number, but analogWrite() uses 8 bits. + You'll want to divide your sensor readings by 4 to keep them in range + of the output. + */ + redValue = redSensorValue / 4; + greenValue = greenSensorValue / 4; + blueValue = blueSensorValue / 4; + + // print out the mapped values + Serial.print("Mapped sensor Values \t red: "); + Serial.print(redValue); + Serial.print("\t green: "); + Serial.print(greenValue); + Serial.print("\t Blue: "); + Serial.println(blueValue); + + /* + Now that you have a usable value, it's time to PWM the LED. + */ + analogWrite(redLEDPin, redValue); + analogWrite(greenLEDPin, greenValue); + analogWrite(blueLEDPin, blueValue); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino new file mode 100644 index 00000000..5e2ccf3c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino @@ -0,0 +1,52 @@ +/* + Arduino Starter Kit example + Project 5 - Servo Mood Indicator + + This sketch is written to accompany Project 5 in the Arduino Starter Kit + + Parts required: + - servo motor + - 10 kilohm potentiometer + - two 100 uF electrolytic capacitors + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// include the Servo library +#include + +Servo myServo; // create a servo object + +int const potPin = A0; // analog pin used to connect the potentiometer +int potVal; // variable to read the value from the analog pin +int angle; // variable to hold the angle for the servo motor + +void setup() { + myServo.attach(9); // attaches the servo on pin 9 to the servo object + Serial.begin(9600); // open a serial connection to your computer +} + +void loop() { + potVal = analogRead(potPin); // read the value of the potentiometer + // print out the value to the Serial Monitor + Serial.print("potVal: "); + Serial.print(potVal); + + // scale the numbers from the pot + angle = map(potVal, 0, 1023, 0, 179); + + // print out the angle for the servo motor + Serial.print(", angle: "); + Serial.println(angle); + + // set the servo position + myServo.write(angle); + + // wait for the servo to get there + delay(15); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino new file mode 100644 index 00000000..1b794058 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino @@ -0,0 +1,62 @@ +/* + Arduino Starter Kit example + Project 6 - Light Theremin + + This sketch is written to accompany Project 6 in the Arduino Starter Kit + + Parts required: + - photoresistor + - 10 kilohm resistor + - piezo + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// variable to hold sensor value +int sensorValue; +// variable to calibrate low value +int sensorLow = 1023; +// variable to calibrate high value +int sensorHigh = 0; +// LED pin +const int ledPin = 13; + +void setup() { + // Make the LED pin an output and turn it on + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); + + // calibrate for the first five seconds after program runs + while (millis() < 5000) { + // record the maximum sensor value + sensorValue = analogRead(A0); + if (sensorValue > sensorHigh) { + sensorHigh = sensorValue; + } + // record the minimum sensor value + if (sensorValue < sensorLow) { + sensorLow = sensorValue; + } + } + // turn the LED off, signaling the end of the calibration period + digitalWrite(ledPin, LOW); +} + +void loop() { + //read the input from A0 and store it in a variable + sensorValue = analogRead(A0); + + // map the sensor values to a wide range of pitches + int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000); + + // play the tone for 20 ms on pin 8 + tone(8, pitch, 20); + + // wait for a moment + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino new file mode 100644 index 00000000..f6b6fb36 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino @@ -0,0 +1,54 @@ +/* + Arduino Starter Kit example + Project 7 - Keyboard + + This sketch is written to accompany Project 7 in the Arduino Starter Kit + + Parts required: + - two 10 kilohm resistors + - 1 megohm resistor + - 220 ohm resistor + - four pushbuttons + - piezo + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// create an array of notes +// the numbers below correspond to the frequencies of middle C, D, E, and F +int notes[] = { 262, 294, 330, 349 }; + +void setup() { + //start serial communication + Serial.begin(9600); +} + +void loop() { + // create a local variable to hold the input on pin A0 + int keyVal = analogRead(A0); + // send the value from A0 to the Serial Monitor + Serial.println(keyVal); + + // play the note corresponding to each value on A0 + if (keyVal == 1023) { + // play the first frequency in the array on pin 8 + tone(8, notes[0]); + } else if (keyVal >= 990 && keyVal <= 1010) { + // play the second frequency in the array on pin 8 + tone(8, notes[1]); + } else if (keyVal >= 505 && keyVal <= 515) { + // play the third frequency in the array on pin 8 + tone(8, notes[2]); + } else if (keyVal >= 5 && keyVal <= 10) { + // play the fourth frequency in the array on pin 8 + tone(8, notes[3]); + } else { + // if the value is out of range, play no tone + noTone(8); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino new file mode 100644 index 00000000..9fbbc186 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino @@ -0,0 +1,79 @@ +/* + Arduino Starter Kit example + Project 8 - Digital Hourglass + + This sketch is written to accompany Project 8 in the Arduino Starter Kit + + Parts required: + - 10 kilohm resistor + - six 220 ohm resistors + - six LEDs + - tilt switch + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// named constant for the switch pin +const int switchPin = 8; + +unsigned long previousTime = 0; // store the last time an LED was updated +int switchState = 0; // the current switch state +int prevSwitchState = 0; // the previous switch state +int led = 2; // a variable to refer to the LEDs + +// 600000 = 10 minutes in milliseconds +long interval = 600000; // interval at which to light the next LED + +void setup() { + // set the LED pins as outputs + for (int x = 2; x < 8; x++) { + pinMode(x, OUTPUT); + } + // set the tilt switch pin as input + pinMode(switchPin, INPUT); +} + +void loop() { + // store the time since the Arduino started running in a variable + unsigned long currentTime = millis(); + + // compare the current time to the previous time an LED turned on + // if it is greater than your interval, run the if statement + if (currentTime - previousTime > interval) { + // save the current time as the last time you changed an LED + previousTime = currentTime; + // Turn the LED on + digitalWrite(led, HIGH); + // increment the led variable + // in 10 minutes the next LED will light up + led++; + + if (led == 7) { + // the hour is up + } + } + + // read the switch value + switchState = digitalRead(switchPin); + + // if the switch has changed + if (switchState != prevSwitchState) { + // turn all the LEDs low + for (int x = 2; x < 8; x++) { + digitalWrite(x, LOW); + } + + // reset the LED variable to the first one + led = 2; + + //reset the timer + previousTime = currentTime; + } + // set the previous switch state to the current state + prevSwitchState = switchState; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino new file mode 100644 index 00000000..8841d32f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino @@ -0,0 +1,48 @@ +/* + Arduino Starter Kit example + Project 9 - Motorized Pinwheel + + This sketch is written to accompany Project 9 in the Arduino Starter Kit + + Parts required: + - 10 kilohm resistor + - pushbutton + - motor + - 9V battery + - IRF520 MOSFET + - 1N4007 diode + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// named constants for the switch and motor pins +const int switchPin = 2; // the number of the switch pin +const int motorPin = 9; // the number of the motor pin + +int switchState = 0; // variable for reading the switch's status + +void setup() { + // initialize the motor pin as an output: + pinMode(motorPin, OUTPUT); + // initialize the switch pin as an input: + pinMode(switchPin, INPUT); +} + +void loop() { + // read the state of the switch value: + switchState = digitalRead(switchPin); + + // check if the switch is pressed. + if (switchState == HIGH) { + // turn motor on: + digitalWrite(motorPin, HIGH); + } else { + // turn motor off: + digitalWrite(motorPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino new file mode 100644 index 00000000..9b9991fa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino @@ -0,0 +1,103 @@ +/* + Arduino Starter Kit example + Project 10 - Zoetrope + + This sketch is written to accompany Project 10 in the Arduino Starter Kit + + Parts required: + - two 10 kilohm resistors + - two momentary pushbuttons + - one 10 kilohm potentiometer + - motor + - 9V battery + - H-Bridge + + created 13 Sep 2012 + by Scott Fitzgerald + Thanks to Federico Vanzati for improvements + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +const int controlPin1 = 2; // connected to pin 7 on the H-bridge +const int controlPin2 = 3; // connected to pin 2 on the H-bridge +const int enablePin = 9; // connected to pin 1 on the H-bridge +const int directionSwitchPin = 4; // connected to the switch for direction +const int onOffSwitchStateSwitchPin = 5; // connected to the switch for turning the motor on and off +const int potPin = A0; // connected to the potentiometer's output + +// create some variables to hold values from your inputs +int onOffSwitchState = 0; // current state of the on/off switch +int previousOnOffSwitchState = 0; // previous position of the on/off switch +int directionSwitchState = 0; // current state of the direction switch +int previousDirectionSwitchState = 0; // previous state of the direction switch + +int motorEnabled = 0; // Turns the motor on/off +int motorSpeed = 0; // speed of the motor +int motorDirection = 1; // current direction of the motor + +void setup() { + // initialize the inputs and outputs + pinMode(directionSwitchPin, INPUT); + pinMode(onOffSwitchStateSwitchPin, INPUT); + pinMode(controlPin1, OUTPUT); + pinMode(controlPin2, OUTPUT); + pinMode(enablePin, OUTPUT); + + // pull the enable pin LOW to start + digitalWrite(enablePin, LOW); +} + +void loop() { + // read the value of the on/off switch + onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin); + delay(1); + + // read the value of the direction switch + directionSwitchState = digitalRead(directionSwitchPin); + + // read the value of the pot and divide by 4 to get a value that can be + // used for PWM + motorSpeed = analogRead(potPin) / 4; + + // if the on/off button changed state since the last loop() + if (onOffSwitchState != previousOnOffSwitchState) { + // change the value of motorEnabled if pressed + if (onOffSwitchState == HIGH) { + motorEnabled = !motorEnabled; + } + } + + // if the direction button changed state since the last loop() + if (directionSwitchState != previousDirectionSwitchState) { + // change the value of motorDirection if pressed + if (directionSwitchState == HIGH) { + motorDirection = !motorDirection; + } + } + + // change the direction the motor spins by talking to the control pins + // on the H-Bridge + if (motorDirection == 1) { + digitalWrite(controlPin1, HIGH); + digitalWrite(controlPin2, LOW); + } else { + digitalWrite(controlPin1, LOW); + digitalWrite(controlPin2, HIGH); + } + + // if the motor is supposed to be on + if (motorEnabled == 1) { + // PWM the enable pin to vary the speed + analogWrite(enablePin, motorSpeed); + } else { // if the motor is not supposed to be on + //turn the motor off + analogWrite(enablePin, 0); + } + // save the current on/off switch state as the previous + previousDirectionSwitchState = directionSwitchState; + // save the current switch state as the previous + previousOnOffSwitchState = onOffSwitchState; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino new file mode 100644 index 00000000..a5a6acb4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino @@ -0,0 +1,114 @@ +/* + Arduino Starter Kit example + Project 11 - Crystal Ball + + This sketch is written to accompany Project 11 in the Arduino Starter Kit + + Parts required: + - 220 ohm resistor + - 10 kilohm resistor + - 10 kilohm potentiometer + - 16x2 LCD screen + - tilt switch + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +// set up a constant for the tilt switch pin +const int switchPin = 6; + +// variable to hold the value of the switch pin +int switchState = 0; + +// variable to hold previous value of the switch pin +int prevSwitchState = 0; + +// a variable to choose which reply from the crystal ball +int reply; + +void setup() { + // set up the number of columns and rows on the LCD + lcd.begin(16, 2); + + // set up the switch pin as an input + pinMode(switchPin, INPUT); + + // Print a message to the LCD. + lcd.print("Ask the"); + // set the cursor to column 0, line 1 + // line 1 is the second row, since counting begins with 0 + lcd.setCursor(0, 1); + // print to the second line + lcd.print("Crystal Ball!"); +} + +void loop() { + // check the status of the switch + switchState = digitalRead(switchPin); + + // compare the switchState to its previous state + if (switchState != prevSwitchState) { + // if the state has changed from HIGH to LOW you know that the ball has been + // tilted from one direction to the other + if (switchState == LOW) { + // randomly chose a reply + reply = random(8); + // clean up the screen before printing a new reply + lcd.clear(); + // set the cursor to column 0, line 0 + lcd.setCursor(0, 0); + // print some text + lcd.print("the ball says:"); + // move the cursor to the second line + lcd.setCursor(0, 1); + + // choose a saying to print based on the value in reply + switch (reply) { + case 0: + lcd.print("Yes"); + break; + + case 1: + lcd.print("Most likely"); + break; + + case 2: + lcd.print("Certainly"); + break; + + case 3: + lcd.print("Outlook good"); + break; + + case 4: + lcd.print("Unsure"); + break; + + case 5: + lcd.print("Ask again"); + break; + + case 6: + lcd.print("Doubtful"); + break; + + case 7: + lcd.print("No"); + break; + } + } + } + // save the current switch state as the last state + prevSwitchState = switchState; +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino new file mode 100644 index 00000000..6401ac91 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino @@ -0,0 +1,171 @@ +/* + Arduino Starter Kit example + Project 12 - Knock Lock + + This sketch is written to accompany Project 12 in the Arduino Starter Kit + + Parts required: + - 1 megohm resistor + - 10 kilohm resistor + - three 220 ohm resistors + - piezo + - servo motor + - push button + - one red LED + - one yellow LED + - one green LED + - 100 uF capacitor + + created 18 Sep 2012 + by Scott Fitzgerald + Thanks to Federico Vanzati for improvements + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// import the library +#include +// create an instance of the Servo library +Servo myServo; + +const int piezo = A0; // pin the piezo is attached to +const int switchPin = 2; // pin the switch is attached to +const int yellowLed = 3; // pin the yellow LED is attached to +const int greenLed = 4; // pin the green LED is attached to +const int redLed = 5; // pin the red LED is attached to + +// variable for the piezo value +int knockVal; +// variable for the switch value +int switchVal; + +// variables for the high and low limits of the knock value +const int quietKnock = 10; +const int loudKnock = 100; + +// variable to indicate if locked or not +bool locked = false; +// how many valid knocks you've received +int numberOfKnocks = 0; + +void setup() { + // attach the servo to pin 9 + myServo.attach(9); + + // make the LED pins outputs + pinMode(yellowLed, OUTPUT); + pinMode(redLed, OUTPUT); + pinMode(greenLed, OUTPUT); + + // set the switch pin as an input + pinMode(switchPin, INPUT); + + // start serial communication for debugging + Serial.begin(9600); + + // turn the green LED on + digitalWrite(greenLed, HIGH); + + // move the servo to the unlocked position + myServo.write(0); + + // print status to the Serial Monitor + Serial.println("the box is unlocked!"); +} + +void loop() { + + // if the box is unlocked + if (locked == false) { + + // read the value of the switch pin + switchVal = digitalRead(switchPin); + + // if the button is pressed, lock the box + if (switchVal == HIGH) { + // set the locked variable to "true" + locked = true; + + // change the status LEDs + digitalWrite(greenLed, LOW); + digitalWrite(redLed, HIGH); + + // move the servo to the locked position + myServo.write(90); + + // print out status + Serial.println("the box is locked!"); + + // wait for the servo to move into position + delay(1000); + } + } + + // if the box is locked + if (locked == true) { + + // check the value of the piezo + knockVal = analogRead(piezo); + + // if there are not enough valid knocks + if (numberOfKnocks < 3 && knockVal > 0) { + + // check to see if the knock is in range + if (checkForKnock(knockVal) == true) { + + // increment the number of valid knocks + numberOfKnocks++; + } + + // print status of knocks + Serial.print(3 - numberOfKnocks); + Serial.println(" more knocks to go"); + } + + // if there are three knocks + if (numberOfKnocks >= 3) { + // unlock the box + locked = false; + + // move the servo to the unlocked position + myServo.write(0); + + // wait for it to move + delay(20); + + // change status LEDs + digitalWrite(greenLed, HIGH); + digitalWrite(redLed, LOW); + Serial.println("the box is unlocked!"); + + numberOfKnocks = 0; + } + } +} + +// this function checks to see if a detected knock is within max and min range +bool checkForKnock(int value) { + // if the value of the knock is greater than the minimum, and larger + // than the maximum + if (value > quietKnock && value < loudKnock) { + // turn the status LED on + digitalWrite(yellowLed, HIGH); + delay(50); + digitalWrite(yellowLed, LOW); + // print out the status + Serial.print("Valid knock of value "); + Serial.println(value); + // return true + return true; + } + // if the knock is not within range + else { + // print status + Serial.print("Bad knock value "); + Serial.println(value); + // return false + return false; + } +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino new file mode 100644 index 00000000..4f25cbe3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino @@ -0,0 +1,66 @@ +/* + Arduino Starter Kit example + Project 13 - Touch Sensor Lamp + + This sketch is written to accompany Project 13 in the Arduino Starter Kit + + Parts required: + - 1 megohm resistor + - metal foil or copper mesh + - 220 ohm resistor + - LED + + Software required : + - CapacitiveSensor library by Paul Badger + https://www.arduino.cc/reference/en/libraries/capacitivesensor/ + + created 18 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// import the library (must be located in the Arduino/libraries directory) +#include + +// create an instance of the library +// pin 4 sends electrical energy +// pin 2 senses senses a change +CapacitiveSensor capSensor = CapacitiveSensor(4, 2); + +// threshold for turning the lamp on +int threshold = 1000; + +// pin the LED is connected to +const int ledPin = 12; + + +void setup() { + // open a serial connection + Serial.begin(9600); + // set the LED pin as an output + pinMode(ledPin, OUTPUT); +} + +void loop() { + // store the value reported by the sensor in a variable + long sensorValue = capSensor.capacitiveSensor(30); + + // print out the sensor value + Serial.println(sensorValue); + + // if the value is greater than the threshold + if (sensorValue > threshold) { + // turn the LED on + digitalWrite(ledPin, HIGH); + } + // if it's lower than the threshold + else { + // turn the LED off + digitalWrite(ledPin, LOW); + } + + delay(10); +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino new file mode 100644 index 00000000..043b6003 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino @@ -0,0 +1,101 @@ +/* + Arduino Starter Kit example + Project 14 - Tweak the Arduino Logo + + This sketch is written to accompany Project 14 in the Arduino Starter Kit + + Parts required: + - 10 kilohm potentiometer + + Software required: + - Processing (3.0 or newer) https://processing.org/ + - Active Internet connection + + created 18 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + + +void setup() { + // initialize serial communication + Serial.begin(9600); +} + +void loop() { + // read the value of A0, divide by 4 and send it as a byte over the + // serial connection + Serial.write(analogRead(A0) / 4); + delay(1); +} + +/* Processing code for this example + + // Tweak the Arduino Logo + + // by Scott Fitzgerald + // This example code is in the public domain. + + // import the serial library + import processing.serial.*; + + // create an instance of the serial library + Serial myPort; + + // create an instance of PImage + PImage logo; + + // a variable to hold the background color + int bgcolor = 0; + + void setup() { + size(1, 1); + surface.setResizable(true); + // set the color mode to Hue/Saturation/Brightness + colorMode(HSB, 255); + + // load the Arduino logo into the PImage instance + logo = loadImage("http://www.arduino.cc/arduino_logo.png"); + + // make the window the same size as the image + surface.setSize(logo.width, logo.height); + + // print a list of available serial ports to the Processing status window + println("Available serial ports:"); + println(Serial.list()); + + // Tell the serial object the information it needs to communicate with the + // Arduino. Change Serial.list()[0] to the correct port corresponding to + // your Arduino board. The last parameter (e.g. 9600) is the speed of the + // communication. It has to correspond to the value passed to + // Serial.begin() in your Arduino sketch. + myPort = new Serial(this, Serial.list()[0], 9600); + + // If you know the name of the port used by the Arduino board, you can + // specify it directly like this. + // port = new Serial(this, "COM1", 9600); + } + + void draw() { + + // if there is information in the serial port + if ( myPort.available() > 0) { + // read the value and store it in a variable + bgcolor = myPort.read(); + + // print the value to the status window + println(bgcolor); + } + + // Draw the background. the variable bgcolor contains the Hue, determined by + // the value from the serial port + background(bgcolor, 255, 255); + + // draw the Arduino logo + image(logo, 0, 0); + } + +*/ diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino new file mode 100644 index 00000000..9db4bbff --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino @@ -0,0 +1,34 @@ +/* + Arduino Starter Kit example + Project 15 - Hacking Buttons + + This sketch is written to accompany Project 15 in the Arduino Starter Kit + + Parts required: + - battery powered component + - 220 ohm resistor + - 4N35 optocoupler + + created 18 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +const int optoPin = 2; // the pin the optocoupler is connected to + +void setup() { + // make the pin with the optocoupler an output + pinMode(optoPin, OUTPUT); +} + +void loop() { + digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler + + delay(15); // give the optocoupler a moment to activate + + digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again + delay(21000); // wait for 21 seconds +} diff --git a/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino new file mode 100644 index 00000000..c75d2332 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/samples/arduino/arduino-examples/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -0,0 +1,734 @@ +// ArduinoISP +// Copyright (c) 2008-2011 Randall Bohn +// If you require a license, see +// https://opensource.org/licenses/bsd-license.php +// +// This sketch turns the Arduino into a AVRISP using the following Arduino pins: +// +// Pin 10 is used to reset the target microcontroller. +// +// By default, the hardware SPI pins MISO, MOSI and SCK are used to communicate +// with the target. On all Arduinos, these pins can be found +// on the ICSP/SPI header: +// +// MISO °. . 5V (!) Avoid this pin on Due, Zero... +// SCK . . MOSI +// . . GND +// +// On some Arduinos (Uno,...), pins MOSI, MISO and SCK are the same pins as +// digital pin 11, 12 and 13, respectively. That is why many tutorials instruct +// you to hook up the target to these pins. If you find this wiring more +// practical, have a define USE_OLD_STYLE_WIRING. This will work even when not +// using an Uno. (On an Uno this is not needed). +// +// Alternatively you can use any other digital pin by configuring +// software ('BitBanged') SPI and having appropriate defines for PIN_MOSI, +// PIN_MISO and PIN_SCK. +// +// IMPORTANT: When using an Arduino that is not 5V tolerant (Due, Zero, ...) as +// the programmer, make sure to not expose any of the programmer's pins to 5V. +// A simple way to accomplish this is to power the complete system (programmer +// and target) at 3V3. +// +// Put an LED (with resistor) on the following pins: +// 9: Heartbeat - shows the programmer is running +// 8: Error - Lights up if something goes wrong (use red if that makes sense) +// 7: Programming - In communication with the target +// + +#include "Arduino.h" +#undef SERIAL + + +#define PROG_FLICKER true + +// Configure SPI clock (in Hz). +// E.g. for an ATtiny @ 128 kHz: the datasheet states that both the high and low +// SPI clock pulse must be > 2 CPU cycles, so take 3 cycles i.e. divide target +// f_cpu by 6: +// #define SPI_CLOCK (128000/6) +// +// A clock slow enough for an ATtiny85 @ 1 MHz, is a reasonable default: + +#define SPI_CLOCK (1000000 / 6) + + +// Select hardware or software SPI, depending on SPI clock. +// Currently only for AVR, for other architectures (Due, Zero,...), hardware SPI +// is probably too fast anyway. + +#if defined(ARDUINO_ARCH_AVR) + +#if SPI_CLOCK > (F_CPU / 128) +#define USE_HARDWARE_SPI +#endif + +#endif + +// Configure which pins to use: + +// The standard pin configuration. +#ifndef ARDUINO_HOODLOADER2 + +#define RESET 10 // Use pin 10 to reset the target rather than SS +#define LED_HB 9 +#define LED_ERR 8 +#define LED_PMODE 7 + +// Uncomment following line to use the old Uno style wiring +// (using pin 11, 12 and 13 instead of the SPI header) on Leonardo, Due... + +// #define USE_OLD_STYLE_WIRING + +#ifdef USE_OLD_STYLE_WIRING + +#define PIN_MOSI 11 +#define PIN_MISO 12 +#define PIN_SCK 13 + +#endif + +// HOODLOADER2 means running sketches on the ATmega16U2 serial converter chips +// on Uno or Mega boards. We must use pins that are broken out: +#else + +#define RESET 4 +#define LED_HB 7 +#define LED_ERR 6 +#define LED_PMODE 5 + +#endif + +// By default, use hardware SPI pins: +#ifndef PIN_MOSI +#define PIN_MOSI MOSI +#endif + +#ifndef PIN_MISO +#define PIN_MISO MISO +#endif + +#ifndef PIN_SCK +#define PIN_SCK SCK +#endif + +// Force bitbanged SPI if not using the hardware SPI pins: +#if (PIN_MISO != MISO) || (PIN_MOSI != MOSI) || (PIN_SCK != SCK) +#undef USE_HARDWARE_SPI +#endif + + +// Configure the serial port to use. +// +// Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one: +// - it does not autoreset (except for the magic baud rate of 1200). +// - it is more reliable because of USB handshaking. +// +// Leonardo and similar have an USB virtual serial port: 'Serial'. +// Due and Zero have an USB virtual serial port: 'SerialUSB'. +// +// On the Due and Zero, 'Serial' can be used too, provided you disable autoreset. +// To use 'Serial': #define SERIAL Serial + +#ifdef SERIAL_PORT_USBVIRTUAL +#define SERIAL SERIAL_PORT_USBVIRTUAL +#else +#define SERIAL Serial +#endif + + +// Configure the baud rate: + +#define BAUDRATE 19200 +// #define BAUDRATE 115200 +// #define BAUDRATE 1000000 + + +#define HWVER 2 +#define SWMAJ 1 +#define SWMIN 18 + +// STK Definitions +#define STK_OK 0x10 +#define STK_FAILED 0x11 +#define STK_UNKNOWN 0x12 +#define STK_INSYNC 0x14 +#define STK_NOSYNC 0x15 +#define CRC_EOP 0x20 //ok it is a space... + +void pulse(int pin, int times); + +#ifdef USE_HARDWARE_SPI +#include "SPI.h" +#else + +#define SPI_MODE0 0x00 + +#if !defined(ARDUINO_API_VERSION) || ARDUINO_API_VERSION != 10001 // A SPISettings class is declared by ArduinoCore-API 1.0.1 +class SPISettings { +public: + // clock is in Hz + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) + : clockFreq(clock) { + (void)bitOrder; + (void)dataMode; + }; + + uint32_t getClockFreq() const { + return clockFreq; + } + +private: + uint32_t clockFreq; +}; +#endif // !defined(ARDUINO_API_VERSION) + +class BitBangedSPI { +public: + void begin() { + digitalWrite(PIN_SCK, LOW); + digitalWrite(PIN_MOSI, LOW); + pinMode(PIN_SCK, OUTPUT); + pinMode(PIN_MOSI, OUTPUT); + pinMode(PIN_MISO, INPUT); + } + + void beginTransaction(SPISettings settings) { + pulseWidth = (500000 + settings.getClockFreq() - 1) / settings.getClockFreq(); + if (pulseWidth == 0) { + pulseWidth = 1; + } + } + + void end() {} + + uint8_t transfer(uint8_t b) { + for (unsigned int i = 0; i < 8; ++i) { + digitalWrite(PIN_MOSI, (b & 0x80) ? HIGH : LOW); + digitalWrite(PIN_SCK, HIGH); + delayMicroseconds(pulseWidth); + b = (b << 1) | digitalRead(PIN_MISO); + digitalWrite(PIN_SCK, LOW); // slow pulse + delayMicroseconds(pulseWidth); + } + return b; + } + +private: + unsigned long pulseWidth; // in microseconds +}; + +static BitBangedSPI SPI; + +#endif + +void setup() { + SERIAL.begin(BAUDRATE); + + pinMode(LED_PMODE, OUTPUT); + pulse(LED_PMODE, 2); + pinMode(LED_ERR, OUTPUT); + pulse(LED_ERR, 2); + pinMode(LED_HB, OUTPUT); + pulse(LED_HB, 2); +} + +int ISPError = 0; +int pmode = 0; +// address for reading and writing, set by 'U' command +unsigned int here; +uint8_t buff[256]; // global block storage + +#define beget16(addr) (*addr * 256 + *(addr + 1)) +typedef struct param { + uint8_t devicecode; + uint8_t revision; + uint8_t progtype; + uint8_t parmode; + uint8_t polling; + uint8_t selftimed; + uint8_t lockbytes; + uint8_t fusebytes; + uint8_t flashpoll; + uint16_t eeprompoll; + uint16_t pagesize; + uint16_t eepromsize; + uint32_t flashsize; +} parameter; + +parameter param; + +// this provides a heartbeat on pin 9, so you can tell the software is running. +uint8_t hbval = 128; +int8_t hbdelta = 8; +void heartbeat() { + static unsigned long last_time = 0; + unsigned long now = millis(); + if ((now - last_time) < 40) { + return; + } + last_time = now; + if (hbval > 192) { + hbdelta = -hbdelta; + } + if (hbval < 32) { + hbdelta = -hbdelta; + } + hbval += hbdelta; + analogWrite(LED_HB, hbval); +} + +static bool rst_active_high; + +void reset_target(bool reset) { + digitalWrite(RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW); +} + +void loop(void) { + // is pmode active? + if (pmode) { + digitalWrite(LED_PMODE, HIGH); + } else { + digitalWrite(LED_PMODE, LOW); + } + // is there an error? + if (ISPError) { + digitalWrite(LED_ERR, HIGH); + } else { + digitalWrite(LED_ERR, LOW); + } + + // light the heartbeat LED + heartbeat(); + if (SERIAL.available()) { + avrisp(); + } +} + +uint8_t getch() { + while (!SERIAL.available()) + ; + return SERIAL.read(); +} +void fill(int n) { + for (int x = 0; x < n; x++) { + buff[x] = getch(); + } +} + +#define PTIME 30 +void pulse(int pin, int times) { + do { + digitalWrite(pin, HIGH); + delay(PTIME); + digitalWrite(pin, LOW); + delay(PTIME); + } while (times--); +} + +void prog_lamp(int state) { + if (PROG_FLICKER) { + digitalWrite(LED_PMODE, state); + } +} + +uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { + SPI.transfer(a); + SPI.transfer(b); + SPI.transfer(c); + return SPI.transfer(d); +} + +void empty_reply() { + if (CRC_EOP == getch()) { + SERIAL.print((char)STK_INSYNC); + SERIAL.print((char)STK_OK); + } else { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + } +} + +void breply(uint8_t b) { + if (CRC_EOP == getch()) { + SERIAL.print((char)STK_INSYNC); + SERIAL.print((char)b); + SERIAL.print((char)STK_OK); + } else { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + } +} + +void get_version(uint8_t c) { + switch (c) { + case 0x80: + breply(HWVER); + break; + case 0x81: + breply(SWMAJ); + break; + case 0x82: + breply(SWMIN); + break; + case 0x93: + breply('S'); // serial programmer + break; + default: + breply(0); + } +} + +void set_parameters() { + // call this after reading parameter packet into buff[] + param.devicecode = buff[0]; + param.revision = buff[1]; + param.progtype = buff[2]; + param.parmode = buff[3]; + param.polling = buff[4]; + param.selftimed = buff[5]; + param.lockbytes = buff[6]; + param.fusebytes = buff[7]; + param.flashpoll = buff[8]; + // ignore buff[9] (= buff[8]) + // following are 16 bits (big endian) + param.eeprompoll = beget16(&buff[10]); + param.pagesize = beget16(&buff[12]); + param.eepromsize = beget16(&buff[14]); + + // 32 bits flashsize (big endian) + param.flashsize = buff[16] * 0x01000000 + + buff[17] * 0x00010000 + + buff[18] * 0x00000100 + + buff[19]; + + // AVR devices have active low reset, AT89Sx are active high + rst_active_high = (param.devicecode >= 0xe0); +} + +void start_pmode() { + + // Reset target before driving PIN_SCK or PIN_MOSI + + // SPI.begin() will configure SS as output, so SPI master mode is selected. + // We have defined RESET as pin 10, which for many Arduinos is not the SS pin. + // So we have to configure RESET as output here, + // (reset_target() first sets the correct level) + reset_target(true); + pinMode(RESET, OUTPUT); + SPI.begin(); + SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0)); + + // See AVR datasheets, chapter "SERIAL_PRG Programming Algorithm": + + // Pulse RESET after PIN_SCK is low: + digitalWrite(PIN_SCK, LOW); + delay(20); // discharge PIN_SCK, value arbitrarily chosen + reset_target(false); + // Pulse must be minimum 2 target CPU clock cycles so 100 usec is ok for CPU + // speeds above 20 KHz + delayMicroseconds(100); + reset_target(true); + + // Send the enable programming command: + delay(50); // datasheet: must be > 20 msec + spi_transaction(0xAC, 0x53, 0x00, 0x00); + pmode = 1; +} + +void end_pmode() { + SPI.end(); + // We're about to take the target out of reset so configure SPI pins as input + pinMode(PIN_MOSI, INPUT); + pinMode(PIN_SCK, INPUT); + reset_target(false); + pinMode(RESET, INPUT); + pmode = 0; +} + +void universal() { + uint8_t ch; + + fill(4); + ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]); + breply(ch); +} + +void flash(uint8_t hilo, unsigned int addr, uint8_t data) { + spi_transaction(0x40 + 8 * hilo, + addr >> 8 & 0xFF, + addr & 0xFF, + data); +} +void commit(unsigned int addr) { + if (PROG_FLICKER) { + prog_lamp(LOW); + } + spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0); + if (PROG_FLICKER) { + delay(PTIME); + prog_lamp(HIGH); + } +} + +unsigned int current_page() { + if (param.pagesize == 32) { + return here & 0xFFFFFFF0; + } + if (param.pagesize == 64) { + return here & 0xFFFFFFE0; + } + if (param.pagesize == 128) { + return here & 0xFFFFFFC0; + } + if (param.pagesize == 256) { + return here & 0xFFFFFF80; + } + return here; +} + + +void write_flash(int length) { + fill(length); + if (CRC_EOP == getch()) { + SERIAL.print((char)STK_INSYNC); + SERIAL.print((char)write_flash_pages(length)); + } else { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + } +} + +uint8_t write_flash_pages(int length) { + int x = 0; + unsigned int page = current_page(); + while (x < length) { + if (page != current_page()) { + commit(page); + page = current_page(); + } + flash(LOW, here, buff[x++]); + flash(HIGH, here, buff[x++]); + here++; + } + + commit(page); + + return STK_OK; +} + +#define EECHUNK (32) +uint8_t write_eeprom(unsigned int length) { + // here is a word address, get the byte address + unsigned int start = here * 2; + unsigned int remaining = length; + if (length > param.eepromsize) { + ISPError++; + return STK_FAILED; + } + while (remaining > EECHUNK) { + write_eeprom_chunk(start, EECHUNK); + start += EECHUNK; + remaining -= EECHUNK; + } + write_eeprom_chunk(start, remaining); + return STK_OK; +} +// write (length) bytes, (start) is a byte address +uint8_t write_eeprom_chunk(unsigned int start, unsigned int length) { + // this writes byte-by-byte, page writing may be faster (4 bytes at a time) + fill(length); + prog_lamp(LOW); + for (unsigned int x = 0; x < length; x++) { + unsigned int addr = start + x; + spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]); + delay(45); + } + prog_lamp(HIGH); + return STK_OK; +} + +void program_page() { + char result = (char)STK_FAILED; + unsigned int length = 256 * getch(); + length += getch(); + char memtype = getch(); + // flash memory @here, (length) bytes + if (memtype == 'F') { + write_flash(length); + return; + } + if (memtype == 'E') { + result = (char)write_eeprom(length); + if (CRC_EOP == getch()) { + SERIAL.print((char)STK_INSYNC); + SERIAL.print(result); + } else { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + } + return; + } + SERIAL.print((char)STK_FAILED); + return; +} + +uint8_t flash_read(uint8_t hilo, unsigned int addr) { + return spi_transaction(0x20 + hilo * 8, + (addr >> 8) & 0xFF, + addr & 0xFF, + 0); +} + +char flash_read_page(int length) { + for (int x = 0; x < length; x += 2) { + uint8_t low = flash_read(LOW, here); + SERIAL.print((char)low); + uint8_t high = flash_read(HIGH, here); + SERIAL.print((char)high); + here++; + } + return STK_OK; +} + +char eeprom_read_page(int length) { + // here again we have a word address + int start = here * 2; + for (int x = 0; x < length; x++) { + int addr = start + x; + uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF); + SERIAL.print((char)ee); + } + return STK_OK; +} + +void read_page() { + char result = (char)STK_FAILED; + int length = 256 * getch(); + length += getch(); + char memtype = getch(); + if (CRC_EOP != getch()) { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + return; + } + SERIAL.print((char)STK_INSYNC); + if (memtype == 'F') { + result = flash_read_page(length); + } + if (memtype == 'E') { + result = eeprom_read_page(length); + } + SERIAL.print(result); +} + +void read_signature() { + if (CRC_EOP != getch()) { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + return; + } + SERIAL.print((char)STK_INSYNC); + uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00); + SERIAL.print((char)high); + uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00); + SERIAL.print((char)middle); + uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00); + SERIAL.print((char)low); + SERIAL.print((char)STK_OK); +} +////////////////////////////////////////// +////////////////////////////////////////// + + +//////////////////////////////////// +//////////////////////////////////// +void avrisp() { + uint8_t ch = getch(); + switch (ch) { + case '0': // signon + ISPError = 0; + empty_reply(); + break; + case '1': + if (getch() == CRC_EOP) { + SERIAL.print((char)STK_INSYNC); + SERIAL.print("AVR ISP"); + SERIAL.print((char)STK_OK); + } else { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + } + break; + case 'A': + get_version(getch()); + break; + case 'B': + fill(20); + set_parameters(); + empty_reply(); + break; + case 'E': // extended parameters - ignore for now + fill(5); + empty_reply(); + break; + case 'P': + if (!pmode) { + start_pmode(); + } + empty_reply(); + break; + case 'U': // set address (word) + here = getch(); + here += 256 * getch(); + empty_reply(); + break; + + case 0x60: //STK_PROG_FLASH + getch(); // low addr + getch(); // high addr + empty_reply(); + break; + case 0x61: //STK_PROG_DATA + getch(); // data + empty_reply(); + break; + + case 0x64: //STK_PROG_PAGE + program_page(); + break; + + case 0x74: //STK_READ_PAGE 't' + read_page(); + break; + + case 'V': //0x56 + universal(); + break; + case 'Q': //0x51 + ISPError = 0; + end_pmode(); + empty_reply(); + break; + + case 0x75: //STK_READ_SIGN 'u' + read_signature(); + break; + + // expecting a command, not CRC_EOP + // this is how we can get back in sync + case CRC_EOP: + ISPError++; + SERIAL.print((char)STK_NOSYNC); + break; + + // anything else we will return STK_UNKNOWN + default: + ISPError++; + if (CRC_EOP == getch()) { + SERIAL.print((char)STK_UNKNOWN); + } else { + SERIAL.print((char)STK_NOSYNC); + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AccessModifierOffset.cpp b/other/clang-format-configuration/testdata/golden/targeted/AccessModifierOffset.cpp new file mode 100644 index 00000000..93f928fb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AccessModifierOffset.cpp @@ -0,0 +1,5 @@ +class Foo { +public: +protected: +private: +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignAfterOpenBracket.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignAfterOpenBracket.cpp new file mode 100644 index 00000000..13400624 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignAfterOpenBracket.cpp @@ -0,0 +1,11 @@ +void foo(int arg1, int arg2) { + (void)arg1; + (void)arg2; +} + +void bar() { + foo(42, + 1234); + foo(42, + 1234); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignArrayOfStructures.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignArrayOfStructures.cpp new file mode 100644 index 00000000..642ec5a1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignArrayOfStructures.cpp @@ -0,0 +1,19 @@ +struct Foo_t { + int bar; + int baz; +}; + +Foo_t pippo[] = { + { 1, 11 }, + { 11, 1 }, +}; + +Foo_t pluto[] = { + { 1, 11 }, + { 11, 1 }, +}; + +Foo_t paperino[] = { + { 1, 11 }, + { 11, 1 }, +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveAssignments.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveAssignments.cpp new file mode 100644 index 00000000..051866db --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveAssignments.cpp @@ -0,0 +1,5 @@ +int a = 42; +int bb = 42; + +int ccc = 42; +int dddd = 42; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveBitFields.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveBitFields.cpp new file mode 100644 index 00000000..94f338d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveBitFields.cpp @@ -0,0 +1,7 @@ +struct Foo_t { + int a : 1; + int bb : 16; + + int ccc : 1; + int dddd : 16; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveDeclarations.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveDeclarations.cpp new file mode 100644 index 00000000..7aa2c57d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveDeclarations.cpp @@ -0,0 +1,5 @@ +int a = 42; +long b = 42; + +int c = 42; +long d = 42; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveMacros.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveMacros.cpp new file mode 100644 index 00000000..47f4b297 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignConsecutiveMacros.cpp @@ -0,0 +1,5 @@ +#define FOO_A 42 +#define FOO_BB 42 + +#define FOO_CCC 42 +#define FOO_DDDD 42 diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignEscapedNewlines.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignEscapedNewlines.cpp new file mode 100644 index 00000000..dbe76dd2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignEscapedNewlines.cpp @@ -0,0 +1,20 @@ +#define FOO \ + int a; \ + int bb; \ + int ccc; \ + int dddd; \ + int e; + +#define BAR \ + int a; \ + int bb; \ + int ccc; \ + int dddd; \ + int e; + +#define BAZ \ + int a; \ + int bb; \ + int ccc; \ + int dddd; \ + int e; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignOperands.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignOperands.cpp new file mode 100644 index 00000000..442aee26 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignOperands.cpp @@ -0,0 +1,9 @@ +int foo = 42 + 1234; + +int bar = 42 + 1234; + +int baz = 42 + + 1234; + +int qux = 42 + + 1234; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlignTrailingComments.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlignTrailingComments.cpp new file mode 100644 index 00000000..d525c3e9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlignTrailingComments.cpp @@ -0,0 +1,5 @@ +int a; // foo +int b = 42; // foo + +int c; // foo +int d = 42; // foo diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowAllArgumentsOnNextLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowAllArgumentsOnNextLine.cpp new file mode 100644 index 00000000..75aefbd2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowAllArgumentsOnNextLine.cpp @@ -0,0 +1,12 @@ +void foo(int arg1, int arg2) { + (void)arg1; + (void)arg2; +} + +void bar() { + foo( + 42, 1234); + + foo(42, + 1234); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowAllConstructorInitializersOnNextLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowAllConstructorInitializersOnNextLine.cpp new file mode 100644 index 00000000..80d43834 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowAllConstructorInitializersOnNextLine.cpp @@ -0,0 +1,13 @@ +class Foo { + Foo(); + Foo(int); + int bar; + int baz; +}; + +Foo::Foo() + : bar(42), baz(1234) {} + +Foo::Foo(int qux) + : bar(qux), + baz(1234) {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowAllParametersOfDeclarationOnNextLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowAllParametersOfDeclarationOnNextLine.cpp new file mode 100644 index 00000000..971ed280 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowAllParametersOfDeclarationOnNextLine.cpp @@ -0,0 +1,21 @@ +void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( + int foo, int bar, int baz); +void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( + int foo, int bar, int baz) { + + (void)foo; + (void)bar; + (void)baz; +} + +void bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(int foo, + int bar, + int baz); +void bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(int foo, + int bar, + int baz) { + + (void)foo; + (void)bar; + (void)baz; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortBlocksOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortBlocksOnASingleLine.cpp new file mode 100644 index 00000000..1a7f90cb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortBlocksOnASingleLine.cpp @@ -0,0 +1,10 @@ +void foo() { + while (true) { + } + + while (true) {} + + while (true) { + continue; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortCaseLabelsOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortCaseLabelsOnASingleLine.cpp new file mode 100644 index 00000000..08fc617a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortCaseLabelsOnASingleLine.cpp @@ -0,0 +1,7 @@ +void foo() { + switch (1) { + case 2: break; + case 3: + break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortEnumsOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortEnumsOnASingleLine.cpp new file mode 100644 index 00000000..ebd41977 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortEnumsOnASingleLine.cpp @@ -0,0 +1,7 @@ +enum Foo_t { A, + B }; + +enum Bar_t { + C, + D +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortFunctionsOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortFunctionsOnASingleLine.cpp new file mode 100644 index 00000000..910ec46c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortFunctionsOnASingleLine.cpp @@ -0,0 +1,27 @@ +void foo() {} + +void bar() { +} + +int baz() { + return 42; +} + +int qux() { + return 42; +} + +class Pippo { + void foo() {} + + void bar() { + } + + int baz() { + return 42; + } + + int qux() { + return 42; + } +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp new file mode 100644 index 00000000..a4e3f7a5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortIfStatementsOnASingleLine.cpp @@ -0,0 +1,18 @@ +void foo() { + bool a = true; + + if (a) + return; + else { + return; + } + + if (a) return; + else + return; + + if (a) return; + else { + return; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortLambdasOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortLambdasOnASingleLine.cpp new file mode 100644 index 00000000..c25185d0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortLambdasOnASingleLine.cpp @@ -0,0 +1,13 @@ +auto foo = []() {}; + +auto bar = []() { +}; + +auto baz = []() { + return 42; +}; + +void qux(void (*)()) {} +void pippo() { + qux([]() {}); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AllowShortLoopsOnASingleLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/AllowShortLoopsOnASingleLine.cpp new file mode 100644 index 00000000..13bbf9ae --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AllowShortLoopsOnASingleLine.cpp @@ -0,0 +1,10 @@ +void foo() { + while (true) continue; + + while (true) + continue; + + while (true) { + continue; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakAfterReturnType.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakAfterReturnType.cpp new file mode 100644 index 00000000..355a137e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakAfterReturnType.cpp @@ -0,0 +1,23 @@ +int foo(); + +int foo() { + return 42; +} + +class Bar { + int foo() { + return 42; + } +}; + +int baz(); + +int baz() { + return 42; +} + +class Qux { + int baz() { + return 42; + } +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakBeforeMultilineStrings.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakBeforeMultilineStrings.cpp new file mode 100644 index 00000000..f1fe78da --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakBeforeMultilineStrings.cpp @@ -0,0 +1,11 @@ +void foo() { + char bar[] = + "asdf" + "zxcv"; + + char baz[] = "asdf" + "zxcv"; + + (void)bar; + (void)baz; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakTemplateDeclarations.cpp b/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakTemplateDeclarations.cpp new file mode 100644 index 00000000..c31eb810 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/AlwaysBreakTemplateDeclarations.cpp @@ -0,0 +1,15 @@ +template T foo() {} +template +T bar() {} + +template T baz(int a, + int b) { + (void)a; + (void)b; +} +template +T qux(int a, + int b) { + (void)a; + (void)b; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BinPackArguments.cpp b/other/clang-format-configuration/testdata/golden/targeted/BinPackArguments.cpp new file mode 100644 index 00000000..999fdbd2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BinPackArguments.cpp @@ -0,0 +1,16 @@ +void foo(int arg1, int arg2, int arg3) { + (void)arg1; + (void)arg2; + (void)arg3; +} + +void bar() { + int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 42; + + foo(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); + + foo(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BinPackParameters.cpp b/other/clang-format-configuration/testdata/golden/targeted/BinPackParameters.cpp new file mode 100644 index 00000000..77d16aa9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BinPackParameters.cpp @@ -0,0 +1,16 @@ +void foo(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + int cccccccccccccccccccccccccccccccccccccccccccccccccc) { + + (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + (void)bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + (void)cccccccccccccccccccccccccccccccccccccccccccccccccc; +} + +void bar(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + int cccccccccccccccccccccccccccccccccccccccccccccccccc) { + + (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + (void)bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + (void)cccccccccccccccccccccccccccccccccccccccccccccccccc; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BitFieldColonSpacing.cpp b/other/clang-format-configuration/testdata/golden/targeted/BitFieldColonSpacing.cpp new file mode 100644 index 00000000..0245c1be --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BitFieldColonSpacing.cpp @@ -0,0 +1,6 @@ +struct Foo_t { + int foo : 2; + int bar : 2; + int baz : 2; + int qux : 2; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterCaseLabel.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterCaseLabel.cpp new file mode 100644 index 00000000..b6d85d23 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterCaseLabel.cpp @@ -0,0 +1,12 @@ +void foo() { + switch (1) { + case 2: + { + break; + } + case 3: + { + break; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterClass.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterClass.cpp new file mode 100644 index 00000000..3087f500 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterClass.cpp @@ -0,0 +1,7 @@ +class Foo { +public: +}; + +class Bar { +public: +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterControlStatement.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterControlStatement.cpp new file mode 100644 index 00000000..3d1390e4 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterControlStatement.cpp @@ -0,0 +1,17 @@ +void foo() { + if (true) { + return; + } + + if (true) { + return; + } + + if (true && true) { + return; + } + + if (true && true) { + return; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterEnum.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterEnum.cpp new file mode 100644 index 00000000..a4ea5375 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterEnum.cpp @@ -0,0 +1,9 @@ +enum Foo_t { + A, + B +}; + +enum Bar_t { + C, + D +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterExternBlock.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterExternBlock.cpp new file mode 100644 index 00000000..ec217d2a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterExternBlock.cpp @@ -0,0 +1,7 @@ +extern "C" { + int foo(); +} + +extern "C" { + int bar(); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterFunction.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterFunction.cpp new file mode 100644 index 00000000..e769e415 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterFunction.cpp @@ -0,0 +1,7 @@ +void foo() { + return; +} + +void bar() { + return; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterNamespace.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterNamespace.cpp new file mode 100644 index 00000000..2f14e3e8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterNamespace.cpp @@ -0,0 +1,7 @@ +namespace { +__attribute__((unused)) int foo; +} + +namespace { +__attribute__((unused)) int bar; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterStruct.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterStruct.cpp new file mode 100644 index 00000000..6ca08f78 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterStruct.cpp @@ -0,0 +1,7 @@ +struct Foo_t { + int bar; +}; + +struct Baz_t { + int qux; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterUnion.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterUnion.cpp new file mode 100644 index 00000000..9503d616 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_AfterUnion.cpp @@ -0,0 +1,7 @@ +union Foo_t { + int bar; +}; + +union Baz_t { + int qux; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeCatch.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeCatch.cpp new file mode 100644 index 00000000..fbacaf29 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeCatch.cpp @@ -0,0 +1,15 @@ +void foo() {} + +void bar() { + try { + foo(); + } catch (int e) { + (void)e; + } + + try { + foo(); + } catch (int e) { + (void)e; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeElse.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeElse.cpp new file mode 100644 index 00000000..a8ba1da6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeElse.cpp @@ -0,0 +1,13 @@ +void foo() { + if (true) { + return; + } else { + return; + } + + if (true) { + return; + } else { + return; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeLambdaBody.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeLambdaBody.cpp new file mode 100644 index 00000000..a3ce54aa --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeLambdaBody.cpp @@ -0,0 +1,11 @@ +void foo(void (*)()) {} + +void bar() { + foo([]() { + return; + }); + + foo([]() { + return; + }); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeWhile.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeWhile.cpp new file mode 100644 index 00000000..ed8f4c9e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_BeforeWhile.cpp @@ -0,0 +1,9 @@ +void foo() { + do { + continue; + } while (true); + + do { + continue; + } while (true); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_IndentBraces.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_IndentBraces.cpp new file mode 100644 index 00000000..fb94b99c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_IndentBraces.cpp @@ -0,0 +1,3 @@ +void foo() {} + +void bar() {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyFunction.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyFunction.cpp new file mode 100644 index 00000000..858e1acf --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyFunction.cpp @@ -0,0 +1,9 @@ +void foo() { +} + +void bar() {} + +void baz() { +} + +void qux() {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyNamespace.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyNamespace.cpp new file mode 100644 index 00000000..d7a585c5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyNamespace.cpp @@ -0,0 +1,9 @@ +namespace { +} + +namespace { +} + +namespace {} + +namespace {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyRecord.cpp b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyRecord.cpp new file mode 100644 index 00000000..0ef315d6 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BraceWrapping_SplitEmptyRecord.cpp @@ -0,0 +1,9 @@ +class Foo { +}; + +class Bar { +}; + +class Baz {}; + +class Qux {}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBinaryOperators.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBinaryOperators.cpp new file mode 100644 index 00000000..483e490c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBinaryOperators.cpp @@ -0,0 +1,16 @@ +int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 42; + +int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + +int ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + +int ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd = + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +int eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee = + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +int fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Allman.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Allman.cpp new file mode 100644 index 00000000..9a742a7c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Allman.cpp @@ -0,0 +1,54 @@ +extern "C" { + void foo(); +} + +void foo() { + switch (1) { + case 2: + { + break; + } + } + + if (true) { + return; + } + + do { + continue; + } while (true); +} + +void bar() { + try { + foo(); + } catch (int e) { + (void)e; + } + try { + foo(); + } catch (int e) { + (void)e; + } +} + +class Foo { +public: +}; + +enum Foo_t { + A, + B +}; + +namespace { +const int foo = 42; +} + +struct Bar_t { + int foo; +}; + +union Baz_t { + int foo; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Attach.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Attach.cpp new file mode 100644 index 00000000..9a742a7c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Attach.cpp @@ -0,0 +1,54 @@ +extern "C" { + void foo(); +} + +void foo() { + switch (1) { + case 2: + { + break; + } + } + + if (true) { + return; + } + + do { + continue; + } while (true); +} + +void bar() { + try { + foo(); + } catch (int e) { + (void)e; + } + try { + foo(); + } catch (int e) { + (void)e; + } +} + +class Foo { +public: +}; + +enum Foo_t { + A, + B +}; + +namespace { +const int foo = 42; +} + +struct Bar_t { + int foo; +}; + +union Baz_t { + int foo; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Whitesmiths.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Whitesmiths.cpp new file mode 100644 index 00000000..9a742a7c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeBraces_Whitesmiths.cpp @@ -0,0 +1,54 @@ +extern "C" { + void foo(); +} + +void foo() { + switch (1) { + case 2: + { + break; + } + } + + if (true) { + return; + } + + do { + continue; + } while (true); +} + +void bar() { + try { + foo(); + } catch (int e) { + (void)e; + } + try { + foo(); + } catch (int e) { + (void)e; + } +} + +class Foo { +public: +}; + +enum Foo_t { + A, + B +}; + +namespace { +const int foo = 42; +} + +struct Bar_t { + int foo; +}; + +union Baz_t { + int foo; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeConceptDeclarations.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeConceptDeclarations.cpp new file mode 100644 index 00000000..ce35423a --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeConceptDeclarations.cpp @@ -0,0 +1,8 @@ +template +concept foo = requires(T bar) { + (void)bar; +}; + +template concept baz = requires(T bar) { + (void)bar; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeTernaryOperators.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeTernaryOperators.cpp new file mode 100644 index 00000000..06f646fc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakBeforeTernaryOperators.cpp @@ -0,0 +1,11 @@ +void foo() { + bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = true; + + bool bar = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + + bar = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + + (void)bar; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakConstructorInitializers.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakConstructorInitializers.cpp new file mode 100644 index 00000000..f881ec56 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakConstructorInitializers.cpp @@ -0,0 +1,18 @@ +class Foo { + Foo(); + Foo(int); + Foo(int, int); + int bar; + int baz; +}; + +Foo::Foo() + : bar(42), + baz(42) {} + +Foo::Foo(int qux) + : bar(qux), baz(42) {} + +Foo::Foo(int qux, int pippo) + : bar(qux), + baz(pippo) {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakInheritanceList.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakInheritanceList.cpp new file mode 100644 index 00000000..4973355e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakInheritanceList.cpp @@ -0,0 +1,13 @@ +class Foo {}; +class Bar {}; + +class Baz + : Foo, + Bar {}; + +class Qux + : Foo, + Bar {}; + +class Pippo : Foo, + Bar {}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/BreakStringLiterals.cpp b/other/clang-format-configuration/testdata/golden/targeted/BreakStringLiterals.cpp new file mode 100644 index 00000000..c24a3ef7 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/BreakStringLiterals.cpp @@ -0,0 +1,8 @@ +char foo[] = "veryVeryVeryVery" + "VeryVeryVeryVeryVeryVery" + "VeryVeryVeryVeryVeryVeryVery" + "VeryVeryVeryVeryVeryVeryVeryVery" + "VeryVeryVeryVeryVeryVeryVery" + "VeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; + +char bar[] = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; diff --git a/other/clang-format-configuration/testdata/golden/targeted/ColumnLimit.cpp b/other/clang-format-configuration/testdata/golden/targeted/ColumnLimit.cpp new file mode 100644 index 00000000..e6740fd9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/ColumnLimit.cpp @@ -0,0 +1 @@ +// VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong diff --git a/other/clang-format-configuration/testdata/golden/targeted/CompactNamespaces.cpp b/other/clang-format-configuration/testdata/golden/targeted/CompactNamespaces.cpp new file mode 100644 index 00000000..5baf8f3f --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/CompactNamespaces.cpp @@ -0,0 +1,9 @@ +namespace foo { +namespace bar { +} +} + +namespace baz { +namespace qux { +} +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/ConstructorInitializerAllOnOneLineOrOnePerLine.cpp b/other/clang-format-configuration/testdata/golden/targeted/ConstructorInitializerAllOnOneLineOrOnePerLine.cpp new file mode 100644 index 00000000..05c8001b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/ConstructorInitializerAllOnOneLineOrOnePerLine.cpp @@ -0,0 +1,15 @@ +class Foo { + Foo(); + Foo(int); + int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + int ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc; +}; + +Foo::Foo() + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(42), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(42), ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc(42) {} + +Foo::Foo(int bar) + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bar), + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(42), + ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc(42) {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/ConstructorInitializerIndentWidth.cpp b/other/clang-format-configuration/testdata/golden/targeted/ConstructorInitializerIndentWidth.cpp new file mode 100644 index 00000000..c037f181 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/ConstructorInitializerIndentWidth.cpp @@ -0,0 +1,20 @@ +class Foo { + Foo(); + Foo(int); + Foo(int, int); + int pippo; + int pluto; + int paperino; +}; +class Bar {}; +class Baz {}; + +class Qux + : Foo, + Bar, + Baz {}; + +Foo::Foo() + : pippo(42), + pluto(42), + paperino(42) {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/ContinuationIndentWidth.cpp b/other/clang-format-configuration/testdata/golden/targeted/ContinuationIndentWidth.cpp new file mode 100644 index 00000000..0fda66ef --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/ContinuationIndentWidth.cpp @@ -0,0 +1,2 @@ +int foo = + 42; diff --git a/other/clang-format-configuration/testdata/golden/targeted/Cpp11BracedListStyle.cpp b/other/clang-format-configuration/testdata/golden/targeted/Cpp11BracedListStyle.cpp new file mode 100644 index 00000000..ec922548 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/Cpp11BracedListStyle.cpp @@ -0,0 +1,3 @@ +int foo[] = { 42, 1234 }; + +int bar[] = { 42, 1234 }; diff --git a/other/clang-format-configuration/testdata/golden/targeted/DeriveLineEnding.cpp b/other/clang-format-configuration/testdata/golden/targeted/DeriveLineEnding.cpp new file mode 100644 index 00000000..5fe51a85 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/DeriveLineEnding.cpp @@ -0,0 +1 @@ +// this file intentionally has CRLF line endings diff --git a/other/clang-format-configuration/testdata/golden/targeted/DerivePointerAlignment.cpp b/other/clang-format-configuration/testdata/golden/targeted/DerivePointerAlignment.cpp new file mode 100644 index 00000000..154f202c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/DerivePointerAlignment.cpp @@ -0,0 +1,14 @@ +int* foo; +int* bar; +int* baz; +int* qux; + +void pippo(int& foo) { + (void)foo; +} +void pluto(int& foo) { + (void)foo; +} +void paperino(int& foo) { + (void)foo; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/EmptyLineAfterAccessModifier.cpp b/other/clang-format-configuration/testdata/golden/targeted/EmptyLineAfterAccessModifier.cpp new file mode 100644 index 00000000..aa0fbc85 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/EmptyLineAfterAccessModifier.cpp @@ -0,0 +1,17 @@ +class Foo { +public: + int foo; +}; + +class Bar { +public: + int foo; + +private: + int bar; +}; + +class Baz { +public: + int foo; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/EmptyLineBeforeAccessModifier.cpp b/other/clang-format-configuration/testdata/golden/targeted/EmptyLineBeforeAccessModifier.cpp new file mode 100644 index 00000000..84f20ce1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/EmptyLineBeforeAccessModifier.cpp @@ -0,0 +1,31 @@ +class Foo { +public: +private: + int foo; + +protected: +}; + +class Bar { +public: +private: + int foo; + +protected: +}; + +class Baz { +public: +private: + int foo; + +protected: +}; + +class Qux { +public: +private: + int foo; + +protected: +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/FixNamespaceComments.cpp b/other/clang-format-configuration/testdata/golden/targeted/FixNamespaceComments.cpp new file mode 100644 index 00000000..27970bbc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/FixNamespaceComments.cpp @@ -0,0 +1,5 @@ +namespace foo { +} + +namespace bar { +} // namespace baz diff --git a/other/clang-format-configuration/testdata/golden/targeted/IncludeBlocks.cpp b/other/clang-format-configuration/testdata/golden/targeted/IncludeBlocks.cpp new file mode 100644 index 00000000..1cb051ad --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IncludeBlocks.cpp @@ -0,0 +1,9 @@ +#include "include/b.h" +#include +#include "include/a.h" +#include + +#include "include/d.h" +#include +#include "include/c.h" +#include diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentAccessModifiers.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentAccessModifiers.cpp new file mode 100644 index 00000000..2e7b3ce1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentAccessModifiers.cpp @@ -0,0 +1,13 @@ +class Foo { + int bar; + +public: + int baz; +}; + +class Pippo { + int pluto; + +public: + int paperino; +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentCaseBlocks.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentCaseBlocks.cpp new file mode 100644 index 00000000..b6d85d23 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentCaseBlocks.cpp @@ -0,0 +1,12 @@ +void foo() { + switch (1) { + case 2: + { + break; + } + case 3: + { + break; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentCaseLabels.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentCaseLabels.cpp new file mode 100644 index 00000000..779ade6b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentCaseLabels.cpp @@ -0,0 +1,8 @@ +void foo() { + switch (1) { + case 2: + break; + case 3: + break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentExternBlock.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentExternBlock.cpp new file mode 100644 index 00000000..8196b19d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentExternBlock.cpp @@ -0,0 +1,4 @@ +extern "C" { + void foo(); + void bar(); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentGotoLabels.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentGotoLabels.cpp new file mode 100644 index 00000000..ac4da688 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentGotoLabels.cpp @@ -0,0 +1,7 @@ +void foo() { +bar: +baz: + + goto bar; + goto baz; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentPPDirectives.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentPPDirectives.cpp new file mode 100644 index 00000000..6d0fdbc9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentPPDirectives.cpp @@ -0,0 +1,7 @@ +#if defined(FOO) +#define BAR +#elif defined(BAZ) +#define QUX +#else +#define PIPPO +#endif diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp new file mode 100644 index 00000000..951d2da9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentRequires.cpp @@ -0,0 +1,5 @@ +template +requires true T foo() {} + +template +requires true T bar() {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentWidth.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentWidth.cpp new file mode 100644 index 00000000..4b35c4da --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentWidth.cpp @@ -0,0 +1,6 @@ +void foo() { + int bar; + (void)bar; + int baz; + (void)baz; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/IndentWrappedFunctionNames.cpp b/other/clang-format-configuration/testdata/golden/targeted/IndentWrappedFunctionNames.cpp new file mode 100644 index 00000000..fb94b99c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/IndentWrappedFunctionNames.cpp @@ -0,0 +1,3 @@ +void foo() {} + +void bar() {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/InsertTrailingCommas.cpp b/other/clang-format-configuration/testdata/golden/targeted/InsertTrailingCommas.cpp new file mode 100644 index 00000000..00118d1d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/InsertTrailingCommas.cpp @@ -0,0 +1,9 @@ +int foo[] = { + 42, + 1234 +}; + +int bar[] = { + 42, + 1234, +}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/KeepEmptyLinesAtTheStartOfBlocks.cpp b/other/clang-format-configuration/testdata/golden/targeted/KeepEmptyLinesAtTheStartOfBlocks.cpp new file mode 100644 index 00000000..43af71a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/KeepEmptyLinesAtTheStartOfBlocks.cpp @@ -0,0 +1,10 @@ +void foo() { + if (true) { + + return; + } + + if (true) { + return; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/LambdaBodyIndentation.cpp b/other/clang-format-configuration/testdata/golden/targeted/LambdaBodyIndentation.cpp new file mode 100644 index 00000000..5fb76e11 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/LambdaBodyIndentation.cpp @@ -0,0 +1,13 @@ +void foo(void (*)()) {} + +void bar() { + foo( + []() { + // baz + }); + + foo( + []() { + // baz + }); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/MaxEmptyLinesToKeep.cpp b/other/clang-format-configuration/testdata/golden/targeted/MaxEmptyLinesToKeep.cpp new file mode 100644 index 00000000..86dc4ce8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/MaxEmptyLinesToKeep.cpp @@ -0,0 +1,24 @@ +int foo; + + + + + + + + + + + + + + + + + + + + + + +int bar; diff --git a/other/clang-format-configuration/testdata/golden/targeted/NamespaceIndentation.cpp b/other/clang-format-configuration/testdata/golden/targeted/NamespaceIndentation.cpp new file mode 100644 index 00000000..95321c21 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/NamespaceIndentation.cpp @@ -0,0 +1,10 @@ +namespace { +const int foo = 42; +const int bar = 42; +namespace baz { +const int qux = 42; +} +namespace pippo { +const int pluto = 42; +} +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/PPIndentWidth.cpp b/other/clang-format-configuration/testdata/golden/targeted/PPIndentWidth.cpp new file mode 100644 index 00000000..6d0fdbc9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/PPIndentWidth.cpp @@ -0,0 +1,7 @@ +#if defined(FOO) +#define BAR +#elif defined(BAZ) +#define QUX +#else +#define PIPPO +#endif diff --git a/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp b/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp new file mode 100644 index 00000000..c86b3848 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/PackConstructorInitializers.cpp @@ -0,0 +1,27 @@ +class Foo { + Foo(); + Foo(int); + Foo(int, int); + Foo(int, int, int); + int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + int cccccccccccccccccccccccccccccccccccccccccccccccccc; + int d; + int e; + int f; + int ddddddddddddddddddddddddd; + int ggggggggggggggggggggggggg; + int hhhhhhhhhhhhhhhhhhhhhhhhh; + int iiiiiiiiiiiiiiiiiiiiiiiii; +}; + +Foo::Foo() + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(42), + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(1234), + cccccccccccccccccccccccccccccccccccccccccccccccccc(11) {} + +Foo::Foo(int bar) + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bar), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(1234), cccccccccccccccccccccccccccccccccccccccccccccccccc(11) {} + +Foo::Foo(int bar, int baz, int qux) + : ggggggggggggggggggggggggg(bar), hhhhhhhhhhhhhhhhhhhhhhhhh(baz), iiiiiiiiiiiiiiiiiiiiiiiii(qux) {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/PointerAlignment.cpp b/other/clang-format-configuration/testdata/golden/targeted/PointerAlignment.cpp new file mode 100644 index 00000000..2ce248d5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/PointerAlignment.cpp @@ -0,0 +1,13 @@ +int* foo; +int* bar; +int* baz; + +void pippo(int& foo) { + (void)foo; +} +void pluto(int& foo) { + (void)foo; +} +void paperino(int& foo) { + (void)foo; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/QualifierAlignment.cpp b/other/clang-format-configuration/testdata/golden/targeted/QualifierAlignment.cpp new file mode 100644 index 00000000..2871ab3d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/QualifierAlignment.cpp @@ -0,0 +1,2 @@ +const int foo = 42; +int const bar = 42; diff --git a/other/clang-format-configuration/testdata/golden/targeted/ReferenceAlignment.cpp b/other/clang-format-configuration/testdata/golden/targeted/ReferenceAlignment.cpp new file mode 100644 index 00000000..25ffdf45 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/ReferenceAlignment.cpp @@ -0,0 +1,9 @@ +void pippo(int& foo) { + (void)foo; +} +void pluto(int& foo) { + (void)foo; +} +void paperino(int& foo) { + (void)foo; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/ReflowComments.cpp b/other/clang-format-configuration/testdata/golden/targeted/ReflowComments.cpp new file mode 100644 index 00000000..407ae299 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/ReflowComments.cpp @@ -0,0 +1,11 @@ +// foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo +// foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo +// foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo + +/* bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar + * bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar + * bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar */ + +// foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo + +/* bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar */ diff --git a/other/clang-format-configuration/testdata/golden/targeted/RemoveBracesLLVM.cpp b/other/clang-format-configuration/testdata/golden/targeted/RemoveBracesLLVM.cpp new file mode 100644 index 00000000..5b1e2fa9 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/RemoveBracesLLVM.cpp @@ -0,0 +1,8 @@ +void foo() { + if (true) + return; + + if (true) { + return; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SeparateDefinitionBlocks.cpp b/other/clang-format-configuration/testdata/golden/targeted/SeparateDefinitionBlocks.cpp new file mode 100644 index 00000000..82f9df04 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SeparateDefinitionBlocks.cpp @@ -0,0 +1,11 @@ +int foo; + +void bar() {} +void baz() {} + +void qux() {} + +void pippo() {} + +void pluto() {} +void paperino() {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/ShortNamespaceLines.cpp b/other/clang-format-configuration/testdata/golden/targeted/ShortNamespaceLines.cpp new file mode 100644 index 00000000..4ca42355 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/ShortNamespaceLines.cpp @@ -0,0 +1,17 @@ +namespace { +} + +namespace { +__attribute__((unused)) int foo; +} + +namespace { +__attribute__((unused)) int bar; +__attribute__((unused)) int baz; +} + +namespace { +__attribute__((unused)) int pippo; +__attribute__((unused)) int pluto; +__attribute__((unused)) int paperino; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SortIncludes.cpp b/other/clang-format-configuration/testdata/golden/targeted/SortIncludes.cpp new file mode 100644 index 00000000..19c4cfab --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SortIncludes.cpp @@ -0,0 +1,4 @@ +#include "include/b.h" +#include "include/a.h" +#include +#include diff --git a/other/clang-format-configuration/testdata/golden/targeted/SortUsingDeclarations.cpp b/other/clang-format-configuration/testdata/golden/targeted/SortUsingDeclarations.cpp new file mode 100644 index 00000000..f6c084f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SortUsingDeclarations.cpp @@ -0,0 +1,13 @@ +namespace a { +int aa; +int ab; +} +namespace b { +int ba; +int bb; +} + +using b::bb; +using b::ba; +using a::ab; +using a::aa; diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterCStyleCast.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterCStyleCast.cpp new file mode 100644 index 00000000..79320cac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterCStyleCast.cpp @@ -0,0 +1,3 @@ +int foo = (int)42; + +int bar = (int)42; diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterLogicalNot.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterLogicalNot.cpp new file mode 100644 index 00000000..28501dbd --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterLogicalNot.cpp @@ -0,0 +1,4 @@ +bool foo() { + return !true; + return !true; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterTemplateKeyword.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterTemplateKeyword.cpp new file mode 100644 index 00000000..b071b0e0 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceAfterTemplateKeyword.cpp @@ -0,0 +1,3 @@ +template T foo() {} + +template T bar() {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceAroundPointerQualifiers.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceAroundPointerQualifiers.cpp new file mode 100644 index 00000000..9a9dcf6d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceAroundPointerQualifiers.cpp @@ -0,0 +1,2 @@ +void* const* foo = nullptr; +void* const* bar = nullptr; diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeAssignmentOperators.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeAssignmentOperators.cpp new file mode 100644 index 00000000..7a1c2cdc --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeAssignmentOperators.cpp @@ -0,0 +1,7 @@ +void foo() { + int bar = 42; + bar += 1; + + int baz = 42; + baz += 1; +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCaseColon.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCaseColon.cpp new file mode 100644 index 00000000..113de322 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCaseColon.cpp @@ -0,0 +1,6 @@ +void foo() { + switch (1) { + case 2: break; + case 3: break; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCpp11BracedList .cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCpp11BracedList .cpp new file mode 100644 index 00000000..038fedca --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCpp11BracedList .cpp @@ -0,0 +1,3 @@ +int foo{}; + +int bar{}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCtorInitializerColon.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCtorInitializerColon.cpp new file mode 100644 index 00000000..1afcebd5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeCtorInitializerColon.cpp @@ -0,0 +1,11 @@ +class Foo { + Foo(); + Foo(int); + int bar; +}; + +Foo::Foo() + : bar(42) {} + +Foo::Foo(int baz) + : bar(baz) {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeInheritanceColon.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeInheritanceColon.cpp new file mode 100644 index 00000000..22d65742 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeInheritanceColon.cpp @@ -0,0 +1,5 @@ +class Foo {}; + +class Bar : Foo {}; + +class Baz : Foo {}; diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeParens.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeParens.cpp new file mode 100644 index 00000000..18c7da57 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeParens.cpp @@ -0,0 +1,11 @@ +void foo() { + if (true) { + foo(); + } +} + +void bar() { + if (true) { + foo(); + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeParensOptions.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeParensOptions.cpp new file mode 100644 index 00000000..3d0fd695 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeParensOptions.cpp @@ -0,0 +1,40 @@ +void foo() { + if (true) {} + if (true) {} +} + +void bar(int); +void baz(int); + +void bar(int qux) { + (void)qux; +} +void baz(int qux) { + (void)qux; +} + +#if (true) +#endif +#if (true) +#endif + +class Foo { +public: + Foo(){}; + Foo(int baz) + : bar(baz) {} + int bar; + + Foo operator++(int qux) { + (void)qux; + return Foo(42); + } + + Foo operator--(int qux) { + (void)qux; + return Foo(42); + } +}; + +void pippo() {} +void pluto() {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeRangeBasedForLoopColon.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeRangeBasedForLoopColon.cpp new file mode 100644 index 00000000..fa093d47 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeRangeBasedForLoopColon.cpp @@ -0,0 +1,9 @@ +void foo() { + for (char bar : "baz") { + (void)bar; + } + + for (char bar : "baz") { + (void)bar; + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeSquareBrackets.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeSquareBrackets.cpp new file mode 100644 index 00000000..10934f92 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceBeforeSquareBrackets.cpp @@ -0,0 +1,2 @@ +int foo[42]; +int bar[42]; diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceInEmptyBlock.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceInEmptyBlock.cpp new file mode 100644 index 00000000..fb94b99c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceInEmptyBlock.cpp @@ -0,0 +1,3 @@ +void foo() {} + +void bar() {} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpaceInEmptyParentheses.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpaceInEmptyParentheses.cpp new file mode 100644 index 00000000..ba23207c --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpaceInEmptyParentheses.cpp @@ -0,0 +1,7 @@ +void foo() { + foo(); +} + +void bar() { + bar(); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpacesBeforeTrailingComments.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpacesBeforeTrailingComments.cpp new file mode 100644 index 00000000..a70b9f95 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpacesBeforeTrailingComments.cpp @@ -0,0 +1,3 @@ +//foo +// bar +// baz diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpacesInAngles.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpacesInAngles.cpp new file mode 100644 index 00000000..292ce32d --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpacesInAngles.cpp @@ -0,0 +1,6 @@ +template void bar() {} + +void baz() { + bar<42>(); + bar<42>(); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpacesInCStyleCastParentheses.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpacesInCStyleCastParentheses.cpp new file mode 100644 index 00000000..79320cac --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpacesInCStyleCastParentheses.cpp @@ -0,0 +1,3 @@ +int foo = (int)42; + +int bar = (int)42; diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpacesInConditionalStatement.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpacesInConditionalStatement.cpp new file mode 100644 index 00000000..1a92a5b1 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpacesInConditionalStatement.cpp @@ -0,0 +1,4 @@ +void foo() { + if (true) {} + if (true) {} +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpacesInLineCommentPrefix.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpacesInLineCommentPrefix.cpp new file mode 100644 index 00000000..a70b9f95 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpacesInLineCommentPrefix.cpp @@ -0,0 +1,3 @@ +//foo +// bar +// baz diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpacesInParentheses.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpacesInParentheses.cpp new file mode 100644 index 00000000..bcff28c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpacesInParentheses.cpp @@ -0,0 +1,9 @@ +void foo(int bar) { + (void)bar; +} + +void baz(int qux) { + foo(qux); + + foo(qux); +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/SpacesInSquareBrackets.cpp b/other/clang-format-configuration/testdata/golden/targeted/SpacesInSquareBrackets.cpp new file mode 100644 index 00000000..651b7bbb --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/SpacesInSquareBrackets.cpp @@ -0,0 +1,3 @@ +int foo[42]; + +int bar[42]; diff --git a/other/clang-format-configuration/testdata/golden/targeted/Standard.cpp b/other/clang-format-configuration/testdata/golden/targeted/Standard.cpp new file mode 100644 index 00000000..05d153df --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/Standard.cpp @@ -0,0 +1,6 @@ +#include +#include + +std::vector> foo; + +std::vector> bar; diff --git a/other/clang-format-configuration/testdata/golden/targeted/TabWidth.cpp b/other/clang-format-configuration/testdata/golden/targeted/TabWidth.cpp new file mode 100644 index 00000000..b08c89d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/TabWidth.cpp @@ -0,0 +1,18 @@ +// This test data must have multiple indentation levels in order to provide sufficient coverage of the unintuitive +// interaction between IndentWidth and TabWidth. See the TabWidth option notes for details. + +void foo() { + int bar = + 42; + (void)bar; + { + int baz = + 42; + (void)baz; + { + int qux = + 42; + (void)qux; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/UseCRLF.cpp b/other/clang-format-configuration/testdata/golden/targeted/UseCRLF.cpp new file mode 100644 index 00000000..6a32543e --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/UseCRLF.cpp @@ -0,0 +1 @@ +// this file intentionally has CRLF line endings diff --git a/other/clang-format-configuration/testdata/golden/targeted/UseTab.cpp b/other/clang-format-configuration/testdata/golden/targeted/UseTab.cpp new file mode 100644 index 00000000..328fc97b --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/UseTab.cpp @@ -0,0 +1,20 @@ +// This test data must have multiple indentation levels in order to provide sufficient coverage of how UseTab is +// affected by the unintuitive interaction between IndentWidth and TabWidth. See the TabWidth option notes for details. + +int a; // foo +int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; // foo +void bar() { + int baz = + 42; + (void)baz; + { + int qux = + 42; + (void)qux; + { + int pippo = + 42; + (void)pippo; + } + } +} diff --git a/other/clang-format-configuration/testdata/golden/targeted/include/a.h b/other/clang-format-configuration/testdata/golden/targeted/include/a.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/include/a.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/golden/targeted/include/aa.h b/other/clang-format-configuration/testdata/golden/targeted/include/aa.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/include/aa.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/golden/targeted/include/b.h b/other/clang-format-configuration/testdata/golden/targeted/include/b.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/include/b.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/golden/targeted/include/bb.h b/other/clang-format-configuration/testdata/golden/targeted/include/bb.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/include/bb.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/golden/targeted/include/c.h b/other/clang-format-configuration/testdata/golden/targeted/include/c.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/include/c.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/golden/targeted/include/cc.h b/other/clang-format-configuration/testdata/golden/targeted/include/cc.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/include/cc.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/golden/targeted/include/d.h b/other/clang-format-configuration/testdata/golden/targeted/include/d.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/include/d.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/golden/targeted/include/dd.h b/other/clang-format-configuration/testdata/golden/targeted/include/dd.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/golden/targeted/include/dd.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/LICENSE new file mode 100644 index 00000000..19e30718 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +(This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.) + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + {signature of Ty Coon}, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/README.md new file mode 100644 index 00000000..9ec934a3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/README.md @@ -0,0 +1,33 @@ +# ArduinoBLE + +[![Compile Examples Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Compile+Examples) [![Spell Check Status](https://github.com/arduino-libraries/ArduinoBLE/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoBLE/actions?workflow=Spell+Check) + +Enables Bluetooth® Low Energy connectivity on the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, Arduino Nano 33 IoT, and Arduino Nano 33 BLE. + +This library supports creating a Bluetooth® Low Energy peripheral & central mode. + +For the Arduino MKR WiFi 1010, Arduino UNO WiFi Rev.2, and Arduino Nano 33 IoT boards, it requires the NINA module to be running [Arduino NINA-W102 firmware](https://github.com/arduino/nina-fw) v1.2.0 or later. + + +For more information about this library please visit us at: +https://www.arduino.cc/en/Reference/ArduinoBLE + +## License + +``` +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +``` diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/LedControl/LedControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/LedControl/LedControl.ino new file mode 100644 index 00000000..953de7d8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/LedControl/LedControl.ino @@ -0,0 +1,128 @@ +/* + LED Control + + This example scans for Bluetooth® Low Energy peripherals until one with the advertised service + "19b10000-e8f2-537e-4f6c-d104768a1214" UUID is found. Once discovered and connected, + it will remotely control the Bluetooth® Low Energy peripheral's LED, when the button is pressed or released. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Button with pull-up resistor connected to pin 2. + + You can use it with another board that is compatible with this library and the + Peripherals -> LED example. + + This example code is in the public domain. +*/ + +#include + +// variables for button +const int buttonPin = 2; +int oldButtonState = LOW; + +void setup() { + Serial.begin(9600); + while (!Serial); + + // configure the button pin as input + pinMode(buttonPin, INPUT); + + // initialize the Bluetooth® Low Energy hardware + BLE.begin(); + + Serial.println("Bluetooth® Low Energy Central - LED control"); + + // start scanning for peripherals + BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); +} + +void loop() { + // check if a peripheral has been discovered + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // discovered a peripheral, print out address, local name, and advertised service + Serial.print("Found "); + Serial.print(peripheral.address()); + Serial.print(" '"); + Serial.print(peripheral.localName()); + Serial.print("' "); + Serial.print(peripheral.advertisedServiceUuid()); + Serial.println(); + + if (peripheral.localName() != "LED") { + return; + } + + // stop scanning + BLE.stopScan(); + + controlLed(peripheral); + + // peripheral disconnected, start scanning again + BLE.scanForUuid("19b10000-e8f2-537e-4f6c-d104768a1214"); + } +} + +void controlLed(BLEDevice peripheral) { + // connect to the peripheral + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + // retrieve the LED characteristic + BLECharacteristic ledCharacteristic = peripheral.characteristic("19b10001-e8f2-537e-4f6c-d104768a1214"); + + if (!ledCharacteristic) { + Serial.println("Peripheral does not have LED characteristic!"); + peripheral.disconnect(); + return; + } else if (!ledCharacteristic.canWrite()) { + Serial.println("Peripheral does not have a writable LED characteristic!"); + peripheral.disconnect(); + return; + } + + while (peripheral.connected()) { + // while the peripheral is connected + + // read the button pin + int buttonState = digitalRead(buttonPin); + + if (oldButtonState != buttonState) { + // button changed + oldButtonState = buttonState; + + if (buttonState) { + Serial.println("button pressed"); + + // button is pressed, write 0x01 to turn the LED on + ledCharacteristic.writeValue((byte)0x01); + } else { + Serial.println("button released"); + + // button is released, write 0x00 to turn the LED off + ledCharacteristic.writeValue((byte)0x00); + } + } + } + + Serial.println("Peripheral disconnected"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/PeripheralExplorer/PeripheralExplorer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/PeripheralExplorer/PeripheralExplorer.ino new file mode 100644 index 00000000..919cdde0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/PeripheralExplorer/PeripheralExplorer.ino @@ -0,0 +1,175 @@ +/* + Peripheral Explorer + + This example scans for Bluetooth® Low Energy peripherals until one with a particular name ("LED") + is found. Then connects, and discovers + prints all the peripheral's attributes. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use it with another board that is compatible with this library and the + Peripherals -> LED example. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1); + } + + Serial.println("Bluetooth® Low Energy Central - Peripheral Explorer"); + + // start scanning for peripherals + BLE.scan(); +} + +void loop() { + // check if a peripheral has been discovered + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // discovered a peripheral, print out address, local name, and advertised service + Serial.print("Found "); + Serial.print(peripheral.address()); + Serial.print(" '"); + Serial.print(peripheral.localName()); + Serial.print("' "); + Serial.print(peripheral.advertisedServiceUuid()); + Serial.println(); + + // see if peripheral is a LED + if (peripheral.localName() == "LED") { + // stop scanning + BLE.stopScan(); + + explorerPeripheral(peripheral); + + // peripheral disconnected, we are done + while (1) { + // do nothing + } + } + } +} + +void explorerPeripheral(BLEDevice peripheral) { + // connect to the peripheral + Serial.println("Connecting ..."); + + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering attributes ..."); + if (peripheral.discoverAttributes()) { + Serial.println("Attributes discovered"); + } else { + Serial.println("Attribute discovery failed!"); + peripheral.disconnect(); + return; + } + + // read and print device name of peripheral + Serial.println(); + Serial.print("Device name: "); + Serial.println(peripheral.deviceName()); + Serial.print("Appearance: 0x"); + Serial.println(peripheral.appearance(), HEX); + Serial.println(); + + // loop the services of the peripheral and explore each + for (int i = 0; i < peripheral.serviceCount(); i++) { + BLEService service = peripheral.service(i); + + exploreService(service); + } + + Serial.println(); + + // we are done exploring, disconnect + Serial.println("Disconnecting ..."); + peripheral.disconnect(); + Serial.println("Disconnected"); +} + +void exploreService(BLEService service) { + // print the UUID of the service + Serial.print("Service "); + Serial.println(service.uuid()); + + // loop the characteristics of the service and explore each + for (int i = 0; i < service.characteristicCount(); i++) { + BLECharacteristic characteristic = service.characteristic(i); + + exploreCharacteristic(characteristic); + } +} + +void exploreCharacteristic(BLECharacteristic characteristic) { + // print the UUID and properties of the characteristic + Serial.print("\tCharacteristic "); + Serial.print(characteristic.uuid()); + Serial.print(", properties 0x"); + Serial.print(characteristic.properties(), HEX); + + // check if the characteristic is readable + if (characteristic.canRead()) { + // read the characteristic value + characteristic.read(); + + if (characteristic.valueLength() > 0) { + // print out the value of the characteristic + Serial.print(", value 0x"); + printData(characteristic.value(), characteristic.valueLength()); + } + } + Serial.println(); + + // loop the descriptors of the characteristic and explore each + for (int i = 0; i < characteristic.descriptorCount(); i++) { + BLEDescriptor descriptor = characteristic.descriptor(i); + + exploreDescriptor(descriptor); + } +} + +void exploreDescriptor(BLEDescriptor descriptor) { + // print the UUID of the descriptor + Serial.print("\t\tDescriptor "); + Serial.print(descriptor.uuid()); + + // read the descriptor value + descriptor.read(); + + // print out the value of the descriptor + Serial.print(", value 0x"); + printData(descriptor.value(), descriptor.valueLength()); + + Serial.println(); +} + +void printData(const unsigned char data[], int length) { + for (int i = 0; i < length; i++) { + unsigned char b = data[i]; + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/Scan/Scan.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/Scan/Scan.ino new file mode 100644 index 00000000..162e3c07 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/Scan/Scan.ino @@ -0,0 +1,68 @@ +/* + Scan + + This example scans for Bluetooth® Low Energy peripherals and prints out their advertising details: + address, local name, advertised service UUID's. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1); + } + + Serial.println("Bluetooth® Low Energy Central scan"); + + // start scanning for peripheral + BLE.scan(); +} + +void loop() { + // check if a peripheral has been discovered + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // discovered a peripheral + Serial.println("Discovered a peripheral"); + Serial.println("-----------------------"); + + // print address + Serial.print("Address: "); + Serial.println(peripheral.address()); + + // print the local name, if present + if (peripheral.hasLocalName()) { + Serial.print("Local Name: "); + Serial.println(peripheral.localName()); + } + + // print the advertised service UUIDs, if present + if (peripheral.hasAdvertisedServiceUuid()) { + Serial.print("Service UUIDs: "); + for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { + Serial.print(peripheral.advertisedServiceUuid(i)); + Serial.print(" "); + } + Serial.println(); + } + + // print the RSSI + Serial.print("RSSI: "); + Serial.println(peripheral.rssi()); + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/ScanCallback/ScanCallback.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/ScanCallback/ScanCallback.ino new file mode 100644 index 00000000..2687a3b9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/ScanCallback/ScanCallback.ino @@ -0,0 +1,73 @@ +/* + Scan Callback + + This example scans for Bluetooth® Low Energy peripherals and prints out their advertising details: + address, local name, advertised service UUIDs. Unlike the Scan example, it uses + the callback style APIs and disables filtering so the peripheral discovery is + reported for every single advertisement it makes. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1); + } + + Serial.println("Bluetooth® Low Energy Central scan callback"); + + // set the discovered event handle + BLE.setEventHandler(BLEDiscovered, bleCentralDiscoverHandler); + + // start scanning for peripherals with duplicates + BLE.scan(true); +} + +void loop() { + // poll the central for events + BLE.poll(); +} + +void bleCentralDiscoverHandler(BLEDevice peripheral) { + // discovered a peripheral + Serial.println("Discovered a peripheral"); + Serial.println("-----------------------"); + + // print address + Serial.print("Address: "); + Serial.println(peripheral.address()); + + // print the local name, if present + if (peripheral.hasLocalName()) { + Serial.print("Local Name: "); + Serial.println(peripheral.localName()); + } + + // print the advertised service UUIDs, if present + if (peripheral.hasAdvertisedServiceUuid()) { + Serial.print("Service UUIDs: "); + for (int i = 0; i < peripheral.advertisedServiceUuidCount(); i++) { + Serial.print(peripheral.advertisedServiceUuid(i)); + Serial.print(" "); + } + Serial.println(); + } + + // print the RSSI + Serial.print("RSSI: "); + Serial.println(peripheral.rssi()); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/SensorTagButton/SensorTagButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/SensorTagButton/SensorTagButton.ino new file mode 100644 index 00000000..a56504f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Central/SensorTagButton/SensorTagButton.ino @@ -0,0 +1,133 @@ +/* + SensorTag Button + + This example scans for Bluetooth® Low Energy peripherals until a TI SensorTag is discovered. + It then connects to it, discovers the attributes of the 0xffe0 service, + subscribes to the Simple Key Characteristic (UUID 0xffe1). When a button is + pressed on the SensorTag a notification is received and the button state is + outputted to the Serial Monitor when one is pressed. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - TI SensorTag + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1); + } + + Serial.println("Bluetooth® Low Energy Central - SensorTag button"); + Serial.println("Make sure to turn on the device."); + + // start scanning for peripheral + BLE.scan(); +} + +void loop() { + // check if a peripheral has been discovered + BLEDevice peripheral = BLE.available(); + + if (peripheral) { + // discovered a peripheral, print out address, local name, and advertised service + Serial.print("Found "); + Serial.print(peripheral.address()); + Serial.print(" '"); + Serial.print(peripheral.localName()); + Serial.print("' "); + Serial.print(peripheral.advertisedServiceUuid()); + Serial.println(); + + // Check if the peripheral is a SensorTag, the local name will be: + // "CC2650 SensorTag" + if (peripheral.localName() == "CC2650 SensorTag") { + // stop scanning + BLE.stopScan(); + + monitorSensorTagButtons(peripheral); + + // peripheral disconnected, start scanning again + BLE.scan(); + } + } +} + +void monitorSensorTagButtons(BLEDevice peripheral) { + // connect to the peripheral + Serial.println("Connecting ..."); + if (peripheral.connect()) { + Serial.println("Connected"); + } else { + Serial.println("Failed to connect!"); + return; + } + + // discover peripheral attributes + Serial.println("Discovering service 0xffe0 ..."); + if (peripheral.discoverService("ffe0")) { + Serial.println("Service discovered"); + } else { + Serial.println("Attribute discovery failed."); + peripheral.disconnect(); + + while (1); + return; + } + + // retrieve the simple key characteristic + BLECharacteristic simpleKeyCharacteristic = peripheral.characteristic("ffe1"); + + // subscribe to the simple key characteristic + Serial.println("Subscribing to simple key characteristic ..."); + if (!simpleKeyCharacteristic) { + Serial.println("no simple key characteristic found!"); + peripheral.disconnect(); + return; + } else if (!simpleKeyCharacteristic.canSubscribe()) { + Serial.println("simple key characteristic is not subscribable!"); + peripheral.disconnect(); + return; + } else if (!simpleKeyCharacteristic.subscribe()) { + Serial.println("subscription failed!"); + peripheral.disconnect(); + return; + } else { + Serial.println("Subscribed"); + Serial.println("Press the right and left buttons on your SensorTag."); + } + + while (peripheral.connected()) { + // while the peripheral is connected + + // check if the value of the simple key characteristic has been updated + if (simpleKeyCharacteristic.valueUpdated()) { + // yes, get the value, characteristic is 1 byte so use byte value + byte value = 0; + + simpleKeyCharacteristic.readValue(value); + + if (value & 0x01) { + // first bit corresponds to the right button + Serial.println("Right button pressed"); + } + + if (value & 0x02) { + // second bit corresponds to the left button + Serial.println("Left button pressed"); + } + } + } + + Serial.println("SensorTag disconnected!"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino new file mode 100644 index 00000000..979b69a8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/EnhancedAdvertising/EnhancedAdvertising.ino @@ -0,0 +1,44 @@ +#include + +BLEService myService("fff0"); +BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); + +// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop' +const uint8_t manufactData[4] = {0x01, 0x02, 0x03, 0x04}; +const uint8_t serviceData[3] = {0x00, 0x01, 0x02}; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!BLE.begin()) { + Serial.println("failed to initialize BLE!"); + while (1); + } + + myService.addCharacteristic(myCharacteristic); + BLE.addService(myService); + + // Build scan response data packet + BLEAdvertisingData scanData; + // Set parameters for scan response packet + scanData.setLocalName("Test enhanced advertising"); + // Copy set parameters in the actual scan response packet + BLE.setScanResponseData(scanData); + + // Build advertising data packet + BLEAdvertisingData advData; + // Set parameters for advertising packet + advData.setManufacturerData(0x004C, manufactData, sizeof(manufactData)); + advData.setAdvertisedService(myService); + advData.setAdvertisedServiceData(0xfff0, serviceData, sizeof(serviceData)); + // Copy set parameters in the actual advertising packet + BLE.setAdvertisingData(advData); + + BLE.advertise(); + Serial.println("advertising ..."); +} + +void loop() { + BLE.poll(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino new file mode 100644 index 00000000..d025dd62 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/Advertising/RawDataAdvertising/RawDataAdvertising.ino @@ -0,0 +1,41 @@ +#include + +BLEService myService("fff0"); +BLEIntCharacteristic myCharacteristic("fff1", BLERead | BLEBroadcast); + +// Advertising parameters should have a global scope. Do NOT define them in 'setup' or in 'loop' +const uint8_t completeRawAdvertisingData[] = {0x02,0x01,0x06,0x09,0xff,0x01,0x01,0x00,0x01,0x02,0x03,0x04,0x05}; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!BLE.begin()) { + Serial.println("failed to initialize BLE!"); + while (1); + } + + myService.addCharacteristic(myCharacteristic); + BLE.addService(myService); + + // Build advertising data packet + BLEAdvertisingData advData; + // If a packet has a raw data parameter, then all the other parameters of the packet will be ignored + advData.setRawData(completeRawAdvertisingData, sizeof(completeRawAdvertisingData)); + // Copy set parameters in the actual advertising packet + BLE.setAdvertisingData(advData); + + // Build scan response data packet + BLEAdvertisingData scanData; + scanData.setLocalName("Test advertising raw data"); + // Copy set parameters in the actual scan response packet + BLE.setScanResponseData(scanData); + + BLE.advertise(); + + Serial.println("advertising ..."); +} + +void loop() { + BLE.poll(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino new file mode 100644 index 00000000..f013c6f5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/BatteryMonitor/BatteryMonitor.ino @@ -0,0 +1,106 @@ +/* + Battery Monitor + + This example creates a Bluetooth® Low Energy peripheral with the standard battery service and + level characteristic. The A0 pin is used to calculate the battery level. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + + // Bluetooth® Low Energy Battery Service +BLEService batteryService("180F"); + +// Bluetooth® Low Energy Battery Level Characteristic +BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID + BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes + +int oldBatteryLevel = 0; // last battery level reading from analog input +long previousMillis = 0; // last time the battery level was checked, in ms + +void setup() { + Serial.begin(9600); // initialize serial communication + while (!Serial); + + pinMode(LED_BUILTIN, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + + while (1); + } + + /* Set a local name for the Bluetooth® Low Energy device + This name will appear in advertising packets + and can be used by remote devices to identify this Bluetooth® Low Energy device + The name can be changed but maybe be truncated based on space left in advertisement packet + */ + BLE.setLocalName("BatteryMonitor"); + BLE.setAdvertisedService(batteryService); // add the service UUID + batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic + BLE.addService(batteryService); // Add the battery service + batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic + + /* Start advertising Bluetooth® Low Energy. It will start continuously transmitting Bluetooth® Low Energy + advertising packets and will be visible to remote Bluetooth® Low Energy central devices + until it receives a new connection */ + + // start advertising + BLE.advertise(); + + Serial.println("Bluetooth® device active, waiting for connections..."); +} + +void loop() { + // wait for a Bluetooth® Low Energy central + BLEDevice central = BLE.central(); + + // if a central is connected to the peripheral: + if (central) { + Serial.print("Connected to central: "); + // print the central's BT address: + Serial.println(central.address()); + // turn on the LED to indicate the connection: + digitalWrite(LED_BUILTIN, HIGH); + + // check the battery level every 200ms + // while the central is connected: + while (central.connected()) { + long currentMillis = millis(); + // if 200ms have passed, check the battery level: + if (currentMillis - previousMillis >= 200) { + previousMillis = currentMillis; + updateBatteryLevel(); + } + } + // when the central disconnects, turn off the LED: + digitalWrite(LED_BUILTIN, LOW); + Serial.print("Disconnected from central: "); + Serial.println(central.address()); + } +} + +void updateBatteryLevel() { + /* Read the current voltage level on the A0 analog input pin. + This is used here to simulate the charge level of a battery. + */ + int battery = analogRead(A0); + int batteryLevel = map(battery, 0, 1023, 0, 100); + + if (batteryLevel != oldBatteryLevel) { // if the battery level has changed + Serial.print("Battery Level % is now: "); // print it + Serial.println(batteryLevel); + batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic + oldBatteryLevel = batteryLevel; // save the level for next comparison + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/ButtonLED/ButtonLED.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/ButtonLED/ButtonLED.ino new file mode 100644 index 00000000..cbc14dd8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/ButtonLED/ButtonLED.ino @@ -0,0 +1,93 @@ +/* + Button LED + + This example creates a Bluetooth® Low Energy peripheral with service that contains a + characteristic to control an LED and another characteristic that + represents the state of the button. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + - Button connected to pin 4 + + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + +const int ledPin = LED_BUILTIN; // set ledPin to on-board LED +const int buttonPin = 4; // set buttonPin to digital pin 4 + +BLEService ledService("19B10010-E8F2-537E-4F6C-D104768A1214"); // create service + +// create switch characteristic and allow remote device to read and write +BLEByteCharacteristic ledCharacteristic("19B10011-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); +// create button characteristic and allow remote device to get notifications +BLEByteCharacteristic buttonCharacteristic("19B10012-E8F2-537E-4F6C-D104768A1214", BLERead | BLENotify); + +void setup() { + Serial.begin(9600); + while (!Serial); + + pinMode(ledPin, OUTPUT); // use the LED as an output + pinMode(buttonPin, INPUT); // use button pin as an input + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1); + } + + // set the local name peripheral advertises + BLE.setLocalName("ButtonLED"); + // set the UUID for the service this peripheral advertises: + BLE.setAdvertisedService(ledService); + + // add the characteristics to the service + ledService.addCharacteristic(ledCharacteristic); + ledService.addCharacteristic(buttonCharacteristic); + + // add the service + BLE.addService(ledService); + + ledCharacteristic.writeValue(0); + buttonCharacteristic.writeValue(0); + + // start advertising + BLE.advertise(); + + Serial.println("Bluetooth® device active, waiting for connections..."); +} + +void loop() { + // poll for Bluetooth® Low Energy events + BLE.poll(); + + // read the current button pin state + char buttonValue = digitalRead(buttonPin); + + // has the value changed since the last read + bool buttonChanged = (buttonCharacteristic.value() != buttonValue); + + if (buttonChanged) { + // button state changed, update characteristics + ledCharacteristic.writeValue(buttonValue); + buttonCharacteristic.writeValue(buttonValue); + } + + if (ledCharacteristic.written() || buttonChanged) { + // update LED, either central has written to characteristic or button state has changed + if (ledCharacteristic.value()) { + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); + } else { + Serial.println("LED off"); + digitalWrite(ledPin, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/CallbackLED/CallbackLED.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/CallbackLED/CallbackLED.ino new file mode 100644 index 00000000..23f67bc3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/CallbackLED/CallbackLED.ino @@ -0,0 +1,95 @@ +/* + Callback LED + + This example creates a Bluetooth® Low Energy peripheral with service that contains a + characteristic to control an LED. The callback features of the + library are used. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service + +// create switch characteristic and allow remote device to read and write +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +const int ledPin = LED_BUILTIN; // pin to use for the LED + +void setup() { + Serial.begin(9600); + while (!Serial); + + pinMode(ledPin, OUTPUT); // use the LED pin as an output + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1); + } + + // set the local name peripheral advertises + BLE.setLocalName("LEDCallback"); + // set the UUID for the service this peripheral advertises + BLE.setAdvertisedService(ledService); + + // add the characteristic to the service + ledService.addCharacteristic(switchCharacteristic); + + // add service + BLE.addService(ledService); + + // assign event handlers for connected, disconnected to peripheral + BLE.setEventHandler(BLEConnected, blePeripheralConnectHandler); + BLE.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler); + + // assign event handlers for characteristic + switchCharacteristic.setEventHandler(BLEWritten, switchCharacteristicWritten); + // set an initial value for the characteristic + switchCharacteristic.setValue(0); + + // start advertising + BLE.advertise(); + + Serial.println(("Bluetooth® device active, waiting for connections...")); +} + +void loop() { + // poll for Bluetooth® Low Energy events + BLE.poll(); +} + +void blePeripheralConnectHandler(BLEDevice central) { + // central connected event handler + Serial.print("Connected event, central: "); + Serial.println(central.address()); +} + +void blePeripheralDisconnectHandler(BLEDevice central) { + // central disconnected event handler + Serial.print("Disconnected event, central: "); + Serial.println(central.address()); +} + +void switchCharacteristicWritten(BLEDevice central, BLECharacteristic characteristic) { + // central wrote new value to characteristic, update LED + Serial.print("Characteristic event, written: "); + + if (switchCharacteristic.value()) { + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); + } else { + Serial.println("LED off"); + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino new file mode 100644 index 00000000..9f9d453b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/EncryptedBatteryMonitor/EncryptedBatteryMonitor.ino @@ -0,0 +1,265 @@ +/* + Battery Monitor + + This example creates a BLE peripheral with the standard battery service and + level characteristic. The A0 pin is used to calculate the battery level. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic BLE central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + + +#define PAIR_BUTTON 3 // button for pairing +#define PAIR_LED 24 // LED used to signal pairing +#define PAIR_LED_ON LOW // Blue LED on Nano BLE has inverted logic +#define PAIR_INTERVAL 30000 // interval for pairing after button press in ms + +#define CTRL_LED LED_BUILTIN + + + // BLE Battery Service +BLEService batteryService("180F"); + +// BLE Battery Level Characteristic +BLEUnsignedCharCharacteristic batteryLevelChar("2A19", // standard 16-bit characteristic UUID + BLERead | BLENotify); // remote clients will be able to get notifications if this characteristic changes +BLEStringCharacteristic stringcharacteristic("183E", BLERead | BLEWrite, 31); + + +// Add BLEEncryption tag to require pairing. This controls the LED. +BLEUnsignedCharCharacteristic secretValue("2a3F", BLERead | BLEWrite | BLEEncryption); + +int oldBatteryLevel = 0; // last battery level reading from analog input +unsigned long previousMillis = 0; // last time the battery level was checked, in ms +unsigned long pairingStarted = 0; // pairing start time when button is pressed +bool wasConnected = 0; +bool acceptOrReject = true; + +void setup() { + Serial.begin(9600); // initialize serial communication + while (!Serial); + + pinMode(CTRL_LED, OUTPUT); // initialize the built-in LED pin to indicate when a central is connected + pinMode(PAIR_LED, OUTPUT); + pinMode(PAIR_BUTTON, INPUT_PULLUP); + + + Serial.println("Serial connected"); + + // Callback function with confirmation code when new device is pairing. + BLE.setDisplayCode([](uint32_t confirmCode){ + Serial.println("New device pairing request."); + Serial.print("Confirm code matches pairing device: "); + char code[6]; + sprintf(code, "%06d", confirmCode); + Serial.println(code); + }); + + // Callback to allow accepting or rejecting pairing + BLE.setBinaryConfirmPairing([&acceptOrReject](){ + Serial.print("Should we confirm pairing? "); + delay(5000); + if(acceptOrReject){ + acceptOrReject = false; + Serial.println("yes"); + return true; + }else{ + acceptOrReject = true; + Serial.println("no"); + return false; + } + }); + + // IRKs are keys that identify the true owner of a random mac address. + // Add IRKs of devices you are bonded with. + BLE.setGetIRKs([](uint8_t* nIRKs, uint8_t** BDaddrTypes, uint8_t*** BDAddrs, uint8_t*** IRKs){ + // Set to number of devices + *nIRKs = 2; + + *BDAddrs = new uint8_t*[*nIRKs]; + *IRKs = new uint8_t*[*nIRKs]; + *BDaddrTypes = new uint8_t[*nIRKs]; + + // Set these to the mac and IRK for your bonded devices as printed in the serial console after bonding. + uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device1IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device2IRK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + + (*BDaddrTypes)[0] = 0; // Type 0 is for pubc address, type 1 is for static random + (*BDAddrs)[0] = new uint8_t[6]; + (*IRKs)[0] = new uint8_t[16]; + memcpy((*IRKs)[0] , device1IRK,16); + memcpy((*BDAddrs)[0], device1Mac, 6); + + + (*BDaddrTypes)[1] = 0; + (*BDAddrs)[1] = new uint8_t[6]; + (*IRKs)[1] = new uint8_t[16]; + memcpy((*IRKs)[1] , device2IRK,16); + memcpy((*BDAddrs)[1], device2Mac, 6); + + + return 1; + }); + // The LTK is the secret key which is used to encrypt bluetooth traffic + BLE.setGetLTK([](uint8_t* address, uint8_t* LTK){ + // address is input + Serial.print("Received request for address: "); + btct.printBytes(address,6); + + // Set these to the MAC and LTK of your devices after bonding. + uint8_t device1Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device1LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device2Mac[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + uint8_t device2LTK[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; + + + if(memcmp(device1Mac, address, 6) == 0) { + memcpy(LTK, device1LTK, 16); + return 1; + }else if(memcmp(device2Mac, address, 6) == 0) { + memcpy(LTK, device2LTK, 16); + return 1; + } + return 0; + }); + BLE.setStoreIRK([](uint8_t* address, uint8_t* IRK){ + Serial.print(F("New device with MAC : ")); + btct.printBytes(address,6); + Serial.print(F("Need to store IRK : ")); + btct.printBytes(IRK,16); + return 1; + }); + BLE.setStoreLTK([](uint8_t* address, uint8_t* LTK){ + Serial.print(F("New device with MAC : ")); + btct.printBytes(address,6); + Serial.print(F("Need to store LTK : ")); + btct.printBytes(LTK,16); + return 1; + }); + + while(1){ + // begin initialization + if (!BLE.begin()) { + Serial.println("starting BLE failed!"); + delay(200); + continue; + } + Serial.println("BT init"); + delay(200); + + /* Set a local name for the BLE device + This name will appear in advertising packets + and can be used by remote devices to identify this BLE device + The name can be changed but maybe be truncated based on space left in advertisement packet + */ + + BLE.setDeviceName("Arduino"); + BLE.setLocalName("BatteryMonitor"); + + BLE.setAdvertisedService(batteryService); // add the service UUID + batteryService.addCharacteristic(batteryLevelChar); // add the battery level characteristic + batteryService.addCharacteristic(stringcharacteristic); + batteryService.addCharacteristic(secretValue); + + BLE.addService(batteryService); // Add the battery service + batteryLevelChar.writeValue(oldBatteryLevel); // set initial value for this characteristic + char* stringCharValue = new char[32]; + stringCharValue = "string"; + stringcharacteristic.writeValue(stringCharValue); + secretValue.writeValue(0); + + delay(1000); + + // prevent pairing until button is pressed (will show a pairing rejected message) + BLE.setPairable(false); + + /* Start advertising BLE. It will start continuously transmitting BLE + advertising packets and will be visible to remote BLE central devices + until it receives a new connection */ + + // start advertising + if(!BLE.advertise()){ + Serial.println("failed to advertise bluetooth."); + BLE.stopAdvertise(); + delay(500); + }else{ + Serial.println("advertising..."); + break; + } + BLE.end(); + delay(100); + } +} + + +void loop() { + // wait for a BLE central + BLEDevice central = BLE.central(); + + + // If button is pressed, allow pairing for 30 sec + if (!BLE.pairable() && digitalRead(PAIR_BUTTON) == LOW){ + pairingStarted = millis(); + BLE.setPairable(Pairable::ONCE); + Serial.println("Accepting pairing for 30s"); + } else if (BLE.pairable() && millis() > pairingStarted + PAIR_INTERVAL){ + BLE.setPairable(false); + Serial.println("No longer accepting pairing"); + } + // Make LED blink while pairing is allowed + digitalWrite(PAIR_LED, (BLE.pairable() ? (millis()%400)<200 : BLE.paired()) ? PAIR_LED_ON : !PAIR_LED_ON); + + + // if a central is connected to the peripheral: + if (central && central.connected()) { + if (!wasConnected){ + wasConnected = true; + Serial.print("Connected to central: "); + // print the central's BT address: + Serial.println(central.address()); + } + + // check the battery level every 200ms + // while the central is connected: + long currentMillis = millis(); + // if 200ms have passed, check the battery level: + if (currentMillis - previousMillis >= 1000) { + previousMillis = currentMillis; + updateBatteryLevel(); + digitalWrite(CTRL_LED, secretValue.value()>0 ? HIGH : LOW); + } + } else if (wasConnected){ + wasConnected = false; + Serial.print("Disconnected from central: "); + Serial.println(central.address()); + } + +} + +void updateBatteryLevel() { + /* Read the current voltage level on the A0 analog input pin. + This is used here to simulate the charge level of a battery. + */ + int battery = analogRead(A0); + int batteryLevel = map(battery, 0, 1023, 0, 100); + + if (batteryLevel != oldBatteryLevel) { // if the battery level has changed + // Serial.print("Battery Level % is now: "); // print it + // Serial.println(batteryLevel); + batteryLevelChar.writeValue(batteryLevel); // and update the battery level characteristic + oldBatteryLevel = batteryLevel; // save the level for next comparison + } +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/LED/LED.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/LED/LED.ino new file mode 100644 index 00000000..2e6d6db9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBLE/examples/Peripheral/LED/LED.ino @@ -0,0 +1,89 @@ +/* + LED + + This example creates a Bluetooth® Low Energy peripheral with service that contains a + characteristic to control an LED. + + The circuit: + - Arduino MKR WiFi 1010, Arduino Uno WiFi Rev2 board, Arduino Nano 33 IoT, + Arduino Nano 33 BLE, or Arduino Nano 33 BLE Sense board. + + You can use a generic Bluetooth® Low Energy central app, like LightBlue (iOS and Android) or + nRF Connect (Android), to interact with the services and characteristics + created in this sketch. + + This example code is in the public domain. +*/ + +#include + +BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // Bluetooth® Low Energy LED Service + +// Bluetooth® Low Energy LED Switch Characteristic - custom 128-bit UUID, read and writable by central +BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite); + +const int ledPin = LED_BUILTIN; // pin to use for the LED + +void setup() { + Serial.begin(9600); + while (!Serial); + + // set LED pin to output mode + pinMode(ledPin, OUTPUT); + + // begin initialization + if (!BLE.begin()) { + Serial.println("starting Bluetooth® Low Energy module failed!"); + + while (1); + } + + // set advertised local name and service UUID: + BLE.setLocalName("LED"); + BLE.setAdvertisedService(ledService); + + // add the characteristic to the service + ledService.addCharacteristic(switchCharacteristic); + + // add service + BLE.addService(ledService); + + // set the initial value for the characeristic: + switchCharacteristic.writeValue(0); + + // start advertising + BLE.advertise(); + + Serial.println("BLE LED Peripheral"); +} + +void loop() { + // listen for Bluetooth® Low Energy peripherals to connect: + BLEDevice central = BLE.central(); + + // if a central is connected to peripheral: + if (central) { + Serial.print("Connected to central: "); + // print the central's MAC address: + Serial.println(central.address()); + + // while the central is still connected to peripheral: + while (central.connected()) { + // if the remote device wrote to the characteristic, + // use the value to control the LED: + if (switchCharacteristic.written()) { + if (switchCharacteristic.value()) { // any value other than 0 + Serial.println("LED on"); + digitalWrite(ledPin, HIGH); // will turn the LED on + } else { // a 0 value + Serial.println(F("LED off")); + digitalWrite(ledPin, LOW); // will turn the LED off + } + } + } + + // when the central disconnects, print it out: + Serial.print(F("Disconnected from central: ")); + Serial.println(central.address()); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/LICENSE new file mode 100644 index 00000000..9b925602 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/LICENSE @@ -0,0 +1,21 @@ +Copyright (c) 2018 Arduino SA. All rights reserved. + +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/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/README.adoc new file mode 100644 index 00000000..965379c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/README.adoc @@ -0,0 +1,38 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoBearSSL + += {repository-name} = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Port of https://bearssl.org[BearSSL] to Arduino. + +This library depends on ArduinoECCX08. This dependency could be +disabled by defining ARDUINO_DISABLE_ECCX08 in ArduinoBearSSLConfig.h +(see examples). + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +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/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/AES128.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/AES128.ino new file mode 100644 index 00000000..a6897a3b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/AES128.ino @@ -0,0 +1,70 @@ +/* + ArduinoCrypto AES128 Example + + This sketch demonstrates how to run AES128 encryption and decryption for an input string. + + Circuit: + - Nano 33 IoT board + + created 13 July 2020 + by Luigi Gubello + + This example code is in the public domain. +*/ + +#include +#include "AES128.h" + +#ifdef ARDUINO_ARCH_MEGAAVR +// Create the object +AES128Class AES128; +#endif + +uint8_t key[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02}; +uint8_t enc_iv[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01}; +uint8_t dec_iv[16] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01}; +uint8_t input[16] = "ArduinoArduino"; // {0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x00,0x00} + +void setup() { + Serial.begin(9600); + while (!Serial); +} + +void loop() { + + Serial.print("Key: "); + printHex(key, 16); + Serial.println(" "); + Serial.print("IV: "); + printHex(enc_iv, 16); + Serial.println(" "); + Serial.print("AES128 Encryption of '"); + printHex(input, 16); + Serial.print("' is 0x"); + AES128.runEnc(key, 16, input, 16, enc_iv); // expect 0x65D0F7758B094114AFA6D33A5EA0716A + printHex(input, 16); + Serial.println(" "); + Serial.println(" "); + Serial.print("Key: "); + printHex(key, 16); + Serial.println(" "); + Serial.print("IV: "); + printHex(dec_iv, 16); + Serial.println(" "); + Serial.print("AES128 Decryption of '"); + printHex(input, 16); + Serial.print("' is 0x"); + AES128.runDec(key, 16, input, 16, dec_iv); + printHex(input, 16); + Serial.println(" "); + while (1); +} + +void printHex(uint8_t *text, size_t size) { + for (byte i = 0; i < size; i = i + 1) { + if (text[i] < 16) { + Serial.print("0"); + } + Serial.print(text[i], HEX); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/AES128/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/DES/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/DES/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/DES/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/DES/DES.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/DES/DES.ino new file mode 100644 index 00000000..cc7d5203 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/DES/DES.ino @@ -0,0 +1,70 @@ +/* + ArduinoCrypto DES Example + + This sketch demonstrates how to run DES encryption and decryption for an input string. + + Circuit: + - Nano 33 IoT board + + created 13 July 2020 + by Luigi Gubello + + This example code is in the public domain. +*/ + +#include +#include "DES.h" + +#ifdef ARDUINO_ARCH_MEGAAVR +// Create the object +DESClass DES; +#endif + +uint8_t key[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x02}; +uint8_t enc_iv[8] = {0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01}; +uint8_t dec_iv[8] = {0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x01}; +uint8_t input[8] = "Arduino"; // {0x41,0x72,0x64,0x75,0x69,0x6E,0x6F,0x00} + +void setup() { + Serial.begin(9600); + while (!Serial); +} + +void loop() { + + Serial.print("Key: "); + printHex(key, 8); + Serial.println(" "); + Serial.print("IV: "); + printHex(enc_iv, 8); + Serial.println(" "); + Serial.print("DES Encryption of '"); + printHex(input, 8); + Serial.print("' is 0x"); + DES.runEnc(key, 8, input, 8, enc_iv); // expect 0x3C21EB6A62D372DB + printHex(input, 8); + Serial.println(" "); + Serial.println(" "); + Serial.print("Key: "); + printHex(key, 8); + Serial.println(" "); + Serial.print("IV: "); + printHex(dec_iv, 8); + Serial.println(" "); + Serial.print("DES Decryption of '"); + printHex(input, 8); + Serial.print("' is 0x"); + DES.runDec(key, 8, input, 8, dec_iv); + printHex(input, 8); + Serial.println(" "); + while (1); +} + +void printHex(uint8_t *text, size_t size) { + for (byte i = 0; i < size; i = i + 1) { + if (text[i] < 16) { + Serial.print("0"); + } + Serial.print(text[i], HEX); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/MD5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/MD5.ino new file mode 100644 index 00000000..37ba2e0e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MD5/MD5.ino @@ -0,0 +1,70 @@ +/* + ArduinoBearSSL MD5 + + This sketch demonstrates how to create a MD5 hash + for an input string. + + This example code is in the public domain. +*/ + +#include +#include "MD5.h" + +#ifdef ARDUINO_ARCH_MEGAAVR +// Create the object +MD5Class MD5; +#endif + +void setup() { + Serial.begin(9600); + while (!Serial); + + // expect 9e107d9d372bb6826bd81d3542a419d6 + printMD5("The quick brown fox jumps over the lazy dog"); + + // expect 80070713463e7749b90c2dc24911e275 + printHMACMD5("key", "The quick brown fox jumps over the lazy dog"); +} + +void loop() { +} + +void printMD5(const char* str) { + Serial.print("MD5 of '"); + Serial.print(str); + Serial.print("' is 0x"); + + MD5.beginHash(); + MD5.print(str); + MD5.endHash(); + + printResult(); +} + +void printHMACMD5(const char* secret, const char* str) { + Serial.print("HMAC-MD5 of '"); + Serial.print(str); + Serial.print("' with secret '"); + Serial.print(secret); + Serial.print("' is 0x"); + + MD5.beginHmac(secret); + MD5.print(str); + MD5.endHmac(); + + printResult(); +} + +void printResult() +{ + while (MD5.available()) { + byte b = MD5.read(); + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/MKRGSMSSLClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/MKRGSMSSLClient.ino new file mode 100644 index 00000000..5d25d777 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/MKRGSMSSLClient/MKRGSMSSLClient.ino @@ -0,0 +1,95 @@ +/* + This example creates a client object that connects and transfers + data using always SSL. + + It is compatible with the methods normally related to plain + connections, like client.connect(host, port). + + Written by Arturo Guadalupi + last revision November 2015 + +*/ + +#include +#include + +const char pin[] = ""; +const char apn[] = "apn"; +const char login[] = "login"; +const char password[] = "pass"; + +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +GPRS gprs; +GSM gsmAccess; + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +GSMClient client; +BearSSLClient sslClient(client); + +unsigned long getTime() { + return gsmAccess.getTime(); +} + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // connection state + boolean notConnected = true; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (notConnected) { + if ((gsmAccess.begin(pin) == GSM_READY) & + (gprs.attachGPRS(apn, login, password) == GPRS_READY)) { + notConnected = false; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected to GPRS"); + + ArduinoBearSSL.onGetTime(getTime); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (sslClient.connect(server, 443)) { + Serial.println("connected to server"); + // Make a HTTP request: + sslClient.println("GET /search?q=arduino HTTP/1.1"); + sslClient.println("Host: www.google.com"); + sslClient.println("Connection: close"); + sslClient.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (sslClient.available()) { + char c = sslClient.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!sslClient.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + sslClient.stop(); + + // do nothing forevermore: + while (true); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/SHA1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/SHA1.ino new file mode 100644 index 00000000..456d75d4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA1/SHA1.ino @@ -0,0 +1,70 @@ +/* + ArduinoBearSSL SHA1 + + This sketch demonstrates how to create a SHA1 hash and HMAC + for an input string. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + // expect 0xDA39A3EE5E6B4B0D3255BFEF95601890AFD80709 + printSHA1(""); + + // expect 0x2FD4E1C67A2D28FCED849EE1BB76E7391B93EB12 + printSHA1("The quick brown fox jumps over the lazy dog"); + + // expect 0xFBDB1D1B18AA6C08324B7D64B71FB76370690E1D + printHMACSHA1("", ""); + + // expect 0xDE7C9B85B8B78AA6BC8A7A36F70A90701C9DB4D9 + printHMACSHA1("key", "The quick brown fox jumps over the lazy dog"); +} + +void loop() { +} + +void printSHA1(const char* str) { + Serial.print("SHA1 of '"); + Serial.print(str); + Serial.print("' is 0x"); + + SHA1.beginHash(); + SHA1.print(str); + SHA1.endHash(); + + printResult(); +} + +void printHMACSHA1(const char* secret, const char* str) { + Serial.print("HMAC-SHA1 of '"); + Serial.print(str); + Serial.print("' with secret '"); + Serial.print(secret); + Serial.print("' is 0x"); + + SHA1.beginHmac(secret); + SHA1.print(str); + SHA1.endHmac(); + + printResult(); +} + +void printResult() +{ + while (SHA1.available()) { + byte b = SHA1.read(); + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/SHA256.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/SHA256.ino new file mode 100644 index 00000000..3a610d5f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/SHA256/SHA256.ino @@ -0,0 +1,76 @@ +/* + ArduinoBearSSL SHA256 + + This sketch demonstrates how to create a SHA256 hash and HMAC + for an input string. + + This example code is in the public domain. +*/ + +#include +#include "SHA256.h" + +#ifdef ARDUINO_ARCH_MEGAAVR +// Create the object +SHA256Class SHA256; +#endif + +void setup() { + Serial.begin(9600); + while (!Serial); + + // expect 0xE3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855 + printSHA256(""); + + // expect 0xD7A8FBB307D7809469CA9ABCB0082E4F8D5651E46D3CDB762D02D0BF37C9E592 + printSHA256("The quick brown fox jumps over the lazy dog"); + + // expect 0xB613679A0814D9EC772F95D778C35FC5FF1697C493715653C6C712144292C5AD + printHMACSHA256("", ""); + + // expect 0xF7BC83F430538424B13298E6AA6FB143EF4D59A14946175997479DBC2D1A3CD8 + printHMACSHA256("key", "The quick brown fox jumps over the lazy dog"); +} + +void loop() { +} + +void printSHA256(const char* str) { + Serial.print("SHA256 of '"); + Serial.print(str); + Serial.print("' is 0x"); + + SHA256.beginHash(); + SHA256.print(str); + SHA256.endHash(); + + printResult(); +} + +void printHMACSHA256(const char* secret, const char* str) { + Serial.print("HMAC-SHA256 of '"); + Serial.print(str); + Serial.print("' with secret '"); + Serial.print(secret); + Serial.print("' is 0x"); + + SHA256.beginHmac(secret); + SHA256.print(str); + SHA256.endHmac(); + + printResult(); +} + +void printResult() +{ + while (SHA256.available()) { + byte b = SHA256.read(); + + if (b < 16) { + Serial.print("0"); + } + + Serial.print(b, HEX); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/ArduinoBearSSLConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/ArduinoBearSSLConfig.h new file mode 100644 index 00000000..160fc225 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/ArduinoBearSSLConfig.h @@ -0,0 +1,7 @@ +#ifndef ARDUINO_BEARSSL_CONFIG_H_ +#define ARDUINO_BEARSSL_CONFIG_H_ + +/* Enabling this define allows the usage of ArduinoBearSSL without crypto chip. */ +//#define ARDUINO_DISABLE_ECCX08 + +#endif /* ARDUINO_BEARSSL_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/WiFiSSLClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/WiFiSSLClient.ino new file mode 100644 index 00000000..91294bab --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoBearSSL/examples/WiFiSSLClient/WiFiSSLClient.ino @@ -0,0 +1,113 @@ +/* + This example creates a client object that connects and transfers + data using always SSL. + + It is compatible with the methods normally related to plain + connections, like client.connect(host, port). + + Written by Arturo Guadalupi + last revision November 2015 + +*/ + +#include +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; +BearSSLClient sslClient(client); + +unsigned long getTime() { + return WiFi.getTime(); +} + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to wifi"); + printWiFiStatus(); + + ArduinoBearSSL.onGetTime(getTime); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (sslClient.connect(server, 443)) { + Serial.println("connected to server"); + // Make a HTTP request: + sslClient.println("GET /search?q=arduino HTTP/1.1"); + sslClient.println("Host: www.google.com"); + sslClient.println("Connection: close"); + sslClient.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (sslClient.available()) { + char c = sslClient.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!sslClient.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + sslClient.stop(); + + // do nothing forevermore: + while (true); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/README.adoc new file mode 100644 index 00000000..56d14c8f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoDMX + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Control DMX lights with your Arduino. + +Using RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library. + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/examples/DMXBlink/DMXBlink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/examples/DMXBlink/DMXBlink.ino new file mode 100644 index 00000000..25a9759e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/examples/DMXBlink/DMXBlink.ino @@ -0,0 +1,51 @@ +/* + DMX Blink + + This sketch toggles the value of DMX channel 1 between 255 and 0. + + Circuit: + - DMX light + - MKR board + - MKR 485 shield + - ISO GND connected to DMX light GND (pin 1) + - Y connected to DMX light Data + (pin 2) + - Z connected to DMX light Data - (pin 3) + - Jumper positions + - Z \/\/ Y set to ON + + created 5 July 2018 + by Sandeep Mistry +*/ + +#include // the ArduinoDMX library depends on ArduinoRS485 +#include + +const int universeSize = 16; + +void setup() { + Serial.begin(9600); + while (!Serial); + + // initialize the DMX library with the universe size + if (!DMX.begin(universeSize)) { + Serial.println("Failed to initialize DMX!"); + while (1); // wait for ever + } +} + +void loop() { + // set channel 1 value to 255 + DMX.beginTransmission(); + DMX.write(1, 255); + DMX.endTransmission(); + + delay(1000); + + // set channel 1 value to 0 + DMX.beginTransmission(); + DMX.write(1, 0); + DMX.endTransmission(); + + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/examples/DMXFade/DMXFade.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/examples/DMXFade/DMXFade.ino new file mode 100644 index 00000000..5db8d873 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoDMX/examples/DMXFade/DMXFade.ino @@ -0,0 +1,57 @@ +/* + DMX Fade + + This sketch fades the value of DMX channel 1 between 0 and 255 in steps to create a fade effect. + All other slots are set to a value of 0. + + Circuit: + - DMX light + - MKR board + - MKR 485 shield + - ISO GND connected to DMX light GND (pin 1) + - Y connected to DMX light Data + (pin 2) + - Z connected to DMX light Data - (pin 3) + - Jumper positions + - Z \/\/ Y set to ON + + created 5 July 2018 + by Sandeep Mistry +*/ + +#include // the ArduinoDMX library depends on ArduinoRS485 +#include + +const int universeSize = 16; + +int brightness = 0; +int fadeAmount = 5; + +void setup() { + Serial.begin(9600); + while (!Serial); + + // initialize the DMX library with the universe size + if (!DMX.begin(universeSize)) { + Serial.println("Failed to initialize DMX!"); + while (1); // wait for ever + } +} + +void loop() { + // set the value of channel 1 + DMX.beginTransmission(); + DMX.write(1, brightness); + DMX.endTransmission(); + + // change the brightness for the next round + brightness += fadeAmount; + + // reverse fade direction when on edge of range + if (brightness <= 0 || brightness >= 255) { + fadeAmount = -fadeAmount; + } + + // delay for dimming effect + delay(30); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/README.adoc new file mode 100644 index 00000000..182880a7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/README.adoc @@ -0,0 +1,29 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: ArduinoECCX08 + += {repository-name} = + +image:https://github.com/{repository-owner}/{repository-name}/workflows/Compile%20Examples/badge.svg["Compile Examples Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Compile+Examples"] +image:https://github.com/{repository-owner}/{repository-name}/workflows/Arduino%20Lint/badge.svg["Arduino Lint Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Arduino+Lint"] +image:https://github.com/{repository-owner}/{repository-name}/workflows/Spell%20Check/badge.svg["Spell Check Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Spell+Check"] + +Arduino Library for the Atmel/Microchip ECC508 and ECC608 crypto chips + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/ECCX08RandomNumber/ECCX08RandomNumber.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/ECCX08RandomNumber/ECCX08RandomNumber.ino new file mode 100644 index 00000000..4744c1e5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/ECCX08RandomNumber/ECCX08RandomNumber.ino @@ -0,0 +1,37 @@ +/* + ECCX08 Random Number + + This sketch uses the ECC508 or ECC608 to generate a random number + every second and print it to the Serial monitor + + Circuit: + - MKR board with ECC508 or ECC608 on board + + created 19 July 2018 + by Sandeep Mistry +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("Failed to communicate with ECC508/ECC608!"); + while (1); + } + + if (!ECCX08.locked()) { + Serial.println("The ECC508/ECC608 is not locked!"); + while (1); + } +} + +void loop() { + Serial.print("Random number = "); + Serial.println(ECCX08.random(65535)); + + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08CSR/ECCX08CSR.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08CSR/ECCX08CSR.ino new file mode 100644 index 00000000..ddc914ae --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08CSR/ECCX08CSR.ino @@ -0,0 +1,151 @@ +/* + ArduinoECCX08 - CSR (Certificate Signing Request) + + This sketch can be used to generate a CSR for a private key + generated in an ECC508/ECC608 crypto chip slot. + + If the ECC508/ECC608 is not configured and locked it prompts + the user to configure and lock the chip with a default TLS + configuration. + + The user is prompted for the following information that is contained + in the generated CSR: + - country + - state or province + - locality + - organization + - organizational unit + - common name + + The user can also select a slot number to use for the private key + A new private key can also be generated in this slot. + + The circuit: + - Arduino MKR board equipped with ECC508 or ECC608 chip + + This example code is in the public domain. +*/ + +#include +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + String serialNumber = ECCX08.serialNumber(); + + Serial.print("ECCX08 Serial Number = "); + Serial.println(serialNumber); + Serial.println(); + + if (!ECCX08.locked()) { + String lock = promptAndReadLine("The ECCX08 on your board is not locked, would you like to PERMANENTLY configure and lock it now? (y/N)", "N"); + lock.toLowerCase(); + + if (!lock.startsWith("y")) { + Serial.println("Unfortunately you can't proceed without locking it :("); + while (1); + } + + if (!ECCX08.writeConfiguration(ECCX08_DEFAULT_TLS_CONFIG)) { + Serial.println("Writing ECCX08 configuration failed!"); + while (1); + } + + if (!ECCX08.lock()) { + Serial.println("Locking ECCX08 configuration failed!"); + while (1); + } + + Serial.println("ECCX08 locked successfully"); + Serial.println(); + } + + Serial.println("Hi there, in order to generate a new CSR for your board, we'll need the following information ..."); + Serial.println(); + + String country = promptAndReadLine("Country Name (2 letter code)", ""); + String stateOrProvince = promptAndReadLine("State or Province Name (full name)", ""); + String locality = promptAndReadLine("Locality Name (eg, city)", ""); + String organization = promptAndReadLine("Organization Name (eg, company)", ""); + String organizationalUnit = promptAndReadLine("Organizational Unit Name (eg, section)", ""); + String common = promptAndReadLine("Common Name (e.g. server FQDN or YOUR name)", serialNumber.c_str()); + String slot = promptAndReadLine("What slot would you like to use? (0 - 4)", "0"); + String generateNewKey = promptAndReadLine("Would you like to generate a new private key? (Y/n)", "Y"); + + Serial.println(); + + generateNewKey.toLowerCase(); + + if (!ECCX08CSR.begin(slot.toInt(), generateNewKey.startsWith("y"))) { + Serial.println("Error starting CSR generation!"); + while (1); + } + + ECCX08CSR.setCountryName(country); + ECCX08CSR.setStateProvinceName(stateOrProvince); + ECCX08CSR.setLocalityName(locality); + ECCX08CSR.setOrganizationName(organization); + ECCX08CSR.setOrganizationalUnitName(organizationalUnit); + ECCX08CSR.setCommonName(common); + + String csr = ECCX08CSR.end(); + + if (!csr) { + Serial.println("Error generating CSR!"); + while (1); + } + + Serial.println("Here's your CSR, enjoy!"); + Serial.println(); + Serial.println(csr); +} + +void loop() { + // do nothing +} + +String promptAndReadLine(const char* prompt, const char* defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + + if (s.length() == 0) { + s = defaultValue; + } + + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + continue; + } else if (c == '\n') { + break; + } + + line += c; + } + } + + return line; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08JWSPublicKey/ECCX08JWSPublicKey.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08JWSPublicKey/ECCX08JWSPublicKey.ino new file mode 100644 index 00000000..e34ce3ac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08JWSPublicKey/ECCX08JWSPublicKey.ino @@ -0,0 +1,118 @@ +/* + ArduinoECCX08 - JWS Public Key + + This sketch can be used to generate a PEM public key for a private key + generated in an ECC508/ECC608 crypto chip slot. + + If the ECC508/ECC608 is not configured and locked it prompts + the user to configure and lock the chip with a default TLS + configuration. + + The user can also select a slot number to use for the private key + A new private key can also be generated in this slot. + + The circuit: + - Arduino MKR board equipped with ECC508 or ECC608 chip + + This example code is in the public domain. +*/ + +#include +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + if (!ECCX08.locked()) { + String lock = promptAndReadLine("The ECCX08 on your board is not locked, would you like to PERMANENTLY configure and lock it now? (y/N)", "N"); + lock.toLowerCase(); + + if (!lock.startsWith("y")) { + Serial.println("Unfortunately you can't proceed without locking it :("); + while (1); + } + + if (!ECCX08.writeConfiguration(ECCX08_DEFAULT_TLS_CONFIG)) { + Serial.println("Writing ECCX08 configuration failed!"); + while (1); + } + + if (!ECCX08.lock()) { + Serial.println("Locking ECCX08 configuration failed!"); + while (1); + } + + Serial.println("ECCX08 locked successfully"); + Serial.println(); + } + + Serial.println("Hi there, in order to generate a PEM public key for your board, we'll need the following information ..."); + Serial.println(); + + String slot = promptAndReadLine("What slot would you like to use? (0 - 4)", "0"); + String generateNewKey = promptAndReadLine("Would you like to generate a new private key? (Y/n)", "Y"); + + Serial.println(); + + generateNewKey.toLowerCase(); + + String publicKeyPem = ECCX08JWS.publicKey(slot.toInt(), generateNewKey.startsWith("y")); + + if (!publicKeyPem || publicKeyPem == "") { + Serial.println("Error generating public key!"); + while (1); + } + + Serial.println("Here's your public key PEM, enjoy!"); + Serial.println(); + Serial.println(publicKeyPem); +} + +void loop() { + // do nothing +} + +String promptAndReadLine(const char* prompt, const char* defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + + if (s.length() == 0) { + s = defaultValue; + } + + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + continue; + } else if (c == '\n') { + break; + } + + line += c; + } + } + + return line; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08SelfSignedCert/ECCX08SelfSignedCert.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08SelfSignedCert/ECCX08SelfSignedCert.ino new file mode 100644 index 00000000..a83562b8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoECCX08/examples/Tools/ECCX08SelfSignedCert/ECCX08SelfSignedCert.ino @@ -0,0 +1,149 @@ +/* + ArduinoECCX08 - Self Signed Cert + + This sketch can be used to generate a self signed certificate + for a private key generated in an ECC508/ECC608 crypto chip slot. + The issue and expired date, and signature are stored in another + slot for reconstrution. + + If the ECC508/ECC608 is not configured and locked it prompts + the user to configure and lock the chip with a default TLS + configuration. + + The user can also select the slot number to use for the private key + and storage. + A new private key can also be generated in this slot. + + The circuit: + - Arduino MKR board equipped with ECC508 or ECC608 chip + + This example code is in the public domain. +*/ + +#include +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + String serialNumber = ECCX08.serialNumber(); + + Serial.print("ECCX08 Serial Number = "); + Serial.println(serialNumber); + Serial.println(); + + if (!ECCX08.locked()) { + String lock = promptAndReadLine("The ECCX08 on your board is not locked, would you like to PERMANENTLY configure and lock it now? (y/N)", "N"); + lock.toLowerCase(); + + if (!lock.startsWith("y")) { + Serial.println("Unfortunately you can't proceed without locking it :("); + while (1); + } + + if (!ECCX08.writeConfiguration(ECCX08_DEFAULT_TLS_CONFIG)) { + Serial.println("Writing ECCX08 configuration failed!"); + while (1); + } + + if (!ECCX08.lock()) { + Serial.println("Locking ECCX08 configuration failed!"); + while (1); + } + + Serial.println("ECCX08 locked successfully"); + Serial.println(); + } + + Serial.println("Hi there, in order to generate a new self signed cert for your board, we'll need the following information ..."); + Serial.println(); + + String issueYear = promptAndReadLine("Please enter the issue year of the certificate? (2000 - 2031)", "2019"); + String issueMonth = promptAndReadLine("Please enter the issue month of the certificate? (1 - 12)", "1"); + String issueDay = promptAndReadLine("Please enter the issue day of the certificate? (1 - 31)", "1"); + String issueHour = promptAndReadLine("Please enter the issue hour of the certificate? (0 - 23)", "0"); + String expireYears = promptAndReadLine("Please enter how many years the certificate is valid for? (1 - 31)", "31"); + String privateKeySlot = promptAndReadLine("What slot would you like to use for the private key? (0 - 4)", "0"); + String storageSlot = promptAndReadLine("What slot would you like to use for storage? (8 - 15)", "8"); + String generateNewKey = promptAndReadLine("Would you like to generate a new private key? (Y/n)", "Y"); + + Serial.println(); + + generateNewKey.toLowerCase(); + + if (!ECCX08SelfSignedCert.beginStorage(privateKeySlot.toInt(), storageSlot.toInt(), generateNewKey.startsWith("y"))) { + Serial.println("Error starting self signed cert generation!"); + while (1); + } + + ECCX08SelfSignedCert.setCommonName(ECCX08.serialNumber()); + ECCX08SelfSignedCert.setIssueYear(issueYear.toInt()); + ECCX08SelfSignedCert.setIssueMonth(issueMonth.toInt()); + ECCX08SelfSignedCert.setIssueDay(issueDay.toInt()); + ECCX08SelfSignedCert.setIssueHour(issueHour.toInt()); + ECCX08SelfSignedCert.setExpireYears(expireYears.toInt()); + + String cert = ECCX08SelfSignedCert.endStorage(); + + if (!cert) { + Serial.println("Error generating self signed cert!"); + while (1); + } + + Serial.println("Here's your self signed cert, enjoy!"); + Serial.println(); + Serial.println(cert); + Serial.println(); + + Serial.print("SHA1: "); + Serial.println(ECCX08SelfSignedCert.sha1()); +} + +void loop() { + // do nothing +} + +String promptAndReadLine(const char* prompt, const char* defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + + if (s.length() == 0) { + s = defaultValue; + } + + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + continue; + } else if (c == '\n') { + break; + } + + line += c; + } + } + + return line; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoGraphics/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoGraphics/README.adoc new file mode 100644 index 00000000..a77a80e7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoGraphics/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoGraphics + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Core graphics library for Arduino. Based on the Processing API. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/ArduinoGraphics + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoGraphics/examples/ASCIIDraw/ASCIIDraw.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoGraphics/examples/ASCIIDraw/ASCIIDraw.ino new file mode 100644 index 00000000..398a40db --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoGraphics/examples/ASCIIDraw/ASCIIDraw.ino @@ -0,0 +1,107 @@ +/* + ASCIIDraw + + Use the ArduinoGraphics library to draw ASCII art on the Serial Monitor. + + This is intended primarily to allow testing of the library. + See the Arduino_MKRRGB library for a more useful demonstration of the ArduinoGraphics library. + + The circuit: + - Arduino board + + This example code is in the public domain. +*/ + +#include + +const byte canvasWidth = 61; +const byte canvasHeight = 27; + +class ASCIIDrawClass : public ArduinoGraphics { + public: + // can be used with an object of any class that inherits from the Print class + ASCIIDrawClass(Print &printObject = (Print &)Serial) : + ArduinoGraphics(canvasWidth, canvasHeight), + _printObject(&printObject) {} + + // this function is called by the ArduinoGraphics library's functions + virtual void set(int x, int y, uint8_t r, uint8_t g, uint8_t b) { + // the r parameter is (mis)used to set the character to draw with + _canvasBuffer[x][y] = r; + // cast unused parameters to void to fix "unused parameter" warning + (void)g; + (void)b; + } + + // display the drawing + void endDraw() { + ArduinoGraphics::endDraw(); + + for (byte row = 0; row < canvasHeight; row++) { + for (byte column = 0; column < canvasWidth; column++) { + // handle unset parts of buffer + if (_canvasBuffer[column][row] == 0) { + _canvasBuffer[column][row] = ' '; + } + _printObject->print(_canvasBuffer[column][row]); + } + _printObject->println(); + } + } + + private: + Print *_printObject; + char _canvasBuffer[canvasWidth][canvasHeight] = {{0}}; +}; + +ASCIIDrawClass ASCIIDraw; + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + ASCIIDraw.beginDraw(); + + // configure the character used to fill the background. The second and third parameters are ignored + ASCIIDraw.background('+', 0, 0); + ASCIIDraw.clear(); + + // add the outer border + ASCIIDraw.stroke('-', 0, 0); + ASCIIDraw.fill('*', 0, 0); + const byte outerBorderThickness = 1; + ASCIIDraw.rect(outerBorderThickness, outerBorderThickness, canvasWidth - outerBorderThickness * 2, canvasHeight - outerBorderThickness * 2); + + // add the inner border + ASCIIDraw.stroke('+', 0, 0); + ASCIIDraw.fill('O', 0, 0); + const byte borderThickness = outerBorderThickness + 6; + ASCIIDraw.rect(borderThickness, borderThickness, canvasWidth - borderThickness * 2, canvasHeight - borderThickness * 2); + + // add the text + ASCIIDraw.background(' ', 0, 0); + ASCIIDraw.stroke('@', 0, 0); + const char text[] = "ARDUINO"; + ASCIIDraw.textFont(Font_5x7); + const byte textWidth = strlen(text) * ASCIIDraw.textFontWidth(); + const byte textHeight = ASCIIDraw.textFontHeight(); + const byte textX = (canvasWidth - textWidth) / 2; + const byte textY = (canvasHeight - textHeight) / 2; + ASCIIDraw.text(text, textX, textY); + + // underline the text + ASCIIDraw.stroke('-', 0, 0); + ASCIIDraw.line(textX, textY + textHeight - 1, textX + textWidth - 1, textY + textHeight - 1); + + // add some accents to the underline + ASCIIDraw.stroke('+', 0, 0); + ASCIIDraw.point(textX + 4, textY + textHeight - 1); + ASCIIDraw.point(textX + textWidth - 1 - 4, textY + textHeight - 1); + + // print the drawing to the Serial Monitor + ASCIIDraw.endDraw(); +} + +void loop() {} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/LICENSE new file mode 100644 index 00000000..4a1b324f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/LICENSE @@ -0,0 +1,688 @@ +This file includes licensing information for ArduinoIoTCloud + +Copyright (c) 2019 ARDUINO SA (www.arduino.cc) + +The software is released under the GNU General Public License, which covers the main body +of the ArduinoIoTCloud code. The terms of this license can be found at: +https://www.gnu.org/licenses/gpl-3.0.en.html + +You can be released from the requirements of the above licenses by purchasing +a commercial license. Buying such a license is mandatory if you want to modify or +otherwise use the software for commercial activities involving the Arduino +software without disclosing the source code of your own applications. To purchase +a commercial license, send an email to license@arduino.cc + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/README.md new file mode 100644 index 00000000..c18fd280 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/README.md @@ -0,0 +1,88 @@ +`ArduinoIoTCloud` +================= + +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoIoTCloud/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoIoTCloud/actions/workflows/check-arduino.yml) +[![Compile Examples](https://github.com/arduino-libraries/ArduinoIoTCloud/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/ArduinoIoTCloud/actions?workflow=Compile+Examples) +[![Spell Check](https://github.com/arduino-libraries/ArduinoIoTCloud/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/ArduinoIoTCloud/actions?workflow=Spell+Check) +[![Unit Tests](https://github.com/arduino-libraries/ArduinoIoTCloud/workflows/Unit%20Tests/badge.svg)](https://github.com/arduino-libraries/ArduinoIoTCloud/actions?workflow=Unit+Tests) +[![codecov](https://codecov.io/gh/arduino-libraries/ArduinoIoTCloud/branch/master/graph/badge.svg)](https://codecov.io/gh/arduino-libraries/ArduinoIoTCloud) + +### What? +The `ArduinoIoTCloud` library is the central element of the firmware enabling certain Arduino boards to connect to the [Arduino IoT Cloud](https://www.arduino.cc/en/IoT/HomePage). The following boards are supported: + +* **WiFi**: [`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), [`Portenta H7`](https://store.arduino.cc/portenta-h7), [`ESP8266`](https://github.com/esp8266/Arduino/releases/tag/2.5.0), [`ESP32`](https://github.com/espressif/arduino-esp32/releases/tag/1.0.6) +* **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) +* **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) +* **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) + +### How? +1) Register your Arduino IoT Cloud capable board via [Arduino IoT Cloud](https://create.arduino.cc/iot) (Devices Section). +2) Create a new logical representation known as a [Thing](https://create.arduino.cc/iot/things). + +### Arduino IoT Cloud Components + +- **Devices**: Physical objects built around a board (e.g. `MKR WiFi 1010`). This is the hardware which runs the sketch, reads sensors, controls actuators and communicates with the Arduino IoT Cloud. + +- **Things**: Logical representation of a connected object. They embody inherent properties of the object, with as little reference to the actual hardware or code used to implement them. Each Thing is represented by a collection of _Properties_ (e.g., temperature, light, pressure...). + +- **Properties**: Qualities defining the characteristics of a system. A _Property_ can be defined as *read-only* (`READ`) to indicate that Arduino IoT Cloud can read the data, but cannot change the value of such _Property_. On the other end, it may be designated to be **read-and-write** (`READWRITE`), allowing Arduino IoT Cloud to remotely change the property’s value and trigger an event notification on the device. It is also possible to mark properties as *write-only* (`WRITE`) which means the cloud can write to this property but not read its value (this limits data transmission for properties which are used to trigger events only). + +### How-to-use +* `thingProperties.h` +```C++ +void onLedChange(); +/* ... */ +bool led; +int seconds; +/* ... */ +void initProperties() { + ArduinoCloud.setThingId("ARDUINO-THING-ID"); + ArduinoCloud.addProperty(led, WRITE, ON_CHANGE, onLedChange); + ArduinoCloud.addProperty(seconds, READ, ON_CHANGE); +} +/* ... */ +WiFiConnectionHandler ArduinoIoTPreferredConnection("SECRET_SSID", "SECRET_PASS"); +``` + +* `MyCloudApplication.ino` +```C++ +#include "thingProperties.h" + +void setup() { + Serial.begin(9600); + while(!Serial) { } + pinMode(LED_BUILTIN, OUTPUT); + + initProperties(); + ArduinoCloud.begin(ArduinoIoTPreferredConnection); +} + +void loop() { + ArduinoCloud.update(); + seconds = millis() / 1000; +} + +void onLedChange() { + digitalWrite(LED_BUILTIN, led); +} +``` + +### FAQ +#### Watchdog +This [1.0.0](https://github.com/arduino-libraries/ArduinoIoTCloud/releases/tag/1.0.0) release of this library adds watchdog functionality to all ATSAMD21G18 based cloud connected boards. A watchdog is simply an electronic timer counting down from a preset start value which, upon reaching zero, triggers a reset of the microcontroller. It can be used to automatically recover from temporary hardware faults or unrecoverable software errors. In order to avoid the watchdog from reaching zero the countdown timer needs to be regularly re-set to its start value. This is happening within `ArduinoCloud.update()` which is periodically called at the start of the `loop()` function. Although the watchdog is automatically enabled it can be disabled by setting the second parameter of `ArduinoCloud.begin(...)` to `false`: +```C++ +ArduinoCloud.begin(ArduinoIoTPreferredConnection, false). +``` + +#### Device can not subscribe to `THING_ID` +``` +ArduinoIoTCloudTCP::handle_SubscribeMqttTopics could not subscribe to /a/t/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/e/i +``` +In this case either the device has not been associated with the thing within the Arduino IoT Cloud GUI configuration or there's a typo in the thing id. + +#### ESP Boards +Support for ESP boards is obtained through third-party core with some differences and limitations compared to Arduino boards. + +- **Authentication scheme**: Board authentication is done through `DEVICE_LOGIN_NAME` and `DEVICE_KEY`, both values are included in the `thingProperties.h` file. +- **RTC**: RTC support is not included thus each `ArduinoCould.update()` call will lead to an NTP request introducing delay in your `loop()` function. The scheduler widget will not work correctly if connection is lost after configuration. +- **Watchdog**: Watchdog support is not included. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino new file mode 100644 index 00000000..aa19f05a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/ArduinoIoTCloud-Advanced.ino @@ -0,0 +1,62 @@ +/* + This sketch demonstrates how to use more complex cloud data types such as a colour or coordinates. + + This sketch is compatible with: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR NB 1500 + - MKR WAN 1300/1310 + - Nano 33 IoT + - ESP 8266 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { } + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +float latMov = 45.5058224, lonMov = 9.1628673; +float latArd = 45.0502078, lonArd = 7.6674765; + +float hueRed = 0.0, satRed = 100.0, briRed = 100.0; +float hueGreen = 80.0, satGreen = 100.0, briGreen = 100.0; + +void loop() { + ArduinoCloud.update(); +} + +void onSwitchButtonChange() { + if (switchButton) + { + location = Location(latMov, lonMov); + color = Color(hueRed, satRed, briRed); + } + else + { + location = Location(latArd, lonArd); + color = Color(hueGreen, satGreen, briGreen); + } +} + +void onColorChange() { + Serial.print("Hue = "); + Serial.println(color.getValue().hue); + Serial.print("Sat = "); + Serial.println(color.getValue().sat); + Serial.print("Bri = "); + Serial.println(color.getValue().bri); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h new file mode 100644 index 00000000..fc0b0661 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) + #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" + #define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) + #define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) + #define SECRET_APP_EUI "" + #define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/thingProperties.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/thingProperties.h new file mode 100644 index 00000000..ad978851 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Advanced/thingProperties.h @@ -0,0 +1,39 @@ +#include +#include + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void onSwitchButtonChange(); +void onColorChange(); + +bool switchButton; +CloudLocation location; +CloudColor color; + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE, onSwitchButtonChange); + ArduinoCloud.addProperty(location, READ, ON_CHANGE); + ArduinoCloud.addProperty(color, READWRITE, ON_CHANGE, onColorChange); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE, onSwitchButtonChange); + ArduinoCloud.addProperty(location, 2, READ, ON_CHANGE); + ArduinoCloud.addProperty(color, 3, READWRITE, ON_CHANGE, onColorChange); +#endif +} + +#if defined(BOARD_HAS_WIFI) + WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) + GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) + LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) + NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino new file mode 100644 index 00000000..011a1fef --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/ArduinoIoTCloud-Basic.ino @@ -0,0 +1,61 @@ +/* + This sketch demonstrates how to exchange data between your board and the Arduino IoT Cloud. + + * Connect a potentiometer (or other analog sensor) to A0. + * When the potentiometer (or sensor) value changes the data is sent to the Cloud. + * When you flip the switch in the Cloud dashboard the onboard LED lights gets turned ON or OFF. + + IMPORTANT: + This sketch works with WiFi, GSM, NB and Lora enabled boards supported by Arduino IoT Cloud. + On a LoRa board, if it is configuered as a class A device (default and preferred option), values from Cloud dashboard are received + only after a value is sent to Cloud. + + This sketch is compatible with: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR NB 1500 + - MKR WAN 1300/1310 + - Nano 33 IoT + - ESP 8266 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +#if defined(ESP32) +static int const LED_BUILTIN = 2; +#endif + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { } + + /* Configure LED pin as an output */ + pinMode(LED_BUILTIN, OUTPUT); + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); + potentiometer = analogRead(A0); + seconds = millis() / 1000; +} + +/* + * 'onLedChange' is called when the "led" property of your Thing changes + */ +void onLedChange() { + Serial.print("LED set to "); + Serial.println(led); + digitalWrite(LED_BUILTIN, led); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/arduino_secrets.h new file mode 100644 index 00000000..fc0b0661 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) + #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" + #define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) + #define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) + #define SECRET_APP_EUI "" + #define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/thingProperties.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/thingProperties.h new file mode 100644 index 00000000..fbf2ea96 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Basic/thingProperties.h @@ -0,0 +1,46 @@ +#include +#include + +#if defined(BOARD_HAS_WIFI) +#elif defined(BOARD_HAS_GSM) +#elif defined(BOARD_HAS_LORA) +#elif defined(BOARD_HAS_NB) +#else + #error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400" +#endif + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void onLedChange(); + +bool led; +int potentiometer; +int seconds; + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange); + ArduinoCloud.addProperty(potentiometer, Permission::Read).publishOnChange(10); + ArduinoCloud.addProperty(seconds, Permission::Read).publishOnChange(1); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange); + ArduinoCloud.addProperty(potentiometer, 2, READ, ON_CHANGE); + ArduinoCloud.addProperty(seconds, 3, READ, 5 * MINUTES); +#endif +} + +#if defined(BOARD_HAS_WIFI) + WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) + GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) + LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) + NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino new file mode 100644 index 00000000..f7841721 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/ArduinoIoTCloud-Callbacks.ino @@ -0,0 +1,80 @@ +/* + This sketch demonstrates how to subscribe to IoT Cloud events and perform actions + The available events are + + CONNECT : Board successfully connects to IoT Cloud + SYNC : Data is successfully synced between Board and IoT Cloud + DISCONNECT : Board has lost connection to IoT Cloud + + You don't need any specific Properties to be created in order to demonstrate these functionalities. + Simply create a new Thing and give it 1 arbitrary Property. + Remember that the Thing ID needs to be configured in thingProperties.h + These events can be very useful in particular cases, for instance to disable a peripheral + or a connected sensor/actuator when no data connection is available, as well as to perform + specific operations on connection or right after properties values are synchronised. + + To subscribe to an event you can use the `addCallback` method and specify + which event will trigger which custom function. + One function per event can be assigned. + + IMPORTANT: + This sketch works with WiFi, GSM, NB and Lora enabled boards supported by Arduino IoT Cloud. + On a LoRa board, if it is configuered as a class A device (default and preferred option), values from Cloud dashboard are received + only after a value is sent to Cloud. + + This sketch is compatible with: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR NB 1500 + - MKR WAN 1300/1310 + - Nano 33 IoT + - ESP 8266 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { } + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + /* + Invoking `addCallback` on the ArduinoCloud object allows you to subscribe + to any of the available events and decide which functions to call when they are fired. + + The functions `doThisOnConnect`, `doThisOnSync`, `doThisOnDisconnect` + are custom functions and can be named to your likings and for this example + they are defined/implemented at the bottom of the Sketch + */ + ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect); + ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, doThisOnSync); + ArduinoCloud.addCallback(ArduinoIoTCloudEvent::DISCONNECT, doThisOnDisconnect); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); +} + +void doThisOnConnect(){ + /* add your custom code here */ + Serial.println("Board successfully connected to Arduino IoT Cloud"); +} +void doThisOnSync(){ + /* add your custom code here */ + Serial.println("Thing Properties synchronised"); +} +void doThisOnDisconnect(){ + /* add your custom code here */ + Serial.println("Board disconnected from Arduino IoT Cloud"); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h new file mode 100644 index 00000000..fc0b0661 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) + #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" + #define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) + #define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) + #define SECRET_APP_EUI "" + #define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/thingProperties.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/thingProperties.h new file mode 100644 index 00000000..9b2aa47b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Callbacks/thingProperties.h @@ -0,0 +1,33 @@ +#include +#include + +#if defined(BOARD_HAS_WIFI) +#elif defined(BOARD_HAS_GSM) +#elif defined(BOARD_HAS_LORA) +#elif defined(BOARD_HAS_NB) +#else + #error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400" +#endif + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +/* BOARD_ID is only required if you are using an ESP8266 */ +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +} + +#if defined(BOARD_HAS_WIFI) + WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) + GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) + LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) + NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino new file mode 100644 index 00000000..34abcdc3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/ArduinoIoTCloud-DeferredOTA.ino @@ -0,0 +1,89 @@ +/* + This sketch demonstrates how to handle deferred OTA from Arduino IoT Cloud. + + Deferred OTA can be triggered using the arduino-cloud-cli with the following command: + ./arduino-cloud-cli ota upload --device-id xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx --file filename.ino.bin --deferred + The update file and the download link will be available to be used within one week. + + * always_deny callback will always postpone the OTA update + * always_allow callback will immediately apply the OTA update + * ask_user_via_serial callback will read user input from serial to apply or postpone OTA update + + This sketch is compatible with: + - MKR WIFI 1010 + - Nano 33 IoT + - Portenta + - Nano RP2040 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +#if defined(ESP32) +static int const LED_BUILTIN = 2; +#endif + +bool always_deny() { + return false; +} + +bool always_allow() { + return true; +} + +static bool ask_user_via_serial_first_run = true; +bool ask_user_via_serial() { + if (ask_user_via_serial_first_run) { + Serial.println("Apply OTA? y / [n]"); + ask_user_via_serial_first_run = false; + } + if (Serial.available()) { + char c = Serial.read(); + if (c == 'y' || c == 'Y') { + return true; + } + } + return false; +} + +bool onOTARequestCallback() +{ + /* Select the preferred behaviour changing the called function */ + //return always_deny(); + //return always_allow(); + return ask_user_via_serial(); +} + +void setup() { + /* Initialize serial and wait up to 5 seconds for port to open */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { } + + /* Configure LED pin as an output */ + pinMode(LED_BUILTIN, OUTPUT); + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + /* Setup OTA callback */ + ArduinoCloud.onOTARequestCb(onOTARequestCallback); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); +} + +/* + * 'onLedChange' is called when the "led" property of your Thing changes + */ +void onLedChange() { + Serial.print("LED set to "); + Serial.println(led); + digitalWrite(LED_BUILTIN, led); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h new file mode 100644 index 00000000..fc0b0661 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) + #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" + #define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) + #define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) + #define SECRET_APP_EUI "" + #define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h new file mode 100644 index 00000000..549f80f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-DeferredOTA/thingProperties.h @@ -0,0 +1,40 @@ +#include +#include + +#if defined(BOARD_HAS_WIFI) +#elif defined(BOARD_HAS_GSM) +#elif defined(BOARD_HAS_LORA) +#elif defined(BOARD_HAS_NB) +#else + #error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400" +#endif + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void onLedChange(); + +bool led; + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + ArduinoCloud.addProperty(led, Permission::Write).onUpdate(onLedChange); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange); +#endif +} + +#if defined(BOARD_HAS_WIFI) + WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) + GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) + LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) + NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino new file mode 100644 index 00000000..3e01f970 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/ArduinoIoTCloud-Schedule.ino @@ -0,0 +1,229 @@ +/* + This sketch demonstrates how to use the cloud schedule variable type. + + This sketch is compatible with the following boards: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR NB 1500 + - Nano 33 IoT + - ESP 8266 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +#if defined(ESP32) +static int const LED_BUILTIN = 2; +#endif + +void setup() { + /* Initialize the serial port and wait up to 5 seconds for a connection */ + Serial.begin(9600); + for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime > 5000); ) { } + + /* Configure LED pin as an output */ + pinMode(LED_BUILTIN, OUTPUT); + + /* This function takes care of connecting your sketch variables to the ArduinoIoTCloud object */ + initProperties(); + + /* Initialize Arduino IoT Cloud library */ + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + setDebugMessageLevel(DBG_INFO); + ArduinoCloud.printDebugInfo(); + + /* Setup one shot schedule example */ + setupOneShotSchedule(); + + /* Setup per minute schedule example */ + setupMinuteSchedule(); + + /* Setup hourly schedule example */ + setupHourlySchedule(); + + /* Setup daily schedule example */ + setupDailySchedule(); + + /* Setup weekly schedule example */ + setupWeeklySchedule(); + + /* Setup monthly schedule example */ + setupMonthlySchedule(); + + /* Setup yearly schedule example */ + setupYearlySchedule(); +} + + /* Setup a schedule with an active period of 5 minutes that doesn't repeat + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 02 17:00:00 + */ +void setupOneShotSchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = startingFrom + ( DAYS * 1 ); + ScheduleTimeType activePeriod = MINUTES * 5; + + /* Warning: there is no cross check between until and activePeriod */ + ScheduleConfigurationType scheduleConfiguration = Schedule::createOneShotScheduleConfiguration(); + + oneShot = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + + /* Setup a schedule with an active period of 15 seconds that repeats each minute + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 02 17:00:00 + */ +void setupMinuteSchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = startingFrom + ( DAYS * 1 ); + ScheduleTimeType activePeriod = SECONDS * 15; + unsigned int repetitionPeriod = 1; + + /* Warning: there is no cross check between repetitionPeriod and activePeriod */ + ScheduleConfigurationType scheduleConfiguration = Schedule::createFixedDeltaScheduleConfiguration(ScheduleUnit::Minutes, repetitionPeriod); + + minute = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 20 minutes that repeats each hour + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 15 13:00:00 + */ +void setupHourlySchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00"); + ScheduleTimeType activePeriod = MINUTES * 20; + unsigned int repetitionPeriod = 1; + + /* Warning: there is no cross check between repetitionPeriod and activePeriod */ + ScheduleConfigurationType scheduleConfiguration = Schedule::createFixedDeltaScheduleConfiguration(ScheduleUnit::Hours, repetitionPeriod); + + hourly = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 2 hours that repeats each day + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 15 13:00:00 + */ +void setupDailySchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00"); + ScheduleTimeType activePeriod = HOURS * 2; + unsigned int repetitionPeriod = 1; + + /* Warning: there is no cross check between repetitionPeriod and activePeriod */ + ScheduleConfigurationType scheduleConfiguration = Schedule::createFixedDeltaScheduleConfiguration(ScheduleUnit::Days, repetitionPeriod); + + daily = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 3 minutes with a weekly configuration + * Starting from 2021 11 01 17:00:00 + * Until 2021 11 31 17:00:00 + * Weekly configuration + * Sunday -> Inactive + * Monday -> Active + * Tuesday -> Inactive + * Wednesday -> Active + * Thursday -> Inactive + * Friday -> Active + * Saturday -> Inactive + */ +void setupWeeklySchedule() { + + unsigned int startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + unsigned int until = startingFrom + ( DAYS * 30 ); + unsigned int executionPeriod = MINUTES * 3; + + ScheduleWeeklyMask WeeklyMask = { + ScheduleState::Inactive, /* Sunday */ + ScheduleState::Active, /* Monday */ + ScheduleState::Inactive, /* Tuesday */ + ScheduleState::Active, /* Wednesday */ + ScheduleState::Inactive, /* Thursday */ + ScheduleState::Active, /* Friday */ + ScheduleState::Inactive, /* Saturday */ + }; + + ScheduleConfigurationType scheduleConfiguration = Schedule::createWeeklyScheduleConfiguration(WeeklyMask); + + weekly = Schedule(startingFrom, until, executionPeriod, scheduleConfiguration); +} + +/* Setup a schedule with an active period of 1 day that repeats each third day of the month + * Starting from 2021 11 01 17:00:00 + * Until 2022 11 15 13:00:00 + */ +void setupMonthlySchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 01 17:00:00"); + ScheduleTimeType until = TimeService::getTimeFromString("2021 Nov 15 13:00:00"); + ScheduleTimeType activePeriod = DAYS * 1; + int dayOfMonth = 3; + + ScheduleConfigurationType scheduleConfiguration = Schedule::createMonthlyScheduleConfiguration(dayOfMonth); + + monthly = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + + +/* Setup a schedule with an active period of 2 days that repeats each year on November 6th + * Starting from 2021 11 06 17:00:00 + * Until 2041 11 15 13:00:00 + */ +void setupYearlySchedule() { + + ScheduleTimeType startingFrom = TimeService::getTimeFromString("2021 Nov 06 17:00:00"); + ScheduleTimeType until = TimeService::getTimeFromString("2041 Nov 06 13:00:00"); + ScheduleTimeType activePeriod = DAYS * 2; + int dayOfMonth = 6; + + ScheduleConfigurationType scheduleConfiguration = Schedule::createYearlyScheduleConfiguration(ScheduleMonth::Nov, dayOfMonth); + + yearly = Schedule(startingFrom, until, activePeriod, scheduleConfiguration); +} + +void loop() { + ArduinoCloud.update(); + + /* Print a message when the oneShot schedule is active */ + if(oneShot.isActive()) { + Serial.println("One shot schedule is active"); + } + + /* Print a message when the per minute schedule is active */ + if(minute.isActive()) { + Serial.println("Per minute schedule is active"); + } + + /* Print a message when the hourly schedule is active */ + if(hourly.isActive()) { + Serial.println("Hourly schedule is active"); + } + + /* Print a message when the daily schedule is active */ + if(daily.isActive()) { + Serial.println("Daily schedule is active"); + } + + /* Activate LED when the weekly schedule is active */ + digitalWrite(LED_BUILTIN, weekly.isActive()); + + /* Print a message when the monthly schedule is active */ + if(monthly.isActive()) { + Serial.println("Monthly schedule is active"); + } + + /* Print a message when the yearly schedule is active */ + if(yearly.isActive()) { + Serial.println("Yearly schedule is active"); + } + +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h new file mode 100644 index 00000000..fc0b0661 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/arduino_secrets.h @@ -0,0 +1,34 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) + #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" + #define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* ESP8266 */ +#if defined(BOARD_ESP8266) + #define SECRET_DEVICE_KEY "my-device-password" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) + #define SECRET_APP_EUI "" + #define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/thingProperties.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/thingProperties.h new file mode 100644 index 00000000..a426978c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/ArduinoIoTCloud-Schedule/thingProperties.h @@ -0,0 +1,46 @@ +#include +#include + +#define THING_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" +#define BOARD_ID "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" + +void onSwitchButtonChange(); + +bool switchButton; +CloudSchedule oneShot; +CloudSchedule minute; +CloudSchedule hourly; +CloudSchedule daily; +CloudSchedule weekly; +CloudSchedule monthly; +CloudSchedule yearly; + +void initProperties() { +#if defined(BOARD_ESP8266) + ArduinoCloud.setBoardId(BOARD_ID); + ArduinoCloud.setSecretDeviceKey(SECRET_DEVICE_KEY); +#endif + ArduinoCloud.setThingId(THING_ID); +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined(BOARD_HAS_NB) + ArduinoCloud.addProperty(switchButton, WRITE, ON_CHANGE); + ArduinoCloud.addProperty(oneShot, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(minute, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(hourly, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(daily, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(weekly, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(monthly, READWRITE, ON_CHANGE); + ArduinoCloud.addProperty(yearly, READWRITE, ON_CHANGE); +#elif defined(BOARD_HAS_LORA) + ArduinoCloud.addProperty(switchButton, 1, WRITE, ON_CHANGE; +#endif +} + +#if defined(BOARD_HAS_WIFI) + WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) + GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) + LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, _lora_band::EU868, NULL, _lora_class::CLASS_A); +#elif defined(BOARD_HAS_NB) + NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino new file mode 100644 index 00000000..bcb46b68 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/ArduinoIoTCloud_Travis_CI.ino @@ -0,0 +1,49 @@ +/* + This sketch is used in combination with Travis CI to check if + unintentional breaking changes are made to the used facing + Arduino IoT Cloud API. + + This sketch is compatible with: + - MKR 1000 + - MKR WIFI 1010 + - MKR GSM 1400 + - MKR WAN 1300/1310 +*/ + +#include "arduino_secrets.h" +#include "thingProperties.h" + +void setup() { + + Serial.begin(9600); + unsigned long serialBeginTime = millis(); + while (!Serial && (millis() - serialBeginTime > 5000)); + + Serial.println("Starting Arduino IoT Cloud Example"); + + initProperties(); + ArduinoCloud.begin(ArduinoIoTPreferredConnection); + + ArduinoCloud.printDebugInfo(); +} + +void loop() { + ArduinoCloud.update(); + +} + +void onBoolPropertyChange() { + Serial.println("'onBoolPropertyChange'"); +} + +void onIntPropertyChange() { + Serial.println("'onIntPropertyChange'"); +} + +void onFloatPropertyChange() { + Serial.println("'onFloatPropertyChange'"); +} + +void onStringPropertyChange() { + Serial.println("'onStringPropertyChange'"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h new file mode 100644 index 00000000..020482cf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/arduino_secrets.h @@ -0,0 +1,29 @@ +#include + +/* MKR1000, MKR WiFi 1010 */ +#if defined(BOARD_HAS_WIFI) + #define SECRET_SSID "YOUR_WIFI_NETWORK_NAME" + #define SECRET_PASS "YOUR_WIFI_PASSWORD" +#endif + +/* MKR GSM 1400 */ +#if defined(BOARD_HAS_GSM) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif + +/* MKR WAN 1300/1310 */ +#if defined(BOARD_HAS_LORA) + #define SECRET_APP_EUI "" + #define SECRET_APP_KEY "" +#endif + +/* MKR NB 1500 */ +#if defined(BOARD_HAS_NB) + #define SECRET_PIN "" + #define SECRET_APN "" + #define SECRET_LOGIN "" + #define SECRET_PASS "" +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h new file mode 100644 index 00000000..c0dded7a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/ArduinoIoTCloud_Travis_CI/thingProperties.h @@ -0,0 +1,140 @@ +/****************************************************************************** + INCLUDE + ******************************************************************************/ + +#include +#include + +#if defined(BOARD_HAS_WIFI) +#elif defined(BOARD_HAS_GSM) +#elif defined(BOARD_HAS_LORA) +#elif defined(BOARD_HAS_NB) +#else + #error "Arduino IoT Cloud currently only supports MKR1000, MKR WiFi 1010, MKR WAN 1300/1310, MKR NB 1500 and MKR GSM 1400" +#endif + +/****************************************************************************** + DEFINES + ******************************************************************************/ + +#define THING_ID "ARDUINO_IOT_CLOUD_THING_ID" + +/****************************************************************************** + GLOBAL CONSTANTS + ******************************************************************************/ + +int const MIN_DELTA_INT_PROPERTY = 5; +float const MIN_DELTA_FLOAT_PROPERTY = 10.0f; + +/****************************************************************************** + GLOBAL VARIABLES + ******************************************************************************/ + +bool bool_property_1; +bool bool_property_2; + +int int_property_1; +int int_property_2; +int int_property_3; +int int_property_4; +int int_property_5; +int int_property_6; + +float float_property_1; +float float_property_2; +float float_property_3; +float float_property_4; + +String str_property_1; +String str_property_2; +String str_property_3; +String str_property_4; +String str_property_5; +String str_property_6; +String str_property_7; +String str_property_8; + +#if defined(BOARD_HAS_WIFI) + WiFiConnectionHandler ArduinoIoTPreferredConnection(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) + GSMConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#elif defined(BOARD_HAS_LORA) + LoRaConnectionHandler ArduinoIoTPreferredConnection(SECRET_APP_EUI, SECRET_APP_KEY, EU868); +#elif defined(BOARD_HAS_NB) + NBConnectionHandler ArduinoIoTPreferredConnection(SECRET_PIN, SECRET_APN, SECRET_LOGIN, SECRET_PASS); +#endif + +/****************************************************************************** + PROTOTYPES + ******************************************************************************/ + +void onBoolPropertyChange(); +void onIntPropertyChange(); +void onFloatPropertyChange(); +void onStringPropertyChange(); + +/****************************************************************************** + FUNCTIONS + ******************************************************************************/ +#if defined(BOARD_HAS_WIFI) || defined(BOARD_HAS_GSM) || defined (BOARD_HAS_NB) +void initProperties() { + ArduinoCloud.setThingId(THING_ID); + + ArduinoCloud.addProperty(bool_property_1, READWRITE, 1 * SECONDS); + ArduinoCloud.addProperty(int_property_1, READ, 2 * MINUTES); + ArduinoCloud.addProperty(float_property_1, WRITE, 3 * HOURS); + ArduinoCloud.addProperty(str_property_1, READWRITE, 4 * DAYS); + + ArduinoCloud.addProperty(bool_property_2, Permission::ReadWrite).publishEvery(1 * SECONDS); + ArduinoCloud.addProperty(int_property_2, Permission::Read).publishEvery(1 * MINUTES); + ArduinoCloud.addProperty(float_property_2, Permission::Write).publishEvery(3 * HOURS); + ArduinoCloud.addProperty(str_property_2, Permission::ReadWrite).publishEvery(4 * DAYS); + + ArduinoCloud.addProperty(int_property_3, READWRITE, ON_CHANGE); /* Default 'minDelta' = 0 */ + ArduinoCloud.addProperty(int_property_4, READWRITE, ON_CHANGE, onIntPropertyChange); /* Default 'minDelta' = 0 */ + ArduinoCloud.addProperty(int_property_5, READWRITE, ON_CHANGE, 0 /* onIntPropertyChange */, MIN_DELTA_INT_PROPERTY); + ArduinoCloud.addProperty(int_property_6, READWRITE, ON_CHANGE, onIntPropertyChange, MIN_DELTA_INT_PROPERTY); + + ArduinoCloud.addProperty(float_property_3, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY); + ArduinoCloud.addProperty(float_property_4, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY).onUpdate(onFloatPropertyChange); + + ArduinoCloud.addProperty(str_property_3, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, MOST_RECENT_WINS); + ArduinoCloud.addProperty(str_property_4, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, CLOUD_WINS); + ArduinoCloud.addProperty(str_property_5, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, DEVICE_WINS); + + ArduinoCloud.addProperty(str_property_6, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(MOST_RECENT_WINS); + ArduinoCloud.addProperty(str_property_7, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(CLOUD_WINS); + ArduinoCloud.addProperty(str_property_8, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(DEVICE_WINS); +} + +#elif defined(BOARD_HAS_LORA) +void initProperties() { + ArduinoCloud.setThingId(THING_ID); + + ArduinoCloud.addProperty(bool_property_1, 1, READWRITE, 1 * SECONDS); + ArduinoCloud.addProperty(int_property_1, 2, READ, 2 * MINUTES); + ArduinoCloud.addProperty(float_property_1, 3, WRITE, 3 * HOURS); + ArduinoCloud.addProperty(str_property_1, 4, READWRITE, 4 * DAYS); + + ArduinoCloud.addProperty(bool_property_2, 5, Permission::ReadWrite).publishEvery(1 * SECONDS); + ArduinoCloud.addProperty(int_property_2, 6, Permission::Read).publishEvery(1 * MINUTES); + ArduinoCloud.addProperty(float_property_2, 7, Permission::Write).publishEvery(3 * HOURS); + ArduinoCloud.addProperty(str_property_2, 8, Permission::ReadWrite).publishEvery(4 * DAYS); + + ArduinoCloud.addProperty(int_property_3, 9, READWRITE, ON_CHANGE); /* Default 'minDelta' = 0 */ + ArduinoCloud.addProperty(int_property_4, 10, READWRITE, ON_CHANGE, onIntPropertyChange); /* Default 'minDelta' = 0 */ + ArduinoCloud.addProperty(int_property_5, 11, READWRITE, ON_CHANGE, 0 /* onIntPropertyChange */, MIN_DELTA_INT_PROPERTY); + ArduinoCloud.addProperty(int_property_6, 12, READWRITE, ON_CHANGE, onIntPropertyChange, MIN_DELTA_INT_PROPERTY); + + ArduinoCloud.addProperty(float_property_3, 13, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY); + ArduinoCloud.addProperty(float_property_4, 14, Permission::ReadWrite).publishOnChange(MIN_DELTA_FLOAT_PROPERTY).onUpdate(onFloatPropertyChange); + + ArduinoCloud.addProperty(str_property_3, 15, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, MOST_RECENT_WINS); + ArduinoCloud.addProperty(str_property_4, 16, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, CLOUD_WINS); + ArduinoCloud.addProperty(str_property_5, 17, READWRITE, 1 * SECONDS, 0 /* onStringPropertyChange */, 0.0 /* 'minDelta' */, DEVICE_WINS); + + ArduinoCloud.addProperty(str_property_6, 18, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(MOST_RECENT_WINS); + ArduinoCloud.addProperty(str_property_7, 19, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(CLOUD_WINS); + ArduinoCloud.addProperty(str_property_8, 20, Permission::ReadWrite).publishEvery(1 * SECONDS).onSync(DEVICE_WINS); +} +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/ECCX08TLSConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/ECCX08TLSConfig.h new file mode 100644 index 00000000..9126b366 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/ECCX08TLSConfig.h @@ -0,0 +1,105 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef _ECCX08_TLS_CONFIG_H_ +#define _ECCX08_TLS_CONFIG_H_ + +const byte DEFAULT_ECCX08_TLS_CONFIG[128] = { + // Read only - start + // SN[0:3] + 0x01, 0x23, 0x00, 0x00, + // RevNum + 0x00, 0x00, 0x50, 0x00, + // SN[4:8] + 0x00, 0x00, 0x00, 0x00, 0x00, + // Reserved + 0xC0, + // I2C_Enable + 0x71, + // Reserved + 0x00, + // Read only - end + // I2C_Address + 0xC0, + // Reserved + 0x00, + // OTPmode + 0x55, + // ChipMode + 0x00, + // SlotConfig + 0x83, 0x20, // External Signatures | Internal Signatures | IsSecret | Write Configure Never, Default: 0x83, 0x20, + 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x87, 0x20, + 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x8F, 0x20, + 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0xC4, 0x8F, + 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0x8F, 0x8F, + 0x8F, 0x8F, + 0x9F, 0x8F, + 0xAF, 0x8F, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0xAF, 0x8F, + // Counter[0] + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + // Counter[1] + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + // LastKeyUse + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + // Write via commands only - start + // UserExtra + 0x00, + // Selector + 0x00, + // LockValue + 0x55, + // LockConfig + 0x55, + // SlotLocked + 0xFF, 0xFF, + // Write via commands only - end + // RFU + 0x00, 0x00, + // X509format + 0x00, 0x00, 0x00, 0x00, + // KeyConfig + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00, + 0x1C, 0x00, + 0x1C, 0x00, + 0x1C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x1C, 0x00 +}; + +#endif /* _ECCX08_TLS_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/Provisioning.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/Provisioning.ino new file mode 100644 index 00000000..c1503afc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/Provisioning/Provisioning.ino @@ -0,0 +1,191 @@ +#include +#include "ECCX08TLSConfig.h" + +const bool DEBUG = true; + +ArduinoIoTCloudCertClass Certificate; +CryptoUtil Crypto; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!Crypto.begin()) { + Serial.println("No crypto present!"); + while (1); + } + + if (!Crypto.locked()) { + String lockConfirm = promptAndReadLine("Your crypto is unlocked, would you like to lock it (y/N): "); + lockConfirm.toLowerCase(); + + if (lockConfirm != "y") { + Serial.println("That's all folks"); + while (1); + } + + if (!Crypto.writeConfiguration(DEFAULT_ECCX08_TLS_CONFIG)) { + Serial.println("Writing crypto configuration failed!"); + while (1); + } + + if (!Crypto.lock()) { + Serial.println("Locking crypto configuration failed!"); + while (1); + } + + Serial.println("crypto locked successfully"); + Serial.println(); + } + + String csrConfirm = promptAndReadLine("Would you like to generate a new private key and CSR (y/N): "); + csrConfirm.toLowerCase(); + + if (csrConfirm != "y") { + Serial.println("That's all folks"); + while (1); + } + + if (!Certificate.begin()) { + Serial.println("Error starting CSR generation!"); + while (1); + } + + String deviceId = promptAndReadLine("Please enter the device id: "); + Certificate.setSubjectCommonName(deviceId); + + if (!Crypto.buildCSR(Certificate, CryptoSlot::Key, true)) { + Serial.println("Error generating CSR!"); + while (1); + } + + String csr = Certificate.getCSRPEM(); + + if (!csr) { + Serial.println("Error generating CSR!"); + while (1); + } + + Serial.println("Generated CSR is:"); + Serial.println(); + Serial.println(csr); + + String issueYear = promptAndReadLine("Please enter the issue year of the certificate (2000 - 2031): "); + String issueMonth = promptAndReadLine("Please enter the issue month of the certificate (1 - 12): "); + String issueDay = promptAndReadLine("Please enter the issue day of the certificate (1 - 31): "); + String issueHour = promptAndReadLine("Please enter the issue hour of the certificate (0 - 23): "); + String expireYears = promptAndReadLine("Please enter how many years the certificate is valid for (0 - 31): "); + String serialNumber = promptAndReadLine("Please enter the certificates serial number: "); + String authorityKeyIdentifier = promptAndReadLine("Please enter the certificates authority key identifier: "); + String signature = promptAndReadLine("Please enter the certificates signature: "); + + byte serialNumberBytes[CERT_SERIAL_NUMBER_LENGTH]; + byte authorityKeyIdentifierBytes[CERT_AUTHORITY_KEY_ID_LENGTH]; + byte signatureBytes[CERT_SIGNATURE_LENGTH]; + + hexStringToBytes(serialNumber, serialNumberBytes, sizeof(serialNumberBytes)); + hexStringToBytes(authorityKeyIdentifier, authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes)); + hexStringToBytes(signature, signatureBytes, sizeof(signatureBytes)); + + if (!Crypto.writeDeviceId(deviceId, CryptoSlot::DeviceId)) { + Serial.println("Error storing device id!"); + while (1); + } + + if (!Certificate.begin()) { + Serial.println("Error starting crypto storage!"); + while (1); + } + + Certificate.setSubjectCommonName(deviceId); + Certificate.setIssuerCountryName("US"); + Certificate.setIssuerOrganizationName("Arduino LLC US"); + Certificate.setIssuerOrganizationalUnitName("IT"); + Certificate.setIssuerCommonName("Arduino"); + Certificate.setSignature(signatureBytes, sizeof(signatureBytes)); + Certificate.setAuthorityKeyId(authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes)); + Certificate.setSerialNumber(serialNumberBytes, sizeof(serialNumberBytes)); + Certificate.setIssueYear(issueYear.toInt()); + Certificate.setIssueMonth(issueMonth.toInt()); + Certificate.setIssueDay(issueDay.toInt()); + Certificate.setIssueHour(issueHour.toInt()); + Certificate.setExpireYears(expireYears.toInt()); + + if (!Crypto.buildCert(Certificate, CryptoSlot::Key)) { + Serial.println("Error building cert!"); + while (1); + } + + if (!Crypto.writeCert(Certificate, CryptoSlot::CompressedCertificate)) { + Serial.println("Error storing cert!"); + while (1); + } + + if (!DEBUG) { + return; + } + + Serial.println("Compressed cert = "); + + const byte* certData = Certificate.bytes(); + int certLength = Certificate.length(); + + for (int i = 0; i < certLength; i++) { + byte b = certData[i]; + + if (b < 16) { + Serial.print('0'); + } + Serial.print(b, HEX); + } + Serial.println(); +} + +void loop() { +} + +String promptAndReadLine(const char* prompt) { + Serial.print(prompt); + String s = readLine(); + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + } else if (c == '\n') { + break; + } + + line += c; + } + } + + line.trim(); + + return line; +} + +void hexStringToBytes(String& in, byte out[], int length) { + int inLength = in.length(); + in.toUpperCase(); + int outLength = 0; + + for (int i = 0; i < inLength && outLength < length; i += 2) { + char highChar = in[i]; + char lowChar = in[i + 1]; + + byte highByte = (highChar <= '9') ? (highChar - '0') : (highChar + 10 - 'A'); + byte lowByte = (lowChar <= '9') ? (lowChar - '0') : (lowChar + 10 - 'A'); + + out[outLength++] = (highByte << 4) | (lowByte & 0xF); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08Cert.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08Cert.h new file mode 100644 index 00000000..d40d4cd0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08Cert.h @@ -0,0 +1,141 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef _ECCX08_CERT_H_ +#define _ECCX08_CERT_H_ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + +/****************************************************************************** + * CLASS DECLARATION + ******************************************************************************/ + +class ECCX08CertClass { + + public: + ECCX08CertClass(); + virtual ~ECCX08CertClass(); + + int beginCSR(int keySlot, bool newPrivateKey = true); + String endCSR(); + + int beginStorage(int compressedCertSlot, int serialNumberAndAuthorityKeyIdentifierSlot); + void setSignature(byte signature[]); + void setIssueYear(int issueYear); + void setIssueMonth(int issueMonth); + void setIssueDay(int issueDay); + void setIssueHour(int issueHour); + void setExpireYears(int expireYears); + void setSerialNumber(const byte serialNumber[]); + void setAuthorityKeyIdentifier(const byte authorityKeyIdentifier[]); + int endStorage(); + + int beginReconstruction(int keySlot, int compressedCertSlot, int serialNumberAndAuthorityKeyIdentifierSlot); + int endReconstruction(); + + byte* bytes(); + int length(); + + void setIssuerCountryName(const String& countryName); + void setIssuerStateProvinceName(const String& stateProvinceName); + void setIssuerLocalityName(const String& localityName); + void setIssuerOrganizationName(const String& organizationName); + void setIssuerOrganizationalUnitName(const String& organizationalUnitName); + void setIssuerCommonName(const String& commonName); + + void setSubjectCountryName(const String& countryName); + void setSubjectStateProvinceName(const String& stateProvinceName); + void setSubjectLocalityName(const String& localityName); + void setSubjectOrganizationName(const String& organizationName); + void setSubjectOrganizationalUnitName(const String& organizationalUnitName); + void setSubjectCommonName(const String& commonName); + + private: + int versionLength(); + + int issuerOrSubjectLength(const String& countryName, + const String& stateProvinceName, + const String& localityName, + const String& organizationName, + const String& organizationalUnitName, + const String& commonName); + + int publicKeyLength(); + + int authorityKeyIdentifierLength(const byte authorityKeyIdentifier[]); + + int signatureLength(const byte signature[]); + + int serialNumberLength(const byte serialNumber[]); + + int sequenceHeaderLength(int length); + + void appendVersion(int version, byte out[]); + + void appendIssuerOrSubject(const String& countryName, + const String& stateProvinceName, + const String& localityName, + const String& organizationName, + const String& organizationalUnitName, + const String& commonName, + byte out[]); + + void appendPublicKey(const byte publicKey[], byte out[]); + + void appendAuthorityKeyIdentifier(const byte authorityKeyIdentifier[], byte out[]); + + void appendSignature(const byte signature[], byte out[]); + + void appendSerialNumber(const byte serialNumber[], byte out[]); + + int appendName(const String& name, int type, byte out[]); + + void appendSequenceHeader(int length, byte out[]); + + int appendDate(int year, int month, int day, int hour, int minute, int second, byte out[]); + + int appendEcdsaWithSHA256(byte out[]); + + private: + int _keySlot; + int _compressedCertSlot; + int _serialNumberAndAuthorityKeyIdentifierSlot; + + String _issuerCountryName; + String _issuerStateProvinceName; + String _issuerLocalityName; + String _issuerOrganizationName; + String _issuerOrganizationalUnitName; + String _issuerCommonName; + + String _subjectCountryName; + String _subjectStateProvinceName; + String _subjectLocalityName; + String _subjectOrganizationName; + String _subjectOrganizationalUnitName; + String _subjectCommonName; + + byte _temp[108]; + byte* _bytes; + int _length; +}; + +#endif /* _ECCX08_CERT_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08TLSConfig.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08TLSConfig.h new file mode 100644 index 00000000..9126b366 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/ECCX08TLSConfig.h @@ -0,0 +1,105 @@ +/* + This file is part of ArduinoIoTCloud. + + Copyright 2019 ARDUINO SA (http://www.arduino.cc/) + + This software is released under the GNU General Public License version 3, + which covers the main part of arduino-cli. + The terms of this license can be found at: + https://www.gnu.org/licenses/gpl-3.0.en.html + + You can be released from the requirements of the above licenses by purchasing + a commercial license. Buying such a license is mandatory if you want to modify or + otherwise use the software for commercial activities involving the Arduino + software without disclosing the source code of your own applications. To purchase + a commercial license, send an email to license@arduino.cc. +*/ + +#ifndef _ECCX08_TLS_CONFIG_H_ +#define _ECCX08_TLS_CONFIG_H_ + +const byte DEFAULT_ECCX08_TLS_CONFIG[128] = { + // Read only - start + // SN[0:3] + 0x01, 0x23, 0x00, 0x00, + // RevNum + 0x00, 0x00, 0x50, 0x00, + // SN[4:8] + 0x00, 0x00, 0x00, 0x00, 0x00, + // Reserved + 0xC0, + // I2C_Enable + 0x71, + // Reserved + 0x00, + // Read only - end + // I2C_Address + 0xC0, + // Reserved + 0x00, + // OTPmode + 0x55, + // ChipMode + 0x00, + // SlotConfig + 0x83, 0x20, // External Signatures | Internal Signatures | IsSecret | Write Configure Never, Default: 0x83, 0x20, + 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x87, 0x20, + 0x87, 0x20, // External Signatures | Internal Signatures | ECDH | IsSecret | Write Configure Never, Default: 0x8F, 0x20, + 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0xC4, 0x8F, + 0x87, 0x2F, // External Signatures | Internal Signatures | ECDH | IsSecret | WriteKey all slots | Write Configure Never, Default: 0x8F, 0x8F, + 0x8F, 0x8F, + 0x9F, 0x8F, + 0xAF, 0x8F, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, + 0xAF, 0x8F, + // Counter[0] + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + // Counter[1] + 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, + // LastKeyUse + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, + // Write via commands only - start + // UserExtra + 0x00, + // Selector + 0x00, + // LockValue + 0x55, + // LockConfig + 0x55, + // SlotLocked + 0xFF, 0xFF, + // Write via commands only - end + // RFU + 0x00, 0x00, + // X509format + 0x00, 0x00, 0x00, 0x00, + // KeyConfig + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x33, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00, + 0x33, 0x00, // Private | Public | P256 NIST ECC key, Default: 0x1C, 0x00, + 0x1C, 0x00, + 0x1C, 0x00, + 0x1C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x3C, 0x00, + 0x1C, 0x00 +}; + +#endif /* _ECCX08_TLS_CONFIG_H_ */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/SelfProvisioning.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/SelfProvisioning.ino new file mode 100644 index 00000000..a0c13724 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/SelfProvisioning.ino @@ -0,0 +1,484 @@ +/* + Self Provisioning on Arduino IoT Cloud + + This sketch demonstrates how to automate the provisioning + of the Arduino boards MKR WiFi 1010 and Nano 33 IoT to + the Arduino IoT Cloud, using the Arduino Cloud API. + + Circuit: + - MKR WiFi 1010 board + - Nano 33 IoT board + + created 14 August 2020 + by Luigi Gubello + + This example code is in the public domain. +*/ + +#include "arduino_secrets.h" +#include "ECCX08TLSConfig.h" +#include "ECCX08Cert.h" +#include +#include +#include + +// from section 10.3.3 of the SAMD datasheet +#define SERIAL_NUMBER_WORD_0 *(volatile uint32_t*)(0x0080A00C) +#define SERIAL_NUMBER_WORD_1 *(volatile uint32_t*)(0x0080A040) +#define SERIAL_NUMBER_WORD_2 *(volatile uint32_t*)(0x0080A044) +#define SERIAL_NUMBER_WORD_3 *(volatile uint32_t*)(0x0080A048) + +const bool DEBUG = true; +const int keySlot = 0; +const int compressedCertSlot = 10; +const int serialNumberAndAuthorityKeyIdentifierSlot = 11; +const int deviceIdSlot = 12; + +char ssid[] = SECRET_SSID; +char pass[] = SECRET_PASS; +char client_id[] = SECRET_CLIENT_ID; +char secret_id[] = SECRET_SECRET_ID; + +#if defined(ARDUINO_SAMD_NANO_33_IOT) + char board_type[] = "nano_33_iot"; // Nano 33 IoT + char board_fqbn[] = "arduino:samd:nano_33_iot"; // Nano 33 IoT +#elif defined(ARDUINO_SAMD_MKRWIFI1010) + char board_type[] = "mkrwifi1010"; // MKR WiFi 1010 + char board_fqbn[] = "arduino:samd:mkrwifi1010"; // MKR WiFi 1010 +#else + char board_type[] = "nonina"; // Not supported boards + char board_fqbn[] = ""; +#endif + +/// Board Info +String board_name = "NewDevice_"; +String ArduinoID; + +String Arduino_Token; +String deviceId; + +String not_before; +String serialNumber; +String authorityKeyIdentifier; +String signature; + +char server[] = "api2.arduino.cc"; // server address + +WiFiSSLClient client; +int status = WL_IDLE_STATUS; + +ECCX08CertClass ECCX08Cert; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (board_type == "nonina") { + Serial.println("Sorry, this sketch only works on Nano 33 IoT and MKR 1010 WiFi"); + while (1) { ; } + } + + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + delay(10000); + } + + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + while (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + delay(100); + } + + if (!ECCX08.locked()) { + + if (!ECCX08.writeConfiguration(DEFAULT_ECCX08_TLS_CONFIG)) { + Serial.println("Writing ECCX08 configuration failed!"); + Serial.println("Stopping Provisioning"); + while (1); + } + + if (!ECCX08.lock()) { + Serial.println("Locking ECCX08 configuration failed!"); + Serial.println("Stopping Provisioning"); + while (1); + } + + Serial.println("ECCX08 locked successfully"); + Serial.println(); + } + + //Random number for device name + board_name += String(ECCX08.random(65535)); + + uint32_t BoardUniqueID[4]; + BoardUniqueID[0] = SERIAL_NUMBER_WORD_0; + BoardUniqueID[1] = SERIAL_NUMBER_WORD_1; + BoardUniqueID[2] = SERIAL_NUMBER_WORD_2; + BoardUniqueID[3] = SERIAL_NUMBER_WORD_3; + uint8_t bid[32]; + for (int i = 0; i < 4; i++) + { + bid[i*4+0] = (uint8_t)(BoardUniqueID[i] >> 24); + bid[i*4+1] = (uint8_t)(BoardUniqueID[i] >> 16); + bid[i*4+2] = (uint8_t)(BoardUniqueID[i] >> 8); + bid[i*4+3] = (uint8_t)(BoardUniqueID[i] >> 0); + } + + for (size_t i = 0; i < 16; i++) { + if (bid[i] < 16) { + ArduinoID += String(0, HEX); + } + ArduinoID += String(bid[i], HEX); + } + ArduinoID.toUpperCase(); + + Serial.print("Device Name: "); + Serial.println(board_name); + // Create Arduino Token + ArduinoToken(client_id, secret_id); + Serial.print("Bearer Token: "); + Serial.println(Arduino_Token); + // Generating Device UUID + BoardUuid(board_name, board_type, board_fqbn, ArduinoID, Arduino_Token); + Serial.print("Device UUID:"); + Serial.println(deviceId); + + delay(2000); + + while (!ECCX08Cert.beginCSR(keySlot, true)) { + Serial.println("Error starting CSR generation!"); + delay(2000); + } + + ECCX08Cert.setSubjectCommonName(deviceId); + + String csr = ECCX08Cert.endCSR(); + + while (!csr) { + Serial.println("Error generating CSR!"); + delay(2000); + } + + Serial.println("Generated CSR is:"); + Serial.println(); + Serial.println(csr); + + // Downloading Arduino cert + ArduinoCertificate(Arduino_Token, deviceId, csr); + + String issueYear = not_before.substring(0,4); + Serial.print("Year: "); + Serial.println(issueYear); + String issueMonth = not_before.substring(5,7); + Serial.print("Month: "); + Serial.println(issueMonth); + String issueDay = not_before.substring(8,10); + Serial.print("Day: "); + Serial.println(issueDay); + String issueHour = not_before.substring(11,13); + Serial.print("Hour: "); + Serial.println(issueHour); + String expireYears = "31"; + Serial.print("Certificate Serial: "); + Serial.println(serialNumber); + Serial.print("Certificate Authority Key: "); + Serial.println(authorityKeyIdentifier); + Serial.print("Certificate Signature: "); + Serial.println(signature); + + byte deviceIdBytes[72]; + byte serialNumberBytes[16]; + byte authorityKeyIdentifierBytes[20]; + byte signatureBytes[64]; + + deviceId.getBytes(deviceIdBytes, sizeof(deviceIdBytes)); + hexStringToBytes(serialNumber, serialNumberBytes, sizeof(serialNumberBytes)); + hexStringToBytes(authorityKeyIdentifier, authorityKeyIdentifierBytes, sizeof(authorityKeyIdentifierBytes)); + hexStringToBytes(signature, signatureBytes, sizeof(signatureBytes)); + + if (!ECCX08.writeSlot(deviceIdSlot, deviceIdBytes, sizeof(deviceIdBytes))) { + Serial.println("Error storing device id!"); + while (1); + } + + if (!ECCX08Cert.beginStorage(compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) { + Serial.println("Error starting ECCX08 storage!"); + while (1); + } + + ECCX08Cert.setSignature(signatureBytes); + ECCX08Cert.setAuthorityKeyIdentifier(authorityKeyIdentifierBytes); + ECCX08Cert.setSerialNumber(serialNumberBytes); + ECCX08Cert.setIssueYear(issueYear.toInt()); + ECCX08Cert.setIssueMonth(issueMonth.toInt()); + ECCX08Cert.setIssueDay(issueDay.toInt()); + ECCX08Cert.setIssueHour(issueHour.toInt()); + ECCX08Cert.setExpireYears(expireYears.toInt()); + + if (!ECCX08Cert.endStorage()) { + Serial.println("Error storing ECCX08 compressed cert!"); + while (1); + } + + if (!ECCX08Cert.beginReconstruction(keySlot, compressedCertSlot, serialNumberAndAuthorityKeyIdentifierSlot)) { + Serial.println("Error starting ECCX08 cert reconstruction!"); + while (1); + } + + ECCX08Cert.setIssuerCountryName("US"); + ECCX08Cert.setIssuerOrganizationName("Arduino LLC US"); + ECCX08Cert.setIssuerOrganizationalUnitName("IT"); + ECCX08Cert.setIssuerCommonName("Arduino"); + + if (!ECCX08Cert.endReconstruction()) { + Serial.println("Error reconstructing ECCX08 compressed cert!"); + while (1); + } + + if (!DEBUG) { + return; + } + + Serial.println("Compressed cert = "); + + const byte* certData = ECCX08Cert.bytes(); + int certLength = ECCX08Cert.length(); + + for (int i = 0; i < certLength; i++) { + byte b = certData[i]; + + if (b < 16) { + Serial.print('0'); + } + Serial.print(b, HEX); + } + Serial.println(); +} + +void loop() { +} + +String promptAndReadLine(const char* prompt) { + Serial.print(prompt); + String s = readLine(); + Serial.println(s); + + return s; +} + +String readLine() { + String line; + + while (1) { + if (Serial.available()) { + char c = Serial.read(); + + if (c == '\r') { + // ignore + } else if (c == '\n') { + break; + } + + line += c; + } + } + + line.trim(); + + return line; +} + +void hexStringToBytes(String& in, byte out[], int length) { + int inLength = in.length(); + in.toUpperCase(); + int outLength = 0; + + for (int i = 0; i < inLength && outLength < length; i += 2) { + char highChar = in[i]; + char lowChar = in[i + 1]; + + byte highByte = (highChar <= '9') ? (highChar - '0') : (highChar + 10 - 'A'); + byte lowByte = (lowChar <= '9') ? (lowChar - '0') : (lowChar + 10 - 'A'); + + out[outLength++] = (highByte << 4) | (lowByte & 0xF); + } +} + +void ArduinoToken(String client_id, String client_secret) { + Serial.println("Creating Bearer Token..."); + String PostData = "grant_type=client_credentials&client_id="; + PostData += client_id; + PostData += "&client_secret="; + PostData += secret_id; + PostData += "&audience=https://api2.arduino.cc/iot"; + + if (client.connect(server, 443)) { + client.println("POST /iot/v1/clients/token HTTP/1.1"); + client.println("Host: api2.arduino.cc"); + client.println("Connection: close"); + client.println("Content-Type: application/x-www-form-urlencoded"); + client.print("Content-Length: "); + client.println(PostData.length()); + client.println(); + client.println(PostData); + } + + while (!client.available()) { + Serial.println("No client"); + delay(2000); + } + + char endOfHeaders[] = "\r\n\r\n"; + if (!client.find(endOfHeaders)) { + Serial.println("Invalid response"); + Serial.println("Error during token generation"); + while (1) { + ; + } + } + + char tokenResponse[1024]; + int intIndex = 0; + while (client.available()) { + tokenResponse[intIndex] = client.read(); + if (tokenResponse[intIndex] == -1) { + break; + } + intIndex++; + } + JSONVar myObject = JSON.parse(tokenResponse); + if (myObject.hasOwnProperty("access_token")) { + Arduino_Token += (const char*) myObject["access_token"]; + } +} + +void BoardUuid(String board_name, String board_type, String board_fqbn, String board_serial, String user_token) { + Serial.println("Adding board to IoT Cloud..."); + String PostData = "{\"fqbn\":\""; + PostData += board_fqbn; + PostData += "\",\"name\":\""; + PostData += board_name; + PostData += "\",\"type\":\""; + PostData += board_type; + PostData += "\",\"serial\":\""; + PostData += board_serial; + PostData += "\"}"; + + if (client.connect(server, 443)) { + client.println("PUT /iot/v2/devices HTTP/1.1"); + client.println("Host: api2.arduino.cc"); + client.println("Connection: close"); + client.println("Content-Type: application/json;charset=UTF-8"); + client.print("Authorization: Bearer "); + client.println(user_token); + client.print("Content-Length: "); + client.println(PostData.length()); + client.println(); + client.println(PostData); + } + + while (!client.available()) { + ; + } + + char endOfHeaders[] = "\r\n\r\n"; + if (!client.find(endOfHeaders)) { + Serial.println("Invalid response"); + Serial.println("Error during Device UUID generation"); + while (1) { + ; + } + } + + char deviceResponse[512]; + int intIndex = 0; + while (client.available()) { + deviceResponse[intIndex] = client.read(); + if (deviceResponse[intIndex] == -1) { + break; + } + intIndex++; + } + JSONVar myObject = JSON.parse(deviceResponse); + if (myObject.hasOwnProperty("id")) { + deviceId += (const char*) myObject["id"]; + } +} + +void ArduinoCertificate(String user_token, String DeviceUuid, String csr) { + Serial.println("Downloading certificate..."); + String url = "/iot/v2/devices/"; + url += DeviceUuid; + url += "/certs"; + + csr.replace("\n", "\\n"); + String PostData = "{\"ca\":\"Arduino\",\"csr\":\""; + PostData += csr; + PostData += "\",\"enabled\":true}"; + + if (client.connect(server, 443)) { + client.print("PUT "); + client.print(url); + client.println(" HTTP/1.1"); + client.println("Host: api2.arduino.cc"); + client.println("Connection: close"); + client.println("Content-Type: application/json;charset=UTF-8"); + client.print("Authorization: Bearer "); + client.println(user_token); + client.print("Content-Length: "); + client.println(PostData.length()); + client.println(); + client.println(PostData); + } + + while (!client.available()) { + ; + } + + char endOfHeaders[] = "\r\n\r\n"; + if (!client.find(endOfHeaders)) { + Serial.println("Invalid response"); + Serial.println("Error during certificate generation"); + while (1) { + ; + } + } + + char certResponse[4096]; + int intIndex = 0; + while (client.available()) { + certResponse[intIndex] = client.read(); + if (certResponse[intIndex] == -1) { + break; + } + intIndex++; + } + JSONVar myObject = JSON.parse(certResponse); + String certZip = JSON.stringify(myObject["compressed"]); + JSONVar myCert = JSON.parse(certZip); + if (myCert.hasOwnProperty("not_before")) { + not_before += (const char*) myCert["not_before"]; + } + if (myCert.hasOwnProperty("serial")) { + serialNumber += (const char*) myCert["serial"]; + } + if (myCert.hasOwnProperty("authority_key_identifier")) { + authorityKeyIdentifier += (const char*) myCert["authority_key_identifier"]; + } + if (myCert.hasOwnProperty("signature_asn1_x")) { + signature += (const char*) myCert["signature_asn1_x"]; + } + if (myCert.hasOwnProperty("signature_asn1_y")) { + signature += (const char*) myCert["signature_asn1_y"]; + } +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/arduino_secrets.h new file mode 100644 index 00000000..cf14c1e1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoIoTCloud/examples/utility/SelfProvisioning/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" +#define SECRET_CLIENT_ID "" +#define SECRET_SECRET_ID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/LICENSE new file mode 100644 index 00000000..19e30718 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +(This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.) + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + {description} + Copyright (C) {year} {fullname} + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + {signature of Ty Coon}, 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/README.md new file mode 100644 index 00000000..55bf63eb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/README.md @@ -0,0 +1,19 @@ +# Arduino Low Power library + +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoLowPower/actions/workflows/spell-check.yml) + +This library allows the use of the low power features of the SAMD21 MCU. This means your battery powered projects will have a longer battery life on boards like [MKRZero](https://store.arduino.cc/usa/arduino-mkrzero), [MKR1000](https://www.arduino.cc/en/Main/ArduinoMKR1000) and [MKRFox1200](https://www.arduino.cc/en/Main/ArduinoBoardMKRFox1200). + +For more information about this library please visit us at + + +# License +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/AdcWakeup/AdcWakeup.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/AdcWakeup/AdcWakeup.ino new file mode 100644 index 00000000..24cafe29 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/AdcWakeup/AdcWakeup.ino @@ -0,0 +1,61 @@ +/* + AdcWakeup + + This sketch demonstrates the usage of the ADC to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, changing the voltage on pin A0 will wake up the board. You can test this by connecting a potentiometer between VCC, A0, and GND. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +// Blink sequence number +// Declare it volatile since it's incremented inside an interrupt +volatile int repetitions = 1; + +// Pin used to trigger a wakeup +const int pin = A0; +// How sensitive to be to changes in voltage +const int margin = 10; + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + pinMode(pin, INPUT); +} + +void loop() { + for (int i = 0; i < repetitions; i++) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } + + // Read the voltage at the ADC pin + int value = analogRead(pin); + + // Define a window around that value + uint16_t lo = max(value - margin, 0); + uint16_t hi = min(value + margin, UINT16_MAX); + + // Attach an ADC interrupt on pin A0, calling repetitionsIncrease when the voltage is outside the given range. + // This should be called immediately before LowPower.sleep() because it reconfigures the ADC internally. + LowPower.attachAdcInterrupt(pin, repetitionsIncrease, ADC_INT_OUTSIDE, lo, hi); + + // Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources) + // The power consumption of the chip will drop consistently + LowPower.sleep(); + + // Detach the ADC interrupt. This should be called immediately after LowPower.sleep() because it restores the ADC configuration after waking up. + LowPower.detachAdcInterrupt(); +} + +void repetitionsIncrease() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context + repetitions ++; +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/ExternalWakeup/ExternalWakeup.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/ExternalWakeup/ExternalWakeup.ino new file mode 100644 index 00000000..61512583 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/ExternalWakeup/ExternalWakeup.ino @@ -0,0 +1,47 @@ +/* + ExternalWakeup + + This sketch demonstrates the usage of External Interrupts (on pins) to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, shorting pin 8 to a GND will wake up the board. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +// Blink sequence number +// Declare it volatile since it's incremented inside an interrupt +volatile int repetitions = 1; + +// Pin used to trigger a wakeup +const int pin = 8; + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + // Set pin 8 as INPUT_PULLUP to avoid spurious wakeup + pinMode(pin, INPUT_PULLUP); + // Attach a wakeup interrupt on pin 8, calling repetitionsIncrease when the device is woken up + LowPower.attachInterruptWakeup(pin, repetitionsIncrease, CHANGE); +} + +void loop() { + for (int i = 0; i < repetitions; i++) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } + // Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources) + // The power consumption of the chip will drop consistently + LowPower.sleep(); +} + +void repetitionsIncrease() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context + repetitions ++; +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/PrimoDeepSleep/PrimoDeepSleep.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/PrimoDeepSleep/PrimoDeepSleep.ino new file mode 100644 index 00000000..702d8a99 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/PrimoDeepSleep/PrimoDeepSleep.ino @@ -0,0 +1,92 @@ +/* + PrimoDeepSleep.ino + + Written by Chiara Ruggeri (chiara@arduino.org) + + This example for the Arduino Primo board shows how to use + Arduino Low Power library to enter in power off mode and save power. + This mode ensures the deepest power saving mode. If you need + a faster response from the board use standby function instead. + + Please note that once exited from the deepest sleep mode the + board will reset (so setup will be run again). + + The functions enableWakeupFrom set the peripheral that will wake up + the board. By calling it more than once you can choose multiple + wakeup sources. + The board will be reset when it wakes up from power off. + You can use wakeUpCause() function to find out what signals woke up + the board if you use more than one wakeUpBy.. function. + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + + +// Pin used to wakeup the board +const int digitalPin = 10; + +// Pin used in Comparator module to wake up the board +const int analogPin = A0; + + +void StmEspPM(bool sleep){ + // enable USER1_BUTTON to turn STM32 off and on when pressed. + // note that when STM32 is off you cannot load any new sketch. + pinMode(USER1_BUTTON, STM32_IT); + + // turn ESP8266 off or on + digitalWrite(GPIO_ESP_PW, sleep ? LOW: HIGH); +} + +void setup() { + Serial.begin(9600); + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + + //look for what peripheral woke up the board + //reason is 0 at the first execution + wakeup_reason reason=LowPower.wakeupReason(); + if(reason==GPIO_WAKEUP) //GPIO caused the wake up + doMyStuff(); + else + if(reason==NFC_WAKEUP) //NFC caused the wake up + doMyStuffWithNFC(); + else + if(reason==ANALOG_COMPARATOR_WAKEUP) //Comparator caused the wake up + doOtherStuff(); + + Serial.println("Hi all, I return to sleep"); + + LowPower.companionLowPowerCallback(StmEspPM); + // Send sleep command to ESP and enable USER1_BUTTON to turn STM off + LowPower.companionSleep(); + + //set digital pin 10 to wake up the board when LOW level is detected + LowPower.enableWakeupFrom(GPIO_WAKEUP, digitalPin, LOW); + //let the board be woken up by any NFC field + LowPower.enableWakeupFrom(NFC_WAKEUP); + //wake up the board when the voltage on pin A0 goes below the voltage on pin AREF + LowPower.enableWakeupFrom(ANALOG_COMPARATOR_WAKEUP, analogPin, AREF, UP); + //go in low power mode. Note that the board will reset once it is woken up + LowPower.deepSleep(); +} + + +void loop() {} + +void doMyStuff(){ + //insert your code here +} + +void doMyStuffWithNFC(){ + //insert your code here +} + +void doOtherStuff(){ + //insert your code here +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/TianStandby/TianStandby.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/TianStandby/TianStandby.ino new file mode 100644 index 00000000..7fc18c48 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/TianStandby/TianStandby.ino @@ -0,0 +1,51 @@ +/* + TianStandby + + This sketch demonstrates the usage of SAMD chip to further reduce the power usage of the Tian + board. This method can be applied to any board with companion chips which expose a method + (via direct pin interrupt or via a command) to enter and exit standby. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered applications can take advantage of these modes to enhance battery life significantly. + + In this sketch, the internal RTC of the SAMD chip will wake up the processor every 20 seconds. + Before going to sleep, the SAMD chip tells the MIPS CPU to standby too. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +#define MIPS_PIN 32 + +void MipsPM(bool sleep) { + pinMode(MIPS_PIN, OUTPUT); + digitalWrite(MIPS_PIN, sleep ? LOW: HIGH); +} + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + LowPower.companionLowPowerCallback(MipsPM); + // Uncomment this function if you wish to attach function dummy when RTC wakes up the chip + LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, onWakeup, CHANGE); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + // Triggers a 2000 ms sleep (the device will be woken up only by the registered wakeup sources and by internal RTC) + // The power consumption of the chip will drop consistently + // Send sleep command to MIPS CPU and then go to sleep + LowPower.companionSleep(); + LowPower.sleep(20000); +} + +void onWakeup() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context + + // Wakeup the companion chip, too + LowPower.companionWakeup(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/TimedWakeup/TimedWakeup.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/TimedWakeup/TimedWakeup.ino new file mode 100644 index 00000000..87075a10 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoLowPower/examples/TimedWakeup/TimedWakeup.ino @@ -0,0 +1,35 @@ +/* + TimedWakeup + + This sketch demonstrates the usage of Internal Interrupts to wakeup a chip in sleep mode. + Sleep modes allow a significant drop in the power usage of a board while it does nothing waiting for an event to happen. Battery powered application can take advantage of these modes to enhance battery life significantly. + + In this sketch, the internal RTC will wake up the processor every 2 seconds. + Please note that, if the processor is sleeping, a new sketch can't be uploaded. To overcome this, manually reset the board (usually with a single or double tap to the RESET button) + + This example code is in the public domain. +*/ + +#include "ArduinoLowPower.h" + +void setup() { + pinMode(LED_BUILTIN, OUTPUT); + // Uncomment this function if you wish to attach function dummy when RTC wakes up the chip + // LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, dummy, CHANGE); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + // Triggers a 2000 ms sleep (the device will be woken up only by the registered wakeup sources and by internal RTC) + // The power consumption of the chip will drop consistently + LowPower.sleep(2000); +} + +void dummy() { + // This function will be called once on device wakeup + // You can do some little operations here (like changing variables which will be used in the loop) + // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/README.adoc new file mode 100644 index 00000000..7221642e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/README.adoc @@ -0,0 +1,41 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: ArduinoModbus + += Modbus Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Use http://www.modbus.org/[Modbus] with your Arduino. + +Using TCP or RS485 shields, like the MKR 485 Shield. This library depends on the ArduinoRS485 library. + +This library is based on https://github.com/stephane/libmodbus[libmodbus], modifications were made to the lower level RS485 and TCP layers to use Arduino Serial/RS485 and Client API's. Then an Arduino friendly API was added on top. + +For more information about this library please visit us at +https://www.arduino.cc/en/ArduinoModbus/ArduinoModbus + +== Useful resources == + +* https://en.wikipedia.org/wiki/Modbus[Modbus - Wikipedia] +* http://www.modbus.org/faq.php[Modbus FAQ] + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientKitchenSink/ModbusRTUClientKitchenSink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientKitchenSink/ModbusRTUClientKitchenSink.ino new file mode 100644 index 00000000..397a382e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientKitchenSink/ModbusRTUClientKitchenSink.ino @@ -0,0 +1,183 @@ +/* + Modbus RTU Client Kitchen Sink + + This sketch creates a Modbus RTU Client and demonstrates + how to use various Modbus Client APIs. + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU server + - Y connected to A/Y of the Modbus RTU server + - Z connected to B/Z of the Modbus RTU server + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to ON + + created 18 July 2018 + by Sandeep Mistry +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +int counter = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("Modbus RTU Client Kitchen Sink"); + + // start the Modbus RTU client + if (!ModbusRTUClient.begin(9600)) { + Serial.println("Failed to start Modbus RTU Client!"); + while (1); + } +} + +void loop() { + writeCoilValues(); + + readCoilValues(); + + readDiscreteInputValues(); + + writeHoldingRegisterValues(); + + readHoldingRegisterValues(); + + readInputRegisterValues(); + + counter++; + + delay(5000); + Serial.println(); +} + +void writeCoilValues() { + // set the coils to 1 when counter is odd + byte coilValue = ((counter % 2) == 0) ? 0x00 : 0x01; + + Serial.print("Writing Coil values ... "); + + // write 10 Coil values to (slave) id 42, address 0x00 + ModbusRTUClient.beginTransmission(42, COILS, 0x00, 10); + for (int i = 0; i < 10; i++) { + ModbusRTUClient.write(coilValue); + } + if (!ModbusRTUClient.endTransmission()) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + } + + // Alternatively, to write a single Coil value use: + // ModbusRTUClient.coilWrite(...) +} + +void readCoilValues() { + Serial.print("Reading Coil values ... "); + + // read 10 Coil values from (slave) id 42, address 0x00 + if (!ModbusRTUClient.requestFrom(42, COILS, 0x00, 10)) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + + while (ModbusRTUClient.available()) { + Serial.print(ModbusRTUClient.read()); + Serial.print(' '); + } + Serial.println(); + } + + // Alternatively, to read a single Coil value use: + // ModbusRTUClient.coilRead(...) +} + +void readDiscreteInputValues() { + Serial.print("Reading Discrete Input values ... "); + + // read 10 Discrete Input values from (slave) id 42, address 0x00 + if (!ModbusRTUClient.requestFrom(42, DISCRETE_INPUTS, 0x00, 10)) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + + while (ModbusRTUClient.available()) { + Serial.print(ModbusRTUClient.read()); + Serial.print(' '); + } + Serial.println(); + } + + // Alternatively, to read a single Discrete Input value use: + // ModbusRTUClient.discreteInputRead(...) +} + +void writeHoldingRegisterValues() { + // set the Holding Register values to counter + + Serial.print("Writing Holding Registers values ... "); + + // write 10 coil values to (slave) id 42, address 0x00 + ModbusRTUClient.beginTransmission(42, HOLDING_REGISTERS, 0x00, 10); + for (int i = 0; i < 10; i++) { + ModbusRTUClient.write(counter); + } + if (!ModbusRTUClient.endTransmission()) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + } + + // Alternatively, to write a single Holding Register value use: + // ModbusRTUClient.holdingRegisterWrite(...) +} + +void readHoldingRegisterValues() { + Serial.print("Reading Input Register values ... "); + + // read 10 Input Register values from (slave) id 42, address 0x00 + if (!ModbusRTUClient.requestFrom(42, HOLDING_REGISTERS, 0x00, 10)) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + + while (ModbusRTUClient.available()) { + Serial.print(ModbusRTUClient.read()); + Serial.print(' '); + } + Serial.println(); + } + + // Alternatively, to read a single Holding Register value use: + // ModbusRTUClient.holdingRegisterRead(...) +} + +void readInputRegisterValues() { + Serial.print("Reading input register values ... "); + + // read 10 discrete input values from (slave) id 42, + if (!ModbusRTUClient.requestFrom(42, INPUT_REGISTERS, 0x00, 10)) { + Serial.print("failed! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + Serial.println("success"); + + while (ModbusRTUClient.available()) { + Serial.print(ModbusRTUClient.read()); + Serial.print(' '); + } + Serial.println(); + } + + // Alternatively, to read a single Input Register value use: + // ModbusRTUClient.inputRegisterRead(...) +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientToggle/ModbusRTUClientToggle.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientToggle/ModbusRTUClientToggle.ino new file mode 100644 index 00000000..266bd164 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUClientToggle/ModbusRTUClientToggle.ino @@ -0,0 +1,55 @@ +/* + Modbus RTU Client Toggle + + This sketch toggles the coil of a Modbus RTU server connected via RS485 + on and off every second. + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU server + - Y connected to A/Y of the Modbus RTU server + - Z connected to B/Z of the Modbus RTU server + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to ON + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("Modbus RTU Client Toggle"); + + // start the Modbus RTU client + if (!ModbusRTUClient.begin(9600)) { + Serial.println("Failed to start Modbus RTU Client!"); + while (1); + } +} + +void loop() { + // for (slave) id 1: write the value of 0x01, to the coil at address 0x00 + if (!ModbusRTUClient.coilWrite(1, 0x00, 0x01)) { + Serial.print("Failed to write coil! "); + Serial.println(ModbusRTUClient.lastError()); + } + + // wait for 1 second + delay(1000); + + // for (slave) id 1: write the value of 0x00, to the coil at address 0x00 + if (!ModbusRTUClient.coilWrite(1, 0x00, 0x00)) { + Serial.print("Failed to write coil! "); + Serial.println(ModbusRTUClient.lastError()); + } + + // wait for 1 second + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerKitchenSink/ModbusRTUServerKitchenSink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerKitchenSink/ModbusRTUServerKitchenSink.ino new file mode 100644 index 00000000..832f05b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerKitchenSink/ModbusRTUServerKitchenSink.ino @@ -0,0 +1,71 @@ +/* + Modbus RTU Server Kitchen Sink + + This sketch creates a Modbus RTU Server and demonstrates + how to use various Modbus Server APIs. + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU server + - Y connected to A/Y of the Modbus RTU client + - Z connected to B/Z of the Modbus RTU client + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to OFF + + created 18 July 2018 + by Sandeep Mistry +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +const int numCoils = 10; +const int numDiscreteInputs = 10; +const int numHoldingRegisters = 10; +const int numInputRegisters = 10; + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("Modbus RTU Server Kitchen Sink"); + + // start the Modbus RTU server, with (slave) id 42 + if (!ModbusRTUServer.begin(42, 9600)) { + Serial.println("Failed to start Modbus RTU Server!"); + while (1); + } + + // configure coils at address 0x00 + ModbusRTUServer.configureCoils(0x00, numCoils); + + // configure discrete inputs at address 0x00 + ModbusRTUServer.configureDiscreteInputs(0x00, numDiscreteInputs); + + // configure holding registers at address 0x00 + ModbusRTUServer.configureHoldingRegisters(0x00, numHoldingRegisters); + + // configure input registers at address 0x00 + ModbusRTUServer.configureInputRegisters(0x00, numInputRegisters); +} + +void loop() { + // poll for Modbus RTU requests + ModbusRTUServer.poll(); + + // map the coil values to the discrete input values + for (int i = 0; i < numCoils; i++) { + int coilValue = ModbusRTUServer.coilRead(i); + + ModbusRTUServer.discreteInputWrite(i, coilValue); + } + + // map the holding register values to the input register values + for (int i = 0; i < numHoldingRegisters; i++) { + long holdingRegisterValue = ModbusRTUServer.holdingRegisterRead(i); + + ModbusRTUServer.inputRegisterWrite(i, holdingRegisterValue); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerLED/ModbusRTUServerLED.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerLED/ModbusRTUServerLED.ino new file mode 100644 index 00000000..07a059bb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUServerLED/ModbusRTUServerLED.ino @@ -0,0 +1,61 @@ +/* + Modbus RTU Server LED + + This sketch creates a Modbus RTU Server with a simulated coil. + The value of the simulated coil is set on the LED + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU server + - Y connected to A/Y of the Modbus RTU client + - Z connected to B/Z of the Modbus RTU client + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to OFF + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +const int ledPin = LED_BUILTIN; + +void setup() { + Serial.begin(9600); + + Serial.println("Modbus RTU Server LED"); + + // start the Modbus RTU server, with (slave) id 1 + if (!ModbusRTUServer.begin(1, 9600)) { + Serial.println("Failed to start Modbus RTU Server!"); + while (1); + } + + // configure the LED + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, LOW); + + // configure a single coil at address 0x00 + ModbusRTUServer.configureCoils(0x00, 1); +} + +void loop() { + // poll for Modbus RTU requests + int packetReceived = ModbusRTUServer.poll(); + + if(packetReceived) { + // read the current value of the coil + int coilValue = ModbusRTUServer.coilRead(0x00); + + if (coilValue) { + // coil value set, turn LED on + digitalWrite(ledPin, HIGH); + } else { + // coil value clear, turn LED off + digitalWrite(ledPin, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUTemperatureSensor/ModbusRTUTemperatureSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUTemperatureSensor/ModbusRTUTemperatureSensor.ino new file mode 100644 index 00000000..323e55ab --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/RTU/ModbusRTUTemperatureSensor/ModbusRTUTemperatureSensor.ino @@ -0,0 +1,65 @@ +/* + Modbus RTU Temperature Sensor + + This sketch shows you how to interact with a Modbus RTU temperature and humidity sensor. + It reads the temperature and humidity values every 5 seconds and outputs them to the + serial monitor. + + Circuit: + - MKR board + - Winners® Modbus RS485 Temperature and Humidity: + https://www.banggood.com/Modbus-RS485-Temperature-and-Humidity-Transmitter-Sensor-High-Precision-Monitoring-p-1159961.html?cur_warehouse=CN + - External 9-36 V power Supply + - MKR 485 shield + - ISO GND connected to GND of the Modbus RTU sensor and the Power supply V- + - Power supply V+ connected to V+ sensor + - Y connected to A/Y of the Modbus RTU sensor + - Z connected to B/Z of the Modbus RTU sensor + - Jumper positions + - FULL set to OFF + - Z \/\/ Y set to ON + + created 8 August 2018 + by Riccardo Rizzo +*/ + +#include + +float temperature; +float humidity; + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("Modbus Temperature Humidity Sensor"); + // start the Modbus RTU client + if (!ModbusRTUClient.begin(9600)) { + Serial.println("Failed to start Modbus RTU Client!"); + while (1); + } +} + +void loop() { + + // send a Holding registers read request to (slave) id 1, for 2 registers + if (!ModbusRTUClient.requestFrom(1, HOLDING_REGISTERS, 0x00, 2)) { + Serial.print("failed to read registers! "); + Serial.println(ModbusRTUClient.lastError()); + } else { + // If the request succeeds, the sensor sends the readings, that are + // stored in the holding registers. The read() method can be used to + // get the raw temperature and the humidity values. + short rawtemperature = ModbusRTUClient.read(); + short rawhumidity = ModbusRTUClient.read(); + + // To get the temperature in Celsius and the humidity reading as + // a percentage, divide the raw value by 10.0. + temperature = rawtemperature / 10.0; + humidity = rawhumidity / 10.0; + Serial.println(temperature); + Serial.println(humidity); + } + + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusClientToggle/EthernetModbusClientToggle.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusClientToggle/EthernetModbusClientToggle.ino new file mode 100644 index 00000000..a15ae116 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusClientToggle/EthernetModbusClientToggle.ino @@ -0,0 +1,87 @@ +/* + Ethernet Modbus TCP Client Toggle + + This sketch toggles the coil of a Modbus TCP server connected + on and off every second. + + Circuit: + - Any Arduino MKR Board + - MKR ETH Shield + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include +#include + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +EthernetClient ethClient; +ModbusTCPClient modbusTCPClient(ethClient); + +IPAddress server(192, 168, 1, 10); // update with the IP Address of your Modbus server + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection and the server: + Ethernet.begin(mac, ip); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } +} + +void loop() { + if (!modbusTCPClient.connected()) { + // client not connected, start the Modbus TCP client + Serial.println("Attempting to connect to Modbus TCP server"); + + if (!modbusTCPClient.begin(server, 502)) { + Serial.println("Modbus TCP Client failed to connect!"); + } else { + Serial.println("Modbus TCP Client connected"); + } + } else { + // client connected + + // write the value of 0x01, to the coil at address 0x00 + if (!modbusTCPClient.coilWrite(0x00, 0x01)) { + Serial.print("Failed to write coil! "); + Serial.println(modbusTCPClient.lastError()); + } + + // wait for 1 second + delay(1000); + + // write the value of 0x00, to the coil at address 0x00 + if (!modbusTCPClient.coilWrite(0x00, 0x00)) { + Serial.print("Failed to write coil! "); + Serial.println(modbusTCPClient.lastError()); + } + + // wait for 1 second + delay(1000); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino new file mode 100644 index 00000000..bedc2b72 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/EthernetModbusServerLED/EthernetModbusServerLED.ino @@ -0,0 +1,116 @@ +/* + Ethernet Modbus TCP Server LED + + This sketch creates a Modbus TCP Server with a simulated coil. + The value of the simulated coil is set on the LED + + Circuit: + - Any Arduino MKR Board + - MKR ETH Shield + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include +#include + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +EthernetServer ethServer(502); + +ModbusTCPServer modbusTCPServer; + +const int ledPin = LED_BUILTIN; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.println("Ethernet Modbus TCP Example"); + + // start the Ethernet connection and the server: + Ethernet.begin(mac, ip); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start the server + ethServer.begin(); + + // start the Modbus TCP server + if (!modbusTCPServer.begin()) { + Serial.println("Failed to start Modbus TCP Server!"); + while (1); + } + + // configure the LED + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, LOW); + + // configure a single coil at address 0x00 + modbusTCPServer.configureCoils(0x00, 1); +} + +void loop() { + // listen for incoming clients + EthernetClient client = ethServer.available(); + + if (client) { + // a new client connected + Serial.println("new client"); + + // let the Modbus TCP accept the connection + modbusTCPServer.accept(client); + + while (client.connected()) { + // poll for Modbus TCP requests, while client connected + modbusTCPServer.poll(); + + // update the LED + updateLED(); + } + + Serial.println("client disconnected"); + } +} + +void updateLED() { + // read the current value of the coil + int coilValue = modbusTCPServer.coilRead(0x00); + + if (coilValue) { + // coil value set, turn LED on + digitalWrite(ledPin, HIGH); + } else { + // coild value clear, turn LED off + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino new file mode 100644 index 00000000..0322c895 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/WiFiModbusClientToggle.ino @@ -0,0 +1,106 @@ +/* + WiFi Modbus TCP Client Toggle + + This sketch toggles the coil of a Modbus TCP server connected + on and off every second. + + Circuit: + - MKR1000 or MKR WiFi 1010 board + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include +#include // for MKR WiFi 1010 +// #include // for MKR1000 + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiClient wifiClient; +ModbusTCPClient modbusTCPClient(wifiClient); + +IPAddress server(192, 168, 1, 10); // update with the IP Address of your Modbus server + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Modbus TCP Client Toggle"); + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + if (!modbusTCPClient.connected()) { + // client not connected, start the Modbus TCP client + Serial.println("Attempting to connect to Modbus TCP server"); + + if (!modbusTCPClient.begin(server)) { + Serial.println("Modbus TCP Client failed to connect!"); + } else { + Serial.println("Modbus TCP Client connected"); + } + } else { + // client connected + + // write the value of 0x01, to the coil at address 0x00 + if (!modbusTCPClient.coilWrite(0x00, 0x01)) { + Serial.print("Failed to write coil! "); + Serial.println(modbusTCPClient.lastError()); + } + + // wait for 1 second + delay(1000); + + // write the value of 0x00, to the coil at address 0x00 + if (!modbusTCPClient.coilWrite(0x00, 0x00)) { + Serial.print("Failed to write coil! "); + Serial.println(modbusTCPClient.lastError()); + } + + // wait for 1 second + delay(1000); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusClientToggle/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino new file mode 100644 index 00000000..60276c09 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/WiFiModbusServerLED.ino @@ -0,0 +1,126 @@ +/* + WiFi Modbus TCP Server LED + + This sketch creates a Modbus TCP Server with a simulated coil. + The value of the simulated coil is set on the LED + + Circuit: + - MKR1000 or MKR WiFi 1010 board + + created 16 July 2018 + by Sandeep Mistry +*/ + +#include +#include // for MKR WiFi 1010 +// #include // for MKR1000 + +#include // ArduinoModbus depends on the ArduinoRS485 library +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +const int ledPin = LED_BUILTIN; + +int status = WL_IDLE_STATUS; + +WiFiServer wifiServer(502); + +ModbusTCPServer modbusTCPServer; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Modbus TCP Server LED"); + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the status: + printWifiStatus(); + + // start the server + wifiServer.begin(); + + // start the Modbus TCP server + if (!modbusTCPServer.begin()) { + Serial.println("Failed to start Modbus TCP Server!"); + while (1); + } + + // configure the LED + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, LOW); + + // configure a single coil at address 0x00 + modbusTCPServer.configureCoils(0x00, 1); +} + +void loop() { + // listen for incoming clients + WiFiClient client = wifiServer.available(); + + if (client) { + // a new client connected + Serial.println("new client"); + + // let the Modbus TCP accept the connection + modbusTCPServer.accept(client); + + while (client.connected()) { + // poll for Modbus TCP requests, while client connected + modbusTCPServer.poll(); + + // update the LED + updateLED(); + } + + Serial.println("client disconnected"); + } +} + +void updateLED() { + // read the current value of the coil + int coilValue = modbusTCPServer.coilRead(0x00); + + if (coilValue) { + // coil value set, turn LED on + digitalWrite(ledPin, HIGH); + } else { + // coild value clear, turn LED off + digitalWrite(ledPin, LOW); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoModbus/examples/TCP/WiFiModbusServerLED/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/LICENSE new file mode 100644 index 00000000..65c5ca88 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/README.md new file mode 100644 index 00000000..3ae26f16 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/README.md @@ -0,0 +1,19 @@ +# ArduinoMotorCarrier library + +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoMotorCarrier/actions/workflows/spell-check.yml) + +This library is designed to use the MKR Motor Carrier. The shield supports micro servo motors, DC motors and DC motors with encoder. This library, therefore, has functions and creates objects to support such hardware. Objects are automatically created when "ArduinoMotorCarrier.h" is included, hence no need to initiate objects manually. + +For more information about this library please visit us at + + +# License +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Flasher/Flasher.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Flasher/Flasher.ino new file mode 100644 index 00000000..3413ebc8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Flasher/Flasher.ino @@ -0,0 +1,131 @@ +/* + STANDALONE FIRMWARE UPDATE FOR Arduino Motor Carrier + + To generate a new firmware, compile D11-Firmware with target MKRMotorShield, 4KB bootloader, LTO enabled, pinmap complete + and execute + + echo -n "const " > fw.h && xxd -i D11-Firmware.ino.bin >> fw.h +*/ + +#include "Wire.h" +#include "ArduinoMotorCarrier.h" + +#ifdef ARDUINO_SAMD_NANO_33_IOT +#include "fw_nano.h" +#else +#include "fw_mkr.h" +#endif + +#define I2C_ADDRESS 0x09 + +void setDataRunning(int cmd, uint8_t target, int data) { + Wire.beginTransmission(0x66); + Wire.write((uint8_t)cmd); + Wire.write((uint8_t)target); + Wire.write(data); + Wire.endTransmission(); +} + + +void setup() { + // put your setup code here, to run once: + Wire.begin(); + Wire.setClock(1000000); + + Serial.begin(115200); + while (!Serial); + pinMode(6, OUTPUT); + digitalWrite(6, HIGH); + + int prev_address = -1; + + Wire.beginTransmission(0x66); + Wire.write((uint8_t)GET_VERSION); + Wire.write((uint8_t)0); + Wire.endTransmission(); + + Wire.requestFrom(0x66, 5); + Wire.read(); + + String version = ""; + + while (Wire.available()) { + version += (char)Wire.read(); + } + + if (version.c_str()[0] == '0') { + Serial.println("Reset D11"); + setDataRunning(RESET, 0, 0); + delay(10); + } else { + // TODO: on NanoMotorCarrier we have the change to forcefully reset the D11; do it now if it is unresponsive + + } + + // reset running D11 + Serial.println("Erase flash"); + + Wire.beginTransmission(I2C_ADDRESS); + Wire.write('r'); + Wire.endTransmission(); + + delay(500); + + Serial.println("Starting flash"); + + int address = 0; + while (address < (D11_Firmware_ino_bin_len + 0x1000)) { + int retry = 0; + do { + Wire.requestFrom(I2C_ADDRESS, 4); + uint8_t buf[4]; + int k = 0; + while (Wire.available()) { + buf[k++] = Wire.read(); + } + address = *(uint32_t*)buf; + delay(10); + } while (prev_address == address && retry++ < 5); + prev_address = address; + Serial.println(address); + + uint8_t crc = 0; + for (int j = 0; j < 64; j++) { + crc ^= D11_Firmware_ino_bin[address - 0x1000 + j]; + } + + Serial.println(crc, HEX); + + Wire.beginTransmission(I2C_ADDRESS); + Wire.write('w'); + Wire.write(crc); + Wire.write(&D11_Firmware_ino_bin[address - 0x1000], 64); + Wire.endTransmission(); + } + + Serial.println("Booting FW"); + Wire.beginTransmission(I2C_ADDRESS); + Wire.write('x'); + Wire.endTransmission(); + + delay(1000); + + Wire.beginTransmission(0x66); + Wire.write((uint8_t)GET_VERSION); + Wire.write((uint32_t)0); + Wire.endTransmission(); + + Wire.requestFrom(0x66, 5); + Wire.read(); + + Serial.print("New version: "); + while (Wire.available()) { + Serial.print((char)Wire.read()); + } + Serial.println(); +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test/Motor_test.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test/Motor_test.ino new file mode 100644 index 00000000..4a150811 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test/Motor_test.ino @@ -0,0 +1,92 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = 0; + +void setup() +{ + //Serial port initialization + Serial.begin(115200); + while (!Serial); + + //Establishing the communication with the Motor Carrier + if (controller.begin()) + { + Serial.print("MKR Motor Connected connected, firmware version "); + Serial.println(controller.getFWVersion()); + } + else + { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); +} + + +void loop() { + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + + //Reset to the default values if the battery level is lower than 11 V + if (batteryVoltage < 11) + { + Serial.println(" "); + Serial.println("WARNING: LOW BATTERY"); + Serial.println("ALL SYSTEMS DOWN"); + M1.setDuty(0); + M2.setDuty(0); + M3.setDuty(0); + M4.setDuty(0); + while (batteryVoltage < 11) + { + batteryVoltage = (float)battery.getConverted(); + } + } + else + { + //Motor test + for (duty=-100; duty<100; duty+=5) + { + Serial.print("Motor Duty: "); + Serial.println(duty); + M1.setDuty(duty); + M2.setDuty(duty); + M3.setDuty(duty); + M4.setDuty(duty); + delay(50); + } + for (duty=100; duty>-100; duty-=5) + { + Serial.print("Motor Duty: "); + Serial.println(duty); + M1.setDuty(duty); + M2.setDuty(duty); + M3.setDuty(duty); + M4.setDuty(duty); + delay(50); + } + + //Keep active the communication between MKR board & MKR Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test_encoder/Motor_test_encoder.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test_encoder/Motor_test_encoder.ino new file mode 100644 index 00000000..4b267e48 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Motor_test_encoder/Motor_test_encoder.ino @@ -0,0 +1,86 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = -20; + +void setup() +{ + //Serial port initialization + Serial.begin(115200); + while (!Serial); + + //Establishing the communication with the Motor Carrier + if (controller.begin()) + { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } + else + { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + // Reset the encoder internal counter to zero (can be set to any initial value) + Serial.println("reset counters"); + encoder1.resetCounter(0); + encoder2.resetCounter(0); + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); +} + + +void loop() { + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + + //Reset to the default values if the battery level is lower than 11 V + if (batteryVoltage < 11) + { + Serial.println(" "); + Serial.println("WARNING: LOW BATTERY"); + Serial.println("ALL SYSTEMS DOWN"); + M1.setDuty(0); + M2.setDuty(0); + M3.setDuty(0); + M4.setDuty(0); + while (batteryVoltage < 11) + { + batteryVoltage = (float)battery.getConverted(); + } + } + else + { + //Chose the motor to use:M1(default), M2, M3 or M4 + Serial.print("M1 Duty: "); + Serial.println(duty); + M1.setDuty(duty); + + //Chose the encoder to use:encoder1(default) or encoder2 + Serial.print("Encoder1 Pos [counts]: "); + Serial.println(encoder1.getRawCount()); + Serial.print("Encoder1 vel [counts/sec]: "); + Serial.println(encoder1.getCountPerSecond()); + } + + //Keep active the communication between MKR board & MKR Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Servo_test/Servo_test.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Servo_test/Servo_test.ino new file mode 100644 index 00000000..8ada2df7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Servo_test/Servo_test.ino @@ -0,0 +1,84 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +int batteryVoltage; + +void setup() +{ + //Serial port initialization + Serial.begin(115200); + while (!Serial); + + //Establishing the communication with the Motor Carrier + if (controller.begin()) + { + Serial.print("MKR Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } + else + { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); +} + + +void loop() { + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + + //Reset to the default values if the battery level is lower than 11 V + if (batteryVoltage < 11) + { + Serial.println(" "); + Serial.println("WARNING: LOW BATTERY"); + Serial.println("ALL SYSTEMS DOWN"); + while (batteryVoltage < 11) { + batteryVoltage = (float)battery.getConverted(); + } + } + else + { + //Servo sweep from 0 position to 180 + for (int i=0; i<180; i+=5) + { + //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + servo1.setAngle(i); + Serial.print("Servo position"); + Serial.println(i); + delay(50); + } + + delay(200); + + //Servo sweep from 180 position to 0 + for (int i=180; i>0; i-=5) + { + //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + servo1.setAngle(i); + Serial.print("Servo position"); + Serial.println(i); + delay(50); + } + } + + //Keep active the communication between MKR board & MKR Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Test/Test.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Test/Test.ino new file mode 100644 index 00000000..71e107d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/MKR/Test/Test.ino @@ -0,0 +1,59 @@ +/* + MKR Motor Carrier Test sketch + This sketch demonstrates some APIs exposed by the ArduinoMotorCarrier library. + For the complete list, visit the reference page on https://www.arduino.cc/en/Reference/MKRMotorCarrier + This example code is in the public domain. +*/ + +#include "ArduinoMotorCarrier.h" + +void setup() { + + Serial.begin(115200); + while (!Serial); + + // Start communication with the Motor Carrier + if (controller.begin()) { + Serial.print("MKR Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } else { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } + + // Reboot the motor controller; brings every value back to default + controller.reboot(); + + Serial.println(controller.getFreeRam()); + + // Reset the encoder internal counter to zero (can be set to any initial value) + encoder1.resetCounter(0); + + // Start DC Motor 1 (labeled M1) with 90% of maximum speed, clockwise + M1.setDuty(90); + + // Read the encoder connected to Motor1 until it reaches 36000 counts + int motor1Pos = 0; + while (motor1Pos < 36000) { + motor1Pos = encoder1.getRawCount(); + // Remember to call ping() here and there! + // If you forget to do so the controller will think that the user sketch is not running and will freeze. + // You can wait up to 3 seconds between pings before the reset kicks in + controller.ping(); + } + + // Switch motor control from DIRECT to PID-driven. + // This way, you can program the motor to reach a certain position or velocity without any further intervention. + // The PID can be carefully tuned if a particular profile is needed. + pid1.setControlMode(CL_POSITION); + pid1.setGains(25, 0, 3); + pid1.setMaxAcceleration(4000); + pid1.setSetpoint(TARGET_POSITION, 5000); +} + +void loop() { + // Simply print the actual position while the PID is running, pinging the controller every loop() + Serial.println(encoder1.getRawCount()); + controller.ping(); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/Battery_Charging/Battery_Charging.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/Battery_Charging/Battery_Charging.ino new file mode 100644 index 00000000..cf9e9219 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/Battery_Charging/Battery_Charging.ino @@ -0,0 +1,35 @@ + +#include + +//Variable to store the battery voltage +float batteryVoltage; + +// the setup function runs once when you press reset or power the board +void setup() { + Serial.begin(115200); + //while (!Serial); + + if (controller.begin()) + { + Serial.print("Nano Motor Shield connected, firmware version "); + Serial.println(controller.getFWVersion()); + } + else + { + Serial.println("Couldn't connect! Is the red led blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } +} + +// the loop function runs over and over again forever +void loop() { + + batteryVoltage = battery.getRaw()/236.0; + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage,3); + //Serial.println("V"); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); + delay(5000); //wait for a few seconds + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/DCMotorTest/DCMotorTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/DCMotorTest/DCMotorTest.ino new file mode 100644 index 00000000..9d517c27 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/DCMotorTest/DCMotorTest.ino @@ -0,0 +1,97 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = 0; + +void setup() +{ + //Serial port initialization + Serial.begin(115200); + //while (!Serial); + + //Establishing the communication with the Motor Carrier + if (controller.begin()) + { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } + else + { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + int dutyInit = 0; // at 50 it works as expected, at 60 shift sides and is too small duty to move, at 70 is very big duty. + M1.setDuty(dutyInit); + M2.setDuty(dutyInit); + M3.setDuty(dutyInit); + M4.setDuty(dutyInit); + Serial.print("Duty init: "); + Serial.println(dutyInit); + // int duty2 = dutyInit * 16777215 / 100; + // Serial.print("Conversion formula: "); + // Serial.println(duty2); + //while (1); //WHILE 1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! REMOVE!!!! +} + + +void loop() { + + //Take the battery status + //float batteryVoltage = (float)battery.getConverted(); + + //Reset to the default values if the battery level is lower than 11 V + // if (batteryVoltage < 11) + // { + // Serial.println(" "); + // Serial.println("WARNING: LOW BATTERY"); + // Serial.println("ALL SYSTEMS DOWN"); + // M1.setDuty(0); + // M2.setDuty(0); + // M3.setDuty(0); + // M4.setDuty(0); + // while (batteryVoltage < 11) + // { + // batteryVoltage = (float)battery.getConverted(); + // } + // } + // else + // { + + //Motor test + for (duty = -100; duty < 100; duty += 1) + { + Serial.print("Motor Duty: "); + Serial.println(duty); + M1.setDuty(duty); + M2.setDuty(duty); + M3.setDuty(duty); + M4.setDuty(duty); + delay(10); + } + for (duty = 100; duty > -100; duty -= 1) + { + Serial.print("Motor Duty: "); + Serial.println(duty); + M1.setDuty(duty); + M2.setDuty(duty); + M3.setDuty(duty); + M4.setDuty(duty); + delay(10); + } + + //Keep active the communication between Nano & Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/EncoderTest/EncoderTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/EncoderTest/EncoderTest.ino new file mode 100644 index 00000000..eef1c632 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/EncoderTest/EncoderTest.ino @@ -0,0 +1,63 @@ +#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = 0; + +void setup() +{ + //Establishing the communication with the Motor Carrier + if (controller.begin()) + { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } + else + { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } + + //Serial port initialization + Serial.begin(115200); + while (!Serial); + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + // Reset the encoder internal counter to zero (can be set to any initial value) + Serial.println("reset counters"); + encoder1.resetCounter(0); + encoder2.resetCounter(0); + + M1.setDuty(30); + M2.setDuty(30); + M3.setDuty(30); + M4.setDuty(30); +} + + +void loop() { + + //Chose the encoder to use:encoder1(default) or encoder2 + Serial.print("Encoder1 Pos [counts]: "); + Serial.print(encoder1.getRawCount()); + Serial.print(" Encoder1 vel [counts/sec]: "); + Serial.println(encoder1.getCountPerSecond()); + Serial.print("Encoder2 Pos [counts]: "); + Serial.print(encoder2.getRawCount()); + Serial.print(" Encoder2 vel [counts/sec]: "); + Serial.println(encoder2.getCountPerSecond()); + Serial.println(""); + + //Keep active the communication between Nano & Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/IMU_Test/IMU_Test.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/IMU_Test/IMU_Test.ino new file mode 100644 index 00000000..9801f09f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/IMU_Test/IMU_Test.ino @@ -0,0 +1,89 @@ +/* + *************************************************************************** + + Euler_Streaming.pde - part of sample SW for using BNO055 with Arduino + + (C) All rights reserved by ROBERT BOSCH GMBH + + Copyright (C) 2014 Bosch Sensortec GmbH + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + **************************************************************************/ +/* Date: 2014/01/07 + Revision: 1.2 + +*/ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* bno055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if ((millis() - lastTime) >= 100) //To stream at 10 Hz without using additional timers + { + lastTime = millis(); + + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p) / 16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/PID_Position_test/PID_Position_test.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/PID_Position_test/PID_Position_test.ino new file mode 100644 index 00000000..3dc65f62 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/PID_Position_test/PID_Position_test.ino @@ -0,0 +1,127 @@ +#include +//#include +#define INTERRUPT_PIN 6 + +//Variable to store the battery voltage +static int batteryVoltage; + +//Variable to change the motor speed and direction +static int duty = 0; + +int target; + +void setup() +{ + //Serial port initialization + Serial.begin(115200); + while (!Serial); + + //Establishing the communication with the Motor Carrier + if (controller.begin()) + { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } + else + { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + //Take the battery status + float batteryVoltage = (float)battery.getConverted(); + Serial.print("Battery voltage: "); + Serial.print(batteryVoltage); + Serial.print("V, Raw "); + Serial.println(battery.getRaw()); + + int dutyInit = 0; // at 50 it works as expected, at 60 shift sides and is too small duty to move, at 70 is very big duty. + M1.setDuty(dutyInit); + M2.setDuty(dutyInit); + M3.setDuty(dutyInit); + M4.setDuty(dutyInit); + Serial.print("Duty: "); + Serial.println(dutyInit); + + /************* PID 1 ***********************/ + +// pid1.setControlMode(CL_POSITION); +// +// //pid1.resetGains(); +// //pid1.setLimits(-100,100); +// pid1.setGains(0.01f, 0.017f, 0.0f); //Proportional(change) Integral(change) Derivative +// Serial.print("P Gain: "); +// Serial.println((float)pid1.getPgain()); +// Serial.print("I Gain: "); +// Serial.println((float)pid1.getIgain()); +// Serial.print("D Gain: "); +// Serial.println((float)pid1.getDgain(), 7); +// Serial.println(""); +// +// encoder1.resetCounter(0); +// Serial.print("encoder1: "); +// Serial.println(encoder1.getRawCount()); +// target = 1000; +// pid1.setSetpoint(TARGET_POSITION, target); + + /************* PID 2 ***********************/ + + pid2.setControlMode(CL_POSITION); + + //pid1.resetGains(); + //pid1.setLimits(-100,100); + pid2.setGains(0.1f, 0.0f, 0.0f); //Proportional(change) Integral(change) Derivative + Serial.print("P Gain: "); + Serial.println((float)pid2.getPgain()); + Serial.print("I Gain: "); + Serial.println((float)pid2.getIgain()); + Serial.print("D Gain: "); + Serial.println((float)pid2.getDgain(), 7); + Serial.println(""); + + encoder2.resetCounter(0); + Serial.print("encoder2: "); + Serial.println(encoder2.getRawCount()); + target = 1000; + pid2.setSetpoint(TARGET_POSITION, target); + +} + +void loop() { + + /************* PID 1 ***********************/ + +// Serial.print("encoder1: "); +// Serial.print(encoder1.getRawCount()); +// Serial.print(" target: "); +// Serial.println(target); +// if (encoder1.getRawCount() == target) { +// target += 1000; +// Serial.print("Target reached: Setting new target.."); +// pid1.setSetpoint(TARGET_POSITION, target); +// //delay(5000); +// } + + /************* PID 2 ***********************/ + + Serial.print("encoder2: "); + Serial.print(encoder2.getRawCount()); + Serial.print(" target: "); + Serial.println(target); + if (encoder2.getRawCount() == target) { + target += 1000; + Serial.print("Target reached: Setting new target.."); + pid2.setSetpoint(TARGET_POSITION, target); + //delay(5000); + } + + //--------------------------------------- + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/ServoTest/ServoTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/ServoTest/ServoTest.ino new file mode 100644 index 00000000..caf21fcb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMotorCarrier/examples/Nano/ServoTest/ServoTest.ino @@ -0,0 +1,77 @@ +#include +#include +//#include +//#include +#define INTERRUPT_PIN 6 + + +void setup() +{ + //Serial port initialization + Serial.begin(115200); + //while (!Serial); + + //Establishing the communication with the Motor Carrier + if (controller.begin()) + { + Serial.print("Motor Carrier connected, firmware version "); + Serial.println(controller.getFWVersion()); + } + else + { + Serial.println("Couldn't connect! Is the red LED blinking? You may need to update the firmware with FWUpdater sketch"); + while (1); + } + + // Reboot the motor controller; brings every value back to default + Serial.println("reboot"); + controller.reboot(); + delay(500); + + M1.setDuty(0); + M2.setDuty(0); + M3.setDuty(0); + M4.setDuty(0); + + if (!PMIC.enableBoostMode()) { + Serial.println("Error enabling Boost Mode"); + } +} + +void loop() { + + //Servo sweep from 0 position to 180 + for (int i = 0; i < 180; i += 1) + { + //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + servo1.setAngle(i); + servo2.setAngle(i); + servo3.setAngle(i); + servo4.setAngle(i); + Serial.print("Servos position"); + Serial.println(i); + delay(20); + } + + delay(200); + + //Servo sweep from 180 position to 0 + for (int i = 180; i > 0; i -= 1) + { + //Choose which of the servo connectors you want to use: servo1(default), servo2, servo3 or servo4 + servo1.setAngle(i); + servo2.setAngle(i); + servo3.setAngle(i); + servo4.setAngle(i); + Serial.print("Servos position: "); + Serial.println(i); + delay(20); + } + + + //Keep active the communication between MKR board & MKR Motor Carrier + //Ping the SAMD11 + controller.ping(); + //wait + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/README.adoc new file mode 100644 index 00000000..050bacaf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/README.adoc @@ -0,0 +1,10 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoMqttClient + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to send and receive MQTT messages using Arduino. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/WiFiAdvancedCallback.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/WiFiAdvancedCallback.ino new file mode 100644 index 00000000..c4bec667 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/WiFiAdvancedCallback.ino @@ -0,0 +1,190 @@ +/* + ArduinoMqttClient - WiFi Advanced Callback + + This example connects to a MQTT broker and subscribes to a single topic, + it also publishes a message to another topic every 10 seconds. + When a message is received it prints the message to the Serial Monitor, + it uses the callback functionality of the library. + + It also demonstrates how to set the will message, get/set QoS, + duplicate and retain values of messages. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) + #include +#elif defined(ARDUINO_SAMD_MKR1000) + #include +#elif defined(ARDUINO_ARCH_ESP8266) + #include +#elif defined(ARDUINO_ARCH_ESP32) + #include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char willTopic[] = "arduino/will"; +const char inTopic[] = "arduino/in"; +const char outTopic[] = "arduino/out"; + +const long interval = 10000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + // By default the library connects with the "clean session" flag set, + // you can disable this behaviour by using + // mqttClient.setCleanSession(false); + + // set a will message, used by the broker when the connection dies unexpectedly + // you must know the size of the message beforehand, and it must be set before connecting + String willPayload = "oh no!"; + bool willRetain = true; + int willQos = 1; + + mqttClient.beginWill(willTopic, willPayload.length(), willRetain, willQos); + mqttClient.print(willPayload); + mqttClient.endWill(); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1); + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + // set the message receive callback + mqttClient.onMessage(onMqttMessage); + + Serial.print("Subscribing to topic: "); + Serial.println(inTopic); + Serial.println(); + + // subscribe to a topic + // the second parameter sets the QoS of the subscription, + // the the library supports subscribing at QoS 0, 1, or 2 + int subscribeQos = 1; + + mqttClient.subscribe(inTopic, subscribeQos); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(inTopic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(inTopic); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to receive MQTT messages and + // send MQTT keep alives which avoids being disconnected by the broker + mqttClient.poll(); + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + String payload; + + payload += "hello world!"; + payload += " "; + payload += count; + + Serial.print("Sending message to topic: "); + Serial.println(outTopic); + Serial.println(payload); + + // send message, the Print interface can be used to set the message contents + // in this case we know the size ahead of time, so the message payload can be streamed + + bool retained = false; + int qos = 1; + bool dup = false; + + mqttClient.beginMessage(outTopic, payload.length(), retained, qos, dup); + mqttClient.print(payload); + mqttClient.endMessage(); + + Serial.println(); + + count++; + } +} + +void onMqttMessage(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', duplicate = "); + Serial.print(mqttClient.messageDup() ? "true" : "false"); + Serial.print(", QoS = "); + Serial.print(mqttClient.messageQoS()); + Serial.print(", retained = "); + Serial.print(mqttClient.messageRetain() ? "true" : "false"); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiAdvancedCallback/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/WiFiEcho.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/WiFiEcho.ino new file mode 100644 index 00000000..53ad4e39 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/WiFiEcho.ino @@ -0,0 +1,146 @@ +/* + ArduinoMqttClient - WiFi Echo + + This example connects to a MQTT broker and subscribes to a single topic, + it also publishes a message to the same topic once a second. + When a message is received it prints the message to the Serial Monitor. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) + #include +#elif defined(ARDUINO_SAMD_MKR1000) + #include +#elif defined(ARDUINO_ARCH_ESP8266) + #include +#elif defined(ARDUINO_ARCH_ESP32) + #include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; + +const char topic[] = "arduino/echo"; + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1); + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + Serial.print("Subscribing to topic: "); + Serial.println(topic); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe(topic); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(topic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(topic); + Serial.println(); +} + +void loop() { + // check for incoming messages + int messageSize = mqttClient.parseMessage(); + if (messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); + } + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + Serial.print("Sending message to topic: "); + Serial.println(topic); + Serial.print("echo "); + Serial.println(count); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage(topic); + mqttClient.print("echo "); + mqttClient.print(count); + mqttClient.endMessage(); + + Serial.println(); + + count++; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEcho/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/WiFiEchoCallback.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/WiFiEchoCallback.ino new file mode 100644 index 00000000..ef17c540 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/WiFiEchoCallback.ino @@ -0,0 +1,151 @@ +/* + ArduinoMqttClient - WiFi Echo + + This example connects to a MQTT broker and subscribes to a single topic, + it also publishes a message to the same topic once a second. + When a message is received it prints the message to the Serial Monitor, + it uses the callback functionality of the library. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) + #include +#elif defined(ARDUINO_SAMD_MKR1000) + #include +#elif defined(ARDUINO_ARCH_ESP8266) + #include +#elif defined(ARDUINO_ARCH_ESP32) + #include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char topic[] = "arduino/echo"; + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1); + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + // set the message receive callback + mqttClient.onMessage(onMqttMessage); + + Serial.print("Subscribing to topic: "); + Serial.println(topic); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe(topic); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(topic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(topic); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to receive MQTT messages and + // send MQTT keep alives which avoids being disconnected by the broker + mqttClient.poll(); + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + Serial.print("Sending message to topic: "); + Serial.println(topic); + Serial.print("echo "); + Serial.println(count); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage(topic); + mqttClient.print("echo "); + mqttClient.print(count); + mqttClient.endMessage(); + + Serial.println(); + + count++; + } +} + +void onMqttMessage(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiEchoCallback/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/WiFiSimpleReceive.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/WiFiSimpleReceive.ino new file mode 100644 index 00000000..753989bd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/WiFiSimpleReceive.ino @@ -0,0 +1,114 @@ +/* + ArduinoMqttClient - WiFi Simple Receive + + This example connects to a MQTT broker and subscribes to a single topic. + When a message is received it prints the message to the Serial Monitor. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) + #include +#elif defined(ARDUINO_SAMD_MKR1000) + #include +#elif defined(ARDUINO_ARCH_ESP8266) + #include +#elif defined(ARDUINO_ARCH_ESP32) + #include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char topic[] = "arduino/simple"; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1); + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + Serial.print("Subscribing to topic: "); + Serial.println(topic); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe(topic); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(topic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(topic); + Serial.println(); +} + +void loop() { + int messageSize = mqttClient.parseMessage(); + if (messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceive/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/WiFiSimpleReceiveCallback.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/WiFiSimpleReceiveCallback.ino new file mode 100644 index 00000000..4dc4b96c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/WiFiSimpleReceiveCallback.ino @@ -0,0 +1,121 @@ +/* + ArduinoMqttClient - WiFi Simple Receive Callback + + This example connects to a MQTT broker and subscribes to a single topic. + When a message is received it prints the message to the Serial Monitor, + it uses the callback functionality of the library. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) + #include +#elif defined(ARDUINO_SAMD_MKR1000) + #include +#elif defined(ARDUINO_ARCH_ESP8266) + #include +#elif defined(ARDUINO_ARCH_ESP32) + #include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char topic[] = "arduino/simple"; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1); + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + // set the message receive callback + mqttClient.onMessage(onMqttMessage); + + Serial.print("Subscribing to topic: "); + Serial.println(topic); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe(topic); + + // topics can be unsubscribed using: + // mqttClient.unsubscribe(topic); + + Serial.print("Waiting for messages on topic: "); + Serial.println(topic); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to receive MQTT messages and + // send MQTT keep alives which avoids being disconnected by the broker + mqttClient.poll(); +} + +void onMqttMessage(int messageSize) { + // we received a message, print out the topic and contents + Serial.println("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleReceiveCallback/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/WiFiSimpleSender.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/WiFiSimpleSender.ino new file mode 100644 index 00000000..b7f94bdb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/WiFiSimpleSender.ino @@ -0,0 +1,115 @@ +/* + ArduinoMqttClient - WiFi Simple Sender + + This example connects to a MQTT broker and publishes a message to + a topic once a second. + + The circuit: + - Arduino MKR 1000, MKR 1010 or Uno WiFi Rev2 board + + This example code is in the public domain. +*/ + +#include +#if defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || defined(ARDUINO_AVR_UNO_WIFI_REV2) + #include +#elif defined(ARDUINO_SAMD_MKR1000) + #include +#elif defined(ARDUINO_ARCH_ESP8266) + #include +#elif defined(ARDUINO_ARCH_ESP32) + #include +#endif + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +// To connect with SSL/TLS: +// 1) Change WiFiClient to WiFiSSLClient. +// 2) Change port value from 1883 to 8883. +// 3) Change broker value to a server with a known SSL/TLS root certificate +// flashed in the WiFi module. + +WiFiClient wifiClient; +MqttClient mqttClient(wifiClient); + +const char broker[] = "test.mosquitto.org"; +int port = 1883; +const char topic[] = "arduino/simple"; + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // attempt to connect to WiFi network: + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // You can provide a unique client ID, if not set the library uses Arduino-millis() + // Each client must have a unique client ID + // mqttClient.setId("clientId"); + + // You can provide a username and password for authentication + // mqttClient.setUsernamePassword("username", "password"); + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1); + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); +} + +void loop() { + // call poll() regularly to allow the library to send MQTT keep alives which + // avoids being disconnected by the broker + mqttClient.poll(); + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + Serial.print("Sending message to topic: "); + Serial.println(topic); + Serial.print("hello "); + Serial.println(count); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage(topic); + mqttClient.print("hello "); + mqttClient.print(count); + mqttClient.endMessage(); + + Serial.println(); + + count++; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoMqttClient/examples/WiFiSimpleSender/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/README.adoc new file mode 100644 index 00000000..b1be50e8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/README.adoc @@ -0,0 +1,15 @@ +:repository-owner: arduino-libraries +:repository-name: ArduinoRS485 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Enables sending and receiving data using the RS-485 standard with RS-485 shields, like the MKR 485 Shield. + +This library supports the Maxim Integrated MAX3157 and equivalent chipsets. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Passthrough/RS485Passthrough.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Passthrough/RS485Passthrough.ino new file mode 100644 index 00000000..f86249f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Passthrough/RS485Passthrough.ino @@ -0,0 +1,44 @@ +/* + RS-485 Passthrough + + This sketch relays data sent and received between the Serial port and the RS-485 interface + + Circuit: + - MKR board + - MKR 485 Shield + - ISO GND connected to GND of the RS-485 device + - Y connected to A of the RS-485 device + - Z connected to B of the RS-485 device + - A connected to Y of the RS-485 device + - B connected to Z of the RS-485 device + - Jumper positions + - FULL set to ON + - Z \/\/ Y set to ON, if the RS-485 device doesn't provide termination + - B \/\/ A set to ON, if the RS-485 device doesn't provide termination + + created 4 July 2018 + by Sandeep Mistry +*/ + +#include + +void setup() { + Serial.begin(9600); + RS485.begin(9600); + + // enable transmission, can be disabled with: RS485.endTransmission(); + RS485.beginTransmission(); + + // enable reception, can be disabled with: RS485.noReceive(); + RS485.receive(); +} + +void loop() { + if (Serial.available()) { + RS485.write(Serial.read()); + } + + if (RS485.available()) { + Serial.write(RS485.read()); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Receiver/RS485Receiver.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Receiver/RS485Receiver.ino new file mode 100644 index 00000000..03734969 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Receiver/RS485Receiver.ino @@ -0,0 +1,37 @@ +/* + RS-485 Receiver + + This sketch receives data over RS-485 interface and outputs the data to the Serial interface + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the RS-485 device + - A connected to A/Y of the RS-485 device + - B connected to B/Z of the RS-485 device + - Jumper positions + - FULL set to ON + - A \/\/ B set to OFF + + created 4 July 2018 + by Sandeep Mistry +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + RS485.begin(9600); + + // enable reception, can be disabled with: RS485.noReceive(); + RS485.receive(); +} + +void loop() { + if (RS485.available()) { + Serial.write(RS485.read()); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Sender/RS485Sender.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Sender/RS485Sender.ino new file mode 100644 index 00000000..c40f0169 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoRS485/examples/RS485Sender/RS485Sender.ino @@ -0,0 +1,37 @@ +/* + RS-485 Sender + + This sketch periodically sends a string over the RS-485 interface + + Circuit: + - MKR board + - MKR 485 shield + - ISO GND connected to GND of the RS-485 device + - Y connected to A of the RS-485 device + - Z connected to B of the RS-485 device + - Jumper positions + - FULL set to ON + - Z \/\/ Y set to ON + + created 4 July 2018 + by Sandeep Mistry +*/ + +#include + +int counter = 0; + +void setup() { + RS485.begin(9600); +} + +void loop() { + RS485.beginTransmission(); + RS485.print("hello "); + RS485.println(counter); + RS485.endTransmission(); + + counter++; + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/README.md new file mode 100644 index 00000000..5e8b15bb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/README.md @@ -0,0 +1,28 @@ +# ArduinoSound + +[![Check Arduino status](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/ArduinoSound/actions/workflows/spell-check.yml) + +A simple way to play and analyze audio data using Arduino. Currently only supports SAMD21 boards and I2S audio devices. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/ArduinoSound + +## License + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/AmplitudeSerialPlotter/AmplitudeSerialPlotter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/AmplitudeSerialPlotter/AmplitudeSerialPlotter.ino new file mode 100644 index 00000000..bc5309a3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/AmplitudeSerialPlotter/AmplitudeSerialPlotter.ino @@ -0,0 +1,57 @@ +/* + This example reads audio data from an InvenSense ICS-43432 I2S microphone + breakout board, and prints out the amplitude to the Serial Monitor. The + Serial Plotter built into the Arduino IDE (Tools -> Serial Plotter) can be + used to plot the audio amplitude data. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * ICS-43432: + * GND connected GND + * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKR Zero) + * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 23 November 2016 + by Sandeep Mistry + */ + +#include + +// create an amplitude analyzer to be used with the I2S input +AmplitudeAnalyzer amplitudeAnalyzer; + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // setup the I2S audio input for 44.1 kHz with 32-bits per sample + if (!AudioInI2S.begin(44100, 32)) { + Serial.println("Failed to initialize I2S input!"); + while (1); // do nothing + } + + // configure the I2S input as the input for the amplitude analyzer + if (!amplitudeAnalyzer.input(AudioInI2S)) { + Serial.println("Failed to set amplitude analyzer input!"); + while (1); // do nothing + } +} + +void loop() { + // check if a new analysis is available + if (amplitudeAnalyzer.available()) { + // read the new amplitude + int amplitude = amplitudeAnalyzer.read(); + //dB relative to full scale + int dpFS = 20 * log10(abs(amplitude)); + // print out the decibel to the serial monitor + Serial.println(dpFS); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/ClapDetector/ClapDetector.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/ClapDetector/ClapDetector.ino new file mode 100644 index 00000000..950030a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/ClapDetector/ClapDetector.ino @@ -0,0 +1,77 @@ +/* + This example reads audio data from an InvenSense ICS-43432 I2S microphone + breakout board, and uses the input to detect clapping sounds. An LED is + toggled when a clap is detected. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * ICS-43432: + * GND connected GND + * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKR Zero) + * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 18 November 2016 + by Sandeep Mistry + */ + +#include + +// the LED pin to use as output +const int ledPin = LED_BUILTIN; + +// the amplitude threshold for a clap to be detected +const int amplitudeDeltaThreshold = 100000000; + +// create an amplitude analyzer to be used with the I2S input +AmplitudeAnalyzer amplitudeAnalyzer; + +// variable to keep track of last amplitude +int lastAmplitude = 0; + +void setup() { + // setup the serial + Serial.begin(9600); + + // configure the LED pin as an output + pinMode(ledPin, OUTPUT); + + // setup the I2S audio input for 44.1 kHz with 32-bits per sample + if (!AudioInI2S.begin(44100, 32)) { + Serial.println("Failed to initialize I2S input!"); + while (1); // do nothing + } + + // configure the I2S input as the input for the amplitude analyzer + if (!amplitudeAnalyzer.input(AudioInI2S)) { + Serial.println("Failed to set amplitude analyzer input!"); + while (1); // do nothing + } +} + +void loop() { + // check if a new analysis is available + if (amplitudeAnalyzer.available()) { + // read the new amplitude + int amplitude = amplitudeAnalyzer.read(); + + // find the difference between the new amplitude and the last + int delta = amplitude - lastAmplitude; + + // check if the difference is larger than the threshold + if (delta > amplitudeDeltaThreshold) { + // a clap was detected + Serial.println("clap detected"); + + // toggle the LED + digitalWrite(ledPin, !digitalRead(ledPin)); + + // delay a bit to debounce + delay(100); + } + + // update the last amplitude with the new amplitude + lastAmplitude = amplitude; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/SpectrumSerialPlotter/SpectrumSerialPlotter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/SpectrumSerialPlotter/SpectrumSerialPlotter.ino new file mode 100644 index 00000000..69d36c77 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/SpectrumSerialPlotter/SpectrumSerialPlotter.ino @@ -0,0 +1,72 @@ +/* + This example reads audio data from an InvenSense ICS-43432 I2S microphone + breakout board, and prints out the spectrum to the Serial Monitor. The + Serial Plotter built into the Arduino IDE (Tools -> Serial Plotter) can be + used to plot the audio amplitude data. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * ICS-43432: + * GND connected GND + * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKR Zero) + * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 21 November 2016 + by Sandeep Mistry + */ + +#include + +// sample rate for the input +const int sampleRate = 8000; + +// size of the FFT to compute +const int fftSize = 128; + +// size of the spectrum output, half of FFT size +const int spectrumSize = fftSize / 2; + +// array to store spectrum output +int spectrum[spectrumSize]; + +// create an FFT analyzer to be used with the I2S input +FFTAnalyzer fftAnalyzer(fftSize); + +void setup() { +// Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // setup the I2S audio input for the sample rate with 32-bits per sample + if (!AudioInI2S.begin(sampleRate, 32)) { + Serial.println("Failed to initialize I2S input!"); + while (1); // do nothing + } + + // configure the I2S input as the input for the FFT analyzer + if (!fftAnalyzer.input(AudioInI2S)) { + Serial.println("Failed to set FFT analyzer input!"); + while (1); // do nothing + } +} + +void loop() { + // check if a new analysis is available + if (fftAnalyzer.available()) { + // read the new spectrum + fftAnalyzer.read(spectrum, spectrumSize); + + // print out the spectrum + for (int i = 0; i < spectrumSize; i++) { + Serial.print((i * sampleRate) / fftSize); // the starting frequency + Serial.print("\t"); // + Serial.println(spectrum[i]); // the spectrum value + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/WavePlayback/WavePlayback.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/WavePlayback/WavePlayback.ino new file mode 100644 index 00000000..ba8084bc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/WavePlayback/WavePlayback.ino @@ -0,0 +1,93 @@ +/* + This reads a wave file from an SD card and plays it using the I2S interface to + a MAX98357 I2S Amp Breakout board. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * SD breakout or shield connected + * MAX98357: + * GND connected GND + * VIN connected 5V + * LRC connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * BCLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * DIN connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 15 November 2016 + by Sandeep Mistry + */ + +#include +#include + +// filename of wave file to play +const char filename[] = "MUSIC.WAV"; + +// variable representing the Wave File +SDWaveFile waveFile; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // setup the SD card, depending on your shield of breakout board + // you may need to pass a pin number in begin for SS + Serial.print("Initializing SD card..."); + if (!SD.begin()) { + Serial.println("initialization failed!"); + return; + } + Serial.println("initialization done."); + + // create a SDWaveFile + waveFile = SDWaveFile(filename); + + // check if the WaveFile is valid + if (!waveFile) { + Serial.println("wave file is invalid!"); + while (1); // do nothing + } + + // print out some info. about the wave file + Serial.print("Bits per sample = "); + Serial.println(waveFile.bitsPerSample()); + + long channels = waveFile.channels(); + Serial.print("Channels = "); + Serial.println(channels); + + long sampleRate = waveFile.sampleRate(); + Serial.print("Sample rate = "); + Serial.print(sampleRate); + Serial.println(" Hz"); + + long duration = waveFile.duration(); + Serial.print("Duration = "); + Serial.print(duration); + Serial.println(" seconds"); + + // adjust the playback volume + AudioOutI2S.volume(5); + + // check if the I2S output can play the wave file + if (!AudioOutI2S.canPlay(waveFile)) { + Serial.println("unable to play wave file using I2S!"); + while (1); // do nothing + } + + // start playback + Serial.println("starting playback"); + AudioOutI2S.play(waveFile); +} + +void loop() { + // check if playback is still going on + if (!AudioOutI2S.isPlaying()) { + // playback has stopped + + Serial.println("playback stopped"); + while (1); // do nothing + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/WhistleDetector/WhistleDetector.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/WhistleDetector/WhistleDetector.ino new file mode 100644 index 00000000..3bcab0a1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/ArduinoSound/examples/WhistleDetector/WhistleDetector.ino @@ -0,0 +1,84 @@ +/* + This example reads audio data from an InvenSense ICS-43432 I2S microphone + breakout board, and uses the input to detect whistling sounds at a particular + frequency. When a whistle is detected, its level is used to control the + brightness of an LED. + + Circuit: + * Arduino Zero, MKR Zero or MKR1000 board + * ICS-43432: + * GND connected GND + * 3.3V connected 3.3V (Zero) or VCC (MKR1000, MKR Zero) + * WS connected to pin 0 (Zero) or pin 3 (MKR1000, MKR Zero) + * CLK connected to pin 1 (Zero) or pin 2 (MKR1000, MKR Zero) + * SD connected to pin 9 (Zero) or pin A6 (MKR1000, MKR Zero) + + created 30 November 2016 + by Sandeep Mistry + */ + +#include + +// the LED pin to use as output +const int ledPin = LED_BUILTIN; + +// sample rate for the input +const int sampleRate = 8000; + +// size of the FFT to compute +const int fftSize = 128; + +// size of the spectrum output, half of FFT size +const int spectrumSize = fftSize / 2; + +// frequency of whistle to detect +const int whistleFrequency = 1250; + +// map whistle frequency to FFT bin +const int whistleBin = (whistleFrequency * fftSize / sampleRate); + +// array to store spectrum output +int spectrum[spectrumSize]; + +// create an FFT analyzer to be used with the I2S input +FFTAnalyzer fftAnalyzer(fftSize); + +void setup() { + // setup the serial + Serial.begin(9600); + + // configure the pin for output mode + pinMode(ledPin, OUTPUT); + + // setup the I2S audio input for the sample rate with 32-bits per sample + if (!AudioInI2S.begin(sampleRate, 32)) { + Serial.println("Failed to initialize I2S input!"); + while (1); // do nothing + } + + // configure the I2S input as the input for the FFT analyzer + if (!fftAnalyzer.input(AudioInI2S)) { + Serial.println("Failed to set FFT analyzer input!"); + while (1); // do nothing + } +} + +void loop() { + if (fftAnalyzer.available()) { + // analysis available, read in the spectrum + fftAnalyzer.read(spectrum, spectrumSize); + + // map the value of the whistle bin magnitude between 0 and 255 + int ledValue = map(spectrum[whistleBin], 50000, 60000, 0, 255); + + // cap the values + if (ledValue < 0) { + ledValue = 0; + } else if (ledValue > 255) { + ledValue = 255; + } + + // set LED brightness based on whistle bin magnitude + analogWrite(ledPin, ledValue); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/README.adoc new file mode 100644 index 00000000..e7b720f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/README.adoc @@ -0,0 +1,12 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_APDS9960 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +A library for the APDS-9960 sensor, allows you to read gestures, color, and proximity on your Arduino Nano 33 BLE Sense board and other boards with sensor attached via I2C. + +For more information about this library please visit us at https://www.arduino.cc/reference/en/libraries/arduino_apds9960/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/ColorSensor/ColorSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/ColorSensor/ColorSensor.ino new file mode 100644 index 00000000..861b8be5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/ColorSensor/ColorSensor.ino @@ -0,0 +1,46 @@ +/* + APDS-9960 - Color Sensor + + This example reads color data from the on-board APDS-9960 sensor of the + Nano 33 BLE Sense and prints the color RGB (red, green, blue) values + to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!APDS.begin()) { + Serial.println("Error initializing APDS-9960 sensor."); + } +} + +void loop() { + // check if a color reading is available + while (! APDS.colorAvailable()) { + delay(5); + } + int r, g, b; + + // read the color + APDS.readColor(r, g, b); + + // print the values + Serial.print("r = "); + Serial.println(r); + Serial.print("g = "); + Serial.println(g); + Serial.print("b = "); + Serial.println(b); + Serial.println(); + + // wait a bit before reading again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/FullExample/FullExample.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/FullExample/FullExample.ino new file mode 100644 index 00000000..204a315d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/FullExample/FullExample.ino @@ -0,0 +1,83 @@ +/* + APDS-9960 - All sensor data from APDS-9960 + + This example reads all data from the on-board APDS-9960 sensor of the + Nano 33 BLE Sense: + - color RGB (red, green, blue) + - proximity + - gesture + and prints updates to the Serial Monitor every 100 ms. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); // Wait for Serial Monitor to open + + if (!APDS.begin()) { + Serial.println("Error initializing APDS-9960 sensor."); + while (true); // Stop forever + } +} + +int proximity = 0; +int r = 0, g = 0, b = 0; +unsigned long lastUpdate = 0; + +void loop() { + + // Check if a proximity reading is available. + if (APDS.proximityAvailable()) { + proximity = APDS.readProximity(); + } + + // Check if a gesture reading is available + if (APDS.gestureAvailable()) { + int gesture = APDS.readGesture(); + switch (gesture) { + case GESTURE_UP: + Serial.println("Detected UP gesture"); + break; + + case GESTURE_DOWN: + Serial.println("Detected DOWN gesture"); + break; + + case GESTURE_LEFT: + Serial.println("Detected LEFT gesture"); + break; + + case GESTURE_RIGHT: + Serial.println("Detected RIGHT gesture"); + break; + + default: + // Ignore + break; + } + } + + // Check if a color reading is available + if (APDS.colorAvailable()) { + APDS.readColor(r, g, b); + } + + // Print updates every 100 ms + if (millis() - lastUpdate > 100) { + lastUpdate = millis(); + Serial.print("PR="); + Serial.print(proximity); + Serial.print(" RGB="); + Serial.print(r); + Serial.print(","); + Serial.print(g); + Serial.print(","); + Serial.println(b); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/GestureSensor/GestureSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/GestureSensor/GestureSensor.ino new file mode 100644 index 00000000..98b62da3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/GestureSensor/GestureSensor.ino @@ -0,0 +1,65 @@ +/* + APDS-9960 - Gesture Sensor + + This example reads gesture data from the on-board APDS-9960 sensor of the + Nano 33 BLE Sense and prints any detected gestures to the Serial Monitor. + + Gesture directions are as follows: + - UP: from USB connector towards antenna + - DOWN: from antenna towards USB connector + - LEFT: from analog pins side towards digital pins side + - RIGHT: from digital pins side towards analog pins side + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!APDS.begin()) { + Serial.println("Error initializing APDS-9960 sensor!"); + } + + // for setGestureSensitivity(..) a value between 1 and 100 is required. + // Higher values make the gesture recognition more sensitive but less accurate + // (a wrong gesture may be detected). Lower values makes the gesture recognition + // more accurate but less sensitive (some gestures may be missed). + // Default is 80 + //APDS.setGestureSensitivity(80); + + Serial.println("Detecting gestures ..."); +} +void loop() { + if (APDS.gestureAvailable()) { + // a gesture was detected, read and print to Serial Monitor + int gesture = APDS.readGesture(); + + switch (gesture) { + case GESTURE_UP: + Serial.println("Detected UP gesture"); + break; + + case GESTURE_DOWN: + Serial.println("Detected DOWN gesture"); + break; + + case GESTURE_LEFT: + Serial.println("Detected LEFT gesture"); + break; + + case GESTURE_RIGHT: + Serial.println("Detected RIGHT gesture"); + break; + + default: + // ignore + break; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/ProximitySensor/ProximitySensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/ProximitySensor/ProximitySensor.ino new file mode 100644 index 00000000..e826ce18 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_APDS9960/examples/ProximitySensor/ProximitySensor.ino @@ -0,0 +1,40 @@ +/* + APDS-9960 - Proximity Sensor + + This example reads proximity data from the on-board APDS-9960 sensor of the + Nano 33 BLE Sense and prints the proximity value to the Serial Monitor + every 100 ms. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!APDS.begin()) { + Serial.println("Error initializing APDS-9960 sensor!"); + } +} + +void loop() { + // check if a proximity reading is available + if (APDS.proximityAvailable()) { + // read the proximity + // - 0 => close + // - 255 => far + // - -1 => error + int proximity = APDS.readProximity(); + + // print value to the Serial Monitor + Serial.println(proximity); + } + + // wait a bit before reading again + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/README.adoc new file mode 100644 index 00000000..21601bbc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_BQ24195 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows the control and configuration of the BQ24195 PMIC used on various Arduino boards. + +The library is in beta and its APIs are not stable yet. + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryCharger/BatteryCharger.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryCharger/BatteryCharger.ino new file mode 100644 index 00000000..37a15758 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryCharger/BatteryCharger.ino @@ -0,0 +1,80 @@ +/* + Battery Charge Example + + This example shows how to configure and enable charge mode on Arduino MKR boards + + Circuit: + - Arduino MKR board + - 750 mAh LiPo battery + + created 21 Aug 2019 + by Riccardo Rizzo + + This sample code is part of the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + if (!PMIC.begin()) { + Serial.println("Failed to initialize PMIC!"); + while (1); + } + + // Set the input current limit to 2 A and the overload input voltage to 3.88 V + if (!PMIC.setInputCurrentLimit(2.0)) { + Serial.println("Error in set input current limit"); + } + + if (!PMIC.setInputVoltageLimit(3.88)) { + Serial.println("Error in set input voltage limit"); + } + + // set the minimum voltage used to feeding the module embed on Board + if (!PMIC.setMinimumSystemVoltage(3.5)) { + Serial.println("Error in set minimum system volage"); + } + + // Set the desired charge voltage to 4.11 V + if (!PMIC.setChargeVoltage(4.2)) { + Serial.println("Error in set charge volage"); + } + + // Set the charge current to 375 mA + // the charge current should be defined as maximum at (C for hour)/2h + // to avoid battery explosion (for example for a 750 mAh battery set to 0.375 A) + if (!PMIC.setChargeCurrent(0.375)) { + Serial.println("Error in set charge current"); + } + Serial.println("Initialization done!"); +} + +void loop() { + // Enable the Charger + if (!PMIC.enableCharge()) { + Serial.println("Error enabling Charge mode"); + } + // canRunOnBattery() returns true if the battery voltage is < the minimum + // systems voltage + if (PMIC.canRunOnBattery()) { + // loop until charge is done + while (PMIC.chargeStatus() != CHARGE_TERMINATION_DONE) { + delay(1000); + } + // Disable the charger and loop forever + Serial.println("Disable Charge mode"); + if (!PMIC.disableCharge()) { + Serial.println("Error disabling Charge mode"); + } + while (1); + // if you really want to detach the battery call + // PMIC.disableBATFET(); + //isbatteryconnected = false; + } + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryChargerInterrupt/BatteryChargerInterrupt.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryChargerInterrupt/BatteryChargerInterrupt.ino new file mode 100644 index 00000000..ae4872cb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/BatteryChargerInterrupt/BatteryChargerInterrupt.ino @@ -0,0 +1,96 @@ +/* + Battery Charge Interrupt Example + + This example shows how to configure and enable charge mode on Arduino MKR boards + + Circuit: + - Arduino MKR board + - 750 mAh LiPo battery + + created 21 Aug 2019 + by Riccardo Rizzo + + This sample code is part of the public domain. +*/ + +#include + +volatile unsigned long time_last_interrupt = millis(); + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + +// Available only for MKRGSM1400 and MKRNB1500 +#if defined(ARDUINO_SAMD_MKRGSM1400) || defined(ARDUINO_SAMD_MKRNB1500) + // Attach the PMIC IRQ pin + attachInterrupt(digitalPinToInterrupt(PMIC_IRQ_PIN), batteryConnected, FALLING); +#endif + + if (!PMIC.begin()) { + Serial.println("Failed to initialize PMIC!"); + while (1); + } + + // Set the input current limit to 2 A and the overload input voltage to 3.88 V + if (!PMIC.setInputCurrentLimit(2.0)) { + Serial.println("Error in set input current limit"); + } + + if (!PMIC.setInputVoltageLimit(3.88)) { + Serial.println("Error in set input voltage limit"); + } + + // set the minimum voltage used to feeding the module embed on Board + if (!PMIC.setMinimumSystemVoltage(3.5)) { + Serial.println("Error in set minimum system volage"); + } + + // Set the desired charge voltage to 4.11 V + if (!PMIC.setChargeVoltage(4.2)) { + Serial.println("Error in set charge volage"); + } + + // Set the charge current to 375 mA + // the charge current should be defined as maximum at (C for hour)/2h + // to avoid battery explosion (for example for a 750mAh battery set to 0.375 A) + if (!PMIC.setChargeCurrent(0.375)) { + Serial.println("Error in set charge current"); + } + Serial.println("Initialization done!"); +} + +void loop() { + if (millis() - time_last_interrupt > 100) { + // Enable the Charger + if (!PMIC.enableCharge()) { + Serial.println("Error enabling Charge mode"); + } + + // canRunOnBattery() returns true if the battery voltage is < the minimum + // systems voltage + if (PMIC.canRunOnBattery()) { + + // loop until charge is done + if (PMIC.chargeStatus() != CHARGE_TERMINATION_DONE) { + delay(1000); + } else { + // Disable the charger + Serial.println("Disable Charge mode"); + if (!PMIC.disableCharge()) { + Serial.println("Error disabling Charge mode"); + } + // if you really want to detach the battery call + // PMIC.disableBATFET(); + //isbatteryconnected = false; + } + } + } + delay(100); +} + +void batteryConnected() { + time_last_interrupt = millis(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/PMICBoostMode/PMICBoostMode.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/PMICBoostMode/PMICBoostMode.ino new file mode 100644 index 00000000..bc264258 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/PMICBoostMode/PMICBoostMode.ino @@ -0,0 +1,48 @@ +/* + PMIC Boost Mode Example + + This example shows how to enable boost mode on Arduino MKR boards + + Circuit: + - Arduino MKR board + - OTG cable + + created 21 Aug 2019 + by Riccardo Rizzo + + This sample code is part of the public domain. +*/ + +#include + +int usb_mode = UNKNOWN_MODE; + +void setup() +{ + // Serial1 shall be used to print messages because the programming + // port is busy with the guest device + Serial1.begin(9600); + if (!PMIC.begin()) { + Serial1.println("Failed to initialize PMIC!"); + while (1); + } + + // Enable boost mode, this mode allows using the board as host to + // connect a guest device such as a keyboard + if (!PMIC.enableBoostMode()) { + Serial1.println("Error enabling Boost Mode"); + } + Serial1.println("Initialization Done!"); +} + +void loop() { + int actual_mode = PMIC.USBmode(); + if (actual_mode != usb_mode) { + usb_mode = actual_mode; + if (actual_mode == BOOST_MODE) { + // if the boost mode was correctly enabled, 5 V should appear on 5V pin + // and on the USB connector + Serial1.println("Boost mode status enabled"); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/PMICFaultCheck/PMICFaultCheck.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/PMICFaultCheck/PMICFaultCheck.ino new file mode 100644 index 00000000..fafbf503 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_BQ24195/examples/PMICFaultCheck/PMICFaultCheck.ino @@ -0,0 +1,65 @@ +/* + PMIC Fault Check Example + + This example shows how to check the PMIC fault states + + Circuit: + - Arduino MKR board + + created 21 Aug 2019 + by Riccardo Rizzo + + This sample code is part of the public domain. +*/ + +#include + +int chargefault = NO_CHARGE_FAULT; +int batTempfault = NO_TEMPERATURE_FAULT; + +void setup() { + if (!PMIC.begin()) { + Serial.println("Failed to initialize PMIC!"); + while (1); + } +} + +void loop() { + // getChargeFault() returns the charge fault state, the fault could be: + // - Thermal shutdown: occurs if internal junction temperature exceeds + // the preset limit; + // - input over voltage: occurs if VBUS voltage exceeds 18 V; + // - charge safety timer expiration: occurs if the charge timer expires. + chargefault = PMIC.getChargeFault(); + // getChargeFault() returns charge fault status + switch (chargefault) { + case INPUT_OVER_VOLTAGE: Serial.println("Input over voltage fault occurred"); + break; + case THERMAL_SHUTDOWN: Serial.println("Thermal shutdown occurred"); + break; + case CHARGE_SAFETY_TIME_EXPIRED: Serial.println("Charge safety timer expired"); + break; + case NO_CHARGE_FAULT: Serial.println("No Charge fault"); + break; + default : break; + } + + // The isBatteryInOverVoltage() returns if battery over-voltage fault occurs. + // When battery over voltage occurs, the charger device immediately disables + // charge and sets the battery fault bit, in fault register, to high. + if (PMIC.isBatteryInOverVoltage()) { + Serial.println("Error: battery over voltage fault"); + } + + + batTempfault = PMIC.hasBatteryTemperatureFault(); + switch (batTempfault) { + case NO_TEMPERATURE_FAULT: Serial.println("No temperature fault"); + break; + case LOWER_THRESHOLD_TEMPERATURE_FAULT: Serial.println("Lower threshold Battery temperature fault"); + break; + case HIGHER_THRESHOLD_TEMPERATURE_FAULT: Serial.println("Higher threshold Battery temperature fault"); + break; + default: break; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/LICENSE new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/README.md new file mode 100644 index 00000000..17eef2e6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/README.md @@ -0,0 +1,63 @@ +Arduino Library for network connections management +================================================== + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_ConnectionHandler/actions/workflows/spell-check.yml) + +Library for handling and managing network connections by providing keep-alive functionality and automatic reconnection in case of connection-loss. It supports the following boards: +* **WiFi**: [`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), [`Portenta H7`](https://store.arduino.cc/products/portenta-h7), [`Nano RP2040 Connect`](https://store.arduino.cc/products/arduino-nano-rp2040-connect), [`Nicla Vision`](https://store.arduino.cc/products/nicla-vision), `ESP8266` +* **GSM**: [`MKR GSM 1400`](https://store.arduino.cc/arduino-mkr-gsm-1400-1415) +* **5G**: [`MKR NB 1500`](https://store.arduino.cc/arduino-mkr-nb-1500-1413) +* **LoRa**: [`MKR WAN 1300/1310`](https://store.arduino.cc/mkr-wan-1310) + +### How-to-use + +```C++ +#include +/* ... */ +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler conMan("SECRET_SSID", "SECRET_PASS"); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS"); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler conMan("SECRET_PIN", "SECRET_APN", "SECRET_GSM_LOGIN", "SECRET_GSM_PASS"); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler conMan("SECRET_APP_EUI", "SECRET_APP_KEY"); +#endif +/* ... */ +void setup() { + Serial.begin(9600); + while(!Serial) { } + + setDebugMessageLevel(DBG_INFO); + + conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); + conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); + conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); +} + +void loop() { + /* The following code keeps on running connection workflows on our + * ConnectionHandler object, hence allowing reconnection in case of failure + * and notification of connect/disconnect event if enabled (see + * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within + * the loop or methods called from it will delay the execution of .check(), + * which might not guarantee the correct functioning of the ConnectionHandler + * object. + */ + conMan.check(); +} +/* ... */ +void onNetworkConnect() { + Serial.println(">>>> CONNECTED to network"); +} + +void onNetworkDisconnect() { + Serial.println(">>>> DISCONNECTED from network"); +} + +void onNetworkError() { + Serial.println(">>>> ERROR"); +} +``` diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino new file mode 100644 index 00000000..b106eed6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/ConnectionHandlerDemo.ino @@ -0,0 +1,68 @@ +/* SECRET_ fields are in arduino_secrets.h included above + * if using a WiFi board (Arduino MKR1000, MKR WiFi 1010, Nano 33 IoT, UNO + * WiFi Rev 2 or ESP8266/32), create a WiFiConnectionHandler object by adding + * Network Name (SECRET_SSID) and password (SECRET_PASS) in the arduino_secrets.h + * file (or Secrets tab in Create Web Editor). + * + * WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS); + * + * If using a MKR GSM 1400 or other GSM boards supporting the same API you'll + * need a GSMConnectionHandler object as follows + * + * GSMConnectionHandler conMan(SECRET_PIN, SECRET_APN, SECRET_GSM_USER, SECRET_GSM_PASS); + * + * If using a MKR NB1500 you'll need a NBConnectionHandler object as follows + * + * NBConnectionHandler conMan(SECRET_PIN); + */ + +#include "arduino_secrets.h" + +#include + +#if defined(BOARD_HAS_WIFI) +WiFiConnectionHandler conMan(SECRET_SSID, SECRET_PASS); +#elif defined(BOARD_HAS_GSM) +GSMConnectionHandler conMan(SECRET_APN, SECRET_PIN, SECRET_GSM_USER, SECRET_GSM_PASS); +#elif defined(BOARD_HAS_NB) +NBConnectionHandler conMan(SECRET_PIN); +#elif defined(BOARD_HAS_LORA) +LoRaConnectionHandler conMan(SECRET_APP_EUI, SECRET_APP_KEY); +#endif + +void setup() { + Serial.begin(9600); + /* Give a few seconds for the Serial connection to be available */ + delay(4000); +#ifndef __AVR__ + setDebugMessageLevel(DBG_INFO); +#endif + conMan.addCallback(NetworkConnectionEvent::CONNECTED, onNetworkConnect); + conMan.addCallback(NetworkConnectionEvent::DISCONNECTED, onNetworkDisconnect); + conMan.addCallback(NetworkConnectionEvent::ERROR, onNetworkError); +} + +void loop() { + /* The following code keeps on running connection workflows on our + * ConnectionHandler object, hence allowing reconnection in case of failure + * and notification of connect/disconnect event if enabled (see + * addConnectCallback/addDisconnectCallback) NOTE: any use of delay() within + * the loop or methods called from it will delay the execution of .update(), + * which might not guarantee the correct functioning of the ConnectionHandler + * object. + */ + + conMan.check(); +} + +void onNetworkConnect() { + Serial.println(">>>> CONNECTED to network"); +} + +void onNetworkDisconnect() { + Serial.println(">>>> DISCONNECTED from network"); +} + +void onNetworkError() { + Serial.println(">>>> ERROR"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/arduino_secrets.h new file mode 100644 index 00000000..0a2a2fe6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ConnectionHandler/examples/ConnectionHandlerDemo/arduino_secrets.h @@ -0,0 +1,10 @@ +const char SECRET_SSID[] = "NETWORK NAME"; +const char SECRET_PASS[] = "NETWORK PASSWORD"; + +const char SECRET_APN[] = "MOBILE PROVIDER APN ADDRESS"; +const char SECRET_PIN[] = "0000"; +const char SECRET_GSM_USER[] = "GSM USERNAME"; +const char SECRET_GSM_PASS[] = "GSM PASSWORD"; + +const char SECRET_APP_EUI[] = "APP_EUI"; +const char SECRET_APP_KEY[] = "APP_KEY"; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/LICENSE new file mode 100644 index 00000000..cd4defc3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/LICENSE @@ -0,0 +1,688 @@ +This file includes licensing information for Arduino_DebugUtils. + +Copyright (c) 2018 ARDUINO SA (www.arduino.cc) + +The software is released under the GNU General Public License, which covers the main body +of the Arduino_DebugUtils code. The terms of this license can be found at: +https://www.gnu.org/licenses/gpl-3.0.en.html + +You can be released from the requirements of the above licenses by purchasing +a commercial license. Buying such a license is mandatory if you want to modify or +otherwise use the software for commercial activities involving the Arduino +software without disclosing the source code of your own applications. To purchase +a commercial license, send an email to license@arduino.cc + + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + Arduino_DebugUtils encapsulates functionality useful for debugging code via printf statements. + Copyright (C) Arduino SA, 2019, Author: Alexander Entinger + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Arduino_DebugUtils Copyright (C) 2019, Arduino SA + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/README.md new file mode 100644 index 00000000..bd8dcd61 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/README.md @@ -0,0 +1,113 @@ +Arduino_DebugUtils +================== + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_DebugUtils/actions/workflows/spell-check.yml) + +This class provides functionality useful for debugging sketches via `printf`-style statements. + +# How-To-Use Basic +Arduino_DebugUtils has 6 different debug levels (described descending from highest to lowest priority): +* `DBG_NONE` - no debug output is shown +* `DBG_ERROR` - critical errors +* `DBG_WARNING` - non-critical errors +* `DBG_INFO` - information +* `DBG_DEBUG` - more information +* `DBG_VERBOSE` - most information + +The desired debug level can be set via `setDebugLevel(DBG_WARNING)`. + +Debug messages are written via `print` which supports `printf`-style formatted output. + +Example: +```C++ +int i = 1; +float pi = 3.1459; +Debug.print(DBG_VERBOSE, "i = %d, pi = %f", i, pi); +``` +**Note**: The output of floating point numbers (`%f`) does NOT work on [ArduinoCore-avr](https://github.com/arduino/ArduinoCore-avr). + +If desired, timestamps can be prefixed to the debug message. Timestamp output can be enabled and disabled via `timestampOn` and `timestampOff`. + +# How-To-Use Advanced +Normally all debug output is redirected to the primary serial output of each board (`Serial`). In case you want to redirect the output to another output stream you can make use of `setDebugOutputStream(&Serial2)`. + +# Documentation +### Debug : +Arduino_DebugUtils Object that will be used for calling member functions. + +### Debug.setDebugLevel(int const debug_level) : +Parameter debug_level in order of lowest to highest priority are : `DBG_NONE`, `DBG_ERROR`, `DBG_WARNING`, `DBG_INFO` (default), `DBG_DEBUG`, and `DBG_VERBOSE`. + +Return type: void. + +Example: +``` +Debug.setDebugLevel(DBG_VERBOSE); +``` +### Debug.setDebugOutputStream(Stream * stream) : +By default, Output Stream is Serial. In advanced cases other objects could be other serial ports (if available), or can be a Software Serial object. + +Return type: void. + +Example: +``` +SoftwareSerial mySerial(10, 11); // RX, TX +Debug.setDebugOutputStream(&mySerial); +``` +### Debug.timestampOn() : +Calling this function switches on the timestamp in the `Debug.print()` function call; +By default, printing timestamp is off, unless turned on using this function call. + +Return type: void. + +Example: +``` +Debug.timestampOn(); +Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : [ 21007 ] i = 21 +``` + +### Debug.timestampOff() : +Calling this function switches off the timestamp in the `Debug.print()` function call; + +Return type: void. + +Example: +``` +Debug.timestampOff(); +Debug.print(DBG_VERBOSE, "i = %d", i); //Output looks like : i = 21 +``` + +### Debug.newlineOn() : +Calling this function ensures that a newline will be sent at the end of the `Debug.print()` function call; +By default, a newline is sent +Return type: void. + +Example: +``` +Debug.newlineOn(); +``` + +### Debug.newlineOff() : +Calling this function ensure that a newline will NOT be sent at the end of the `Debug.print()` function call; +By default a newline is sent. Call this to shut that functionality off. +Return type: void. + +Example: +``` +Debug.timestampOff(); +``` + + +### Debug.print(int const debug_level, const char * fmt, ...); +This function prints the message if parameter `debug_level` in the `Debug.print(debug_level, ...)` function call belongs to the range: DBG_ERROR <= debug_level <= ( that has been set using `setDebugLevel()` function). + +Return type: void. + +Example: +``` +Debug.setDebugLevel(DBG_VERBOSE); +int i = 0; +Debug.print(DBG_VERBOSE, "DBG_VERBOSE i = %d", i); +``` diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Advance/Arduino_Debug_Advance.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Advance/Arduino_Debug_Advance.ino new file mode 100644 index 00000000..5837b52e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Advance/Arduino_Debug_Advance.ino @@ -0,0 +1,30 @@ +/* + Advanced Debug can be helpful in embedded applications when + there are more than two microcontrollers connected serially + or a wireless sensor like XBee is connected to the serial port + that will send data wirelessly to other XBee nodes. + + In boards like Arduino Nano, UNO, or MEGA only one serial port is available, + therefore additional software serial ports can be made using the + SoftwareSerial library. +*/ + +#include "Arduino_DebugUtils.h" +#include + +SoftwareSerial mySerial(10, 11); // RX, TX + +void setup() { + mySerial.begin(9600); + Debug.setDebugOutputStream(&mySerial); + Debug.setDebugLevel(DBG_VERBOSE); + Debug.timestampOn(); +} + +int i = 0; + +void loop() { + Debug.print(DBG_VERBOSE, "i = %d", i); + i++; + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino new file mode 100644 index 00000000..ddfedfeb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_DebugUtils/examples/Arduino_Debug_Basic/Arduino_Debug_Basic.ino @@ -0,0 +1,14 @@ +#include "Arduino_DebugUtils.h" + +void setup() { + Serial.begin(9600); + Debug.timestampOn(); +} + +int i = 0; + +void loop() { + Debug.print(DBG_INFO, "i = %d", i); + i++; + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/LICENSE new file mode 100644 index 00000000..a612ad98 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/LICENSE @@ -0,0 +1,373 @@ +Mozilla Public License Version 2.0 +================================== + +1. Definitions +-------------- + +1.1. "Contributor" + means each individual or legal entity that creates, contributes to + the creation of, or owns Covered Software. + +1.2. "Contributor Version" + means the combination of the Contributions of others (if any) used + by a Contributor and that particular Contributor's Contribution. + +1.3. "Contribution" + means Covered Software of a particular Contributor. + +1.4. "Covered Software" + means Source Code Form to which the initial Contributor has attached + the notice in Exhibit A, the Executable Form of such Source Code + Form, and Modifications of such Source Code Form, in each case + including portions thereof. + +1.5. "Incompatible With Secondary Licenses" + means + + (a) that the initial Contributor has attached the notice described + in Exhibit B to the Covered Software; or + + (b) that the Covered Software was made available under the terms of + version 1.1 or earlier of the License, but not also under the + terms of a Secondary License. + +1.6. "Executable Form" + means any form of the work other than Source Code Form. + +1.7. "Larger Work" + means a work that combines Covered Software with other material, in + a separate file or files, that is not Covered Software. + +1.8. "License" + means this document. + +1.9. "Licensable" + means having the right to grant, to the maximum extent possible, + whether at the time of the initial grant or subsequently, any and + all of the rights conveyed by this License. + +1.10. "Modifications" + means any of the following: + + (a) any file in Source Code Form that results from an addition to, + deletion from, or modification of the contents of Covered + Software; or + + (b) any new file in Source Code Form that contains any Covered + Software. + +1.11. "Patent Claims" of a Contributor + means any patent claim(s), including without limitation, method, + process, and apparatus claims, in any patent Licensable by such + Contributor that would be infringed, but for the grant of the + License, by the making, using, selling, offering for sale, having + made, import, or transfer of either its Contributions or its + Contributor Version. + +1.12. "Secondary License" + means either the GNU General Public License, Version 2.0, the GNU + Lesser General Public License, Version 2.1, the GNU Affero General + Public License, Version 3.0, or any later versions of those + licenses. + +1.13. "Source Code Form" + means the form of the work preferred for making modifications. + +1.14. "You" (or "Your") + means an individual or a legal entity exercising rights under this + License. For legal entities, "You" includes any entity that + controls, is controlled by, or is under common control with You. For + purposes of this definition, "control" means (a) the power, direct + or indirect, to cause the direction or management of such entity, + whether by contract or otherwise, or (b) ownership of more than + fifty percent (50%) of the outstanding shares or beneficial + ownership of such entity. + +2. License Grants and Conditions +-------------------------------- + +2.1. Grants + +Each Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) + Licensable by such Contributor to use, reproduce, make available, + modify, display, perform, distribute, and otherwise exploit its + Contributions, either on an unmodified basis, with Modifications, or + as part of a Larger Work; and + +(b) under Patent Claims of such Contributor to make, use, sell, offer + for sale, have made, import, and otherwise transfer either its + Contributions or its Contributor Version. + +2.2. Effective Date + +The licenses granted in Section 2.1 with respect to any Contribution +become effective for each Contribution on the date the Contributor first +distributes such Contribution. + +2.3. Limitations on Grant Scope + +The licenses granted in this Section 2 are the only rights granted under +this License. No additional rights or licenses will be implied from the +distribution or licensing of Covered Software under this License. +Notwithstanding Section 2.1(b) above, no patent license is granted by a +Contributor: + +(a) for any code that a Contributor has removed from Covered Software; + or + +(b) for infringements caused by: (i) Your and any other third party's + modifications of Covered Software, or (ii) the combination of its + Contributions with other software (except as part of its Contributor + Version); or + +(c) under Patent Claims infringed by Covered Software in the absence of + its Contributions. + +This License does not grant any rights in the trademarks, service marks, +or logos of any Contributor (except as may be necessary to comply with +the notice requirements in Section 3.4). + +2.4. Subsequent Licenses + +No Contributor makes additional grants as a result of Your choice to +distribute the Covered Software under a subsequent version of this +License (see Section 10.2) or under the terms of a Secondary License (if +permitted under the terms of Section 3.3). + +2.5. Representation + +Each Contributor represents that the Contributor believes its +Contributions are its original creation(s) or it has sufficient rights +to grant the rights to its Contributions conveyed by this License. + +2.6. Fair Use + +This License is not intended to limit any rights You have under +applicable copyright doctrines of fair use, fair dealing, or other +equivalents. + +2.7. Conditions + +Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted +in Section 2.1. + +3. Responsibilities +------------------- + +3.1. Distribution of Source Form + +All distribution of Covered Software in Source Code Form, including any +Modifications that You create or to which You contribute, must be under +the terms of this License. You must inform recipients that the Source +Code Form of the Covered Software is governed by the terms of this +License, and how they can obtain a copy of this License. You may not +attempt to alter or restrict the recipients' rights in the Source Code +Form. + +3.2. Distribution of Executable Form + +If You distribute Covered Software in Executable Form then: + +(a) such Covered Software must also be made available in Source Code + Form, as described in Section 3.1, and You must inform recipients of + the Executable Form how they can obtain a copy of such Source Code + Form by reasonable means in a timely manner, at a charge no more + than the cost of distribution to the recipient; and + +(b) You may distribute such Executable Form under the terms of this + License, or sublicense it under different terms, provided that the + license for the Executable Form does not attempt to limit or alter + the recipients' rights in the Source Code Form under this License. + +3.3. Distribution of a Larger Work + +You may create and distribute a Larger Work under terms of Your choice, +provided that You also comply with the requirements of this License for +the Covered Software. If the Larger Work is a combination of Covered +Software with a work governed by one or more Secondary Licenses, and the +Covered Software is not Incompatible With Secondary Licenses, this +License permits You to additionally distribute such Covered Software +under the terms of such Secondary License(s), so that the recipient of +the Larger Work may, at their option, further distribute the Covered +Software under the terms of either this License or such Secondary +License(s). + +3.4. Notices + +You may not remove or alter the substance of any license notices +(including copyright notices, patent notices, disclaimers of warranty, +or limitations of liability) contained within the Source Code Form of +the Covered Software, except that You may alter any license notices to +the extent required to remedy known factual inaccuracies. + +3.5. Application of Additional Terms + +You may choose to offer, and to charge a fee for, warranty, support, +indemnity or liability obligations to one or more recipients of Covered +Software. However, You may do so only on Your own behalf, and not on +behalf of any Contributor. You must make it absolutely clear that any +such warranty, support, indemnity, or liability obligation is offered by +You alone, and You hereby agree to indemnify every Contributor for any +liability incurred by such Contributor as a result of warranty, support, +indemnity or liability terms You offer. You may include additional +disclaimers of warranty and limitations of liability specific to any +jurisdiction. + +4. Inability to Comply Due to Statute or Regulation +--------------------------------------------------- + +If it is impossible for You to comply with any of the terms of this +License with respect to some or all of the Covered Software due to +statute, judicial order, or regulation then You must: (a) comply with +the terms of this License to the maximum extent possible; and (b) +describe the limitations and the code they affect. Such description must +be placed in a text file included with all distributions of the Covered +Software under this License. Except to the extent prohibited by statute +or regulation, such description must be sufficiently detailed for a +recipient of ordinary skill to be able to understand it. + +5. Termination +-------------- + +5.1. The rights granted under this License will terminate automatically +if You fail to comply with any of its terms. However, if You become +compliant, then the rights granted under this License from a particular +Contributor are reinstated (a) provisionally, unless and until such +Contributor explicitly and finally terminates Your grants, and (b) on an +ongoing basis, if such Contributor fails to notify You of the +non-compliance by some reasonable means prior to 60 days after You have +come back into compliance. Moreover, Your grants from a particular +Contributor are reinstated on an ongoing basis if such Contributor +notifies You of the non-compliance by some reasonable means, this is the +first time You have received notice of non-compliance with this License +from such Contributor, and You become compliant prior to 30 days after +Your receipt of the notice. + +5.2. If You initiate litigation against any entity by asserting a patent +infringement claim (excluding declaratory judgment actions, +counter-claims, and cross-claims) alleging that a Contributor Version +directly or indirectly infringes any patent, then the rights granted to +You by any and all Contributors for the Covered Software under Section +2.1 of this License shall terminate. + +5.3. In the event of termination under Sections 5.1 or 5.2 above, all +end user license agreements (excluding distributors and resellers) which +have been validly granted by You or Your distributors under this License +prior to termination shall survive termination. + +************************************************************************ +* * +* 6. Disclaimer of Warranty * +* ------------------------- * +* * +* Covered Software is provided under this License on an "as is" * +* basis, without warranty of any kind, either expressed, implied, or * +* statutory, including, without limitation, warranties that the * +* Covered Software is free of defects, merchantable, fit for a * +* particular purpose or non-infringing. The entire risk as to the * +* quality and performance of the Covered Software is with You. * +* Should any Covered Software prove defective in any respect, You * +* (not any Contributor) assume the cost of any necessary servicing, * +* repair, or correction. This disclaimer of warranty constitutes an * +* essential part of this License. No use of any Covered Software is * +* authorized under this License except under this disclaimer. * +* * +************************************************************************ + +************************************************************************ +* * +* 7. Limitation of Liability * +* -------------------------- * +* * +* Under no circumstances and under no legal theory, whether tort * +* (including negligence), contract, or otherwise, shall any * +* Contributor, or anyone who distributes Covered Software as * +* permitted above, be liable to You for any direct, indirect, * +* special, incidental, or consequential damages of any character * +* including, without limitation, damages for lost profits, loss of * +* goodwill, work stoppage, computer failure or malfunction, or any * +* and all other commercial damages or losses, even if such party * +* shall have been informed of the possibility of such damages. This * +* limitation of liability shall not apply to liability for death or * +* personal injury resulting from such party's negligence to the * +* extent applicable law prohibits such limitation. Some * +* jurisdictions do not allow the exclusion or limitation of * +* incidental or consequential damages, so this exclusion and * +* limitation may not apply to You. * +* * +************************************************************************ + +8. Litigation +------------- + +Any litigation relating to this License may be brought only in the +courts of a jurisdiction where the defendant maintains its principal +place of business and such litigation shall be governed by laws of that +jurisdiction, without reference to its conflict-of-law provisions. +Nothing in this Section shall prevent a party's ability to bring +cross-claims or counter-claims. + +9. Miscellaneous +---------------- + +This License represents the complete agreement concerning the subject +matter hereof. If any provision of this License is held to be +unenforceable, such provision shall be reformed only to the extent +necessary to make it enforceable. Any law or regulation which provides +that the language of a contract shall be construed against the drafter +shall not be used to construe this License against a Contributor. + +10. Versions of the License +--------------------------- + +10.1. New Versions + +Mozilla Foundation is the license steward. Except as provided in Section +10.3, no one other than the license steward has the right to modify or +publish new versions of this License. Each version will be given a +distinguishing version number. + +10.2. Effect of New Versions + +You may distribute the Covered Software under the terms of the version +of the License under which You originally received the Covered Software, +or under the terms of any subsequent version published by the license +steward. + +10.3. Modified Versions + +If you create software not governed by this License, and you want to +create a new license for such software, you may create and use a +modified version of this License if you rename the license and remove +any references to the name of the license steward (except to note that +such modified license differs from this License). + +10.4. Distributing Source Code Form that is Incompatible With Secondary +Licenses + +If You choose to distribute Source Code Form that is Incompatible With +Secondary Licenses under the terms of this version of the License, the +notice described in Exhibit B of this License must be attached. + +Exhibit A - Source Code Form License Notice +------------------------------------------- + + This Source Code Form is subject to the terms of the Mozilla Public + License, v. 2.0. If a copy of the MPL was not distributed with this + file, You can obtain one at http://mozilla.org/MPL/2.0/. + +If it is not possible or desirable to put the notice in a particular +file, then You may include the notice in a location (such as a LICENSE +file in a relevant directory) where a recipient would be likely to look +for such a notice. + +You may add additional accurate notices of copyright ownership. + +Exhibit B - "Incompatible With Secondary Licenses" Notice +--------------------------------------------------------- + + This Source Code Form is "Incompatible With Secondary Licenses", as + defined by the Mozilla Public License, v. 2.0. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/README.md new file mode 100644 index 00000000..27d1162e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/README.md @@ -0,0 +1,16 @@ +![Compile Examples](https://github.com/arduino-libraries/Arduino_EdgeControl/actions/workflows/compile-examples.yml/badge.svg) + +# Arduino_EdgeControl + +Arduino Library for Arduino Edge Control + +## License + +Copyright (C) 2021 Arduino AG (http://www.arduino.cc/) + +SPDX-License-Identifier: MPL-2.0 + + +This Source Code Form is subject to the terms of the Mozilla Public +License, v. 2.0. If a copy of the MPL was not distributed with this +file, You can obtain one at https://mozilla.org/MPL/2.0/. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/3WiresValve/3WiresValve.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/3WiresValve/3WiresValve.ino new file mode 100644 index 00000000..6503ccb5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/3WiresValve/3WiresValve.ino @@ -0,0 +1,30 @@ +#include + +void setup() +{ + Serial.begin(9600); + while(!Serial); + + delay(1000); + + Serial.println("3-Wire Valve Demo"); + + EdgeControl.begin(); + Latching.begin(); + + Serial.println("Starting"); +} + +void loop() +{ + Serial.println("Closing"); + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(4500); + + delay(2500); + + Serial.println("Opening"); + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(4500); + delay(2500); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.cpp new file mode 100644 index 00000000..68a704dc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.cpp @@ -0,0 +1,83 @@ +#include "AlarmTasks.h" + +/** +* Parse a task line from the alarmtab.txt file +* +* Lines must follow the following structure. +* +* The name of the command to execute must match an entry +* in the 'commandMap' map defined in the CustomTasks.h file. +* +* In case of TR, TO and RO alarm types, the day of week, hour +* and minute parameters are ignored. +* In case of RO alarm type, the second parameters must bean UNIX +* specified as UNIX timestamp (seconds since EPOCH). +* +* See the TimeAlarms (https://github.com/PaulStoffregen/TimeAlarms) +* docs for further specs. +* +* Lines starting with pound symbol (#) are ignored. +* +* +* ┌──────────── alarm type: AR == AlarmRepeat, AO == AlarmOnce, +* | TR == TimerRepeat, TO == TimerOnne, +* | RO == TriggerOnce +* | ┌────────── day of week: 0 == None, 1 == Sun, ..., 7 == Sat +* | | ┌─────── hour +* | | | ┌──── minute +* | | | | ┌─ second +* | | | | | +* | | | | | +* AR 0 18 45 0 OpenLatchingValve +* AR 0 18 45 30 CloseLatchingValve +* AR 0 18 46 0 OpenLatchingValve +* AR 0 18 46 30 CloseLatchingValve +* TR 0 0 0 20 DisplayClock +* TR 0 0 0 10 BlinkLed +* TO 0 0 0 10 DisplayClockOnce +* RO 0 0 0 1602759860 DisplayClockTrigger +* +*/ +AlarmTask parseAlarmTask(const String line) +{ + auto const len { line.length() + 1 }; + char buf[len] { 0 }; + char cmd[32] { 0 }; + char method[3] { 0 }; + + AlarmTask task; + + line.toCharArray(buf, len); + auto n = sscanf(buf, "%s %d %d %d %d %s", method, &task.day, &task.hour, &task.min, &task.sec, cmd); + if (n != 6) + return task; + + auto itm = alarmMethods.find(method); + if (itm != alarmMethods.end()) + task.method = itm->second; + + auto itc = commandMap.find(cmd); + if (itc != commandMap.end()) + task.handler = itc->second; + + return task; +} + +/** + * Parse the alarmtab.txt file + */ +std::list parseAlarmTab(File& file) +{ + std::list taskList; + + while (file.available()) { + auto line = file.readStringUntil('\n'); + if ( line.charAt(0) == '#' ) + continue; + auto task = parseAlarmTask(line); + if (task.handler != nullptr && task.method != METHOD_INVALID) + taskList.push_back(task); + } + + return taskList; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.h new file mode 100644 index 00000000..cfa16d22 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/AlarmTasks.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + +#include "CustomTasks.h" + +/** + * Supported alarm types + */ +enum AlarmMethod { + METHOD_INVALID, + ALARM_REPEAT, + ALARM_ONCE, + TIMER_REPEAT, + TIMER_ONCE, + TRIGGER_ONCE, +}; + +/** + * The internal structure for managing tasks + */ +struct AlarmTask { + AlarmMethod method { METHOD_INVALID }; + OnTick_t handler { nullptr }; + timeDayOfWeek_t day; + int hour; + int min; + int sec; +}; + +/** + * An helper map for parsing alarm types from alarmtab lines + */ +static std::map alarmMethods { + {"AR", ALARM_REPEAT}, + {"AO", ALARM_ONCE}, + {"TR", TIMER_REPEAT}, + {"TO", TIMER_ONCE}, + {"RO", TRIGGER_ONCE}, +}; + +/** + * Parse a task line from the alarmtab.txt file + */ +AlarmTask parseAlarmTask(const String line); + +/** + * Parse the alarmtab.txt file + */ +std::list parseAlarmTab(File& file); diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.cpp new file mode 100644 index 00000000..cf415a6d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.cpp @@ -0,0 +1,116 @@ +#include "CustomTasks.h" + +void openLatchingValve() +{ + Serial.println("Alarm: Opening Latching Valve"); + + Serial.print("["); + Serial.print(getLocaltime()); + Serial.print("] Opening Valve: "); + + // Polarize the opening pin of the 3-wires valve + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(5000); + + Serial.println("Valve Open"); +} + +void closeLatchingValve() +{ + Serial.println("Alarm: Closing Latching Valve"); + + Serial.print("["); + Serial.print(getLocaltime()); + Serial.print("] Closing Valve: "); + + // Polarize the closing pin of the 3-wires valve + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(5000); + + Serial.println("Valve Closed"); +} + +void openSolenoidValve() +{ + Serial.println("Alarm: Opening Solenoid Valve"); + + Serial.print("["); + Serial.print(getLocaltime()); + Serial.print("] Opening Valve: "); + + // Open the Solid State Relay on Channel 1 + Relay.on(RELAY_CH01); + + Serial.println("Valve Open"); +} + +void closeSolenoidValve() +{ + Serial.println("Alarm: Closing Solenoid Valve"); + + Serial.print("["); + Serial.print(getLocaltime()); + Serial.print("] Closing Valve: "); + + // Close the Solid State Relay on Channel 1 + Relay.off(RELAY_CH01); + + Serial.println("Valve Closed"); +} + +void displayClock() +{ + String date = getLocaltime("%Y-%m-%d", true, 0); + String time = getLocaltime("%k:%M:%S", true, 0); + Serial.println(date); + Serial.println(time); +} + +void blinkLed() +{ + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, LOW); + delay(10); + + // Power off the on-board LED (active low) + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, HIGH); +} + +void getSensors() +{ + extern std::list dataPoints; + + Serial.print("Moisture: "); + + auto value = getAverageInputRead(INPUT_05V_CH01); + auto perc = getMoisturePerc(INPUT_05V_CH01); + + DataPoint d{value, perc}; + + Serial.println(d); + dataPoints.push_back(d); +} + +void saveData() +{ + Serial.println("Saving Data..."); + + auto ret = saveSensorsData(); + if (ret <= 0) + Serial.print("Error: "); + else + Serial.print("Saved: "); + + Serial.println(ret); +} + +void helloWorld() +{ + Serial.println("Hello, World!"); +} + +void hiThere() +{ + Serial.println("Hi, There!"); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.h new file mode 100644 index 00000000..bf03a87d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/CustomTasks.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +#include "Helpers.h" +#include "SensorsData.h" +#include "TimeHelpers.h" + +void openLatchingValve(); +void closeLatchingValve(); +void openSolenoidValve(); +void closeSolenoidValve(); +void displayClock(); +void blinkLed(); +void saveData(); +void helloWorld(); +void hiThere(); +void getSensors(); + +/** + * Define your task function and add it to the commandMap. + * The key of the map is the name to be used in the alarmtab file. + */ +static std::map commandMap { + { "OpenLatchingValve", openLatchingValve }, + { "CloseLatchingValve", closeLatchingValve }, + { "OpenSolenoidValve", openSolenoidValve }, + { "CloseSolenoidValve", closeSolenoidValve }, + { "DisplayClock", displayClock }, + { "BlinkLed", blinkLed }, + { "SaveData", saveData }, + { "HelloWorld", helloWorld }, + { "HiThere", hiThere }, + { "GetSensors", getSensors }, +}; \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.cpp new file mode 100644 index 00000000..b426cae7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.cpp @@ -0,0 +1,110 @@ +#include "Helpers.h" + +/** + * Set system and TimeAlarm clock from compile datetime or RTC + */ +void setSystemClock(String buildDate, String buildTime) +{ + // Retrieve clock time from compile date... + auto buildDateTime = buildDateTimeToSystemTime(buildDate, buildTime, true, 2); + // ... ore use the one from integrated RTC. + auto rtcTime = time(NULL); + + // Remember to connect at least the CR2032 battery + // to keep the RTC running. + auto actualTime = rtcTime > buildDateTime ? rtcTime : buildDateTime; + + // Set both system time and the alarms one + set_time(actualTime); + setTime(actualTime); + + Serial.print("Compile Date and Time: "); + Serial.println(getLocaltime(buildDateTime)); + Serial.print("RTC Date and Time: "); + Serial.println(getLocaltime(rtcTime)); + Serial.print("System Clock: "); + Serial.println(getLocaltime()); +} + +void statusPrint() +{ + String msg; + + Serial.println("Measures..."); + + msg = "Moisture ["; + msg += dataPoints.size(); + msg += "]"; + Serial.println(msg); + + msg = "Latest: "; + auto d = dataPoints.back(); + msg += d.moistureP; + msg += "%"; + Serial.println(msg); + + Serial.println("Loaded Tasks..."); + + msg = "Custom: "; + msg += alarmTabIDs.size(); + Serial.println(msg); + + msg = "Sketch: "; + msg += alarmSketchIDs.size(); + Serial.println(msg); +} + +float getAverage05VRead(int pin) +{ + constexpr size_t loops { 10 }; + constexpr float toV { 3.3f / float { (1 << ADC_RESOLUTION) - 1 } }; + + // Resistor divider on Input ports + constexpr float rDiv { 17.4f / (10.0f + 17.4f) }; + + int tot { 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return avg / rDiv; +} + +uint16_t getAverageInputRead(int pin, const size_t loops) +{ + unsigned int tot { 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + return tot / loops; +} + +uint8_t getMoisturePerc(int pin) +{ + // Keep track ok dry/wet values. YMMV. + static long dryValue { 2160 }; + static long wetValue { 975 }; + + auto val = getAverageInputRead(pin); + + // Self-update dry/wet values range. + if (val > dryValue) + dryValue = val; + if (val < wetValue) + wetValue = val; + + auto perc = map(val, dryValue, wetValue, 0, 100); + + return static_cast(perc); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.h new file mode 100644 index 00000000..dd3153e0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/Helpers.h @@ -0,0 +1,20 @@ +#pragma once + +#include "SensorsData.h" +#include "TimeHelpers.h" +#include +#include +#include + +#include +#include + +void setSystemClock(String date = __DATE__, String time = __TIME__); +void statusPrint(); +uint16_t getAverageInputRead(int pin, size_t loops = 20); +float getAverage05VRead(int pin); +uint8_t getMoisturePerc(int pin); + +extern std::list alarmTabIDs; +extern std::list alarmSketchIDs; +extern std::list dataPoints; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/IrrigationSimple.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/IrrigationSimple.ino new file mode 100644 index 00000000..4ee74ac1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/IrrigationSimple.ino @@ -0,0 +1,178 @@ +/** + * Simple irrigation system with Arduino EdgeControl + * + * Circuit: + * - Arduino EdgeControl + * - MicroSD card + * - CR2032 Battery and/or 12V Lead Battery + * - Button connected to POWER_ON pin on the LCD breakout header + * + * Usage: + * - Define your callback functions in CustomTasks.{h,cpp} + * - Map the callback functions to alarmatab command names in + * CustomTasks.h::commandMap map. + * - Add tasks to the alarmtab.txt file and copy it on the SD card; + * See alarmtab.txt and AlarmTasks.cpp for documentation. + */ + +#include + +#include "AlarmTasks.h" +#include "SensorsData.h" +#include "TimeHelpers.h" +#include "TasksHelpers.h" +#include "Helpers.h" + +/** UI Management **/ +// Button statuses +enum ButtonStatus : byte { + ZERO_TAP, + SINGLE_TAP, + DOUBLE_TAP, + TRIPLE_TAP, + LOT_OF_TAPS +}; + +// ISR: count the button taps +volatile byte taps { 0 }; +// ISR: keep elapsed timings +volatile unsigned long previousPress { 0 }; +// ISR: Final button status +volatile ButtonStatus buttonStatus { ZERO_TAP }; + +/** + * Used to keep track of the running alarms from + * alarmtab.txt. + * + * The loadAndSetTasks() function will fill this + * with tasks defined in CustomTasks.{h.cpp} and + * loaded from the alarmtab.txt on the SD. + * + */ +std::list alarmTabIDs; + +/** + * Used to keep track of the alarms defined in the + * sketch. + */ +std::list alarmSketchIDs; + +/** + * Used to keep track of the measurements points + */ +std::list dataPoints; + +void setup() +{ + Serial.begin(9600); + constexpr unsigned long timeout { 2500 }; + + // Wait for Serial Monitor for timeout ms + auto startNow = millis() + timeout; + while (!Serial && millis() < startNow ) + ; + + delay(1000); + + // Set System and Alarm clock + // Use compile datetime as proxy clock synch + // Use a CR2032 battery for persistent RTC. + setSystemClock(); + + // Init board-related objects + EdgeControl.begin(); + + // Enable the 3V3 and 12V power rails. + // Needed for IO Expander and SD card. + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + // Init the sensors inputs. + // If needed, will also take care of enabling the + // 3V3 and 12V power rails and to initialize the IO Expander. + Input.begin(); + + Latching.begin(); + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(5000); + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(5000); + + Relay.begin(); + delay(1000); + Relay.on(RELAY_CH01); + delay(5000); + Relay.off(RELAY_CH01); + + // Load alarm tasks list from file on SD. + // See example alarmtab.txt for example and + // AlarmTasks.{h, cpp} source files for documentation. + loadAndSetTasks(alarmTabIDs); + + // Use the a button for housekeeping stuff: + // Single Tap: Show status + // Double Tap: Reload alarm tasks from SD + // Triple Tap: Force saving data to SD + pinMode(POWER_ON, INPUT); + attachInterrupt(POWER_ON, buttonPress, RISING); + + auto id = Alarm.timerRepeat(10, getSensors); + alarmSketchIDs.push_back(id); +} + +void loop() +{ + // Do alarms processing + Alarm.delay(10); + + // Detect Single Tap, Double Tap, etc. + // to buttonStatus + detectTaps(); + + switch (buttonStatus) { + case ZERO_TAP: + break; + case SINGLE_TAP: + Serial.println("Single Tap"); + statusPrint(); + buttonStatus = ZERO_TAP; + break; + case DOUBLE_TAP: + Serial.println("Double Tap"); + loadAndSetTasks(alarmTabIDs, true); + buttonStatus = ZERO_TAP; + break; + case TRIPLE_TAP: + Serial.println("Triple Tap"); + saveData(); + buttonStatus = ZERO_TAP; + break; + default: + Serial.println("Too Many Taps"); + buttonStatus = ZERO_TAP; + break; + } +} + +void buttonPress() +{ + const auto now = millis(); + // Poor-man debouncing + if (now - previousPress > 100) + taps++; + + previousPress = now; +} + +void detectTaps() +{ + // Timeout to validate the button taps counter + constexpr unsigned int buttonTapsTimeout { 300 }; + + // Set the button status and reset the taps counter when button has been + // pressed at least once and button taps validation timeout has been reached. + if (taps > 0 && millis() - previousPress >= buttonTapsTimeout) { + buttonStatus = static_cast(taps); + taps = 0; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.cpp new file mode 100644 index 00000000..a1ea934b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.cpp @@ -0,0 +1,48 @@ +#include "SensorsData.h" + +DataPoint::DataPoint(uint16_t moistureA, uint8_t moistureP) + : ts(time(nullptr)) + , moistureA(moistureA) + , moistureP(moistureP) +{ +} + +size_t DataPoint::printTo(Print& p) const +{ + size_t written { 0 }; + + written += p.print((unsigned long)ts); + written += p.print(','); + written += p.print(moistureA); + written += p.print(','); + written += p.print(moistureP); + + return written; +} + +int saveSensorsData() +{ + extern std::list dataPoints; + + unsigned int count { 0 }; + + if (!SD.begin(PIN_SD_CS)) + return -2; + + auto dataLog = SD.open("datalog.csv", FILE_WRITE); + if (!dataLog) + return -1; + + for (auto d = dataPoints.begin(); d != dataPoints.end(); ++d) { + auto bytes = dataLog.println(*d); + if (bytes == 0) // if write failed, don't erase + continue; + count++; + dataPoints.erase(d); + } + + dataLog.close(); + SD.end(); + + return count; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.h new file mode 100644 index 00000000..384ead5d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/SensorsData.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +struct DataPoint: Printable { + time_t ts; + uint16_t moistureA; + uint8_t moistureP; + + DataPoint(uint16_t moistureA, uint8_t moistureP); + + virtual size_t printTo(Print& p) const; + +}; + +int saveSensorsData(); diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.cpp new file mode 100644 index 00000000..43d5c5c9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.cpp @@ -0,0 +1,138 @@ +#include "TasksHelpers.h" + +/** + * Load alarm task from parsed alarmtab.txt file on SD. + */ +std::list loadTasks() +{ + if (!SD.begin(PIN_SD_CS)) { + Serial.println("SD initialization failed"); + while (true) + ; + } + auto alarmtab = SD.open("alarmtab.txt"); + auto taskList = parseAlarmTab(alarmtab); + + alarmtab.close(); + SD.end(); + + return taskList; +} + +/** + * Set the alarm tasks from the loaded list. + */ +std::list setTasks(std::list taskList) +{ + AlarmID_t alarmID { dtINVALID_ALARM_ID }; + std::list alarmIDs; + + for (auto& task : taskList) { + switch (task.method) { + case ALARM_REPEAT: { + if (task.day == 0) + alarmID = Alarm.alarmRepeat(task.hour, task.min, task.sec, task.handler); + else + alarmID = Alarm.alarmRepeat(task.day, task.hour, task.min, task.sec, task.handler); + break; + } + case ALARM_ONCE: { + if (task.day == 0) + alarmID = Alarm.alarmOnce(task.hour, task.min, task.sec, task.handler); + else + alarmID = Alarm.alarmOnce(task.day, task.hour, task.min, task.sec, task.handler); + break; + } + case TIMER_REPEAT: { + alarmID = Alarm.timerRepeat(task.sec, task.handler); + break; + } + case TIMER_ONCE: { + alarmID = Alarm.timerOnce(task.sec, task.handler); + break; + } + case TRIGGER_ONCE: { + alarmID = Alarm.triggerOnce(task.sec, task.handler); + break; + } + default: + break; + } + alarmIDs.push_back(alarmID); + } + + return alarmIDs; +} + +/** + * Free the current alarm tasks + */ +void freeTasks(std::list& alarmIDs) +{ + for (auto& id : alarmIDs) { + Alarm.free(id); + id = dtINVALID_ALARM_ID; + } +} + +/** + * Load and set tasks from alarmtab.txt file. + * + * Remove previously loaded tasks if parameter is true. + */ +void loadAndSetTasks(std::list& alarmIDs, bool reload) +{ + if (reload) { + Serial.println("Reloading Tasks: "); + freeTasks(alarmIDs); + } else { + Serial.println("Loading Tasks: "); + } + + auto taskList = loadTasks(); + alarmIDs = setTasks(taskList); + printTasks(taskList); + + Serial.print(alarmIDs.size()); + Serial.println(" loaded"); +} + +void printTasks(const std::list taskList) +{ + for (auto const task : taskList) { + Serial.print("- "); + switch (task.method) { + case ALARM_REPEAT: + Serial.print("ALARM_REPEAT"); + break; + case ALARM_ONCE: + Serial.print("ALARM_ONCE"); + break; + case TIMER_REPEAT: + Serial.print("TIMER_REPEAT"); + break; + case TIMER_ONCE: + Serial.print("TIMER_ONCE"); + break; + case TRIGGER_ONCE: + Serial.print("TRIGGER_ONCE"); + break; + default: + Serial.print("UNKNOWN"); + break; + } + Serial.print(" "); + Serial.print(task.day); + Serial.print(" "); + Serial.print(task.hour); + Serial.print(" "); + Serial.print(task.min); + Serial.print(" "); + Serial.print(task.sec); + Serial.print(" "); + Serial.println((uint64_t)(task.handler), HEX); + } + + Serial.print(taskList.size()); + Serial.println(" tasks loaded."); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.h new file mode 100644 index 00000000..d316d925 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TasksHelpers.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include + +#include "AlarmTasks.h" + +std::list loadTasks(); +std::list setTasks(std::list taskList); +void freeTasks(std::list& alarmIDs); +void loadAndSetTasks(std::list& alarmIDs, bool reload = false); +void printTasks(const std::list taskList); + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.cpp new file mode 100644 index 00000000..9162b6b9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.cpp @@ -0,0 +1,101 @@ +#include "TimeHelpers.h" + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String date, const String time, bool local_time = true, int tz = 0) +{ + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + sscanf(date.c_str(), "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(time.c_str(), "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) + { + if (tz > 200) + { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } + else + { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t &build_time) +{ + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char *fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) + { + if (tz > 200) + { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } + else + { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char *fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) + { + if (tz > 200) + { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } + else + { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.h new file mode 100644 index 00000000..31646165 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/TimeHelpers.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String, const String, bool local_time, int tz); +String getLocaltime(); +String getLocaltime(const time_t &build_time); +String getLocaltime(const char *fmt, bool local_time, int); +String getLocaltime(const time_t build_time, const char *fmt, bool local_time, int tz); diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/alarmtab.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/alarmtab.txt new file mode 100644 index 00000000..934a3bbe --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimple/alarmtab.txt @@ -0,0 +1,23 @@ +#┌──────────── alarm type: AR == AlarmRepeat, AO == AlarmOnce, +#| TR == TimerRepeat, TO == TimerOnce, +#| RO == TriggerOnce +#| See TimeAlarms (https://github.com/PaulStoffregen/TimeAlarms) for specs +#| ┌────────── day of week: 0 == None, 1 == Sun, ..., 7 == Sat +#| | ┌─────── hour +#| | | ┌──── minute +#| | | | ┌─ second +#| | | | | +#| | | | | +AR 0 15 55 0 OpenLatchingValve +AR 0 15 55 30 CloseLatchingValve +AR 0 15 56 0 OpenLatchingValve +AR 0 15 56 30 CloseLatchingValve +AR 0 15 57 0 OpenSolenoidValve +AR 0 15 57 30 CloseSolenoidValve +AR 0 15 58 0 OpenSolenoidValve +AR 0 15 58 30 CloseSolenoidValve +TR 0 0 0 300 SaveData +TR 0 0 0 60 DisplayClock +TR 0 0 0 30 BlinkLed +TO 0 0 0 10 HelloWorld +RO 0 0 0 1603895279 HiThere \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.cpp new file mode 100644 index 00000000..68a704dc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.cpp @@ -0,0 +1,83 @@ +#include "AlarmTasks.h" + +/** +* Parse a task line from the alarmtab.txt file +* +* Lines must follow the following structure. +* +* The name of the command to execute must match an entry +* in the 'commandMap' map defined in the CustomTasks.h file. +* +* In case of TR, TO and RO alarm types, the day of week, hour +* and minute parameters are ignored. +* In case of RO alarm type, the second parameters must bean UNIX +* specified as UNIX timestamp (seconds since EPOCH). +* +* See the TimeAlarms (https://github.com/PaulStoffregen/TimeAlarms) +* docs for further specs. +* +* Lines starting with pound symbol (#) are ignored. +* +* +* ┌──────────── alarm type: AR == AlarmRepeat, AO == AlarmOnce, +* | TR == TimerRepeat, TO == TimerOnne, +* | RO == TriggerOnce +* | ┌────────── day of week: 0 == None, 1 == Sun, ..., 7 == Sat +* | | ┌─────── hour +* | | | ┌──── minute +* | | | | ┌─ second +* | | | | | +* | | | | | +* AR 0 18 45 0 OpenLatchingValve +* AR 0 18 45 30 CloseLatchingValve +* AR 0 18 46 0 OpenLatchingValve +* AR 0 18 46 30 CloseLatchingValve +* TR 0 0 0 20 DisplayClock +* TR 0 0 0 10 BlinkLed +* TO 0 0 0 10 DisplayClockOnce +* RO 0 0 0 1602759860 DisplayClockTrigger +* +*/ +AlarmTask parseAlarmTask(const String line) +{ + auto const len { line.length() + 1 }; + char buf[len] { 0 }; + char cmd[32] { 0 }; + char method[3] { 0 }; + + AlarmTask task; + + line.toCharArray(buf, len); + auto n = sscanf(buf, "%s %d %d %d %d %s", method, &task.day, &task.hour, &task.min, &task.sec, cmd); + if (n != 6) + return task; + + auto itm = alarmMethods.find(method); + if (itm != alarmMethods.end()) + task.method = itm->second; + + auto itc = commandMap.find(cmd); + if (itc != commandMap.end()) + task.handler = itc->second; + + return task; +} + +/** + * Parse the alarmtab.txt file + */ +std::list parseAlarmTab(File& file) +{ + std::list taskList; + + while (file.available()) { + auto line = file.readStringUntil('\n'); + if ( line.charAt(0) == '#' ) + continue; + auto task = parseAlarmTask(line); + if (task.handler != nullptr && task.method != METHOD_INVALID) + taskList.push_back(task); + } + + return taskList; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.h new file mode 100644 index 00000000..cfa16d22 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/AlarmTasks.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include +#include + +#include +#include +#include + +#include "CustomTasks.h" + +/** + * Supported alarm types + */ +enum AlarmMethod { + METHOD_INVALID, + ALARM_REPEAT, + ALARM_ONCE, + TIMER_REPEAT, + TIMER_ONCE, + TRIGGER_ONCE, +}; + +/** + * The internal structure for managing tasks + */ +struct AlarmTask { + AlarmMethod method { METHOD_INVALID }; + OnTick_t handler { nullptr }; + timeDayOfWeek_t day; + int hour; + int min; + int sec; +}; + +/** + * An helper map for parsing alarm types from alarmtab lines + */ +static std::map alarmMethods { + {"AR", ALARM_REPEAT}, + {"AO", ALARM_ONCE}, + {"TR", TIMER_REPEAT}, + {"TO", TIMER_ONCE}, + {"RO", TRIGGER_ONCE}, +}; + +/** + * Parse a task line from the alarmtab.txt file + */ +AlarmTask parseAlarmTask(const String line); + +/** + * Parse the alarmtab.txt file + */ +std::list parseAlarmTab(File& file); diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.cpp new file mode 100644 index 00000000..3241791d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.cpp @@ -0,0 +1,156 @@ +#include "CustomTasks.h" + +void openLatchingValve() +{ + Serial.println("Alarm: Opening Latching Valve"); + + LCD.home(); + LCD.backlight(); + LCD.print(getLocaltime()); + LCD.setCursor(0, 1); + LCD.print("Opening Valve "); + + // Polarize the opening pin of the 3-wires valve + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(5000); + + LCD.setCursor(0, 1); + LCD.print("Valve Open "); + + // Power off the backlight after 5 seconds + Alarm.timerOnce(5, [] { backlightOff(false); }); +} + +void closeLatchingValve() +{ + Serial.println("Alarm: Closing Latching Valve"); + + LCD.home(); + LCD.backlight(); + LCD.print(getLocaltime()); + LCD.setCursor(0, 1); + LCD.print("Closing Valve "); + + // Polarize the closing pin of the 3-wires valve + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(5000); + + LCD.setCursor(0, 1); + LCD.print("Valve Closed "); + + // Power off the backlight after 5 seconds + // and power off everything else + Alarm.timerOnce(5, [] { backlightOff(true); }); +} + +void openSolenoidValve() +{ + Serial.println("Alarm: Opening Solenoid Valve"); + + LCD.home(); + LCD.backlight(); + LCD.print(getLocaltime()); + LCD.setCursor(0, 1); + LCD.print("Opening Valve "); + + // Open the Solid State Relay on Channel 1 + Relay.on(RELAY_CH01); + + LCD.setCursor(0, 1); + LCD.print("Valve Open "); + + // Power off the backlight after 5 seconds + Alarm.timerOnce(5, [] { backlightOff(false); }); +} + +void closeSolenoidValve() +{ + Serial.println("Alarm: Closing Solenoid Valve"); + + LCD.home(); + LCD.backlight(); + LCD.print(getLocaltime()); + LCD.setCursor(0, 1); + LCD.print("Closing Valve "); + + // Close the Solid State Relay on Channel 1 + Relay.off(RELAY_CH01); + + LCD.setCursor(0, 1); + LCD.print("Valve Closed "); + + // Power off the backlight after 5 seconds + // and power off everything else + Alarm.timerOnce(5, [] { backlightOff(true); }); +} + +void displayClock() +{ + String date = getLocaltime("%Y-%m-%d", true, 0); + String time = getLocaltime("%k:%M:%S", true, 0); + displayMsg(date, 0, 0, true, false); + displayMsg(time, 5000, 1, false, true); +} + +void blinkLed() +{ + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, LOW); + delay(10); + + // Power off the on-board LED (active low) + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, HIGH); +} + +void getSensors() +{ + extern std::list dataPoints; + + String msg = "Moisture: "; + Serial.print(msg); + + auto value = getAverageInputRead(INPUT_05V_CH01); + auto perc = getMoisturePerc(INPUT_05V_CH01); + + DataPoint d{value, perc}; + + Serial.println(d); + dataPoints.push_back(d); + + Alarm.timerOnce(5, [] { backlightOff(true); }); +} + +void saveData() +{ + String msg = "Saving Data"; + Serial.println(msg); + LCD.clear(); + LCD.backlight(); + LCD.home(); + LCD.print(msg); + for (auto rem = 16 - msg.length(); rem > 0; rem--) + LCD.write(' '); + + LCD.home(); + LCD.setCursor(0, 1); + auto ret = saveSensorsData(); + if (ret <= 0) + LCD.print("ERROR:"); + else + LCD.print("Saved:"); + + LCD.print(ret); + + Alarm.timerOnce(5, [] { backlightOff(true); }); +} + +void helloWorld() +{ + displayMsg("Hello, World!"); +} + +void hiThere() +{ + displayMsg("Hi, There!"); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.h new file mode 100644 index 00000000..bf03a87d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/CustomTasks.h @@ -0,0 +1,42 @@ +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +#include "Helpers.h" +#include "SensorsData.h" +#include "TimeHelpers.h" + +void openLatchingValve(); +void closeLatchingValve(); +void openSolenoidValve(); +void closeSolenoidValve(); +void displayClock(); +void blinkLed(); +void saveData(); +void helloWorld(); +void hiThere(); +void getSensors(); + +/** + * Define your task function and add it to the commandMap. + * The key of the map is the name to be used in the alarmtab file. + */ +static std::map commandMap { + { "OpenLatchingValve", openLatchingValve }, + { "CloseLatchingValve", closeLatchingValve }, + { "OpenSolenoidValve", openSolenoidValve }, + { "CloseSolenoidValve", closeSolenoidValve }, + { "DisplayClock", displayClock }, + { "BlinkLed", blinkLed }, + { "SaveData", saveData }, + { "HelloWorld", helloWorld }, + { "HiThere", hiThere }, + { "GetSensors", getSensors }, +}; \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.cpp new file mode 100644 index 00000000..2be8900d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.cpp @@ -0,0 +1,180 @@ +#include "Helpers.h" + +/** + * Set system and TimeAlarm clock from compile datetime or RTC + */ +void setSystemClock(String buildDate, String buildTime) +{ + // Retrieve clock time from compile date... + auto buildDateTime = buildDateTimeToSystemTime(buildDate, buildTime, true, 2); + // ... ore use the one from integrated RTC. + auto rtcTime = time(NULL); + + // Remember to connect at least the CR2032 battery + // to keep the RTC running. + auto actualTime = rtcTime > buildDateTime ? rtcTime : buildDateTime; + + // Set both system time and the alarms one + set_time(actualTime); + setTime(actualTime); + + Serial.print("Compile Date and Time: "); + Serial.println(getLocaltime(buildDateTime)); + Serial.print("RTC Date and Time: "); + Serial.println(getLocaltime(rtcTime)); + Serial.print("System Clock: "); + Serial.println(getLocaltime()); +} + +void statusLCD() +{ + // Small helper for waiting without delay() + auto wait = [](size_t timeout) { + for (auto go = millis() + timeout; millis() < go; yield()) + ; + }; + + String msg; + + LCD.clear(); + LCD.backlight(); + + LCD.home(); + LCD.print("Measures..."); + + wait(500); + + LCD.setCursor(16, 0); + msg = "Moisture ["; + msg += dataPoints.size(); + msg += "]"; + LCD.print(msg); + LCD.autoscroll(); + LCD.setCursor(16, 1); + msg = "Latest: "; + auto d = dataPoints.back(); + msg += d.moistureP; + msg += "%"; + + while (msg.length() < 16) + msg += ' '; + + LCD.print(msg); + LCD.noAutoscroll(); + wait(1000); + + LCD.clear(); + LCD.home(); + LCD.print("Loaded Tasks..."); + + wait(500); + + LCD.setCursor(16, 0); + msg = "Custom: "; + msg += alarmTabIDs.size(); + LCD.print(msg); + LCD.autoscroll(); + LCD.setCursor(16, 1); + msg = "Sketch: "; + msg += alarmSketchIDs.size(); + + while (msg.length() < 16) + msg += ' '; + + LCD.print(msg); + LCD.noAutoscroll(); + wait(1000); + + // Power off the backlight after 5 seconds + // and power off everything else + Alarm.timerOnce(5, [] { backlightOff(true); }); +} + +void backlightOff(bool powerDown) +{ + LCD.noBacklight(); + if (powerDown) + LCD.clear(); +} + +float getAverage05VRead(int pin) +{ + constexpr size_t loops { 10 }; + constexpr float toV { 3.3f / float { (1 << ADC_RESOLUTION) - 1 } }; + + // Resistor divider on Input ports + constexpr float rDiv { 17.4f / (10.0f + 17.4f) }; + + int tot { 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return avg / rDiv; +} + +uint16_t getAverageInputRead(int pin, const size_t loops) +{ + unsigned int tot { 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + return tot / loops; +} + +uint8_t getMoisturePerc(int pin) +{ + // Keep track ok dry/wet values. YMMV. + static long dryValue { 2160 }; + static long wetValue { 975 }; + + auto val = getAverageInputRead(pin); + + // Self-update dry/wet values range. + if (val > dryValue) + dryValue = val; + if (val < wetValue) + wetValue = val; + + auto perc = map(val, dryValue, wetValue, 0, 100); + + return perc; +} + +void displayMsg(const String msg, const unsigned timeout, const unsigned line, const bool clear, const bool off) +{ + if (clear) + LCD.clear(); + + LCD.home(); + LCD.backlight(); + + if (line == 1) + LCD.setCursor(0, 1); + + if (msg.length() > 16) + LCD.autoscroll(); + + LCD.print(msg); + + for (auto go = millis() + timeout; millis() < go; yield()) + ; + + LCD.noAutoscroll(); + + if (off) { + LCD.clear(); + LCD.noBacklight(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.h new file mode 100644 index 00000000..ac811a6a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/Helpers.h @@ -0,0 +1,23 @@ +#pragma once + +#include "SensorsData.h" +#include "TimeHelpers.h" +#include +#include +#include +#include + +#include +#include + +void setSystemClock(String date = __DATE__, String time = __TIME__); +void statusLCD(); +void backlightOff(bool powerDown); +uint16_t getAverageInputRead(int pin, size_t loops = 20); +float getAverage05VRead(int pin); +uint8_t getMoisturePerc(int pin); +void displayMsg(const String msg, const unsigned timeout = 5000, const unsigned line = 0, const bool clear = true, const bool off = true); + +extern std::list alarmTabIDs; +extern std::list alarmSketchIDs; +extern std::list dataPoints; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/IrrigationSimpleLCD.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/IrrigationSimpleLCD.ino new file mode 100644 index 00000000..9162e4a5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/IrrigationSimpleLCD.ino @@ -0,0 +1,181 @@ +/** + * Simple irrigation system with Arduino EdgeControl + * + * Circuit: + * - Arduino EdgeControl + * - MicroSD card + * - CR2032 Battery and/or 12V Lead Battery + * + * Usage: + * - Define your callback functions in CustomTasks.{h,cpp} + * - Map the callback functions to alarmatab command names in + * CustomTasks.h::commandMap map. + * - Add tasks to the alarmtab.txt file and copy it on the SD card; + * See alarmtab.txt and AlarmTasks.cpp for documentation. + */ + +#include + +#include "AlarmTasks.h" +#include "SensorsData.h" +#include "TimeHelpers.h" +#include "TasksHelpers.h" +#include "Helpers.h" + +/** UI Management **/ +// Button statuses +enum ButtonStatus : byte { + ZERO_TAP, + SINGLE_TAP, + DOUBLE_TAP, + TRIPLE_TAP, + LOT_OF_TAPS +}; + +// ISR: count the button taps +volatile byte taps { 0 }; +// ISR: keep elapsed timings +volatile unsigned long previousPress { 0 }; +// ISR: Final button status +volatile ButtonStatus buttonStatus { ZERO_TAP }; + +/** + * Used to keep track of the running alarms from + * alarmtab.txt. + * + * The loadAndSetTasks() function will fill this + * with tasks defined in CustomTasks.{h.cpp} and + * loaded from the alarmtab.txt on the SD. + * + */ +std::list alarmTabIDs; + +/** + * Used to keep track of the alarms defined in the + * sketch. + */ +std::list alarmSketchIDs; + +/** + * Used to keep track of the measurements points + */ +std::list dataPoints; + +void setup() +{ + Serial.begin(9600); + constexpr unsigned long timeout { 2500 }; + + // Wait for Serial Monitor for timeout ms + auto startNow = millis() + timeout; + while (!Serial && millis() < startNow ) + ; + + delay(1000); + + // Set System and Alarm clock + // Use compile datetime as proxy clock synch + // Use a CR2032 battery for persistent RTC. + setSystemClock(); + + // Init board-related objects + EdgeControl.begin(); + + // Enable the 3V3 and 12V power rails. + // Needed for IO Expander and SD card. + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + // Init the sensors inputs. + // If needed, will also take care of enabling the + // 3V3 and 12V power rails and to initialize the IO Expander. + Input.begin(); + + Latching.begin(); + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(5000); + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(5000); + + Relay.begin(); + delay(1000); + Relay.on(RELAY_CH01); + delay(5000); + Relay.off(RELAY_CH01); + + // Init the LCD display + LCD.begin(16, 2); + LCD.leftToRight(); + + // Load alarm tasks list from file on SD. + // See example alarmtab.txt for example and + // AlarmTasks.{h, cpp} source files for documentation. + loadAndSetTasks(alarmTabIDs); + + // Use the LCD button for housekeeping stuff: + // Single Tap: Show status + // Double Tap: Reload alarm tasks from SD + // Triple Tap: Force saving data to SD + pinMode(POWER_ON, INPUT); + attachInterrupt(POWER_ON, buttonPress, RISING); + + auto id = Alarm.timerRepeat(10, getSensors); + alarmSketchIDs.push_back(id); +} + +void loop() +{ + // Do alarms processing + Alarm.delay(10); + + // Detect Single Tap, Double Tap, etc. + // to buttonStatus + detectTaps(); + + switch (buttonStatus) { + case ZERO_TAP: + break; + case SINGLE_TAP: + Serial.println("Single Tap"); + statusLCD(); + buttonStatus = ZERO_TAP; + break; + case DOUBLE_TAP: + Serial.println("Double Tap"); + loadAndSetTasks(alarmTabIDs, true); + buttonStatus = ZERO_TAP; + break; + case TRIPLE_TAP: + Serial.println("Triple Tap"); + saveData(); + buttonStatus = ZERO_TAP; + break; + default: + Serial.println("Too Many Taps"); + buttonStatus = ZERO_TAP; + break; + } +} + +void buttonPress() +{ + const auto now = millis(); + // Poor-man debouncing + if (now - previousPress > 100) + taps++; + + previousPress = now; +} + +void detectTaps() +{ + // Timeout to validate the button taps counter + constexpr unsigned int buttonTapsTimeout { 300 }; + + // Set the button status and reset the taps counter when button has been + // pressed at least once and button taps validation timeout has been reached. + if (taps > 0 && millis() - previousPress >= buttonTapsTimeout) { + buttonStatus = static_cast(taps); + taps = 0; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.cpp new file mode 100644 index 00000000..a1ea934b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.cpp @@ -0,0 +1,48 @@ +#include "SensorsData.h" + +DataPoint::DataPoint(uint16_t moistureA, uint8_t moistureP) + : ts(time(nullptr)) + , moistureA(moistureA) + , moistureP(moistureP) +{ +} + +size_t DataPoint::printTo(Print& p) const +{ + size_t written { 0 }; + + written += p.print((unsigned long)ts); + written += p.print(','); + written += p.print(moistureA); + written += p.print(','); + written += p.print(moistureP); + + return written; +} + +int saveSensorsData() +{ + extern std::list dataPoints; + + unsigned int count { 0 }; + + if (!SD.begin(PIN_SD_CS)) + return -2; + + auto dataLog = SD.open("datalog.csv", FILE_WRITE); + if (!dataLog) + return -1; + + for (auto d = dataPoints.begin(); d != dataPoints.end(); ++d) { + auto bytes = dataLog.println(*d); + if (bytes == 0) // if write failed, don't erase + continue; + count++; + dataPoints.erase(d); + } + + dataLog.close(); + SD.end(); + + return count; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.h new file mode 100644 index 00000000..384ead5d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/SensorsData.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +struct DataPoint: Printable { + time_t ts; + uint16_t moistureA; + uint8_t moistureP; + + DataPoint(uint16_t moistureA, uint8_t moistureP); + + virtual size_t printTo(Print& p) const; + +}; + +int saveSensorsData(); diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.cpp new file mode 100644 index 00000000..39972812 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.cpp @@ -0,0 +1,149 @@ +#include "TasksHelpers.h" + +/** + * Load alarm task from parsed alarmtab.txt file on SD. + */ +std::list loadTasks() +{ + if (!SD.begin(PIN_SD_CS)) { + Serial.println("SD initialization failed"); + while (true) + ; + } + auto alarmtab = SD.open("alarmtab.txt"); + auto taskList = parseAlarmTab(alarmtab); + + alarmtab.close(); + SD.end(); + + return taskList; +} + +/** + * Set the alarm tasks from the loaded list. + */ +std::list setTasks(std::list taskList) +{ + AlarmID_t alarmID { dtINVALID_ALARM_ID }; + std::list alarmIDs; + + for (auto& task : taskList) { + switch (task.method) { + case ALARM_REPEAT: { + if (task.day == 0) + alarmID = Alarm.alarmRepeat(task.hour, task.min, task.sec, task.handler); + else + alarmID = Alarm.alarmRepeat(task.day, task.hour, task.min, task.sec, task.handler); + break; + } + case ALARM_ONCE: { + if (task.day == 0) + alarmID = Alarm.alarmOnce(task.hour, task.min, task.sec, task.handler); + else + alarmID = Alarm.alarmOnce(task.day, task.hour, task.min, task.sec, task.handler); + break; + } + case TIMER_REPEAT: { + alarmID = Alarm.timerRepeat(task.sec, task.handler); + break; + } + case TIMER_ONCE: { + alarmID = Alarm.timerOnce(task.sec, task.handler); + break; + } + case TRIGGER_ONCE: { + alarmID = Alarm.triggerOnce(task.sec, task.handler); + break; + } + default: + break; + } + alarmIDs.push_back(alarmID); + } + + return alarmIDs; +} + +/** + * Free the current alarm tasks + */ +void freeTasks(std::list& alarmIDs) +{ + for (auto& id : alarmIDs) { + Alarm.free(id); + id = dtINVALID_ALARM_ID; + } +} + +/** + * Load and set tasks from alarmtab.txt file. + * + * Remove previously loaded tasks if parameter is true. + */ +void loadAndSetTasks(std::list& alarmIDs, bool reload) +{ + LCD.clear(); + LCD.backlight(); + + LCD.setCursor(0, 0); + if (reload) { + Serial.println("Reloading Tasks: "); + LCD.print("Reloading Tasks:"); + freeTasks(alarmIDs); + } else { + Serial.println("Loading Tasks: "); + LCD.print("Loading Tasks:"); + } + + auto taskList = loadTasks(); + alarmIDs = setTasks(taskList); + printTasks(taskList); + + LCD.setCursor(0, 1); + LCD.print(alarmIDs.size()); + LCD.print(" loaded"); + + // Power off the backlight after 5 seconds + // and power off everything else + Alarm.timerOnce(5, [] { backlightOff(true); }); +} + +void printTasks(const std::list taskList) +{ + for (auto const task : taskList) { + Serial.print("- "); + switch (task.method) { + case ALARM_REPEAT: + Serial.print("ALARM_REPEAT"); + break; + case ALARM_ONCE: + Serial.print("ALARM_ONCE"); + break; + case TIMER_REPEAT: + Serial.print("TIMER_REPEAT"); + break; + case TIMER_ONCE: + Serial.print("TIMER_ONCE"); + break; + case TRIGGER_ONCE: + Serial.print("TRIGGER_ONCE"); + break; + default: + Serial.print("UNKNOWN"); + break; + } + Serial.print(" "); + Serial.print(task.day); + Serial.print(" "); + Serial.print(task.hour); + Serial.print(" "); + Serial.print(task.min); + Serial.print(" "); + Serial.print(task.sec); + Serial.print(" "); + Serial.println((uint64_t)(task.handler), HEX); + } + + Serial.print(taskList.size()); + Serial.println(" tasks loaded."); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.h new file mode 100644 index 00000000..d316d925 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TasksHelpers.h @@ -0,0 +1,14 @@ +#pragma once + +#include +#include +#include + +#include "AlarmTasks.h" + +std::list loadTasks(); +std::list setTasks(std::list taskList); +void freeTasks(std::list& alarmIDs); +void loadAndSetTasks(std::list& alarmIDs, bool reload = false); +void printTasks(const std::list taskList); + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.cpp new file mode 100644 index 00000000..9162b6b9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.cpp @@ -0,0 +1,101 @@ +#include "TimeHelpers.h" + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String date, const String time, bool local_time = true, int tz = 0) +{ + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + sscanf(date.c_str(), "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(time.c_str(), "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) + { + if (tz > 200) + { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } + else + { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t &build_time) +{ + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char *fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) + { + if (tz > 200) + { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } + else + { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char *fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) + { + if (tz > 200) + { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } + else + { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.h new file mode 100644 index 00000000..31646165 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/TimeHelpers.h @@ -0,0 +1,11 @@ +#pragma once + +#include +#include + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String, const String, bool local_time, int tz); +String getLocaltime(); +String getLocaltime(const time_t &build_time); +String getLocaltime(const char *fmt, bool local_time, int); +String getLocaltime(const time_t build_time, const char *fmt, bool local_time, int tz); diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/alarmtab.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/alarmtab.txt new file mode 100644 index 00000000..934a3bbe --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/IrrigationSimpleLCD/alarmtab.txt @@ -0,0 +1,23 @@ +#┌──────────── alarm type: AR == AlarmRepeat, AO == AlarmOnce, +#| TR == TimerRepeat, TO == TimerOnce, +#| RO == TriggerOnce +#| See TimeAlarms (https://github.com/PaulStoffregen/TimeAlarms) for specs +#| ┌────────── day of week: 0 == None, 1 == Sun, ..., 7 == Sat +#| | ┌─────── hour +#| | | ┌──── minute +#| | | | ┌─ second +#| | | | | +#| | | | | +AR 0 15 55 0 OpenLatchingValve +AR 0 15 55 30 CloseLatchingValve +AR 0 15 56 0 OpenLatchingValve +AR 0 15 56 30 CloseLatchingValve +AR 0 15 57 0 OpenSolenoidValve +AR 0 15 57 30 CloseSolenoidValve +AR 0 15 58 0 OpenSolenoidValve +AR 0 15 58 30 CloseSolenoidValve +TR 0 0 0 300 SaveData +TR 0 0 0 60 DisplayClock +TR 0 0 0 30 BlinkLed +TO 0 0 0 10 HelloWorld +RO 0 0 0 1603895279 HiThere \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/DebugMode.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/DebugMode.h new file mode 100644 index 00000000..4b2a930f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/DebugMode.h @@ -0,0 +1,9 @@ +#pragma once + +#ifdef DEBUG +constexpr bool debugMode = true; +#else +constexpr bool debugMode = false; +#endif + +#define DebugSerial if constexpr (debugMode) Serial \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/Helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/Helpers.h new file mode 100644 index 00000000..5d9db8d2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/Helpers.h @@ -0,0 +1,131 @@ +#pragma once + +#include +#include + +#include "DebugMode.h" + +rtos::Mutex pwrMutex; + +void powerOn() +{ + DebugSerial.print("Powering On"); + auto locked = pwrMutex.trylock(); + if (!locked) { + DebugSerial.println(": Already Powered On!"); + return; + } + DebugSerial.println(); + + Power.on(PWR_VBAT); + Power.on(PWR_3V3); + Wire.begin(); + delay(500); + Expander.begin(); + Input.begin(); +} + +void powerOff() +{ + DebugSerial.print("Powering Off"); + auto owner = rtos::ThisThread::get_id() == pwrMutex.get_owner(); + if (!owner) { + DebugSerial.println(": Someone still needs power!"); + return; + } + DebugSerial.println(); + + Input.end(); + Expander.end(); + Wire.end(); + Power.off(PWR_3V3); + Power.off(PWR_VBAT); + pwrMutex.unlock(); +} + +int getAverageInputRead(int pin, const size_t loops) +{ + unsigned int tot { 0 }; + + analogReadResolution(ADC_RESOLUTION); + + Input.enable(); + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + Input.disable(); + + return tot / loops; +} + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String date, const String time, bool local_time = true, int tz = 0) +{ + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + sscanf(date.c_str(), "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(time.c_str(), "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) +{ + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +/** + * Set system clock from compile datetime or RTC + */ +void setSystemClock(String buildDate, String buildTime) +{ + // Retrieve clock time from compile date... + auto buildDateTime = buildDateTimeToSystemTime(buildDate, buildTime, true, 2); + // ... ore use the one from integrated RTC. + auto rtcTime = time(NULL); + + // Remember to connect at least the CR2032 battery + // to keep the RTC running. + auto actualTime = rtcTime > buildDateTime ? rtcTime : buildDateTime; + + // Set both system time + set_time(actualTime); + + DebugSerial.print("Compile Date and Time: "); + DebugSerial.println(getLocaltime(buildDateTime)); + DebugSerial.print("RTC Date and Time: "); + DebugSerial.println(getLocaltime(rtcTime)); + DebugSerial.print("System Clock: "); + DebugSerial.println(getLocaltime()); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/LowPowerDataLogger.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/LowPowerDataLogger.ino new file mode 100644 index 00000000..0171319f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/LowPowerDataLogger/LowPowerDataLogger.ino @@ -0,0 +1,433 @@ +/* + A Low Power Data Logger for the Arduino Edge Control + + This example demonstrates how to use a few advanced features of the MbedOS + APIs to build a low power data logger. + + The sketch periodically reads data from one of the analog INPUTS and stores + it on the SPIF memory using a KeyValue datastore. When the user press a + button connected to the POWER_ON, the data is moved from the SPIF to a + FAT-formatted SD Card. + + Features: + * Low Power Ticker for managing recurring task + https://os.mbed.com/docs/mbed-os/v6.7/apis/lowpowerticker.html + * EventQueue for managing scheduled tasks in IRQ-friendly contexts + https://os.mbed.com/docs/mbed-os/v6.7/apis/eventqueue.html + * Mutex for coordinating R/W access to SPIF and Power management + https://os.mbed.com/docs/mbed-os/v6.7/apis/mutex.html + * TDBStore for keyvalue datastore + https://os.mbed.com/docs/mbed-os/v6.7/apis/kvstore.html + + Requirements: + * Arduino Edge Control + * SD Card + * Momentary button + + Circuit: + * Insert the SD Card + * Connect the button pins to GND and POWER_ON on the LCD header + * Connect a 12V Power Supply to GND/S pins + + + Created by Giampaolo Mancini +*/ +#include +#include +#include +#include +#include +#include +#include + +/* + To enable debugging print on Serial Monitor define DEBUG on "DebugMode.h" or + compile the sketch with the CLI using the '--build-property' parameter, eg. + + arduino-cli compile -b arduino:mbed:edge_control --build-property 'compiler.cpp.extra_flags="-DDEBUG=1"' +*/ +#include "DebugMode.h" +#include "Helpers.h" + +using namespace mbed; +using namespace events; +using namespace rtos; +using namespace std::chrono_literals; + +// Low Power Tickers for timed actions +LowPowerTicker meter; +LowPowerTicker printer; + +// Event queue for managing IRQ-Unsafe tasks +EventQueue queue(32 * EVENTS_EVENT_SIZE); +Thread t; + +// Serial Flash management +constexpr uint32_t SPIF_FREQ { 32000000 }; +SPIFBlockDevice bd(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_SS, SPIF_FREQ); +TDBStore tdb_store(&bd); + +// Use a Mutex to coordinate reads and writes to SPIF storage +Mutex spifMutex; + +/** UI Management **/ +// Button statuses +enum ButtonStatus : byte { + ZERO_TAP, + SINGLE_TAP, + DOUBLE_TAP, + LOT_OF_TAPS +}; + +// ISR: count the button taps +volatile byte taps { 0 }; +// ISR: keep elapsed timings +volatile unsigned long previousPress { 0 }; +// ISR: Final button status +volatile ButtonStatus buttonStatus { ZERO_TAP }; + +// Struct for data storage +struct Data { + time_t ts; + uint32_t moist; +}; + +void setup() +{ + if constexpr (debugMode) { + Serial.begin(115200); + const uint32_t startNow { millis() + 2500 }; + while (!Serial && millis() < startNow) + ; + delay(500); + } + + EdgeControl.begin(); + + // Init system clock from compilation time + setSystemClock(__DATE__, __TIME__); + + Power.on(PWR_3V3); + + pinMode(POWER_ON, INPUT); + attachInterrupt(POWER_ON, buttonPress, RISING); + + // Init the Key/Value Store + DebugSerial.println("Init TinyDB Key Value store"); + auto err = tdb_store.init(); + DebugSerial.println("TDB Init " + String(err == 0 ? "OK" : "KO") + " (" + String(err) + ")"); + + // Initialize the SD Card and the FAT filesystem function-wide + // to manage SD Card extraction and insertion at run-time + SDBlockDevice sd(SD_MOSI, SD_MISO, SD_CLK, SD_CS); + FATFileSystem fat("fat"); + DebugSerial.print("Checking the SD Card"); + auto ret = fat.mount(&sd); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": Error"); + DebugSerial.println("Please, check your SD Card."); + while (true); + } + DebugSerial.println(": Ok"); + fat.unmount(); + + // Start the Event Queue manager + t.start(callback(&queue, &EventQueue::dispatch_forever)); + + // Init the stats printer and metering tasks + printer.attach(printStatsISR, 30s); + meter.attach(readSensorsISR, 10s); +} + +void loop() +{ + // Use loop() just to manage UI + + detectTaps(); + + switch (buttonStatus) { + case ZERO_TAP: { + break; + } + case SINGLE_TAP: { + DebugSerial.println("Single Tap"); + printStats(); + buttonStatus = ZERO_TAP; + break; + } + case DOUBLE_TAP: { + DebugSerial.println("Double Tap"); + storeData(); + buttonStatus = ZERO_TAP; + break; + } + default: { + DebugSerial.println("Too Many Taps"); + buttonStatus = ZERO_TAP; + break; + } + } + + // Schedule for low-power operations. + delay(100); +} + +void buttonPress() +{ + const auto now = millis(); + // Poor-man debouncing + if (now - previousPress > 100) + taps++; + + previousPress = now; +} + +void detectTaps() +{ + // Timeout to validate the button taps counter + constexpr unsigned int buttonTapsTimeout { 300 }; + + // Set the button status and reset the taps counter when button has been + // pressed at least once and button taps validation timeout has been reached. + if (taps > 0 && millis() - previousPress >= buttonTapsTimeout) { + buttonStatus = static_cast(taps); + taps = 0; + } +} + +void printStatsISR() +{ + // Do something IRQ-safe here... + // irqSafeCall(); + + // ... and distpatch IRQ-unsafe execution to Event Queue + queue.call(printStats); +} + +// Print current stored measures +void printStats() +{ + powerOn(); + + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, LOW); + delay(100); + Expander.digitalWrite(EXP_LED1, HIGH); + delay(100); + Expander.digitalWrite(EXP_LED1, LOW); + delay(100); + Expander.digitalWrite(EXP_LED1, HIGH); + + // If not in debug mode just blink the LED and exit + if constexpr (!debugMode) + return; + DebugSerial.begin(115200); + + spifMutex.lock(); + + // Use a TDBStore iterator to retrieve all the keys + TDBStore::iterator_t it; + TDBStore::info_t info; + // Iterate over all the keys starting with name "key_" + auto ret = tdb_store.iterator_open(&it, "key_"); + if (ret != MBED_SUCCESS) { + DebugSerial.println("Error opening the iterator"); + spifMutex.unlock(); + return; + } + + char key[128] { 0 }; + unsigned int counter { 0 }; + while (tdb_store.iterator_next(it, key, sizeof(key)) != MBED_ERROR_ITEM_NOT_FOUND) { + // Get info about the key and its contents + tdb_store.get_info(key, &info); + + String msg = "Key: "; + msg += String(key, 16); + msg += " - Size: "; + msg += info.size; + msg += " - "; + DebugSerial.print(msg); + + // Get the value using parameters from the info retrieved + Data out; + size_t actual_size; + tdb_store.get(key, &out, info.size, &actual_size); + + // Do something useful with the key-value pair... + msg = "Value ("; + msg += actual_size; + msg += ") - { ts: "; + msg += static_cast(out.ts); + msg += ", moist: "; + msg += out.moist; + msg += " }"; + DebugSerial.print(msg); + DebugSerial.println(); + counter++; + } + DebugSerial.print(counter); + DebugSerial.println(" keys stored"); + // Close the iterator at the end of the cycle + tdb_store.iterator_close(it); + spifMutex.unlock(); + + DebugSerial.end(); + powerOff(); +} + +void readSensorsISR() +{ + // Do something IRQ-safe here... + // irqSafeCall(); + + // ... and distpatch IRQ-unsafe execution to Event Queue + queue.call(readSensors); +} + + +// Read measures from sensors and store on SPIF +void readSensors() +{ + powerOn(); + + DebugSerial.begin(115200); + DebugSerial.println("Reading Sensors"); + + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.digitalWrite(EXP_LED1, LOW); + delay(50); + Expander.digitalWrite(EXP_LED1, HIGH); + + auto value = getAverageInputRead(INPUT_05V_CH01, 10); + + String key = "key_"; + auto ts = time(nullptr); + key += static_cast(ts); + + Data data { ts, value }; + spifMutex.lock(); + auto res = tdb_store.set(key.c_str(), reinterpret_cast(&data), sizeof(data), 0); + spifMutex.unlock(); + if (res == MBED_SUCCESS) + DebugSerial.println(key + ": " + String(value)); + + DebugSerial.end(); + + powerOff(); +} + +// Move data from SPIF to SD +void storeData() +{ + powerOn(); + + DebugSerial.begin(115200); + DebugSerial.println("Saving Data on SD Card"); + + Expander.pinMode(EXP_LED1, OUTPUT); + + SDBlockDevice sd(SD_MOSI, SD_MISO, SD_CLK, SD_CS); + FATFileSystem fat("fat"); + DebugSerial.print("Mounting the SD Card"); + auto ret = fat.mount(&sd); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": Error"); + return; + } + DebugSerial.println(": Ok"); + + DebugSerial.print("Opening the log file"); + auto f = fopen("/fat/datalog.csv", "a+"); + if (f == nullptr) { + DebugSerial.println(": Error"); + return; + } + DebugSerial.println(": Ok"); + + spifMutex.lock(); + TDBStore::iterator_t it; + ret = tdb_store.iterator_open(&it, "key_"); + if (ret != MBED_SUCCESS) { + DebugSerial.println("Error opening the iterator"); + spifMutex.unlock(); + return; + } + + unsigned int counter { 0 }; + TDBStore::info_t info; + char key[128] { 0 }; + while (tdb_store.iterator_next(it, key, sizeof(key)) != MBED_ERROR_ITEM_NOT_FOUND) { + DebugSerial.print("Saving "); + DebugSerial.print(key); + + ret = tdb_store.get_info(key, &info); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": error getting the info"); + continue; + } + + Data out; + size_t actual_size; + tdb_store.get(key, &out, info.size, &actual_size); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": error getting the keyvalue"); + continue; + } + + String line; + line += static_cast(out.ts); + line += ","; + line += out.moist; + + DebugSerial.print(" ("); + DebugSerial.print(line); + DebugSerial.print(") "); + + line += "\r\n"; + ret = fputs(line.c_str(), f); + if (ret < 0) { + DebugSerial.print(": saving error: "); + DebugSerial.print(strerror(errno)); + DebugSerial.print(" "); + DebugSerial.println(-errno); + continue; + } + + ret = fflush(f); + if (ret != 0) { + DebugSerial.print(": flushing error: "); + DebugSerial.print(strerror(errno)); + DebugSerial.print(" "); + DebugSerial.println(-errno); + continue; + } + + ret = tdb_store.remove(key); + if (ret != MBED_SUCCESS) { + DebugSerial.println(": error removing."); + } + DebugSerial.println(": removed."); + + counter++; + + Expander.digitalWrite(EXP_LED1, LOW); + delay(25); + Expander.digitalWrite(EXP_LED1, HIGH); + delay(50); + } + DebugSerial.print(counter); + DebugSerial.println(" keys found."); + + tdb_store.iterator_close(it); + spifMutex.unlock(); + fclose(f); + fat.unmount(); + DebugSerial.end(); + + Expander.digitalWrite(EXP_LED1, LOW); + delay(500); + Expander.digitalWrite(EXP_LED1, HIGH); + + powerOff(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/Helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/Helpers.h new file mode 100644 index 00000000..f0ffa103 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/Helpers.h @@ -0,0 +1,79 @@ +#pragma once + +#include +#include +#include + + +// Convert compile time to system time +time_t buildDateTimeToSystemTime(const String date, const String time, bool local_time = true, int tz = 0) +{ + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + sscanf(date.c_str(), "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(time.c_str(), "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) +{ + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +/** + * Set system clock from compile datetime or RTC + */ +void setSystemClock(String buildDate, String buildTime) +{ + // Retrieve clock time from compile date... + auto buildDateTime = buildDateTimeToSystemTime(buildDate, buildTime, true, 2); + // ... ore use the one from integrated RTC. + auto rtcTime = time(NULL); + + // Remember to connect at least the CR2032 battery + // to keep the RTC running. + auto actualTime = rtcTime > buildDateTime ? rtcTime : buildDateTime; + + // Set both system time + set_time(actualTime); + + Serial.print("Compile Date and Time: "); + Serial.println(getLocaltime(buildDateTime)); + Serial.print("RTC Date and Time: "); + Serial.println(getLocaltime(rtcTime)); + Serial.print("System Clock: "); + Serial.println(getLocaltime()); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/RTCClock.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/RTCClock.ino new file mode 100644 index 00000000..1a5777ff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Application/RTCClock/RTCClock.ino @@ -0,0 +1,22 @@ +// #include +#include "Helpers.h" + +void setup() +{ + Serial.begin(115200); + for (auto startNow = millis() + 2500; !Serial & millis() < startNow; delay(500)); + + Serial.println("Starting RTC example"); + // EdgeControl.begin(); + + // Init system clock from compilation time or RTC + setSystemClock(__DATE__, __TIME__); + + // Power.on(PWR_3V3); +} + +void loop() +{ + Serial.println(getLocaltime()); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/0-5V_Input/0-5V_Input.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/0-5V_Input/0-5V_Input.ino new file mode 100644 index 00000000..99ff96b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/0-5V_Input/0-5V_Input.ino @@ -0,0 +1,97 @@ +/* + Testing strategy: connect each 5V ANALOG-IN input pin alternatively to +5V on the same connector. +*/ + +#include + +constexpr unsigned int adcResolution { 12 }; + +constexpr pin_size_t inputChannels [] { + INPUT_05V_CH01, + INPUT_05V_CH02, + INPUT_05V_CH03, + INPUT_05V_CH04, + INPUT_05V_CH05, + INPUT_05V_CH06, + INPUT_05V_CH07, + INPUT_05V_CH08 +}; +constexpr size_t inputChannelsLen { sizeof(inputChannels) / sizeof(inputChannels[0]) }; +int inputChannelIndex { 0 }; + +struct Voltages { + float volt3V3; + float volt5V; +}; + +void setup() +{ + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + Expander.begin(); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + + Input.begin(); + Input.enable(); + + analogReadResolution(adcResolution); +} + +void loop() +{ + Serial.print("0-5V Input Channel "); + switch (inputChannels[inputChannelIndex]) { + case INPUT_05V_CH01: Serial.print("01"); break; + case INPUT_05V_CH02: Serial.print("02"); break; + case INPUT_05V_CH03: Serial.print("03"); break; + case INPUT_05V_CH04: Serial.print("04"); break; + case INPUT_05V_CH05: Serial.print("05"); break; + case INPUT_05V_CH06: Serial.print("06"); break; + case INPUT_05V_CH07: Serial.print("07"); break; + case INPUT_05V_CH08: Serial.print("08"); break; + default: break; + } + Serial.print(": "); + + auto [ voltsMuxer, voltsInput ] = getAverageAnalogRead(inputChannels[inputChannelIndex]); + + Serial.print(voltsInput); + Serial.print(" ("); + Serial.print(voltsMuxer); + Serial.println(")"); + delay(1000); + + inputChannelIndex = ++inputChannelIndex % inputChannelsLen; +} + +Voltages getAverageAnalogRead(int pin) +{ + constexpr size_t loops { 100 }; + constexpr float toV { 3.3f / float { (1 << adcResolution) - 1 } }; + constexpr float rDiv { 17.4f / ( 10.0f + 17.4f) }; + + int tot { 0 }; + + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return { avg, avg / rDiv }; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/19V/19V.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/19V/19V.ino new file mode 100644 index 00000000..22bd3b13 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/19V/19V.ino @@ -0,0 +1,68 @@ +#include + +constexpr unsigned int adcResolution { 12 }; + +struct Voltages { + float volt3V3; + float volt19V; +}; + +void setup() +{ + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + Power.on(PWR_19V); + + Wire.begin(); + Expander.begin(); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + + Input.begin(); + Input.enable(); + + analogReadResolution(adcResolution); +} + +void loop() +{ + Serial.print("19V Input Channel "); + Serial.print(": "); + + auto [ voltsMuxer, voltsReference ] = getAverageAnalogRead(INPUT_19V_REF); + + Serial.print(voltsReference); + Serial.print(" ("); + Serial.print(voltsMuxer); + Serial.println(")"); + delay(1000); +} + +Voltages getAverageAnalogRead(int pin) +{ + constexpr size_t loops { 100 }; + constexpr float toV { 3.3f / float { (1 << adcResolution) - 1 } }; + constexpr float rDiv { 0.0616f }; + + int tot { 0 }; + + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return { avg, avg / rDiv }; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/4-20mA_Input/4-20mA_Input.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/4-20mA_Input/4-20mA_Input.ino new file mode 100644 index 00000000..f74c00cd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/4-20mA_Input/4-20mA_Input.ino @@ -0,0 +1,93 @@ +/* + Testing strategy: + - Connect a GND Pin of a 10K potentiometer to +19V reference + - Connect each 4-20mA IN pin alternatively to signal pin of potentiomer + - Range the potentiometer +*/ + +#include + +constexpr unsigned int adcResolution { 12 }; + +constexpr pin_size_t inputChannels [] { + INPUT_420mA_CH01, + INPUT_420mA_CH02, + INPUT_420mA_CH03, + INPUT_420mA_CH04 +}; +constexpr size_t inputChannelsLen { sizeof(inputChannels) / sizeof(inputChannels[0]) }; +int inputChannelIndex { 0 }; + +struct Voltages { + float volt3V3; + float voltRef; +}; + +void setup() +{ + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + Power.on(PWR_19V); + + Wire.begin(); + Expander.begin(); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + + Input.begin(); + Input.enable(); + + analogReadResolution(adcResolution); +} + +void loop() +{ + Serial.print("4-20mA Input Channel "); + switch (inputChannels[inputChannelIndex]) { + case INPUT_420mA_CH01: Serial.print("01"); break; + case INPUT_420mA_CH02: Serial.print("02"); break; + case INPUT_420mA_CH03: Serial.print("03"); break; + case INPUT_420mA_CH04: Serial.print("04"); break; + default: break; + } + Serial.print(": "); + + auto [ voltsMuxer, voltsReference ] = getAverageAnalogRead(inputChannels[inputChannelIndex]); + + Serial.print(voltsReference); + Serial.print(" ("); + Serial.print(voltsMuxer); + Serial.println(")"); + delay(1000); + + inputChannelIndex = ++inputChannelIndex % inputChannelsLen; +} + +Voltages getAverageAnalogRead(int pin) +{ + constexpr size_t loops { 100 }; + constexpr float toV { 3.3f / float { (1 << adcResolution) - 1 } }; + constexpr float rDiv { 17.4f / ( 10.0f + 17.4f) }; + + int tot { 0 }; + + for (auto i = 0u; i < loops; i++) + tot += Input.analogRead(pin); + const auto avg = static_cast(tot) * toV / static_cast(loops); + + return { avg, avg / rDiv }; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/BatterySolarStatus/BatterySolarStatus.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/BatterySolarStatus/BatterySolarStatus.ino new file mode 100644 index 00000000..431bf683 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/BatterySolarStatus/BatterySolarStatus.ino @@ -0,0 +1,56 @@ +#include + +constexpr uint32_t printInterval { 5000 }; +uint32_t printNow { 0 }; + +void setup() +{ + Serial.begin(115200); + + const uint32_t startNow { millis() + 2500 }; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Checking Power Supply and Solar Charger status"); + + EdgeControl.begin(); + Power.on(PWR_VBAT); + Power.on(PWR_3V3); + + Wire.begin(); + delay(500); + + Serial.print("I/O Expander initializazion "); + while (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + delay(500); + } + Serial.println("succeeded."); + + Expander.pinMode(EXP_FAULT_SOLAR_PANEL, INPUT); + Expander.pinMode(EXP_FAULT_5V, INPUT); + + printNow = millis(); +} + +void loop() +{ + if (millis() > printNow) { + auto vbat = Power.getVBat(); + Serial.print("Battery Voltage: "); + Serial.println(vbat); + + auto solarStatus = Power.getSolarChargerStatus(); + Serial.print("Solar Panel Charger Status: "); + Serial.println(solarStatus ? "OK" : "Error"); + + auto fiveVoltsStatus = Power.get5VoltStatus(); + Serial.print("5V Power Rail Status: "); + Serial.println(fiveVoltsStatus ? "OK" : "Error"); + + printNow = millis() + printInterval; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Blink/Blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Blink/Blink.ino new file mode 100644 index 00000000..366b3605 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Blink/Blink.ino @@ -0,0 +1,52 @@ +/* + Blink LED1 and external LED via the IO Expander (TCA6424). + + Connect an external LED to J1 connector: + - LED anod to J1-16 + - LED cathod to J1-15 via 1K Ohm resistor + +*/ + +#include + +void setup() +{ + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + + delay(500); + + Serial.print("IO Expander initializazion "); + if (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + } + Serial.println("succeeded."); + + Expander.pinMode(EXP_LED1, OUTPUT); + Expander.pinMode(EXP_LCD_D7, OUTPUT); + +} + +void loop() +{ + Serial.println("Blink"); + Expander.digitalWrite(EXP_LED1, LOW); + Expander.digitalWrite(EXP_LCD_D7, HIGH); + delay(500); + Expander.digitalWrite(EXP_LED1, HIGH); + Expander.digitalWrite(EXP_LCD_D7, LOW); + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounter/IRQCounter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounter/IRQCounter.ino new file mode 100644 index 00000000..5b607e98 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounter/IRQCounter.ino @@ -0,0 +1,56 @@ +/* + Testing strategy: alternatively create a short-time connection between + WAKEUP 1-6 and any of the +BAT_ext pins (the row above the WAKEUP ones). + + Check IRQChannelMap for advanced C++ implementation. +*/ + +#include + +volatile int irqCounts[6] { }; + +enum IRQChannelsIndex { + irqChannel1 = 0, + irqChannel2, + irqChannel3, + irqChannel4, + irqChannel5, + irqChannel6 +}; + + +void setup() +{ + EdgeControl.begin(); + + Serial.begin(115200); + + // Wait for Serial Monitor or start after 2.5s + for (const auto timeout = millis() + 2500; millis() < timeout && !Serial; delay(250)); + + // Init IRQ INPUT pins + for (auto pin = IRQ_CH1; pin <= IRQ_CH6; pin++) + pinMode(pin, INPUT); + + // Attach callbacks to IRQ pins + attachInterrupt(digitalPinToInterrupt(IRQ_CH1), []{ irqCounts[irqChannel1]++; }, CHANGE); + attachInterrupt(digitalPinToInterrupt(IRQ_CH2), []{ irqCounts[irqChannel2]++; }, CHANGE); + attachInterrupt(digitalPinToInterrupt(IRQ_CH3), []{ irqCounts[irqChannel3]++; }, CHANGE); + attachInterrupt(digitalPinToInterrupt(IRQ_CH4), []{ irqCounts[irqChannel4]++; }, CHANGE); + attachInterrupt(digitalPinToInterrupt(IRQ_CH5), []{ irqCounts[irqChannel5]++; }, CHANGE); + attachInterrupt(digitalPinToInterrupt(IRQ_CH6), []{ irqCounts[irqChannel6]++; }, CHANGE); + +} + +void loop() +{ + // Check for received IRQ every second. + Serial.println("--------"); + for (unsigned int i = irqChannel1; i <= irqChannel6; i++) { + Serial.print("IRQ Channel: "); + Serial.print(i + 1); + Serial.print(" - "); + Serial.println(irqCounts[i]); + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounterMap/IRQCounterMap.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounterMap/IRQCounterMap.ino new file mode 100644 index 00000000..232de576 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/IRQCounterMap/IRQCounterMap.ino @@ -0,0 +1,73 @@ +/* + Testing strategy: alternatively create a short-time connection between + WAKEUP 1-6 and any of the +BAT_ext pins (the row above the WAKEUP ones). + + Check IRQChannel for a simpler implementation. +*/ + +#include + +#include + +// Use a map to collect IRQ counts +std::map irqCounts { + { IRQ_CH1, 0 }, + { IRQ_CH2, 0 }, + { IRQ_CH3, 0 }, + { IRQ_CH4, 0 }, + { IRQ_CH5, 0 }, + { IRQ_CH6, 0 } +}; + +// Map pin numbers to pin names for pretty printing +std::map irqNames { +#define NE(IRQ) { IRQ, #IRQ } + NE(IRQ_CH1), + NE(IRQ_CH2), + NE(IRQ_CH3), + NE(IRQ_CH4), + NE(IRQ_CH5), + NE(IRQ_CH6), +}; + +void setup() +{ + EdgeControl.begin(); + + Serial.begin(115200); + + // Wait for Serial Monitor or start after 2.5s + for (const auto timeout = millis() + 2500; millis() < timeout && !Serial; delay(250)) + ; + + // Init IRQ pins and attach callbacks + // NOTE: .first holds the channel pin and .second holds the counter + for (const auto& irq : irqCounts) { + // Init pins + pinMode(irq.first, INPUT); + + // Create a type alias helper + using IrqCount = std::pair; + + // Define the IRQ callback as lambda function + // Will receive an entry from the irqCounts map: + auto isr = [](void* arg) { IrqCount * ic = (IrqCount *)arg; (*ic).second++; }; + + // attach the callback passing the current map entry as parameter + attachInterruptParam( + digitalPinToInterrupt(irq.first), isr, RISING, (void*)&irq); + } +} + +void loop() +{ + // Print counters every second. + Serial.println("--------"); + for (const auto& irq : irqCounts) { + Serial.print("IRQ Channel: "); + Serial.print(irqNames[irq.first]); + Serial.print(" - Counts: "); + Serial.println(irq.second); + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LCD/LCD.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LCD/LCD.ino new file mode 100644 index 00000000..effca0c1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LCD/LCD.ino @@ -0,0 +1,112 @@ +/* + LCD Display (HD44780) via LiquidCrystal for TCA6224A + + The circuit: + * Arduino Edge Control + * Arduino Edge Control LCD brekout board + +*/ + +#include +#include + +byte smiley[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b10001, + 0b01110, + 0b00000 +}; + +byte armsUp[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + 0b00100, + 0b01010 +}; + +byte frownie[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b00000, + 0b01110, + 0b10001 +}; + +void setup() +{ + EdgeControl.begin(); + + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Testing LCD for Arduino Edge Control"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + + delay(500); + + Serial.print("IO Expander initializazion "); + if (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + } + Serial.println("succeeded."); + + // set up the LCD's number of columns and rows: + LCD.begin(16, 2); + + LCD.createChar(0, smiley); // load character to the LCD + LCD.createChar(1, armsUp); // load character to the LCD + LCD.createChar(2, frownie); // load character to the LCD + + // Print a message to the LCD. + LCD.home(); // go home + LCD.print("Edge Control"); + LCD.setCursor(15, 0); + LCD.print(char(1)); +} + +void loop() +{ + static bool backlight = true; + + if (backlight) { + LCD.backlight(); + backlight = false; + } else { + LCD.noBacklight(); + backlight = true; + } + + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + LCD.setCursor(0, 1); + // print the number of seconds since reset: + LCD.print(millis() / 1000); + // Do a little animation by writing to the same location + LCD.setCursor(15, 1); + LCD.print(char(2)); + delay(200); + LCD.setCursor(15, 1); + LCD.print(char(0)); + delay(200); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Latching/Latching.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Latching/Latching.ino new file mode 100644 index 00000000..a56d0b56 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Latching/Latching.ino @@ -0,0 +1,44 @@ +#include + +void setup() +{ + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Hello, Challenge!"); + + Latching.begin(); +} + +void loop() +{ + Latching.channelDirection(LATCHING_CMD_1, POSITIVE); + Latching.strobe(200); + // Latching.channelDirection(LATCHING_CMD_1, POSITIVE); + // Latching.latch(); + // delay(200); + // Latching.release(); + Latching.channelDirection(LATCHING_CMD_1, NEGATIVE); + Latching.strobe(200); + // Latching.channelDirection(LATCHING_CMD_1, LOW); + // Latching.latch(); + // delay(200); + // Latching.release(); + Latching.channelDirection(LATCHING_OUT_1, POSITIVE); + Latching.strobe(200); + // Latching.digitalWrite(LATCHING_OUT_1, HIGH); + // Latching.latch(); + // delay(200); + // Latching.release(); + Latching.channelDirection(LATCHING_OUT_1, NEGATIVE); + Latching.strobe(200); + // Latching.digitalWrite(LATCHING_OUT_1, LOW); + // Latching.latch(); + // delay(200); + // Latching.release(); + delay(1000); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LowPowerButton/LowPowerButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LowPowerButton/LowPowerButton.ino new file mode 100644 index 00000000..0476ba24 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/LowPowerButton/LowPowerButton.ino @@ -0,0 +1,169 @@ +/* +* Show usage of POWER_ON pin (J1-2). +* +* Board goes to low power mode as soon as started. +* Pressing a momentary button connected to POWER_ON pin +* will wake up the board for 5 seconds. +* +* Requirements: +* - Connect a momentary button between POWER_ON (J1-2) and GND (J1-9) +* - Connect the PC/Mac to USB and open the Arduino Serial Monitor +* or any serial communication application. +* +*/ + +#include +#include + +constexpr unsigned long printInterval { 250 }; +unsigned long printNow { 0 }; +constexpr unsigned long wakeUpInterval { printInterval * 20 }; +unsigned long sleepNow { 0 }; +volatile bool sleeping { true }; +volatile bool poweredOn { false }; + +void wakeUp() +{ + sleeping = false; + poweredOn = true; +} + +void setup() +{ + EdgeControl.begin(); + Power.on(PWR_3V3); + + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + delay(1000); + Serial.println("Testing Low Power"); + Serial.println("and Power On Button."); + + pinMode(POWER_ON, INPUT); + attachInterrupt(digitalPinToInterrupt(POWER_ON), wakeUp, FALLING); + + sleepNow = millis(); + printNow = millis() + printInterval; + + powerDown(); + +} + +void loop() +{ + if (poweredOn) { + poweredOn = false; + + powerOn(); + + delay(1000); // Wait for Serial Monitor/Serial Communication Application + Serial.println(""); + Serial.println("Woke Up!"); + sleepNow = millis() + wakeUpInterval; + } + + if (millis() > sleepNow && !sleeping) { + // Going to sleep + powerDown(); + sleeping = true; + } + + if (sleeping) + delay(10000); // delay() puts the board in low power mode. + else + if (millis() > printNow) { + Serial.print('.'); + printNow = millis() + printInterval; + } +} + +void powerOn() +{ + // Enable Gated 3V3 to devices and peripherals + Power.on(PWR_3V3); + + // Enable Gated 12V and 5V to output pins, devices and peripherals + Power.on(PWR_VBAT); + + // Enable Gated 12V and 5V to output pins, devices and peripherals + Power.on(PWR_19V); + + // Attach USB + PluggableUSBD().begin(); + + // Enable stdin + mbed::mbed_file_handle(STDIN_FILENO)->enable_input(true); + + // Open Serial and wait for connection + Serial.begin(9600); + while(!Serial); +} + +void powerDown() +{ + Serial.println(); + Serial.println("Powering down"); + + // Disable Gated 3V3 + Power.off(PWR_3V3); + + // Disable Gated 12V and 5V + Power.off(PWR_VBAT); + + // Disable Gated 19V + Power.off(PWR_19V); + + // Close Serial + Serial.end(); + Serial1.end(); + // Disable stdin + mbed::mbed_file_handle(STDIN_FILENO)->enable_input(false); + // Detach USB + PluggableUSBD().deinit(); + // Put pins in threestate + powerDownPins(); +} + +void powerDownPins() +{ + pinMode(I2C_SDA, INPUT_PULLDOWN); + pinMode(I2C_SCL, INPUT_PULLDOWN); + pinMode(I2C_SDA1, INPUT_PULLDOWN); + pinMode(I2C_SCL1, INPUT_PULLDOWN); + + pinMode(VBAT_PROBE, INPUT_PULLDOWN); + + pinMode(CMD_TRIAC_1, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_2, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_3, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_4, INPUT_PULLDOWN); + + pinMode(SENSOR_COMMON, INPUT_PULLDOWN); + pinMode(SENSOR_CALIB, INPUT_PULLDOWN); + pinMode(SENSOR_INPUT_ADC, INPUT_PULLDOWN); + pinMode(SENSOR_CAPTURE_A, INPUT_PULLDOWN); + pinMode(SENSOR_CAPTURE, INPUT_PULLDOWN); + + pinMode(PULSE_DIRECTION, INPUT_PULLDOWN); + pinMode(PULSE_STROBE, INPUT_PULLDOWN); + + pinMode(SD_CS, INPUT_PULLDOWN); + + pinMode(QSPIDCS, INPUT_PULLDOWN); + pinMode(GPIOCLK, INPUT_PULLDOWN); + pinMode(QSPID0, INPUT_PULLDOWN); + pinMode(QSPID1, INPUT_PULLDOWN); + pinMode(QSPID2, INPUT_PULLDOWN); + pinMode(QSPID3, INPUT_PULLDOWN); + + pinMode(IRQ_CH1, INPUT); + pinMode(IRQ_CH2, INPUT); + pinMode(IRQ_CH3, INPUT); + pinMode(IRQ_CH4, INPUT); + pinMode(IRQ_CH5, INPUT); + pinMode(IRQ_CH6, INPUT); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/PowerOnButton/PowerOnButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/PowerOnButton/PowerOnButton.ino new file mode 100644 index 00000000..3576a2d0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/PowerOnButton/PowerOnButton.ino @@ -0,0 +1,58 @@ +/* + Test Power On button on LCD breakout board + + Circuit: + * Arduino Edge Control + * Arduino Edge Control LCD brekout board +*/ + +#include + +// Keep track of toggle-style press with an ISR +volatile bool buttonPressed { false }; +bool ledStatus { false }; + +void setup() +{ + Serial.begin(9600); + + for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250)) + ; + + Serial.println("Hello, Arduino Edge Control!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + + delay(500); + + Serial.print("IO Expander initializazion "); + if (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + } + Serial.println("succeeded."); + + Expander.pinMode(EXP_LED1, OUTPUT); + + pinMode(POWER_ON, INPUT); + // ISR for button press detection + attachInterrupt( + digitalPinToInterrupt(POWER_ON), [] { buttonPressed = true; }, FALLING); + +} + +void loop() +{ + if (buttonPressed == true) { + buttonPressed = false; + ledStatus = !ledStatus; + Serial.print(millis()); + Serial.println(" Pressed"); + } + + Expander.digitalWrite(EXP_LED1, ledStatus == true ? LOW : HIGH); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/Helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/Helpers.h new file mode 100644 index 00000000..ff26c315 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/Helpers.h @@ -0,0 +1,132 @@ +#pragma once + +#include +#include +#include + +// Convert build time to UNIX time +time_t getBuildDateTime(bool local_time = true, int tz = 0) +{ + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + sscanf(__DATE__, "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(__TIME__, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3 + 1; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getRTCDate() +{ + // APIs to get date fields. + auto years = RealTimeClock.getYears(); + auto months = RealTimeClock.getMonths(); + auto days = RealTimeClock.getDays(); + + char buf[12] {}; + + snprintf(buf, 11, "20%02d-%02d-%02d", years, months, days); + + return String(buf); +} + +String getRTCTime() +{ + // APIs to get time fields. + auto hours = RealTimeClock.getHours(); + auto minutes = RealTimeClock.getMinutes(); + auto seconds = RealTimeClock.getSeconds(); + + char buf[11] {}; + + snprintf(buf, 10, "%02d:%02d:%02d", hours, minutes, seconds); + + return String(buf); +} + +String getRTCDateTime() +{ + auto date = getRTCDate(); + auto time = getRTCTime(); + + auto dateTime = date + ' ' + time; + + return dateTime; +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) +{ + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char* fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char* fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/RealTimeClock.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/RealTimeClock.ino new file mode 100644 index 00000000..c8d9a03d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock/RealTimeClock.ino @@ -0,0 +1,67 @@ +/* + Arduino Edge Control - RTC Example + + This sketch shows how to use the RTC (PCF8563T) on the Arduino + Edge Control and how to configure the RTC's time registers. + + Circuit: + - Arduino Edge Control + - CR2032 Battery + - Optional: Arduino Edge Control LCD + Button brekout + +*/ + +#include "Helpers.h" +#include + +void setup() +{ + pinMode(POWER_ON, INPUT); + + Serial.begin(9600); + + for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250)) + ; + + Serial.println("Hello, Arduino Edge Control!"); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Initializating the Real Time Clock..."); + while (!RealTimeClock.begin()) { + Serial.println(" failed! Retrying..."); + delay(250); + } + Serial.println(" done!"); + + // APIs to set date's fields: years, months, days, hours, minutes and seconds + // The RTC time can be set as epoch, using one of the following two options: + // - Calendar time: RealTimeClock.setEpoch(years, months, days, hours, minutes, seconds); + // - UTC time: RealTimeClock.setEpoch(date_in_seconds); + + // Set the RTC only when LCD's PowerOn button is pressed. + // YMMV. + if (digitalRead(POWER_ON) == LOW) { + Serial.println("Resetting the RTC to Sketch Build Datetime!"); + auto buildDateTime = getBuildDateTime(); + RealTimeClock.setEpoch(buildDateTime); + Serial.print("Build "); + } +} + +void loop() +{ + Serial.print("Date: "); + Serial.println(getRTCDateTime()); + + Serial.print("Unix time: "); + Serial.println(time(NULL)); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/Helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/Helpers.h new file mode 100644 index 00000000..5ad9f7a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/Helpers.h @@ -0,0 +1,93 @@ +#pragma once + +#include +#include + +// Convert build time to UNIX time +time_t getBuildDateTime(bool local_time = true, int tz = 0) +{ + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + sscanf(__DATE__, "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(__TIME__, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3 + 1; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) +{ + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char* fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char* fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/RealTimeClock_Alarm.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/RealTimeClock_Alarm.ino new file mode 100644 index 00000000..c0128b0e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_Alarm/RealTimeClock_Alarm.ino @@ -0,0 +1,133 @@ +/* + Arduino Edge Control - RTC Alarm Example + + This sketch shows how to use the RTC (PCF8563T) on the Arduino + Edge Control and how to configure and use the RTC's alarm. + + Circuit: + - Arduino Edge Control + - CR2032 Battery + - Optional: Arduino Edge Control LCD + Button brekout + +*/ + +#include "Helpers.h" +#include + +volatile bool alarmFlag { false }; +byte alarmInterval { 1 }; + +void setup() +{ + Serial.begin(9600); + + for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250)) + ; + + Serial.println("Hello, Arduino Edge Control!"); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Initializating the Real Time Clock..."); + while (!RealTimeClock.begin()) { + Serial.println(" failed! Retrying..."); + delay(250); + } + Serial.println(" done!"); + + // Set the RTC only when LCD's PowerOn button is pressed. + // YMMV. + if (digitalRead(POWER_ON) == LOW) { + auto buildDateTime = getBuildDateTime(); + RealTimeClock.setEpoch(buildDateTime); + Serial.print("Build "); + } + + Serial.print("Date: "); + Serial.println(getRTCDateTime()); + + // Enables Alarm on the RTC + RealTimeClock.enableAlarm(); + + // Set the minutes at which the alarm should rise + // Trigger in a minute + auto minutes = RealTimeClock.getMinutes(); + RealTimeClock.setMinuteAlarm(minutes + alarmInterval); + + // Attach an interrupt to the RTC interrupt pin + attachInterrupt( + digitalPinToInterrupt(IRQ_RTC), [] { alarmFlag = true; }, FALLING); + + Serial.println(); +} + +void loop() +{ + if (alarmFlag) { + Serial.println("Alarm!"); + + auto totalMinutes = RealTimeClock.getMinutes() + alarmInterval; + + // Take care of the 60-minute wrapping and... + auto minutesAlarm = totalMinutes % 60; + RealTimeClock.setMinuteAlarm(minutesAlarm); + + // don't forget to manage the hour increment. + if (totalMinutes >= 60) + RealTimeClock.setHourAlarm(RealTimeClock.getHours() + 1); + + RealTimeClock.clearAlarm(); + + // To disable the alarm uncomment the following line: + // RealTimeClock.disableAlarm(); + + alarmFlag = false; + } + + Serial.println(getRTCTime()); + delay(10000); +} + +String getRTCDate() +{ + // APIs to get date fields. + auto years = RealTimeClock.getYears(); + auto months = RealTimeClock.getMonths(); + auto days = RealTimeClock.getDays(); + + char buf[12] {}; + + snprintf(buf, 11, "20%02d-%02d-%02d", years, months, days); + + return String(buf); +} + +String getRTCTime() +{ + // APIs to get time fields. + auto hours = RealTimeClock.getHours(); + auto minutes = RealTimeClock.getMinutes(); + auto seconds = RealTimeClock.getSeconds(); + + char buf[11] {}; + + snprintf(buf, 10, "%02d:%02d:%02d", hours, minutes, seconds); + + return String(buf); +} + +String getRTCDateTime() +{ + auto date = getRTCDate(); + auto time = getRTCTime(); + + auto dateTime = date + ' ' + time; + + return dateTime; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/Helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/Helpers.h new file mode 100644 index 00000000..ff26c315 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/Helpers.h @@ -0,0 +1,132 @@ +#pragma once + +#include +#include +#include + +// Convert build time to UNIX time +time_t getBuildDateTime(bool local_time = true, int tz = 0) +{ + char s_month[5]; + int year; + + tm t; + time_t seconds; + + static const char month_names[] = "JanFebMarAprMayJunJulAugSepOctNovDec"; + + sscanf(__DATE__, "%s %d %d", s_month, &t.tm_mday, &year); + sscanf(__TIME__, "%2d %*c %2d %*c %2d", &t.tm_hour, &t.tm_min, &t.tm_sec); + + // Find where is s_month in month_names. Deduce month value. + t.tm_mon = (strstr(month_names, s_month) - month_names) / 3 + 1; + t.tm_year = year - 1900; + _rtc_maketime(&t, &seconds, RTC_FULL_LEAP_YEAR_SUPPORT); + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + seconds += (3600UL) * tz; + } else { + seconds -= (3600UL) * tz; + } + } + + return seconds; +} + +String getRTCDate() +{ + // APIs to get date fields. + auto years = RealTimeClock.getYears(); + auto months = RealTimeClock.getMonths(); + auto days = RealTimeClock.getDays(); + + char buf[12] {}; + + snprintf(buf, 11, "20%02d-%02d-%02d", years, months, days); + + return String(buf); +} + +String getRTCTime() +{ + // APIs to get time fields. + auto hours = RealTimeClock.getHours(); + auto minutes = RealTimeClock.getMinutes(); + auto seconds = RealTimeClock.getSeconds(); + + char buf[11] {}; + + snprintf(buf, 10, "%02d:%02d:%02d", hours, minutes, seconds); + + return String(buf); +} + +String getRTCDateTime() +{ + auto date = getRTCDate(); + auto time = getRTCTime(); + + auto dateTime = date + ' ' + time; + + return dateTime; +} + +String getLocaltime() +{ + char buffer[32]; + tm t; + _rtc_localtime(time(NULL), &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const time_t& build_time) +{ + char buffer[32]; + tm t; + _rtc_localtime(build_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 32, "%Y-%m-%d %k:%M:%S", &t); + return String(buffer); +} + +String getLocaltime(const char* fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = time(NULL); + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} + +String getLocaltime(const time_t build_time, const char* fmt, bool local_time = true, int tz = 0) +{ + char buffer[64]; + time_t tmp_time = build_time; + tm t; + + if (!local_time) { + if (tz > 200) { + tz = 0x100 - tz; // Handle negative values + tmp_time -= (3600UL) * tz; + } else { + tmp_time += (3600UL) * tz; + } + } + + _rtc_localtime(tmp_time, &t, RTC_FULL_LEAP_YEAR_SUPPORT); + strftime(buffer, 64, fmt, &t); + return String(buffer); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/RealTimeClock_LowPower.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/RealTimeClock_LowPower.ino new file mode 100644 index 00000000..114dc8ec --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/RealTimeClock_LowPower/RealTimeClock_LowPower.ino @@ -0,0 +1,109 @@ +/* + Arduino Edge Control - RTC Low Power Example + + This sketch shows how to use the RTC (PCF8563T) on the Arduino + Edge Control and how to configure and use the RTC on Low Power mode. + + Circuit: + - Arduino Edge Control + - CR2032 Battery + - Optional: Arduino Edge Control LCD + Button brekout + +*/ + +#include "Helpers.h" +#include +#include + +void setup() +{ + Serial.begin(9600); + + for (auto timeout = millis() + 2500l; !Serial && millis() < timeout; delay(250)) + ; + + Serial.println("Hello, Arduino Edge Control!"); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Initializating the Real Time Clock..."); + while (!RealTimeClock.begin()) { + Serial.println(" failed! Retrying..."); + delay(250); + } + Serial.println(" done!"); + + // Set the RTC only when LCD's PowerOn button is pressed. + // YMMV. + if (digitalRead(POWER_ON) == LOW) { + auto buildDateTime = getBuildDateTime(); + RealTimeClock.setEpoch(buildDateTime); + Serial.print("Build "); + } + + Serial.print("Date: "); + Serial.println(getRTCDateTime()); + + delay(5000); + + Wire.end(); + Serial.end(); + Serial1.end(); + + Power.off(PWR_3V3); + Power.off(PWR_VBAT); + + mbed::mbed_file_handle(STDIN_FILENO)->enable_input(false); + PluggableUSBD().deinit(); +} + +void loop() +{ + delay(10000); +} + +void powerDown() +{ + pinMode(I2C_SDA, INPUT_PULLDOWN); + pinMode(I2C_SCL, INPUT_PULLDOWN); + pinMode(I2C_SDA1, INPUT_PULLDOWN); + pinMode(I2C_SCL1, INPUT_PULLDOWN); + + pinMode(VBAT_PROBE, INPUT_PULLDOWN); + + pinMode(CMD_TRIAC_1, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_2, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_3, INPUT_PULLDOWN); + pinMode(CMD_TRIAC_4, INPUT_PULLDOWN); + + pinMode(SENSOR_COMMON, INPUT_PULLDOWN); + pinMode(SENSOR_CALIB, INPUT_PULLDOWN); + pinMode(SENSOR_INPUT_ADC, INPUT_PULLDOWN); + pinMode(SENSOR_CAPTURE_A, INPUT_PULLDOWN); + pinMode(SENSOR_CAPTURE, INPUT_PULLDOWN); + + pinMode(PULSE_DIRECTION, INPUT_PULLDOWN); + pinMode(PULSE_STROBE, INPUT_PULLDOWN); + + pinMode(SD_CS, INPUT_PULLDOWN); + + pinMode(QSPIDCS, INPUT_PULLDOWN); + pinMode(GPIOCLK, INPUT_PULLDOWN); + pinMode(QSPID0, INPUT_PULLDOWN); + pinMode(QSPID1, INPUT_PULLDOWN); + pinMode(QSPID2, INPUT_PULLDOWN); + pinMode(QSPID3, INPUT_PULLDOWN); + + pinMode(IRQ_CH1, INPUT_PULLDOWN); + pinMode(IRQ_CH2, INPUT_PULLDOWN); + pinMode(IRQ_CH3, INPUT_PULLDOWN); + pinMode(IRQ_CH4, INPUT_PULLDOWN); + pinMode(IRQ_CH5, INPUT_PULLDOWN); + pinMode(IRQ_CH6, INPUT_PULLDOWN); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/SolidStateRelay/SolidStateRelay.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/SolidStateRelay/SolidStateRelay.ino new file mode 100644 index 00000000..6f3a6d13 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/SolidStateRelay/SolidStateRelay.ino @@ -0,0 +1,80 @@ +#include "Arduino_EdgeControl.h" + +// #define SSR_POLL + +constexpr unsigned long onInterval = { 5000 }; +constexpr unsigned long offInterval = { 5000 }; +constexpr unsigned long pollInterval = { 1000 }; +unsigned long offTime; +unsigned long onTime; +unsigned long pollTime; +bool on = false; + +int relayChannel { RELAY_CH01 }; + +void setup() +{ + Serial.begin(9600); + while (!Serial) + ; + + delay(2000); + + Serial.println("Hello, SolidStateRelay!"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + Expander.pinMode(EXP_LED1, OUTPUT); + + for (auto i = 0; i < 3; i++) { + Expander.digitalWrite(EXP_LED1, LOW); + delay(50); + Expander.digitalWrite(EXP_LED1, HIGH); + delay(100); + } + + Relay.begin(); +} + +void loop() +{ + if (millis() > onTime && !on) { + Serial.println("RELAY ON"); + + Relay.on(relayChannel); + + Expander.digitalWrite(EXP_LED1, LOW); + + on = true; + offTime = onInterval + millis(); + } + + if (millis() > offTime && on) { + Serial.println("RELAY OFF"); + + Relay.off(relayChannel); + + Expander.digitalWrite(EXP_LED1, HIGH); + + on = false; + onTime = millis() + offInterval; + } + +#if defined(SSR_POLL) + if (millis() > pollTime && on) { + Serial.println("POLLING"); + + Relay.poll(relayChannel); + + pollTime = millis() + pollInterval; + } +#endif +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Watermark10k/Watermark10k.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Watermark10k/Watermark10k.ino new file mode 100644 index 00000000..86d7ddb5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/Watermark10k/Watermark10k.ino @@ -0,0 +1,65 @@ +#include + +constexpr unsigned int calibResistor { 7870 }; + +void setup() +{ + Serial.begin(115200); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + EdgeControl.begin(); + delay(2000); + + Serial.println("Hello, 10k"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander.begin()) { + Serial.print("."); + delay(250); + } + Serial.println(" done."); + + Watermark.begin(); + Serial.println("Watermark OK"); + + Watermark.calibrationMode(OUTPUT); + Watermark.calibrationWrite(LOW); + + Watermark.commonMode(OUTPUT); + Watermark.commonWrite(HIGH); + +} + +void loop() +{ + auto val = wmkAvgAnalogRead(WATERMARK_CH01); + Serial.print("Watermark Channel 01"); + Serial.print(" - average analogRead value: "); + Serial.print(val); + Serial.print(" - Calculated Resistor: "); + Serial.println(calibResistor * (1023 - val) / val); + + delay(1000); +} + +int wmkAvgAnalogRead(pin_size_t pin) +{ + constexpr size_t count { 10 }; + unsigned int sum { 0 }; + + Watermark.enable(); + for (auto i = 0u; i < count; i ++) + sum += Watermark.analogRead(pin); + Watermark.disable(); + + return sum / count; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkMega/WatermarkMega.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkMega/WatermarkMega.ino new file mode 100644 index 00000000..ff259474 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkMega/WatermarkMega.ino @@ -0,0 +1,139 @@ +/* + This sketch is the implementation of the classic Watermark example + for Arduino Mega ported to the Arduino Edge Control. + + Please, refer to https://www.irrometer.com/200ss.html for further info. + + Another algorithm that can be implemented using the Watermark circuits + on the Edge Control is the one described at + https://medium.com/fasal-engineering/a-low-cost-circuit-to-read-from-multiple-watermark-irrometer-200ss-sensors-a4c838da233a + + Requirements: + - Arduino Edge Control + - Watermark Sensor + - External 12V power supply + + Circuit: + - Connect PS 12V and GND to BATT+ and GND pins + - Connect the two sensor's cables to WATERMARK COMM and INPUT 1 pins + +*/ + +#include + +constexpr auto adcResolution { 12 }; + +// You will need a proper temperature value to get correct results +auto refTemperature { 24.5f }; + +void setup() +{ + Serial.begin(115200); + + // Wait for Serial or start after 2.5s + for (const auto startNow = millis() + 2500; !Serial && millis() < startNow; delay(250)); + + EdgeControl.begin(); + delay(2000); + + Serial.println("Hello, Watermark Mega"); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + delay(500); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander.begin()) { + Serial.print("."); + delay(250); + } + Serial.println(" done."); + + Watermark.begin(); + Serial.println("Watermark OK"); +} + +void loop() +{ + auto wm = getWatermark(WATERMARK_CH01); + Serial.print("Watermark = "); + Serial.print(wm); + Serial.println("kPa"); + + delay(1000); +} + + +int getAverageWatermarkRead(pin_size_t pin) +{ + constexpr size_t count { 20 }; + int sum { 0 }; + + Watermark.calibrationMode(OUTPUT); + Watermark.calibrationWrite(LOW); + + Watermark.commonMode(OUTPUT); + + Watermark.enable(); + + for (auto i = 0u; i < count; i++) { + Watermark.commonWrite(HIGH); + delay(2); + sum += Watermark.analogRead(pin); + Watermark.commonWrite(LOW); + } + + Watermark.disable(); + + return sum / count; +} + +float getWatermark(pin_size_t pin) +{ + constexpr unsigned int calibResistor { 7870 }; + constexpr long openResistance { 35000 }; + constexpr long shortResistance { 200 }; + constexpr long shortkPa { 240 }; + constexpr long openkPa { 255 }; + + constexpr auto maxValue { 1 << adcResolution }; + constexpr float toV { 3.3f / float { maxValue } }; + + float kPa; + + auto val = getAverageWatermarkRead(pin); + + if (val == 0) + return openkPa; + + auto resistor = calibResistor * float { maxValue - val } / float { val }; + + if (resistor > 550.f) { + if (resistor > 8000.f) { + kPa = -2.246f - 5.239f * (resistor / 1500.f) * (1.f + .018f * (refTemperature - 24.f)) - .06756f * (resistor / 1500.f) * (resistor / 1500.f) * ((1.f + 0.018f * (refTemperature - 24.f)) * (1.f + 0.018f * (refTemperature - 24.f))); + } else if (resistor > 1500.f) { + kPa = (-3.213f * (resistor / 1500.f) - 4.093f) / (1.f - 0.009733f * (resistor / 1500.f) - 0.01205f * (refTemperature)); + } else { + kPa = ((resistor / 1500.f) * 23.156f - 12.736f) * (1.f + 0.018f * (refTemperature - 24.f)); + } + } else { + if (resistor > 300.f) + kPa = 0.f; + if (resistor < 300.f && resistor >= shortResistance) + kPa = shortkPa; // 240 is a fault code for sensor terminal short + } + + if (resistor >= openResistance) { + kPa = openkPa; // 255 is a fault code for open circuit or sensor not present + } + + Serial.print("Watermark average analogRead value: "); + Serial.print(val); + Serial.print(" - Calculated Resistor: "); + Serial.print(resistor); + Serial.println(); + + return abs(kPa); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkTau/WatermarkTau.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkTau/WatermarkTau.ino new file mode 100644 index 00000000..fc2278aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Basic/WatermarkTau/WatermarkTau.ino @@ -0,0 +1,139 @@ +#include +#include + +#include +#include + +constexpr unsigned int adcResolution { 12 }; + +mbed::LowPowerTimeout TimerM; + +uint8_t watermarkChannel { 1 }; + +constexpr float tauRatio { 0.63f }; +constexpr float tauRatioSamples { tauRatio * float { (1 << adcResolution) - 1 } }; +constexpr unsigned long sensorDischargeDelay { 2 }; + +constexpr unsigned int measuresCount { 20 }; +RunningMedian measures { measuresCount }; + +constexpr unsigned int calibsCount { 10 }; +RunningMedian calibs { calibsCount }; + +void setup() +{ + Serial.begin(9600); + + auto startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + delay(2000); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Wire.begin(); + Expander.begin(); + + Serial.print("Waiting for IO Expander Initialization..."); + while (!Expander) { + Serial.print("."); + delay(100); + } + Serial.println(" done."); + + Watermark.begin(); + + analogReadResolution(adcResolution); +} + +void loop() +{ + static bool highPrec { false }; + Watermark.setHighPrecision(highPrec); + highPrec = !highPrec; + + // Init commands and reset devices + Watermark.calibrationMode(OUTPUT); + Watermark.calibrationWrite(LOW); + Watermark.commonMode(OUTPUT); + Watermark.commonWrite(LOW); + + Watermark.fastDischarge(sensorDischargeDelay); + + // Calibration cycle: + // disable Watermark demuxer + Watermark.disable(); + + Watermark.commonMode(INPUT); + Watermark.calibrationMode(OUTPUT); + for (auto i = 0u; i < measuresCount; i++) { + Watermark.calibrationWrite(HIGH); + + auto start = micros(); + while (Watermark.analogRead(watermarkChannel) < tauRatioSamples) + ; + auto stop = micros(); + + Watermark.calibrationWrite(LOW); + + Watermark.fastDischarge(sensorDischargeDelay); + + calibs.add(stop - start); + } + + Serial.print("CALIBS - Precision: "); + Serial.print(highPrec ? "High" : "Low "); + Serial.print(" - Median: "); + Serial.print(calibs.getMedian()); + Serial.print(" - Average: "); + Serial.print(calibs.getAverage()); + Serial.print(" - Lowest: "); + Serial.print(calibs.getLowest()); + Serial.print(" - Highest: "); + Serial.print(calibs.getHighest()); + Serial.println(); + + calibs.clear(); + + Watermark.fastDischarge(sensorDischargeDelay); + + // Measures cycle: + // enable Watermark demuxer + Watermark.enable(); + + Watermark.commonMode(OUTPUT); + Watermark.calibrationMode(INPUT); + for (auto i = 0u; i < measuresCount; i++) { + Watermark.commonWrite(HIGH); + + auto start = micros(); + while (Watermark.analogRead(watermarkChannel) < tauRatioSamples) + ; + auto stop = micros(); + + Watermark.commonWrite(LOW); + + Watermark.fastDischarge(sensorDischargeDelay); + + measures.add(stop - start); + } + + Serial.print("MEASURES - Precision: "); + Serial.print(highPrec ? "High" : "Low "); + Serial.print(" - Median: "); + Serial.print(measures.getMedian()); + Serial.print(" - Average: "); + Serial.print(measures.getAverage()); + Serial.print(" - Lowest: "); + Serial.print(measures.getLowest()); + Serial.print(" - Highest: "); + Serial.print(measures.getHighest()); + Serial.println(); + + measures.clear(); + + Serial.println(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/BlinkOverSerial/BlinkOverSerial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/BlinkOverSerial/BlinkOverSerial.ino new file mode 100644 index 00000000..1c6defe8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/BlinkOverSerial/BlinkOverSerial.ino @@ -0,0 +1,47 @@ +/* + This sketch shows how to use an MKR board connected to one of the + two available slots. The Edge Control and the MKR board will communicate + over UART connection. + + Circuit: + - Arduino Edge Control + - Any Arduino MKR Board connected to MKR Slot 2 + - External 12V Power Supply + + To get the example working, please, load the extras/BlinkFromSerial + sketch on the MKR board. + + +*/ + +#include + +bool led { false }; + +void setup() +{ + EdgeControl.begin(); + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + // Power on the MKR on slot 2 + Power.on(PWR_MKR2); + + // Wait for MKR to power on + delay(5000); + + // Open the serial communication with the MKR board on slot 2... + SerialMKR2.begin(115200); + + // ... and ait for the serial communication from the MKR board + while (!SerialMKR2) { + delay(500); + } +} + +void loop() +{ + SerialMKR2.write(led); + led = !led; + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/LORA_EdgeControl/LORA_EdgeControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/LORA_EdgeControl/LORA_EdgeControl.ino new file mode 100644 index 00000000..d7701fcb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/LORA_EdgeControl/LORA_EdgeControl.ino @@ -0,0 +1,111 @@ +// LoRa example for the Edge control. +// +// This script configures your Arduino Edge control to receive Lora messages from another Arduino. +// Requirements: +// 1 Edge Control board +// 2 MKR1300/1310 boards (sender and receiver) +// +// Connect one of the MKR1300 to the MKR2 socket in the EdgeControl board +// This script is designed to pair with "LORA_receiver-EC.ino". Also +// you will need a LoRa transmitter. We have used the LoRa Sender example from the other +// MKR1300. +// +// The sketch make use of the OpenMV RPC library for communicating between the EdgeControl +// and the MKR1300 via UART +// +// Created 20 April. 2021 +// by e.lopez + + +#include +#include + +openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer. +openmv::rpc_hardware_serial1_uart_master rpc(115200); + +//LoRa message received interrupt pin +const byte interruptPin = PIN_WIRE_SCL1; + +bool message_received = false; +uint16_t msg_count {0}; + + +////////////////////////////////////////////////////////////// +// Call Back Handlers +////////////////////////////////////////////////////////////// + +void rpc_retrieve_LoRa_data() +{ + rpc.begin(); + void *message; + size_t result_data_len; + + if (rpc.call_no_copy_no_args(F("retrieve_msg"), &message, &result_data_len) ) { + + char buff[result_data_len + 1]; + memset(buff, 0, result_data_len + 1); + // Copy what we received into our data type container. + memcpy(buff, message, result_data_len); + // Use it now. + Serial.print(F(": ")); + Serial.println(buff); + + //print on LCD + //LCD.setCursor(0, 0); + //LCD.print("LoRa MSG:"); + //LCD.setCursor(0, 1); + //LCD.print(buff); + + } else { + Serial.print(F("Error:rpc_retrieve_LoRa_data() failed! ")); + } + rpc.end(); +} + +//******************* +//SETUP +//******************* +void setup() +{ + //LoRa data available interrupt + pinMode(interruptPin, INPUT_PULLUP); + attachInterrupt(digitalPinToInterrupt(interruptPin), LoRa_ISR, FALLING); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Power.on(PWR_MKR2); + delay(5000); // Wait for MKR2 to power-on' + + Serial.begin(115200); + while (!Serial); + + // //LCD init + // LCD.begin(16, 2); // set up the LCD's number of columns and rows: + // LCD.home(); // go home + // LCD.backlight(); // turn on Backlight + // LCD.print("EDGE:"); // Print a message to the LCD. + + String serialNumber = EdgeControl.serialNumber(); + Serial.print("Serial Number: "); + Serial.println(serialNumber); +} + +//******************* +//LOOP +//******************* +void loop() +{ + if (message_received) { + Serial.print("Message "); + Serial.print(++msg_count); + rpc_retrieve_LoRa_data(); + message_received = false; + } +} + +void LoRa_ISR() { + message_received = true; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/OpenMV_RPC_Controller/OpenMV_RPC_Controller.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/OpenMV_RPC_Controller/OpenMV_RPC_Controller.ino new file mode 100644 index 00000000..65be2040 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/OpenMV_RPC_Controller/OpenMV_RPC_Controller.ino @@ -0,0 +1,108 @@ +// Remote Control - As The Controller Device +// +// This script configures your Arduino to remotely control another Arduino. +// +// This script is designed to pair with "arduino_to_arduino_communication_as_the_remote_device.ino" +// example sketch included with this library. + +#include +#include + +openmv::rpc_scratch_buffer<256> scratch_buffer; // All RPC objects share this buffer. + +#define RPC_OVER_SERIAL 1 + +#if defined(RPC_OVER_SERIAL) +openmv::rpc_hardware_serial1_uart_master rpc(115200); +#else +openmv::rpc_i2c1_master rpc(0x12, 10000); +#endif + +void setup() +{ + EdgeControl.begin(); + + Power.on(PWR_3V3); + Power.on(PWR_VBAT); + + Power.on(PWR_MKR2); + delay(5000); // Wait for MKR2 to power-on + + Serial.begin(115200); + rpc.begin(); +} + +////////////////////////////////////////////////////////////// +// Call Back Handlers +////////////////////////////////////////////////////////////// + +// This example shows reading a Digital I/O pin remotely. +// +void digital_read_example() +{ + uint8_t state; + if (rpc.call_no_args("digital_read", &state, sizeof(state))) { + Serial.print(F("Remote Digital I/O State: ")); + Serial.println(state); + } +} + +// This example shows reading an Analog I/O pin remotely. +// +void analog_read_example() +{ + uint16_t state; + if (rpc.call_no_args(F("analog_read"), &state, sizeof(state))) { + Serial.print(F("Remote Analog I/O State: ")); + Serial.println(state); + } +} + +// This example shows writing a Digital I/O pin remotely. +// +void digital_write_example() +{ + static uint8_t state = 0; + + auto ret = rpc.call("digital_write", &state, sizeof(state), nullptr, 0, false); + if (!ret) { + Serial.println("DigitalWrite Call Failed!"); + return; + } + state = !state; // flip state for next time +} + +// This example shows writing an Analog I/O pin remotely. +// +void analog_write_example() +{ + static uint8_t state = 0; + + auto ret = rpc.call("analog_write", &state, sizeof(state), nullptr, 0, false); + if (!ret) { + Serial.println("AnalogWrite Call Failed!"); + return; + } + + state = state + 1; // counts from 0 to 255 then rolls over +} + +void serial_print_example() +{ + String str = "Hello World @"; + str += millis(); + + char buffer[str.length() + 1] {}; + str.toCharArray(buffer, sizeof(buffer)); + + rpc.call("serial_print", buffer, sizeof(buffer)); +} + +void loop() +{ + digital_read_example(); + analog_read_example(); + digital_write_example(); + analog_write_example(); + serial_print_example(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/RPC_DweetBlink/RPC_DweetBlink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/RPC_DweetBlink/RPC_DweetBlink.ino new file mode 100644 index 00000000..3289fc03 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/RPC/RPC_DweetBlink/RPC_DweetBlink.ino @@ -0,0 +1,183 @@ +/* + Blink LED via Dweet using an MKR connected board as network interface + + This example uses the OpenMV Arduino RPC Interface Library + https://github.com/openmv/openmv-arduino-rpc to control an + Arduino MKR WiFi 1010 board stacked on the MKR connector + to send REST requests to the Dweet.io. Please, install the library + from the repo as a zip library before compile the sketch. + + The code checks for a "led" key in the content payload of the Dweet + response and sets the on-board LED accordingly. + + Requirements: + * Arduino Edge Control powered via 12V power adapter or 12V lead-acid battery + * Arduino MKR WiFi1010 stacked on connector MKR2 (the one next to the CR2032 battery holder) + * OpenMV Arduino RPC Interface Library + + Steps: + * Upload this sketch to Edge Control + * Upload the "extras/RPC/RPC_DweetBlink_Remote" sketch to the MKR 1010 + (don't forget to configure your WiFi credentials) + * Connect your favorite serial monitor or terminal emulator to both the boards + * Retrieve the Serial Number () of the Edge Control by running the sketch + * Send a Dweet to the Serial Number of the Edge Control board setting the value + of the "led" key to "on" or "off" to blink the on-board LED. Eg. + + curl -X POST http://dweet.io/dweet/for/ -F led=on + + * Current status of the LED can be retrieved from Dweet at "SERIALNUMBER-status" path, eg. + + curl -i http://dweet.io/get/latest/dweet/for/-status + + created 12 Feb 2021 + by Giampaolo Mancini +*/ + +#include +#include +#include + +// Configure the RPC controller +openmv::rpc_scratch_buffer<256> scratch_buffer; // static memory buffer +openmv::rpc_hardware_serial1_uart_master rpc(115200); + +constexpr uint32_t requestInterval { 20 * 1000 }; +uint32_t requestNow {}; + +bool ledStatus { false }; + +String serialNumber; + +void setup() +{ + Serial.begin(115200); + const uint32_t startNow = millis() + 2500; + while (!Serial && millis() < startNow) + ; + + EdgeControl.begin(); + + Power.on(PWR_3V3); + + // Enable the 5V power rail + Power.on(PWR_VBAT); + + // Power on the MKR on connector 2 + Power.on(PWR_MKR2); + // Wait for MKR2 to power-on + delay(5000); + + serialNumber = EdgeControl.serialNumber(); + Serial.print("Serial Number: "); + Serial.println(serialNumber); + + // Init the I2C bus + Wire.begin(); + delay(500); + + // Init the I/O Expander + Serial.print("I/O Expander initializazion "); + if (!Expander.begin()) { + Serial.println("failed."); + Serial.println("Please, be sure to enable gated 3V3 and 5V power rails"); + Serial.println("via Power.on(PWR_3V3) and Power.on(PWR_VBAT)."); + } + Serial.println("succeeded."); + + // Configure the LED1 pin + Expander.pinMode(EXP_LED1, OUTPUT); + // LED1 is active low + Expander.digitalWrite(EXP_LED1, HIGH); + + // Start the RPC controller + rpc.begin(); + + requestNow = millis(); +} + +void loop() +{ + if (millis() > requestNow) { + + // Post the status of the LED to Dweet using + // the serial number as device ID + rpcPostDweetFor(serialNumber); + + delay(1000); + + // Get the next status of the LED + rpcGetLatestDweetFor(serialNumber); + + requestNow = millis() + requestInterval; + } + + Expander.digitalWrite(EXP_LED1, ledStatus); +} + +void rpcPostDweetFor(String deviceID) +{ + Serial.print("Posting Status Dweet For "); + Serial.print(deviceID); + Serial.print(" via RPC: "); + + // Pass data to remote RPC client in JSON format. YMMV. + JSONVar data; + data["deviceID"] = deviceID; + // Pin LED is active low + data["ledStatus"] = !ledStatus; + + auto dataString = JSON.stringify(data); + Serial.println(dataString); + + // Call the "postDweetFor" callback on the MKR WiFi 1010 + // Remember to set large RPC timeouts: the Network is SLOW! + // + // Please, refer to openmv-rpc-arduino documentation for more + // call() examples. + auto ret = rpc.call("postDweetFor", + (void*)dataString.c_str(), dataString.length(), // arguments + NULL, 0, // no returns + false, 1000, 3000); // parameters + + if (ret == 0) { + Serial.println("Error"); + return; + } +} + +void rpcGetLatestDweetFor(String deviceID) +{ + Serial.print("Getting Latest Dweet For "); + Serial.print(deviceID); + Serial.print(" via RPC: "); + + // buffer for return data from RPC client + size_t bufferLen { scratch_buffer.buffer_size() }; + char buffer[bufferLen] {}; + + // Call the "getLatestDweetFor" callback on the MKR WiFi 1010 + // Remember to set large RPC timeouts: the Network is SLOW! + auto ret = rpc.call("getLatestDweetFor", + (void*)deviceID.c_str(), deviceID.length(), // arguments + buffer, bufferLen, // returns + true, 1000, 3000); // parameters + + if (ret == 0) { + Serial.println("Error"); + return; + } + + // Data from Dweet is in JSON format + Serial.println(buffer); + JSONVar dweet = JSON.parse(buffer); + + // Extract next LED status + JSONVar ledCommandJSON = dweet["with"][0]["content"]["led"]; + String ledCommand = (const char*)ledCommandJSON; + + // Pin LED is active low + ledStatus = !(ledCommand == "on"); + Serial.print("LED "); + Serial.println(ledStatus ? "Off" : "On"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/CardInfo/CardInfo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/CardInfo/CardInfo.ino new file mode 100644 index 00000000..a91fe6b3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/CardInfo/CardInfo.ino @@ -0,0 +1,136 @@ +/* + SD card test ported to Arduino Edge Control + + All the other example from the SD Library will work out-of-the-box + on the Edge Control board provided you remember to enable the 3V3 + power rail using the + + Power.on(PWR_3V3); + + call. + + This example shows how use the utility libraries on which the' + SD library is based in order to get info about your SD card. + Very useful for testing a card when you're not sure whether its working or not. + + The circuit: + SD card attached to SPI bus as follows: + ** MOSI - pin 11 on Arduino Uno/Duemilanove/Diecimila + ** MISO - pin 12 on Arduino Uno/Duemilanove/Diecimila + ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila + ** CS - depends on your SD card shield or module. + Pin 4 used here for consistency with other Arduino examples + + + created 28 Mar 2011 + by Limor Fried + modified 9 Apr 2012 + by Tom Igoe + modified 15 Feb 2021 + by Giampaolo Mancini +*/ + +#include + +// include the SD library: +#include +#include + +// set up variables using the SD utility library functions: +Sd2Card card; +SdVolume volume; +SdFile root; + +// change this to match your SD shield or module; +// Arduino Ethernet shield: pin 4 +// Adafruit SD shields and modules: pin 10 +// Sparkfun SD shield: pin 8 +// MKRZero SD: SDCARD_SS_PIN +const int chipSelect = PIN_SD_CS; + +void setup() +{ + // Open serial communications and wait for port to open: + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + EdgeControl.begin(); + // Power on the 3V3 rail for SD Card + Power.on(PWR_3V3); + + Serial.print("\nInitializing SD card..."); + + // we'll use the initialization code from the utility libraries + // since we're just testing if the card is working! + if (!card.init(SPI_HALF_SPEED, chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("* is a card inserted?"); + Serial.println("* is your wiring correct?"); + Serial.println("* did you change the chipSelect pin to match your shield or module?"); + while (1) + ; + } else { + Serial.println("Wiring is correct and a card is present."); + } + + // print the type of card + Serial.println(); + Serial.print("Card type: "); + switch (card.type()) { + case SD_CARD_TYPE_SD1: + Serial.println("SD1"); + break; + case SD_CARD_TYPE_SD2: + Serial.println("SD2"); + break; + case SD_CARD_TYPE_SDHC: + Serial.println("SDHC"); + break; + default: + Serial.println("Unknown"); + } + + // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 + if (!volume.init(card)) { + Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); + while (1) + ; + } + + Serial.print("Clusters: "); + Serial.println(volume.clusterCount()); + Serial.print("Blocks x Cluster: "); + Serial.println(volume.blocksPerCluster()); + + Serial.print("Total Blocks: "); + Serial.println(volume.blocksPerCluster() * volume.clusterCount()); + Serial.println(); + + // print the type and size of the first FAT-type volume + uint32_t volumesize; + Serial.print("Volume type is: FAT"); + Serial.println(volume.fatType(), DEC); + + volumesize = volume.blocksPerCluster(); // clusters are collections of blocks + volumesize *= volume.clusterCount(); // we'll have a lot of clusters + volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1KB) + Serial.print("Volume size (Kb): "); + Serial.println(volumesize); + Serial.print("Volume size (Mb): "); + volumesize /= 1024; + Serial.println(volumesize); + Serial.print("Volume size (Gb): "); + Serial.println((float)volumesize / 1024.0); + + Serial.println("\nFiles found on the card (name, date and size in bytes): "); + root.openRoot(volume); + + // list all files in the card with date and size + root.ls(LS_R | LS_DATE | LS_SIZE); +} + +void loop(void) +{ +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/SecureDigital/SecureDigital.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/SecureDigital/SecureDigital.ino new file mode 100644 index 00000000..0327b506 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/SecureDigital/SecureDigital.ino @@ -0,0 +1,222 @@ +/* + Demonstrate use of Mbed OS FAT API for SD cards on Arduino Edge Control. + Please, note that this example uses POSIX File and Filesyteam APIS. + + If your are looking for how to use the classic Arduino "SD" library with + the Arduino Edge Control, check the CardInfo example. + + Please, look at Mbed OS documentation for details + * https://os.mbed.com/docs/mbed-os/v6.7/apis/sdblockdevice.html + * https://os.mbed.com/docs/mbed-os/v6.7/apis/fatfilesystem.html + + + Ported from mbed-os-example-filesystem + + * Arduino Edge Control + * MicroSD Memory Card +*/ + +#include + +#include +#include +using namespace mbed; + +SDBlockDevice bd(SD_MOSI, SD_MISO, SD_CLK, SD_CS); + +// The parameter indicates the MbedOS-wide mount point +// where the root of the filesystem on the SD will be available at. +FATFileSystem fat("fat"); + +void setup() +{ + EdgeControl.begin(); + Power.on(PWR_3V3); + + Serial.begin(115200); + while (!Serial) + ; + + delay(2000); + Serial.println("Arduino Edge Control w/ SD and FAT"); + + Serial.print("Initializing SD Card:"); + int err = bd.init(); + if (err != 0) { + Serial.print(" FAIL!"); + Serial.print("Please, check your SD Card."); + while(true); + } + Serial.println(" SUCCESS!"); + Serial.print("SD size: "); + Serial.println(bd.size()); + Serial.print("SD read size: "); + Serial.println(bd.get_read_size()); + Serial.print("SD program size: "); + Serial.println(bd.get_program_size()); + Serial.print("SD erase size: "); + Serial.println(bd.get_erase_size()); + + Serial.print("Mounting... "); + err = fat.mount(&bd); + Serial.println(err ? "Fail :(" : "OK"); + if (err) { + Error(); + // Format and remount + Serial.println("No filesystem found, formatting..."); + err = fat.reformat(&bd); + if (err) { + Error(); + while (1) + ; + } + } + + Serial.println("Hello, FAT!"); + // Open the numbers file + Serial.print("Opening \"/fat/numbers.txt\"... "); + FILE* f = fopen("/fat/numbers.txt", "r+"); + Serial.println(!f ? "Fail :(" : "OK"); + if (!f) { + // Create the numbers file if it doesn't exist + Serial.print("No file found, creating a new file... "); + f = fopen("/fat/numbers.txt", "w+"); + Serial.println(!f ? "Fail :(" : "OK"); + if (!f) { + Error(); + while (1) + ; + } + + for (int i = 0; i < 10; i++) { + Serial.println(); + Serial.print("Writing numbers ("); + Serial.print(i); + Serial.print("/"); + Serial.print(10); + Serial.print(")... "); + err = fprintf(f, " %d\n", i); + if (err < 0) { + Serial.println("Fail :("); + Error(); + } + } + Serial.println(); + Serial.println("Writing numbers (10/10)... OK"); + + Serial.print("Seeking file... "); + err = fseek(f, 0, SEEK_SET); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + } + + // Go through and increment the numbers + Serial.println("Incrementing numbers:"); + for (int i = 0; i < 10; i++) { + Serial.print("("); + Serial.print(i); + Serial.print("/"); + Serial.print(10); + Serial.print("): "); + + // Get current stream position + long pos = ftell(f); + + // Parse out the number and increment + int32_t number; + fscanf(f, "%d", &number); + Serial.println(number); + number += 1; + + // Seek to beginning of number + fseek(f, pos, SEEK_SET); + + // Store number + fprintf(f, " %d\n", number); + + // Flush between write and read on same file + fflush(f); + } + Serial.println("Done."); + + // Close the file which also flushes any cached writes + Serial.print("Closing \"/fat/numbers.txt\"... "); + err = fclose(f); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + + // Display the root directory + Serial.print("Opening the root directory... "); + DIR* d = opendir("/fat/"); + Serial.println(!d ? "Fail :(" : "OK"); + if (!d) { + Error(); + } + + Serial.println("root directory:"); + while (true) { + struct dirent* e = readdir(d); + if (!e) { + break; + } + + Serial.print(" "); + Serial.println(e->d_name); + } + + Serial.print("Closing the root directory... "); + err = closedir(d); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + + // Display the numbers file + Serial.print("Opening \"/fat/numbers.txt\"... "); + f = fopen("/fat/numbers.txt", "r"); + Serial.println(!f ? "Fail :(" : "OK"); + if (!f) { + Error(); + } + + Serial.println("numbers:"); + while (!feof(f)) { + int c = fgetc(f); + Serial.print(c); + } + + Serial.print("Closing \"/fat/numbers.txt\"... "); + err = fclose(f); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + + // Tidy up + Serial.print("Unmounting... "); + err = fat.unmount(); + Serial.println(err < 0 ? "Fail :(" : "OK"); + if (err < 0) { + Error(); + } + + Serial.println("Mbed OS filesystem example done!"); +} + +void loop() +{ + // put your main code here, to run repeatedly: +} + +void Error() +{ + Serial.print("ERRNO: "); + Serial.print(errno); + Serial.print("("); + Serial.print(strerror(errno)); + Serial.println(")"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/StoragePartitions.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/StoragePartitions.ino new file mode 100644 index 00000000..2658f8e7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/StoragePartitions.ino @@ -0,0 +1,220 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +using namespace std::chrono_literals; + +#include "edge_control_storage_limits.h" + +using namespace mbed; + +// Connect to the on-board serial flash device +// https://os.mbed.com/docs/mbed-os/v6.4/apis/spifblockdevice.html +// SPIFBlockDevice root(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_SS, 40000000); +SPIFBlockDevice root(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_SS, SPIF_FREQ); + +constexpr int USER_DATA_PARTITION { 1 }; +constexpr int TDBS_DATA_PARTITION { 2 }; + +// Define block devices for serial flash partitions +// https://os.mbed.com/docs/mbed-os/v6.4/apis/mbrblockdevice.html +// Partition for user filesystem (LittleFS) +MBRBlockDevice user_data(&root, USER_DATA_PARTITION); +// Partition for user keyvalu store (TDBStore) +MBRBlockDevice tdbs_data(&root, TDBS_DATA_PARTITION); + +// Define the start and stop addresses of the partitions +// Start from the first user-available block... +constexpr bd_addr_t USER_DATA_PARTITION_START { USER_BLOCKS_START }; +// ... reserve 4MB for user filesystem... +constexpr bd_addr_t USER_DATA_PARTITION_STOP { SPIF_SIZE / 2 }; +// ... start keyvalue store space from there... +constexpr bd_addr_t TDBS_DATA_PARTITION_START { USER_DATA_PARTITION_STOP }; +// ... and reserve all the ramaining space until last user-available block. +constexpr bd_addr_t TDBS_DATA_PARTITION_STOP { USER_BLOCKS_STOP }; + +// Filesystem for user data +// https://os.mbed.com/docs/mbed-os/v6.4/apis/littlefilesystem.html +// +// LittleFS is a fail-safe filesystem for embedded systems: +// this is the recommended filesystem for user data storage. +LittleFileSystem user_data_fs("user"); + +// KeyValue store for user data +// https://os.mbed.com/docs/mbed-os/v6.4/apis/kvstore.html +// ATTENTION, PLEASE! +// This is a very powerful API that can be used to create +// an EEPROM-style API using the on-board serial flash. +TDBStore tdb_store(&tdbs_data); + +// Define MbesOS Tickers for recurring tasks +// https://os.mbed.com/docs/mbed-os/v6.4/apis/ticker.html +Ticker lister; +Ticker writer; +volatile bool doList { false }; +volatile bool doWrite { false }; + +Timer t; + +void setup() +{ + int err; + + Serial.begin(115200); + while (!Serial) + ; + + delay(1000); + + Serial.println("Starting Partitions and Storage Example."); + + EdgeControl.begin(); + + Power.on(PWR_3V3); + + // Define partition for User LittleFS filesystem + err = MBRBlockDevice::partition(&root, USER_DATA_PARTITION, 0x83, USER_DATA_PARTITION_START, USER_DATA_PARTITION_STOP); + Serial.println("Partition " + String(USER_DATA_PARTITION) + (err == 0 ? " OK" : " KO") + " (" + String(err) + ")"); + + // Define partition for User KeyValue store + err = MBRBlockDevice::partition(&root, TDBS_DATA_PARTITION, 0x83, TDBS_DATA_PARTITION_START, TDBS_DATA_PARTITION_STOP); + Serial.println("Partition " + String(TDBS_DATA_PARTITION) + (err == 0 ? " OK" : " KO") + " (" + String(err) + ")"); + + Serial.print("Mount LittleFS filesystem on Partition " + String(USER_DATA_PARTITION) + ": "); + err = user_data_fs.mount(&user_data); + if (err) { + Serial.print("No LittleFS filesystem found, formatting... "); + err = user_data_fs.reformat(&user_data); + } + Serial.println("done"); + + Serial.println("Init TinyDB Key Value store"); + err = tdb_store.init(); + Serial.println("TDB Init " + String(err == 0 ? "OK" : "KO") + " (" + String(err) + ")"); + + // Store data every 1 second + writer.attach([] { doWrite = true; }, 1s); + + // Display data every 5 seconds + lister.attach([] { doList = true; }, 5s); + + // Init the RNG + srand(t.elapsed_time().count()); +} + +void loop() +{ + if (doList) { + doList = false; + listDirs(); + } + + if (doWrite) { + doWrite = false; + storeData(); + } +} + +void storeData() +{ + constexpr char data_key[] { "data_key" }; + uint8_t data_value { 0 }; + size_t _actual; + + int res; + + // Get stored data, if any. Increment and save on success. + // Please, refer to https://os.mbed.com/docs/mbed-os/v6.4/apis/kvstore.html + // for more API use examples. + res = tdb_store.get(data_key, &data_value, sizeof(data_value), &_actual); + if (res == MBED_SUCCESS) { + Serial.print(data_key); + Serial.print(": "); + Serial.println(data_value); + data_value++; + } + tdb_store.set(data_key, &data_value, sizeof(data_value), 0); + + // Store a random key with random data + String random_key = "key_"; + random_key += String(rand(), HEX); + auto random_data = rand(); + res = tdb_store.set(random_key.c_str(), &random_data, sizeof(random_data), 0); + if (res == MBED_SUCCESS) + Serial.println(random_key + ": " + String(random_data)); + + // Append data to file on LittleFS filesystem + // Any MbedOS filesystem exposes a POSIX-compliant API: + // use the standard functions here. + FILE* f = fopen("/user/numbers.csv", "a"); + if (f != nullptr) { + String line; + line += static_cast(time(nullptr)); + line += ','; + line += data_value; + line += '\n'; + fputs(line.c_str(), f); + fclose(f); + } +} + +void listDirs() +{ + DIR* dir; + struct dirent* ent; + + Serial.println("Listing /user on LittleFS Filesystem"); + if ((dir = opendir("/user")) != nullptr) { + while ((ent = readdir(dir)) != nullptr) { + String fullname = "/user/" + String(ent->d_name); + Serial.println(fullname); + } + closedir(dir); + + FILE* f = fopen("/user/numbers.csv", "r+"); + if (f != nullptr) { + char buf[64] { 0 }; + while (std::fgets(buf, sizeof buf, f) != nullptr) + Serial.print(buf); + fclose(f); + } + } + + + // Use a TDBStore iterator to retrieve all the keys + TDBStore::iterator_t it; + TDBStore::info_t info; + size_t actual_size; + + // Iterate over all the keys starting with name "key_" + tdb_store.iterator_open(&it, "key_"); + char key[128] { 0 }; + while (tdb_store.iterator_next(it, key, sizeof(key)) != MBED_ERROR_ITEM_NOT_FOUND) { + // Get info about the key and its contents + tdb_store.get_info(key, &info); + + char buf[128]; + sprintf(buf, "Key: %-12s - Size: %d - ", key, info.size); + Serial.print(buf); + + // Get the value using parameters from the info retrieved + int out; + tdb_store.get(key, &out, info.size, &actual_size); + + // Do something useful with the key-value pair... + sprintf(buf, "Value (%d): %10d - ", actual_size, out); + Serial.print(buf); + + + // .. then (optionally) remove the key + tdb_store.remove(key); + Serial.println("Removed."); + } + // Close the iterator at the end of the cycle + tdb_store.iterator_close(it); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/edge_control_storage_limits.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/edge_control_storage_limits.h new file mode 100644 index 00000000..87a689d7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_EdgeControl/examples/Storage/StoragePartitions/edge_control_storage_limits.h @@ -0,0 +1,11 @@ +#pragma once + +using namespace mbed; + + +constexpr bd_addr_t SPIF_SIZE { 2 * 1024 * 1024 }; + +constexpr bd_addr_t USER_BLOCKS_START { 0 }; +constexpr bd_addr_t USER_BLOCKS_STOP { SPIF_SIZE }; + +constexpr int SPIF_FREQ { 32'000'000 }; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/README.adoc new file mode 100644 index 00000000..a46504df --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/README.adoc @@ -0,0 +1,29 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_HTS221 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the temperature and humidity sensors of your Nano 33 BLE Sense. + + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensors/ReadSensors.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensors/ReadSensors.ino new file mode 100644 index 00000000..890adf5a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensors/ReadSensors.ino @@ -0,0 +1,45 @@ +/* + HTS221 - Read Sensors + + This example reads data from the on-board HTS221 sensor of the + Nano 33 BLE Sense and prints the temperature and humidity sensor + values to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!HTS.begin()) { + Serial.println("Failed to initialize humidity temperature sensor!"); + while (1); + } +} + +void loop() { + // read all the sensor values + float temperature = HTS.readTemperature(); + float humidity = HTS.readHumidity(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °C"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensorsImperial/ReadSensorsImperial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensorsImperial/ReadSensorsImperial.ino new file mode 100644 index 00000000..c6cf9552 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/ReadSensorsImperial/ReadSensorsImperial.ino @@ -0,0 +1,46 @@ +/* + HTS221 - Read Sensors Imperial + + This example reads data from the on-board HTS221 sensor of the + Nano 33 BLE Sense then, prints the temperature and humidity sensor + values in imperial units to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!HTS.begin()) { + Serial.println("Failed to initialize humidity temperature sensor!"); + while (1); + } +} + +void loop() { + // Passing in FAHRENHEIT as the unit parameter to HTS.readTemperature(...), + // allows you to read the sensor values in imperial units + float temperature = HTS.readTemperature(FAHRENHEIT); + float humidity = HTS.readHumidity(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °F"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/TemperatureAlert/TemperatureAlert.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/TemperatureAlert/TemperatureAlert.ino new file mode 100644 index 00000000..beb44fa8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_HTS221/examples/TemperatureAlert/TemperatureAlert.ino @@ -0,0 +1,48 @@ +/* + HTS221 - Temperature Alert + This example reads data from the on-board HTS221 sensor of the + Nano 33 BLE Sense. If the temperature increases above a certain limit, it turns the buzzer on. + The circuit: + - Arduino Nano 33 BLE Sense + - Active buzzer module connected to pin 9 and GND + + written by K.Abhijeet + This example code is in the public domain +*/ + +#include + +float tempLimit = 37; // set your temperature limit in °C + +void setup() { + Serial.begin(9600); + while (!Serial); + + pinMode(9, OUTPUT); + + if (!HTS.begin()) { + Serial.println("Failed to initialize humidity temperature sensor!"); + while (1); + } +} + +void loop() { + + float temperature = HTS.readTemperature(); // read the sensor value + + Serial.print("Temperature = "); // print the sensor value + Serial.print(temperature); + Serial.println(" °C"); + + if (temperature > tempLimit) + { + digitalWrite(9, HIGH); + delay(500); + digitalWrite(9, LOW); + delay(500); + } + else + { + delay(2000); // wait a while before displaying the next reading If the temperature is below the limit + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/README.adoc new file mode 100644 index 00000000..04f99b60 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_JSON + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Process JSON in your Arduino sketches. + +This library is based on https://github.com/DaveGamble/cJSON[cJSON]. + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONArray/JSONArray.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONArray/JSONArray.ino new file mode 100644 index 00000000..3fb80a8b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONArray/JSONArray.ino @@ -0,0 +1,104 @@ +/* + JSON Array + + This sketch demonstrates how to use various features + of the Official Arduino_JSON library, in particular for JSON arrays. + + This example code is in the public domain. +*/ + +#include + +const char input[] = "[true, 42, \"apple\"]"; + +void setup() { + Serial.begin(9600); + while (!Serial); + + demoParse(); + + demoCreation(); +} + +void loop() { +} + +void demoParse() { + Serial.println("parse"); + Serial.println("====="); + + JSONVar myArray = JSON.parse(input); + + // JSON.typeof(jsonVar) can be used to get the type of the variable + if (JSON.typeof(myArray) == "undefined") { + Serial.println("Parsing input failed!"); + return; + } + + Serial.print("JSON.typeof(myArray) = "); + Serial.println(JSON.typeof(myArray)); // prints: array + + // myArray.length() can be used to get the length of the array + Serial.print("myArray.length() = "); + Serial.println(myArray.length()); + Serial.println(); + + Serial.print("JSON.typeof(myArray[0]) = "); + Serial.println(JSON.typeof(myArray[0])); + + Serial.print("myArray[0] = "); + Serial.println(myArray[0]); + Serial.println(); + + Serial.print("myArray[1] = "); + Serial.println((int) myArray[1]); + Serial.println(); + + Serial.print("myArray[2] = "); + Serial.println((const char*) myArray[2]); + Serial.println(); + + Serial.println(); +} + +void demoCreation() { + Serial.println("creation"); + Serial.println("========"); + + JSONVar myArray; + + myArray[0] = false; + myArray[1] = 4242.5; + myArray[2] = "orange"; + myArray[3] = "world"; + myArray[4] = true; + myArray[5] = 42; + + Serial.print("myArray.length() = "); + Serial.println(myArray.length()); + + // JSON.stringify(myVar) can be used to convert the JSONVar to a String + String jsonString = JSON.stringify(myArray); + + Serial.print("JSON.stringify(myArray) = "); + Serial.println(jsonString); + Serial.println(); + + for (int i = 0; i < myArray.length(); i++) { + JSONVar value = myArray[i]; + + Serial.print("JSON.typeof(myArray["); + Serial.print(i); + Serial.print("]) = "); + Serial.println(JSON.typeof(value)); + + Serial.print("myArray["); + Serial.print(i); + Serial.print("] = "); + Serial.println(value); + + Serial.println(); + } + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONKitchenSink/JSONKitchenSink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONKitchenSink/JSONKitchenSink.ino new file mode 100644 index 00000000..f2245050 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONKitchenSink/JSONKitchenSink.ino @@ -0,0 +1,165 @@ +/* + JSON Kitchen Sink + + This sketch demonstrates how to use various features + of the Official Arduino_JSON library. + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + // boolean + booleanDemo(); + + intDemo(); + + doubleDemo(); + + stringDemo(); + + arrayDemo(); + + objectDemo(); +} + +void loop() { +} + +void booleanDemo() { + Serial.println("boolean"); + Serial.println("======="); + + JSONVar myBoolean = true; + + Serial.print("JSON.typeof(myBoolean) = "); + Serial.println(JSON.typeof(myBoolean)); // prints: boolean + + Serial.print("myBoolean = "); + Serial.println(myBoolean); // prints: true + + myBoolean = false; + + Serial.print("myBoolean = "); + Serial.println((boolean) myBoolean); // prints: 0 + + Serial.println(); +} + +void intDemo() { + Serial.println("int"); + Serial.println("==="); + + JSONVar myInt = 42; + + Serial.print("JSON.typeof(myInt) = "); + Serial.println(JSON.typeof(myInt)); // prints: number + + Serial.print("myInt = "); + Serial.println(myInt); // prints: 42 + + myInt = 4242; + + Serial.print("myInt = "); + Serial.println((int) myInt); // prints: 4242 + + Serial.println(); +} + +void doubleDemo() { + Serial.println("double"); + Serial.println("======"); + + JSONVar myDouble = 42.5; + + Serial.print("JSON.typeof(myDouble) = "); + Serial.println(JSON.typeof(myDouble)); // prints: number + + Serial.print("myDouble = "); + Serial.println(myDouble); // prints: 42.5 + + myDouble = 4242.4242; + + Serial.print("myDouble = "); + Serial.println((double) myDouble, 4); // prints: 4242.4242 + + Serial.println(); +} + +void stringDemo() { + Serial.println("string"); + Serial.println("======"); + + JSONVar myString = "Hello World!"; + + Serial.print("JSON.typeof(myString) = "); + Serial.println(JSON.typeof(myString)); // prints: string + + Serial.print("myString = "); + Serial.println(myString); // prints: Hello World! + + myString = ":)"; + + Serial.print("myString = "); + Serial.println((const char*) myString); // prints: :) + + Serial.println(); +} + +void arrayDemo() { + Serial.println("array"); + Serial.println("====="); + + JSONVar myArray; + + myArray[0] = 42; + + Serial.print("JSON.typeof(myArray) = "); + Serial.println(JSON.typeof(myArray)); // prints: array + + Serial.print("myArray = "); + Serial.println(myArray); // prints: [42] + + Serial.print("myArray[0] = "); + Serial.println((int)myArray[0]); // prints: 42 + + myArray[1] = 42.5; + + Serial.print("myArray = "); + Serial.println(myArray); // prints: [42,42.5] + + Serial.print("myArray[1] = "); + Serial.println((double)myArray[1]); // prints: 42.50 + + Serial.println(); +} + +void objectDemo() { + Serial.println("object"); + Serial.println("======"); + + JSONVar myObject; + + myObject["foo"] = "bar"; + + Serial.print("JSON.typeof(myObject) = "); + Serial.println(JSON.typeof(myObject)); // prints: object + + Serial.print("myObject.keys() = "); + Serial.println(myObject.keys()); // prints: ["foo"] + + Serial.print("myObject = "); + Serial.println(myObject); // prints: {"foo":"bar"} + + myObject["blah"]["abc"] = 42; + + Serial.print("myObject.keys() = "); + Serial.println(myObject.keys()); // prints: ["foo","blah"] + + Serial.print("myObject = "); + Serial.println(myObject); // prints: {"foo":"bar","blah":{"abc":42}} +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONObject/JSONObject.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONObject/JSONObject.ino new file mode 100644 index 00000000..786185a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_JSON/examples/JSONObject/JSONObject.ino @@ -0,0 +1,123 @@ +/* + JSON Object + + This sketch demonstrates how to use various features + of the Official Arduino_JSON library, in particular for JSON objects. + + This example code is in the public domain. +*/ + +#include + +const char input[] = "{\"result\":true,\"count\":42,\"foo\":\"bar\"}"; + +void setup() { + Serial.begin(9600); + while (!Serial); + + demoParse(); + + demoCreation(); +} + +void loop() { +} + +void demoParse() { + Serial.println("parse"); + Serial.println("====="); + + JSONVar myObject = JSON.parse(input); + + // JSON.typeof(jsonVar) can be used to get the type of the variable + if (JSON.typeof(myObject) == "undefined") { + Serial.println("Parsing input failed!"); + return; + } + + Serial.print("JSON.typeof(myObject) = "); + Serial.println(JSON.typeof(myObject)); // prints: object + + // myObject.hasOwnProperty(key) checks if the object contains an entry for key + if (myObject.hasOwnProperty("result")) { + Serial.print("myObject[\"result\"] = "); + + Serial.println((bool) myObject["result"]); + } + + if (myObject.hasOwnProperty("count")) { + Serial.print("myObject[\"count\"] = "); + + Serial.println((int) myObject["count"]); + } + + if (myObject.hasOwnProperty("count")) { + Serial.print("myObject[\"count\"] = "); + + Serial.println((double) myObject["count"]); + } + + if (myObject.hasOwnProperty("foo")) { + Serial.print("myObject[\"foo\"] = "); + + Serial.println((const char*) myObject["foo"]); + } + + // JSONVars can be printed using print or println + Serial.print("myObject = "); + Serial.println(myObject); + + Serial.println(); +} + +void demoCreation() { + Serial.println("creation"); + Serial.println("========"); + + JSONVar myObject; + + myObject["hello"] = "world"; + myObject["true"] = true; + myObject["x"] = 42; + + Serial.print("myObject.keys() = "); + Serial.println(myObject.keys()); + + // JSON.stringify(myVar) can be used to convert the JSONVar to a String + String jsonString = JSON.stringify(myObject); + + Serial.print("JSON.stringify(myObject) = "); + Serial.println(jsonString); + + Serial.println(); + + // myObject.keys() can be used to get an array of all the keys in the object + JSONVar keys = myObject.keys(); + + for (int i = 0; i < keys.length(); i++) { + JSONVar value = myObject[keys[i]]; + + Serial.print("JSON.typeof(myObject["); + Serial.print(keys[i]); + Serial.print("]) = "); + Serial.println(JSON.typeof(value)); + + Serial.print("myObject["); + Serial.print(keys[i]); + Serial.print("] = "); + Serial.println(value); + + Serial.println(); + } + + Serial.println(); + + // setting a value to undefined can remove it from the object + myObject["x"] = undefined; + + // you can also change a value + myObject["hello"] = "there!"; + + Serial.print("myObject = "); + Serial.println(myObject); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/README.adoc new file mode 100644 index 00000000..157ea387 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/README.adoc @@ -0,0 +1,29 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_LPS22HB + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the pressure sensor of your Nano 33 BLE Sense. + + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressure/ReadPressure.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressure/ReadPressure.ino new file mode 100644 index 00000000..00bb7c1b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressure/ReadPressure.ino @@ -0,0 +1,47 @@ +/* + LPS22HB - Read Pressure + + This example reads data from the on-board LPS22HB sensor of the + Nano 33 BLE Sense and prints the temperature and pressure sensor + value to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!BARO.begin()) { + Serial.println("Failed to initialize pressure sensor!"); + while (1); + } +} + +void loop() { + // read the sensor value + float pressure = BARO.readPressure(); + + // print the sensor value + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" kPa"); + + float temperature = BARO.readTemperature(); + + // print the sensor value + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" C"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressureImperial/ReadPressureImperial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressureImperial/ReadPressureImperial.ino new file mode 100644 index 00000000..464375be --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LPS22HB/examples/ReadPressureImperial/ReadPressureImperial.ino @@ -0,0 +1,48 @@ +/* + LPS22HB - Read Pressure Imperial + + This example reads data from the on-board LPS22HB sensor of the + Nano 33 BLE Sense and prints the temperature and pressure sensor + value in imperial units to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!BARO.begin()) { + Serial.println("Failed to initialize pressure sensor!"); + while (1); + } +} + +void loop() { + // Passing PSI to readPressure(...) + // allows you to read the sensor values in imperial units + float pressure = BARO.readPressure(PSI); + + // print the sensor value + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" psi"); + + float temperature = BARO.readTemperature(); + + // print the sensor value + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" C"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/README.adoc new file mode 100644 index 00000000..81f5ae88 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/README.adoc @@ -0,0 +1,12 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_LSM6DS3 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the accelerometer and gyroscope values from the LSM6DS3 IMU on your Arduino Nano 33 IoT or Arduino Uno WiFi Rev2 boards. + +For more information about this library please visit us at https://www.arduino.cc/reference/en/libraries/arduino_lsm6ds3/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleAccelerometer/SimpleAccelerometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleAccelerometer/SimpleAccelerometer.ino new file mode 100644 index 00000000..9f8a9178 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleAccelerometer/SimpleAccelerometer.ino @@ -0,0 +1,49 @@ +/* + Arduino LSM6DS3 - Simple Accelerometer + + This example reads the acceleration values from the LSM6DS3 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1); + } + + Serial.print("Accelerometer sample rate = "); + Serial.print(IMU.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Acceleration in g's"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.accelerationAvailable()) { + IMU.readAcceleration(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleGyroscope/SimpleGyroscope.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleGyroscope/SimpleGyroscope.ino new file mode 100644 index 00000000..100e1a4d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM6DS3/examples/SimpleGyroscope/SimpleGyroscope.ino @@ -0,0 +1,49 @@ +/* + Arduino LSM6DS3 - Simple Gyroscope + + This example reads the gyroscope values from the LSM6DS3 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1); + } + + Serial.print("Gyroscope sample rate = "); + Serial.print(IMU.gyroscopeSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Gyroscope in degrees/second"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.gyroscopeAvailable()) { + IMU.readGyroscope(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/README.adoc new file mode 100644 index 00000000..d4cd7b51 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/README.adoc @@ -0,0 +1,10 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_LSM9DS1 + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the accelerometer, magnetometer and gyroscope values from the LSM9DS1 IMU on your Arduino Nano 33 BLE Sense. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleAccelerometer/SimpleAccelerometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleAccelerometer/SimpleAccelerometer.ino new file mode 100644 index 00000000..7c282552 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleAccelerometer/SimpleAccelerometer.ino @@ -0,0 +1,49 @@ +/* + Arduino LSM9DS1 - Simple Accelerometer + + This example reads the acceleration values from the LSM9DS1 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Nano 33 BLE Sense + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + Serial.println("Started"); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1); + } + + Serial.print("Accelerometer sample rate = "); + Serial.print(IMU.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Acceleration in g's"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.accelerationAvailable()) { + IMU.readAcceleration(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleGyroscope/SimpleGyroscope.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleGyroscope/SimpleGyroscope.ino new file mode 100644 index 00000000..9aab70a4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleGyroscope/SimpleGyroscope.ino @@ -0,0 +1,48 @@ +/* + Arduino LSM9DS1 - Simple Gyroscope + + This example reads the gyroscope values from the LSM9DS1 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Nano 33 BLE Sense + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + Serial.println("Started"); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1); + } + Serial.print("Gyroscope sample rate = "); + Serial.print(IMU.gyroscopeSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Gyroscope in degrees/second"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.gyroscopeAvailable()) { + IMU.readGyroscope(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleMagnetometer/SimpleMagnetometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleMagnetometer/SimpleMagnetometer.ino new file mode 100644 index 00000000..02c9d391 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_LSM9DS1/examples/SimpleMagnetometer/SimpleMagnetometer.ino @@ -0,0 +1,48 @@ +/* + Arduino LSM9DS1 - Simple Magnetometer + + This example reads the magnetic field values from the LSM9DS1 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Nano 33 BLE Sense + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + Serial.println("Started"); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1); + } + Serial.print("Magnetic field sample rate = "); + Serial.print(IMU.magneticFieldSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Magnetic Field in uT"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.magneticFieldAvailable()) { + IMU.readMagneticField(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/README.md new file mode 100644 index 00000000..993484a5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/README.md @@ -0,0 +1,32 @@ +# MCHPTouch Library for Arduino + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MCHPTouch/actions/workflows/spell-check.yml) + +This library allows you to read touch sensors values from the [Arduino MKR](https://store.arduino.cc/arduino-mkr-wifi-1010) boards and the [Arduino Nano 33 IoT](https://store.arduino.cc/arduino-nano-33-iot). Touch sensing is a hardware capability of the SAMD21 processor. + +```c++ +#include "Arduino_MCHPTouch.h" + +void setup() { + TOUCH.begin(); +} + +void loop() { + TOUCH.poll(); + if (TOUCH.available()) { + int value = TOUCH.read(0); // read sensor 0 + } +} +``` + +See the bundled [examples](examples/) for usage and visit the [Microchip Developer](https://microchipdeveloper.com/touch:start) website to learn more about touch sensing. + +## License + +This library is a wrapper around the MCHPTouch library by Microchip, which is bundled in binary form in this distribution in agreement with Microchip. + +> Microchip Technology Inc., provides the Microchip Touch Library software subject to the license terms contained at the link below.  By using the Microchip Touch Library, you acknowledge and agree to the terms of the license contained at the link below. [Microchip Touch Library License Agreement](Microchip%20Touch%20Library%20License%20Agreement%20-%20Arduino%20082420.pdf) + +The Arduino_MCHPTouch wrapper library is distributed under the terms of the MPL-2.0 license. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/examples/ReadSensors/ReadSensors.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/examples/ReadSensors/ReadSensors.ino new file mode 100644 index 00000000..3606213d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/examples/ReadSensors/ReadSensors.ino @@ -0,0 +1,52 @@ +/* + Arduino_MCHPTouch - Sensor data read example + This example shows how to configure and read data + from touch sensor buttons on MKR IoT Carrier and + prints updates to the Serial Monitor. + + The circuit: + - Arduino MKR board + - MKR IoT Carrier + + This example code is in the public domain. +*/ +#include "Arduino_MCHPTouch.h" + +void setup() +{ + Serial.begin(9600); + while (!Serial) + ; + // QTouch initialization + if (!TOUCH.begin()) + { + Serial.println("Error in sensors initialization!"); + while (1) + ; + } + Serial.println("Touch initialization Done!"); +} + +void loop() +{ + // polling the sensor for new data + TOUCH.poll(); + + // Checks if new data are available + if (TOUCH.available()) + { + //reads senseors + Serial.print("Sensor 1 status: "); + Serial.println(TOUCH.read(0)); + Serial.print("Sensor 2 status: "); + Serial.println(TOUCH.read(1)); + Serial.print("Sensor 3 status: "); + Serial.println(TOUCH.read(2)); + Serial.print("Sensor 4 status: "); + Serial.println(TOUCH.read(3)); + Serial.print("Sensor 5 status: "); + Serial.println(TOUCH.read(4)); + Serial.println(); + } + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/examples/setCustomSensitivity/setCustomSensitivity.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/examples/setCustomSensitivity/setCustomSensitivity.ino new file mode 100644 index 00000000..5b5adddb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MCHPTouch/examples/setCustomSensitivity/setCustomSensitivity.ino @@ -0,0 +1,56 @@ +/* + Arduino_MCHPTouch - Sensor data read example + This example shows how to configure and read data + from touch sensor buttons on MKR IoT Carrier and + prints updates to the Serial Monitor. + + The circuit: + - Arduino MKR board + - MKR IoT Carrier + + This example code is in the public domain. +*/ +#include "Arduino_MCHPTouch.h" + +void setup() +{ + Serial.begin(9600); + while (!Serial) + ; + //Set custom sensitivity on X channel + //TOUCH.setSensorsSensitivity(*newSensitivity*, channel); + TOUCH.setSensorsSensitivity(98, 0); + // QTouch initialization + if (!TOUCH.begin()) + { + Serial.println("Error in sensors initialization!"); + while (1) + ; + } + Serial.println("Touch initialization Done!"); +} + +void loop() +{ + // polling the sensor for new measure + TOUCH.poll(); + + // Checks if new data are available + if (TOUCH.available()) + { + //reads sensors + + Serial.print("Sensor 1 status: "); + Serial.println(TOUCH.read(0)); + Serial.print("Sensor 2 status: "); + Serial.println(TOUCH.read(1)); + Serial.print("Sensor 3 status: "); + Serial.println(TOUCH.read(2)); + Serial.print("Sensor 4 status: "); + Serial.println(TOUCH.read(3)); + Serial.print("Sensor 5 status: "); + Serial.println(TOUCH.read(4)); + Serial.println(); + } + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/README.adoc new file mode 100644 index 00000000..9a36c5cc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_MKRENV + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the temperature, humidity, pressure, light and UV sensors of your MKR ENV shield. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensors/ReadSensors.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensors/ReadSensors.ino new file mode 100644 index 00000000..430aaefa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensors/ReadSensors.ino @@ -0,0 +1,67 @@ +/* + MKR ENV Shield - Read Sensors + + This example reads the sensors on-board the MKR ENV Shield + and prints them to the Serial Monitor once a second. + + The circuit: + - Arduino MKR board + - Arduino MKR ENV Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ENV.begin()) { + Serial.println("Failed to initialize MKR ENV Shield!"); + while (1); + } +} + +void loop() { + // read all the sensor values + float temperature = ENV.readTemperature(); + float humidity = ENV.readHumidity(); + float pressure = ENV.readPressure(); + float illuminance = ENV.readIlluminance(); + float uva = ENV.readUVA(); + float uvb = ENV.readUVB(); + float uvIndex = ENV.readUVIndex(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °C"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" kPa"); + + Serial.print("Illuminance = "); + Serial.print(illuminance); + Serial.println(" lx"); + + Serial.print("UVA = "); + Serial.println(uva); + + Serial.print("UVB = "); + Serial.println(uvb); + + Serial.print("UV Index = "); + Serial.println(uvIndex); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensorsImperial/ReadSensorsImperial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensorsImperial/ReadSensorsImperial.ino new file mode 100644 index 00000000..e5d24eae --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRENV/examples/ReadSensorsImperial/ReadSensorsImperial.ino @@ -0,0 +1,69 @@ +/* + MKR ENV Shield - Read Sensors Imperial + + This example reads the sensors on-board the MKR ENV Shield + and prints them in imperial units to the Serial Monitor once a second. + + The circuit: + - Arduino MKR board + - Arduino MKR ENV Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ENV.begin()) { + Serial.println("Failed to initialize MKR ENV Shield!"); + while (1); + } +} + +void loop() { + // Passing in FAHRENHEIT as the unit parameter to ENV.readTemperature(...), + // PSI to readPressure(...) and FOOTCANDLE to readIlluminance(...) + // allows you to read the sensor values in imperial units + float temperature = ENV.readTemperature(FAHRENHEIT); + float humidity = ENV.readHumidity(); + float pressure = ENV.readPressure(PSI); + float illuminance = ENV.readIlluminance(FOOTCANDLE); + float uva = ENV.readUVA(); + float uvb = ENV.readUVB(); + float uvIndex = ENV.readUVIndex(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °F"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" psi"); + + Serial.print("Illuminance = "); + Serial.print(illuminance); + Serial.println(" fc"); + + Serial.print("UVA = "); + Serial.println(uva); + + Serial.print("UVB = "); + Serial.println(uvb); + + Serial.print("UV Index = "); + Serial.println(uvIndex); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/README.adoc new file mode 100644 index 00000000..9e61f2f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/README.adoc @@ -0,0 +1,14 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_MKRGPS + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the location from the GPS on your MKR GPS Shield. + +This library is based on https://github.com/kosma/minmea[minmea]. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/ArduinoMKRGPS diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocation/GPSLocation.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocation/GPSLocation.ino new file mode 100644 index 00000000..e2c9a47d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocation/GPSLocation.ino @@ -0,0 +1,60 @@ +/* + GPS Location + + This sketch uses the GPS to determine the location of the board + and prints it to the Serial Monitor. + + Circuit: + - MKR board + - MKR GPS Shield attached via I2C cable + + This example code is in the public domain. +*/ + +#include + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // If you are using the MKR GPS as shield, change the next line to pass + // the GPS_MODE_SHIELD parameter to the GPS.begin(...) + if (!GPS.begin()) { + Serial.println("Failed to initialize GPS!"); + while (1); + } +} + +void loop() { + // check if there is new GPS data available + if (GPS.available()) { + // read GPS values + float latitude = GPS.latitude(); + float longitude = GPS.longitude(); + float altitude = GPS.altitude(); + float speed = GPS.speed(); + int satellites = GPS.satellites(); + + // print GPS values + Serial.print("Location: "); + Serial.print(latitude, 7); + Serial.print(", "); + Serial.println(longitude, 7); + + Serial.print("Altitude: "); + Serial.print(altitude); + Serial.println("m"); + + Serial.print("Ground speed: "); + Serial.print(speed); + Serial.println(" km/h"); + + Serial.print("Number of satellites: "); + Serial.println(satellites); + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocationStandy/GPSLocationStandy.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocationStandy/GPSLocationStandy.ino new file mode 100644 index 00000000..b500cc12 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRGPS/examples/GPSLocationStandy/GPSLocationStandy.ino @@ -0,0 +1,81 @@ +/* + GPS Location Standby + + This sketch uses the GPS to determine the location of the board + and prints it to the Serial Monitor. + + It puts the GPS into standby mode every 10 seconds, then wakes it up. + + Circuit: + - MKR board + - MKR GPS Shield attached via I2C cable + + This example code is in the public domain. +*/ + +#include + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // If you are using the MKR GPS as shield, change the next line to pass + // the GPS_MODE_SHIELD parameter to the GPS.begin(...) + if (!GPS.begin()) { + Serial.println("Failed to initialize GPS!"); + while (1); + } +} + +void loop() { + // put the GPS in standby mode + Serial.println("standby"); + GPS.standby(); + + // wait for 10 seconds + Serial.print("delay "); + for (int i = 0; i < 10; i++) { + delay(1000); + Serial.print("."); + } + Serial.println(); + + // wake up the GPS + Serial.println("wakeup"); + GPS.wakeup(); + + Serial.print("wait location ... "); + + // wait for new GPS data to become available + unsigned long startMillis = millis(); + while (!GPS.available()); + unsigned long endMillis = millis(); + + Serial.print(endMillis - startMillis); + Serial.println(" ms"); + + // read GPS values + float latitude = GPS.latitude(); + float longitude = GPS.longitude(); + float altitude = GPS.altitude(); + int satellites = GPS.satellites(); + + // print GPS values + Serial.println(); + Serial.print("Location: "); + Serial.print(latitude, 7); + Serial.print(", "); + Serial.println(longitude, 7); + + Serial.print("Altitude: "); + Serial.print(altitude); + Serial.println("m"); + + Serial.print("Number of satellites: "); + Serial.println(satellites); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/LICENSE new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/Readme.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/Readme.md new file mode 100644 index 00000000..6dba21b7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/Readme.md @@ -0,0 +1,34 @@ +# MKRIoTCarrier + +[![Compiling](https://github.com/arduino-libraries/Arduino_MKRIoTCarrier/actions/workflows/Compile%20Examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MKRIoTCarrier/actions/workflows/Compile%20Examples.yml) + +This library enables the MKR family to use the MKR IoT Carrier + +Get the carrier: + * [Standalone Board](https://store.arduino.cc/mkr-iot-carrier) + * Kits: + * [Explore IoT Kit](https://store.arduino.cc/explore-iot-kit) + * [Oplà IoT Kit](https://store.arduino.cc/opla-iot-kit) + + + +For more information about this library please visit us at +https://www.arduino.cc/reference/en/libraries/arduino_mkriotcarrier/ + +## License + +Copyright (c) 2020 Arduino AG. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/Buzzer_Melody.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/Buzzer_Melody.ino new file mode 100644 index 00000000..9995e62e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/Buzzer_Melody.ino @@ -0,0 +1,44 @@ +/* + Melody + + Adapted for the Arduino MKR IoT Carrier + +*/ +#include +#include "pitches.h" + +MKRIoTCarrier carrier; + +// notes in the melody: +int melody[] = { + NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 +}; + +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations[] = { + 4, 8, 8, 4, 4, 4, 4, 4 +}; + +void setup() { + carrier.begin(); + + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < 8; thisNote++) { + + // to calculate the note duration, take one second divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 1000 / noteDurations[thisNote]; + carrier.Buzzer.sound(melody[thisNote]); + delay(noteDuration); + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.30; + delay(pauseBetweenNotes); + // stop the tone playing: + carrier.Buzzer.noSound(); + } +} + +void loop() { + // no need to repeat the melody. +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/pitches.h new file mode 100644 index 00000000..9f16b4d6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Buzzer_Melody/pitches.h @@ -0,0 +1,93 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Relays_blink/Relays_blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Relays_blink/Relays_blink.ino new file mode 100644 index 00000000..2de0cfbb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Actuators/Relays_blink/Relays_blink.ino @@ -0,0 +1,30 @@ +#include + +MKRIoTCarrier carrier; + +void setup() { + + Serial.begin(9600); + Serial.println("Init"); + carrier.noCase(); + carrier.begin(); +} + +void loop() { + //Switch to NO + carrier.Relay1.open(); + carrier.Relay2.open(); + Serial.println("Both Relays switched to NO"); + delay(2500); + + + //Switch to NC + carrier.Relay1.close(); + carrier.Relay2.close(); + Serial.println("Both Relays switched to NC"); + + //Get status + Serial.print("Relay 1 is: "); + Serial.println(carrier.Relay1.getStatus()); + delay(2500); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/All_Features/All_Features.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/All_Features/All_Features.ino new file mode 100644 index 00000000..e827638f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/All_Features/All_Features.ino @@ -0,0 +1,194 @@ +/* +This sketch will test the carrier board +Unless the touch pads +*/ + +#include +MKRIoTCarrier carrier; //Constructor of the carrier maybe we can include it on the library itself + +float temperature; +float humidity; + +int light; +int r,g,b; + +float pressure; + +float Gx, Gy, Gz; +float Ax, Ay, Az; + +void setup() { + // put your setup code here, to run once: + //Start Serial comm + Serial.begin(9600); + while (!Serial); //Wait to open the Serial monitor to start the program and see details on errors + + //Init everything and outputs the errors + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + //LED show up + //( led index , red , green , blue ) + carrier.leds.setPixelColor(0, 0 , 0 , 20); + carrier.leds.setPixelColor(1, 0 , 20 , 0 ); + carrier.leds.setPixelColor(2, 20 , 0 , 0 ); + carrier.leds.setPixelColor(3, 0 , 20 , 20); + carrier.leds.setPixelColor(4, 20 , 20 , 20); + carrier.leds.show(); + + //Function to display + displayTitle(); + + //Buzzer sound sound(freq) + /* + * Can be used also with tone(BUZZER , freq); + */ + carrier.Buzzer.sound(8000); + delay(100); + carrier.Buzzer.noSound(); + + //Simple relay open and close loop + /* Relay function + open() - goes to Normally Open (NO) circuit, status LED will be ON + close() - goes to Normally Close (NC) circuit, status LED will be OFF + */ + carrier.Relay1.close(); + delay(1000); + printStatus(); + delay(100); + + carrier.Relay1.open(); + delay(1000); + printStatus(); + delay(100); + + printStatus(); + carrier.Relay2.close(); + delay(1000); + printStatus(); + delay(100); + + carrier.Relay2.open(); + delay(1000); + printStatus(); + delay(100); + + delay(1000); + + //SENSORS + //RGB and Light sensor + //It set the values that you point inside the brackets + while (! carrier.Light.colorAvailable()) { + delay(5); + } + carrier.Light.readColor(r,g, b, light); + Serial.println("Ambient light sensor"); + Serial.print("\t light: "); + Serial.println(light); + displayLight(); + + //Env sensor (Temp and Hum) + temperature = carrier.Env.readTemperature(); + humidity = carrier.Env.readHumidity(); + Serial.println("Env sensor"); + Serial.print("\t Temperature:"); + Serial.println(temperature); + Serial.print("\t Humidity: "); + Serial.println(humidity); + displayEnv(); + + //Barometric sensor + pressure = carrier.Pressure.readPressure(); + Serial.println("Barometric sensor"); + Serial.print("\t Pressure:"); + Serial.println(pressure); + displayBaro(); + + //IMU + //Gyroscope + Serial.println("IMU module"); + carrier.IMUmodule.readGyroscope(Gx, Gy, Gz); + Serial.println("Gyroscope:"); + Serial.print ("\t X:"); + Serial.println(Gx); + Serial.print ("\t Y:"); + Serial.println(Gy); + Serial.print ("\t Z:"); + Serial.println(Gz); + + //Accelerometer + carrier.IMUmodule.readAcceleration(Ax, Ay, Az); + Serial.println("Accelerometer:"); + Serial.print ("\t X:"); + Serial.println(Ax); + Serial.print ("\t Y:"); + Serial.println(Ay); + Serial.print ("\t Z:"); + Serial.println(Az); + + Serial.println(); + Serial.println("--- \t END OF READS \t ---"); + Serial.println(); + + + +} + +void displayTitle() { + carrier.display.fillScreen(ST77XX_BLACK); + + carrier.display.setCursor(80, 120); + carrier.display.setTextColor(ST77XX_RED); + carrier.display.print("MKR "); + carrier.display.setTextColor(ST77XX_GREEN); + carrier.display.print("IoT "); + carrier.display.setTextColor(ST77XX_MAGENTA); + carrier.display.print("Carrier"); + carrier.display.setCursor(105, 130); + carrier.display.setTextColor(ST77XX_WHITE); + carrier.display.print("Library"); +} + +void printStatus() { + carrier.display.fillScreen(ST77XX_BLACK); //oled clear() + carrier.display.setCursor(70, 100); + carrier.display.setTextColor(ST77XX_BLUE); + carrier.display.print("Relay 1 status: "); + carrier.display.setTextColor(ST77XX_RED); + carrier.display.print(carrier.Relay1.getStatus()); + + carrier.display.setCursor(70, 120); + carrier.display.setTextColor(ST77XX_BLUE); + carrier.display.print("Relay 2 status: "); + carrier.display.setTextColor(ST77XX_RED); + carrier.display.print(carrier.Relay2.getStatus()); + +} + +void displayLight() { + carrier.display.fillScreen(ST77XX_BLACK); //oled clear() + carrier.display.setCursor(70, 100); + carrier.display.print("Light: "); + carrier.display.setTextColor(ST77XX_MAGENTA); + carrier.display.print(light); + delay(2500); +} + +void displayEnv() { + carrier.display.fillScreen(ST77XX_BLACK); //oled clear() + carrier.display.setCursor(70, 100); + carrier.display.print("Humidity: "); + carrier.display.setTextColor(ST77XX_MAGENTA); + carrier.display.print(humidity); + carrier.display.setCursor(70, 115); + carrier.display.print("Temperature: "); + carrier.display.setTextColor(ST77XX_BLUE); + carrier.display.print(temperature); + delay(2500); +} + +void displayBaro() { +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Compose_images/Compose_images.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Compose_images/Compose_images.ino new file mode 100644 index 00000000..f744f84e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Compose_images/Compose_images.ino @@ -0,0 +1,88 @@ +/************************************************************************** + This example shows how to compose images from bitmaps + + We have used this tool to convert the .bmp to cpp + https://javl.github.io/image2cpp/ + Thanks! + + **************************************************************************/ +#include "Images.h" //We save the images code there +#include +MKRIoTCarrier carrier; + + +uint32_t orange = carrier.leds.Color(50, 242, 0); + +void setup() { + Serial.begin(9600); + carrier.noCase(); + carrier.begin(); + + uint16_t time = millis(); + carrier.display.fillScreen(ST77XX_BLACK); + time = millis() - time; + + carrier.leds.fill(orange, 0, 5); + carrier.leds.setBrightness(15); + carrier.leds.show(); +} + +int i = 0; +int ledC = 0; +int ledA = 0; + +void loop() { + carrier.display.fillScreen(ST77XX_BLACK); + drawArduino(0x04B3); + fadeLoop(); + carrier.display.fillScreen(ST77XX_BLACK); + drawEIoT(); + fadeLoop(); + + carrier.display.fillScreen(ST77XX_WHITE); + drawArduino(0x0000); + fadeLoop(); + + drawArduino(0xF324); + fadeLoop(); + drawArduino(0x04B3); + fadeLoop(); + + carrier.display.fillScreen(ST77XX_WHITE); + drawEIoT(); + fadeLoop(); +} + +//Fading Orange loop +void fadeLoop() { + carrier.leds.fill(orange, ledA, ledC); + for ( i = 0; i < 125; i++) { + carrier.leds.setBrightness(i); + carrier.leds.show(); + delay(10); + } + + for ( i = 125; i > -1; i--) { + carrier.leds.setBrightness(i); + carrier.leds.show(); + delay(10); + } + carrier.leds.clear(); + delay(500); + +} + +//Compose the differentn parts of the image +void drawEIoT() { + carrier.display.drawBitmap(44, 25, ArduinoLogo, 152, 72, 0x04B3); + carrier.display.drawBitmap(48, 110, ArduinoText, 144, 23, 0x04B3); + carrier.display.drawBitmap(0, 150, ExploreFrame, 240, 75, 0xF324); + carrier.display.drawBitmap(0, 150, ExplreIoTKittext, 240, 75, 0x04B3); + carrier.display.drawBitmap(0, 150, ExploreIoTtext, 240, 75, 0xFFFF); +} + +//Same with the Arduino Logo and the text +void drawArduino(uint16_t color) { + carrier.display.drawBitmap(44, 60, ArduinoLogo, 152, 72, color); + carrier.display.drawBitmap(48, 145, ArduinoText, 144, 23, color); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Graphics/Graphics.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Graphics/Graphics.ino new file mode 100644 index 00000000..5442169e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Graphics/Graphics.ino @@ -0,0 +1,263 @@ +/************************************************************************** + This example orignillay from Adafruit ST7735 library, just converted for the carrier usage + **************************************************************************/ + +#include +MKRIoTCarrier carrier; + +float p = 3.1415926; + +void setup(void) { + + Serial.begin(9600); + Serial.print(F("Hello! ST77xx TFT Test")); + carrier.noCase(); + carrier.begin(); + + uint16_t time = millis(); + carrier.display.fillScreen(ST77XX_BLACK); + time = millis() - time; + + Serial.println(time, DEC); + delay(500); + + // large block of text + carrier.display.fillScreen(ST77XX_BLACK); + testdrawtext("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur adipiscing ante sed nibh tincidunt feugiat. Maecenas enim massa, fringilla sed malesuada et, malesuada sit amet turpis. Sed porttitor neque ut ante pretium vitae malesuada nunc bibendum. Nullam aliquet ultrices massa eu hendrerit. Ut sed nisi lorem. In vestibulum purus a tortor imperdiet posuere. ", ST77XX_WHITE); + delay(1000); + + // tft print function! + tftPrintTest(); + delay(4000); + + // a single pixel + carrier.display.drawPixel(carrier.display.width() / 2, carrier.display.height() / 2, ST77XX_GREEN); + delay(500); + + // line draw test + testlines(ST77XX_YELLOW); + delay(500); + + // optimized lines + testfastlines(ST77XX_RED, ST77XX_BLUE); + delay(500); + + testdrawrects(ST77XX_GREEN); + delay(500); + + testfillrects(ST77XX_YELLOW, ST77XX_MAGENTA); + delay(500); + + carrier.display.fillScreen(ST77XX_BLACK); + testfillcircles(10, ST77XX_BLUE); + testdrawcircles(10, ST77XX_WHITE); + delay(500); + + testroundrects(); + delay(500); + + testtriangles(); + delay(500); + + mediabuttons(); + delay(500); + + Serial.println("done"); + delay(1000); +} + +void loop() { + carrier.display.invertDisplay(true); + delay(500); + carrier.display.invertDisplay(false); + delay(500); +} + +void testlines(uint16_t color) { + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawLine(0, 0, x, carrier.display.height() - 1, color); + delay(0); + } + for (int16_t y = 0; y < carrier.display.height(); y += 6) { + carrier.display.drawLine(0, 0, carrier.display.width() - 1, y, color); + delay(0); + } + + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawLine(carrier.display.width() - 1, 0, x, carrier.display.height() - 1, color); + delay(0); + } + for (int16_t y = 0; y < carrier.display.height(); y += 6) { + carrier.display.drawLine(carrier.display.width() - 1, 0, 0, y, color); + delay(0); + } + + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawLine(0, carrier.display.height() - 1, x, 0, color); + delay(0); + } + for (int16_t y = 0; y < carrier.display.height(); y += 6) { + carrier.display.drawLine(0, carrier.display.height() - 1, carrier.display.width() - 1, y, color); + delay(0); + } + + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawLine(carrier.display.width() - 1, carrier.display.height() - 1, x, 0, color); + delay(0); + } + for (int16_t y = 0; y < carrier.display.height(); y += 6) { + carrier.display.drawLine(carrier.display.width() - 1, carrier.display.height() - 1, 0, y, color); + delay(0); + } +} + +void testdrawtext(char *text, uint16_t color) { + carrier.display.setCursor(0, 0); + carrier.display.setTextColor(color); + carrier.display.setTextWrap(true); + carrier.display.print(text); +} + +void testfastlines(uint16_t color1, uint16_t color2) { + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t y = 0; y < carrier.display.height(); y += 5) { + carrier.display.drawFastHLine(0, y, carrier.display.width(), color1); + } + for (int16_t x = 0; x < carrier.display.width(); x += 5) { + carrier.display.drawFastVLine(x, 0, carrier.display.height(), color2); + } +} + +void testdrawrects(uint16_t color) { + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = 0; x < carrier.display.width(); x += 6) { + carrier.display.drawRect(carrier.display.width() / 2 - x / 2, carrier.display.height() / 2 - x / 2 , x, x, color); + } +} + +void testfillrects(uint16_t color1, uint16_t color2) { + carrier.display.fillScreen(ST77XX_BLACK); + for (int16_t x = carrier.display.width() - 1; x > 6; x -= 6) { + carrier.display.fillRect(carrier.display.width() / 2 - x / 2, carrier.display.height() / 2 - x / 2 , x, x, color1); + carrier.display.drawRect(carrier.display.width() / 2 - x / 2, carrier.display.height() / 2 - x / 2 , x, x, color2); + } +} + +void testfillcircles(uint8_t radius, uint16_t color) { + for (int16_t x = radius; x < carrier.display.width(); x += radius * 2) { + for (int16_t y = radius; y < carrier.display.height(); y += radius * 2) { + carrier.display.fillCircle(x, y, radius, color); + } + } +} + +void testdrawcircles(uint8_t radius, uint16_t color) { + for (int16_t x = 0; x < carrier.display.width() + radius; x += radius * 2) { + for (int16_t y = 0; y < carrier.display.height() + radius; y += radius * 2) { + carrier.display.drawCircle(x, y, radius, color); + } + } +} + +void testtriangles() { + carrier.display.fillScreen(ST77XX_BLACK); + uint16_t color = 0xF800; + int t; + int w = carrier.display.width() / 2; + int x = carrier.display.height() - 1; + int y = 0; + int z = carrier.display.width(); + for (t = 0 ; t <= 15; t++) { + carrier.display.drawTriangle(w, y, y, x, z, x, color); + x -= 4; + y += 4; + z -= 4; + color += 100; + } +} + +void testroundrects() { + carrier.display.fillScreen(ST77XX_BLACK); + uint16_t color = 100; + int i; + int t; + for (t = 0 ; t <= 4; t += 1) { + int x = 0; + int y = 0; + int w = carrier.display.width() - 2; + int h = carrier.display.height() - 2; + for (i = 0 ; i <= 16; i += 1) { + carrier.display.drawRoundRect(x, y, w, h, 5, color); + x += 2; + y += 3; + w -= 4; + h -= 6; + color += 1100; + } + color += 100; + } +} + +void tftPrintTest() { + carrier.display.setTextWrap(false); + carrier.display.fillScreen(ST77XX_BLACK); + carrier.display.setCursor(0, 30); + carrier.display.setTextColor(ST77XX_RED); + carrier.display.setTextSize(1); + carrier.display.println("Hello World!"); + carrier.display.setTextColor(ST77XX_YELLOW); + carrier.display.setTextSize(2); + carrier.display.println("Hello World!"); + carrier.display.setTextColor(ST77XX_GREEN); + carrier.display.setTextSize(3); + carrier.display.println("Hello World!"); + carrier.display.setTextColor(ST77XX_BLUE); + carrier.display.setTextSize(4); + carrier.display.print(1234.567); + delay(1500); + carrier.display.setCursor(0, 0); + carrier.display.fillScreen(ST77XX_BLACK); + carrier.display.setTextColor(ST77XX_WHITE); + carrier.display.setTextSize(0); + carrier.display.println("Hello World!"); + carrier.display.setTextSize(1); + carrier.display.setTextColor(ST77XX_GREEN); + carrier.display.print(p, 6); + carrier.display.println(" Want pi?"); + carrier.display.println(" "); + carrier.display.print(8675309, HEX); // print 8,675,309 out in HEX! + carrier.display.println(" Print HEX!"); + carrier.display.println(" "); + carrier.display.setTextColor(ST77XX_WHITE); + carrier.display.println("Sketch has been"); + carrier.display.println("running for: "); + carrier.display.setTextColor(ST77XX_MAGENTA); + carrier.display.print(millis() / 1000); + carrier.display.setTextColor(ST77XX_WHITE); + carrier.display.print(" seconds."); +} + +void mediabuttons() { + // play + carrier.display.fillScreen(ST77XX_BLACK); + carrier.display.fillRoundRect(25, 10, 78, 60, 8, ST77XX_WHITE); + carrier.display.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_RED); + delay(500); + // pause + carrier.display.fillRoundRect(25, 90, 78, 60, 8, ST77XX_WHITE); + carrier.display.fillRoundRect(39, 98, 20, 45, 5, ST77XX_GREEN); + carrier.display.fillRoundRect(69, 98, 20, 45, 5, ST77XX_GREEN); + delay(500); + // play color + carrier.display.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_BLUE); + delay(50); + // pause color + carrier.display.fillRoundRect(39, 98, 20, 45, 5, ST77XX_RED); + carrier.display.fillRoundRect(69, 98, 20, 45, 5, ST77XX_RED); + // play color + carrier.display.fillTriangle(42, 20, 42, 60, 90, 40, ST77XX_GREEN); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Show_GIF/Show_GIF.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Show_GIF/Show_GIF.ino new file mode 100644 index 00000000..f3ac69c9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Display/Show_GIF/Show_GIF.ino @@ -0,0 +1,141 @@ +// Base sketch from Fil Connesso, https://www.youtube.com/watch?v=qNVWZY3WbhU +// Using AnimatedGIF from @bitbank2 +// Thanks!! + +#include +#include + +#include "Adafruit_GFX.h" + +#include "gifs.h" + +MKRIoTCarrier carrier; + +// AnimatedGIF library needed, https://github.com/bitbank2/AnimatedGIF +AnimatedGIF gif; + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + + carrier.begin(); + carrier.display.setRotation(4); + carrier.display.fillScreen(ST77XX_BLACK); + + gif.begin(LITTLE_ENDIAN_PIXELS); + + carrier.leds.fill(0xFFFFFF, 0, 5); + +} + +void loop() { + int c = 0; + if (gif.open((uint8_t *)LOGO_Arduino, sizeof(LOGO_Arduino), GIFDraw)) + { + + while (gif.playFrame(false, NULL)) + { + carrier.leds.setBrightness(c ); + c++; + carrier.leds.show(); + } + c = 0; + carrier.leds.setBrightness(0); + carrier.leds.show(); + gif.close(); + } + delay(1500); +} + +void GIFDraw(GIFDRAW *pDraw) +{ + uint8_t *s; + uint16_t *d, *usPalette, usTemp[320]; + int x, y, dWidth, vardX, vardY, varY; + int DX = carrier.display.width(); + int DY = carrier.display.height(); + + dWidth = pDraw->iWidth; + vardX = pDraw->iX; + vardY = pDraw->iY; + varY = pDraw->y; + + if (dWidth + vardX > dWidth) + dWidth = DX - pDraw->iX; + usPalette = pDraw->pPalette; + y = varY + vardY; + if (y >= DY || vardX >= DX || dWidth < 1) + return; + s = pDraw->pPixels; + if (pDraw->ucDisposalMethod == 2) + { + for (x = 0; x < dWidth; x++) + { + if (s[x] == pDraw->ucTransparent) + s[x] = pDraw->ucBackground; + } + pDraw->ucHasTransparency = 0; + } + if (pDraw->ucHasTransparency) + { + uint8_t *pEnd, c, ucTransparent = pDraw->ucTransparent; + int x, iCount; + pEnd = s + dWidth; + x = 10; //offset + y += 10; + iCount = 0; + while (x < dWidth) + { + c = ucTransparent - 1; + d = usTemp; + while (c != ucTransparent && s < pEnd) + { + c = *s++; + if (c == ucTransparent) + { + s--; + } + else + { + *d++ = usPalette[c]; + iCount++; + } + } + if (iCount) + { + carrier.display.startWrite(); + carrier.display.setAddrWindow(pDraw->iX + x, y, iCount, 1); + carrier.display.writePixels(usTemp, iCount, true, false); + carrier.display.endWrite(); + x += iCount; + iCount = 0; + } + c = ucTransparent; + while (c == ucTransparent && s < pEnd) + { + c = *s++; + if (c == ucTransparent) + iCount++; + else + s--; + } + if (iCount) + { + x += iCount; + iCount = 0; + } + } + } + else + { + s = pDraw->pPixels; + for (x = 0; x < dWidth; x++) + usTemp[x] = usPalette[*s++]; + carrier.display.startWrite(); + carrier.display.setAddrWindow(pDraw->iX + 50, y, dWidth, 1); + carrier.display.writePixels(usTemp, dWidth, true, false); + carrier.display.endWrite(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Grove_Inputs/Grove_Inputs.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Grove_Inputs/Grove_Inputs.ino new file mode 100644 index 00000000..2443f34a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Grove_Inputs/Grove_Inputs.ino @@ -0,0 +1,34 @@ +#include +MKRIoTCarrier carrier; //Constructor of the carrier maybe we can include it on the library itself + +//Be sure that the Pins are the same as your wiring +int moisture = A5; +int moist; +int pir = A6; +bool trigger = false; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while(!Serial); + carrier.noCase(); + carrier.begin(); + pinMode(moisture,INPUT); + pinMode(pir,INPUT); + +} + +void loop() { + // put your main code here, to run repeatedly: + //Save readings + moist = analogRead(moisture); + trigger = digitalRead(pir); + Serial.println("Reading grove inputs A5 and A6"); + Serial.print("Moist: "); + Serial.print(moist); + Serial.print("\t Move state: "); + Serial.println(digitalRead(pir)); + Serial.println(); + //delay(00); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/LEDs-Examples/strandtest/strandtest.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/LEDs-Examples/strandtest/strandtest.ino new file mode 100644 index 00000000..6c32c95e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/LEDs-Examples/strandtest/strandtest.ino @@ -0,0 +1,31 @@ +#include +MKRIoTCarrier carrier; + +#define NUMPIXELS 5 + +void setup() { + carrier.noCase(); + carrier.begin(); +} + +// Runs 10 LEDs at a time along strip, cycling through red, green and blue. +// This requires about 200 mA for all the 'on' pixels + 1 mA per 'off' pixel. + +int head = 0, tail = -4; // Index of first 'on' and 'off' pixels +uint32_t color = 0xFF0000; // 'On' color (starts red) + +void loop() { + + carrier.leds.setPixelColor(head, color); // 'On' pixel at head + carrier.leds.setPixelColor(tail, 0); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(20); // Pause 20 milliseconds (~50 FPS) + + + if (++head >= NUMPIXELS) { // Increment head index. Off end of strip? + head = 0; // Yes, reset head index to start + if ((color >>= 8) == 0) // Next color (R->G->B) ... past blue now? + color = 0xFF0000; // Yes, reset to red + } + if (++tail >= NUMPIXELS) tail = 0; // Increment, reset tail index +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/SD_card/SD_card.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/SD_card/SD_card.ino new file mode 100644 index 00000000..034bd558 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/SD_card/SD_card.ino @@ -0,0 +1,52 @@ +#include +MKRIoTCarrier carrier; + +File myFile; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Init the entire Carrier + carrier.noCase(); + carrier.begin(); + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + myFile = SD.open("test.txt", FILE_WRITE); + + // if the file opened okay, write to it: + if (myFile) { + Serial.print("Writing to test.txt..."); + myFile.println("testing 1, 2, 3."); + // close the file: + myFile.close(); + Serial.println("done."); + } else { + // if the file didn't open, print an error: + Serial.println("error opening test.txt"); + } + + // re-open the file for reading: + myFile = SD.open("test.txt"); + if (myFile) { + Serial.println("test.txt:"); + + // read from the file until there's nothing else in it: + while (myFile.available()) { + Serial.write(myFile.read()); + } + // close the file: + myFile.close(); + } else { + // if the file didn't open, print an error: + Serial.println("error opening test.txt"); + } +} + +void loop() { + // nothing happens after setup +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensors/ReadSensors.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensors/ReadSensors.ino new file mode 100644 index 00000000..73f16375 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensors/ReadSensors.ino @@ -0,0 +1,36 @@ +/* + HTS221 - Read Sensors +*/ + +#include +MKRIoTCarrier carrier; + + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // read all the sensor values + float temperature = carrier.Env.readTemperature(); + float humidity = carrier.Env.readHumidity(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °C"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensorsImperial/ReadSensorsImperial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensorsImperial/ReadSensorsImperial.ino new file mode 100644 index 00000000..52a4af81 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/ENV-HTS221/ReadSensorsImperial/ReadSensorsImperial.ino @@ -0,0 +1,37 @@ +/* + HTS221 - Read Sensors Imperial + +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // Passing in FAHRENHEIT as the unit parameter to ENV.readTemperature(...), + // allows you to read the sensor values in imperial units + float temperature = carrier.Env.readTemperature(FAHRENHEIT); + float humidity = carrier.Env.readHumidity(); + + // print each of the sensor values + Serial.print("Temperature = "); + Serial.print(temperature); + Serial.println(" °F"); + + Serial.print("Humidity = "); + Serial.print(humidity); + Serial.println(" %"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleAccelerometer/SimpleAccelerometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleAccelerometer/SimpleAccelerometer.ino new file mode 100644 index 00000000..4b42b5d6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleAccelerometer/SimpleAccelerometer.ino @@ -0,0 +1,50 @@ +/* + Arduino LSM6DS3 - Simple Accelerometer + + This example reads the acceleration values from the LSM6DS3 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!carrier.IMUmodule.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1); + } + + Serial.print("Accelerometer sample rate = "); + Serial.print(carrier.IMUmodule.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Acceleration in G's"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (carrier.IMUmodule.accelerationAvailable()) { + carrier.IMUmodule.readAcceleration(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleGyroscope/SimpleGyroscope.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleGyroscope/SimpleGyroscope.ino new file mode 100644 index 00000000..be146d2a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/IMU-LSM6DS3/SimpleGyroscope/SimpleGyroscope.ino @@ -0,0 +1,51 @@ +/* + Arduino LSM6DS3 - Simple Gyroscope + + This example reads the gyroscope values from the LSM6DS3 + sensor and continuously prints them to the Serial Monitor + or Serial Plotter. + + The circuit: + - Arduino Uno WiFi Rev 2 or Arduino Nano 33 IoT + + created 10 Jul 2019 + by Riccardo Rizzo + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Failed to initialize!"); + + while (1); + } + + Serial.print("Gyroscope sample rate = "); + Serial.print(carrier.IMUmodule.gyroscopeSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Gyroscope in degrees/second"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (carrier.IMUmodule.gyroscopeAvailable()) { + carrier.IMUmodule.readGyroscope(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/FullExample/FullExample.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/FullExample/FullExample.ino new file mode 100644 index 00000000..4bc3ca63 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/FullExample/FullExample.ino @@ -0,0 +1,85 @@ +/* + APDS9960 - All sensor data from APDS9960 + + This example reads all data from the on-board APDS9960 sensor of the + Nano 33 BLE Sense: + - color RGB (red, green, blue) + - proximity + - gesture + and prints updates to the Serial Monitor every 100 ms. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); // Wait for serial monitor to open + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Error"); + while (true); // Stop forever + } +} + +int proximity = 0; +int r = 0, g = 0, b = 0; +unsigned long lastUpdate = 0; + +void loop() { + + // Check if a proximity reading is available. + if (carrier.Light.proximityAvailable()) { + proximity = carrier.Light.readProximity(); + } + + // check if a gesture reading is available + if (carrier.Light.gestureAvailable()) { + int gesture = carrier.Light.readGesture(); + switch (gesture) { + case GESTURE_UP: + Serial.println("Detected UP gesture"); + break; + + case GESTURE_DOWN: + Serial.println("Detected DOWN gesture"); + break; + + case GESTURE_LEFT: + Serial.println("Detected LEFT gesture"); + break; + + case GESTURE_RIGHT: + Serial.println("Detected RIGHT gesture"); + break; + + default: + // ignore + break; + } + } + + // check if a color reading is available + if (carrier.Light.colorAvailable()) { + carrier.Light.readColor(r, g, b); + } + + // Print updates every 100ms + if (millis() - lastUpdate > 100) { + lastUpdate = millis(); + Serial.print("PR="); + Serial.print(proximity); + Serial.print(" rgb="); + Serial.print(r); + Serial.print(","); + Serial.print(g); + Serial.print(","); + Serial.println(b); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/GestureSensor/GestureSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/GestureSensor/GestureSensor.ino new file mode 100644 index 00000000..653bb63d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/GestureSensor/GestureSensor.ino @@ -0,0 +1,68 @@ +/* + APDS9960 - Gesture Sensor + + This example reads gesture data from the on-board APDS9960 sensor of the + Nano 33 BLE Sense and prints any detected gestures to the Serial Monitor. + + Gesture directions are as follows: + - UP: from USB connector towards antenna + - DOWN: from antenna towards USB connector + - LEFT: from analog pins side towards digital pins side + - RIGHT: from digital pins side towards analog pins side + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Error"); + } + + // for setGestureSensitivity(..) a value between 1 and 100 is required. + // Higher values makes the gesture recognition more sensible but less accurate + // (a wrong gesture may be detected). Lower values makes the gesture recognition + // more accurate but less sensible (some gestures may be missed). + // Default is 80 + //APDS.setGestureSensitivity(80); + + Serial.println("Detecting gestures ..."); +} + +void loop() { + if (carrier.Light.gestureAvailable()) { + // a gesture was detected, read and print to serial monitor + int gesture = APDS.readGesture(); + + switch (gesture) { + case UP: + Serial.println("Detected UP gesture"); + break; + + case DOWN: + Serial.println("Detected DOWN gesture"); + break; + + case LEFT: + Serial.println("Detected LEFT gesture"); + break; + + case RIGHT: + Serial.println("Detected RIGHT gesture"); + break; + + default: + // ignore + break; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/ProximitySensor/ProximitySensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/ProximitySensor/ProximitySensor.ino new file mode 100644 index 00000000..0dad18b7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/ProximitySensor/ProximitySensor.ino @@ -0,0 +1,42 @@ +/* + APDS9960 - Proximity Sensor + + This example reads proximity data from the on-board APDS9960 sensor of the + Nano 33 BLE Sense and prints the proximity value to the Serial Monitor + every 100ms. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Error initializing APDS9960 sensor!"); + } +} + +void loop() { + // check if a proximity reading is available + if (carrier.Light.proximityAvailable()) { + // read the proximity + // - 0 => close + // - 255 => far + // - -1 => error + int proximity = carrier.Light.readProximity(); + + // print value to the Serial Monitor + Serial.println(proximity); + } + + // wait a bit before reading again + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/Read_Colors/Read_Colors.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/Read_Colors/Read_Colors.ino new file mode 100644 index 00000000..e0a8315f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Light-APDS9960/Read_Colors/Read_Colors.ino @@ -0,0 +1,37 @@ +/* + APDS9960 - Color Sensor +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // check if a color reading is available + while (! carrier.Light.colorAvailable()) { + delay(5); + } + int r, g, b; + + // read the color + carrier.Light.readColor(r, g, b); + + // print the values + Serial.print("r = "); + Serial.println(r); + Serial.print("g = "); + Serial.println(g); + Serial.print("b = "); + Serial.println(b); + Serial.println(); + + // wait a bit before reading again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressure/ReadPressure.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressure/ReadPressure.ino new file mode 100644 index 00000000..9fb8d752 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressure/ReadPressure.ino @@ -0,0 +1,42 @@ +/* + LPS22HB - Read Pressure + + This example reads data from the on-board LPS22HB sensor of the + Nano 33 BLE Sense and prints the pressure sensor value to the + Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Failed to initialize!"); + while (1); + } +} + +void loop() { + // read the sensor value + float pressure = carrier.Pressure.readPressure(); + + // print the sensor value + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" kPa"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressureImperial/ReadPressureImperial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressureImperial/ReadPressureImperial.ino new file mode 100644 index 00000000..5d52c4c4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/Sensors/Pressure-LPS22HB/ReadPressureImperial/ReadPressureImperial.ino @@ -0,0 +1,43 @@ +/* + LPS22HB - Read Pressure Imperial + + This example reads data from the on-board LPS22HB sensor of the + Nano 33 BLE Sense and prints the pressure sensor value in imperial + units to the Serial Monitor once a second. + + The circuit: + - Arduino Nano 33 BLE Sense + + This example code is in the public domain. +*/ + +#include +MKRIoTCarrier carrier; + +void setup() { + Serial.begin(9600); + while (!Serial); + + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Failed to initialize!"); + while (1); + } +} + +void loop() { + // Passing PSI to readPressure(...) + // allows you to read the sensor values in imperial units + float pressure = carrier.Pressure.readPressure(PSI); + + // print the sensor value + Serial.print("Pressure = "); + Serial.print(pressure); + Serial.println(" psi"); + + // print an empty line + Serial.println(); + + // wait 1 second to print again + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino new file mode 100644 index 00000000..f84aaf22 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Custom_Sensitivity/Custom_Sensitivity.ino @@ -0,0 +1,49 @@ +#include "Arduino_MKRIoTCarrier.h" +MKRIoTCarrier carrier; + +// When calling carrier.noCase() (default) it's set to 100 (closer) +// When calling carrier.case() it's set to 4 (further) +// But if you use Buttons.updateConfig(value) It will not set the above values + +unsigned int threshold = 98; +unsigned int threshold_btn_0 = 95; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while (!Serial); + + carrier.begin(); + //carrier.noCase(); + //Now we can set our custom touch threshold + // First we update all the buttons with the new threshold + // Then we overwrite individually one of them (they can be all set individually too) + carrier.Buttons.updateConfig(threshold); + carrier.Buttons.updateConfig(threshold_btn_0, TOUCH0); +} + +void loop() { + // put your main code here, to run repeatedly: + carrier.Buttons.update(); + + // Verify your thresholds + if (carrier.Buttons.getTouch(TOUCH0)) { + Serial.println("touching 0"); + } + + if (carrier.Buttons.getTouch(TOUCH1)) { + Serial.println("touching 1"); + } + + if (carrier.Buttons.getTouch(TOUCH2)) { + Serial.println("touching 2"); + } + + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("touching 3"); + } + + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("touching 4"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino new file mode 100644 index 00000000..39224064 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Relays_control_Qtouch/Relays_control_Qtouch.ino @@ -0,0 +1,94 @@ +/* + Set the relays with touch pads +*/ +#include +MKRIoTCarrier carrier; + +//False means Normally closed +bool newRelay1 = false; +bool newRelay2 = false; + +//uint32_t myColor = carrier.leds.Color(green, red, blue) +uint32_t c_orange = carrier.leds.Color(15, 40, 0); +uint32_t c_green = carrier.leds.Color(40, 0, 0); + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + + carrier.noCase(); + carrier.begin(); + + carrier.leds.setPixelColor(0, c_green); + carrier.leds.setPixelColor(4, c_green); + carrier.leds.setPixelColor(2, c_green); + carrier.leds.show(); +} + +void loop() { + // put your main code here, to run repeatedly: + carrier.Buttons.update(); + + /* Qtouch events + ButtonX. + + onTouchDown() + onTouchUp() + onTouchChange() + getTouch() + + */ + + //Side pads set the new status for each relay + //The LED changes to Green its going to be NC (Normally Closed) or Orange to NO (Normally Open) + //Then the middle pad its going to upload the relay status, to confirm both new status + + if (carrier.Buttons.onTouchDown(TOUCH0)) { + newRelay2 = !newRelay2; + if (newRelay2) { + carrier.leds.setPixelColor(0, c_orange); + } else { + carrier.leds.setPixelColor(0, c_green); + } + carrier.leds.show(); + + } + if (carrier.Buttons.onTouchDown(TOUCH3)) { + newRelay1 = !newRelay1; + if (newRelay1) { + carrier.leds.setPixelColor(4, c_orange); + } else { + carrier.leds.setPixelColor(4, c_green); + } + carrier.leds.show(); + } + + if (carrier.Buttons.onTouchDown(TOUCH1)) { + carrier.leds.setPixelColor(2, c_orange); + carrier.leds.show(); + + //Set the relays + //Relay 1 + if (newRelay1) { + carrier.Relay1.open(); + } else { + carrier.Relay1.close(); + } + //Relay 1 + if (newRelay2) { + carrier.Relay2.open(); + } else { + carrier.Relay2.close(); + } + + delay(250); + carrier.leds.setPixelColor(2, 0); + carrier.leds.show(); + delay(250); + carrier.leds.setPixelColor(2, c_green); + carrier.leds.show(); + } + + delay(20); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/TouchTypes/TouchTypes.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/TouchTypes/TouchTypes.ino new file mode 100644 index 00000000..165f621e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/TouchTypes/TouchTypes.ino @@ -0,0 +1,48 @@ +/* + Arduino_Qtouch - Sensor data read Example + This example shows how to configure and read data + from touch sensors buttons on MKR IoT Carrier and + prints updates to the Serial Monitor. + + The circuit: + - Arduino MKR baord; + - MKR IoT carrier. + + This example code is in the public domain. +*/ +#include +MKRIoTCarrier carrier; + + +void setup() { + Serial.begin(9600); + while (!Serial); + carrier.noCase(); + if (!carrier.begin()) { + Serial.println("Error in sensors initialization!"); + while (1); + } + Serial.println("Touch initialization Done!"); +} + +void loop() { + // polling the sensor for new measure + carrier.Buttons.update(); + + if (carrier.Buttons.onTouchDown(TOUCH0)) { + Serial.println("Touched Down Button 0"); + } + if (carrier.Buttons.onTouchUp(TOUCH1)) { + Serial.println("Release Touch Button 1"); + } + if (carrier.Buttons.onTouchChange(TOUCH2)) { + Serial.println("Changed Touch Button 2"); + } + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("Touching Button 3"); + } + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("Touching Button 4"); + } + delay(20); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino new file mode 100644 index 00000000..f52d4a73 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_and_LEDs/Touch_and_LEDs.ino @@ -0,0 +1,80 @@ +#include +MKRIoTCarrier carrier; //Constructor of the carrier maybe we can include it on the library itself + + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while (!Serial); + + //Init all the components from the board + carrier.noCase(); + carrier.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + + //Each time you want to update the reads from the pads use this + //It will update all the pads at the same time + carrier.Buttons.update(); + + //Different types of touches + //When you first touch it + if (carrier.Buttons.onTouchDown(TOUCH0)) { + Serial.println("Touched Down Button 0"); + carrier.leds.setPixelColor(0, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(50); + } else { + carrier.leds.setPixelColor(0, 0); + carrier.leds.show(); // Refresh strip + } + + //When you release it + if (carrier.Buttons.onTouchUp(TOUCH1)) { + Serial.println("Release Touch Button 1"); + carrier.leds.setPixelColor(1, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(50); + } else { + carrier.leds.setPixelColor(1, 0); + carrier.leds.show(); // Refresh strip + } + + //When it detects a change, down or up + if (carrier.Buttons.onTouchChange(TOUCH2)) { + Serial.println("Changed Touch Button 2"); + carrier.leds.setPixelColor(2, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(50); + } else { + carrier.leds.setPixelColor(2, 0); + carrier.leds.show(); // Refresh strip + } + + //Normal, if it is being pressed + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("Touching Button 3"); + carrier.leds.setPixelColor(3, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(5); + } else { + carrier.leds.setPixelColor(3, 0); + carrier.leds.show(); // Refresh strip + } + + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("Touching Button 4"); + carrier.leds.setPixelColor(4, 20, 20, 20); // 'Off' pixel at tail + carrier.leds.show(); // Refresh strip + delay(5); + } else { + carrier.leds.setPixelColor(4, 0); + carrier.leds.show(); // Refresh strip + } + + + Serial.println(); + delay(10); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_signals/Touch_signals.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_signals/Touch_signals.ino new file mode 100644 index 00000000..88c6ef52 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/Touch_signals/Touch_signals.ino @@ -0,0 +1,28 @@ +// Touch Buttons test + +#include +MKRIoTCarrier carrier; + +int msr[5]; + +void setup() { + // put your setup code here, to run once: + //carrier.noCase(); //No need to use it, default false + Serial.begin(9600); + carrier.begin(); + + +} + +void loop() { + // put your main code here, to run repeatedly: + for (int i = 0; i < 5; i++) { + msr[i] = analogRead(i); + Serial.print(i); + Serial.print(" - "); + Serial.print(msr[i]); + Serial.print("\t"); + } + Serial.println(); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/getTouch/getTouch.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/getTouch/getTouch.ino new file mode 100644 index 00000000..b8fc79ef --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRIoTCarrier/examples/TouchPads/getTouch/getTouch.ino @@ -0,0 +1,49 @@ +/* + Arduino_Qtouch - Sensor data read Example + This example shows how to configure and read data + from touch sensors buttons on MKR IoT Carrier and + prints updates to the Serial Monitor. + + The circuit: + - Arduino MKR baord; + - MKR IoT carrier. + + This example code is in the public domain. +*/ +#include +MKRIoTCarrier carrier; + + +void setup() { + Serial.begin(9600); + while (!Serial); + // Qtouch initialization + if (!carrier.begin()) { + Serial.println("Error in sensors initialization!"); + while (1); + } + Serial.println("Touch initialization Done!"); +} + +void loop() { + // polling the sensor for new measure + carrier.Buttons.update(); + + // Checks if new data are available + if (carrier.Buttons.getTouch(TOUCH0)) { + Serial.println("Touching Button 0"); + } + if (carrier.Buttons.getTouch(TOUCH1)) { + Serial.println("Touching Button 1"); + } + if (carrier.Buttons.getTouch(TOUCH2)) { + Serial.println("Touching Button 2"); + } + if (carrier.Buttons.getTouch(TOUCH3)) { + Serial.println("Touching Button 3"); + } + if (carrier.Buttons.getTouch(TOUCH4)) { + Serial.println("Touching Button 4"); + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/LICENSE new file mode 100644 index 00000000..0a041280 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/README.md new file mode 100644 index 00000000..a307b37d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/README.md @@ -0,0 +1,52 @@ +`Arduino_MKRMEM` +================ + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MKRMEM/actions/workflows/spell-check.yml) + +This library provides a driver for the [Arduino MKR MEM Shield](https://store.arduino.cc/arduino-mkr-mem-shield) W25Q16DV SPI flash (with a capacity of 2 MByte) complete with integration for the [SPIFFS](https://github.com/pellepl/spiffs) embedded flash file system (EFFS). + +**Attention**: Before you can use SPIFFS you need to erase and format the flash memory chip using [SPIFFSFormat.ino](examples/SPIFFSFormat/SPIFFSFormat.ino). + +## Why use an EFFS? +The usage of semiconductor based flash memories differs fundamentally from other devices such as magnetic based hard discs. In flash terminology you don't write to memory but you **program** it. When a flash memory is programmed the default state of the flash memory (all bits equal to 1) is changed to the desired value. Note that you can only change bits from 1 to 0, in order to change a bit to 1 again an **erase operation** has to be performed. Such an erase operation can not be performed for each individual bit, only a bit block of bits and bytes can be "erased" together. The smallest possible erase size for the W25Q16DV is 4 kByte (sector erase). Also you can not just program any address on the flash, programming is usually performed **page-by-page**. The W25Q16DV page size is 256 bytes. + +If data stored on the flash memory needs to be changed the data has to be read, modified and written to another address while the the old entry has to be marked as as invalid. Since this tends to consume the available space fairly quickly, a process known as **garbage collection** has to be performed periodically. During garbage collection all valid data are copied to fresh blocks and the old blocks are erased. + +When a maximum number of program / erase cycles (≥ 10^5) are exceeded the flash memory will start to wear down, causing the flash memory to no longer function reliably. As a countermeasure **wear leveling** techniques are used which distribute the data evenly across all sectors of the flash memory to minimize the number of erase cycles per sector and thus extend the life of the flash memory. **Dynamic** Wear Leveling refers to a wear-leveling strategy which works only with those data. **Static** Wear Leveling refers to a wear-leveling strategy that looks at all data, including those already written to the flash memory. + +The goals of garbage collection (maximizing the free sectors) and wear-leveling (even utilization of all sectors) are in conflict with one another. To get both sufficient performance and endurance, a good trade-off must be found between these two tasks. + +So while the usage of an embedded flash file system comes with a bit of overhead, it is the only way to reasonably ensure successful long-term operation of flash memories. + +## How to use + +```C++ +#include +/* ... */ +static char const PANGRAM[] = "The quick brown fox jumps over the lazy dog."; +/* ... */ +void setup() +{ + Serial.begin(); + flash.begin(); + /* ... */ + if(SPIFFS_OK != filesystem.mount()) { + Serial.println("mount() failed with error code "); Serial.println(filesystem.err()); return; + } + /* ... */ + File file = filesystem.open("fox.txt", CREATE | READ_WRITE| TRUNCATE); + /* ... */ + file.write((void *)PANGRAM, strlen(PANGRAM)); + /* ... */ + file.lseek(0, START); /* Rewind file pointer to the start */ + char buf[64] = {0}; + int const bytes_read = file.read(buf, sizeof(buf)); + buf[bytes_read] = '\0'; + Serial.println(buf); + /* ... */ + file.close(); + filesystem.unmount(); +} +``` diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/RawFlashAccess/RawFlashAccess.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/RawFlashAccess/RawFlashAccess.ino new file mode 100644 index 00000000..9f3c847f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/RawFlashAccess/RawFlashAccess.ino @@ -0,0 +1,131 @@ +/* RawFlashAccess.ino + * + * This sketch demonstrates the raw API of the W25Q16DV class + * which allows for low level flash memory control. + * + * Alexander Entinger + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +#undef max +#undef min +#include +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + + unsigned long const start = millis(); + for(unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { }; + + flash.begin(); + + W25Q16DV_Id const id = flash.readId(); + + char msg[32] = {0}; + snprintf(msg, sizeof(msg), "ID: %02X %02X %02X", id.manufacturer_id, id.memory_type, id.capacity); + Serial.println(msg); + + + std::array data_write = {0}, + data_read = {0}; + + /************************************************************************************** + * CHIP ERASE + **************************************************************************************/ + + Serial.println("Erasing chip"); + + flash.eraseChip(); + + flash.read(0x000100, data_read.data(), data_read.size()); + + if(std::all_of(data_read.begin(), data_read.end(), [](uint8_t const elem) { return (elem == 0xFF); })) { + Serial.println("Comparison OK"); + } else { + Serial.println("Comparison FAIL"); + } + printArray("RD: ", data_read); + + /************************************************************************************** + * PAGE PROGRAM + **************************************************************************************/ + + Serial.println("Programming page"); + + /* Initialize data */ + std::transform(data_write.begin(), data_write.end(), data_write.begin(), + [](uint8_t const elem) + { + static uint8_t i = 0; + return i++; + }); + + flash.programPage(0x000100, data_write.data(), data_write.size()); + flash.read (0x000100, data_read.data(), data_read.size()); + + printArray("WR: ", data_write); + printArray("RD: ", data_read); + + if(std::equal(data_write.begin(), data_write.end(), data_read.begin())) { + Serial.println("Comparison OK"); + } else { + Serial.println("Comparison FAIL"); + } + + /************************************************************************************** + * SECTOR ERASE + **************************************************************************************/ + + Serial.println("Sector erase"); + + /* Erase the whole first sector (4 kB) */ + flash.eraseSector(0x000000); + + /* Set the comparison buffer to 0xFF since we now need to compare if every value is 0xFF */ + std::fill(data_write.begin(), data_write.end(), 0xFF); + + /* Read the data */ + flash.read(0x000100, data_read.data(), data_read.size()); + printArray("RD: ", data_read); + + /* Compare the two data buffers */ + if(std::all_of(data_read.begin(), data_read.end(), [](uint8_t const elem) { return (elem == 0xFF); })) { + Serial.println("Comparison OK"); + } else { + Serial.println("Comparison FAIL"); + } +} + +void loop() +{ + +} + +/************************************************************************************** + * HELPER + **************************************************************************************/ + +void printArray(char const * desc, std::array arr) +{ + Serial.print(desc); + + std::for_each(arr.begin(), arr.end(), + [](uint8_t const elem) + { + Serial.print(elem, HEX); + Serial.print(" "); + }); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino new file mode 100644 index 00000000..e8c2f613 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSDirectories/SPIFFSDirectories.ino @@ -0,0 +1,56 @@ +/* SPIFFSDirectories.ino + * + * This sketch demonstrates how to use directories (as much + * as is supported by SPIFFS). + * + * Alexander Entinger + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + + unsigned long const start = millis(); + for(unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { }; + + flash.begin(); + + Serial.println("Mounting ..."); + int res = filesystem.mount(); + if(res != SPIFFS_OK && res != SPIFFS_ERR_NOT_A_FS) { + Serial.println("mount() failed with error code "); Serial.println(res); return; + } + + /* Note: SPIFFS is a flat file system; it doesn't have directories. */ + File file_A = filesystem.open("/testfile_A.txt", CREATE | WRITE_ONLY | TRUNCATE); + File file_B = filesystem.open("/testdir/testfile_B.txt", CREATE | WRITE_ONLY | TRUNCATE); + + Serial.println("opendir('/')"); + Directory dir = filesystem.opendir("/"); + DirEntry entry; + while(dir.readdir(entry)) { + if (entry.isFile()) Serial.print(" F "); + else if(entry.isDirectory()) Serial.print(" D "); + Serial.print(entry.name()); + Serial.println(); + } + dir.closedir(); + + Serial.println("Unmounting ..."); + filesystem.unmount(); +} + +void loop() +{ + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSFormat/SPIFFSFormat.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSFormat/SPIFFSFormat.ino new file mode 100644 index 00000000..8b581548 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSFormat/SPIFFSFormat.ino @@ -0,0 +1,77 @@ +/* SPIFFSFormat.ino + * + * This sketch erases the complete flash and formats it for + * usage with the SPIFFS (SPI Flash File System). + * + * Alexander Entinger + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + + unsigned long const start = millis(); + for(unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { }; + + flash.begin(); + + Serial.println("Erasing chip ..."); + flash.eraseChip(); + + Serial.println("Mounting ..."); + int res = filesystem.mount(); + if(res != SPIFFS_OK && res != SPIFFS_ERR_NOT_A_FS) { + Serial.println("mount() failed with error code "); Serial.println(res); return; + } + + Serial.println("Unmounting ..."); + filesystem.unmount(); + + Serial.println("Formatting ..."); + res = filesystem.format(); + if(res != SPIFFS_OK) { + Serial.println("format() failed with error code "); Serial.println(res); return; + } + + Serial.println("Mounting ..."); + res = filesystem.mount(); + if(res != SPIFFS_OK) { + Serial.println("mount() failed with error code "); Serial.println(res); return; + } + + Serial.println("Checking ..."); + res = filesystem.check(); + if(res != SPIFFS_OK) { + Serial.println("check() failed with error code "); Serial.println(res); return; + } + + Serial.println("Retrieving filesystem info ..."); + unsigned int bytes_total = 0, + bytes_used = 0; + res = filesystem.info(bytes_total, bytes_used); + if(res != SPIFFS_OK) { + Serial.println("check() failed with error code "); Serial.println(res); return; + } else { + char msg[64] = {0}; + snprintf(msg, sizeof(msg), "SPIFFS Info:\nBytes Total: %d\nBytes Used: %d", bytes_total, bytes_used); + Serial.println(msg); + } + + Serial.println("Unmounting ..."); + filesystem.unmount(); +} + +void loop() +{ + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSUsage/SPIFFSUsage.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSUsage/SPIFFSUsage.ino new file mode 100644 index 00000000..4a71a6a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRMEM/examples/SPIFFSUsage/SPIFFSUsage.ino @@ -0,0 +1,105 @@ +/* SPIFFSUsage.ino + * + * This sketch demonstrates various file operations utilizing + * the Arduino MKR MEM Shield port for the SPIFFS. + * + * Alexander Entinger + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +/* A pangram is a sentence using every letter of a given alphabet at least once. */ +static char const PANGRAM[] = "The quick brown fox jumps over the lazy dog."; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for(unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { }; + + flash.begin(); + + Serial.println("Mounting ..."); + if(SPIFFS_OK != filesystem.mount()) { + Serial.println("mount() failed with error code "); Serial.println(filesystem.err()); return; + } + + + Serial.println("Checking ..."); + if(SPIFFS_OK != filesystem.check()) { + Serial.println("check() failed with error code "); Serial.println(filesystem.err()); return; + } + + Serial.print("Checking for file ... "); + File fnf = filesystem.open("404.txt", READ_ONLY); + if (!fnf) { + Serial.println(" 404.txt does not exist."); + } + + Serial.print("Checking for file ... "); + File fox = filesystem.open("fox.txt", READ_ONLY); + if (fox) { + Serial.println(" fox.txt exists. It will be overwritten."); + } + + Serial.println("Writing ..."); + /* Create file if it doesn't exist (SPIFFS_CREAT) and open in + * write only mode (SPIFFS_WRONLY). If the file does exist + * delete the existing content (SPIFFS_TRUNC). + */ + File file = filesystem.open("fox.txt", CREATE | READ_WRITE| TRUNCATE); + + int const bytes_to_write = strlen(PANGRAM); + int const bytes_written = file.write((void *)PANGRAM, bytes_to_write); + + if(bytes_written != bytes_to_write) { + Serial.println("write() failed with error code "); Serial.println(filesystem.err()); return; + } else { + Serial.print(bytes_written); + Serial.println(" bytes written"); + } + + + Serial.println("Retrieving filesystem info ..."); + unsigned int bytes_total = 0, + bytes_used = 0; + if(SPIFFS_OK != filesystem.info(bytes_total, bytes_used)) { + Serial.println("check() failed with error code "); Serial.println(filesystem.err()); return; + } else { + char msg[64] = {0}; + snprintf(msg, sizeof(msg), "SPIFFS Info:\nBytes Total: %d\nBytes Used: %d", bytes_total, bytes_used); + Serial.println(msg); + } + + + Serial.println("Reading ..."); + file.lseek(0, START); /* Rewind file pointer to the start */ + + char buf[64] = {0}; + int const bytes_read = file.read(buf, sizeof(buf)); + buf[bytes_read] = '\0'; + + file.close(); + Serial.print("["); Serial.print(bytes_read); Serial.print("] "); + Serial.println(buf); + + + Serial.println("Unmounting ..."); + filesystem.unmount(); +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/README.adoc new file mode 100644 index 00000000..8e95cbe7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_MKRRGB + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to draw on your official Arduino MKR RGB shield. Depends on the ArduinoGraphics library. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/examples/ScrollText/ScrollText.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/examples/ScrollText/ScrollText.ino new file mode 100644 index 00000000..691bc6e7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/examples/ScrollText/ScrollText.ino @@ -0,0 +1,41 @@ +/* + MKR RGB - Scroll Text + + This example demonstrates how to display and scroll text + on the MKR RGB shield. It continuously scrolls the + current millis() value on the display. + + The circuit: + - Arduino MKR board + - Arduino MKR RGB shield attached + + This example code is in the public domain. +*/ + +#include // Arduino_MKRRGB depends on ArduinoGraphics +#include + +void setup() { + // initialize the display + MATRIX.begin(); + + // set the brightness, supported values are 0 - 255 + MATRIX.brightness(10); + + // configure the text scroll speed + MATRIX.textScrollSpeed(125); + + // display some short text without scrolling + MATRIX.beginText(0, 0, 127, 0, 0); // X, Y, then R, G, B + MATRIX.print("Hi"); + MATRIX.endText(); + + delay(2000); +} + +void loop() { + MATRIX.beginText(MATRIX.width() - 1, 0); // use the same color as before, start text at the right edge + MATRIX.print("millis="); + MATRIX.println(millis()); + MATRIX.endText(SCROLL_LEFT); // SCROLL_LEFT parameter here to configure scrolling left +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/examples/SimpleDraw/SimpleDraw.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/examples/SimpleDraw/SimpleDraw.ino new file mode 100644 index 00000000..76fe0bea --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRRGB/examples/SimpleDraw/SimpleDraw.ino @@ -0,0 +1,104 @@ +/* + MKR RGB - Simple Draw + + This example demonstrates how to draw on the + MKR RGB shield. + + The circuit: + - Arduino MKR board + - Arduino MKR RGB shield attached + + This example code is in the public domain. +*/ + +#include // Arduino_MKRRGB depends on ArduinoGraphics +#include + +void setup() { + // initialize the display + MATRIX.begin(); + + // set the brightness, supported values are 0 - 255 + MATRIX.brightness(10); +} + +void loop() { + // set one pixel RED + MATRIX.beginDraw(); + MATRIX.set(0, 0, 255, 0, 0); // X, Y, and R, G, B + MATRIX.endDraw(); + + delay(1000); + + // clear the display + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.endDraw(); + + delay(1000); + + // set one pixel GREEN, using the stroke and point methods + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(0, 255, 0); + MATRIX.point(1, 1); + MATRIX.endDraw(); + + delay(1000); + + // set draw a BLUE line + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(0, 0, 255); + MATRIX.line(0, 0, MATRIX.width() - 1, MATRIX.height() - 1); + MATRIX.endDraw(); + + delay(1000); + + // outline a CYAN rectangle + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(0, 255, 255); + MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height()); + MATRIX.endDraw(); + + delay(1000); + + // fill a YELLOW rectangle + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.noStroke(); + MATRIX.fill(255, 255, 0); + MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height()); + MATRIX.endDraw(); + + delay(1000); + + // fill and stroke a rectangle + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(255, 0, 255); + MATRIX.fill(0, 255, 0); + MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height()); + MATRIX.endDraw(); + + delay(1000); + + // stroke a small text + MATRIX.beginDraw(); + MATRIX.clear(); + MATRIX.stroke(255, 255, 255); + MATRIX.text("abc", 0, 1); + MATRIX.endDraw(); + + delay(1000); + + // clear the display + MATRIX.beginDraw(); + MATRIX.noFill(); + MATRIX.noStroke(); + MATRIX.clear(); + MATRIX.endDraw(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/README.adoc new file mode 100644 index 00000000..65feed40 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/README.adoc @@ -0,0 +1,12 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_MKRTHERM + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the temperature sensors connected to your MKR THERM Shield. + +For more information about this library please visit us at https://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensor/ReadSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensor/ReadSensor.ino new file mode 100644 index 00000000..b978af81 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensor/ReadSensor.ino @@ -0,0 +1,43 @@ +/* + MKR THERM Shield - Read Sensors + + This example reads the temperatures measured by the thermocouple + connected to the MKR THERM Shield and prints them to the Serial Monitor + once a second. + + The circuit: + - Arduino MKR board + - Arduino MKR THERM Shield attached + - A type K thermocouple temperature sensor connected to the shield + + This example code is in the public domain. +*/ + +#include + +void setup() { + + Serial.begin(9600); + + while (!Serial); + + if (!THERM.begin()) { + Serial.println("Failed to initialize MKR THERM Shield!"); + while (1); + } +} + +void loop() { + + Serial.print("Reference temperature "); + Serial.print(THERM.readReferenceTemperature()); + Serial.println(" °C"); + + Serial.print("Temperature "); + Serial.print(THERM.readTemperature(CELSIUS)); + Serial.println(" °C"); + + Serial.println(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino new file mode 100644 index 00000000..d525cc43 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MKRTHERM/examples/ReadSensorOtherUnits/ReadSensorOtherUnits.ino @@ -0,0 +1,47 @@ +/* + MKR THERM Shield - Read Sensors + + This example reads the temperatures (in Fahrenheit and kelvins) measured by the thermocouple + connected to the MKR THERM Shield and prints them to the Serial Monitor + once a second. + + The circuit: + - Arduino MKR board + - Arduino MKR THERM Shield attached + - A type K thermocouple temperature sensor connected to the shield + + This example code is in the public domain. +*/ + +#include + +void setup() { + + Serial.begin(9600); + + while (!Serial); + + if (!THERM.begin()) { + Serial.println("Failed to initialize MKR THERM Shield!"); + while (1); + } +} + +void loop() { + + Serial.print("Reference temperature "); + Serial.print(THERM.readReferenceTemperature()); + Serial.println(" °C"); + + Serial.print("Temperature in Fahrenheit "); + Serial.print(THERM.readTemperature(FAHRENHEIT)); + Serial.println(" °F"); + + Serial.print("Temperature in kelvin "); + Serial.print(THERM.readTemperature(KELVIN)); + Serial.println(" K"); + + Serial.println(); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/README.md new file mode 100644 index 00000000..1cf65333 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/README.md @@ -0,0 +1,30 @@ +# Portenta Machine Control Library for Arduino + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_MachineControl/actions/workflows/spell-check.yml) + +Arduino Library for the Portenta Machine Control + +The Portenta Machine Control enhances existing products with minimal effort, allowing companies to implement a standard platform across different equipment models. It is now easy to create an infrastructure of interconnected machines, which can be controlled onsite or via the cloud when needed; moreover, human-machine interaction can be further enahnced via mobile apps thanks to BLE connectivity. + +For more information about this library please visit us at https://www.arduino.cc/reference/en/libraries/arduino_machinecontrol/ +For more information about this product: https://www.arduino.cc/pro/hardware/product/portenta-machine-control + +## License + +Copyright (c) 2021 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_Out/Analog_Out.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_Out/Analog_Out.ino new file mode 100644 index 00000000..89110e7e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_Out/Analog_Out.ino @@ -0,0 +1,52 @@ +/* + Machine Control - Analog out Example + + This example shows how to use the Analog out channels on + the Machine Control. + The example sets the channels PWM period in the setup, + then loops the channels voltage output value from 0V to 10.4V. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ + +#include + +using namespace machinecontrol; + +void setup() { + //analog_out.period_ms(CHANNEL, PERIOD_MILLISECONDS); + analog_out.period_ms(0, 4); + analog_out.period_ms(1, 4); + analog_out.period_ms(2, 4); + analog_out.period_ms(3, 4); + + Serial.begin(9600); + Serial.println("Analog out test"); + +} + +//Output values which will be changed with this variable +float counter = 1; + +void loop() { + //analog_out.write(CHANNEL, OUTPUT_VOLTAGE_VALUE); + analog_out.write(0, counter); + analog_out.write(1, counter); + analog_out.write(2, counter); + analog_out.write(3, counter); + Serial.println("All channels set at "+String(counter)+"V"); + + counter = counter + 0.1; + //Maximum output value is 10.4V + if (counter >= 10.5) + { + counter = 0; + //Additional 100 ms delay introduced to manage 10.5V -> 0V fall time of 150 ms + delay(100); + } + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_0_10V/Analog_input_0_10V.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_0_10V/Analog_input_0_10V.ino new file mode 100644 index 00000000..93058759 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_0_10V/Analog_input_0_10V.ino @@ -0,0 +1,52 @@ +/* + Machine Control - Analog in 0 - 10 V Example + + This example provides the voltage value acquired by the + Machine Control. For each channel of the ANALOG IN connector, + there is a resistor divider made by a 100k and 39k, + the input voltage is divided by a ratio of 0.28. + Maximum input voltage is 10V. + To use the 0V-10V functionality, a 24V supply on + the PWR SUPPLY connector is necessary. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ +#include + +using namespace machinecontrol; + +float res_divider = 0.28057; +float reference = 3.3; + +void setup() { + analogReadResolution(16); + + Serial.begin(9600); + analog_in.set0_10V(); +} + +void loop() { + float raw_voltage_ch0 = analog_in.read(0); + float voltage_ch0 = (raw_voltage_ch0 * reference) / 65535 / res_divider; + Serial.print("Voltage CH0: "); + Serial.print(voltage_ch0, 3); + Serial.println("V"); + + float raw_voltage_ch1 = analog_in.read(1); + float voltage_ch1 = (raw_voltage_ch1 * reference) / 65535 / res_divider; + Serial.print("Voltage CH1: "); + Serial.print(voltage_ch1, 3); + Serial.println("V"); + + float raw_voltage_ch2 = analog_in.read(2); + float voltage_ch2 = (raw_voltage_ch2 * reference) / 65535 / res_divider; + Serial.print("Voltage CH2: "); + Serial.print(voltage_ch2, 3); + Serial.println("V"); + Serial.println(); + delay(250); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_4_20mA/Analog_input_4_20mA.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_4_20mA/Analog_input_4_20mA.ino new file mode 100644 index 00000000..167de2dc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_4_20mA/Analog_input_4_20mA.ino @@ -0,0 +1,56 @@ +/* + Machine Control - Analog in 4 - 20 mA Example + + This example provides the current value acquired by the + Machine Control. For each channel of the ANALOG IN + connector, there is a 120 ohm resistor to GND. The current + of the 4-20mA sensor flows through it, generating a voltage + which is sampled by the Portenta's ADC. + To use the 4-20mA functionality, a 24V supply on + the PWR SUPPLY connector is necessary. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ +#include + +using namespace machinecontrol; + +#define SENSE_RES 120 + +float reference = 3.3; + +void setup() { + analogReadResolution(16); + + Serial.begin(9600); + analog_in.set4_20mA(); +} + +void loop() { + float raw_voltage_ch0 = analog_in.read(0); + float voltage_ch0 = (raw_voltage_ch0 * reference) / 65535; + float current_ch0 = (voltage_ch0 / SENSE_RES) * 1000; + Serial.print("Measured Current CH0: "); + Serial.print(current_ch0); + Serial.println("mA"); + + float raw_voltage_ch1 = analog_in.read(1); + float voltage_ch1 = (raw_voltage_ch1 * reference) / 65535; + float current_ch1 = (voltage_ch1 / SENSE_RES) * 1000; + Serial.print("Measured Current CH1: "); + Serial.print(current_ch1); + Serial.println("mA"); + float raw_voltage_ch2 = analog_in.read(2); + float voltage_ch2 = (raw_voltage_ch2 * reference) / 65535; + float current_ch2 = (voltage_ch2 / SENSE_RES) * 1000; + Serial.print("Measured Current CH2: "); + Serial.print(current_ch2); + Serial.println("mA"); + + Serial.println(); + delay(250); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_NTC/Analog_input_NTC.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_NTC/Analog_input_NTC.ino new file mode 100644 index 00000000..d15149ce --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Analog_input/Analog_input_NTC/Analog_input_NTC.ino @@ -0,0 +1,81 @@ +/* + Machine Control - Analog in NTC Example + + This example provides the resistance value acquired by the + Machine Control. A 3V voltage reference is connected + to each channel of the ANALOG IN connector. The reference + has a 100k resistor in series, so it can provide only a low + current. + The voltage sampled by the Portenta's ADC is the reference + voltage divided by the voltage divider composed by the + input resistor and the 100k in series to the voltage reference. + The resistor value is calculated by inverting the formula of the + voltage divider. + To use the NTC functionality, the 24V supply on + the PWR SUPPLY connector is necessary. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ +#include + +using namespace machinecontrol; + +#define REFERENCE_RES 100000 + +float reference = 3.3; +float lowest_voltage = 2.7; + +void setup() { + analogReadResolution(16); + + Serial.begin(9600); + analog_in.setNTC(); +} + +void loop() { + float raw_voltage_ch0 = analog_in.read(0); + float voltage_ch0 = (raw_voltage_ch0 * reference) / 65535; + float resistance_ch0; + Serial.print("Resistance CH0: "); + if (voltage_ch0 < lowest_voltage) { + resistance_ch0 = ((-REFERENCE_RES) * voltage_ch0) / (voltage_ch0 - reference); + Serial.print(resistance_ch0); + Serial.println(" ohm"); + } else { + resistance_ch0 = -1; + Serial.println("NaN"); + } + + float raw_voltage_ch1 = analog_in.read(1); + float voltage_ch1 = (raw_voltage_ch1 * reference) / 65535; + float resistance_ch1; + Serial.print("Resistance CH1: "); + if (voltage_ch1 < lowest_voltage) { + resistance_ch1 = ((-REFERENCE_RES) * voltage_ch1) / (voltage_ch1 - reference); + Serial.print(resistance_ch1); + Serial.println(" ohm"); + } else { + resistance_ch1 = -1; + Serial.println("NaN"); + } + + float raw_voltage_ch2 = analog_in.read(2); + float voltage_ch2 = (raw_voltage_ch2 * reference) / 65535; + float resistance_ch2; + Serial.print("Resistance CH2: "); + if (voltage_ch2 < lowest_voltage) { + resistance_ch2 = ((-REFERENCE_RES) * voltage_ch2) / (voltage_ch2 - reference); + Serial.print(resistance_ch2); + Serial.println(" ohm"); + } else { + resistance_ch2 = -1; + Serial.println("NaN"); + } + + Serial.println(); + delay(250); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/ReadCan/ReadCan.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/ReadCan/ReadCan.ino new file mode 100644 index 00000000..c7273f73 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/ReadCan/ReadCan.ino @@ -0,0 +1,51 @@ +/* + CAN Read Example + + This sketch shows how to use the CAN transceiver on the Machine + Control and how to receive data from the RX CAN channel. + + Circuit: + - Portenta H7 + - Machine Control + +*/ +#include +#include + +using namespace machinecontrol; + +#define DATARATE_2MB 2000000 +#define DATARATE_1_5MB 1500000 +#define DATARATE_1MB 1000000 +#define DATARATE_800KB 800000 + + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. + } + + Serial.println("Start CAN initialization"); + comm_protocols.enableCAN(); + comm_protocols.can.frequency(DATARATE_800KB); + Serial.println("Initialization done"); +} + + +void loop() { + mbed::CANMessage msg; + if (comm_protocols.can.read(msg)) { + + // Print the sender ID + Serial.print("ID: "); + Serial.println(msg.id); + + // Print the first Payload Byte + Serial.print("Message received:"); + Serial.println(msg.data[0], DEC); + + } + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/WriteCan/WriteCan.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/WriteCan/WriteCan.ino new file mode 100644 index 00000000..6250cfd2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/CAN/WriteCan/WriteCan.ino @@ -0,0 +1,50 @@ +/* + CAN Write Example + + This sketch shows how to use the CAN transceiver on the Machine + Control and how to transmit data from the TX CAN channel. + + Circuit: + - Portenta H7 + - Machine Control + +*/ +#include +#include +using namespace machinecontrol; + +#define DATARATE_2MB 2000000 +#define DATARATE_1_5MB 1500000 +#define DATARATE_1MB 1000000 +#define DATARATE_800KB 800000 + + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. + } + + Serial.println("Start CAN initialization"); + comm_protocols.enableCAN(); + comm_protocols.can.frequency(DATARATE_800KB); + Serial.println("Initialization done"); +} + +int counter = 0; +unsigned char payload = 0x49; +int payload_size = 1; + +void loop() { + + mbed::CANMessage msg = mbed::CANMessage(13ul, &payload, payload_size); + if (comm_protocols.can.write(msg)) { + Serial.println("Message sent"); + } else { + Serial.println("Transmission Error: "); + Serial.println(comm_protocols.can.tderror()); + comm_protocols.can.reset(); + } + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_output/Digital_output.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_output/Digital_output.ino new file mode 100644 index 00000000..5bf6b519 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_output/Digital_output.ino @@ -0,0 +1,116 @@ +/* + Machine Control - Digital Output Example + + This sketch shows how to send values on the + DIGITAL OUT channels on the Machine Control. + Please remember that pin "24V IN" of the connector + DIGITAL_OUTPUTS must be connected to 24V. + The DIGITAL OUT channels are high side switches + capable to handle up to 0.5A. There is an over current + protection that open the channel when the current is + above 0.7A with a +-20% tolerance. + The over current protection can be set to have two + different behaviors, and it is the same for all channels: + 1) Latch mode: when the over current is detected + the channel is opened, and will remain opened until + it is toggled via software. + 2) Auto retry: when the over current is detected + the channel is opened, but after some tens of + milliseconds the channel will automatically try + to close itself again. In case of a persistent + overcurrent the channel will continuously toggle. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ + +#include + +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + // The loop starts only when the Serial Monitor is opened. + while (!Serial); + + //Set over current behavior of all channels to latch mode: + digital_outputs.setLatch(); + + // Uncomment this line to set over current behavior of all + // channels to auto retry mode instead of latch mode: + //digital_outputs.setRetry(); + + //At startup set all channels to OPEN + digital_outputs.setAll(0); +} + + +void loop() { + Serial.println("DIGITAL OUT:"); + + // Set all channels to CLOSED + digital_outputs.setAll(255); + Serial.print("All channels are CLOSED for 1 s..."); + delay(1000); + + // Set all channels to OPEN + digital_outputs.setAll(0); + Serial.println("now they are OPEN."); + delay(1000); + + // Toggle each channel for 1 s, one by one + + digital_outputs.set(0, HIGH); + Serial.print("CH0 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(0, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(1, HIGH); + Serial.print("CH1 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(1, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(2, HIGH); + Serial.print("CH2 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(2, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(3, HIGH); + Serial.print("CH3 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(3, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(4, HIGH); + Serial.print("CH4 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(4, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(5, HIGH); + Serial.print("CH5 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(5, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(6, HIGH); + Serial.print("CH6 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(6, LOW); + Serial.println("now is OPEN."); + + digital_outputs.set(7, HIGH); + Serial.print("CH7 is CLOSED for 1 s..."); + delay(1000); + digital_outputs.set(7, LOW); + Serial.println("now is OPEN."); + + Serial.println(); + delay(1000); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/CombinedIOExpander/CombinedIOExpander.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/CombinedIOExpander/CombinedIOExpander.ino new file mode 100644 index 00000000..9615050d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/CombinedIOExpander/CombinedIOExpander.ino @@ -0,0 +1,98 @@ +/* + Machine Control - IOExpander Read And Write Example + + This sketch shows how to use the GPIO Expanders on the Machine Control, + how to periodically send a value on the PROGRAMMABLE DIGITAL I/O + output channels and how to periodically read from the PROGRAMMABLE + DIGITAL I/O input channels and DIGITAL INPUT channels. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ + +#include +#include "Wire.h" +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + while (!Serial); + Wire.begin(); + if (!digital_inputs.init()){ + Serial.println("GPIO expander initialization fail!!"); + } + if (!digital_programmables.init()){ + Serial.println("GPIO expander initialization fail!!"); + } + + Serial.println("GPIO expander initialization done"); + digital_programmables.setLatch(); + Serial.println("GPIO expander initialization done"); +// digital_inputs.setLatch(); +} + +void loop() { + // Write the status value to On to Pin 3 + digital_programmables.set(IO_WRITE_CH_PIN_03, SWITCH_ON); + delay(1000); + + // Read from PROGRAMMABLE DIGITAL I/O Pin 3 + Serial.println("Read IO Pin 03: " + String(digital_programmables.read(IO_READ_CH_PIN_03))); + delay(1000); + + // Read from DIGITAL INPUT Expander Pin 3 + Serial.println("Read DIN Pin 03: " + String(digital_inputs.read(DIN_READ_CH_PIN_03))); + delay(1000); + + // Write the status value to Off to Pin 3 + digital_programmables.set(IO_WRITE_CH_PIN_03, SWITCH_OFF); + delay(1000); + + Serial.println(); + // Write the status value to On to all the Output Pins + digital_programmables.writeAll(SWITCH_ON_ALL); + + // Reads from all Input Pins + readAll(); + delay(1000); + + // Write the status value to Off all to all the Output Pins + digital_programmables.writeAll(SWITCH_OFF_ALL); + + // Reads from all Input Pins + readAll(); + Serial.println(); + delay(1000); + +} + + +void readAll() { + uint32_t inputs = digital_programmables.readAll(); + Serial.println("CH00: " + String((inputs & (1 << IO_READ_CH_PIN_00)) >> IO_READ_CH_PIN_00)); + Serial.println("CH01: " + String((inputs & (1 << IO_READ_CH_PIN_01)) >> IO_READ_CH_PIN_01)); + Serial.println("CH02: " + String((inputs & (1 << IO_READ_CH_PIN_02)) >> IO_READ_CH_PIN_02)); + Serial.println("CH03: " + String((inputs & (1 << IO_READ_CH_PIN_03)) >> IO_READ_CH_PIN_03)); + Serial.println("CH04: " + String((inputs & (1 << IO_READ_CH_PIN_04)) >> IO_READ_CH_PIN_04)); + Serial.println("CH05: " + String((inputs & (1 << IO_READ_CH_PIN_05)) >> IO_READ_CH_PIN_05)); + Serial.println("CH06: " + String((inputs & (1 << IO_READ_CH_PIN_06)) >> IO_READ_CH_PIN_06)); + Serial.println("CH07: " + String((inputs & (1 << IO_READ_CH_PIN_07)) >> IO_READ_CH_PIN_07)); + Serial.println("CH08: " + String((inputs & (1 << IO_READ_CH_PIN_08)) >> IO_READ_CH_PIN_08)); + Serial.println("CH09: " + String((inputs & (1 << IO_READ_CH_PIN_09)) >> IO_READ_CH_PIN_09)); + Serial.println("CH10: " + String((inputs & (1 << IO_READ_CH_PIN_10)) >> IO_READ_CH_PIN_10)); + Serial.println("CH11: " + String((inputs & (1 << IO_READ_CH_PIN_11)) >> IO_READ_CH_PIN_11)); + Serial.println(); + inputs = digital_inputs.readAll(); + Serial.println("CH00: " + String((inputs & (1 << DIN_READ_CH_PIN_00)) >> DIN_READ_CH_PIN_00)); + Serial.println("CH01: " + String((inputs & (1 << DIN_READ_CH_PIN_01)) >> DIN_READ_CH_PIN_01)); + Serial.println("CH02: " + String((inputs & (1 << DIN_READ_CH_PIN_02)) >> DIN_READ_CH_PIN_02)); + Serial.println("CH03: " + String((inputs & (1 << DIN_READ_CH_PIN_03)) >> DIN_READ_CH_PIN_03)); + Serial.println("CH04: " + String((inputs & (1 << DIN_READ_CH_PIN_04)) >> DIN_READ_CH_PIN_04)); + Serial.println("CH05: " + String((inputs & (1 << DIN_READ_CH_PIN_05)) >> DIN_READ_CH_PIN_05)); + Serial.println("CH06: " + String((inputs & (1 << DIN_READ_CH_PIN_06)) >> DIN_READ_CH_PIN_06)); + Serial.println("CH07: " + String((inputs & (1 << DIN_READ_CH_PIN_07)) >> DIN_READ_CH_PIN_07)); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/Digital_input/Digital_input.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/Digital_input/Digital_input.ino new file mode 100644 index 00000000..91c0f7d2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/Digital_input/Digital_input.ino @@ -0,0 +1,75 @@ +/* + Machine Control - Digital Input Example + + This sketch shows how to periodically read from all the DIGITAL + INPUTS channels on the Machine Control. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ +#include +#include "Wire.h" + +using namespace machinecontrol; + uint16_t readings = 0; + +void setup() { + Serial.begin(9600); + //The loop starts only when the Serial Monitor is opened. + while(!Serial); + Wire.begin(); + + if (!digital_inputs.init()) { + Serial.println("Digital input GPIO expander initialization fail!!"); + } +} + +void loop() { + //Reads and Prints all channels (in a single operation) + readAll(); + + //Read one-by-one each channel and print them one-by-one + readings = digital_inputs.read(DIN_READ_CH_PIN_00); + Serial.println("CH00: "+String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_01); + Serial.println("CH01: "+String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_02); + Serial.println("CH02: "+String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_03); + Serial.println("CH03: "+String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_04); + Serial.println("CH04: "+String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_05); + Serial.println("CH05: "+String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_06); + Serial.println("CH06: "+String(readings)); + + readings = digital_inputs.read(DIN_READ_CH_PIN_07); + Serial.println("CH07: "+String(readings)); + + Serial.println(); + + delay(250); +} + +uint8_t readAll() { + uint32_t inputs = digital_inputs.readAll(); + Serial.println("CH00: " + String((inputs & (1 << DIN_READ_CH_PIN_00)) >> DIN_READ_CH_PIN_00)); + Serial.println("CH01: " + String((inputs & (1 << DIN_READ_CH_PIN_01)) >> DIN_READ_CH_PIN_01)); + Serial.println("CH02: " + String((inputs & (1 << DIN_READ_CH_PIN_02)) >> DIN_READ_CH_PIN_02)); + Serial.println("CH03: " + String((inputs & (1 << DIN_READ_CH_PIN_03)) >> DIN_READ_CH_PIN_03)); + Serial.println("CH04: " + String((inputs & (1 << DIN_READ_CH_PIN_04)) >> DIN_READ_CH_PIN_04)); + Serial.println("CH05: " + String((inputs & (1 << DIN_READ_CH_PIN_05)) >> DIN_READ_CH_PIN_05)); + Serial.println("CH06: " + String((inputs & (1 << DIN_READ_CH_PIN_06)) >> DIN_READ_CH_PIN_06)); + Serial.println("CH07: " + String((inputs & (1 << DIN_READ_CH_PIN_07)) >> DIN_READ_CH_PIN_07)); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/GPIO_programmable/GPIO_programmable.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/GPIO_programmable/GPIO_programmable.ino new file mode 100644 index 00000000..cf80f0a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Digital_programmable/GPIO_programmable/GPIO_programmable.ino @@ -0,0 +1,88 @@ +/* + Machine Control - IOExpander Read And Write Example + + This sketch shows how to use the GPIO Expanders on the Machine Control, + how to periodically send a value on the PROGRAMMABLE DIGITAL I/O + output channels and how to periodically read from the PROGRAMMABLE + DIGITAL I/O input channels. + + The circuit: + - Portenta H7 + - Machine Control + + This example code is in the public domain. +*/ + +#include +#include "Wire.h" +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + while (!Serial); + Wire.begin(); + if (!digital_programmables.init()) { + Serial.println("GPIO expander initialization fail!!"); + } + + Serial.println("GPIO expander initialization done"); + digital_programmables.setLatch(); +} + +void loop() { + // Write the status value to On to Pin 3 + digital_programmables.set(IO_WRITE_CH_PIN_03, SWITCH_ON); + delay(1000); + + // Read from Pin 3 + Serial.println("Read Pin 03: " + String(digital_programmables.read(IO_READ_CH_PIN_03))); + delay(1000); + + // Write the status value to Off to Pin 3 + digital_programmables.set(IO_WRITE_CH_PIN_03, SWITCH_OFF); + delay(1000); + + Serial.println(); + // Sets all the status Pins Values to On in one single operation + uint32_t status = ON_VALUE_PIN_10 | ON_VALUE_PIN_08 | ON_VALUE_PIN_06 | ON_VALUE_PIN_04 | ON_VALUE_PIN_02 | ON_VALUE_PIN_00; + digital_programmables.writeAll(status); + delay(1000); + + // Toggles the actual status values of all digital programmables Pins + digital_programmables.toggle(); + delay(1000); + + Serial.println(); + // Write the status value to On to all the Output Pins + digital_programmables.writeAll(SWITCH_ON_ALL); + + // Reads from all Input Pins + readAll(); + delay(1000); + + // Write the status value to Off all to all the Output Pins + digital_programmables.writeAll(SWITCH_OFF_ALL); + + // Reads from all Input Pins + readAll(); + Serial.println(); + delay(1000); +} + +uint8_t readAll() { + uint32_t inputs = digital_programmables.readAll(); + Serial.println("CH00: " + String((inputs & (1 << IO_READ_CH_PIN_00)) >> IO_READ_CH_PIN_00)); + Serial.println("CH01: " + String((inputs & (1 << IO_READ_CH_PIN_01)) >> IO_READ_CH_PIN_01)); + Serial.println("CH02: " + String((inputs & (1 << IO_READ_CH_PIN_02)) >> IO_READ_CH_PIN_02)); + Serial.println("CH03: " + String((inputs & (1 << IO_READ_CH_PIN_03)) >> IO_READ_CH_PIN_03)); + Serial.println("CH04: " + String((inputs & (1 << IO_READ_CH_PIN_04)) >> IO_READ_CH_PIN_04)); + Serial.println("CH05: " + String((inputs & (1 << IO_READ_CH_PIN_05)) >> IO_READ_CH_PIN_05)); + Serial.println("CH06: " + String((inputs & (1 << IO_READ_CH_PIN_06)) >> IO_READ_CH_PIN_06)); + Serial.println("CH07: " + String((inputs & (1 << IO_READ_CH_PIN_07)) >> IO_READ_CH_PIN_07)); + Serial.println("CH08: " + String((inputs & (1 << IO_READ_CH_PIN_08)) >> IO_READ_CH_PIN_08)); + Serial.println("CH09: " + String((inputs & (1 << IO_READ_CH_PIN_09)) >> IO_READ_CH_PIN_09)); + Serial.println("CH10: " + String((inputs & (1 << IO_READ_CH_PIN_10)) >> IO_READ_CH_PIN_10)); + Serial.println("CH11: " + String((inputs & (1 << IO_READ_CH_PIN_11)) >> IO_READ_CH_PIN_11)); + Serial.println(); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Encoders/Encoders.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Encoders/Encoders.ino new file mode 100644 index 00000000..0e91d45c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Encoders/Encoders.ino @@ -0,0 +1,28 @@ +#include + +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + while (!Serial); +} + +void loop() { + // put your main code here, to run repeatedly: + Serial.print("Encoder 0 State: "); + Serial.println(encoders[0].getCurrentState(),BIN); + Serial.print("Encoder 0 Pulses: "); + Serial.println(encoders[0].getPulses()); + Serial.print("Encoder 0 Revolutions: "); + Serial.println(encoders[0].getRevolutions()); + Serial.println(); + + Serial.print("Encoder 1 State: "); + Serial.println(encoders[1].getCurrentState(),BIN); + Serial.print("Encoder 1 Pulses: "); + Serial.println(encoders[1].getPulses()); + Serial.print("Encoder 1 Revolutions: "); + Serial.println(encoders[1].getRevolutions()); + Serial.println(); + delay(25); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Ethernet/Ethernet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Ethernet/Ethernet.ino new file mode 100644 index 00000000..dffd867d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Ethernet/Ethernet.ino @@ -0,0 +1,84 @@ +#include "EthernetInterface.h" +EthernetInterface net; + +void setup() +{ + Serial.begin(115200); + while (!Serial) + ; + + Serial.println("Ethernet example for H7 + PMC"); + + // Bring up the ethernet interface + net.connect(); + + // Show the network address + SocketAddress addr; + net.get_ip_address(&addr); + Serial.print("IP address: "); + Serial.println(addr.get_ip_address() ? addr.get_ip_address() : "None"); + + // Open a socket on the network interface, and create a TCP connection to mbed.org + TCPSocket socket; + socket.open(&net); + + net.gethostbyname("ifconfig.io", &addr); + addr.set_port(80); + socket.connect(addr); + + String request; + request += "GET / HTTP/1.1\r\n"; + request += "Host: ifconfig.io\r\n"; + request += "User-Agent: curl/7.64.1\r\n"; + request += "Accept: */*\r\n"; + request += "Connection: close\r\n"; + request += "\r\n"; + + auto scount = socket.send(request.c_str(), request.length()); + Serial.print("Sent "); + Serial.print(scount); + Serial.println(" bytes: "); + Serial.print(request); + + // Receive a simple HTTP response + const size_t rlen { 64 }; + char rbuffer[rlen + 1] {}; + size_t rcount; + size_t rec { 0 }; + String response; + + while ((rec = socket.recv(rbuffer, rlen)) > 0) { + rcount += rec; + response += rbuffer; + memset(rbuffer, 0, rlen); + } + Serial.print("Received "); + Serial.print(rcount); + Serial.println(" bytes: "); + Serial.println(response); + + const String clTag = "Content-Length: "; + auto clIndex = response.indexOf(clTag); + clIndex += clTag.length(); + auto cl = response.substring(clIndex, clIndex + 2); + const String bodyTag = "\r\n\r\n"; + auto bodyIndex = response.indexOf(bodyTag); + if (bodyIndex != -1) { + bodyIndex += bodyTag.length(); + auto body = response.substring(bodyIndex, bodyIndex + cl.toInt()); + Serial.print("My public IPv4 Address is: "); + Serial.println(body); + } + + + // Close the socket to return its memory and bring down the network interface + socket.close(); + + // Bring down the ethernet interface + net.disconnect(); + Serial.println("Done"); +} + +void loop() +{ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS232/RS232.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS232/RS232.ino new file mode 100644 index 00000000..97b4a0bb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS232/RS232.ino @@ -0,0 +1,88 @@ +/* + RS232 communication + + This sketch shows how to use the SP335ECR1 on the Machine + Control as a RS232 interface, how to periodically send + a string on the RS232 TX channel and how to receive data + from the interface RX channel. + + Circuit: + - Arduino Portenta Machine Control (PMC) + - Device with RS232 interface + - Connect PMC TXN to RS232 Device RXD + - Connect PMC RXP to RS232 Device TXD + - Connect PMC GND to RS232 Device GND + +*/ + +#include + +using namespace machinecontrol; + +constexpr unsigned long sendInterval { 1000 }; +unsigned long sendNow { 0 }; + +unsigned long counter { 0 }; + +void setup() +{ + + Serial.begin(115200); + // Wait for Serial or start after 2.5s + for (auto const timeout = millis() + 2500; !Serial && timeout < millis(); delay(500)) + ; + + delay(2500); + Serial.println("Start RS232 initialization"); + + // Set the PMC Communication Protocols to default config + comm_protocols.init(); + + // RS485/RS232 default config is: + // - RS485/RS232 system disabled + // - RS485 mode + // - Half Duplex + // - No A/B and Y/Z 120 Ohm termination enabled + + // Enable the RS485/RS232 system + comm_protocols.rs485Enable(true); + // Enable the RS232 mode + comm_protocols.rs485ModeRS232(true); + + // Specify baudrate for RS232 communication + comm_protocols.rs485.begin(115200); + // Start in receive mode + comm_protocols.rs485.receive(); + + Serial.println("Initialization done!"); +} + +void loop() +{ + if (comm_protocols.rs485.available()) + Serial.write(comm_protocols.rs485.read()); + + if (millis() > sendNow) { + String log = "["; + log += sendNow; + log += "] "; + + String msg = "hello "; + msg += counter++; + + log += msg; + Serial.println(log); + + // Disable receive mode before transmission + comm_protocols.rs485.noReceive(); + + comm_protocols.rs485.beginTransmission(); + comm_protocols.rs485.println(msg); + comm_protocols.rs485.endTransmission(); + + // Re-enable receive mode after transmission + comm_protocols.rs485.receive(); + + sendNow = millis() + sendInterval; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_fullduplex/RS485_fullduplex.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_fullduplex/RS485_fullduplex.ino new file mode 100644 index 00000000..4c1a04a0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_fullduplex/RS485_fullduplex.ino @@ -0,0 +1,81 @@ +/* + RS485 Full duplex communication + + This sketch shows how to use the SP335ECR1 on the Machine + Control as a full duplex (AB and YZ) RS485 interface, how to periodically + send a string on the RS485 TX channel and how to receive data + from the interface RX channel. + + Circuit: + - Portenta H7 + - Machine Control + - A Slave device with RS485 interface + - Connect TXP to A(+) and TXN to B(-) + - Connect RXP to Y(+) and RXN to Z(-) + +*/ + +#include "Arduino_MachineControl.h" + +using namespace machinecontrol; + +constexpr unsigned long sendInterval { 1000 }; +unsigned long sendNow { 0 }; +unsigned long counter = 0; + +void setup() +{ + + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. + } + delay(1000); + Serial.println("Start RS485 initialization"); + + // Set the PMC Communication Protocols to default config + comm_protocols.init(); + // RS485/RS232 default config is: + // - RS485 mode + // - Half Duplex + // - No A/B and Y/Z 120 Ohm termination enabled + + // Enable the RS485/RS232 system + comm_protocols.rs485Enable(true); + + // Enable Full Duplex mode + // This will also enable A/B and Y/Z 120 Ohm termination resistors + comm_protocols.rs485FullDuplex(true); + + // Specify baudrate, and preamble and postamble times for RS485 communication + comm_protocols.rs485.begin(115200, 0, 500); + + // Start in receive mode + comm_protocols.rs485.receive(); + + + Serial.println("Initialization done!"); +} + +void loop() +{ + if (comm_protocols.rs485.available()) + Serial.write(comm_protocols.rs485.read()); + + if (millis() > sendNow) { + // Disable receive mode before transmission + comm_protocols.rs485.noReceive(); + + comm_protocols.rs485.beginTransmission(); + + comm_protocols.rs485.print("hello "); + comm_protocols.rs485.println(counter++); + + comm_protocols.rs485.endTransmission(); + + // Re-enable receive mode after transmission + comm_protocols.rs485.receive(); + + sendNow = millis() + sendInterval; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_halfduplex/RS485_halfduplex.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_halfduplex/RS485_halfduplex.ino new file mode 100644 index 00000000..3e5de9dc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RS485_halfduplex/RS485_halfduplex.ino @@ -0,0 +1,77 @@ +/* + RS485 Half Duplex communication + + This sketch shows how to use the SP335ECR1 on the Machine + Control as a half duplex (AB) RS485 interface, how to periodically + send a string on the RS485 TX channel and how to receive data + from the interface RX channel. + + Circuit: + - Portenta H7 + - Machine Control + - A Slave device with RS485 interface + - Connect TXP to A(+) and TXN to B(-) + +*/ + +#include "Arduino_MachineControl.h" + +using namespace machinecontrol; + +constexpr unsigned long sendInterval { 1000 }; +unsigned long sendNow { 0 }; + +unsigned long counter { 0 }; + +void setup() +{ + + Serial.begin(115200); + // Wait for Serial or start after 2.5s + for (auto const timeout = millis() + 2500; !Serial && timeout < millis(); delay(500)) + ; + + delay(2500); + Serial.println("Start RS485 initialization"); + + // Set the PMC Communication Protocols to default config + comm_protocols.init(); + + // RS485/RS232 default config is: + // - RS485 mode + // - Half Duplex + // - No A/B and Y/Z 120 Ohm termination enabled + + // Enable the RS485/RS232 system + comm_protocols.rs485Enable(true); + + // Specify baudrate, and preamble and postamble times for RS485 communication + comm_protocols.rs485.begin(115200, 0, 500); + // Start in receive mode + comm_protocols.rs485.receive(); + + Serial.println("Initialization done!"); +} + +void loop() +{ + if (comm_protocols.rs485.available()) + Serial.write(comm_protocols.rs485.read()); + + if (millis() > sendNow) { + // Disable receive mode before transmission + comm_protocols.rs485.noReceive(); + + comm_protocols.rs485.beginTransmission(); + + comm_protocols.rs485.print("hello "); + comm_protocols.rs485.println(counter++); + + comm_protocols.rs485.endTransmission(); + + // Re-enable receive mode after transmission + comm_protocols.rs485.receive(); + + sendNow = millis() + sendInterval; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RTC/RTC.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RTC/RTC.ino new file mode 100644 index 00000000..954e2376 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RTC/RTC.ino @@ -0,0 +1,68 @@ +/* + Machine Control - RTC Example + + This sketch shows how to use the RTC PCF8563T on the Machine + Control Carrier and how to configure the PCF8563T's + time registers. + + Circuit: + - Portenta H7 + - Machine Control + +*/ +#include + +using namespace machinecontrol; + +int years = 20; +int months = 9; +int days = 24; +int hours = 12; +int minutes = 43; +int seconds = 31; + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. + } + + Serial.println("Initialization"); + if(!rtc_controller.begin()) { + Serial.println("Initialization fail!"); + } + Serial.println("Initialization Done!"); + + // APIs to set date's fields: years, months, days, hours, minutes and seconds + // The RTC time can be set as epoch, using one of the following two options: + // - Calendar time: rtc_controller.setEpoch(years, months, days, hours, minutes, seconds); + // - UTC time: rtc_controller.setEpoch(date_in_seconds); + rtc_controller.setYears(years); + rtc_controller.setMonths(months); + rtc_controller.setDays(days); + rtc_controller.setHours(hours); + rtc_controller.setMinutes(minutes); + rtc_controller.setSeconds(seconds); + rtc_controller.setEpoch(); +} + +void loop() { + // APIs to get date's fields. + Serial.print("Date: "); + Serial.print(rtc_controller.getYears()); + Serial.print("/"); + Serial.print(rtc_controller.getMonths()); + Serial.print("/"); + Serial.print(rtc_controller.getDays()); + Serial.print(" - "); + Serial.print(rtc_controller.getHours()); + Serial.print(":"); + Serial.print(rtc_controller.getMinutes()); + Serial.print(":"); + Serial.println(rtc_controller.getSeconds()); + time_t utc_time = time(NULL); + Serial.print("Date as UTC time: "); + Serial.println(utc_time); + Serial.println(); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RTC_Alarm/RTC_Alarm.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RTC_Alarm/RTC_Alarm.ino new file mode 100644 index 00000000..c455af63 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/RTC_Alarm/RTC_Alarm.ino @@ -0,0 +1,81 @@ +/* + Machine Control - RTC Alarm Example + + This sketch shows how to use the RTC PCF8563T on the Machine + Control Carrier and how to configure and use the PCF8563T's + alarm. + + Circuit: + - Portenta H7 + - Machine Control + +*/ +#include + +using namespace machinecontrol; + +int hours = 12; +int minutes = 45; +int seconds = 57; + +void callback_alarm(); + +bool alarm_flag = false; + +void setup() { + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. + } + Serial.println("Initialization"); + + if (!rtc_controller.begin()) { + Serial.println("Initialization fail!"); + } + + + Serial.println("Initialization Done!"); + + // APIs to set date's fields: hours, minutes and seconds + rtc_controller.setHours(hours); + rtc_controller.setMinutes(minutes); + rtc_controller.setSeconds(seconds); + // Enables Alarm on PCF8563T + rtc_controller.enableAlarm(); + + // set the minutes at which the alarm should rise + rtc_controller.setMinuteAlarm(46); + + // Attach an interrupt to the RTC interrupt pin + attachInterrupt(RTC_INT, callback_alarm, FALLING); + + Serial.println(); +} +int counter = 1; +void loop() { + if (alarm_flag) { + Serial.println("Alarm!!"); + detachInterrupt(RTC_INT); + rtc_controller.setSeconds(seconds); + rtc_controller.setMinuteAlarm(minutes + counter); + rtc_controller.clearAlarm(); + attachInterrupt(RTC_INT, callback_alarm, FALLING); + alarm_flag = false; + + // To disable the alarm uncomment the following line: + // rtc_controller.disableAlarm(); + } + + // APIs to get date's fields. + //Serial.println(digitalRead(rtc_controller.int_pin)); + Serial.print(rtc_controller.getHours()); + Serial.print(":"); + Serial.print(rtc_controller.getMinutes()); + Serial.print(":"); + Serial.println(rtc_controller.getSeconds()); + delay(1000); +} + +void callback_alarm () { + alarm_flag = true; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_RTD/Temp_probes_RTD.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_RTD/Temp_probes_RTD.ino new file mode 100644 index 00000000..2899dc60 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_RTD/Temp_probes_RTD.ino @@ -0,0 +1,148 @@ +/* + Machine Control - Temperature probes RTD example + + This example provides a way to test the 3-wire RTDs + on the Machine control Carrier. It is possible to + acquire 2-wire RTD simply by shorting the RTDx pin + to the TPx pin. The Machine control carrier has on + board a precise 400 ohm 0.1% reference resistor which + is used as a reference by the MAX31865. + + The circuit: + - Portenta H7 + - Portenta Machine Control Carrier + - 3-wire RTD or 2-wire RTD +*/ + +#include + +using namespace machinecontrol; + +// The value of the Rref resistor. Use 430.0 for PT100 and 4300.0 for PT1000 +#define RREF 400.0 +// The 'nominal' 0-degrees-C resistance of the sensor +// 100.0 for PT100, 1000.0 for PT1000 +#define RNOMINAL 100.0 + +void setup() { + Serial.begin(9600); + Serial.println("MAX31865 PT100 Sensor Test!"); + temp_probes.rtd.begin(THREE_WIRE); + temp_probes.enableRTD(); +} + +void loop() { + temp_probes.selectChannel(0); + Serial.println("CHANNEL 0 SELECTED"); + uint16_t rtd = temp_probes.rtd.readRTD(); + float ratio = rtd; + ratio /= 32768; + + // Check and print any faults + uint8_t fault = temp_probes.rtd.readFault(); + if (fault) { + Serial.print("Fault 0x"); Serial.println(fault, HEX); + if (temp_probes.rtd.getHighThresholdFault(fault)) { + Serial.println("RTD High Threshold"); + } + if (temp_probes.rtd.getLowThresholdFault(fault)) { + Serial.println("RTD Low Threshold"); + } + if (temp_probes.rtd.getLowREFINFault(fault)) { + Serial.println("REFIN- > 0.85 x Bias"); + } + if (temp_probes.rtd.getHighREFINFault(fault)) { + Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getLowRTDINFault(fault)) { + Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getVoltageFault(fault)) { + Serial.println("Under/Over voltage"); + } + temp_probes.rtd.clearFault(); + } else { + Serial.print("RTD value: "); Serial.println(rtd); + Serial.print("Ratio = "); Serial.println(ratio, 8); + Serial.print("Resistance = "); Serial.println(RREF * ratio, 8); + Serial.print("Temperature = "); Serial.println(temp_probes.rtd.readTemperature(RNOMINAL, RREF)); + } + Serial.println(); + delay(100); + + temp_probes.selectChannel(1); + Serial.println("CHANNEL 1 SELECTED"); + rtd = temp_probes.rtd.readRTD(); + ratio = rtd; + ratio /= 32768; + + // Check and print any faults + fault = temp_probes.rtd.readFault(); + if (fault) { + Serial.print("Fault 0x"); Serial.println(fault, HEX); + if (temp_probes.rtd.getHighThresholdFault(fault)) { + Serial.println("RTD High Threshold"); + } + if (temp_probes.rtd.getLowThresholdFault(fault)) { + Serial.println("RTD Low Threshold"); + } + if (temp_probes.rtd.getLowREFINFault(fault)) { + Serial.println("REFIN- > 0.85 x Bias"); + } + if (temp_probes.rtd.getHighREFINFault(fault)) { + Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getLowRTDINFault(fault)) { + Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getVoltageFault(fault)) { + Serial.println("Under/Over voltage"); + } + temp_probes.rtd.clearFault(); + } else { + Serial.print("RTD value: "); Serial.println(rtd); + Serial.print("Ratio = "); Serial.println(ratio, 8); + Serial.print("Resistance = "); Serial.println(RREF * ratio, 8); + Serial.print("Temperature = "); Serial.println(temp_probes.rtd.readTemperature(RNOMINAL, RREF)); + } + Serial.println(); + delay(100); + + temp_probes.selectChannel(2); + Serial.println("CHANNEL 2 SELECTED"); + rtd = temp_probes.rtd.readRTD(); + ratio = rtd; + ratio /= 32768; + + // Check and print any faults + fault = temp_probes.rtd.readFault(); + if (fault) { + Serial.print("Fault 0x"); Serial.println(fault, HEX); + if (temp_probes.rtd.getHighThresholdFault(fault)) { + Serial.println("RTD High Threshold"); + } + if (temp_probes.rtd.getLowThresholdFault(fault)) { + Serial.println("RTD Low Threshold"); + } + if (temp_probes.rtd.getLowREFINFault(fault)) { + Serial.println("REFIN- > 0.85 x Bias"); + } + if (temp_probes.rtd.getHighREFINFault(fault)) { + Serial.println("REFIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getLowRTDINFault(fault)) { + Serial.println("RTDIN- < 0.85 x Bias - FORCE- open"); + } + if (temp_probes.rtd.getVoltageFault(fault)) { + Serial.println("Under/Over voltage"); + } + temp_probes.rtd.clearFault(); + } else { + Serial.print("RTD value: "); Serial.println(rtd); + Serial.print("Ratio = "); Serial.println(ratio, 8); + Serial.print("Resistance = "); Serial.println(RREF * ratio, 8); + Serial.print("Temperature = "); Serial.println(temp_probes.rtd.readTemperature(RNOMINAL, RREF)); + } + Serial.println(); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_Thermocouples/Temp_probes_Thermocouples.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_Thermocouples/Temp_probes_Thermocouples.ino new file mode 100644 index 00000000..5fef867d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/Temp_probes_Thermocouples/Temp_probes_Thermocouples.ino @@ -0,0 +1,59 @@ +/* + Machine Control - Thermocouples Read Sensors + + This example reads the temperatures measured by the thermocouples + connected to the Machine Control Carrier's temp probe inputs and prints + them to the Serial Monitor once a second. + + The circuit: + - Portenta H7 + - Portenta Machine Control Carrier + - Two K Type thermocouple temperature sensors connected to + TEMP PROBES CH0 and CH1 on the Machine Control + - A J Type thermocouple temperature sensor connected to + TEMP PROBES CH3 on the Machine Control + + This example code is in the public domain. +*/ + +#include + +using namespace machinecontrol; + +void setup() { + Serial.begin(9600); + // Initialize temperature probes + temp_probes.tc.begin(); + Serial.println("Temperature probes initialization done"); + // Enables Thermocouples chip select + temp_probes.enableTC(); + Serial.println("Thermocouples enabled"); +} + +void loop() { + //Set CH0, has internal 150 ms delay + temp_probes.selectChannel(0); + //Take CH0 measurement + float temp_ch0 = temp_probes.tc.readTemperature(); + Serial.print("Temperature CH0 [°C]: "); + Serial.print(temp_ch0); + Serial.println(); + + //Set CH1, has internal 150 ms delay + temp_probes.selectChannel(1); + //Take CH1 measurement + float temp_ch1 = temp_probes.tc.readTemperature(); + Serial.print("Temperature CH1 [°C]: "); + Serial.print(temp_ch1); + Serial.println(); + + //Set CH2, has internal 150 ms delay + temp_probes.selectChannel(2); + //Take CH2 measurement + float temp_ch2 = temp_probes.tc.readTemperature(); + Serial.print("Temperature CH2 [°C]: "); + Serial.print(temp_ch2); + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/TUSB_helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/TUSB_helpers.h new file mode 100644 index 00000000..dddde716 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/TUSB_helpers.h @@ -0,0 +1,151 @@ +/* + _______ _ _ _____ ____ + |__ __| | | | |/ ____| _ \ + | | ___ ___ _ __ _ _| | | | (___ | |_) | + | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < + | | __/ __/ | | | |_| | |__| |____) | |_) | + |_|\___|\___|_| |_|\__, |\____/|_____/|____/ + __/ | + |___/ + + TeenyUSB - light weight usb stack for STM32 micro controllers + + Copyright (c) 2019 XToolBox - admin@xtoolbox.org + www.tusb.org + + 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. +*/ + +#pragma once + +#include + +static const tusbh_boot_key_class_t cls_boot_key = { + .backend = &tusbh_boot_keyboard_backend, + //.on_key = process_key +}; + +static const tusbh_boot_mouse_class_t cls_boot_mouse = { + .backend = &tusbh_boot_mouse_backend, + // .on_mouse = process_mouse +}; + +static const tusbh_hid_class_t cls_hid = { + .backend = &tusbh_hid_backend, + //.on_recv_data = process_hid_recv, + //.on_send_done = process_hid_sent, +}; + +static const tusbh_hub_class_t cls_hub = { + .backend = &tusbh_hub_backend, +}; + +static const tusbh_vendor_class_t cls_vendor = { + .backend = &tusbh_vendor_backend, + //.transfer_done = process_vendor_xfer_done +}; + +int msc_ff_mount(tusbh_interface_t* interface, int max_lun, const tusbh_block_info_t* blocks); +int msc_ff_unmount(tusbh_interface_t* interface); + +static const tusbh_msc_class_t cls_msc_bot = { + .backend = &tusbh_msc_bot_backend, + // .mount = msc_ff_mount, + // .unmount = msc_ff_unmount, +}; + +static const tusbh_cdc_acm_class_t cls_cdc_acm = { + .backend = &tusbh_cdc_acm_backend, +}; + +static const tusbh_cdc_rndis_class_t cls_cdc_rndis = { + .backend = &tusbh_cdc_rndis_backend, +}; + +static const tusbh_class_reg_t class_table[] = { + (tusbh_class_reg_t)&cls_boot_key, + (tusbh_class_reg_t)&cls_boot_mouse, + (tusbh_class_reg_t)&cls_hub, + (tusbh_class_reg_t)&cls_msc_bot, + (tusbh_class_reg_t)&cls_cdc_acm, + (tusbh_class_reg_t)&cls_cdc_rndis, + (tusbh_class_reg_t)&cls_hid, + (tusbh_class_reg_t)&cls_vendor, + 0, +}; + +#define MOD_CTRL (0x01 | 0x10) +#define MOD_SHIFT (0x02 | 0x20) +#define MOD_ALT (0x04 | 0x40) +#define MOD_WIN (0x08 | 0x80) + +#define LED_NUM_LOCK 1 +#define LED_CAPS_LOCK 2 +#define LED_SCROLL_LOCK 4 + +#define stdin_recvchar Serial1.write + +static uint8_t key_leds; +static const char knum[] = "1234567890"; +static const char ksign[] = "!@#$%^&*()"; +static const char tabA[] = "\t -=[]\\#;'`,./"; +static const char tabB[] = "\t _+{}|~:\"~<>?"; + +// route the key event to stdin +static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) +{ + Serial.println(); + + uint8_t modify = keys[0]; + uint8_t key = keys[2]; + uint8_t last_leds = key_leds; + if (key >= KEY_A && key <= KEY_Z) { + char ch = 'A' + key - KEY_A; + if ( (!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK)) ) { + ch += 'a' - 'A'; + } + stdin_recvchar(ch); + Serial.print(ch); + } else if (key >= KEY_1 && key <= KEY_0) { + if (modify & MOD_SHIFT) { + stdin_recvchar(ksign[key - KEY_1]); + } else { + stdin_recvchar(knum[key - KEY_1]); + } + } else if (key >= KEY_TAB && key <= KEY_SLASH) { + if (modify & MOD_SHIFT) { + stdin_recvchar(tabB[key - KEY_TAB]); + } else { + stdin_recvchar(tabA[key - KEY_TAB]); + } + } else if (key == KEY_ENTER) { + stdin_recvchar('\r'); + } else if (key == KEY_CAPSLOCK) { + key_leds ^= LED_CAPS_LOCK; + } else if (key == KEY_NUMLOCK) { + key_leds ^= LED_NUM_LOCK; + } else if (key == KEY_SCROLLLOCK) { + key_leds ^= LED_SCROLL_LOCK; + } + + if (key_leds != last_leds) { + tusbh_set_keyboard_led(ep, key_leds); + } + return 0; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/USB_host.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/USB_host.ino new file mode 100644 index 00000000..69cc975d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_MachineControl/examples/USB_host/USB_host.ino @@ -0,0 +1,25 @@ +#include +#include + +#include "TUSB_helpers.h" + +using namespace machinecontrol; + +// Redirect log output from MbedOS and low-level libraries to Serial +REDIRECT_STDOUT_TO(Serial); + +USBHost usb; + +void setup() +{ + Serial1.begin(115200); + usb_controller.powerEnable(); + usb.Init(USB_CORE_ID_FS, class_table); + +} + +void loop() { + usb.Task(); +} + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/LICENSE.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/LICENSE.md new file mode 100644 index 00000000..a39b7233 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/LICENSE.md @@ -0,0 +1,39 @@ +Copyright (C) 2011 - 2014 Bosch Sensortec GmbH + +Arduino_NAxisMotion Library +Date: 2014/09/12 +Usage:Library and example code for the BNO055 + +License: + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright +notice, this list of conditions and the following disclaimer in the +documentation and/or other materials provided with the distribution. + +Neither the name of the copyright holder nor the names of the +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + +The information provided is believed to be accurate and reliable. +The copyright holder assumes no responsibility for the consequences of use +of such information nor for any infringement of patents or +other rights of third parties which may result from its use. +No license is granted by implication or otherwise under any patent or +patent rights of the copyright holder. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/README.md new file mode 100644 index 00000000..44ec8225 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/README.md @@ -0,0 +1,48 @@ +> **Note:** this library is deprecated and no longer maintained. + +9 Axes Motion Library + +[![Check Arduino status](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/NineAxesMotion/actions/workflows/spell-check.yml) + +----------- +The Arduino_NineAxesMotion.cpp and Arduino_NineAxesMotion.h files are C++ wrapper codes for the +BNO055.c and BNO055.h Sensor API. The wrapper code has been designed to +abstract the Sensor API and also to give an idea on how to use the +advanced features in the Sensor API. Apart from that it acts a bridge +between the Sensor API and the Arduino framework. Copy this library into +"yourArduinoInstallation"/libraries folder. + + +------------------------------------------------------------------------------- +There are 4 examples with the 9 Axes Motion library. + + - BareMinimum: This example code is as the name says the minimum code + required to use the 9 Axes Motion shield. + + - Euler: This example code reads out the Euler angles in the NDoF mode to + the Serial Monitor. It also reads out the Calibration Status. Each sensor + and the System itself has its own Calibration Status. See below on how to + calibrate each of the sensors. + + - Accelerometer: This example code reads out the Accelerometer data and + associated data which are the Linear Acceleration data, which is the + Accelerometer data without the gravity vector, the other is the Gravity + Acceleration data, which is only the gravity vector. + + - Motion: This example code is a game to test how steadily you can move an + object, in this case it is the shield with the Arduino board. The goal is + to demonstrate on how to use the Any motion and No motion Interrupts. + +Calibration helps the Sensor identify its environment and automatically +determine offsets. Follow the instructions below to calibrate your sensor. + + - Gyroscope: Keep it steady and do not move it. Preferably keep it on a fixed + surface such as a table. + + - Accelerometer: Rotate the shield slowly and pause at every 45deg for a + second. Rotate one 1 axis at a time. Preferably rotate along 2 axes. + + - Magnetometer: Move the magnetometer in a large 8 like pattern a few times + gently. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Accelerometer/Accelerometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Accelerometer/Accelerometer.ino new file mode 100644 index 00000000..360e9b96 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Accelerometer/Accelerometer.ino @@ -0,0 +1,145 @@ +/**************************************************************************** +* Copyright (C) 2011 - 2014 Bosch Sensortec GmbH +* +* Accelerometer.ino +* Date: 2014/09/09 +* Revision: 3.0 $ +* +* Usage: Example code to stream Accelerometer data +* +**************************************************************************** +/*************************************************************************** +* License: +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* Neither the name of the copyright holder nor the names of the +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE +* +* The information provided is believed to be accurate and reliable. +* The copyright holder assumes no responsibility for the consequences of use +* of such information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of the copyright holder. +*/ + +#include "Arduino_NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment +#include + +NineAxesMotion mySensor; //Object that for the sensor +unsigned long lastStreamTime = 0; //To store the last streamed time stamp +const int streamPeriod = 40; //To stream at 25Hz without using additional timers (time period(ms) =1000/frequency(Hz)) +bool updateSensorData = true; //Flag to update the sensor data. Default is true to perform the first read before the first stream + +void setup() //This code is executed once +{ + //Peripheral Initialization + Serial.begin(9600); //Initialize the Serial Port to view information on the Serial Monitor + Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + //Sensor Initialization + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired + mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to manual requires calling the relevant update functions prior to calling the read functions + //Setting to MANUAL requires lesser reads to the sensor + mySensor.updateAccelConfig(); + updateSensorData = true; + Serial.println(); + Serial.println("Default accelerometer configuration settings..."); + Serial.print("Range: "); + Serial.println(mySensor.readAccelRange()); + Serial.print("Bandwidth: "); + Serial.println(mySensor.readAccelBandwidth()); + Serial.print("Power Mode: "); + Serial.println(mySensor.readAccelPowerMode()); + Serial.println("Streaming in ..."); //Countdown + Serial.print("3..."); + delay(1000); //Wait for a second + Serial.print("2..."); + delay(1000); //Wait for a second + Serial.println("1..."); + delay(1000); //Wait for a second +} + +void loop() //This code is looped forever +{ + if (updateSensorData) //Keep the updating of data as a separate task + { + mySensor.updateAccel(); //Update the Accelerometer data + mySensor.updateLinearAccel(); //Update the Linear Acceleration data + mySensor.updateGravAccel(); //Update the Gravity Acceleration data + mySensor.updateCalibStatus(); //Update the Calibration Status + updateSensorData = false; + } + if ((millis() - lastStreamTime) >= streamPeriod) + { + lastStreamTime = millis(); + + Serial.print("Time: "); + Serial.print(lastStreamTime); + Serial.print("ms "); + + Serial.print(" aX: "); + Serial.print(mySensor.readAccelerometer(X_AXIS)); //Accelerometer X-Axis data + Serial.print("m/s2 "); + + Serial.print(" aY: "); + Serial.print(mySensor.readAccelerometer(Y_AXIS)); //Accelerometer Y-Axis data + Serial.print("m/s2 "); + + Serial.print(" aZ: "); + Serial.print(mySensor.readAccelerometer(Z_AXIS)); //Accelerometer Z-Axis data + Serial.print("m/s2 "); + + Serial.print(" lX: "); + Serial.print(mySensor.readLinearAcceleration(X_AXIS)); //Linear Acceleration X-Axis data + Serial.print("m/s2 "); + + Serial.print(" lY: "); + Serial.print(mySensor.readLinearAcceleration(Y_AXIS)); //Linear Acceleration Y-Axis data + Serial.print("m/s2 "); + + Serial.print(" lZ: "); + Serial.print(mySensor.readLinearAcceleration(Z_AXIS)); //Linear Acceleration Z-Axis data + Serial.print("m/s2 "); + + Serial.print(" gX: "); + Serial.print(mySensor.readGravAcceleration(X_AXIS)); //Gravity Acceleration X-Axis data + Serial.print("m/s2 "); + + Serial.print(" gY: "); + Serial.print(mySensor.readGravAcceleration(Y_AXIS)); //Gravity Acceleration Y-Axis data + Serial.print("m/s2 "); + + Serial.print(" gZ: "); + Serial.print(mySensor.readGravAcceleration(Z_AXIS)); //Gravity Acceleration Z-Axis data + Serial.print("m/s2 "); + + Serial.print(" C: "); + Serial.print(mySensor.readAccelCalibStatus()); //Accelerometer Calibration Status (0 - 3) + + Serial.println(); + + updateSensorData = true; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/BareMinimum/BareMinimum.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/BareMinimum/BareMinimum.ino new file mode 100644 index 00000000..92cc4b40 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/BareMinimum/BareMinimum.ino @@ -0,0 +1,64 @@ +/**************************************************************************** +* Copyright (C) 2011 - 2014 Bosch Sensortec GmbH +* +* BareMinimum.ino +* Date: 2014/08/25 +* Revision: 2.1 $ +* +* Usage: Example code to describe the Bare Minimum +* +**************************************************************************** +/*************************************************************************** +* License: +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* Neither the name of the copyright holder nor the names of the +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE +* +* The information provided is believed to be accurate and reliable. +* The copyright holder assumes no responsibility for the consequences of use +* of such information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of the copyright holder. +*/ + +#include "Arduino_NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment +#include + +NineAxesMotion mySensor; //Object that for the sensor + +void setup() //This code is executed once +{ + //Peripheral Initialization + Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + //Sensor Initialization + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired +} + +void loop() //This code is looped forever +{ + //Blank +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Euler/Euler.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Euler/Euler.ino new file mode 100644 index 00000000..0437afba --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Euler/Euler.ino @@ -0,0 +1,104 @@ +/**************************************************************************** +* Copyright (C) 2011 - 2014 Bosch Sensortec GmbH +* +* Euler.ino +* Date: 2014/09/09 +* Revision: 3.0 $ +* +* Usage: Example code to stream Euler data +* +**************************************************************************** +/*************************************************************************** +* License: +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* Neither the name of the copyright holder nor the names of the +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY +* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE +* +* The information provided is believed to be accurate and reliable. +* The copyright holder assumes no responsibility for the consequences of use +* of such information nor for any infringement of patents or +* other rights of third parties which may result from its use. +* No license is granted by implication or otherwise under any patent or +* patent rights of the copyright holder. +*/ + +#include "Arduino_NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment +#include + +NineAxesMotion mySensor; //Object that for the sensor +unsigned long lastStreamTime = 0; //To store the last streamed time stamp +const int streamPeriod = 20; //To stream at 50Hz without using additional timers (time period(ms) =1000/frequency(Hz)) + +void setup() //This code is executed once +{ + //Peripheral Initialization + Serial.begin(9600); //Initialize the Serial Port to view information on the Serial Monitor + Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + //Sensor Initialization + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired + mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to MANUAL requires calling the relevant update functions prior to calling the read functions + //Setting to MANUAL requires fewer reads to the sensor +} + +void loop() //This code is looped forever +{ + if ((millis() - lastStreamTime) >= streamPeriod) + { + lastStreamTime = millis(); + mySensor.updateEuler(); //Update the Euler data into the structure of the object + mySensor.updateCalibStatus(); //Update the Calibration Status + + Serial.print("Time: "); + Serial.print(lastStreamTime); + Serial.print("ms "); + + Serial.print(" H: "); + Serial.print(mySensor.readEulerHeading()); //Heading data + Serial.print("deg "); + + Serial.print(" R: "); + Serial.print(mySensor.readEulerRoll()); //Roll data + Serial.print("deg"); + + Serial.print(" P: "); + Serial.print(mySensor.readEulerPitch()); //Pitch data + Serial.print("deg "); + + Serial.print(" A: "); + Serial.print(mySensor.readAccelCalibStatus()); //Accelerometer Calibration Status (0 - 3) + + Serial.print(" M: "); + Serial.print(mySensor.readMagCalibStatus()); //Magnetometer Calibration Status (0 - 3) + + Serial.print(" G: "); + Serial.print(mySensor.readGyroCalibStatus()); //Gyroscope Calibration Status (0 - 3) + + Serial.print(" S: "); + Serial.print(mySensor.readSystemCalibStatus()); //System Calibration Status (0 - 3) + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Motion/Motion.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Motion/Motion.ino new file mode 100644 index 00000000..f095560b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_NineAxesMotion/examples/Motion/Motion.ino @@ -0,0 +1,115 @@ +/**************************************************************************** + Copyright (C) 2011 - 2014 Bosch Sensortec GmbH + + Motion.ino + Date: 2014/09/09 + Revision: 2.0 $ + + Usage: Example code of a game to demonstrate the Any motion + and No motion Interrupt features + +**************************************************************************** + /*************************************************************************** + License: + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + Neither the name of the copyright holder nor the names of the + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY + DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE + + The information provided is believed to be accurate and reliable. + The copyright holder assumes no responsibility for the consequences of use + of such information nor for any infringement of patents or + other rights of third parties which may result from its use. + No license is granted by implication or otherwise under any patent or + patent rights of the copyright holder. +*/ + +#include "Arduino_NineAxesMotion.h" //Contains the bridge code between the API and the Arduino Environment +#include + +NineAxesMotion mySensor; //Object that for the sensor +bool intDetected = false; //Flag to indicate if an interrupt was detected +int threshold = 5; //At a Range of 4g, the threshold is set at 39.05mg or 0.3830m/s2. This Range is the default for NDOF Mode +int duration = 1; //At a filter Bandwidth of 62.5Hz, the duration is 8ms. This Bandwidth is the default for NDOF Mode +bool anyMotion = true; //To know which interrupt was triggered + +int InterruptPin = 2; // Pin D2 is connected to the INT LED + +void setup() //This code is executed once +{ + //Peripheral Initialization + Serial.begin(9600); //Initialize the Serial Port to view information on the Serial Monitor + Wire.begin(); //Initialize I2C communication to the let the library communicate with the sensor. + //Sensor Initialization + Serial.println("Please wait. Initialization in process."); + mySensor.initSensor(); //The I2C Address can be changed here inside this function in the library + mySensor.setOperationMode(OPERATION_MODE_NDOF); //Can be configured to other operation modes as desired + mySensor.setUpdateMode(MANUAL); //The default is AUTO. Changing to manual requires calling the relevant update functions prior to calling the read functions + //Setting to MANUAL requires lesser reads to the sensor + + + attachInterrupt(digitalPinToInterrupt(InterruptPin), motionISR, RISING); //Attach the interrupt to the Interrupt Service Routine for a Rising Edge. Change the interrupt pin depending on the board + + //Setup the initial interrupt to trigger at No Motion + mySensor.resetInterrupt(); + mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION); + anyMotion = false; + mySensor.accelInterrupts(ENABLE, ENABLE, ENABLE); //Accelerometer interrupts can be triggered from all 3 axes + Serial.println("This is a game to test how steady you can move an object with one hand. \nKeep the device on a table and mark 2 points."); + Serial.println("Move the Device from one place to another without triggering the Any Motion Interrupt.\n\n"); + delay(1000); //Delay for the player(s) to read + Serial.println("Move the device around and then place it at one position.\nChange the threshold and duration to increase the difficulty level."); + Serial.println("Have fun!\n\n"); +} + +void loop() //This code is looped forever +{ + if (intDetected) + { + if (anyMotion) + { + Serial.println("You moved!! Try again. Keep the Device at one place.\n"); + intDetected = false; + mySensor.resetInterrupt(); //Reset the interrupt line + mySensor.disableAnyMotion(); //Disable the Any motion interrupt + mySensor.enableSlowNoMotion(threshold, duration, NO_MOTION); //Enable the No motion interrupt (can also use the Slow motion instead) + anyMotion = false; + } + else + { + Serial.println("Device is not moving. You may start again.\n\n\n"); + intDetected = false; + mySensor.resetInterrupt(); //Reset the interrupt line + mySensor.disableSlowNoMotion(); //Disable the Slow or No motion interrupt + mySensor.enableAnyMotion(threshold, duration); //Enable the Any motion interrupt + anyMotion = true; + } + } +} + +//Interrupt Service Routine when the sensor triggers an Interrupt +void motionISR() +{ + intDetected = true; +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/README.adoc new file mode 100644 index 00000000..16baf8ff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/README.adoc @@ -0,0 +1,30 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_OAuth + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +OAuth 1.0 client library for Arduino. + +This library depends on ArduinoHttpClient and ArduinoBearSSL. + +== License == + +Copyright (c) 2019 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/GetTwitterStatus.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/GetTwitterStatus.ino new file mode 100644 index 00000000..785401b1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/GetTwitterStatus.ino @@ -0,0 +1,126 @@ +/* + Get Twitter status + + This example shows a REST API GET using OAuth 1.0 + authentication. It then parses the JSON response. + + OAuth credentials can be retrieved from your Twitter + developer account after creating a new app: + + https://developer.twitter.com/en/apps + + Circuit: + + - Arduino MKR WiFi 1010 board + + This example code is in the public domain. +*/ + +#include // ArduinoBearSSL depends on ArduinoECCX08 +#include // Arduino_OAuth depends on ArduinoBearSSL +#include // Arduino_OAuth depends on ArduinoHttpClient +#include +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +const char ssid[] = SECRET_SSID; // your network SSID (name) +const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +const char consumerKey[] = SECRET_CONSUMER_KEY; +const char consumerKeySecret[] = SECRET_CONSUMER_KEY_SECRET; +const char accessToken[] = SECRET_ACCESS_TOKEN; +const char accessTokenSecret[] = SECRET_ACCESS_TOKEN_SECRET; + +int status = WL_IDLE_STATUS; // the WiFi radio's status + +WiFiSSLClient wifiSSLClient; +OAuthClient oauthClient(wifiSSLClient, "api.twitter.com", 443); + +String twitterHandle = "arduino"; // Twitter handle to retrieve Tweets from + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now + Serial.println("You're connected to the network"); + Serial.println(); + + Serial.print("Waiting for the network time to sync "); + while (getTime() == 0) { + Serial.print("."); + delay(1000); + } + Serial.println(); + Serial.println(); + + // assign the OAuth credentials + oauthClient.setCredentials(consumerKey, consumerKeySecret, accessToken, accessTokenSecret); + + // assign the callback to get the current epoch time, the epoch time is + // needed for every OAuth request, as it's used in the HTTP "Authorization" + // request header value and to calculate the request's signature + oauthClient.onGetTime(getTime); +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void loop() { + // Twitter API requests latest Arduino status + oauthClient.get("/1.1/statuses/user_timeline.json?screen_name=" + twitterHandle + "&count=1"); + + int statusCode = oauthClient.responseStatusCode(); + String response = oauthClient.responseBody(); + + if (statusCode != 200) { + // An error occurred + Serial.println(statusCode); + Serial.println(response); + } else { + // Parse JSON response + JSONVar statusesObject = JSON.parse(response); + + // print the handle + Serial.print("@"); + Serial.print(twitterHandle); + Serial.println("'s twitter status: "); + + // print the tweet text, retweet + favorite counts + // we only care about the first item + Serial.println(statusesObject[0]["text"]); + Serial.print("Retweets: "); + Serial.println(statusesObject[0]["retweet_count"]); + Serial.print("Likes: "); + Serial.println(statusesObject[0]["favorite_count"]); + } + Serial.println(); + + // Wait one minute (see Twitter API rate limits before changing) + delay(60 * 1000L); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/arduino_secrets.h new file mode 100644 index 00000000..10878a45 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/GetTwitterStatus/arduino_secrets.h @@ -0,0 +1,8 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" + +// from https://developer.twitter.com/en/apps +#define SECRET_CONSUMER_KEY "" +#define SECRET_CONSUMER_KEY_SECRET "" +#define SECRET_ACCESS_TOKEN "" +#define SECRET_ACCESS_TOKEN_SECRET "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/Tweeter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/Tweeter.ino new file mode 100644 index 00000000..e76749a4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/Tweeter.ino @@ -0,0 +1,128 @@ +/* + Tweeter + + This sketch demonstrates how to post a Tweet directly to + Twitter via the Twitter's HTTP API using OAuth 1.0 for authentication. + + OAuth credentials can be retrieved from the following + website, using your Twitter account and creating a new + app: + + https://developer.twitter.com/en/apps + + Circuit: + - MKR WiFi 1010 board + + This example code is in the public domain. +*/ + +#include // ArduinoBearSSL depends on ArduinoECCX08 +#include // Arduino_OAuth depends on ArduinoBearSSL +#include // Arduino_OAuth depends on ArduinoHttpClient +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +const char ssid[] = SECRET_SSID; // your network SSID (name) +const char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +const char consumerKey[] = SECRET_CONSUMER_KEY; +const char consumerKeySecret[] = SECRET_CONSUMER_KEY_SECRET; +const char accessToken[] = SECRET_ACCESS_TOKEN; +const char accessTokenSecret[] = SECRET_ACCESS_TOKEN_SECRET; + +int status = WL_IDLE_STATUS; // the WiFi radio's status + +WiFiSSLClient wifiSSLClient; +OAuthClient oauthClient(wifiSSLClient, "api.twitter.com", 443); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now + Serial.println("You're connected to the network"); + Serial.println(); + + Serial.print("Waiting for the network time to sync "); + while (getTime() == 0) { + Serial.print("."); + delay(1000); + } + Serial.println(); + Serial.println(); + + // assign the OAuth credentials + oauthClient.setCredentials(consumerKey, consumerKeySecret, accessToken, accessTokenSecret); + + // assign the callback to get the current epoch time, the epoch time is + // needed for every OAuth request, as it's used in the HTTP "Authorization" + // request header value and to calculate the request's signature + oauthClient.onGetTime(getTime); +} + +void loop() { + String status; + + // create the status text + status += "millis() is now: "; + status += millis(); + + tweet(status); + + // wait one minute before Tweeting again + delay(60 * 1000L); +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void tweet(String text) { + Serial.println("Sending tweet: "); + Serial.println(text); + + String requestBody; + + // build the URL encoded request body, the text must be URL encoded + requestBody += "status="; + requestBody += URLEncoder.encode(text); + + // HTTP POST it via the OAuth client, which sets the Authorization header for us + oauthClient.post("/1.1/statuses/update.json", "application/x-www-form-urlencoded", requestBody); + + // read the HTTP status code and body + int statusCode = oauthClient.responseStatusCode(); + String responseBody = oauthClient.responseBody(); + + Serial.print("statusCode = "); + Serial.println(statusCode); + + Serial.print("responseBody = "); + Serial.println(responseBody); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/arduino_secrets.h new file mode 100644 index 00000000..10878a45 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OAuth/examples/Tweeter/arduino_secrets.h @@ -0,0 +1,8 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" + +// from https://developer.twitter.com/en/apps +#define SECRET_CONSUMER_KEY "" +#define SECRET_CONSUMER_KEY_SECRET "" +#define SECRET_ACCESS_TOKEN "" +#define SECRET_ACCESS_TOKEN_SECRET "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/LICENSE new file mode 100644 index 00000000..d159169d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/LICENSE @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/README.adoc new file mode 100644 index 00000000..9db3fc6f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/README.adoc @@ -0,0 +1,22 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_OV767X + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Capture images from your OmniVision OV7670 camera in your Arduino sketches. + +This library is based on https://www.kernel.org[Linux Kernel's] V4L2 driver for OmniVision OV7670 cameras - which was created by Jonathan Corbet. + +== License == + +Copyright (c) 2021 Arduino SA. All rights reserved. + +This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraCapture/CameraCapture.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraCapture/CameraCapture.ino new file mode 100644 index 00000000..51a1c452 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraCapture/CameraCapture.ino @@ -0,0 +1,92 @@ +/* + OV767X - Camera Test Pattern + + This sketch waits for the letter 'c' on the Serial Monitor, + it then reads a frame from the OmniVision OV7670 camera and + prints the data to the Serial Monitor as a hex string. + + The website https://rawpixels.net - can be used the visualize the data: + width: 176 + height: 144 + RGB565 + Little Endian + + Circuit: + - Arduino Nano 33 BLE board + - OV7670 camera module: + - 3.3 connected to 3.3 + - GND connected GND + - SIOC connected to A5 + - SIOD connected to A4 + - VSYNC connected to 8 + - HREF connected to A1 + - PCLK connected to A0 + - XCLK connected to 9 + - D7 connected to 4 + - D6 connected to 6 + - D5 connected to 5 + - D4 connected to 3 + - D3 connected to 2 + - D2 connected to 0 / RX + - D1 connected to 1 / TX + - D0 connected to 10 + + This example code is in the public domain. +*/ + +#include + +unsigned short pixels[176 * 144]; // QCIF: 176x144 X 2 bytes per pixel (RGB565) + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("OV767X Camera Capture"); + Serial.println(); + + if (!Camera.begin(QCIF, RGB565, 1)) { + Serial.println("Failed to initialize camera!"); + while (1); + } + + Serial.println("Camera settings:"); + Serial.print("\twidth = "); + Serial.println(Camera.width()); + Serial.print("\theight = "); + Serial.println(Camera.height()); + Serial.print("\tbits per pixel = "); + Serial.println(Camera.bitsPerPixel()); + Serial.println(); + + Serial.println("Send the 'c' character to read a frame ..."); + Serial.println(); +} + +void loop() { + if (Serial.read() == 'c') { + Serial.println("Reading frame"); + Serial.println(); + Camera.readFrame(pixels); + + int numPixels = Camera.width() * Camera.height(); + + for (int i = 0; i < numPixels; i++) { + unsigned short p = pixels[i]; + + if (p < 0x1000) { + Serial.print('0'); + } + + if (p < 0x0100) { + Serial.print('0'); + } + + if (p < 0x0010) { + Serial.print('0'); + } + + Serial.print(p, HEX); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino new file mode 100644 index 00000000..0e44f3c0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino @@ -0,0 +1,56 @@ +/* + OV767X - Camera Capture Raw Bytes + + This sketch reads a frame from the OmniVision OV7670 camera + and writes the bytes to the Serial port. Use the Processing + sketch in the extras folder to visualize the camera output. + + Circuit: + - Arduino Nano 33 BLE board + - OV7670 camera module: + - 3.3 connected to 3.3 + - GND connected GND + - SIOC connected to A5 + - SIOD connected to A4 + - VSYNC connected to 8 + - HREF connected to A1 + - PCLK connected to A0 + - XCLK connected to 9 + - D7 connected to 4 + - D6 connected to 6 + - D5 connected to 5 + - D4 connected to 3 + - D3 connected to 2 + - D2 connected to 0 / RX + - D1 connected to 1 / TX + - D0 connected to 10 + + This example code is in the public domain. +*/ + +#include + +int bytesPerFrame; + +byte data[320 * 240 * 2]; // QVGA: 320x240 X 2 bytes per pixel (RGB565) + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!Camera.begin(QVGA, RGB565, 1)) { + Serial.println("Failed to initialize camera!"); + while (1); + } + + bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel(); + + // Optionally, enable the test pattern for testing + // Camera.testPattern(); +} + +void loop() { + Camera.readFrame(data); + + Serial.write(data, bytesPerFrame); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraTestPattern/CameraTestPattern.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraTestPattern/CameraTestPattern.ino new file mode 100644 index 00000000..4f488bcb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/CameraTestPattern/CameraTestPattern.ino @@ -0,0 +1,95 @@ +/* + OV767X - Camera Test Pattern + + This sketch enables the test pattern mode, then reads a frame from + the OmniVision OV7670 camera and prints the data to the + Serial Monitor as a hex string. + + The website https://rawpixels.net - can be used the visualize the data: + width: 176 + height: 144 + RGB565 + Little Endian + + Circuit: + - Arduino Nano 33 BLE board + - OV7670 camera module: + - 3.3 connected to 3.3 + - GND connected GND + - SIOC connected to A5 + - SIOD connected to A4 + - VSYNC connected to 8 + - HREF connected to A1 + - PCLK connected to A0 + - XCLK connected to 9 + - D7 connected to 4 + - D6 connected to 6 + - D5 connected to 5 + - D4 connected to 3 + - D3 connected to 2 + - D2 connected to 0 / RX + - D1 connected to 1 / TX + - D0 connected to 10 + + This example code is in the public domain. +*/ + +#include + +unsigned short pixels[176 * 144]; // QCIF: 176x144 X 2 bytes per pixel (RGB565) + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("OV767X Test Pattern"); + Serial.println(); + + if (!Camera.begin(QCIF, RGB565, 1)) { + Serial.println("Failed to initialize camera!"); + while (1); + } + + Serial.println("Camera settings:"); + Serial.print("\twidth = "); + Serial.println(Camera.width()); + Serial.print("\theight = "); + Serial.println(Camera.height()); + Serial.print("\tbits per pixel = "); + Serial.println(Camera.bitsPerPixel()); + Serial.println(); + + Serial.println("Enabling test pattern mode"); + Serial.println(); + Camera.testPattern(); + + Serial.println("Reading frame"); + Serial.println(); + Camera.readFrame(pixels); + + int numPixels = Camera.width() * Camera.height(); + + for (int i = 0; i < numPixels; i++) { + unsigned short p = pixels[i]; + + if (p < 0x1000) { + Serial.print('0'); + } + + if (p < 0x0100) { + Serial.print('0'); + } + + if (p < 0x0010) { + Serial.print('0'); + } + + Serial.print(p, HEX); + } + + Serial.println(); +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/ConnectionTest/ConnectionTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/ConnectionTest/ConnectionTest.ino new file mode 100644 index 00000000..c5deb8e6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_OV767X/examples/ConnectionTest/ConnectionTest.ino @@ -0,0 +1,95 @@ +/* + OV767X - ConnectionTest.ino + + Test that the connection between your Arduino and Camera is able to transfer data correctly at the given speed + + Circuit: + - Arduino Nano 33 BLE board + - OV7670 camera module: + - 3.3 connected to 3.3 + - GND connected GND + - SIOC connected to A5 + - SIOD connected to A4 + - VSYNC connected to 8 + - HREF connected to A1 + - PCLK connected to A0 + - XCLK connected to 9 + - D7 connected to 4 + - D6 connected to 6 + - D5 connected to 5 + - D4 connected to 3 + - D3 connected to 2 + - D2 connected to 0 / RX + - D1 connected to 1 / TX + - D0 connected to 10 + + This example code is in the public domain. + +*/ + +#include +#include + +int bytesPerFrame; +int errors = 0; +int count = 0; +int bestTime = 100000; +int worstTime = 0; +int delayTime = 300; + + +long timer = 0; +Arduino_CRC32 crc32; + +const bool error_checking = true; + +byte data[176 * 144 * 2]; // QCIF at 2 bytes per pixel + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!Camera.begin(QCIF, RGB565, 5)) { + Serial.println("Failed to initialize camera!"); + while (1); + } + + bytesPerFrame = Camera.width() * Camera.height() * Camera.bytesPerPixel(); + + // Enable the test pattern so we have a fixed image to run a checksum against + Camera.testPattern(); +} + +void loop() { + + // sliding delay window to try different start times wrt camera VSYNC + if (delayTime>0) {delayTime=delayTime-10;} + delay(delayTime); + + // benchmarking + timer = millis(); + Camera.readFrame(data); + timer = millis() - timer; + // Check if it is a best case or worse case time + bestTime = min(timer, bestTime); + worstTime = max(timer, worstTime); + + // Test against known checksum values (minor pixel variations at the start but were visually confirmed to be a good test pattern) + uint32_t const crc32_res = crc32.calc(data, bytesPerFrame); + if (crc32_res != 0x15AB2939 && crc32_res != 0xD3EC95E && crc32_res != 0xB9C43ED9) { + errors++; + }; + + count++; + + Serial.print(" errors:"); + Serial.print(errors); + Serial.print("/"); + Serial.print(count); + Serial.print(" best:"); + Serial.print(bestTime); + Serial.print("ms worst:"); + Serial.print(worstTime); + Serial.println("ms"); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_PF1550/examples/BasicUsage/BasicUsage.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_PF1550/examples/BasicUsage/BasicUsage.ino new file mode 100644 index 00000000..1e687388 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_PF1550/examples/BasicUsage/BasicUsage.ino @@ -0,0 +1,34 @@ +#include "Arduino_PMIC.h" + +void setup() { + PMIC.begin(); + + PMIC.configLDO1(Ldo1Voltage::V_1_00, true, true, false); + PMIC.configLDO2(Ldo2Voltage::V_1_80, true, true, false); + PMIC.configLDO3(Ldo3Voltage::V_1_20, true, true, false); + + PMIC.configSw2(Sw2Voltage::V_3_30, /* V_SW2 Normal Mode */ + Sw2Voltage::V_3_30, /* V_SW2 Standby Mode */ + Sw2Voltage::V_3_30, /* V_SW2 Sleep Mode */ + Sw2CurrentLimit::I_1_5_A, /* Current Limit */ + true, /* Enable Normal Mode */ + true, /* Enable Standby Mode */ + true); /* Enable Sleep Mode */ + + PMIC.configCharger(IFastCharge::I_500_mA, + VFastCharge::V_3_80, + IEndOfCharge::I_5_mA, + IInputCurrentLimit::I_100_mA); + + /* TODO: Clarify if a interrupt event is generated by a rising or falling edge, + * according to schematic/datasheet it's a open-drain output with a pull-up resistor. + * Probably we need to do the registering with a ISR handler internally in the future + * since the PMIC_INT pin PK0 will not be exposed externally. + */ + attachInterrupt(digitalPinToInterrupt(0), PF1550::ISR_onPMICEvent, RISING); +} + + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_PF1550/examples/ReadWriteRegs/ReadWriteRegs.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_PF1550/examples/ReadWriteRegs/ReadWriteRegs.ino new file mode 100644 index 00000000..20694d98 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_PF1550/examples/ReadWriteRegs/ReadWriteRegs.ino @@ -0,0 +1,40 @@ +#include "Arduino_PMIC.h" +#include "PF1550/PF1550_Register.h" + +#define Serial Serial1 + +uint8_t regVal; + +void setup() { + Serial.begin(115200); + while(!Serial); + + PMIC.begin(); + + PMIC.debug(Serial); + +} + + +void loop() { + PMIC.writePMICreg(Register::CHARGER_CHG_EOC_CNFG, 0x41); + regVal = PMIC.readPMICreg(Register::CHARGER_CHG_EOC_CNFG); + + Serial.print("CHARGER_CHG_SNS register value: "); + Serial.println(regVal,HEX); + + regVal = PMIC.readPMICreg(Register::CHARGER_VBUS_SNS); + + Serial.print("CHARGER_VBUS_SNS register value: "); + Serial.println(regVal,HEX); + + regVal = PMIC.readPMICreg(Register::CHARGER_CHG_INT_OK); + + Serial.print("CHARGER_CHG_INT_OK register value: "); + Serial.println(regVal,HEX); + Serial.println(); + Serial.println(); + + delay(5000); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/README.md new file mode 100644 index 00000000..5640e59a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/README.md @@ -0,0 +1,55 @@ +Arduino_Portenta_OTA +==================== + +[![Compile Examples](https://github.com/arduino-libraries/Arduino_Portenta_OTA/workflows/Compile%20Examples/badge.svg)](https://github.com/arduino-libraries/Arduino_Portenta_OTA/actions?workflow=Compile+Examples) +[![Arduino Lint](https://github.com/arduino-libraries/Arduino_Portenta_OTA/workflows/Arduino%20Lint/badge.svg)](https://github.com/arduino-libraries/Arduino_Portenta_OTA/actions?workflow=Arduino+Lint) +[![Spell Check](https://github.com/arduino-libraries/Arduino_Portenta_OTA/workflows/Spell%20Check/badge.svg)](https://github.com/arduino-libraries/Arduino_Portenta_OTA/actions?workflow=Spell+Check) + +This library allows OTA (Over-The-Air) firmware updates for the Arduino Portenta H7. OTA binaries are downloaded via WiFi and stored on a SD card or on the Portenta H7's QSPI flash storage. Next, all information relevant to the firmware update is stored in non-volatile memory. After a reset the Portenta H7 bootloader accesses this information and uses it to perform the firmware update. + +### Example +```C++ +#include +#include +#include "arduino_secrets.h" +/* ... */ +void setup() +{ + if (WiFi.status() == WL_NO_SHIELD) + return; + + int status = WL_IDLE_STATUS; + while (status != WL_CONNECTED) + { + status = WiFi.begin(SSID, PASS); + delay(10000); + } + + Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2); + Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None; + + if (!ota.isOtaCapable()) + return; + + if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None) + return; + + int const ota_download = ota.download("http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota", false /* is_https */); + if (ota_download <= 0) + return; + + int const ota_decompress = ota.decompress(); + if (ota_decompress < 0) + return; + + if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None) + return; + + ota.reset(); +} + +void loop() +{ + +} +``` diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/OTA_Qspi_Flash.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/OTA_Qspi_Flash.ino new file mode 100644 index 00000000..0bd06894 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/OTA_Qspi_Flash.ino @@ -0,0 +1,127 @@ +/* + * This example demonstrates how to use to update the firmware of the Arduino Portenta H7 using + * a firmware image stored on the QSPI. + * + * Steps: + * 1) Create a sketch for the Portenta H7 and verifiy + * that it both compiles and works on a board. + * 2) In the IDE select: Sketch -> Export compiled Binary. + * 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in + * https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools . + * A) ./lzss.py --encode SKETCH.bin SKETCH.lzss + * B) ./bin2ota.py PORTENTA_H7_M7 SKETCH.lzss SKETCH.ota + * 4) Upload the OTA file to a network reachable location, e.g. OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * has been uploaded to: http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * 5) Perform an OTA update via steps outlined below. + */ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + +#include + +#include "arduino_secrets.h" + +/****************************************************************************** + * CONSTANT + ******************************************************************************/ + +/* Please enter your sensitive data in the Secret tab/arduino_secrets.h */ +static char const SSID[] = SECRET_SSID; /* your network SSID (name) */ +static char const PASS[] = SECRET_PASS; /* your network password (use for WPA, or use as key for WEP) */ + +static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota"; + +/****************************************************************************** + * SETUP/LOOP + ******************************************************************************/ + +void setup() +{ + Serial.begin(115200); + while (!Serial) {} + + if (WiFi.status() == WL_NO_SHIELD) + { + Serial.println("Communication with WiFi module failed!"); + return; + } + + int status = WL_IDLE_STATUS; + while (status != WL_CONNECTED) + { + Serial.print ("Attempting to connect to '"); + Serial.print (SSID); + Serial.println("'"); + status = WiFi.begin(SSID, PASS); + delay(10000); + } + Serial.print ("You're connected to '"); + Serial.print (WiFi.SSID()); + Serial.println("'"); + + Arduino_Portenta_OTA_QSPI ota(QSPI_FLASH_FATFS_MBR, 2); + Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None; + + if (!ota.isOtaCapable()) + { + Serial.println("Higher version bootloader required to perform OTA."); + Serial.println("Please update the bootloader."); + Serial.println("File -> Examples -> Portenta_System -> PortentaH7_updateBootloader"); + return; + } + + Serial.println("Initializing OTA storage"); + if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None) + { + Serial.print ("Arduino_Portenta_OTA::begin() failed with error code "); + Serial.println((int)ota_err); + return; + } + + + Serial.println("Starting download to QSPI ..."); + int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */); + if (ota_download <= 0) + { + Serial.print ("Arduino_Portenta_OTA_QSPI::download failed with error code "); + Serial.println(ota_download); + return; + } + Serial.print (ota_download); + Serial.println(" bytes stored."); + + + Serial.println("Decompressing LZSS compressed file ..."); + int const ota_decompress = ota.decompress(); + if (ota_decompress < 0) + { + Serial.print("Arduino_Portenta_OTA_QSPI::decompress() failed with error code"); + Serial.println(ota_decompress); + return; + } + Serial.print(ota_decompress); + Serial.println(" bytes decompressed."); + + + Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory ..."); + if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None) + { + Serial.print ("ota.update() failed with error code "); + Serial.println((int)ota_err); + return; + } + + Serial.println("Performing a reset after which the bootloader will update the firmware."); + Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green."); + delay(1000); /* Make sure the serial message gets out before the reset. */ + ota.reset(); +} + +void loop() +{ + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Qspi_Flash/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/OTA_SD_Portenta.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/OTA_SD_Portenta.ino new file mode 100644 index 00000000..0a9fc965 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/OTA_SD_Portenta.ino @@ -0,0 +1,128 @@ +/* + * This example demonstrates how to use to update the firmware of the Arduino Portenta H7 using + * a firmware image stored on the SD. + * + * Steps: + * 1) Create a sketch for the Portenta H7 and verifiy + * that it both compiles and works on a board. + * 2) In the IDE select: Sketch -> Export compiled Binary. + * 3) Create an OTA update file utilising the tools 'lzss.py' and 'bin2ota.py' stored in + * https://github.com/arduino-libraries/ArduinoIoTCloud/tree/master/extras/tools . + * A) ./lzss.py --encode SKETCH.bin PORTENTA_H7_M7.lzss + * B) ./bin2ota.py PORTENTA_H7_M7.lzss PORTENTA_H7_M7.ota + * 4) Upload the OTA file to a network reachable location, e.g. OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * has been uploaded to: http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota + * 5) Perform an OTA update via steps outlined below. + */ + +/****************************************************************************** + * INCLUDE + ******************************************************************************/ + +#include + +#include + +#include "arduino_secrets.h" + +/****************************************************************************** + * CONSTANT + ******************************************************************************/ + +/* Please enter your sensitive data in the Secret tab/arduino_secrets.h */ +static char const SSID[] = SECRET_SSID; /* your network SSID (name) */ +static char const PASS[] = SECRET_PASS; /* your network password (use for WPA, or use as key for WEP) */ + +static char const OTA_FILE_LOCATION[] = "http://downloads.arduino.cc/ota/OTA_Usage_Portenta.ino.PORTENTA_H7_M7.ota"; + +/****************************************************************************** + * SETUP/LOOP + ******************************************************************************/ + +void setup() +{ + Serial.begin(115200); + while (!Serial) {} + + if (WiFi.status() == WL_NO_SHIELD) + { + Serial.println("Communication with WiFi module failed!"); + return; + } + + int status = WL_IDLE_STATUS; + while (status != WL_CONNECTED) + { + Serial.print ("Attempting to connect to '"); + Serial.print (SSID); + Serial.println("'"); + status = WiFi.begin(SSID, PASS); + delay(10000); + } + Serial.print ("You're connected to '"); + Serial.print (WiFi.SSID()); + Serial.println("'"); + + //Arduino_Portenta_OTA_SD ota(SD_FATFS, 0); + Arduino_Portenta_OTA_SD ota(SD_FATFS_MBR, 1); + Arduino_Portenta_OTA::Error ota_err = Arduino_Portenta_OTA::Error::None; + + if (!ota.isOtaCapable()) + { + Serial.println("Higher version bootloader required to perform OTA."); + Serial.println("Please update the bootloader."); + Serial.println("File -> Examples -> Portenta_System -> PortentaH7_updateBootloader"); + return; + } + + Serial.println("Initializing OTA storage"); + if ((ota_err = ota.begin()) != Arduino_Portenta_OTA::Error::None) + { + Serial.print ("Arduino_Portenta_OTA::begin() failed with error code "); + Serial.println((int)ota_err); + return; + } + + + Serial.println("Starting download to SD ..."); + int const ota_download = ota.download(OTA_FILE_LOCATION, false /* is_https */); + if (ota_download <= 0) + { + Serial.print ("Arduino_Portenta_OTA_SD::download failed with error code "); + Serial.println(ota_download); + return; + } + Serial.print (ota_download); + Serial.println(" bytes stored."); + + + Serial.println("Decompressing LZSS compressed file ..."); + int const ota_decompress = ota.decompress(); + if (ota_decompress < 0) + { + Serial.print("Arduino_Portenta_OTA_SD::decompress() failed with error code"); + Serial.println(ota_decompress); + return; + } + Serial.print(ota_decompress); + Serial.println(" bytes decompressed."); + + + Serial.println("Storing parameters for firmware update in bootloader accessible non-volatile memory"); + if ((ota_err = ota.update()) != Arduino_Portenta_OTA::Error::None) + { + Serial.print ("Arduino_Portenta_OTA::update() failed with error code "); + Serial.println((int)ota_err); + return; + } + + Serial.println("Performing a reset after which the bootloader will update the firmware."); + Serial.println("Hint: Portenta H7 LED will blink Red-Blue-Green."); + delay(1000); + ota.reset(); +} + +void loop() +{ + +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_SD_Portenta/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Usage_Portenta/OTA_Usage_Portenta.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Usage_Portenta/OTA_Usage_Portenta.ino new file mode 100644 index 00000000..9481df9b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Portenta_OTA/examples/OTA_Usage_Portenta/OTA_Usage_Portenta.ino @@ -0,0 +1,58 @@ +/* + This sketch can be used to generate an example binary that can be uploaded to Portenta via OTA. + It needs to be used together with + - 'OTA_Qspi_Flash.ino' if you want to use the Qspi Flash as storage system + OR + - 'SD_Qspi_Flash.ino' if you want to use the SD card as storage system + + Steps to test OTA on Portenta: + 1) Upload this sketch or any other sketch (this one lights up the RGB LED with different colours). + 2) In the IDE select: Sketch -> Export compiled Binary + 3) Upload the exported binary to a server + 4) Choose a storage mechanism (SD or QSPI), open the related OTA_*_Portenta.ino sketch, + eventually update the OTA_FILE_LOCATION + 5) Upload the sketch OTA_*_Portenta.ino to perform OTA via SD or QSPI Flash +*/ + +void setLed(int blue, int gree, int red) { + if (blue == 1) { + digitalWrite(LEDB, LOW); + } + else { + digitalWrite(LEDB, HIGH); + } + + if (gree == 1) { + digitalWrite(LEDG, LOW); + } + else { + digitalWrite(LEDG, HIGH); + } + + if (red == 1) { + digitalWrite(LEDR, LOW); + } + else { + digitalWrite(LEDR, HIGH); + } +} + + +void setup() +{ + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDR, OUTPUT); +} + +void loop() +{ //led BLUE ON + setLed(1, 0, 0); + delay(1000); + //led GREEN ON + setLed(0, 1, 0); + delay(1000); + //led RED ON + setLed(0, 0, 1); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/README.adoc new file mode 100644 index 00000000..1588e74f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/README.adoc @@ -0,0 +1,28 @@ +:repository-owner: arduino-libraries +:repository-name: Arduino_ScienceJournal + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Firmware for the Physics Lab kit and the Arduino Nano 33 BLE Sense. + +== License == + +Copyright (c) 2020 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.cpp new file mode 100644 index 00000000..a7638f12 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.cpp @@ -0,0 +1,36 @@ +#include "Arduino.h" +#include "mbed.h" +#include "ArduinoBLE.h" +#include "LowPower.h" + +#include "nrf_power.h" +#include "nrf_uarte.h" +#include "nrf_uart.h" + +void lowPower() +{ + // Disable UARTE0 which is initially enabled by the bootloader + nrf_uarte_task_trigger(NRF_UARTE0, NRF_UARTE_TASK_STOPRX); + while (!nrf_uarte_event_check(NRF_UARTE0, NRF_UARTE_EVENT_RXTO)) ; + NRF_UARTE0->ENABLE = 0; + NRF_UART0->ENABLE = 0; + + // Enable DCDC + nrf_power_dcdcen_set(true); + + // Turn off LED_BUILTIN + digitalWrite(LED_BUILTIN, LOW); +} + +void lowPowerWait(unsigned long time) +{ + rtos::ThisThread::sleep_for(time); +} + +void lowPowerBleWait(unsigned long time) +{ + unsigned long timeRef = millis(); + while (millis() - timeRef < time) { + BLE.poll(time - (millis() - timeRef)); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.h new file mode 100644 index 00000000..1f77f5c9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/LowPower.h @@ -0,0 +1,8 @@ +#ifndef _LOWPOWER_H_ +#define _LOWPOWER_H_ + +void lowPower(); +void lowPowerWait(unsigned long time); +void lowPowerBleWait(unsigned long time); + +#endif //_LOWPOWER_H_ \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino new file mode 100644 index 00000000..96b1b535 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/Nano33BLESenseFirmware/Nano33BLESenseFirmware.ino @@ -0,0 +1,248 @@ +#include "LowPower.h" +#include + +#include +#include +#include +#include +#include + +#include + +const int VERSION = 0x00000001; +const float TEMPERATURE_CALIBRATION = -5.0; + +#define SCIENCE_KIT_UUID(val) ("555a0002-" val "-467a-9538-01f0652c74e8") +#define RESISTANCE_PIN A0 +#define VOLTAGE_BUFFER_SIZE 16 + +//#define DEBUG 0 + +BLEService service (SCIENCE_KIT_UUID("0000")); +BLEUnsignedIntCharacteristic versionCharacteristic (SCIENCE_KIT_UUID("0001"), BLERead); +BLECharacteristic accelerationCharacteristic (SCIENCE_KIT_UUID("0011"), BLENotify, 3 * sizeof(float)); +BLECharacteristic gyroscopeCharacteristic (SCIENCE_KIT_UUID("0012"), BLENotify, 3 * sizeof(float)); +BLECharacteristic magneticFieldCharacteristic(SCIENCE_KIT_UUID("0013"), BLENotify, 3 * sizeof(float)); +BLEFloatCharacteristic temperatureCharacteristic (SCIENCE_KIT_UUID("0014"), BLENotify); +BLEFloatCharacteristic pressureCharacteristic (SCIENCE_KIT_UUID("0015"), BLENotify); +BLEFloatCharacteristic humidityCharacteristic (SCIENCE_KIT_UUID("0016"), BLENotify); +BLEUnsignedIntCharacteristic proximityCharacteristic (SCIENCE_KIT_UUID("0017"), BLENotify); +BLECharacteristic colorCharacteristic (SCIENCE_KIT_UUID("0018"), BLENotify, 4 * sizeof(int)); +BLEUnsignedShortCharacteristic soundPressureCharacteristic(SCIENCE_KIT_UUID("0019"), BLENotify); +BLEFloatCharacteristic resistanceCharacteristic (SCIENCE_KIT_UUID("0020"), BLENotify); + +byte voltageBufferIndex = 0; +bool voltageBufferFilled = false; +short soundSampleBuffer[256]; +short voltageSampleBuffer[VOLTAGE_BUFFER_SIZE]; + +void onPDMdata() { + // query the number of bytes available + int bytesAvailable = PDM.available(); + + // read into the sample buffer + PDM.read(soundSampleBuffer, bytesAvailable); +} + +uint16_t getSoundAverage() { + uint32_t avg = 0; + for (int i = 0; i < sizeof(soundSampleBuffer)/sizeof(soundSampleBuffer[0]); i++) { + avg += soundSampleBuffer[i]*soundSampleBuffer[i]; + } + return sqrt(avg); +} + +void readVoltage() { + voltageSampleBuffer[voltageBufferIndex] = analogRead(RESISTANCE_PIN); + if (!voltageBufferFilled && voltageBufferIndex == VOLTAGE_BUFFER_SIZE - 1) { + voltageBufferFilled = true; + } + voltageBufferIndex = (++voltageBufferIndex) % VOLTAGE_BUFFER_SIZE; +} + +uint16_t getVoltageAverage() { + uint16_t avg = 0; + byte upperBound = voltageBufferFilled ? VOLTAGE_BUFFER_SIZE : voltageBufferIndex; + for (int i = 0; i < upperBound; i++) { + avg += voltageSampleBuffer[i]; + } + return avg / upperBound; +} + +// String to calculate the local and device name +String name; +unsigned long lastNotify = 0; + +void printSerialMsg(const char * msg) { + #ifdef DEBUG + if (Serial) { + Serial.println(msg); + } + #endif +} + +void blinkLoop() { + while (1) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } +} + +void setup() { + #ifdef DEBUG + Serial.begin(9600); + while (!Serial); + Serial.println("Started"); + #endif + + delay(2000); + + pinMode(RESISTANCE_PIN, INPUT); // Used for reading resistance + + if (!APDS.begin()) { + printSerialMsg("Failed to initialized APDS!"); + blinkLoop(); + } + + if (!HTS.begin()) { + printSerialMsg("Failed to initialized HTS!"); + blinkLoop(); + } + + if (!BARO.begin()) { + printSerialMsg("Failed to initialized BARO!"); + blinkLoop(); + } + + if (!IMU.begin()) { + printSerialMsg("Failed to initialized IMU!"); + blinkLoop(); + } + + PDM.onReceive(onPDMdata); + if (!PDM.begin(1, 16000)) { + printSerialMsg("Failed to start PDM!"); + blinkLoop(); + } + + if (!BLE.begin()) { + printSerialMsg("Failed to initialized BLE!"); + blinkLoop(); + } + + String address = BLE.address(); + #ifdef DEBUG + if (Serial) { + Serial.print("address = "); + Serial.println(address); + } + #endif + address.toUpperCase(); + + name = "BLE Sense - "; + name += address[address.length() - 5]; + name += address[address.length() - 4]; + name += address[address.length() - 2]; + name += address[address.length() - 1]; + + #ifdef DEBUG + if (Serial) { + Serial.print("name = "); + Serial.println(name); + } + #endif + + BLE.setLocalName(name.c_str()); + BLE.setDeviceName(name.c_str()); + BLE.setAdvertisedService(service); + + service.addCharacteristic(versionCharacteristic); + service.addCharacteristic(accelerationCharacteristic); + service.addCharacteristic(gyroscopeCharacteristic); + service.addCharacteristic(magneticFieldCharacteristic); + service.addCharacteristic(temperatureCharacteristic); + service.addCharacteristic(pressureCharacteristic); + service.addCharacteristic(humidityCharacteristic); + service.addCharacteristic(proximityCharacteristic); + service.addCharacteristic(colorCharacteristic); + service.addCharacteristic(soundPressureCharacteristic); + service.addCharacteristic(resistanceCharacteristic); + + versionCharacteristic.setValue(VERSION); + + BLE.addService(service); + BLE.advertise(); + + lowPower(); +} + +void loop() { + BLE.poll(1000); + while (BLE.connected()) { + lowPowerBleWait(100); + updateSubscribedCharacteristics(); + } +} + +void updateSubscribedCharacteristics() { + if (accelerationCharacteristic.subscribed()) { + float acceleration[3]; + if (IMU.accelerationAvailable() && IMU.readAcceleration(acceleration[0], acceleration[1], acceleration[2])) { + accelerationCharacteristic.writeValue((byte*)acceleration, sizeof(acceleration)); + } + } + if (gyroscopeCharacteristic.subscribed()) { + float gyroscope[3]; + if (IMU.gyroscopeAvailable() && IMU.readGyroscope(gyroscope[0], gyroscope[1], gyroscope[2])) { + gyroscopeCharacteristic.writeValue((byte*)gyroscope, sizeof(gyroscope)); + } + } + + if (magneticFieldCharacteristic.subscribed()) { + float magneticField[3]; + if (IMU.magneticFieldAvailable() && IMU.readMagneticField(magneticField[0], magneticField[1], magneticField[2])) { + magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField)); + } + } + if (soundPressureCharacteristic.subscribed()) { + uint16_t sound = getSoundAverage(); + soundPressureCharacteristic.writeValue(sound); + } + if (proximityCharacteristic.subscribed() && APDS.proximityAvailable()) { + uint32_t proximity = APDS.readProximity(); + proximityCharacteristic.writeValue(proximity); + } + if (colorCharacteristic.subscribed() && APDS.colorAvailable()) { + int color[4]; + APDS.readColor(color[0], color[1], color[2], color[3]); + colorCharacteristic.writeValue((byte*)color, sizeof(color)); + } + bool doTemperature = temperatureCharacteristic.subscribed(); + bool doHumidity = humidityCharacteristic.subscribed(); + if (doTemperature || doHumidity) { + float temperature = HTS.readTemperature(); + float temperatureCalibrated = temperature + TEMPERATURE_CALIBRATION; + if (doTemperature) { + temperatureCharacteristic.writeValue(temperatureCalibrated); + } + if (doHumidity) { + float humidity = HTS.readHumidity(); + float dp = temperature - ((100.0 - humidity) / 5.0); + float humidityCalibrated = 100.0 - (5.0 * (temperatureCalibrated - dp)); + humidityCharacteristic.writeValue(humidityCalibrated); + } + } + if (pressureCharacteristic.subscribed()) { + float pressure = BARO.readPressure(); + pressureCharacteristic.writeValue(pressure); + } + + if(resistanceCharacteristic.subscribed()){ + readVoltage(); + uint16_t measuredValue = getVoltageAverage(); + float voltageRatio = 1024.0f / measuredValue; + resistanceCharacteristic.writeValue(voltageRatio); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/PhysicsLabFirmware/PhysicsLabFirmware.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/PhysicsLabFirmware/PhysicsLabFirmware.ino new file mode 100644 index 00000000..66127d96 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/PhysicsLabFirmware/PhysicsLabFirmware.ino @@ -0,0 +1,297 @@ +/* + This file is part of the PhysicsLabFirmware library. + Copyright (c) 2019 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include // click here to install the library: http://librarymanager#ArduinoBLE +#include // click here to install the library: http://librarymanager#Adafruit&LSM9DS1 +#include // click here to install the library: http://librarymanager#Adafruit&unified&Sensor&abstraction + +#include "INA226.h" + +#define SCIENCE_KIT_UUID(val) ("555a0001-" val "-467a-9538-01f0652c74e8") + +BLEService service (SCIENCE_KIT_UUID("0000")); +BLEUnsignedIntCharacteristic versionCharacteristic (SCIENCE_KIT_UUID("0001"), BLERead); +BLEByteCharacteristic ledCharacteristic (SCIENCE_KIT_UUID("1001"), BLERead | BLEWrite); +BLEUnsignedShortCharacteristic input1Characteristic (SCIENCE_KIT_UUID("2001"), BLENotify); +BLEUnsignedShortCharacteristic input2Characteristic (SCIENCE_KIT_UUID("2002"), BLENotify); +BLEUnsignedShortCharacteristic input3Characteristic (SCIENCE_KIT_UUID("2003"), BLENotify); +BLEByteCharacteristic ouput1Characteristic (SCIENCE_KIT_UUID("3001"), BLERead | BLEWrite); +BLEByteCharacteristic ouput2Characteristic (SCIENCE_KIT_UUID("3002"), BLERead | BLEWrite); +BLEFloatCharacteristic voltageCharacteristic (SCIENCE_KIT_UUID("4001"), BLENotify); +BLEFloatCharacteristic currentCharacteristic (SCIENCE_KIT_UUID("4002"), BLENotify); +BLEFloatCharacteristic resistanceCharacteristic (SCIENCE_KIT_UUID("4003"), BLENotify); +BLECharacteristic accelerationCharacteristic (SCIENCE_KIT_UUID("5001"), BLENotify, 3 * sizeof(float)); +BLECharacteristic gyroscopeCharacteristic (SCIENCE_KIT_UUID("5002"), BLENotify, 3 * sizeof(float)); +BLECharacteristic magneticFieldCharacteristic(SCIENCE_KIT_UUID("5003"), BLENotify, 3 * sizeof(float)); + +const int LED_PIN = 0; +const int INPUT1_PIN = A3; +const int INPUT2_PIN = A1; +const int INPUT3_PIN = A0; +const int OUTPUT1_PIN = 5; +const int OUTPUT2_PIN = 1; +const int RESISTANCE_PIN = A2; +const int RESISTANCE_AUX_PIN = 8; + +String name; +unsigned long lastNotify = 0; + +unsigned long imuTime; + +#define RESISTOR_AUX_LOW 47000.0 +#define RESISTOR_AUX_HIGH 979.16 // 47k in parallel with 1k = 979.16 Ohm + +#define IMU_UPDATE_TIME 50 + +//#define DEBUG //uncomment to debug the code :) + +Adafruit_LSM9DS1 imu = Adafruit_LSM9DS1(); + +void setup() { + Serial.begin(9600); +#ifdef DEBUG + while (!Serial); + Serial.println("Started"); +#endif + + pinMode(LED_PIN, OUTPUT); + pinMode(INPUT1_PIN, INPUT); + pinMode(INPUT2_PIN, INPUT); + pinMode(INPUT3_PIN, INPUT); + pinMode(OUTPUT1_PIN, OUTPUT); + pinMode(OUTPUT2_PIN, OUTPUT); + pinMode(RESISTANCE_AUX_PIN, OUTPUT); + + digitalWrite(RESISTANCE_AUX_PIN, LOW); + + if (!INA226.begin(0x45)) { + Serial.println("Failed to initialized INA226!"); + + while (1); + } + + if (!imu.begin()) { + Serial.println("Failed to initialized IMU!"); + + while (1); + } + + imu.setupAccel(imu.LSM9DS1_ACCELRANGE_2G); + imu.setupMag(imu.LSM9DS1_MAGGAIN_4GAUSS); + imu.setupGyro(imu.LSM9DS1_GYROSCALE_245DPS); + + if (!BLE.begin()) { + Serial.println("Failed to initialized BLE!"); + + while (1); + } + + String address = BLE.address(); + + address.toUpperCase(); + + name = "MKRSci"; + name += address[address.length() - 5]; + name += address[address.length() - 4]; + name += address[address.length() - 2]; + name += address[address.length() - 1]; + + BLE.setLocalName(name.c_str()); + BLE.setDeviceName(name.c_str()); + BLE.setAdvertisedService(service); + + service.addCharacteristic(versionCharacteristic); + service.addCharacteristic(ledCharacteristic); + service.addCharacteristic(input1Characteristic); + service.addCharacteristic(input2Characteristic); + service.addCharacteristic(input3Characteristic); + service.addCharacteristic(ouput1Characteristic); + service.addCharacteristic(ouput2Characteristic); + service.addCharacteristic(voltageCharacteristic); + service.addCharacteristic(currentCharacteristic); + service.addCharacteristic(resistanceCharacteristic); + service.addCharacteristic(accelerationCharacteristic); + service.addCharacteristic(gyroscopeCharacteristic); + service.addCharacteristic(magneticFieldCharacteristic); + + BLE.addService(service); + + BLE.advertise(); + imuTime = millis(); +} + +void loop() { + lastNotify = 0; + + while (BLE.connected()) { + if (ledCharacteristic.written()) { + analogWrite(LED_PIN, ledCharacteristic.value()); + } + + if (ouput1Characteristic.written()) { + analogWrite(OUTPUT1_PIN, ouput1Characteristic.value()); + } + + if (ouput2Characteristic.written()) { + analogWrite(OUTPUT2_PIN, ouput2Characteristic.value()); + } + + unsigned long now = millis(); + + if (abs((long)now - (long)lastNotify) >= 100) { + lastNotify = now; + + // every 100ms update subscribed characteristics + updateSubscribedCharacteristics(); + } + + updateSubscribedIMUCharacteristics(); + } +} + +void updateSubscribedCharacteristics() { + if (input1Characteristic.subscribed()) { + input1Characteristic.writeValue(analogReadAverage(INPUT1_PIN, 30)); + } + + if (input2Characteristic.subscribed()) { + input2Characteristic.writeValue(analogReadAverage(INPUT2_PIN, 30)); + } + + if (input3Characteristic.subscribed()) { + input3Characteristic.writeValue(analogReadAverage(INPUT3_PIN, 30)); + } + + if (voltageCharacteristic.subscribed()) { + float voltage = INA226.readBusVoltage(); + + voltageCharacteristic.writeValue(voltage); + } + + if (currentCharacteristic.subscribed()) { + float current = INA226.readCurrent(); + + currentCharacteristic.writeValue(current); + } + + if (resistanceCharacteristic.subscribed()) { + float Vout = 0; + float resistanceAuxLow = INFINITY; + float resistanceAuxHigh = INFINITY; + float resistanceAvg = INFINITY; //open circuit as default + + digitalWrite(RESISTANCE_AUX_PIN, LOW); + Vout = getVoutAverage(); + if ((Vout >= 0.1) && (Vout <= 3.0)) { + resistanceAuxLow = RESISTOR_AUX_LOW * ((3.3 / Vout) - 1); + } + + digitalWrite(RESISTANCE_AUX_PIN, HIGH); + Vout = getVoutAverage(); + if (Vout >= 0.1) { + resistanceAuxHigh = RESISTOR_AUX_HIGH * ((3.3 / Vout) - 1); + } + +#ifdef DEBUG + Serial.print("Resistance (HIGH): "); + Serial.print(resistanceAuxHigh); + Serial.println(" Ohm"); + + Serial.print("Resistance (LOW): "); + Serial.print(resistanceAuxLow); + Serial.println(" Ohm"); +#endif + + if ((resistanceAuxHigh != INFINITY) && (resistanceAuxLow != INFINITY)) { + resistanceAvg = (resistanceAuxHigh + resistanceAuxLow) / 2; + } else if ((resistanceAuxHigh != INFINITY) && (resistanceAuxLow == INFINITY)) { + resistanceAvg = resistanceAuxHigh; + } else if ((resistanceAuxHigh == INFINITY) && (resistanceAuxLow != INFINITY)) { + resistanceAvg = resistanceAuxLow; + } + resistanceAvg += 0.025 * resistanceAvg; + +#ifdef DEBUG + Serial.print("Resistance (AVG): "); + Serial.print(resistanceAvg); + Serial.println(" Ohm"); +#endif + resistanceCharacteristic.writeValue(resistanceAvg); + } +} + +float getVoutAverage() { + float Vout = 0; + for (int i = 0; i < 30; i++) { + Vout += (analogRead(RESISTANCE_PIN) * 3.30) / 1023.0; + } + Vout /= 30; + +#ifdef DEBUG + Serial.print("Vout: "); + Serial.print(Vout); + Serial.println("V"); +#endif + return Vout; +} + +int analogReadAverage(int pin, int numberOfSamples) { + int averageValue = 0; + for (int i = 0; i < numberOfSamples; i++) { + averageValue += analogRead(pin); + } + + return (averageValue / numberOfSamples); +} + +void updateSubscribedIMUCharacteristics() { + if (millis() - imuTime > IMU_UPDATE_TIME) { + imuTime = millis(); + imu.read(); + sensors_event_t a, m, g, temp; + imu.getEvent(&a, &m, &g, &temp); + + if (accelerationCharacteristic.subscribed()) { + float acceleration[3]; + + acceleration[0] = a.acceleration.x; + acceleration[1] = a.acceleration.y; + acceleration[2] = a.acceleration.z/10; + accelerationCharacteristic.writeValue((byte*)acceleration, sizeof(acceleration)); + } + + if (gyroscopeCharacteristic.subscribed()) { + float gyroscope[3]; + + gyroscope[0] = g.gyro.x; + gyroscope[1] = g.gyro.y; + gyroscope[2] = g.gyro.z; + gyroscopeCharacteristic.writeValue((byte*)gyroscope, sizeof(gyroscope)); + } + + if (magneticFieldCharacteristic.subscribed()) { + float magneticField[3]; + + magneticField[0] = m.magnetic.x; + magneticField[1] = m.magnetic.y; + magneticField[2] = m.magnetic.z; + magneticFieldCharacteristic.writeValue((byte*)magneticField, sizeof(magneticField)); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/RP2040ConnectFirmware/RP2040ConnectFirmware.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/RP2040ConnectFirmware/RP2040ConnectFirmware.ino new file mode 100644 index 00000000..c3768dad --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_ScienceJournal/examples/RP2040ConnectFirmware/RP2040ConnectFirmware.ino @@ -0,0 +1,178 @@ +#include +#include + +#include + +const int VERSION = 0x00000001; + +#define SCIENCE_KIT_UUID(val) ("555a0002-" val "-467a-9538-01f0652c74e8") +#define RESISTANCE_PIN A0 +#define VOLTAGE_BUFFER_SIZE 16 + +//#define DEBUG 0 + +BLEService service (SCIENCE_KIT_UUID("0000")); +BLEUnsignedIntCharacteristic versionCharacteristic (SCIENCE_KIT_UUID("0001"), BLERead); +BLECharacteristic accelerationCharacteristic (SCIENCE_KIT_UUID("0011"), BLENotify, 3 * sizeof(float)); +BLECharacteristic gyroscopeCharacteristic (SCIENCE_KIT_UUID("0012"), BLENotify, 3 * sizeof(float)); +BLEUnsignedShortCharacteristic soundPressureCharacteristic(SCIENCE_KIT_UUID("0019"), BLENotify); +BLEFloatCharacteristic resistanceCharacteristic (SCIENCE_KIT_UUID("0020"), BLENotify); + +byte voltageBufferIndex = 0; +bool voltageBufferFilled = false; +short soundSampleBuffer[256]; +short voltageSampleBuffer[VOLTAGE_BUFFER_SIZE]; + +void onPDMdata() { + // query the number of bytes available + int bytesAvailable = PDM.available(); + + // read into the sample buffer + PDM.read(soundSampleBuffer, bytesAvailable); +} + +uint16_t getSoundAverage() { + uint32_t avg = 0; + for (int i = 0; i < sizeof(soundSampleBuffer)/sizeof(soundSampleBuffer[0]); i++) { + avg += soundSampleBuffer[i]*soundSampleBuffer[i]; + } + return sqrt(avg); +} + +void readVoltage() { + voltageSampleBuffer[voltageBufferIndex] = analogRead(RESISTANCE_PIN); + if (!voltageBufferFilled && voltageBufferIndex == VOLTAGE_BUFFER_SIZE - 1) { + voltageBufferFilled = true; + } + voltageBufferIndex = (++voltageBufferIndex) % VOLTAGE_BUFFER_SIZE; +} + +uint16_t getVoltageAverage() { + uint16_t avg = 0; + byte upperBound = voltageBufferFilled ? VOLTAGE_BUFFER_SIZE : voltageBufferIndex; + for (int i = 0; i < upperBound; i++) { + avg += voltageSampleBuffer[i]; + } + return avg / upperBound; +} + +// String to calculate the local and device name +String name; +unsigned long lastNotify = 0; + +void printSerialMsg(const char * msg) { + #ifdef DEBUG + if (Serial) { + Serial.println(msg); + } + #endif +} + +void blinkLoop() { + while (1) { + digitalWrite(LED_BUILTIN, HIGH); + delay(500); + digitalWrite(LED_BUILTIN, LOW); + delay(500); + } +} + +void setup() { + #ifdef DEBUG + Serial.begin(9600); + while (!Serial); + Serial.println("Started"); + #endif + + delay(2000); + + pinMode(RESISTANCE_PIN, INPUT); // Used for reading resistance + + if (!IMU.begin()) { + printSerialMsg("Failed to initialize IMU!"); + blinkLoop(); + } + + PDM.onReceive(onPDMdata); + if (!PDM.begin(1, 16000)) { + printSerialMsg("Failed to start PDM!"); + blinkLoop(); + } + + if (!BLE.begin()) { + printSerialMsg("Failed to initialize BLE!"); + blinkLoop(); + } + + String address = BLE.address(); + #ifdef DEBUG + if (Serial) { + Serial.print("address = "); + Serial.println(address); + } + #endif + address.toUpperCase(); + + name = "BLE Sense - "; + name += address[address.length() - 5]; + name += address[address.length() - 4]; + name += address[address.length() - 2]; + name += address[address.length() - 1]; + + #ifdef DEBUG + if (Serial) { + Serial.print("name = "); + Serial.println(name); + } + #endif + + BLE.setLocalName(name.c_str()); + BLE.setDeviceName(name.c_str()); + BLE.setAdvertisedService(service); + + service.addCharacteristic(versionCharacteristic); + service.addCharacteristic(accelerationCharacteristic); + service.addCharacteristic(gyroscopeCharacteristic); + service.addCharacteristic(soundPressureCharacteristic); + service.addCharacteristic(resistanceCharacteristic); + + versionCharacteristic.setValue(VERSION); + + BLE.addService(service); + BLE.advertise(); +} + +void loop() { + BLE.poll(1000); + while (BLE.connected()) { + updateSubscribedCharacteristics(); + } +} + +void updateSubscribedCharacteristics() { + if (accelerationCharacteristic.subscribed()) { + float acceleration[3]; + if (IMU.accelerationAvailable() && IMU.readAcceleration(acceleration[0], acceleration[1], acceleration[2])) { + accelerationCharacteristic.writeValue((byte*)acceleration, sizeof(acceleration)); + } + } + + if (gyroscopeCharacteristic.subscribed()) { + float gyroscope[3]; + if (IMU.gyroscopeAvailable() && IMU.readGyroscope(gyroscope[0], gyroscope[1], gyroscope[2])) { + gyroscopeCharacteristic.writeValue((byte*)gyroscope, sizeof(gyroscope)); + } + } + + if (soundPressureCharacteristic.subscribed()) { + uint16_t sound = getSoundAverage(); + soundPressureCharacteristic.writeValue(sound); + } + + if(resistanceCharacteristic.subscribed()){ + readVoltage(); + uint16_t measuredValue = getVoltageAverage(); + float voltageRatio = 1024.0f / measuredValue; + resistanceCharacteristic.writeValue(voltageRatio); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/README.md new file mode 100644 index 00000000..5b53668d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/README.md @@ -0,0 +1,14 @@ +# Arduino SensorKit Library + +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_SensorKit/actions/workflows/spell-check.yml) + +This documentation contains information about the classes and the usage of Arduino_SensorKit library which is primarily used in the [Arduino Sensor Kit](https://store.arduino.cc/sensor-kit-base). This library is a wrapper for other libraries such as + +* [U8g2_Arduino](https://github.com/olikraus/U8g2_Arduino) Library for monochrome displays +* [Seeed_Arduino_LIS3DHTR](https://github.com/Seeed-Studio/Seeed_Arduino_LIS3DHTR) for the 3 Axis Accelerometer +* [Grove_BMP280](https://github.com/Seeed-Studio/Grove_BMP280) Library for the Barometer +* [DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library) for the Temperature and Humidity Sensor + +The Arduino_SensorKit Library can be downloaded from the Arduino IDE's library manager or from the GitHub repository. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Accelerometer/Accelerometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Accelerometer/Accelerometer.ino new file mode 100644 index 00000000..4a178e2f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Accelerometer/Accelerometer.ino @@ -0,0 +1,24 @@ +#include "Arduino_SensorKit.h" + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while(!Serial); + + Accelerometer.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + // 3 axis + Serial.print("x:"); + Serial.print(Accelerometer.readX()); + Serial.print(" "); + Serial.print("y:"); + Serial.print(Accelerometer.readY()); + Serial.print(" "); + Serial.print("z:"); + Serial.println(Accelerometer.readZ()); + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Combined_Demo/Combined_Demo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Combined_Demo/Combined_Demo.ino new file mode 100644 index 00000000..464e270e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Combined_Demo/Combined_Demo.ino @@ -0,0 +1,102 @@ +// Combined Demo by Marc MERLIN +// Reviewed by Pablo Marquínez +// This demo uses all the devices from the Arduino Sensor Kit +// Showing the values on the Display + +#include "Arduino_SensorKit.h" + +#define BUZZER 5 +#define BUTTON 4 +#define LED 6 +#define POT A0 +#define MIC A2 +#define LIGHT A3 + +int pot_value; +bool button_state; +int mic_value; +int light_value; + +void setup() { + Serial.begin(9600); + + pinMode(MIC , INPUT); + pinMode(LIGHT , INPUT); + pinMode(BUTTON , INPUT); + + pinMode(LED, OUTPUT); + digitalWrite(LED, LOW); + pinMode(BUZZER, OUTPUT); + + Environment.begin(); + + Oled.begin(); + Oled.setFlipMode(true); + + Accelerometer.begin(); + Pressure.begin(); +} + +void loop() { + Oled.setFont(u8x8_font_amstrad_cpc_extended_r); + + //cursor values are in characters, not pixels + Oled.setCursor(0, 4); + + // If accelerometer and altimeter are queried too close to one another + // this causes a hang, so we read this first. + Oled.print("x:"); + Oled.print(Accelerometer.readX()); + Oled.print(" y:"); + Oled.print(Accelerometer.readY()); + Oled.setCursor(0, 5); + Oled.print("z:"); + Oled.print(Accelerometer.readZ()); + Oled.print(" T:"); + Oled.print(Environment.readTemperature()); + Oled.print("C"); + + Oled.setCursor(0, 0); + Oled.print("But:"); + + pot_value = analogRead(POT); + + button_state = digitalRead(BUTTON); + Oled.print(button_state); + + if (button_state == true) { + digitalWrite(LED, HIGH); + tone(BUZZER, pot_value); + } else { + digitalWrite(LED, LOW); + noTone(BUZZER); + } + + Oled.setCursor(0, 1); + Oled.print("BuzPot: "); + Oled.print(pot_value); + Oled.print("Hz "); + + mic_value = analogRead(MIC); + Oled.setCursor(0, 2); + Oled.print("Mic: "); + Oled.print(mic_value); + Oled.print(" "); + + light_value = analogRead(LIGHT); + Oled.setCursor(0, 3); + Oled.print("Light: "); + Oled.print(light_value); + Oled.print(" "); + + Oled.setCursor(0, 6); + Oled.print("Hum: "); + Oled.print(Environment.readHumidity()); + Oled.print("%"); + + Oled.setCursor(0, 7); + Oled.print("Alt:"); + Oled.print(Pressure.readAltitude()); + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Oled_Display/Oled_Display.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Oled_Display/Oled_Display.ino new file mode 100644 index 00000000..f980c899 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Oled_Display/Oled_Display.ino @@ -0,0 +1,16 @@ +#include "Arduino_SensorKit.h" + +void setup() { + Oled.begin(); + Oled.setFlipMode(true); +} + +void loop() { + int random_value = random(0, 1023); // create a random value + + Oled.setFont(u8x8_font_chroma48medium8_r); + Oled.setCursor(0, 3); + Oled.print("Value: "); + Oled.print(random_value); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Plug_Sketch_Play/Plug_Sketch_Play.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Plug_Sketch_Play/Plug_Sketch_Play.ino new file mode 100644 index 00000000..e6db3c43 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Plug_Sketch_Play/Plug_Sketch_Play.ino @@ -0,0 +1,24 @@ +#include "Arduino_SensorKit.h" + +int button = 4; +int LED = 6; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + while (!Serial); + + pinMode(button , INPUT); + pinMode(LED, OUTPUT); + + digitalWrite(LED, LOW); +} + +void loop() { + // put your main code here, to run repeatedly: + if (digitalRead(button)) { + digitalWrite(LED, HIGH); + } else { + digitalWrite(LED, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Pressure_Sensor/Pressure_Sensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Pressure_Sensor/Pressure_Sensor.ino new file mode 100644 index 00000000..1279cb48 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Pressure_Sensor/Pressure_Sensor.ino @@ -0,0 +1,27 @@ +#include "Arduino_SensorKit.h" + +void setup() { + Serial.begin(9600); + Pressure.begin(); +} + +void loop() { + // Get and print temperatures + Serial.print("Temp: "); + Serial.print(Pressure.readTemperature()); + Serial.println("C"); // The unit for Celsius because original Arduino don't support special symbols + + // Get and print atmospheric pressure data + Serial.print("Pressure: "); + Serial.print(Pressure.readPressure()); + Serial.println("Pa"); + + // Get and print altitude data + Serial.print("Altitude: "); + Serial.print(Pressure.readAltitude()); + Serial.println("m"); + + Serial.println("\n");//add a line between output of different times. + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Temp_and_Humidity/Temp_and_Humidity.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Temp_and_Humidity/Temp_and_Humidity.ino new file mode 100644 index 00000000..ae7a742f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_SensorKit/examples/Temp_and_Humidity/Temp_and_Humidity.ino @@ -0,0 +1,17 @@ +//#define DHTPIN 3 // By default its connected to pin D3, it can be changed, define it before the #include of the library +#include "Arduino_SensorKit.h" + +void setup() { + Serial.begin(9600); + Environment.begin(); +} + +void loop() { + Serial.print("Temperature = "); + Serial.print(Environment.readTemperature()); //print temperature + Serial.println(" C"); + Serial.print("Humidity = "); + Serial.print(Environment.readHumidity()); //print humidity + Serial.println(" %"); + delay(2000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/LICENSE new file mode 100644 index 00000000..b4e6b5f5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + This library enables threadsafe peripheral IO access via pipes. + Copyright (C) 2021 Alexander Entinger / Arduino + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/README.md new file mode 100644 index 00000000..ca585ae0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/README.md @@ -0,0 +1,82 @@ + + +`Arduino_Threads` +================= +*Note: This library is currently in [beta](#zap-caveats).* + +[![Compile Examples status](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/compile-examples.yml) +[![Check Arduino status](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/check-arduino.yml) +[![Spell Check status](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Threads/actions/workflows/spell-check.yml) + +This library makes it easy to use the multi-threading capability of [Arduino](https://www.arduino.cc/) boards that use an [Mbed OS](https://os.mbed.com/docs/mbed-os/latest/introduction/index.html)-based core library. Additionally this library provides thread-safe access to `Wire`, `SPI` and `Serial` which is relevant when creating multi-threaded sketches in order to avoid common pitfalls such as race-conditions and invalid state. ​ + +Preeliminary **documentation** and download links for **required tooling** are available within the [`/docs`](docs/README.md) subfolder. + +## :star: Features +### :thread: Multi-threaded sketch execution +Instead of one big state-machine-of-doom you can split your application into multiple independent threads, each with it's own `setup()` and `loop()` function. Instead of implementing your application in a single `.ino` file, each independent thread is implemented in a dedicated `.inot` file (t suffix stands for **t**hread) representing a clear separation of concerns on a file level. + +### :calling: Easy communication between multiple threads +Easy inter-thread-communication is facilitated via a `Shared` abstraction object providing thread-safe sink/source semantics allowing to safely exchange data of any type between threads. + +### :shield: Thread-safe I/O +A key problem of multi-tasking is the **prevention of erroneous state when multiple threads share a single resource**. The following example borrowed from a typical application demonstrates the problems resulting from multiple threads accessing a single resource: + +Imagine an embedded system where multiple `Wire` client devices are physically connected to a single `Wire` server. Each `Wire` client device is managed by a separate software thread. Each thread polls its `Wire` client device periodically. Access to the I2C bus is managed via the `Wire` library and typically follows this pattern: + +```C++ +/* Wire Write Access */ +Wire.beginTransmission(address); +Wire.write(value); +// Interrupting the current thread e.g. at this point can lead to an erroneous state +// if another thread performs Wire I/O before the transmission ends. +Wire.endTransmission(); + +/* Wire Read Access */ +Wire.requestFrom(address, bytes) +while(Wire.available()) { + int value = Wire.read(); +} +``` + +Since we are using [ARM Mbed OS](https://os.mbed.com/mbed-os/) which is a [preemptive](https://en.wikipedia.org/wiki/Preemption_(computing)) [RTOS](https://en.wikipedia.org/wiki/Real-time_operating_system) for achieving multi-tasking capability and under the assumption that all threads share the same priority (which leads to a [round-robin](https://en.wikipedia.org/wiki/Round-robin_scheduling) scheduling) it can easily happen that one thread is half-way through its Wire I/O access when the scheduler interrupts its execution and schedules the next thread which in turn starts, continues or ends its own Wire I/O access. + +As a result this interruption by the scheduler will break Wire I/O access for both devices and leave the Wire I/O controller in an undefined state :fire:. + +`Arduino_Threads` solves this problem by encapsulating the complete I/O access (e.g. reading from a `Wire` client device) within a single function call which generates an I/O request to be asynchronously executed by a high-priority I/O thread. The high-priority I/O thread is the **only** instance which directly communicates with physical hardware. + +### :runner: Asynchronous +The mechanisms implemented in this library allow any thread to dispatch an I/O request asynchronously and either continue its operation or [yield](https://en.wikipedia.org/wiki/Yield_(multithreading)) control to the next scheduled thread. All I/O requests are stored in a queue and are executed within a high-priority I/O thread after a [context-switch](https://en.wikipedia.org/wiki/Context_switch). An example of this can be seen [here](examples/Threadsafe_IO/Threadsafe_SPI/Threadsafe_SPI.ino). + +### :relieved: Convenient API +Although you are free to directly manipulate I/O requests and responses (e.g. [Threadsafe_Wire](examples/Threadsafe_IO/Threadsafe_Wire/Threadsafe_Wire.ino)) there are convenient `read`/`write`/`writeThenRead` abstractions inspired by the [Adafruit_BusIO](https://github.com/adafruit/Adafruit_BusIO) library (e.g. [Threadsafe_Wire_BusIO](examples/Threadsafe_IO/Threadsafe_Wire_BusIO/Threadsafe_Wire_BusIO.ino)). + +## :zap: Caveats + +This library is currently in **BETA** phase. This means that neither the API nor the usage patterns are set in stone and are likely to change. We are publishing this library in the full knowledge that we can't foresee every possible use-case and edge-case. Therefore we would like to treat this library, while it's in beta phase, as an experiment and ask for your input for shaping this library. Please help us by providing feedback in the [issues section](https://github.com/bcmi-labs/Arduino_Threads/issues) or participating in our [discussions](https://github.com/arduino/language/discussions). + +## :mag_right: Resources + +* [How to install a library](https://www.arduino.cc/en/guide/libraries) +* [Help Center](https://support.arduino.cc/) - Get help from Arduino's official support team +* [Forum](https://forum.arduino.cc) - Get support from the community + +## :bug: Bugs & Issues + +If you found an issue in this library, you can submit it to the [issue tracker](issues) of this repository. Remember to include as much detail as you can about your hardware set-up, code and steps for reproducing the issue. To prevent hardware related incompatibilities make sure to use an [original Arduino board](https://support.arduino.cc/hc/en-us/articles/360020652100-How-to-spot-a-counterfeit-Arduino). + +## :technologist: Contribute + +There are many ways to contribute: + +* Improve documentation and examples +* Fix a bug +* Test open Pull Requests +* Implement a new feature +* Discuss potential ways to improve this library + +You can submit your patches directly to this repository as Pull Requests. Please provide a detailed description of the problem you're trying to solve and make sure you test on real hardware. + +## :yellow_heart: Donations + +This open-source code is maintained by Arduino with the help of the community. We invest a considerable amount of time in testing code, optimizing it and introducing new features. Please consider [donating](https://www.arduino.cc/en/donate/) or [sponsoring](https://github.com/sponsors/arduino) to support our work, as well as [buying original Arduino boards](https://store.arduino.cc/) which is the best way to make sure our effort can continue in the long term. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Consumer.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Consumer.inot new file mode 100644 index 00000000..c6a89fd0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Consumer.inot @@ -0,0 +1,16 @@ +void setup() +{ + Serial.begin(9600); + while(!Serial) { } +} + +void loop() +{ + /* If a value is available for reading within the internal + * queue then the value is removed from the queue and made + * available to the calling function. Should no data be + * available, then this thread is suspended until new data + * is available for reading. + */ + Serial.println(counter.pop()); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Producer.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Producer.inot new file mode 100644 index 00000000..59578d4a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Producer.inot @@ -0,0 +1,16 @@ +void setup() +{ + +} + +void loop() +{ + static int i = 0; + /* Every 100 ms a new value is inserted into the shared variable + * 'counter'. Internally this is stored within a queue in a FIFO + * (First-In/First-Out) manner. + */ + counter.push(i); + i++; + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/SharedVariables.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/SharedVariables.h new file mode 100644 index 00000000..7cc8c0c0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/SharedVariables.h @@ -0,0 +1,2 @@ +/* Define a shared variable named 'counter' of type 'int'. */ +SHARED(counter, int); diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Shared_Counter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Shared_Counter.ino new file mode 100644 index 00000000..87f7007d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Shared_Counter/Shared_Counter.ino @@ -0,0 +1,15 @@ +/* This example demonstrates data exchange between + * threads using a shared counter variable defined + * within 'SharedVariables.h'. + */ + +void setup() +{ + Producer.start(); + Consumer.start(); +} + +void loop() +{ + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Consumer.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Consumer.inot new file mode 100644 index 00000000..21aafec6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Consumer.inot @@ -0,0 +1,13 @@ +/* Define a data sink named 'counter' of type 'int' with a internal queue size of 10. */ +SINK(counter, int, 10); + +void setup() +{ + Serial.begin(9600); + while(!Serial) { } +} + +void loop() +{ + Serial.println(counter.pop()); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Producer.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Producer.inot new file mode 100644 index 00000000..c359c401 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Producer.inot @@ -0,0 +1,14 @@ +/* Define a data source named 'counter' of type 'int'. */ +SOURCE(counter, int); + +void setup() +{ + +} + +void loop() +{ + static int i = 0; + counter.push(i); + i++; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/SharedVariables.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Source_Sink_Counter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Source_Sink_Counter.ino new file mode 100644 index 00000000..f237bb21 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_Counter/Source_Sink_Counter.ino @@ -0,0 +1,16 @@ +/* This examples demonstrates the SOURCE/SINK abstraction. Each thread + * may have any number of SOURCES and SINKS that can be connected + * together using the 'connectTo' method. + */ + +void setup() +{ + Producer.counter.connectTo(Consumer.counter); + Producer.start(); + Consumer.start(); +} + +void loop() +{ + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/SharedVariables.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Sink_Thread.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Sink_Thread.inot new file mode 100644 index 00000000..e4dd9756 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Sink_Thread.inot @@ -0,0 +1,16 @@ +/* Define a data sink named 'led' of type 'bool' with a internal queue size of 1. */ +SINK(led, bool); + +void setup() +{ + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() +{ + /* Read a 'bool' value from the SINK and discard it. Since there is no delay in the loop + * this call will block until new data is inserted from the connected SOURCE. This means + * that the pace is dictated by the SOURCE that sends data every 100 ms. + */ + digitalWrite(LED_BUILTIN, led.pop()); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Sink_LED.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Sink_LED.ino new file mode 100644 index 00000000..c0e94be2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Sink_LED.ino @@ -0,0 +1,16 @@ +/* This examples demonstrates the SOURCE/SINK abstraction. Each thread + * may have any number of SOURCES and SINKS that can be connected + * together using the 'connectTo' method. + */ + +void setup() +{ + Source_Thread.led.connectTo(Sink_Thread.led); + Sink_Thread.start(); + Source_Thread.start(); +} + +void loop() +{ + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Thread.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Thread.inot new file mode 100644 index 00000000..dc8f864f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threading_Basics/Source_Sink_LED/Source_Thread.inot @@ -0,0 +1,15 @@ +/* Define a data source named 'led' of type 'bool'. */ +SOURCE(led, bool); + +void setup() +{ + +} + +void loop() +{ + led.push(true); + delay(100); + led.push(false); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI/SPI.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI/SPI.ino new file mode 100644 index 00000000..b4b6ae11 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI/SPI.ino @@ -0,0 +1,94 @@ +/* This example demonstrates how multiple threads can communicate + * with a single SPI client device using the BusDevice abstraction + * for SPI. In a similar way multiple threads can interface + * with different client devices on the same SPI bus. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static int const BMP388_CS_PIN = 2; +static int const BMP388_INT_PIN = 6; +static byte const BMP388_CHIP_ID_REG_ADDR = 0x00; + +static size_t constexpr NUM_THREADS = 20; + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +byte bmp388_read_reg(byte const reg_addr); +void bmp388_thread_func(); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice bmp388(SPI, BMP388_CS_PIN, 1000000, MSBFIRST, SPI_MODE0); + +static char thread_name[NUM_THREADS][32]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + while (!Serial) { } + + pinMode(BMP388_CS_PIN, OUTPUT); + digitalWrite(BMP388_CS_PIN, HIGH); + + for(size_t i = 0; i < NUM_THREADS; i++) + { + snprintf(thread_name[i], sizeof(thread_name[i]), "Thread #%02d", i); + rtos::Thread * t = new rtos::Thread(osPriorityNormal, OS_STACK_SIZE, nullptr, thread_name[i]); + t->start(bmp388_thread_func); + } +} + +void loop() +{ + +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +byte bmp388_read_reg(byte const reg_addr) +{ + /* REG_ADDR | DUMMY_BYTE | REG_VAL is on SDO */ + byte read_write_buf[] = {static_cast(0x80 | reg_addr), 0, 0}; + + IoRequest req(read_write_buf, sizeof(read_write_buf), nullptr, 0); + IoResponse rsp = transferAndWait(bmp388, req); + + return read_write_buf[2]; +} + +void bmp388_thread_func() +{ + Serial.begin(9600); + while(!Serial) { } + + for(;;) + { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5,500))); + /* Try to read some data from the BMP3888. */ + byte const chip_id = bmp388_read_reg(BMP388_CHIP_ID_REG_ADDR); + /* Print thread id and chip id value to serial. */ + char msg[64] = {0}; + snprintf(msg, sizeof(msg), "%s: Chip ID = 0x%X", rtos::ThisThread::get_name(), chip_id); + Serial.println(msg); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI_BusIO/SPI_BusIO.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI_BusIO/SPI_BusIO.ino new file mode 100644 index 00000000..d5b26481 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/SPI_BusIO/SPI_BusIO.ino @@ -0,0 +1,93 @@ +/* This example demonstrates how multiple threads can communicate + * with a single SPI client device using the BusDevice abstraction + * for SPI. In a similar way multiple threads can interface + * with different client devices on the same SPI bus. + * + * This example uses Adafruit_BusIO style read(), write(), + * writeThenRead() APIs. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static int const BMP388_CS_PIN = 2; +static int const BMP388_INT_PIN = 6; +static byte const BMP388_CHIP_ID_REG_ADDR = 0x00; + +static size_t constexpr NUM_THREADS = 20; + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +byte bmp388_read_reg(byte const reg_addr); +void bmp388_thread_func(); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice bmp388(SPI, BMP388_CS_PIN, 1000000, MSBFIRST, SPI_MODE0); + +static char thread_name[NUM_THREADS][32]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + pinMode(BMP388_CS_PIN, OUTPUT); + digitalWrite(BMP388_CS_PIN, HIGH); + + for(size_t i = 0; i < NUM_THREADS; i++) + { + snprintf(thread_name[i], sizeof(thread_name[i]), "Thread #%02d", i); + rtos::Thread * t = new rtos::Thread(osPriorityNormal, OS_STACK_SIZE, nullptr, thread_name[i]); + t->start(bmp388_thread_func); + } +} + +void loop() +{ + +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +byte bmp388_read_reg(byte const reg_addr) +{ + /* REG_ADDR | DUMMY_BYTE | REG_VAL is on SDO */ + byte write_buf[2] = {static_cast(0x80 | reg_addr), 0}; + byte read_buf = 0; + + bmp388.spi().writeThenRead(write_buf, sizeof(write_buf), &read_buf, sizeof(read_buf)); + return read_buf; +} + +void bmp388_thread_func() +{ + Serial.begin(9600); + while(!Serial) { } + + for(;;) + { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5,500))); + /* Try to read some data from the BMP3888. */ + byte const chip_id = bmp388_read_reg(BMP388_CHIP_ID_REG_ADDR); + /* Print thread id and chip id value to serial. */ + char msg[64] = {0}; + snprintf(msg, sizeof(msg), "%s: Chip ID = 0x%X", rtos::ThisThread::get_name(), chip_id); + Serial.println(msg); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Serial_GlobalPrefixSuffix.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Serial_GlobalPrefixSuffix.ino new file mode 100644 index 00000000..9c3328a1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Serial_GlobalPrefixSuffix.ino @@ -0,0 +1,58 @@ +/* This example demonstrates how every Serial message can be prefixed + * as well as suffixed by a user-configurable message. In this example + * this functionality is used for appending the current timestamp and + * prepending a line feed. Other uses might be to prepend the thread + * from which a given serial message is originating. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +String serial_log_message_prefix(String const & /* msg */); +String serial_log_message_suffix(String const & prefix, String const & msg); + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + while (!Serial) { } + + Serial.globalPrefix(serial_log_message_prefix); + Serial.globalSuffix(serial_log_message_suffix); + + Thread_1.start(); + Thread_2.start(); + Thread_3.start(); +} + +void loop() +{ + Serial.block(); + Serial.println("Thread #0: Lorem ipsum ..."); + Serial.unblock(); +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +String serial_log_message_prefix(String const & /* msg */) +{ + char msg[32] = {0}; + snprintf(msg, sizeof(msg), "[%05lu] ", millis()); + return String(msg); +} + +String serial_log_message_suffix(String const & prefix, String const & msg) +{ + return String("\r\n"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/SharedVariables.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_1.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_1.inot new file mode 100644 index 00000000..3de8ac9a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_1.inot @@ -0,0 +1,11 @@ +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + Serial.block(); + Serial.println("Thread #1: Lorem ipsum ..."); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_2.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_2.inot new file mode 100644 index 00000000..12731f07 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_2.inot @@ -0,0 +1,11 @@ +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + Serial.block(); + Serial.println("Thread #2: Lorem ipsum ..."); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_3.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_3.inot new file mode 100644 index 00000000..eccc6e8d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_GlobalPrefixSuffix/Thread_3.inot @@ -0,0 +1,11 @@ +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + Serial.block(); + Serial.println("Thread #3: Lorem ipsum ..."); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/GPS_Thread.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/GPS_Thread.inot new file mode 100644 index 00000000..85a99a5b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/GPS_Thread.inot @@ -0,0 +1,64 @@ +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +static String nmea_message_prefix(String const & /* msg */) +{ + return String("$"); +} + +static String nmea_message_suffix(String const & prefix, String const & msg) +{ + /* NMEA checksum is calculated over the complete message + * starting with '$' and ending with the end of the message. + */ + byte checksum = 0; + std::for_each(msg.c_str(), + msg.c_str() + msg.length(), + [&checksum](char const c) + { + checksum ^= static_cast(c); + }); + /* Assemble the footer of the NMEA message. */ + char footer[16] = {0}; + snprintf(footer, sizeof(footer), "*%02X\r\n", checksum); + return String(footer); +} + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + + Serial.prefix(nmea_message_prefix); + Serial.suffix(nmea_message_suffix); +} + +void loop() +{ + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5,500))); + + /* Print a fake NMEA GPRMC message: + * $GPRMC,062101.714,A,5001.869,N,01912.114,E,955535.7,116.2,290520,000.0,W*45\r\n + */ + Serial.block(); + + Serial.print("GPRMC,"); + Serial.print(millis()); + Serial.print(",A,"); + Serial.print("5001.869,"); + Serial.print("N,"); + Serial.print("01912.114,"); + Serial.print("E,"); + Serial.print("955535.7,"); + Serial.print("116.2,"); + Serial.print("290520,"); + Serial.print("000.0,"); + Serial.print("W"); + + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/Serial_ProtocolWrapping.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/Serial_ProtocolWrapping.ino new file mode 100644 index 00000000..7faffb02 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/Serial_ProtocolWrapping.ino @@ -0,0 +1,29 @@ +/* This example demonstrates how every Serial message can be prefixed + * as well as suffixed by a user-configurable message. In this example + * this functionality is used for prepending the right header for a + * pseudo NMEA-encoded (think GPS) message as well as for calculating + * and appending the checksum at the end. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + while (!Serial) { } + + GPS_Thread.start(); +} + +void loop() +{ + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/SharedVariables.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_ProtocolWrapping/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Serial_Reader.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Serial_Reader.ino new file mode 100644 index 00000000..16dad9e1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Serial_Reader.ino @@ -0,0 +1,49 @@ +/* This example demonstrates how multiple threads can subscribe to + * reading from the same physical Serial interface. Incoming data + * is copied into per-thread receive buffers so that no thread + * can "steal" data from another thread by reading it first. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + while (!Serial) { } + + Thread_1.start(); + Thread_2.start(); + Thread_3.start(); + + Serial.block(); + Serial.println("Thread #0 started."); + Serial.unblock(); +} + +void loop() +{ + /* Read data from the serial interface into a String. */ + String serial_msg; + while (Serial.available()) + serial_msg += (char)Serial.read(); + + /* Print thread id and chip id value to serial. */ + if (serial_msg.length()) + { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #0: "); + Serial.print(serial_msg); + Serial.println(); + Serial.unblock(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/SharedVariables.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_1.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_1.inot new file mode 100644 index 00000000..04e9bf50 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_1.inot @@ -0,0 +1,28 @@ +void setup() +{ + Serial.begin(9600); + + Serial.block(); + Serial.println("Thread #1 started."); + Serial.unblock(); +} + +void loop() +{ + /* Read data from the serial interface into a String. */ + String serial_msg; + while (Serial.available()) + serial_msg += (char)Serial.read(); + + /* Print thread id and chip id value to serial. */ + if (serial_msg.length()) + { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #1: "); + Serial.print(serial_msg); + Serial.println(); + Serial.unblock(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_2.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_2.inot new file mode 100644 index 00000000..e5940c25 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_2.inot @@ -0,0 +1,28 @@ +void setup() +{ + Serial.begin(9600); + + Serial.block(); + Serial.println("Thread #2 started."); + Serial.unblock(); +} + +void loop() +{ + /* Read data from the serial interface into a String. */ + String serial_msg; + while (Serial.available()) + serial_msg += (char)Serial.read(); + + /* Print thread id and chip id value to serial. */ + if (serial_msg.length()) + { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #2: "); + Serial.print(serial_msg); + Serial.println(); + Serial.unblock(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_3.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_3.inot new file mode 100644 index 00000000..3a21fa22 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Reader/Thread_3.inot @@ -0,0 +1,28 @@ +void setup() +{ + Serial.begin(9600); + + Serial.block(); + Serial.println("Thread #3 started."); + Serial.unblock(); +} + +void loop() +{ + /* Read data from the serial interface into a String. */ + String serial_msg; + while (Serial.available()) + serial_msg += (char)Serial.read(); + + /* Print thread id and chip id value to serial. */ + if (serial_msg.length()) + { + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #3: "); + Serial.print(serial_msg); + Serial.println(); + Serial.unblock(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Serial_Writer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Serial_Writer.ino new file mode 100644 index 00000000..d0194927 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Serial_Writer.ino @@ -0,0 +1,34 @@ +/* This example demonstrates how multiple threads can write to + * the same physical Serial interface without interfering with + * one another. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + Serial.begin(9600); + while (!Serial) { } + + Thread_1.start(); + Thread_2.start(); + Thread_3.start(); +} + +void loop() +{ + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #0: Lorem ipsum ..."); + Serial.println(); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/SharedVariables.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/SharedVariables.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_1.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_1.inot new file mode 100644 index 00000000..71039e45 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_1.inot @@ -0,0 +1,14 @@ +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #1: Lorem ipsum ..."); + Serial.println(); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_2.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_2.inot new file mode 100644 index 00000000..d02c9cdd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_2.inot @@ -0,0 +1,14 @@ +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #2: Lorem ipsum ..."); + Serial.println(); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_3.inot b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_3.inot new file mode 100644 index 00000000..4591cf09 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Serial_Writer/Thread_3.inot @@ -0,0 +1,14 @@ +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + Serial.block(); + Serial.print("["); + Serial.print(millis()); + Serial.print("] Thread #3: Lorem ipsum ..."); + Serial.println(); + Serial.unblock(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire/Wire.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire/Wire.ino new file mode 100644 index 00000000..476b3c5b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire/Wire.ino @@ -0,0 +1,92 @@ +/* This example demonstrates how multiple threads can communicate + * with a single Wire client device using the BusDevice abstraction + * for Wire. In a similar way multiple threads can interface + * with different client devices on the same Wire bus. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static byte constexpr LSM6DSOX_ADDRESS = 0x6A; +static byte constexpr LSM6DSOX_WHO_AM_I_REG = 0x0F; + +static size_t constexpr NUM_THREADS = 20; + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte const reg_addr); +void lsm6dsox_thread_func(); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice lsm6dsox(Wire, LSM6DSOX_ADDRESS); + +static char thread_name[NUM_THREADS][32]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + /* Fire up some threads all accessing the LSM6DSOX */ + for(size_t i = 0; i < NUM_THREADS; i++) + { + snprintf(thread_name[i], sizeof(thread_name[i]), "Thread #%02d", i); + rtos::Thread * t = new rtos::Thread(osPriorityNormal, OS_STACK_SIZE, nullptr, thread_name[i]); + t->start(lsm6dsox_thread_func); + } +} + +void loop() +{ + +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte const reg_addr) +{ + /* As we need only 1 byte large write/read buffers for this IO transaction + * the buffers are not arrays but rather simple variables. + */ + byte write_buf = reg_addr; + byte read_buf = 0; + + IoRequest req(write_buf, read_buf); + IoResponse rsp = transferAndWait(lsm6dsox, req); + + return read_buf; +} + + +void lsm6dsox_thread_func() +{ + Serial.begin(9600); + while(!Serial) { } + + for(;;) + { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5,500))); + /* Try to read some data from the LSM6DSOX. */ + byte const who_am_i = lsm6dsox_read_reg(LSM6DSOX_WHO_AM_I_REG); + /* Print thread id and chip id value to serial. */ + char msg[64] = {0}; + snprintf(msg, sizeof(msg), "%s: LSM6DSOX[WHO_AM_I] = 0x%X", rtos::ThisThread::get_name(), who_am_i); + Serial.println(msg); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire_BusIO/Wire_BusIO.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire_BusIO/Wire_BusIO.ino new file mode 100644 index 00000000..ec669f52 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Arduino_Threads/examples/Threadsafe_IO/Wire_BusIO/Wire_BusIO.ino @@ -0,0 +1,87 @@ +/* This example demonstrates how multiple threads can communicate + * with a single Wire client device using the BusDevice abstraction + * for Wire. In a similar way multiple threads can interface + * with different client devices on the same Wire bus. + * + * This example uses Adafruit_BusIO style read(), write(), + * writeThenRead() APIs. + */ + +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static byte constexpr LSM6DSOX_ADDRESS = 0x6A; +static byte constexpr LSM6DSOX_WHO_AM_I_REG = 0x0F; + +static size_t constexpr NUM_THREADS = 20; + +/************************************************************************************** + * FUNCTION DECLARATION + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte const reg_addr); +void lsm6dsox_thread_func(); + +/************************************************************************************** + * GLOBAL VARIABLES + **************************************************************************************/ + +BusDevice lsm6dsox(Wire, LSM6DSOX_ADDRESS); + +static char thread_name[NUM_THREADS][32]; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() +{ + /* Fire up some threads all accessing the LSM6DSOX */ + for(size_t i = 0; i < NUM_THREADS; i++) + { + snprintf(thread_name[i], sizeof(thread_name[i]), "Thread #%02d", i); + rtos::Thread * t = new rtos::Thread(osPriorityNormal, OS_STACK_SIZE, nullptr, thread_name[i]); + t->start(lsm6dsox_thread_func); + } +} + +void loop() +{ + +} + +/************************************************************************************** + * FUNCTION DEFINITION + **************************************************************************************/ + +byte lsm6dsox_read_reg(byte reg_addr) +{ + byte read_buf = 0; + lsm6dsox.wire().writeThenRead(®_addr, 1, &read_buf, 1); + return read_buf; +} + +void lsm6dsox_thread_func() +{ + Serial.begin(9600); + while(!Serial) { } + + for(;;) + { + /* Sleep between 5 and 500 ms */ + rtos::ThisThread::sleep_for(rtos::Kernel::Clock::duration_u32(random(5,500))); + /* Try to read some data from the LSM6DSOX. */ + byte const who_am_i = lsm6dsox_read_reg(LSM6DSOX_WHO_AM_I_REG); + /* Print thread id and chip id value to serial. */ + char msg[64] = {0}; + snprintf(msg, sizeof(msg), "%s: LSM6DSOX[WHO_AM_I] = 0x%X", rtos::ThisThread::get_name(), who_am_i); + Serial.println(msg); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/README.adoc new file mode 100644 index 00000000..950fff1a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: Audio + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The Audio library enables an Arduino Due board to play back .wav files from a storage device like an SD card. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino new file mode 100644 index 00000000..da825f1f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Audio/examples/SimpleAudioPlayer/SimpleAudioPlayer.ino @@ -0,0 +1,81 @@ +/* + Simple Audio Player + + Demonstrates the use of the Audio library for the Arduino Due + + Hardware required : + * Arduino shield with a SD card on CS4 + * A sound file named "test.wav" in the root directory of the SD card + * An audio amplifier to connect to the DAC0 and ground + * A speaker to connect to the audio amplifier + + Original by Massimo Banzi September 20, 2012 + Modified by Scott Fitzgerald October 19, 2012 + Modified by Arturo Guadalupi December 18, 2015 + + This example code is in the public domain + + http://www.arduino.cc/en/Tutorial/SimpleAudioPlayer + +*/ + +#include +#include +#include + +void setup() { + // debug output at 9600 baud + Serial.begin(9600); + + // setup SD-card + Serial.print("Initializing SD card..."); + if (!SD.begin(4)) { + Serial.println(" failed!"); + while(true); + } + Serial.println(" done."); + // hi-speed SPI transfers + + // 44100 Hz stereo => 88200 Hz sample rate + // 100 mSec of prebuffering. +} + +void loop() { + int count = 0; + + // open wave file from SD card + File myFile = SD.open("test.wav"); + Audio.begin(88200, 100); + if (!myFile) { + // if the file didn't open, print an error and stop + Serial.println("error opening test.wav"); + while (true); + } + + const int S = 1024; // Number of samples to read in block + short buffer[S]; + + Serial.print("Playing"); + // until the file is finished + while (myFile.available()) { + // read from the file into buffer + myFile.read(buffer, sizeof(buffer)); + + // Prepare samples + int volume = 1024; + Audio.prepare(buffer, S, volume); + // Feed samples to audio + Audio.write(buffer, S); + + // Every 100 blocks print a '.' + count++; + if (count == 100) { + Serial.print("."); + count = 0; + } + } + myFile.close(); + Audio.close(); + Serial.println("End of file. Thank you for listening!"); + while (true) ; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioFrequencyMeter/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioFrequencyMeter/README.adoc new file mode 100644 index 00000000..86f6820b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioFrequencyMeter/README.adoc @@ -0,0 +1,48 @@ +:repository-owner: arduino-libraries +:repository-name: AudioFrequencyMeter + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows the Arduino Zero and MKR1000 to sample a generic input audio signal and get the fundamental pitch. + + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +== Methods == +* begin(uint32_t ulPin, uint32_t sampleRate) : initialize the ADC to sample ulPin at the chosen sample rate. This process works in interrupt using TC5 to start the sampling process. ADC resolution is set to 8 bit + +* end() : stops the sampling process disabling both the ADC and TC5 and resetting TC5 + +* setClippingPin(int pin) : put pin in output to be used as a clipping indicator + +* checkClipping : checks if there is a clipping event (converted value equals to the top or the bottom of the ADC dynamic) and drives HIGH the clippingPin + +* setAmplitudeThreshold(uint8_t threshold) : sets the threshold for which a detected frequency is considered right or wrong. Default is 30 + +* setTimerTolerance(int tolerance) : sets the tolerance for which a sampled signal is considered valid. Default is 10 + +* setSlopeTolerance(int tolerance) : sets the tolerance for which the slope is valid for the trigger process. Default is 3 + +* setBandwidth(float minFrequency, float maxFrequency) : set the range of frequencies for which the detected frequency is valid. Default values for now are 60 Hz - 1500 Hz. This must be improved + +* getFrequency : return the value of the detected frequency if it is above the threshold defined by setAmplitudeThreshold, else -1 diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioFrequencyMeter/examples/SimpleAudioFrequencyMeter/SimpleAudioFrequencyMeter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioFrequencyMeter/examples/SimpleAudioFrequencyMeter/SimpleAudioFrequencyMeter.ino new file mode 100644 index 00000000..06ec8ad6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioFrequencyMeter/examples/SimpleAudioFrequencyMeter/SimpleAudioFrequencyMeter.ino @@ -0,0 +1,35 @@ +/* + Simple Frequency Meter for Arduino Zero + + Demonstrates how to sample an input signal and get back its frequency + + This example code is in the public domain + + https://www.arduino.cc/en/Tutorial/SimpleAudioFrequencyMeter + + created by Arturo Guadalupi + 10 Nov 2015 +*/ + +#include + +AudioFrequencyMeter meter; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + Serial.println("started"); + + meter.setBandwidth(70.00, 1500); // Ignore frequency out of this range + meter.begin(A0, 45000); // Initialize A0 at sample rate of 45 kHz +} + +void loop() { + // put your main code here, to run repeatedly: + float frequency = meter.getFrequency(); + if (frequency > 0) + { + Serial.print(frequency); + Serial.println(" Hz"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioZero/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioZero/README.adoc new file mode 100644 index 00000000..547433f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioZero/README.adoc @@ -0,0 +1,31 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: AudioZero + += {repository-name} library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The {repository-name} library enables an Arduino SAMD Board (e.g., https://store.arduino.cc/catalogsearch/result/?q=mkr[MKR boards], https://store.arduino.cc/arduino-nano-33-iot[Nano 33 IoT], https://store.arduino.cc/arduino-zero[Zero]) to play back .wav files from a storage device like an SD card to the `DAC0`/`A0` pin. +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioZero/examples/SimpleAudioPlayerZero/SimpleAudioPlayerZero.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioZero/examples/SimpleAudioPlayerZero/SimpleAudioPlayerZero.ino new file mode 100644 index 00000000..4e5f2ff1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/AudioZero/examples/SimpleAudioPlayerZero/SimpleAudioPlayerZero.ino @@ -0,0 +1,62 @@ +/* + Simple Audio Player for Arduino Zero + + Demonstrates the use of the Audio library for the Arduino Zero + + Hardware required : + * Arduino shield with a SD card on CS4 + * A sound file named "test.wav" in the root directory of the SD card + * An audio amplifier to connect to the DAC0 and ground + * A speaker to connect to the audio amplifier + + + Arturo Guadalupi + Angelo Scialabba + Claudio Indellicati + + This example code is in the public domain + + https://www.arduino.cc/en/Tutorial/SimpleAudioPlayerZero + +*/ + +#include +#include +#include + +void setup() +{ + // debug output at 115200 baud + Serial.begin(115200); + + // setup SD-card + Serial.print("Initializing SD card..."); + if (!SD.begin(4)) { + Serial.println(" failed!"); + while(true); + } + Serial.println(" done."); +} + +void loop() +{ + int count = 0; + + // open wave file from sdcard + File myFile = SD.open("test.wav"); + // 44100kHz stereo => 88200 sample rate + AudioZero.begin(2*44100); + if (!myFile) { + // if the file didn't open, print an error and stop + Serial.println("error opening test.wav"); + while (true); + } + + Serial.print("Playing"); + + // until the file is not finished + AudioZero.play(myFile); + AudioZero.close(); + Serial.println("End of file. Thank you for listening!"); + while (true) ; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/README.md new file mode 100644 index 00000000..eadcaba7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/README.md @@ -0,0 +1,22 @@ +Sample SW for using BNO055 with Arduino + +[![Check Arduino status](https://github.com/arduino-libraries/BNO055/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/BNO055/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/BNO055/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/BNO055/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/BNO055/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/BNO055/actions/workflows/spell-check.yml) + +(C) All rights reserved by ROBERT BOSCH GMBH + +Copyright (C) 2014 Bosch Sensortec GmbH + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Basic/Basic.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Basic/Basic.ino new file mode 100644 index 00000000..8f8ee19a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Basic/Basic.ino @@ -0,0 +1,99 @@ +/* + *************************************************************************** + * + * Basic.ino - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* BNO055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); + + //Read out device information + Serial.print("Chip ID: "); + Serial.println(myBNO.chip_id); + + //Read out the software revision ID + Serial.print("Software Revision ID: "); + Serial.println(myBNO.sw_revision_id); + + //Read out the page ID + Serial.print("Page ID: "); + Serial.println(myBNO.page_id); + + //Read out the accelerometer revision ID + Serial.print("Accelerometer Revision ID: "); + Serial.println(myBNO.accel_revision_id); + + //Read out the gyroscope revision ID + Serial.print("Gyroscope Revision ID: "); + Serial.println(myBNO.gyro_revision_id); + + //Read out the magnetometer revision ID + Serial.print("Magnetometer Revision ID: "); + Serial.println(myBNO.mag_revision_id); + + //Read out the bootloader revision ID + Serial.print("Bootloader Revision ID: "); + Serial.println(myBNO.bootloader_revision_id); + + //Read out the device address + Serial.print("Device Address: "); + Serial.println(myBNO.dev_addr); +} + +void loop() //This code is looped forever +{ + //Blank +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Command_Line_Configuration/Command_Line_Configuration.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Command_Line_Configuration/Command_Line_Configuration.ino new file mode 100644 index 00000000..ffd9ba94 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Command_Line_Configuration/Command_Line_Configuration.ino @@ -0,0 +1,253 @@ +/* + *************************************************************************** + * + * Command_Line_Configuration.ino - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* BNO055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +//Variables and Flags +unsigned long lastTime = 0; +bool streamReqd = false; //Flag to indicate the requirement for streaming of data + +//Function Prototypes +void streamData(void); //Function to stream data +void getCommand(void); //Function to receive the command and parse it +void execCommand(char ,int); //Function to execute relevant functions depending on the command + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode (Currently defaulted to NDoF) + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); + + //Indication on the Serial Monitor that the Initialization is complete + Serial.println("Initialization Complete"); + Serial.println("Set the terminal character to newline and baud rate to 115200"); + Serial.println("List of commands:"); + Serial.println("s toggles streaming of Euler data"); + Serial.println("c0 to c12 changes the Operation mode"); + Serial.println("p0 to p2 changes the Power mode"); +} + +void loop() //This code is looped forever +{ + if(streamReqd) //If data needs to be streamed then stream data + streamData(); + getCommand();//To look for incoming UART commands and call relevant functions +} + +void streamData(void) +{ + if((millis()-lastTime) >= 100) //To stream at 10Hz without using additional timers + { + lastTime = millis(); + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h)/16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r)/16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p)/16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} + +void getCommand(void) +{ + int commPos = 0;//Register used to keep track of the index of the command + char par1 = 0;//To store the first parameter of the command + int par2 = 0;//To store the seconds parameter of the command + char command[10] = {0};//Array to store the incoming commands + int index; + for(index = 0; index < 10; index++)//Initialize the command array to NULL + command[index] = 0; + if(Serial.available()) + { + int commLen = Serial.readBytesUntil('\n', &command[0], 10);//Store the command in an array and store the length of the incoming command + for(index = 0; index < 10; index++)//Echo the incoming command + Serial.print(command[index]); + Serial.println(); + par1 = command[0]; //Store the first parameter of the command + commPos++; + while((command[commPos] >= '0') && (command[commPos] <= '9'))//To process digits [0-9]+ and store in par2 + { + par2 *= 10;//Shift the digit position + par2 += command[commPos] - '0';//Convert ASCII to Integer + commPos++;//Increment the position of the array + } + execCommand(par1, par2); + } +} + +void execCommand(char head, int tail) +{ + switch(head) + { + case 's': //Command to toggle Streaming of data + streamReqd = !streamReqd; + if(streamReqd) + Serial.println("Streaming ON"); + else + Serial.println("Streaming OFF"); + break; + + case 'c': //Command to change the operation mode + streamReqd = false; //Comment this line if you want to data streaming to be kept on + switch(tail) + { + case 0: + Serial.println("Set into Configuration Mode"); + bno055_set_operation_mode(OPERATION_MODE_CONFIG); + break; + + case 1: + Serial.println("Set into Accelerometer Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCONLY); + break; + + case 2: + Serial.println("Set into Magnetometer Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_MAGONLY); + break; + + case 3: + Serial.println("Set into Gyroscope Only Mode"); + bno055_set_operation_mode(OPERATION_MODE_GYRONLY); + break; + + case 4: + Serial.println("Set into Accelerometer and Magnetometer Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCMAG); + break; + + case 5: + Serial.println("Set into Accelerometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_ACCGYRO); + break; + + case 6: + Serial.println("Set into Magnetometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_MAGGYRO); + break; + + case 7: + Serial.println("Set into Accelerometer, Magnetometer and Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_AMG); + break; + + case 8: + Serial.println("Set into Sensor Fusion IMU Plus Mode"); + bno055_set_operation_mode(OPERATION_MODE_IMUPLUS); + break; + + case 9: + Serial.println("Set into Sensor Fusion Compass Mode"); + bno055_set_operation_mode(OPERATION_MODE_COMPASS); + break; + + case 10: + Serial.println("Set into Sensor Fusion Magnetometer for Gyroscope Mode"); + bno055_set_operation_mode(OPERATION_MODE_M4G); + break; + + case 11: + Serial.println("Set into Sensor Fusion NDoF Mode with Fast Magnetometer Calibration Off"); + bno055_set_operation_mode(OPERATION_MODE_NDOF_FMC_OFF); + break; + + case 12: + Serial.println("Set into Sensor Fusion NDoF Mode"); + bno055_set_operation_mode(OPERATION_MODE_NDOF); + break; + + default: + Serial.println("Invalid Configuration Mode"); + } + break; + + case 'p': //To change power modes + streamReqd = false; //Comment this line if you want to data streaming to be kept on + switch(tail) + { + case 0: + Serial.println("Set into Normal Power Mode"); + bno055_set_powermode(POWER_MODE_NORMAL); + break; + + case 1: + Serial.println("Set into Low Power Mode"); + bno055_set_operation_mode(POWER_MODE_LOW_POWER); + break; + + case 2: + Serial.println("Set into Suspend Power Mode"); + bno055_set_operation_mode(POWER_MODE_SUSPEND); + break; + + default: + Serial.println("Invalid Power Mode"); + } + break; + + default: + Serial.println("Invalid Command"); + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Euler_Streaming/Euler_Streaming.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Euler_Streaming/Euler_Streaming.ino new file mode 100644 index 00000000..dd2afd4c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Euler_Streaming/Euler_Streaming.ino @@ -0,0 +1,89 @@ +/* + *************************************************************************** + + Euler_Streaming.ino - part of sample SW for using BNO055 with Arduino + + (C) All rights reserved by ROBERT BOSCH GMBH + + Copyright (C) 2014 Bosch Sensortec GmbH + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + + **************************************************************************/ +/* Date: 2014/01/07 + Revision: 1.2 + +*/ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* BNO055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +struct bno055_euler myEulerData; //Structure to hold the Euler data + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if ((millis() - lastTime) >= 100) //To stream at 10 Hz without using additional timers + { + lastTime = millis(); + + bno055_read_euler_hrp(&myEulerData); //Update Euler data into the structure + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + Serial.print("Heading(Yaw): "); //To read out the Heading (Yaw) + Serial.println(float(myEulerData.h) / 16.00); //Convert to degrees + + Serial.print("Roll: "); //To read out the Roll + Serial.println(float(myEulerData.r) / 16.00); //Convert to degrees + + Serial.print("Pitch: "); //To read out the Pitch + Serial.println(float(myEulerData.p) / 16.00); //Convert to degrees + + Serial.println(); //Extra line to differentiate between packets + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Sensor_Calibration/Sensor_Calibration.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Sensor_Calibration/Sensor_Calibration.ino new file mode 100644 index 00000000..a939bbcf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/BNO055/examples/Sensor_Calibration/Sensor_Calibration.ino @@ -0,0 +1,97 @@ +/* + *************************************************************************** + * + * Sensor_Calibration.ino - part of sample SW for using BNO055 with Arduino + * + * (C) All rights reserved by ROBERT BOSCH GMBH + * + * Copyright (C) 2014 Bosch Sensortec GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + **************************************************************************/ +/* Date: 2014/01/07 + * Revision: 1.2 + * + */ + +#include "BNO055_support.h" //Contains the bridge code between the API and Arduino +#include + +//The device address is set to BNO055_I2C_ADDR2 in this example. You can change this in the BNO055.h file in the code segment shown below. +// /* BNO055 I2C Address */ +// #define BNO055_I2C_ADDR1 0x28 +// #define BNO055_I2C_ADDR2 0x29 +// #define BNO055_I2C_ADDR BNO055_I2C_ADDR2 + +//Pin assignments as tested on the Arduino Due. +//Vdd,Vddio : 3.3V +//GND : GND +//SDA/SCL : SDA/SCL +//PSO/PS1 : GND/GND (I2C mode) + +//This structure contains the details of the BNO055 device that is connected. (Updated after initialization) +struct bno055_t myBNO; +unsigned char accelCalibStatus = 0; //Variable to hold the calibration status of the Accelerometer +unsigned char magCalibStatus = 0; //Variable to hold the calibration status of the Magnetometer +unsigned char gyroCalibStatus = 0; //Variable to hold the calibration status of the Gyroscope +unsigned char sysCalibStatus = 0; //Variable to hold the calibration status of the System (BNO055's MCU) + +unsigned long lastTime = 0; + +void setup() //This code is executed once +{ + //Initialize I2C communication + Wire.begin(); + + //Initialization of the BNO055 + BNO_Init(&myBNO); //Assigning the structure to hold information about the device + + //Configuration to NDoF mode + bno055_set_operation_mode(OPERATION_MODE_NDOF); + + delay(1); + + //Initialize the Serial Port to view information on the Serial Monitor + Serial.begin(115200); +} + +void loop() //This code is looped forever +{ + if((millis()-lastTime) >= 200) //To read calibration status at 5 Hz without using additional timers + { + lastTime = millis(); + + Serial.print("Time Stamp: "); //To read out the Time Stamp + Serial.println(lastTime); + + bno055_get_accelcalib_status(&accelCalibStatus); + Serial.print("Accelerometer Calibration Status: "); //To read out the Accelerometer Calibration Status (0-3) + Serial.println(accelCalibStatus); + + bno055_get_magcalib_status(&magCalibStatus); + Serial.print("Magnetometer Calibration Status: "); //To read out the Magnetometer Calibration Status (0-3) + Serial.println(magCalibStatus); + + bno055_get_magcalib_status(&gyroCalibStatus); + Serial.print("Gyroscope Calibration Status: "); //To read out the Gyroscope Calibration Status (0-3) + Serial.println(gyroCalibStatus); + + bno055_get_syscalib_status(&sysCalibStatus); + Serial.print("System Calibration Status: "); //To read out the Magnetometer Calibration Status (0-3) + Serial.println(sysCalibStatus); + + Serial.println(); //To separate between packets + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/README.adoc new file mode 100644 index 00000000..a5688b89 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/README.adoc @@ -0,0 +1,29 @@ +:repository-owner: arduino-libraries +:repository-name: Braccio + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The library offers easy access to the data from the onboard TinkerKit Braccio, and provides moves for the Braccio. + +For more information about this library please visit us at +https://www.arduino.cc/en/Guide/Braccio + +== License == + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/braccioOfUnoWiFi/braccioOfUnoWiFi.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/braccioOfUnoWiFi/braccioOfUnoWiFi.ino new file mode 100644 index 00000000..565c6840 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/braccioOfUnoWiFi/braccioOfUnoWiFi.ino @@ -0,0 +1,265 @@ +/* + + braccioOfUnoWifi.ino + + Based on Arduino Uno WiFi Rest Server example + + This example for the Arduino Uno WiFi shows how to + control a TinkerKit Braccio through REST calls. + You can create your mobile app or your + browser app to control the Braccio in wireless mode + + Note that with the Braccio shield version less than V4 + you need to disconnect the pin A4 from the shield to the board + + Possible commands created in this sketch: + + * "/arduino/custom/base/value:80" -> Moves the base of the Braccio at 80 degrees + * "/arduino/custom/shoulder/value:150" -> Moves the shoulder of the Braccio at 150 degrees + * "/arduino/custom/elbow/value:45" -> Moves the elbow of the Braccio at 45 degrees + * "/arduino/custom/wristv/value:10" -> Moves the wristv of the Braccio at 10 degrees + * "/arduino/custom/wristr/value:120" -> Moves the wristr of the Braccio at 120 degrees + * "/arduino/custom/gripper/value:73" -> Close the gripper + * "/arduino/custom/ledon" -> Turn ON the LED 13 + * "/arduino/custom/ledoff" -> Turn OFF the LED 13 + * "/arduino/custom/servo:3/value:73" -> Moves the servo to the pin 3 at 73 degrees + * "/arduino/custom/sayciao" -> Run the function sayciao(). The Braccio says "Ciao" with the gripper + * "/arduino/custom/takesponge" -> Run the function takesponge(). The Braccio takes the big sponge you can find in its box + * "/arduino/custom/showsponge" -> Run the function showsponge(). The Braccio shows the sponge to the user + * "/arduino/custom/throwsponge" -> Run the function throwsponge(). The Braccio throws away the sponge + + This example code is part of the public domain + + https://web.archive.org/web/20160502122840/http://labs.arduino.org/RestServer+and+RestClient + https://store.arduino.cc/tinkerkit-braccio-robot + +*/ + +#include +#include +#include +#include + +//Initial Value for each Motor +int m1 = 0; +int m2 = 45; +int m3 = 180; +int m4 = 180; +int m5 = 90; +int m6 = 0; + +bool moveBraccio = false; + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + + +void setup() { + //Initialization of Braccio + Braccio.begin(); + //Initialization of the Uno WiFi + Wifi.begin(); + Wifi.println("REST Server is up"); +} + +void loop() { + //Wait until the board receives HTTP commands + while (Wifi.available()) { + process(Wifi); + } + delay(50); +} + +/** +Parse Command from REST +It parse a command like: /arduino/custom/base/value:45 +@param command: The message to parse +@param type: the key for parsing +@return the value for the key +*/ +int parseCommand(String command, String type) { + int typeIndex = command.indexOf(type); + int dotsIndex = command.indexOf(':', typeIndex + type.length()); + + int idxtmp = dotsIndex + 4; + if ((dotsIndex + 4) > command.length()) idxtmp = command.length(); + String tmp = command.substring(dotsIndex + 1, idxtmp); + + return tmp.toInt(); +} + +/** +It process data from the HTTP protocol +*/ +void process(WifiData client) { + // read the command + String command = client.readString(); + command.toUpperCase(); + + if(command.indexOf("CUSTOM")==-1){ + client.println("Invalid command: " + command + ""); + return; + } + + //The message from sender + String message = command.substring(16); + //client.println(message); //Debug + + /* + For each message perform the proper command + */ + if (message == "LEDON") { + //Turn ON Led 13 + digitalWrite(13, HIGH); + //Return message to the sender (Eg: the browser) + client.println("alert('Led D13 ON');"); + } + else if (message == "LEDOFF") { + digitalWrite(13, LOW); + client.println("alert('Led D13 OFF');"); + } + //This command allow you to move a desired servo motor giving the + //PWM pin where is connected + //eg: http://192.168.240.1/arduino/custom/servo:3/value:45 or http://192.168.240.1/arduino/custom/base/value:45 + else if (message.startsWith("SERVO")) { + //Parse the message to retrieve which servo to move + int servo = parseCommand(message, "SERVO"); + //Parse the message to retrieve the value for the servo + int value = parseCommand(message, "VALUE"); + + client.println("Message:" + String(message) + "SERVO: " + String(servo) + " " + String(value)); + + moveBraccio=true; + } + //http://192.168.240.1/arduino/custom/base:45 or http://192.168.240.1/arduino/custom/base/value:45 + //Command for the base of the Braccio (M1) + else if (message.startsWith("BASE")) { + m1 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("BASE: " + String(m1)); + } + //Command for the shoulder of the Braccio (M2) + else if (message.startsWith("SHOULDER")) { + m2 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("SHOULDER: " + String(m2)); + } + //Command for the elbow of the Braccio (M3) + else if (message.startsWith("ELBOW")) { + m3 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("ELBOW: " + String(m3)); + } + //Command for the wrist of the Braccio to move it up and down (M4) + else if (message.startsWith("WRISTV")) { + m4 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("WRISTV: " + String(m4)); + } + //Command for the wrist of the Braccio to rotate it (M5) + else if (message.startsWith("WRISTR")) { + m5 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("WRISTR: " + String(m5)); + } + //Command for the GRIPPER of the Braccio to open and close it (M6) + else if (message.startsWith("GRIPPER")) { + m6 = parseCommand(message, "VALUE"); + moveBraccio = true; + client.println("GRIPPER: " + String(m6)); + } + //Command to say "Ciao" + else if (message.startsWith("SAYCIAO")) { + sayCiao(); + client.println("SAYCIAO: " + String(m6)); + } + //Command for take the sponge + else if (message.startsWith("TAKESPONGE")) { + takesponge(); + client.println("TAKESPONGE: " + String(m6)); + } + //Command for show the sponge + else if (message.startsWith("SHOWSPONGE")) { + showsponge(); + client.println("SHOWSPONGE: " + String(m6)); + } + //Command for throw away the sponge + else if (message.startsWith("THROWSPONGE")) { + throwsponge(); + client.println("THROWSPONGE: " + String(m6)); + } + else + client.println("command error: " + message); + + //if flag moveBraccio is true fire the movement + if (moveBraccio) { + //client.println("moveBraccio"); + Braccio.ServoMovement(20, m1, m2, m3, m4, m5, m6); + moveBraccio = false; + } + + client.flush(); +} + +/** +The Braccio Say 'Ciao' with the GRIPPER +*/ +void sayCiao() { + Braccio.ServoMovement(20, 90, 0, 180, 160, 0, 15); + + for (int i = 0; i < 5; i++) { + Braccio.ServoMovement(10, 90, 0, 180, 160, 0, 15); + delay(500); + + Braccio.ServoMovement(10, 90, 0, 180, 160, 0, 73); + delay(500); + } +} + +/** +Braccio take the Sponge +*/ +void takesponge() { + //starting position + //(step delay M1 , M2 , M3 , M4 , M5 , M6); + Braccio.ServoMovement(20, 0, 45, 180, 180, 90, 0); + + //I move arm towards the sponge + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 0); + + //the GRIPPER takes the sponge + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 60 ); + + //up the sponge + Braccio.ServoMovement(20, 0, 45, 180, 45, 0, 60); +} + + +/** +Braccio show the sponge to the user +*/ +void showsponge() { + for (int i = 0; i < 2; i++) { + + //(step delay M1 , M2 , M3 , M4 , M5 , M6 ); + Braccio.ServoMovement(10, 0, 45, 180, 45, 180, 60); + + Braccio.ServoMovement(10, 0, 45, 180, 45, 0, 60); + } +} + +/** +Braccio throw away the sponge +*/ +void throwsponge() { + //(step delay M1 , M2 , M3 , M4 , M5 , M6 ); + Braccio.ServoMovement(20, 0, 45, 90, 45, 90, 60); + + Braccio.ServoMovement(5, 0, 45, 135, 90, 90, 60); + + Braccio.ServoMovement(5, 0, 90, 150, 90, 90, 0); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/ciaoBraccio/ciaoBraccio.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/ciaoBraccio/ciaoBraccio.ino new file mode 100644 index 00000000..8000dd9c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/ciaoBraccio/ciaoBraccio.ino @@ -0,0 +1,237 @@ +/* + + This sketch uses the REST connector to receive command for the MCU from a REST client. + Each command received will fire an action for the Braccio. + Run the sketch with Arduino Braccio - Web Examples to move your Braccio via web page. + Visit the Demo section of the Braccio's page. + https://www.arduino.cc/en/Guide/Braccio + + + +REST command example: + + * "ledon" -> turn on led 13 + * "ledoff" -> turn off led 13 + + example: http://arduino.local/arduino/ledon + + NOTE: be sure to activate and configure REST connector on Linino OS + https://www.arduino.cc/en/Reference/Ciao + + created March 2016 + by andrea[at]arduino[dot]org and a.ferrante[at]arduino[dot]org + + */ + +#include +#include +#include + +//Initial Value for each Motor +int m1 = 0; +int m2 = 45; +int m3 = 180; +int m4 = 180; +int m5 = 90; +int m6 = 0; + +bool moveBraccio = false; + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + +void setup() { + //Initialization function for Ciao + Ciao.begin(); + //Initialization function for Braccio + //You should set begin(SOFT_START_DISABLED) if you are using the Arm Robot shield V1.6 + Braccio.begin(); +} + +/** +Parse Command from REST +It parses a command like: /arduino/base/value:45 +Giving "base" it return the value +@param command: The message to parse +@param type: the key for parsing +*/ +int parseCommand(String command, String type) { + int typeIndex = command.indexOf(type); + int dotsIndex = command.indexOf(':', typeIndex + type.length()); + + int idxtmp = dotsIndex + 4; + if ((dotsIndex + 4) > command.length()) idxtmp = command.length(); + String tmp = command.substring(dotsIndex + 1, idxtmp); + + return tmp.toInt(); +} + +void loop() { + + //Select REST connector + CiaoData data = Ciao.read("restserver"); + //If data is not empty + if (!data.isEmpty()) { + //ID of the command + String id = data.get(0); + //Sender ID + String sender = data.get(1); + //The message from sender + String message = data.get(2); + + message.toUpperCase(); + + /* + For each message do the proper command + */ + if (message == "LEDON") { + //Turn OFF Led 13 + digitalWrite(13, HIGH); + //Return message to the sender (Eg: the browser) + Ciao.writeResponse("restserver", id, "Led D13 ON"); + } + else if (message == "LEDOFF") { + digitalWrite(13, LOW); + Ciao.writeResponse("restserver", id, "Led D13 OFF"); + } + //This command allow you to move a desired servo motor giving the + //PWM pin where is connected + else if (message.startsWith("SERVO")) { + //Parse the message to retrieve which servo to move + int servo = parseCommand(message, "SERVO"); + //Parse the message to retrieve the value for the servo + int value = parseCommand(message, "VALUE"); + + Ciao.writeResponse("restserver", id, "Message:" + String(message) + "SERVO: " + String(servo) + " " + String(value)); + } + //Command for the base of the Braccio (M1) + else if (message.startsWith("BASE")) { + m1 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "BASE: " + String(m1)); + } + //Command for the shoulder of the Braccio (M2) + else if (message.startsWith("SHOULDER")) { + m2 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "SHOULDER: " + String(m2)); + } + //Command for the elbow of the Braccio (M3) + else if (message.startsWith("ELBOW")) { + m3 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "ELBOW: " + String(m3)); + } + //Command for the wrist of the Braccio to move up and down (M4) + else if (message.startsWith("WRISTV")) { + m4 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "WRISTV: " + String(m4)); + } + //Command for the wrist of the Braccio to rotate (M5) + else if (message.startsWith("WRISTR")) { + m5 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "WRISTR: " + String(m5)); + } + //Command for the gripper of the Braccio to open and close (M6) + else if (message.startsWith("GRIPPER")) { + m6 = parseCommand(message, "VALUE"); + moveBraccio = true; + Ciao.writeResponse("restserver", id, "GRIPPER: " + String(m6)); + } + //Command to say "Ciao" + else if (message.startsWith("SAYCIAO")) { + sayCiao(); + Ciao.writeResponse("restserver", id, "SAYCIAO: " + String(m6)); + } + //Command to take the sponge + else if (message.startsWith("TAKESPONGE")) { + takesponge(); + Ciao.writeResponse("restserver", id, "TAKESPONGE: " + String(m6)); + } + //Command to show the sponge + else if (message.startsWith("SHOWSPONGE")) { + showsponge(); + Ciao.writeResponse("restserver", id, "SHOWSPONGE: " + String(m6)); + } + //Command to throw away the sponge + else if (message.startsWith("THROWSPONGE")) { + throwsponge(); + Ciao.writeResponse("restserver", id, "THROWSPONGE: " + String(m6)); + } + + else + Ciao.writeResponse("restserver", id, "command error"); + + //if flag moveBraccio is true fire the movement + if (moveBraccio) { + Braccio.ServoMovement(20, m1, m2, m3, m4, m5, m6); + moveBraccio = false; + } + } +} + +/** +The Braccio says 'Ciao' with the Tongue +*/ +void sayCiao() { + + Braccio.ServoMovement(20, 90, 0, 180, 160, 0, 15); + + for (int i = 0; i < 5; i++) { + Braccio.ServoMovement(10, 90, 0, 180, 160, 0, 15); + delay(500); + + Braccio.ServoMovement(10, 90, 0, 180, 160, 0, 73); + delay(500); + } +} + +/** +Braccio takes the Sponge +*/ +void takesponge() { + //starting position + //(step delay M1 , M2 , M3 , M4 , M5 , M6); + Braccio.ServoMovement(20, 0, 45, 180, 180, 90, 0); + + //I move arm towards the sponge + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 0); + + //the gripper takes the sponge + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 60 ); + + //raise the sponge + Braccio.ServoMovement(20, 0, 45, 180, 45, 0, 60); +} + + +/** +Braccio shows the sponge to the user +*/ +void showsponge() { + for (int i = 0; i < 2; i++) { + + //(step delay M1 , M2 , M3 , M4 , M5 , M6 ); + Braccio.ServoMovement(10, 0, 45, 180, 45, 180, 60); + + Braccio.ServoMovement(10, 0, 45, 180, 45, 0, 60); + } +} + +/** +Braccio throws away the sponge +*/ +void throwsponge() { + //(step delay M1 , M2 , M3 , M4 , M5 , M6 ); + Braccio.ServoMovement(20, 0, 45, 90, 45, 90, 60); + + Braccio.ServoMovement(5, 0, 45, 135, 90, 90, 60); + + Braccio.ServoMovement(5, 0, 90, 150, 90, 90, 0); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/simpleMovements/simpleMovements.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/simpleMovements/simpleMovements.ino new file mode 100644 index 00000000..2ae8901a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/simpleMovements/simpleMovements.ino @@ -0,0 +1,56 @@ + +/* + simpleMovements.ino + + The simpleMovements sketch shows how to move each servo motor of the Braccio + + Created on 18 Nov 2015 + by Andrea Martino + + This example is in the public domain. + */ + +#include +#include + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + +void setup() { + //Initialization functions and set up the initial position for Braccio + //All the servo motors will be positioned in the "safety" position: + //Base (M1):90 degrees + //Shoulder (M2): 45 degrees + //Elbow (M3): 180 degrees + //Wrist vertical (M4): 180 degrees + //Wrist rotation (M5): 90 degrees + //gripper (M6): 10 degrees + Braccio.begin(); +} + +void loop() { + /* + Step Delay: a milliseconds delay between the movement of each servo. Allowed values from 10 to 30 msec. + M1=base degrees. Allowed values from 0 to 180 degrees + M2=shoulder degrees. Allowed values from 15 to 165 degrees + M3=elbow degrees. Allowed values from 0 to 180 degrees + M4=wrist vertical degrees. Allowed values from 0 to 180 degrees + M5=wrist rotation degrees. Allowed values from 0 to 180 degrees + M6=gripper degrees. Allowed values from 10 to 73 degrees. 10: the tongue is open, 73: the gripper is closed. + */ + + //(step delay, M1, M2, M3, M4, M5, M6); + Braccio.ServoMovement(20, 0, 15, 180, 170, 0, 73); + + //Wait 1 second + delay(1000); + + Braccio.ServoMovement(20, 180, 165, 0, 0, 180, 10); + + //Wait 1 second + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/takethesponge/takethesponge.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/takethesponge/takethesponge.ino new file mode 100644 index 00000000..ca1c5f6e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/takethesponge/takethesponge.ino @@ -0,0 +1,73 @@ +/* + takethesponge.ino + + This example commands the Braccio to take a sponge from the table and show it to the user + + Created on 18 Nov 2015 + by Andrea Martino + + This example is in the public domain. +*/ + +#include +#include + + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + + +void setup() { + //Initialization functions and set up the initial position for Braccio + //All the servo motors will be positioned in the "safety" position: + //Base (M1):90 degrees + //Shoulder (M2): 45 degrees + //Elbow (M3): 180 degrees + //Wrist vertical (M4): 180 degrees + //Wrist rotation (M5): 90 degrees + //gripper (M6): 10 degrees + Braccio.begin(); +} + +void loop() { + /* + Step Delay: a milliseconds delay between the movement of each servo. Allowed values from 10 to 30 msec. + M1=base degrees. Allowed values from 0 to 180 degrees + M2=shoulder degrees. Allowed values from 15 to 165 degrees + M3=elbow degrees. Allowed values from 0 to 180 degrees + M4=wrist vertical degrees. Allowed values from 0 to 180 degrees + M5=wrist rotation degrees. Allowed values from 0 to 180 degrees + M6=gripper degrees. Allowed values from 10 to 73 degrees. 10: the tongue is open, 73: the gripper is closed. + */ + + //Starting position + //(step delay M1 , M2 , M3 , M4 , M5 , M6); + Braccio.ServoMovement(20, 0, 45, 180, 180, 90, 10); + + //Wait 1 second + delay(1000); + + //The Braccio moves to the sponge. Only the M2 servo will moves + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 10); + + //Close the gripper to take the sponge. Only the M6 servo will moves + Braccio.ServoMovement(10, 0, 90, 180, 180, 90, 60 ); + + //Brings the sponge upwards. + Braccio.ServoMovement(20, 0, 45, 180, 45, 0, 60); + + //Show the sponge. Only the M1 servo will moves + Braccio.ServoMovement(20, 180, 45, 180, 45, 0, 60); + + //Return to the start position. + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 60); + + //Open the gripper + Braccio.ServoMovement(20, 0, 90, 180, 180, 90, 10 ); + + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/testBraccio90/testBraccio90.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/testBraccio90/testBraccio90.ino new file mode 100644 index 00000000..2fc5c12a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Braccio/examples/testBraccio90/testBraccio90.ino @@ -0,0 +1,53 @@ + /* + testBraccio90.ino + + testBraccio90 is a setup sketch to check the alignment of all the servo motors + This is the first sketch you need to run on Braccio + When you start this sketch Braccio will be positioned perpendicular to the base + If you can't see the Braccio in this exact position you need to realign the servo motor positions + + Created on 18 Nov 2015 + by Andrea Martino + + This example is in the public domain. + */ + +#include +#include + + +Servo base; +Servo shoulder; +Servo elbow; +Servo wrist_rot; +Servo wrist_ver; +Servo gripper; + +void setup() { + //Initialization functions and set up the initial position for Braccio + //All the servo motors will be positioned in the "safety" position: + //Base (M1):90 degrees + //Shoulder (M2): 45 degrees + //Elbow (M3): 180 degrees + //Wrist vertical (M4): 180 degrees + //Wrist rotation (M5): 90 degrees + //gripper (M6): 10 degrees + Braccio.begin(); +} + +void loop() { + /* + Step Delay: a milliseconds delay between the movement of each servo. Allowed values from 10 to 30 msec. + M1=base degrees. Allowed values from 0 to 180 degrees + M2=shoulder degrees. Allowed values from 15 to 165 degrees + M3=elbow degrees. Allowed values from 0 to 180 degrees + M4=wrist vertical degrees. Allowed values from 0 to 180 degrees + M5=wrist rotation degrees. Allowed values from 0 to 180 degrees + M6=gripper degrees. Allowed values from 10 to 73 degrees. 10: the tongue is open, 73: the gripper is closed. + */ + + // the arm is aligned upwards and the gripper is closed + //(step delay, M1, M2, M3, M4, M5, M6); + Braccio.ServoMovement(20, 90, 90, 90, 90, 90, 73); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity1/AnalogInputs_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity1/AnalogInputs_Activity1.ino new file mode 100644 index 00000000..50f8707f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity1/AnalogInputs_Activity1.ino @@ -0,0 +1,22 @@ +/* + CTC GO! CORE MODULE + LESSON 07 - Analog Inputs + + This sketch is written to accompany Activity 1 in Lesson 07 of the CTC GO! core module +*/ + +int pot = A0; +int val = 0; + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + // Read and display the value of the potentiometers + val = analogRead(pot); + Serial.print("Value read: "); + Serial.println(val); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity2/AnalogInputs_Activity2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity2/AnalogInputs_Activity2.ino new file mode 100644 index 00000000..bc080d5c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity2/AnalogInputs_Activity2.ino @@ -0,0 +1,36 @@ +/* + CTC GO! CORE MODULE + LESSON 07 - Analog Inputs + + This sketch is written to accompany Activity 2 in Lesson 07 of the CTC GO! core module +*/ + + +int lightSensor = A0; +int LED = 13; +int val = 0; +int trigger = 250; + +void setup() +{ + pinMode(LED, OUTPUT); + Serial.begin(9600); +} + +void loop() +{ + //savethe read on a variable and print it + val = analogRead(lightSensor); + Serial.print("Value read: "); + Serial.println(val); + + if (val < trigger) + { + digitalWrite(LED, HIGH); + } + else + { + digitalWrite(LED, LOW); + } + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity3/AnalogInputs_Activity3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity3/AnalogInputs_Activity3.ino new file mode 100644 index 00000000..6831d3cd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogInputs/AnalogInputs_Activity3/AnalogInputs_Activity3.ino @@ -0,0 +1,61 @@ + +/* + CTC GO! CORE MODULE + LESSON 07 - Analog Inputs + + This sketch is written to accompany Activity 3 in Lesson 07 of the CTC GO! core module +*/ + + int USsensor = A0; + int greenLED = 9; + int yellowLED = 11; + int redLED = 13; + + float distance = 0; + int value = 0; + + + void setup() + { + pinMode(redLED, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(greenLED, OUTPUT); + + Serial.begin(9600); + } + + void loop() + { + // reading, calculating and printing the distance + value = analogRead(USsensor); + distance = value * 3; + Serial.print("Dinstance to the object (mm): "); + Serial.println(distance); + delay(250); + + // visualizing the distance with the LEDs + if (distance < 200) + { + digitalWrite(redLED, HIGH); + digitalWrite(yellowLED, LOW); + digitalWrite(greenLED, LOW); + } + else if (distance < 400) + { + digitalWrite(yellowLED, HIGH); + digitalWrite(redLED, LOW); + digitalWrite(greenLED, LOW); + } + else if (distance < 600) + { + digitalWrite(greenLED, HIGH); + digitalWrite(yellowLED, LOW); + digitalWrite(redLED, LOW); + } + else + { + digitalWrite(greenLED, LOW); + digitalWrite(yellowLED, LOW); + digitalWrite(redLED, LOW); + } + } diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity1/AnalogOutputs_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity1/AnalogOutputs_Activity1.ino new file mode 100644 index 00000000..6085fdb8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity1/AnalogOutputs_Activity1.ino @@ -0,0 +1,30 @@ + +/* + CTC GO! CORE MODULE + LESSON 08 - Analog Outputs + + This sketch is written to accompany Activity 1 in Lesson 08 of the CTC GO! core module +*/ + +int pot = A0; +int LED = 3; + +// to save the potentiometer position +int val = 0; + +// to change the LED bright +int PWM = 0; + +void setup() +{ + pinMode(LED, OUTPUT); +} + +void loop() +{ + val = analogRead(pot); + + //re-ranging val values + PWM = map (val, 0, 1023, 0, 255); + analogWrite(LED, PWM); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity2/AnalogOutputs_Activity2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity2/AnalogOutputs_Activity2.ino new file mode 100644 index 00000000..0915732f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity2/AnalogOutputs_Activity2.ino @@ -0,0 +1,51 @@ + +/* + CTC GO! CORE MODULE + LESSON 08 - Analog Outputs + + This sketch is written to accompany Activity 2 in Lesson 08 of the CTC GO! core module +*/ + + //pin connections + int buttonA = 13; + int buttonB = 12; + int piezo = 8; + + // notes frequency + int A_note = 262; + int B_note = 493; + + // to save the button states + int buttAvalue = 0; + int buttBvalue = 0; + + void setup() + { + pinMode(buttonA, INPUT); + pinMode(buttonB, INPUT); + pinMode(piezo, OUTPUT); + } + + void loop() + { + //reading the buttons states + buttAvalue = digitalRead(buttonA); + buttBvalue = digitalRead(buttonB); + + // play a note, based on the button pressed + if (buttAvalue == HIGH) + { + tone (piezo, A_note); + } + else if (buttBvalue == HIGH) + { + tone (piezo, B_note); + } + else + { + noTone(piezo); + } + } + + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity3/AnalogOutputs_Activity3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity3/AnalogOutputs_Activity3.ino new file mode 100644 index 00000000..7c8adf9d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/AnalogOutputs/AnalogOutputs_Activity3/AnalogOutputs_Activity3.ino @@ -0,0 +1,74 @@ + +/* + CTC GO! CORE MODULE + LESSON 08 - Analog Outputs + + This sketch is written to accompany Activity 3 in Lesson 08 of the CTC GO! core module +*/ + + + int button = 13; + int piezo = 8; + int LED = 5; + int USsensor = A0; + + int C_note = 262; + int B_note = 493; + + int buttValue = 0; + int value = 0; + int distance = 0; + + int alarm = 0; + int trigger = 500; + + void setup() + { + pinMode(button, INPUT); + pinMode(piezo, OUTPUT); + pinMode(LED, OUTPUT); + } + + void loop() + { + // reading button state and distance + buttValue = digitalRead(button); + value = analogRead(USsensor); + distance = value * 3; + + // setting the trigger distance + if (distance < trigger) + { + alarm = 1; + } + // deactivating the alarm + else if (buttValue == HIGH) + { + alarm = 0; + } + + // if the alarm is triggered + if (alarm == 1) + { + tone (piezo, C_note); + for (int i = 0; i < 255; i++) + { + analogWrite(LED, i); + delay(5); + } + + tone (piezo, B_note); + for (int i = 255; i > 0; i--) + { + analogWrite(LED, i); + delay(5); + } + } + + //if the alarm is not triggered + else + { + digitalWrite(LED, LOW); + noTone(piezo); //stop playing sound + } + } diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity1/DigitalIO_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity1/DigitalIO_Activity1.ino new file mode 100644 index 00000000..dd4d458e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity1/DigitalIO_Activity1.ino @@ -0,0 +1,25 @@ +/* + CTC GO! CORE MODULE + LESSON 04 - Digital Inputs & Outputs + + This sketch is written to accompany Activity 1 in Lesson 04 of the CTC GO! core module +*/ + +// Initialising the pins and other variables. + +int button_pin = 2; +int button_state = 0; + +void setup() +{ + // Setting up the pins as OUTPUTS & INPUTS. + pinMode(LED_BUILTIN, OUTPUT); + pinMode(button_pin,INPUT); +} + +void loop() +{ + // Saving the button state in a variable + button_state = digitalRead(button_pin); + digitalWrite(LED_BUILTIN, button_state); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity2/DigitalIO_Activity2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity2/DigitalIO_Activity2.ino new file mode 100644 index 00000000..a4ce4eff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity2/DigitalIO_Activity2.ino @@ -0,0 +1,34 @@ +/* + CTC GO! CORE MODULE + LESSON 04 - Digital Inputs & Outputs + + This sketch is written to accompany Activity 2 in Lesson 04 of the CTC GO! core module +*/ + +int button_pin = 2; +int button_state = 0; + +void setup() +{ + // Setting up the pins as OUTPUTS & INPUTS. + pinMode(LED_BUILTIN, OUTPUT); + pinMode(button_pin,INPUT); +} + +void loop() +{ + button_state = digitalRead(button_pin); + + // if the button is presed, blink the LEDS + if (button_state == HIGH) + { + digitalWrite(LED_BUILTIN, HIGH); + delay(1000); + digitalWrite(LED_BUILTIN, LOW); + delay(1000); + } + else + { + digitalWrite(LED_BUILTIN, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity3/DigitalIO_Activity3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity3/DigitalIO_Activity3.ino new file mode 100644 index 00000000..769bdf1c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/DigitalIO/DigitalIO_Activity3/DigitalIO_Activity3.ino @@ -0,0 +1,47 @@ +/* + CTC GO! CORE MODULE + LESSON 04 - Digital Inputs & Outputs + + This sketch is written to accompany Activity 3 in Lesson 04 of the CTC GO! core module +*/ + +// Initialising the pins and other variables. +int greenLED = 11; +int yellowLED = 12; +int redLED = 13; + +int blinkingLED = 0; + +void setup() +{ + // Setting up the pins as OUTPUTS. + pinMode(greenLED, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(redLED, OUTPUT); +} + +void loop() +{ + // Randomly blink the LEDs + blinkingLED = random(11, 14); + + if (blinkingLED == greenLED) + { + digitalWrite(greenLED, HIGH); + } + + else if (blinkingLED == yellowLED) + { + digitalWrite(yellowLED, HIGH); + } + else if (blinkingLED == redLED) + { + digitalWrite(redLED, HIGH); + } + + delay (1000); + digitalWrite(greenLED, LOW); + digitalWrite(yellowLED, LOW); + digitalWrite(redLED, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity1/Programming_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity1/Programming_Activity1.ino new file mode 100644 index 00000000..2429780d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity1/Programming_Activity1.ino @@ -0,0 +1,21 @@ +/* + CTC GO! CORE MODULE + LESSON 03 - Let's Start Programming + + This sketch is written to accompany Activity 1 in Lesson 03 of the CTC GO! core module + +*/ + +void setup() +{ + // initialize digital pin LED_BUILTIN as an output. + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() +{ + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity3/Programming_Activity3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity3/Programming_Activity3.ino new file mode 100644 index 00000000..c6bf4417 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/Programming/Programming_Activity3/Programming_Activity3.ino @@ -0,0 +1,29 @@ +/* + CTC GO! CORE MODULE + LESSON 03 - Let's Start Programming + + This sketch is written to accompany Activity 3 in Lesson 03 of the CTC GO! core module + +*/ + +// initialising the pins. +int redLED = 13; +int yellowLED = 12; + +void setup() +{ + // Setting up the pins as OUTPUTS. + pinMode(redLED, OUTPUT); + pinMode(yellowLED, OUTPUT); +} + +void loop() +{ + // Blink the LEDs. + digitalWrite(redLED, HIGH); + digitalWrite(yellowLED, HIGH); + delay(1000); + digitalWrite(redLED, LOW); + digitalWrite(yellowLED, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity1/SerialToBoard_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity1/SerialToBoard_Activity1.ino new file mode 100644 index 00000000..d6736a91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity1/SerialToBoard_Activity1.ino @@ -0,0 +1,30 @@ + +/* + CTC GO! CORE MODULE + LESSON 06 - Sending Data to the Board + + This sketch is written to accompany Activity 1 in Lesson 06 of the CTC GO! core module +*/ + +int incomingNum = 0; +char incomingChar; + +void setup() +{ + Serial.begin(9600); +} + +void loop() +{ + // if there are characters available, read and print them + if (Serial.available() > 0) + { + incomingNum = Serial.read(); + incomingChar = incomingNum; + + Serial.println("Character Code"); + Serial.print(incomingChar); + Serial.print(" "); + Serial.println(incomingNum); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity2/SerialToBoard_Activity2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity2/SerialToBoard_Activity2.ino new file mode 100644 index 00000000..48caec9b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity2/SerialToBoard_Activity2.ino @@ -0,0 +1,99 @@ +/* + CTC GO! CORE MODULE + LESSON 06 - Sending Data to the Board + + This sketch is written to accompany Activity 2 in Lesson 06 of the CTC GO! core module +*/ + +char incomingWord[10]; +int counter = 0; +int i = 0; + +// initialising the pins. +int redLED = 13; +int greenLED = 12; + +void setup() +{ + pinMode(redLED, OUTPUT); + pinMode(greenLED, OUTPUT); + Serial.begin(9600); +} + +void loop() +{ + // send data only when you receive data: + if (Serial.available() > 0) + { + incomingWord[i] = Serial.read(); + + if (incomingWord[i] == 'a') + { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } + else if (incomingWord[i] == 'e') + { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } + else if (incomingWord[i] == 'i') + { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } + else if (incomingWord[i] == 'o') + { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } + else if (incomingWord[i] == 'u') + { + digitalWrite(greenLED, HIGH); + delay(500); + digitalWrite(greenLED, LOW); + delay(500); + counter += 1; + } + else + { + digitalWrite(redLED, HIGH); + delay(500); + digitalWrite(redLED, LOW); + delay(500); + } + + i += 1; + } + else + { + Serial.print("The word introduced is: "); + for (int i = 0; i < 10; i++) + { + Serial.print(incomingWord[i]); + } + Serial.println(""); + Serial.print("It has: "); + Serial.print (counter); + Serial.println(" Vowels"); + delay(5000); + counter = 0; + i = 0; + for (int i = 0; i < 10; i++) + { + incomingWord[i] = 0; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity3/SerialToBoard_Activity3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity3/SerialToBoard_Activity3.ino new file mode 100644 index 00000000..f5f32ff8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToBoard/SerialToBoard_Activity3/SerialToBoard_Activity3.ino @@ -0,0 +1,92 @@ +/* + CTC GO! CORE MODULE + LESSON 06 - Sending Data to the Board + + This sketch is written to accompany Activity 3 in Lesson 06 of the CTC GO! core module +*/ + +// choosing the word to guess +char selectedWord[] = {"HelloWorld"}; +char guessingWord[sizeof(selectedWord)]; +char incoming = 0; + +int counter = 0; +int mistakes = 0; +int success = 0; +int chances = 3; + +void setup() +{ + // opens serial port, sets data rate to 9600 bps + Serial.begin(9600); + // to show the length of the word has to be guessed + for (int i = 0; i < sizeof(selectedWord) - 1; i++) + { + guessingWord[i] = '_'; + } + Serial.print("The Word you are looking for is: "); + Serial.println(guessingWord); +} + +void loop() +{ + + if (Serial.available() > 0) + { + incoming = Serial.read(); + // checking if it is a success or mistake + for (int i = 0; i < sizeof(selectedWord); i++) + { + if (incoming == selectedWord[i]) + { + guessingWord[i] = incoming; + success += 1; + } + else + { + counter = counter + 1; + } + } + + if (counter == sizeof(selectedWord)) + { + mistakes += 1; + Serial.println("Wrong letter!! Try again..."); + } + } + + // printing the state of the guess word + if (mistakes < chances) + { + Serial.print("The Word you are looking for is: "); + for (int i = 0; i < sizeof(selectedWord); i++) + { + Serial.print(guessingWord[i]); + } + Serial.print(" Mistakes: "); + Serial.println(mistakes); + counter = 0; + delay(1000); + } + + // finishing the game + else if (mistakes == chances) + { + Serial.println(); + Serial.println("Game Over"); + mistakes = 5; + } + + // end of the game + else + {} + + // winning + if (success == sizeof(selectedWord) - 1) + { + Serial.println(); + Serial.print("WINEER!!"); + success = 0; + mistakes = 5; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity1/SerialToPC_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity1/SerialToPC_Activity1.ino new file mode 100644 index 00000000..fd12b9f3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity1/SerialToPC_Activity1.ino @@ -0,0 +1,19 @@ +/* + CTC GO! CORE MODULE + LESSON 05 - Showing messages on PC + + This sketch is written to accompany Activity 1 in Lesson 05 of the CTC GO! core module +*/ + +void setup() +{ + // initialize digital serial communication at 9600baud. + Serial.begin(9600); +} + +void loop() +{ + //Printing a sentnce every second + Serial.println("Hello World!!"); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity2/SerialToPC_Activity2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity2/SerialToPC_Activity2.ino new file mode 100644 index 00000000..40a3e8c7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Lessons/SerialToPC/SerialToPC_Activity2/SerialToPC_Activity2.ino @@ -0,0 +1,38 @@ +/* + CTC GO! CORE MODULE + LESSON 05 - Showing messages on PC + + This sketch is written to accompany Activity 2 in Lesson 05 of the CTC GO! core module +*/ + + // initialising the pins and other variables. + int button = 2; + int button_state = 0; + int counter = 0; + + void setup() + { + Serial.begin(9600); + // Setting up the pins as OUTPUTS. + pinMode(button, INPUT); + } + + void loop() + { + button_state = digitalRead(button); + + //increase the value of counter one unit when button is pressed + if (button_state == HIGH) + { + counter += 1; + delay(500); + Serial.print("counter value = "); + Serial.println(counter); + + //Reset counter when it reaches 100 + if (counter == 100) + { + counter = 0; + } + } + } diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage1/ARGlasses_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage1/ARGlasses_Stage1.ino new file mode 100644 index 00000000..dc0d266b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage1/ARGlasses_Stage1.ino @@ -0,0 +1,28 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 1 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; + +int freq_1 = 500; + +void setup() +{ + pinMode(_____,_____); + pinMode(_____,_____); +} + +void loop() +{ + digitalWrite(yellowLED,_____); + _____(piezo,_____); + delay(100); + + digitalWrite(yellowLED,_____); + _____(piezo); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage2/ARGlasses_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage2/ARGlasses_Stage2.ino new file mode 100644 index 00000000..4f8076c1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage2/ARGlasses_Stage2.ino @@ -0,0 +1,40 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 2 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; + +int distanceSensor = A0 ; + +int freq_1 = 500; +int distanceSensorValue = 0; + +void setup() +{ + pinMode(piezo,OUTPUT); + pinMode(yellowLED,OUTPUT); + + Serial.begin(9600); +} + +void loop() +{ + + distanceSensorValue = _____(distanceSensor); + _____("Distance read: "); + Serial.println(_____); + + /* + //STEP 1; Blink the LED and Activate the Piezo + digitalWrite(yellowLED,HIGH); + tone(piezo,freq_1); + delay(100); + digitalWrite(yellowLED,LOW); + noTone(piezo); + delay(100); + */ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage3/ARGlasses_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage3/ARGlasses_Stage3.ino new file mode 100644 index 00000000..263dc08a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage3/ARGlasses_Stage3.ino @@ -0,0 +1,45 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 3 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; + +int distanceSensor = A0 ; + +int freq_1 = 500; +int distanceSensorValue = 0; +int actualDistanceMM = 0; + +void setup() +{ + pinMode(piezo, OUTPUT); + pinMode(yellowLED, OUTPUT); + Serial.begin(9600); +} + +void loop() +{ + + distanceSensorValue = analogRead(distanceSensor); + actualDistanceMM = map(distanceSensorValue, 0, 1023, _____, _____); + + Serial.print("Distance read: "); + Serial.println(_____); + Serial.print("Distance converted: "); + Serial.println(_____); + + /* + digitalWrite(yellowLED,HIGH); + tone(piezo,freq_1); + delay(100); + digitalWrite(yellowLED,LOW); + noTone(piezo,freq_1); + delay(100); + */ + + delay(_____); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage4/ARGlasses_Stage4.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage4/ARGlasses_Stage4.ino new file mode 100644 index 00000000..371d3b4d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage4/ARGlasses_Stage4.ino @@ -0,0 +1,44 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 4 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; +int distanceSensor = A0 ; + +int freq_1 = 500; +int distanceSensorValue = 0; +int actualDistanceMM = 0; +int actualDelay = 0; + +void setup() +{ + pinMode(piezo, OUTPUT); + pinMode(yellowLED, OUTPUT); + Serial.begin(9600); +} + +void loop() +{ + + distanceSensorValue = analogRead(distanceSensor); + + actualDistanceMM = map(distanceSensorValue,0,1023,0,3000); + + Serial.print("Distance read: "); + Serial.println(distanceSensorValue); + Serial.print("Distance converted: "); + Serial.println(actualDistanceMM); + + actualDelay = map(actualDistanceMM,_____,_____,_____,_____); + + digitalWrite(yellowLED,HIGH); + tone(piezo,freq_1); + delay(_____); + digitalWrite(yellowLED,LOW); + noTone(piezo); + delay(_____); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage5/ARGlasses_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage5/ARGlasses_Stage5.ino new file mode 100644 index 00000000..3e1a30b9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/ARGlasses/ARGlasses_Stage5/ARGlasses_Stage5.ino @@ -0,0 +1,55 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - AR GLASSES + + This sketch is written to accompany Stage 5 in AR GLASSES of the CTC GO! core module +*/ + +int piezo = 11; +int yellowLED = 13; +int redLED = 12; +int distanceSensor = A0 ; +int freq_1 = 500; +int distanceSensorValue = 0; +int actualDistanceMM = 0; +int actualDelay = 0; +int distance = 250; + +void setup() +{ + pinMode(piezo, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(redLED, OUTPUT); + + Serial.begin(9600); +} + +void loop() +{ + distanceSensorValue = analogRead(distanceSensor); + actualDistanceMM = map(distanceSensorValue, 0, 1023, 0, 3000); + Serial.print("Distance read: "); + Serial.println(distanceSensorValue); + Serial.print("Distance converted: "); + Serial.println(actualDistanceMM); + + actualDelay = map(actualDistanceMM,0,3000,0,1000); + + if (actualDistanceMM < _____) + { + digitalWrite(redLED, _____); + _____ (_____, freq_1); + delay(100); + digitalWrite(redLED, _____); + delay(100); + } + else if (actualDistanceMM > _____) + { + digitalWrite(yellowLED, _____); + tone(piezo, freq_1); + delay(actualDelay); + digitalWrite(yellowLED, _____); + noTone(piezo); + delay(actualDelay); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage1/CrazyDJ_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage1/CrazyDJ_Stage1.ino new file mode 100644 index 00000000..833a6d9f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage1/CrazyDJ_Stage1.ino @@ -0,0 +1,30 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - CRAZY DJ + + This sketch is written to accompany Stage 1 in CRAZY DJ of the CTC GO! core module +*/ + +//STEP 1; Variables for blue LED & light sensor +int lightSensor = A0; +int ledPin = 10; + +int lightValue = 0; +int LEDvalue = 0; + +void setup() +{ + _____(ledPin, _____); + Serial.begin(9600); +} + +void loop() +{ + lightValue = _____(lightSensor); + LEDvalue = map(lightValue, _____, _____, _____, _____); + analogWrite(ledPin, LEDvalue); + + Serial.print("Light value: "); + Serial.println(lightValue); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage2/CrazyDJ_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage2/CrazyDJ_Stage2.ino new file mode 100644 index 00000000..39db27e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage2/CrazyDJ_Stage2.ino @@ -0,0 +1,41 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - CRAZY DJ + + This sketch is written to accompany Stage 2 in CRAZY DJ of the CTC GO! core module +*/ + + +int lightSensor = A0; +int ledPin = 10; +int piezo = 9; + +int lightValue = 0; +int LEDvalue = 0; +int soundValue = 0; + +void setup() +{ + pinMode(ledPin, OUTPUT); + pinMode(_____, _____); + Serial.begin(9600); +} + +void loop() +{ + lightValue = analogRead(lightSensor); + LEDvalue = map(lightValue, 0, 1023, 0, 255); + analogWrite(ledPin, LEDvalue); + + soundValue = map(lightValue, _____, _____, _____, _____); + _____(piezo, _____); + delay(_____); + _____(piezo); + delay(_____); + + Serial.print("Light value: "); + Serial.print(lightValue); + Serial.print(" Sound frequence: "); + Serial.println(soundValue); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage3/CrazyDJ_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage3/CrazyDJ_Stage3.ino new file mode 100644 index 00000000..34aa31bd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage3/CrazyDJ_Stage3.ino @@ -0,0 +1,53 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - CRAZY DJ + + This sketch is written to accompany Stage 3 in CRAZY DJ of the CTC GO! core module +*/ + +int lightSensor = A0; +int on_pot = A1; +int off_pot = A2; +int ledPin = 10; +int piezo = 9; + +int lightValue = 0; +int LEDvalue = 0; +int soundValue = 0; +int onTime = 0; +int offTime = 0; + +void setup() +{ + pinMode(ledPin, OUTPUT); + pinMode(piezo, OUTPUT); + Serial.begin(9600); +} + +void loop() +{ + lightValue = analogRead(lightSensor); + LEDvalue = map(lightValue, 0, 1023, 0, 255); + analogWrite(ledPin, LEDvalue); + + onTime = _____; + offTime = _____; + + soundValue = map(lightValue, 0, 1023, 31, 4000); + + tone(piezo, soundValue); + delay(_____); + noTone(piezo); + delay(_____); + + Serial.print("Light value: "); + Serial.print(lightValue); + Serial.print(" Sound frequence: "); + Serial.println(soundValue); + Serial.print("Time ON: "); + Serial.print(_____); + Serial.print(" Time OFF: "); + Serial.println(_____); + + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage4/CrazyDJ_Stage4.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage4/CrazyDJ_Stage4.ino new file mode 100644 index 00000000..4ca4a1c1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/CrazyDJ/CrazyDJ_Stage4/CrazyDJ_Stage4.ino @@ -0,0 +1,54 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - CRAZY DJ + + This sketch is written to accompany Stage 4 in CRAZY DJ of the CTC GO! core module +*/ + +int lightSensor = A0; +int on_pot = A1; +int off_pot = A2; +int av_pot = A3; +int ledPin = 10; +int piezo = 9; + +int lightValue = 0; +int LEDvalue = 0; +int soundValue = 0; +int onTime = 0; +int offTime = 0; +int avPitch = 0; + +void setup() +{ + pinMode(ledPin, OUTPUT); + pinMode(piezo, OUTPUT); + Serial.begin(9600); +} + +void loop() +{ + lightValue = analogRead(lightSensor); + LEDvalue = map(lightValue, 0, 1023, 0, 255); + analogWrite(ledPin, LEDvalue); + + onTime = analogRead(on_pot); + offTime = analogRead(off_pot); + + avPitch = _____; + soundValue = map(_____, 0, 1023, 31, 4000); + + tone(piezo, soundValue); + delay(onTime); + noTone(piezo); + delay(offTime); + + Serial.print("Light value: "); + Serial.print(lightValue); + Serial.print(" Sound frequence: "); + Serial.println(soundValue); + Serial.print("Time ON: "); + Serial.print(onTime); + Serial.print(" Time OFF: "); + Serial.println(offTime); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage1/FingerRace_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage1/FingerRace_Stage1.ino new file mode 100644 index 00000000..ecc76faa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage1/FingerRace_Stage1.ino @@ -0,0 +1,27 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 1 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int button_P1 = 6; + +void setup() +{ + pinMode(greenLED_P1, _____); + pinMode(button_P1, _____); +} + +void loop() +{ + if ( digitalRead(button_P1) == HIGH) + { + digitalWrite(greenLED_P1, _____); + } + else + { + digitalWrite(greenLED_P1, _____); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage2/FingerRace_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage2/FingerRace_Stage2.ino new file mode 100644 index 00000000..dc19faf6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage2/FingerRace_Stage2.ino @@ -0,0 +1,41 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 2 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int button_P1 = 6; +int greenLED_P2 = 9; +int button_P2 = 7; + +void setup() +{ + pinMode(greenLED_P1, OUTPUT); + pinMode(greenLED_P2, _____); + pinMode(button_P2, INPUT); + pinMode(button_P1, _____); + +} + +void loop() { + + if ( digitalRead(button_P1) == HIGH) + { + digitalWrite(greenLED_P1, HIGH); + } + else + { + digitalWrite(greenLED_P1, LOW); + } + + if ( digitalRead(_____) == _____) + { + digitalWrite(_____,_____); + } + else + { + digitalWrite(_____,_____); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage3/FingerRace_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage3/FingerRace_Stage3.ino new file mode 100644 index 00000000..feec0f60 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage3/FingerRace_Stage3.ino @@ -0,0 +1,74 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 3 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int greenLED_P2 = 9; + +int button_P1 = 6; +int button_P2 = 7; + +int blueLED_P1 = 12; +int blueLED_P2 = 10; + +int gameState = 0; + +void setup() +{ + pinMode(greenLED_P1, OUTPUT); + pinMode(blueLED_P1, _____); + pinMode(blueLED_P2, _____); + pinMode(greenLED_P2, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() +{ + + if (gameState == _____) + { + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + delay(200); + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + delay(200); + } + else if (gameState == 1) + { + + } + else if (gameState == 2) + { + + } + + if ( digitalRead(button_P1) == HIGH) + { + gameState = _____; + digitalWrite(greenLED_P1, HIGH); + } + else + { + digitalWrite(greenLED_P1, LOW); + } + + if ( digitalRead(button_P2) == HIGH) + { + gameState = _____; + digitalWrite(greenLED_P2, HIGH); + } + else + { + digitalWrite(greenLED_P2, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage4/FingerRace_Stage4.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage4/FingerRace_Stage4.ino new file mode 100644 index 00000000..9f4d1267 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage4/FingerRace_Stage4.ino @@ -0,0 +1,121 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 4 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int blueLED_P1 = 12; + +int blueLED_P2 = 10; +int greenLED_P2 = 9; + +int button_P1 = 6; +int button_P2 = 7; + +int gameState = 0; + +int player_1 = 0; +int player_2 = 0; + +void setup() +{ + pinMode(greenLED_P1, OUTPUT); + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED_P2, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() +{ + + if (gameState == 0) + { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED_P2, HIGH); + delay(200); + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + delay(200); + } + + else if(gameState == 1) + { + + } + + else if (gameState == 2) + { + if (_____ ) + { + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + } + else if (_____) + { + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + } + else + { + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + } + if (_____) + { + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + + delay(_____); + gameState = _____; + player_1 = _____; + player_2 = _____; + } + if (_____) + { + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + + delay(_____); + gameState = _____; + player_1 = _____; + player_2 = _____; + } + } + + + if ( digitalRead(button_P1) == HIGH) + { + gameState = 2; + digitalWrite(greenLED_P1, HIGH); + player_1 = _____; + } + + else + { + digitalWrite(greenLED_P1, LOW); + } + + if ( digitalRead(button_P2) == HIGH) + { + gameState = 2; + digitalWrite(greenLED_P2, HIGH); + player_2 = _____; + } + else + { + digitalWrite(greenLED_P2, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage5/FingerRace_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage5/FingerRace_Stage5.ino new file mode 100644 index 00000000..b944fd86 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage5/FingerRace_Stage5.ino @@ -0,0 +1,137 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 5 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int blueLED_P1 = 12; + +int blueLED_P2 = 10; +int greenLED_P2 = 9; + +int button_P1 = 6; +int button_P2 = 7; + +int gameState = 0; + +int player_1 = 0; +int player_2 = 0; + +int previousButtonState_P1 = 0; +int previousButtonState_P2 = 0; + +void setup() +{ + pinMode(greenLED_P1, OUTPUT); + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED_P2, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() +{ + + if (gameState == 0) + { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED_P2, HIGH); + delay(200); + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + delay(200); + } + else if(gameState == 1) + { + + } + else if (gameState == 2) + { + if (player_1 > player_2) + { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, LOW); + } + else if (player_2 > player_1) + { + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, HIGH); + } + else + { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + } + + if (player_1 > 30) + { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + + delay(3000); + gameState = 0; + player_1 = 0; + player_2 = 0; + } + + if (player_2 > 30) + { + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, HIGH); + + delay(3000); + gameState = 0; + player_1 = 0; + player_2 = 0; + } + } + else if (gameState == 2) + { + } + + if ( digitalRead(button_P1) == HIGH) + { + gameState = 2; + digitalWrite(greenLED_P1, HIGH); + + if (previousButtonState_P1 == _____) + { + player_1 = player_1 + 1; + } + previousButtonState_P1 = _____; + } + + else + { + digitalWrite(greenLED_P1, LOW); + previousButtonState_P1 = HIGH; + } + + if ( digitalRead(button_P2) == HIGH) + { + gameState = 2; + digitalWrite(greenLED_P2, HIGH); + if (previousButtonState_P2 == _____) + { + player_2 = player_2 + 1; + } + previousButtonState_P2 = _____; + } + else + { + digitalWrite(greenLED_P2, LOW); + previousButtonState_P2 = _____; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage6/FingerRace_Stage6.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage6/FingerRace_Stage6.ino new file mode 100644 index 00000000..3b3c4d5f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/FingerRace/FingerRace_Stage6/FingerRace_Stage6.ino @@ -0,0 +1,166 @@ +/* + CTC GO! - CORE MODULE + PROJECT 1 - Finger Race + + This sketch is written to accompany Stage 6 in Finger Race of the CTC GO! Core Module +*/ + +int greenLED_P1 = 13; +int blueLED_P1 = 12; + +int blueLED_P2 = 10; +int greenLED_P2 = 9; + +int button_P1 = 6; +int button_P2 = 7; + +int gameState = 0; +int previousButtonState_P1 = 0; +int previousButtonState_P2 = 0; +int player_1 = 0; +int player_2 = 0; + +void setup() +{ + pinMode(greenLED_P1, OUTPUT); + pinMode(blueLED_P1, OUTPUT); + pinMode(blueLED_P2, OUTPUT); + pinMode(greenLED_P2, OUTPUT); + + pinMode(button_P1, INPUT); + pinMode(button_P2, INPUT); +} + +void loop() +{ + if (gameState == 0) + { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED_P2, HIGH); + delay(200); + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + delay(200); + } + else if (gameState == 1) { + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + delay( _____); + digitalWrite(greenLED_P1, _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED_P2, _____); + delay( _____); + digitalWrite(greenLED_P1, _____); + digitalWrite(greenLED_P2, _____); + delay( _____); + digitalWrite(greenLED_P1, _____); + digitalWrite(greenLED_P2, _____); + delay( _____); + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + delay( _____); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + + player_1 = _____; + player_2 = _____; + gameState = _____; + } + else if (gameState == 2) + { + + if (player_1 > player_2) + { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, LOW); + } + + else if (player_2 > player_1) + { + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, HIGH); + } + + else + { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + } + + if (player_1 > 30) + { + digitalWrite(greenLED_P1, HIGH); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, LOW); + delay(3000); + + gameState = 0; + player_1 = 0; + player_2 = 0; + } + + if (player_2 > 30) + { + digitalWrite(greenLED_P1, LOW); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED_P2, HIGH); + delay(3000); + gameState = 0; + player_1 = 0; + player_2 = 0; + } + } + + delay(5); + + if ( digitalRead(button_P1) == HIGH) + { + if (gameState == _____) + { + gameState = _____1; + } + digitalWrite(greenLED_P1, HIGH); + + if (previousButtonState_P1 == LOW) + { + player_1 = player_1 + 1; + } + previousButtonState_P1 = HIGH; + } + + else + { + + digitalWrite(greenLED_P1, LOW); + previousButtonState_P1 = LOW; + } + + if ( digitalRead(button_P2) == HIGH) + { + if (gameState == _____) + { + gameState = _____; + } + + digitalWrite(greenLED_P2, HIGH); + if (previousButtonState_P2 == LOW) + { + player_2 = player_2 + 1; + } + previousButtonState_P2 = HIGH; + } + else + { + digitalWrite(greenLED_P2, LOW); + previousButtonState_P2 = LOW; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage1/MorseAlien_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage1/MorseAlien_Stage1.ino new file mode 100644 index 00000000..d0e12fa9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage1/MorseAlien_Stage1.ino @@ -0,0 +1,36 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 1 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; + +void setup() +{ + pinMode(_____,_____); + Serial.begin(9600); +} + +void loop() +{ + + int distanceSensorValue = _____(distanceSensor); + + int actualDistanceMM = map(_____,0,1023,0,3000); + + Serial.print(_____); + Serial.print(","); + Serial.println(_____); + + if (_____<200) + { + digitalWrite(_____,HIGH); + } + _____ + { + digitalWrite(_____,LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage2/MorseAlien_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage2/MorseAlien_Stage2.ino new file mode 100644 index 00000000..2ea3eab0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage2/MorseAlien_Stage2.ino @@ -0,0 +1,86 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 2 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; +int breakButton = 10; +int recordButton = 12; +int playButton = 11; +int piezo = 8; + +int prevBreakButtonState = LOW; +int prevRecordButtonState = LOW; +int prevPlayButtonState = LOW; + +void setup() +{ + pinMode(blueLED,OUTPUT); + pinMode(breakButton,_____); + pinMode(recordButton,_____); + pinMode(playButton,_____); + pinMode(piezo, _____); + + Serial.begin(9600); +} + +void loop() +{ + int distanceSensorValue = analogRead(distanceSensor); + int actualDistanceMM = map(distanceSensorValue,0,1023,0,3000); + + if (distanceSensorValue < 200) + { + digitalWrite(blueLED,HIGH); + } + else + { + digitalWrite(blueLED,LOW); + } + + if (digitalRead(_____) == _____) + { + if (prevRecordButtonState == _____) + { + Serial.println("_____"); + tone(_____, 1000); + } + prevRecordButtonState = _____; + } + else + { + prevRecordButtonState = _____; + } + + if (_____ == _____) + { + if (prevBreakButtonState == _____) + { + Serial.println(_____); + tone(_____, _____); + } + prevBreakButtonState = _____; + } + else + { + prevBreakButtonState = _____; + } + + if (_____ == _____) + { + if (prevPlayButtonState == _____) + { + Serial.println(_____); + tone(_____, _____); + } + _____ = _____; + } + else + { + _____ = _____; + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage3/MorseAlien_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage3/MorseAlien_Stage3.ino new file mode 100644 index 00000000..162ddcc6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage3/MorseAlien_Stage3.ino @@ -0,0 +1,128 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 3 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; +int breakButton = 10; +int recordButton = 12; +int playButton = 11; +int piezo = 8; + +int prevBreakButtonState = LOW; +int prevRecordButtonState = LOW; +int prevPlayButtonState = LOW; + +int mySymbols[50]; +int symbolIndex = 0; +int symbolLength = 300; +int currentSymbol = 0; +int sequencePlayed = false; + +int DASH = 2; +int DOT = 1; +int freq_DASH = 1500 ; +int freq_DOT = 1000 ; + +void setup() +{ + pinMode(blueLED,OUTPUT); + pinMode(breakButton,INPUT); + pinMode(recordButton,INPUT); + pinMode(playButton,INPUT); + pinMode(piezo, OUTPUT); + + Serial.begin(9600); +} + +void loop() +{ + int distanceSensorValue = analogRead(distanceSensor); + int actualDistanceMM = map(distanceSensorValue,0,1023,0,3000); + + if (distanceSensorValue < 200) + { + digitalWrite(blueLED,HIGH); + currentSymbol = _____; + } + else + { + digitalWrite(blueLED,LOW); + currentSymbol = _____; + } + + if (digitalRead(recordButton) == HIGH) + { + if (prevRecordButtonState == LOW) + { + Serial.print("ADDING SYMBOL"); + Serial.print(_____); + Serial.print(" "); + Serial.println(_____); + digitalWrite(blueLED, LOW); + delay(symbolLength); + + if (currentSymbol == _____) + { + digitalWrite(_____, _____); + tone(_____, freq_DOT); + delay(symbolLength); + digitalWrite(_____, _____); + } + else if (currentSymbol == DASH) + { + digitalWrite(_____, _____); + tone(piezo, _____ ); + delay(symbolLength * 3); + digitalWrite(_____, _____); + } + } + prevRecordButtonState = HIGH; + + /* + Add the symbol to the array + */ + if (sequencePlayed == true) + { + sequencePlayed = _____; + symbolIndex = _____; + } + mySymbols[ _____ ] = _____; + symbolIndex = _____; + } + else + { + prevRecordButtonState = LOW; + } + + if (digitalRead(breakButton) == HIGH) + { + if (prevBreakButtonState == LOW) + { + Serial.println("ADDING BREAK"); + tone(piezo, 1000); + } + prevBreakButtonState = HIGH; + } + else + { + prevBreakButtonState = LOW; + } + + if (digitalRead(playButton) == HIGH) + { + if (prevPlayButtonState == LOW) + { + Serial.println("START PLAYING SYMBOLS"); + tone(piezo, 1000); + } + prevPlayButtonState = HIGH; + } + else + { + prevPlayButtonState = LOW; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage4/MorseAlien_Stage4.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage4/MorseAlien_Stage4.ino new file mode 100644 index 00000000..179f905a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage4/MorseAlien_Stage4.ino @@ -0,0 +1,144 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 4 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; +int breakButton = 10; +int recordButton = 12; +int playButton = 11; +int piezo = 8; + +int prevBreakButtonState = LOW; +int prevRecordButtonState = LOW; +int prevPlayButtonState = LOW; + +int mySymbols[50]; +int symbolIndex = 0; +int symbolLength = 300; +int currentSymbol = 0; +int sequencePlayed = false; + +int DASH = 2; +int DOT = 1; +int BREAK = 0; + +int freq_DASH = 1500 ; +int freq_DOT = 1000 ; +int freq_BREAK = 500 ; + +void setup() +{ + pinMode(blueLED,OUTPUT); + pinMode(breakButton,INPUT); + pinMode(recordButton,INPUT); + pinMode(playButton,INPUT); + pinMode(piezo, OUTPUT); + + Serial.begin(9600); +} + +void loop() +{ + int distanceSensorValue = analogRead(distanceSensor); + int actualDistanceMM = map(distanceSensorValue,0,1023,0,3000); + + if (distanceSensorValue < 200) + { + digitalWrite(blueLED,HIGH); + currentSymbol = DASH; + } + else + { + digitalWrite(blueLED,LOW); + currentSymbol = DOT; + } + + if (digitalRead(recordButton) == HIGH) + { + if (prevRecordButtonState == LOW) + { + Serial.print("ADDING SYMBOL"); + Serial.print(symbolIndex); + Serial.print(" "); + Serial.println(currentSymbol); + + digitalWrite(blueLED, LOW); + delay(symbolLength); + if (currentSymbol == DOT) + { + digitalWrite(blueLED, HIGH); + tone(piezo, freq_DOT); + delay(symbolLength); + digitalWrite(blueLED, LOW); + } + else if (currentSymbol == DASH) + { + digitalWrite(blueLED, HIGH); + tone(piezo, freq_DASH); + delay(symbolLength * 3); + digitalWrite(blueLED, LOW); + } + } + prevRecordButtonState = HIGH; + + /* + Add the symbol to the array + */ + //If the sequence played already, start recording from scratch + if (sequencePlayed == true) + { + sequencePlayed = false; + symbolIndex = 0; + } + mySymbols[symbolIndex] = currentSymbol; + symbolIndex = symbolIndex + 1; + } + else + { + prevRecordButtonState = LOW; + } + + if (digitalRead(breakButton) == HIGH) + { + if (prevBreakButtonState == LOW) + { + Serial.print("ADDING BREAK"); + currentSymbol = _____; + Serial.print(_____); + Serial.print(" "); + Serial.println(_____); + tone(piezo, freq_BREAK ); + delay(symbolLength * 3); + + if (sequencePlayed == true) + { + symbolIndex = _____; + } + mySymbols[_____] = _____; + symbolIndex = symbolIndex + 1; + } + prevBreakButtonState = HIGH; + } + else + { + prevBreakButtonState = LOW; + } + + if (digitalRead(playButton) == HIGH) + { + if (prevPlayButtonState == LOW) + { + Serial.println("START PLAYING SYMBOLS"); + tone(piezo, 1000); + } + prevPlayButtonState = HIGH; + } + else + { + prevPlayButtonState = LOW; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage5/MorseAlien_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage5/MorseAlien_Stage5.ino new file mode 100644 index 00000000..4dea602a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/MorseAlien/MorseAlien_Stage5/MorseAlien_Stage5.ino @@ -0,0 +1,168 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - MORSE ALIEN + + This sketch is written to accompany Stage 5 in MORSE ALIEN of the CTC GO! core module +*/ + +int distanceSensor = A0; +int blueLED = 13; +int breakButton = 10; +int recordButton = 12; +int playButton = 11; +int piezo = 8; + +int prevBreakButtonState = LOW; +int prevRecordButtonState = LOW; +int prevPlayButtonState = LOW; + +int mySymbols[50]; +int symbolIndex = 0; +int symbolLength = 300; +int currentSymbol = 0; +int sequencePlayed = false; + +int DASH = 2; +int DOT = 1; +int BREAK = 0; + +int freq_DASH = 1500 ; +int freq_DOT = 1000 ; +int freq_BREAK = 500 ; + +void setup() +{ + pinMode(blueLED,OUTPUT); + pinMode(breakButton,INPUT); + pinMode(recordButton,INPUT); + pinMode(playButton,INPUT); + pinMode(piezo, OUTPUT); + + Serial.begin(9600); +} + +void loop() +{ + int distanceSensorValue = analogRead(distanceSensor); + int actualDistanceMM = map(distanceSensorValue,0,1023,0,3000); + + if (distanceSensorValue < 200) + { + digitalWrite(blueLED,HIGH); + currentSymbol = DASH; + } + else + { + digitalWrite(blueLED,LOW); + currentSymbol = DOT; + } + + if (digitalRead(recordButton) == HIGH) + { + if (prevRecordButtonState == LOW) + { + Serial.print("ADDING SYMBOL "); + Serial.print(symbolIndex); + Serial.print(" "); + Serial.println(currentSymbol); + + digitalWrite(blueLED, LOW); + delay(symbolLength); + + if (currentSymbol == DOT) + { + digitalWrite(blueLED, HIGH); + tone(piezo, freq_DOT); + delay(symbolLength); + digitalWrite(blueLED, LOW); + } + else if (currentSymbol == DASH) + { + digitalWrite(blueLED, HIGH); + tone(piezo, freq_DASH ); + delay(symbolLength * 3); + digitalWrite(blueLED, LOW); + } + } + prevRecordButtonState = HIGH; + + if (sequencePlayed == true) + { + sequencePlayed = false; + symbolIndex = 0; + } + mySymbols[symbolIndex] = currentSymbol; + symbolIndex = symbolIndex + 1; + } + else + { + prevRecordButtonState = LOW; + } + + if (digitalRead(breakButton) == HIGH) + { + if (prevBreakButtonState == LOW) + { + Serial.print("ADDING BREAK"); + currentSymbol = BREAK; + Serial.print(symbolIndex); + Serial.println(currentSymbol); + tone(piezo, freq_BREAK); + delay(symbolLength * 3); + /* + Add the symbol to the array + */ + //If the sequence played already, start recording from scratch + if (sequencePlayed == true) + { + symbolIndex = 0; + } + mySymbols[symbolIndex] = currentSymbol; + symbolIndex = symbolIndex + 1; + } + prevBreakButtonState = HIGH; + } + else + { + prevBreakButtonState = LOW; + } + + if (digitalRead(playButton) == HIGH) + { + if (prevPlayButtonState == LOW) + { + Serial.println("START PLAYING SYMBOLS"); + sequencePlayed = true; + for (int i = 0; i < symbolIndex; i++) + { + digitalWrite(blueLED, LOW); + delay(symbolLength); + + if (mySymbols[i] == _____) + { + digitalWrite(_____, _____); + tone(piezo, _____ ); + delay(_____); + digitalWrite(_____, _____); + } + else if (_____ == DASH) + { + digitalWrite(_____, _____); + tone(_____, _____); + delay(_____); + digitalWrite(_____, _____); + } + else if (mySymbols[i] == _____) + { + digitalWrite(_____, _____); + delay(_____); + } + } + prevPlayButtonState = HIGH; + } + } + else + { + prevPlayButtonState = LOW; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage1/PersonalTrainer_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage1/PersonalTrainer_Stage1.ino new file mode 100644 index 00000000..97c1ba61 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage1/PersonalTrainer_Stage1.ino @@ -0,0 +1,34 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 1 in PERSONAL TRAINER of the CTC GO! core module +*/ + + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; + +void setup(){ + + pinMode(ledCounter_1, _____); + pinMode(ledCounter_2, _____); + pinMode(ledCounter_3, _____); +} + +void loop(){ + + digitalWrite(ledCounter_1,_____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + delay(100); + digitalWrite(ledCounter_1, _____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + delay(100); + digitalWrite(ledCounter_1, _____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage2/PersonalTrainer_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage2/PersonalTrainer_Stage2.ino new file mode 100644 index 00000000..a0cc5e35 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage2/PersonalTrainer_Stage2.ino @@ -0,0 +1,47 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 2 in PERSONAL TRAINER of the CTC GO! core module +*/ + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; +int distanceSensor = A0; + +int distanceSensorValue; +int currentDistanceMM = 0; +int lastDistance = 0; + +void setup(){ + pinMode(ledCounter_1, OUTPUT); + pinMode(ledCounter_2, OUTPUT); + pinMode(ledCounter_3, OUTPUT); + + Serial.begin(_____); +} + +void loop() +{ + + digitalWrite(ledCounter_1,HIGH); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, HIGH); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, HIGH); + delay(100); + + distanceSensorValue = analogRead(_____); + currentDistanceMM = map(_____,_____,_____,0,3000); + Serial.println(_____); + + lastDistance = currentDistanceMM; + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage3/PersonalTrainer_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage3/PersonalTrainer_Stage3.ino new file mode 100644 index 00000000..08ace3f2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage3/PersonalTrainer_Stage3.ino @@ -0,0 +1,70 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 3 in PERSONAL TRAINER of the CTC GO! core module +*/ + + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; +int distanceSensor = A0; +int incrementButton = 8; + +int distanceSensorValue; +int currentDistanceMM = 0; +int lastDistance = 0; + +int incrementButtonState = LOW; +int lastIncrementButtonState = LOW; +int stepCounter = 30; + +void setup(){ + + pinMode(ledCounter_1, OUTPUT); + pinMode(ledCounter_2, OUTPUT); + pinMode(ledCounter_3, OUTPUT); + pinMode(incrementButton, INPUT); + Serial.begin(9600); + +} + +void loop(){ + + digitalWrite(ledCounter_1,HIGH); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, HIGH); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, HIGH); + delay(100); + + distanceSensorValue = analogRead(distanceSensor); + currentDistanceMM = map(distanceSensorValue,0,1023,0,3000); + //Serial.println(currentDistanceMM); + + incrementButtonState = digitalRead(_____); + + if (_____ == HIGH && lastIncrementButtonState == _____) + { + if (_____) + { + Serial.println("increase the stepCounter by 10"); + stepCounter += _____; + }else + { + stepCounter = _____; + } + Serial.print("stepCounter is "); + Serial.println(stepCounter); + } + lastIncrementButtonState = incrementButtonState; + + lastDistance = currentDistanceMM; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage4/PersonalTrainer_Stage4.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage4/PersonalTrainer_Stage4.ino new file mode 100644 index 00000000..5c7709f0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage4/PersonalTrainer_Stage4.ino @@ -0,0 +1,112 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 4 in PERSONAL TRAINER of the CTC GO! core module +*/ + + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; +int distanceSensor = A0; +int incrementButton = 8; +int piezo = 6; + +int distanceSensorValue; +int currentDistanceMM = 0; +int lastDistance = 0; + +int incrementButtonState = LOW; +int lastIncrementButtonState = LOW; +int stepCounter = 30; + +int freq_1 = 1000; +int freq_2 = 1500; + +void setup(){ + + pinMode(ledCounter_1, OUTPUT); + pinMode(ledCounter_2, OUTPUT); + pinMode(ledCounter_3, OUTPUT); + pinMode(incrementButton, INPUT); + pinMode(piezo, OUTPUT); + Serial.begin(9600); + +} + +void loop(){ + /* + digitalWrite(ledCounter_1,HIGH); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, HIGH); + digitalWrite(ledCounter_3, LOW); + delay(100); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, HIGH); + delay(100); + */ + + distanceSensorValue = analogRead(distanceSensor); + currentDistanceMM = map(distanceSensorValue,0,1023,0,3000); + //Serial.println(currentDistanceMM); + + incrementButtonState = digitalRead(incrementButton); + if (incrementButtonState == HIGH && lastIncrementButtonState == LOW){ + Serial.println("increase the stepCounter by 10"); + if (stepCounter < 30){ + stepCounter += 10; + //STEP 4; make a litte sound to indicate a button press + tone(piezo, freq_2); + delay(100); + noTone(piezo); + }else{ + stepCounter = 10; + //STEP 4; make two sounds to indicate an overflow + tone(piezo,freq_1); + delay(100); + noTone(piezo); + delay(100); + tone(piezo,freq_1); + delay(100); + noTone(piezo); + } + Serial.print("stepCounter is "); + Serial.println(stepCounter); + } + lastIncrementButtonState = incrementButtonState; + + if (lastDistance > 200 && currentDistanceMM < 200){ + Serial.println("decrease the stepCounter with one"); + stepCounter = stepCounter - 1; + Serial.print("stepCounter is "); + Serial.println(_____); + digitalWrite(ledCounter_1, _____); + digitalWrite(ledCounter_2, _____); + digitalWrite(ledCounter_3, _____); + tone(piezo,freq_2); + delay(100); + noTone(piezo); + delay(100); + } + + digitalWrite(ledCounter_1,_____); + digitalWrite(ledCounter_2,_____); + digitalWrite(ledCounter_3,_____); + if (stepCounter > 0) + { + digitalWrite(ledCounter_1, _____); + } + if (stepCounter > 10){ + digitalWrite(ledCounter_2, _____); + } + if (stepCounter > 20){ + digitalWrite(ledCounter_3, _____); + } + + lastDistance = currentDistanceMM; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage5/PersonalTrainer_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage5/PersonalTrainer_Stage5.ino new file mode 100644 index 00000000..967ba78b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PersonalTrainer/PersonalTrainer_Stage5/PersonalTrainer_Stage5.ino @@ -0,0 +1,113 @@ +/* + CTC GO! CORE MODULE + PROJECT 2 - PERSONAL TRAINER + + This sketch is written to accompany Stage 5 in PERSONAL TRAINER of the CTC GO! core module +*/ + + +int ledCounter_1 = 2; +int ledCounter_2 = 3; +int ledCounter_3 = 4; +int distanceSensor = A0; +int incrementButton = 8; +int piezo = 6; + +int currentDistanceMM = 0; +int distanceSensorValue; +int lastDistance = 0; + +int incrementButtonState = LOW; +int lastIncrementButtonState = LOW; +int stepCounter = 30; + +int freq_1 = 1000; +int freq_2 = 1500; +int freq_3 = 2000; + +void setup(){ + + pinMode(ledCounter_1, OUTPUT); + pinMode(ledCounter_2, OUTPUT); + pinMode(ledCounter_3, OUTPUT); + pinMode(incrementButton, INPUT); + pinMode(piezo, OUTPUT); + + Serial.begin(9600); + +} + +void loop(){ + + distanceSensorValue = analogRead(distanceSensor); + currentDistanceMM = map(distanceSensorValue,0,1023,0,3000); + + incrementButtonState = digitalRead(incrementButton); + if (incrementButtonState == HIGH && lastIncrementButtonState == LOW){ + Serial.println("increase the stepCounter by 10"); + if (stepCounter < 30){ + stepCounter = stepCounter + 10; + tone(piezo, freq_2); + delay(100); + noTone(piezo); + }else{ + stepCounter = 10; + tone(piezo,freq_1); + delay(100); + noTone(piezo); + delay(100); + tone(piezo,freq_1); + delay(100); + noTone(piezo); + } + Serial.print("stepCounter is "); + Serial.println(stepCounter); + } + lastIncrementButtonState = incrementButtonState; + + if (lastDistance > 200 && currentDistanceMM < 200){ + Serial.println("decrease the stepCounter with one"); + stepCounter = stepCounter - 1; + Serial.print("stepCounter is "); + Serial.println(stepCounter); + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + tone(piezo,freq_2); + delay(100); + noTone(piezo); + delay(100); + } + + digitalWrite(ledCounter_1, LOW); + digitalWrite(ledCounter_2, LOW); + digitalWrite(ledCounter_3, LOW); + + if (stepCounter <= 0) + { + Serial.println("Woopwoop, you succeeded"); + tone(piezo,_____); + delay(100); + noTone(_____); + delay(100); + tone(piezo,_____); + delay(200); + noTone(_____); + digitalWrite(_____, _____); + digitalWrite(_____, _____); + digitalWrite(_____, _____); + } + else + { + if (stepCounter > 0){ + digitalWrite(ledCounter_1, HIGH); + } + if (stepCounter > 10){ + digitalWrite(ledCounter_2, HIGH); + } + if (stepCounter > 20){ + digitalWrite(ledCounter_3, HIGH); + } + } + lastDistance = currentDistanceMM; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage1/Pinball_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage1/Pinball_Stage1.ino new file mode 100644 index 00000000..77d1668b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage1/Pinball_Stage1.ino @@ -0,0 +1,33 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 1 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; + +void setup() +{ + pinMode (blueLED_1, _____); + pinMode (blueLED_2, _____); + pinMode (redLED, _____); + pinMode (greenLED, _____); +} + +void loop() +{ + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2,_____); + digitalWrite(redLED,_____); + digitalWrite(greenLED,_____); + delay(1000); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2,LOW); + digitalWrite(redLED,LOW); + digitalWrite(greenLED,LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage2/Pinball_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage2/Pinball_Stage2.ino new file mode 100644 index 00000000..6e4c95d8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage2/Pinball_Stage2.ino @@ -0,0 +1,57 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 2 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; + +int button_1 = 7; +int button_2 = 6; + +void setup() +{ + pinMode (blueLED_1, OUTPUT); + pinMode (blueLED_2, OUTPUT); + pinMode (redLED, OUTPUT); + pinMode (greenLED, OUTPUT); + + pinMode (button_1, _____); + pinMode (button_2, _____); +} + +void loop() { + + /* + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2,HIGH); + digitalWrite(redLED,HIGH); + digitalWrite(greenLED,HIGH); + delay(1000); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2,LOW); + digitalWrite(redLED,LOW); + digitalWrite(greenLED,LOW); + delay(1000); + */ + + if ( digitalRead(button_1) == _____) + { + digitalWrite(greenLED, _____); + delay(_____); + } + + if ( digitalRead(_____) == _____ ) + { + digitalWrite(blueLED_1, _____); + delay(_____); + } + + digitalWrite(blueLED_1, _____); + digitalWrite(greenLED, _____); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage3/Pinball_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage3/Pinball_Stage3.ino new file mode 100644 index 00000000..e7ab0dac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage3/Pinball_Stage3.ino @@ -0,0 +1,62 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 3 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; +int button_1 = 7; +int button_2 = 6; + +int losing = 0; +int winning = 0; + +void setup() +{ + pinMode (blueLED_1, OUTPUT); + pinMode (blueLED_2, OUTPUT); + pinMode (redLED, OUTPUT); + pinMode (greenLED, OUTPUT); + pinMode (button_1, INPUT); + pinMode (button_2, INPUT); +} + +void loop() { + +if ( digitalRead(button_1) == HIGH ) + { + digitalWrite(greenLED, HIGH); + winning = _____; + delay(_____); + } + + if ( digitalRead(button_2) == HIGH ) + { + digitalWrite(blueLED_1, HIGH); + losing = _____; + delay(_____); + } + + digitalWrite(blueLED_1, LOW); + digitalWrite(greenLED, LOW); + + if(losing == _____ && winning == _____) + { + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2,HIGH); + digitalWrite(redLED,HIGH); + digitalWrite(greenLED,HIGH); + delay(1000); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2,LOW); + digitalWrite(redLED,LOW); + digitalWrite(greenLED,LOW); + delay(1000); + } + + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage4/Pinball_Stage4.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage4/Pinball_Stage4.ino new file mode 100644 index 00000000..410e128a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage4/Pinball_Stage4.ino @@ -0,0 +1,93 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 4 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; + +int button_1 = 7; +int button_2 = 6; + +int losing = 0; +int winning = 0; + +void setup() +{ + pinMode (blueLED_1, OUTPUT); + pinMode (blueLED_2, OUTPUT); + pinMode (redLED, OUTPUT); + pinMode (greenLED, OUTPUT); + pinMode (button_1, INPUT); + pinMode (button_2, INPUT); +} + +void loop() { + + + if ( digitalRead(button_1) == HIGH ) + { + winning = 1; + delay(2000); + } + + if ( digitalRead(button_2) == HIGH ) + { + losing = losing + 1; + delay(2000); + } + + if(losing == 0 && winning == 0) + { + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2,HIGH); + digitalWrite(redLED,HIGH); + digitalWrite(greenLED,HIGH); + delay(1000); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2,LOW); + digitalWrite(redLED,LOW); + digitalWrite(greenLED,LOW); + delay(1000); + } + + else if (losing == 1) + { + digitalWrite(_____, _____); + delay(1500); + } + else if (losing == 2) + { + digitalWrite(_____, _____); + delay(1500); + } + else if (losing == 3) + { + digitalWrite(redLED, HIGH); + digitalWrite(greenLED, LOW); + delay(_____); + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2, _____); + digitalWrite(redLED, _____); + delay(_____); + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2, _____); + digitalWrite(redLED, _____); + delay(_____); + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2,_____); + digitalWrite(redLED, _____); + delay(_____); + digitalWrite(blueLED_1, _____); + digitalWrite(blueLED_2, _____); + digitalWrite(redLED, _____); + delay(_____); + + losing = _____; + winning = _____; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage5/Pinball_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage5/Pinball_Stage5.ino new file mode 100644 index 00000000..3b07bfe7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/PinBall/Pinball_Stage5/Pinball_Stage5.ino @@ -0,0 +1,112 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - Pinball + + This sketch is written to accompany Stage 5 in Pinball of the CTC GO! core module +*/ + +int blueLED_1 = 11; +int blueLED_2 = 12; +int redLED = 13; +int greenLED = 9; + +int button_1 = 7; +int button_2 = 6; + +int losing = 0; +int winning = 0; + +void setup() +{ + pinMode (blueLED_1, OUTPUT); + pinMode (blueLED_2, OUTPUT); + pinMode (redLED, OUTPUT); + pinMode (greenLED, OUTPUT); + + pinMode (button_1, INPUT); + pinMode (button_2, INPUT); +} + +void loop() { + + if ( digitalRead(button_1) == HIGH ) + { + winning = 1; + delay(2000); + } + + if ( digitalRead(button_2) == HIGH ) + { + losing = losing + 1; + delay(2000); + } + + if(losing == 0 && winning == 0) + { + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2,HIGH); + digitalWrite(redLED,HIGH); + digitalWrite(greenLED,HIGH); + delay(1000); + ddigitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2,LOW); + digitalWrite(redLED,LOW); + digitalWrite(greenLED,LOW); + delay(1000); + } + else if (losing == 1) + { + digitalWrite(blueLED_1, HIGH); + delay(1500); + } + else if (losing == 2) + { + digitalWrite(blueLED_2, HIGH); + delay(1500); + } + else if (losing == 3) + { + digitalWrite(redLED, HIGH); + digitalWrite(greenLED, LOW); + delay(200); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2, LOW); + digitalWrite(redLED, LOW); + delay(200); + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2, HIGH); + digitalWrite(redLED, HIGH); + delay(200); + digitalWrite(blueLED_1, LOW); + digitalWrite(blueLED_2, LOW); + digitalWrite(redLED, LOW); + delay(200); + digitalWrite(blueLED_1, HIGH); + digitalWrite(blueLED_2, HIGH); + digitalWrite(redLED, HIGH); + delay(3000); + + losing = 0; + winning = 0; + } + + if (_____) + { + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(_____); + digitalWrite(greenLED, _____); + delay(3000); + + winning = _____; + losing = _____; + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage1/React_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage1/React_Stage1.ino new file mode 100644 index 00000000..e89f5ef4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage1/React_Stage1.ino @@ -0,0 +1,34 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 1 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; + + +void setup() +{ + pinMode (blueLED_P1, _____); + pinMode (blueLED_P2, _____); + pinMode (greenLED, _____); + pinMode (redLED, _____); +} + +void loop() +{ + digitalWrite(blueLED_P1, _____); + digitalWrite(blueLED_P2, _____); + digitalWrite(greenLED, _____); + digitalWrite(redLED, _____); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage2/React_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage2/React_Stage2.ino new file mode 100644 index 00000000..e832c423 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage2/React_Stage2.ino @@ -0,0 +1,58 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 2 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; +int button_P1 = 2; +int button_P2 = 3; + +void setup() { + + pinMode (blueLED_P1, OUTPUT); + pinMode (blueLED_P2, OUTPUT); + pinMode (greenLED, OUTPUT); + pinMode (redLED, OUTPUT); + + pinMode (button_P1, _____); + pinMode (button_P2, _____); + +} + +void loop() +{ + /* + //STEP 1; check if the LEDs are working + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); + */ + + if (digitalRead(button_P1) == _____) + { + digitalWrite(blueLED_P1, _____); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + } + + if (digitalRead(button_P2) == _____) + { + digitalWrite(blueLED_P2, _____); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage3/React_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage3/React_Stage3.ino new file mode 100644 index 00000000..944f175e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage3/React_Stage3.ino @@ -0,0 +1,80 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 3 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; + +int button_P1 = 2; +int button_P2 = 3; + +int game = 0; + +void setup() { + + pinMode (blueLED_P1, OUTPUT); + pinMode (blueLED_P2, OUTPUT); + pinMode (greenLED, OUTPUT); + pinMode (redLED, OUTPUT); + + pinMode (button_P1, INPUT); + pinMode (button_P2, INPUT); +} + +void loop() { + + if (game == _____) + { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); + + if (digitalRead(button_P1)== _____ || digitalRead(button_P2) == _____ ) + { + game += 1; + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(_____); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(_____); + } + } + + if (game == _____) + { + if (digitalRead(button_P1) == HIGH) + { + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + game = _____; + } + + if (digitalRead(button_P2) == HIGH) + { + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + game = _____; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage4/React_Stage4.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage4/React_Stage4.ino new file mode 100644 index 00000000..0cb66035 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage4/React_Stage4.ino @@ -0,0 +1,102 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 4 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; + +int button_P1 = 2; +int button_P2 = 3; + +int game = 0; +int level = 300; +int gameSpeed = 0; + +void setup() +{ + pinMode (blueLED_P1, OUTPUT); + pinMode (blueLED_P2, OUTPUT); + pinMode (greenLED, OUTPUT); + pinMode (redLED, OUTPUT); + + pinMode (button_P1, INPUT); + pinMode (button_P2, INPUT); +} + +void loop() +{ + + if (game == 0) + { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); + + + if (digitalRead(button_P1)== HIGH || digitalRead(button_P2) == HIGH ) + { + game += 1; + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(3000); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(1000); + } + } + + if (game == 1) + { + + digitalWrite(redLED, _____); + digitalWrite(greenLED, _____); + delay(level); + + if (digitalRead(button_P1) == HIGH ) + { + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + game = 0; + } + + if (digitalRead(button_P2) == HIGH ) + { + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + game = 0; + } + + digitalWrite (greenLED, _____); + digitalWrite(redLED, _____); + gameSpeed = random(_____, _____); + delay(gameSpeed); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage5/React_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage5/React_Stage5.ino new file mode 100644 index 00000000..d59d2358 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/React/React_Stage5/React_Stage5.ino @@ -0,0 +1,162 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - REACT + + This sketch is written to accompany Stage 5 in REACT of the CTC GO! core module +*/ + +int blueLED_P1 = 10; +int redLED = 11; +int greenLED = 12; +int blueLED_P2 = 13; + +int button_P1 = 2; +int button_P2 = 3; + +int game = 0; + +int level = 300; +int gameSpeed = 0; +int win_P1 = 0; +int win_P2 = 0; + +void setup() { + + pinMode (blueLED_P1, OUTPUT); + pinMode (blueLED_P2, OUTPUT); + pinMode (greenLED, OUTPUT); + pinMode (redLED, OUTPUT); + + pinMode (button_P1, INPUT); + pinMode (button_P2, INPUT); + +} + +void loop() { + + if (game == 0) + { + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(100); + + if (digitalRead(button_P1)== HIGH || digitalRead(button_P2) == HIGH ) + { + game += 1; + digitalWrite(blueLED_P1, HIGH); + digitalWrite(blueLED_P2, HIGH); + digitalWrite(greenLED, HIGH); + digitalWrite(redLED, HIGH); + delay(3000); + digitalWrite(blueLED_P1, LOW); + digitalWrite(blueLED_P2, LOW); + digitalWrite(greenLED, LOW); + digitalWrite(redLED, LOW); + delay(1000); + } + } + + if (game == 1) + { + digitalWrite(redLED, LOW); + digitalWrite(greenLED, HIGH); + + delay(level); + + if (digitalRead(button_P1) == HIGH) + { + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + digitalWrite(blueLED_P1, HIGH); + delay(100); + digitalWrite(blueLED_P1, LOW); + delay(100); + win_P1 += _____; + } + + if (digitalRead(button_P2) == HIGH) + { + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + digitalWrite(blueLED_P2, HIGH); + delay(100); + digitalWrite(blueLED_P2, LOW); + delay(100); + win_P2 += _____; + } + + digitalWrite (greenLED, LOW); + digitalWrite(redLED, HIGH); + + if (win_P1 == 5) + { + digitalWrite(redLED, LOW); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P1, _____); + delay(2000); + win_P1 = 0; + win_P2 = 0; + game = 0; + } + + //STEP 5; Code to show the victory of player 2 + if (win_P2 == _____) + { + digitalWrite(redLED, LOW); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(200); + digitalWrite(greenLED, _____); + digitalWrite(blueLED_P2, _____); + delay(2000); + win_P1 = 0; + win_P2 = 0; + game = 0; + } + + gameSpeed = random(1000, 5000); + delay(gameSpeed); + + } + + + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage1/WhackAMole_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage1/WhackAMole_Stage1.ino new file mode 100644 index 00000000..4b0234f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage1/WhackAMole_Stage1.ino @@ -0,0 +1,37 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 1 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; + +void setup() +{ + pinMode(loseLED, _____); + pinMode(winLED, _____); + pinMode(yellowLED_1, _____); + pinMode(yellowLED_2, _____); + pinMode(yellowLED_3, _____); +} + +void loop() +{ + digitalWrite(loseLED, _____); + digitalWrite(winLED, _____); + digitalWrite(yellowLED_1, _____); + digitalWrite(yellowLED_2, _____); + digitalWrite(yellowLED_3, _____); + delay(1000); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage2/WhackAMole_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage2/WhackAMole_Stage2.ino new file mode 100644 index 00000000..26d0c199 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage2/WhackAMole_Stage2.ino @@ -0,0 +1,67 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 2 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +void setup() +{ + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + + pinMode(button_1, _____); + pinMode(button_2, _____); + pinMode(button_3, _____); +} + +void loop() +{ + /* + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(1000); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(1000); + */ + + if (digitalRead(button_1) == _____) + { + digitalWrite(yellowLED_1, _____); + } + else if (digitalRead(button_2) == _____) + { + digitalWrite(yellowLED_2, _____); + } + else if (digitalRead(button_3) == _____) + { + digitalWrite(yellowLED_3, _____); + } + else + { + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage3/WhackAMole_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage3/WhackAMole_Stage3.ino new file mode 100644 index 00000000..6949edf9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage3/WhackAMole_Stage3.ino @@ -0,0 +1,77 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 3 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +int startLevel = 500; +int gameStarted = 0; + +void setup() +{ + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + pinMode(button_3, INPUT); +} + +void loop() +{ + if (gameStarted == 0) + { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(_____); + + if (digitalRead(button_1) == _____) + { + gameStarted = 1; + } + } + else if (gameStarted == 1) + { + if (digitalRead(button_1) == _____) + { + digitalWrite(yellowLED_1, HIGH); + } + else if (digitalRead(button_2) == _____) + { + digitalWrite(yellowLED_2, HIGH); + } + else if (digitalRead(button_3) == HIGH) + { + digitalWrite(yellowLED_3, HIGH); + } + else + { + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage4/WhackAMole_Stage4.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage4/WhackAMole_Stage4.ino new file mode 100644 index 00000000..72bac8f5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage4/WhackAMole_Stage4.ino @@ -0,0 +1,82 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 4 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +int startLevel = 500; +int gameStarted = 0; + +void setup() +{ + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + pinMode(button_3, INPUT); +} + +void loop() +{ + if (gameStarted == 0) + { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(startLevel); + + if (digitalRead(button_1) == _____ || digitalRead(button_2) == HIGH _____ digitalRead(button_3) == _____ ) + { + digitalWrite(loseLED, _____); + digitalWrite(winLED, _____); + gameStarted = 1; + delay(_____); + digitalWrite(loseLED, _____); + digitalWrite(winLED, _____); + } + } + else if (gameStarted == 1) + { + if (digitalRead(button_1) == HIGH) + { + digitalWrite(yellowLED_1, HIGH); + } + else if (digitalRead(button_2) == HIGH) + { + digitalWrite(yellowLED_2, HIGH); + } + else if (digitalRead(button_3) == HIGH) + { + digitalWrite(yellowLED_3, HIGH); + } + else + { + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage5/WhackAMole_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage5/WhackAMole_Stage5.ino new file mode 100644 index 00000000..24b66722 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage5/WhackAMole_Stage5.ino @@ -0,0 +1,90 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 5 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +int startLevel = 500; +int gameStarted = 0; +int blinkLED = 0; + +void setup() +{ + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + pinMode(button_3, INPUT); +} + +void loop() +{ + if (gameStarted == 0) + { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(startLevel); + + if (digitalRead(button_1) == HIGH || digitalRead(button_2) == HIGH || digitalRead(button_3) == HIGH ) + { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + gameStarted = 1; + delay(2000); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + } + } + else if (gameStarted == 1) + { + blinkLED = random (_____, _____); + + if (blinkLED == _____) + { + digitalWrite(yellowLED_1, HIGH); + delay(startLevel); + + } + + if (blinkLED == _____) + { + digitalWrite(yellowLED_2, HIGH); + delay(startLevel); + } + + + if (blinkLED == _____) + { + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + } + } + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(_____); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage6/WhackAMole_Stage6.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage6/WhackAMole_Stage6.ino new file mode 100644 index 00000000..c5f008ac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Core-Module/examples/Projects/WhackAMole/WhackAMole_Stage6/WhackAMole_Stage6.ino @@ -0,0 +1,140 @@ +/* + CTC GO! CORE MODULE + PROJECT 1 - WHACK A MOLE + + This sketch is written to accompany Stage 6 in Whack-a-mole of the CTC GO! core module +*/ + +int loseLED = 13; +int winLED = 12; +int yellowLED_1 = 11; +int yellowLED_2 = 10; +int yellowLED_3 = 9; +int button_1 = 5; +int button_2 = 6; +int button_3 = 7; + +int startLevel = 500; +int gameStarted = 0; +int blinkLED = 0; +int level = 0; + +void setup() +{ + pinMode(loseLED, OUTPUT); + pinMode(winLED, OUTPUT); + pinMode(yellowLED_1, OUTPUT); + pinMode(yellowLED_2, OUTPUT); + pinMode(yellowLED_3, OUTPUT); + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + pinMode(button_3, INPUT); +} + +void loop() +{ + if (gameStarted == 0) + { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + digitalWrite(yellowLED_1, HIGH); + digitalWrite(yellowLED_2, HIGH); + digitalWrite(yellowLED_3, HIGH); + delay(startLevel); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(startLevel); + + if (digitalRead(button_1) == HIGH || digitalRead(button_2) == HIGH || digitalRead(button_3) == HIGH ) + { + digitalWrite(loseLED, HIGH); + digitalWrite(winLED, HIGH); + + gameStarted = 1; + delay(2000); + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + } + + + }else if (gameStarted == 1) + { + + blinkLED = random (1, 4); + + if (blinkLED == 1) + { + digitalWrite(yellowLED_1, HIGH); + delay(startLevel - level); + + if (digitalRead(button_2) == _____ || digitalRead(button_3) == _____ ) + { + digitalWrite(loseLED, HIGH); + delay(2000); + gameStarted = _____; + } + + else if (digitalRead(button_1) == _____) + { + digitalWrite(winLED, HIGH); + delay(_____); + level = level + 5; + } + } + + if (blinkLED == 2) + { + digitalWrite(yellowLED_2, HIGH); + delay(startLevel - _____); + + + if (digitalRead(button_1) == _____ || digitalRead(button_3) == _____ ) + { + digitalWrite(loseLED, HIGH); + delay(2000); + gameStarted = _____; + } + + else if (digitalRead(button_2) == _____) + { + digitalWrite(winLED, HIGH); + delay(_____); + level = level + 5; + } + } + + + if (blinkLED == 3) + { + digitalWrite(yellowLED_3, HIGH); + delay(startLevel - _____); + + if (digitalRead(button_1) == _____ || digitalRead(button_2) == _____ ) + { + digitalWrite(loseLED, HIGH); + delay(2000); + gameStarted = _____; + } + + else if (digitalRead(button_3) == _____) + { + digitalWrite(winLED, HIGH); + delay(_____); + level = level + 5; + } + } + } + if (level >= startLevel) + { + level = startLevel; + } + digitalWrite(loseLED, LOW); + digitalWrite(winLED, LOW); + digitalWrite(yellowLED_1, LOW); + digitalWrite(yellowLED_2, LOW); + digitalWrite(yellowLED_3, LOW); + delay(startLevel - _____); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/README.md new file mode 100644 index 00000000..404eb569 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/README.md @@ -0,0 +1,2 @@ +# CTC-Go-Motions-Expansion +CTC GO MOTIONS EXPANSION - the repository for the motions expansion pack to Arduino's CTC Go educational programmes diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity1/MakingThingsMove_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity1/MakingThingsMove_Activity1.ino new file mode 100644 index 00000000..8b792fe8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity1/MakingThingsMove_Activity1.ino @@ -0,0 +1,37 @@ +/* + CTC GO! MOTION + LESSON 01 - Making Things Move + + This sketch is written to accompany activity 1 of Lesson 1 +*/ + +#include + +Servo servo_Standard; + +int pos = 0; + +void setup() +{ + servo_Standard.attach(9); + + Serial.begin(9600); +} + +void loop() +{ + for (pos = 0; pos <= 180; pos += 1) + { + servo_Standard.write(pos); + Serial.print("Shaft position: "); + Serial.println(pos); + delay(50); + } + for (pos = 180; pos >= 0; pos -= 1) + { + servo_Standard.write(pos); + Serial.print("Shaft position: "); + Serial.println(pos); + delay(50); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity2/MakingThingsMove_Activity2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity2/MakingThingsMove_Activity2.ino new file mode 100644 index 00000000..995093c0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity2/MakingThingsMove_Activity2.ino @@ -0,0 +1,34 @@ +/* + CTC GO! MOTION + LESSON 01 - Making Things Move + + This sketch is written to accompany activity 2 of Lesson 1 +*/ + + +#include + +Servo servo_Standard; + +int potPin = A0; + +int potValue = 0; +int pos = 0; + +void setup() +{ + servo_Standard.attach(9); + + Serial.begin(9600); +} + +void loop() +{ + potValue = analogRead(potPin); + pos = map(potValue,0,1023,0,180); + + servo_Standard.write(pos); + delay(15); + Serial.print("Shaft position: "); + Serial.println(pos); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity3/MakingThingsMove_Activity3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity3/MakingThingsMove_Activity3.ino new file mode 100644 index 00000000..c5dcb803 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/01_MakingThingsMove/MakingThingsMove_Activity3/MakingThingsMove_Activity3.ino @@ -0,0 +1,46 @@ +/* + CTC GO! MOTION + LESSON 01 - Making Things Move + + This sketch is written to accompany activity 3 of Lesson 1 +*/ + +#include + +Servo servo_Standard; + +int USsensor = A0; + +int USvalue = 0; +int distance = 0; +int triggerDistance = 500; + +void setup() +{ + servo_Standard.attach(9); + + Serial.begin(9600); +} + +void loop() +{ + USvalue = analogRead(USsensor); + distance = USvalue * 3; + distance = map(distance, 0, 1023, 0, 3000); + + Serial.print("Distance to the object (mm): "); + Serial.println(distance); + + if (distance <= triggerDistance) + { + servo_Standard.write(90); + delay(5000); + Serial.print("Door opened"); + } + else + { + servo_Standard.write(0); + delay(15); + Serial.print("Door closed"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity1/CircularToLinearMovement_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity1/CircularToLinearMovement_Activity1.ino new file mode 100644 index 00000000..47850b54 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity1/CircularToLinearMovement_Activity1.ino @@ -0,0 +1,37 @@ +/* + CTC GO! MOTION + LESSON 02 - Circular To Linear Movement + + This sketch is written to accompany activity 1 of Lesson 2 +*/ + +#include + +Servo servo_Standard; + +int potPin = A0; + +int pos = 0; +int potValue = 0; + +int max_pos = 180; +int min_pos = 0; + +void setup() +{ + servo_Standard.attach(6); + + Serial.begin(9600); +} + +void loop() +{ + potValue = analogRead(potPin); + + pos = map(potValue, 0, 1023, min_pos, max_pos); + + servo_Standard.write(pos); + Serial.print("Shaft position: "); + Serial.println(pos); + delay(15); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity2/CircularToLinearMovement_Activity2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity2/CircularToLinearMovement_Activity2.ino new file mode 100644 index 00000000..d300db76 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/02_CircularToLinearMovement/CircularToLinearMovement_Activity2/CircularToLinearMovement_Activity2.ino @@ -0,0 +1,82 @@ + +/* + CTC GO! MOTION + LESSON 02 - Circular To Linear Movement + + This sketch is written to accompany activity 2 of Lesson 2 +*/ + +#include + +Servo servo_Standard; + +int photo = A0; +int piezo = 3; + +bool open = true; +bool closed = false; + +int light = 0; +int trigger = 400; +int open_pos = 30; +int closed_pos = 125; +int closed_tone = 250; +int open_tone = 1500; + +void setup() +{ + servo_Standard.attach(9); + pinMode(piezo, OUTPUT); +} + +void loop() +{ + light = analogRead(A0); + + if (light <= trigger) + { + servo_Standard.write(closed_pos); + delay(400); + sounds(closed); + } + else + { + servo_Standard.write(open_pos); + delay(400); + sounds(open); + } +} + + +void sounds(bool state) { + static bool prev_state = open; + + if (state != prev_state) + { + if (state == true) + { + for (int i = 0; i < 2; i++) + { + tone(piezo, open_tone); + delay(50); + noTone(piezo); + delay(50); + } + } + else + { + for (int i = 0; i < 2; i++) + { + tone(piezo, closed_tone); + delay(50); + noTone(piezo); + delay(50); + } + } + } + else + { + noTone(piezo); + } + prev_state = state; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity1/ContinuousRotation_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity1/ContinuousRotation_Activity1.ino new file mode 100644 index 00000000..11109da0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity1/ContinuousRotation_Activity1.ino @@ -0,0 +1,36 @@ +/* + CTC GO! MOTION + LESSON 03 - Continuous Rotation + + This sketch is written to accompany activity 1 of Lesson 3 +*/ + +#include + +Servo servo_Cont; + +int pos = 0; + +void setup() +{ + servo_Cont.attach(9); + Serial.begin(9600); +} + +void loop() +{ + for (pos = 0; pos <= 180; pos += 1) + { + servo_Cont.write(pos); + Serial.print("Position value: "); + Serial.println(pos); + delay(0); + } + for (pos = 180; pos >= 0; pos -= 1) + { + servo_Cont.write(pos); + Serial.print("Position value: "); + Serial.println(pos); + delay(0); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity2/ContinuousRotation_Activity2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity2/ContinuousRotation_Activity2.ino new file mode 100644 index 00000000..9c01654c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity2/ContinuousRotation_Activity2.ino @@ -0,0 +1,32 @@ +/* + CTC GO! MOTION + LESSON 03 - Continuous Rotation + + This sketch is written to accompany activity 2 of Lesson 3 +*/ + +#include + +Servo servo_Cont; + +int potPin = A0; + +int potValue = 0; +int vel = 0; + +void setup() +{ + servo_Cont.attach(9); + Serial.begin(9600); +} + +void loop() +{ + potValue = analogRead(potPin); + vel = map(potValue,0,1023,0,180); + + servo_Cont.write(vel); + delay(15); + Serial.print("Shaft spee: "); + Serial.println(vel); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity3/ContinuousRotation_Activity3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity3/ContinuousRotation_Activity3.ino new file mode 100644 index 00000000..5246ed47 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/03_ContinuousRotation/ContinuousRotation_Activity3/ContinuousRotation_Activity3.ino @@ -0,0 +1,60 @@ +/* + CTC GO! MOTION + LESSON 03 - Continuous Rotation + + This sketch is written to accompany activity 3 of Lesson 3 +*/ + +#include + +Servo servo_Cont; + +int USsensor = A0; + +int USvalue = 0; +int distance = 0; +int speed = 0; + +void setup() +{ + servo_Cont.attach(9); + Serial.begin(9600); +} + +void loop() +{ + USvalue = analogRead(USsensor); + distance = map(USvalue, 0, 1023, 0, 3000); + + Serial.print("Distance: "); + Serial.println(distance); + + if (distance < 150) + { + servo_Cont.write(135); + Serial.print("Object too close to the sensor"); + } + else if (distance >= 150 && distance <= 200) + { + servo_Cont.write(90); + Serial.print("Object in the targeted position"); + } + else if (distance > 200 && distance <= 350) + { + servo_Cont.write(80); + Serial.print("Third speed control range"); + } + else if (distance > 350 && distance <= 500) + { + servo_Cont.write(50); + Serial.print("Second speed control range"); + } + + else + { + servo_Cont.write(0); + Serial.print("Full speed range"); + } + + delay(250); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/04_GearsAndPulleys/GearsAndPulleys_Activity1/GearsAndPulleys_Activity1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/04_GearsAndPulleys/GearsAndPulleys_Activity1/GearsAndPulleys_Activity1.ino new file mode 100644 index 00000000..f0216a92 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Lessons/04_GearsAndPulleys/GearsAndPulleys_Activity1/GearsAndPulleys_Activity1.ino @@ -0,0 +1,70 @@ +/* + CTC GO! MOTION + LESSON 04 - Gears and Pulleys + + This sketch is written to accompany activity 1 of Lesson 4 +*/ + +#include + +Servo waterServo; + +int button1 = 2; +int button2 = 3; + +int waterLevel = 0; +int b1_state = 0; +int b2_state = 0; + +void setup() +{ + waterServo.attach(9); + + Serial.begin(9600); +} + +void loop() +{ + b1_state = digitalRead(button1); + b2_state = digitalRead(button2); + + if (b1_state == 1 && b2_state == 1) + { + waterLevel = 100; + } + else if (b1_state == 1 && b2_state == 0) + { + waterLevel = 60; + } + else if (b1_state == 0 && b2_state == 1) + { + waterLevel = 30; + } + else + { + waterLevel = 0; + } + + switch (waterLevel) + { + case 100: + waterServo.write(180); + Serial.println("Water level 100%"); + break; + + case 60: + waterServo.write(110); + Serial.println("Water level 60%"); + break; + + case 30: + waterServo.write(100); + Serial.println("Water level 30%"); + break; + + default: + waterServo.write(90); + Serial.println("Water level 0%"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage1/rockPaperScissor_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage1/rockPaperScissor_Stage1.ino new file mode 100644 index 00000000..e7cabcc8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage1/rockPaperScissor_Stage1.ino @@ -0,0 +1,34 @@ +/* + CTC GO! MOTION + PROJECT - ROCK PAPER SCISSOR + + This sketch is written to accompany Stage 1 of the ROCK PAPER SCISSOR project +*/ + +int piezo = 8; +int USsensor = A0; + +int USvalue = 0; +float distance = 0; + + +void setup() { +______(piezo, ______); +Serial.begin(9600); +} + +void loop() { + USvalue = ______(______); + distance = ______ * 3; + + Serial.print("Distance to object: "); + Serial.println(______); + + if (______ < 400) { + tone(______, 500); + delay(100); + noTone(______); + } + +delay(250); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage2/rockPaperScissor_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage2/rockPaperScissor_Stage2.ino new file mode 100644 index 00000000..28e3874c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage2/rockPaperScissor_Stage2.ino @@ -0,0 +1,66 @@ +/* + CTC GO! MOTION + PROJECT - ROCK PAPER SCISSOR + + This sketch is written to accompany Stage 2 of the ROCK PAPER SCISSOR project +*/ + +int redLED = 2; +int yellowLED = 3; +int greenLED = 4; +int piezo = 8; +int USsensor = A0; + +int USvalue = 0; +float distance = 0; +int check = 0; + +void setup() { + pinMode(piezo, OUTPUT); + + ______(redLED, ______); + ______(yellowLED, ______); + ______(greenLED, ______); + + Serial.begin(9600); +} + +void loop() { + USvalue = analogRead(USsensor); + distance = USvalue * 3; + + if (distance < 400) { + /*tone(piezo, 500); + delay(100); + noTone(piezo);*/ + + ______++; + delay(400); + Serial.println(______); + } + + if (check == 0) { + ____________(redLED, ______); + ____________(yellowLED, ______); + ____________(greenLED, ______); + } + + else if (check == 1) { + ______(redLED, ______); + } + + else if (check == 2) { + ____________(yellowLED, ______); + ____________(redLED, ______); + } + + else if (check == 3) { + ____________(greenLED, ______); + ____________(yellowLED, ______); + tone(piezo, 500); + delay(100); + noTone(piezo); + ______ = 0; + } +} + \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage3/rockPaperScissor_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage3/rockPaperScissor_Stage3.ino new file mode 100644 index 00000000..232c0d83 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage3/rockPaperScissor_Stage3.ino @@ -0,0 +1,114 @@ +/* + CTC GO! MOTION + PROJECT - ROCK PAPER SCISSOR + + This sketch is written to accompany Stage 3 of the ROCK PAPER SCISSOR project +*/ + +#include + +Servo servo_main; +Servo servo_wheel; + +int redLED = 2; +int yellowLED = 3; +int greenLED = 4; +int piezo = 11; +int USsensor = A0; + +int USvalue = 0; +float distance = 0; +int check = 0; +int randomNumber; + +void setup() { + pinMode(redLED, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(greenLED, OUTPUT); + + servo_main.______(6); + servo_wheel.______(9); + + servo_main.______(0); + delay(10); + + Serial.begin(9600); +} + +void loop() +{ + + USvalue = analogRead(USsensor); + distance = USvalue * 3; + + servo_wheel.______(80); + delay(10); + + if (distance < 400) { + check++; + delay(400); + Serial.println(check); + } + + if (check == 0) { + digitalWrite(redLED, LOW); + digitalWrite(yellowLED, LOW); + digitalWrite(greenLED, LOW); + } + + else if (check == 1) { + digitalWrite(redLED, HIGH); + } + + else if (check == 2) { + digitalWrite(yellowLED, HIGH); + digitalWrite(redLED, LOW); + } + + else if (check == 3) { + digitalWrite(greenLED, HIGH); + digitalWrite(yellowLED, LOW); + tone(piezo, 500); + delay(100); + noTone(piezo); + randomNumber = ______(1, 4); + delay(10); + Serial.println(randomNumber); + delay(100); + check = 0; + + switch(____________) + { + case 1: + servo_main.______(0); + delay(1000); + servo_wheel.______(93); + delay(2000); + servo_main.______(0); + delay(2000); + break; + + case 2: + servo_main.______(80); + delay(1000); + servo_wheel.______(93); + delay(2000); + servo_main.______(0); + delay(2000); + break; + + case 3: + servo_main.______(160); + delay(1000); + servo_wheel.______(93); + delay(2000); + servo_main.______(0); + delay(2000); + break; + } + + ____________ = 0; + } + +delay(250); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage5/rockPaperScissor_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage5/rockPaperScissor_Stage5.ino new file mode 100644 index 00000000..11ababa2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/RockPaperScissors/rockPaperScissor_Stage5/rockPaperScissor_Stage5.ino @@ -0,0 +1,115 @@ +/* + CTC GO! MOTION + PROJECT - ROCK PAPER SCISSOR + + This sketch is written to accompany Stage 5 of the ROCK PAPER SCISSOR project +*/ + +#include + +Servo servo_main; +Servo servo_wheel; + +int redLED = 2; +int yellowLED = 3; +int greenLED = 4; +int piezo = 8; +int USsensor = A0; + +int rock = 0; +int paper = 80; +int scissor = 160; + +int USvalue = 0; +float distance = 0; +int check = 0; +int randomNumber; + +void setup() { + pinMode(redLED, OUTPUT); + pinMode(yellowLED, OUTPUT); + pinMode(greenLED, OUTPUT); + + servo_main.attach(6); + servo_wheel.attach(9); + + servo_main.write(0); + delay(10); + + Serial.begin(9600); +} + +void loop() { + USvalue = analogRead(USsensor); + distance = USvalue * 3; + + servo_wheel.write(80); + delay(10); + + + if (distance < 400) { + check++; + delay(400); + } + + if (check == 0) { + digitalWrite(redLED, LOW); + digitalWrite(yellowLED, LOW); + digitalWrite(greenLED, LOW); + } + + else if (check == 1) { + digitalWrite(redLED, HIGH); + } + + else if (check == 2) { + digitalWrite(yellowLED, HIGH); + digitalWrite(redLED, LOW); + } + + else if (check == 3) + { + digitalWrite(greenLED, HIGH); + digitalWrite(yellowLED, LOW); + tone(piezo, 500); + delay(100); + noTone(piezo); + randomNumber = random(1, 4); + Serial.println(randomNumber); + delay(100); + check = 0; + + switch(randomNumber) + { + case 1: + ____________(rock); + break; + + case 2: + ____________(paper); + break; + + case 3: + ____________(scissor); + break; + } + + randomNumber = 0; + } + + delay(250); +} + +void ____________(int object) +{ + servo_main.write(______); + delay(1000); + + servo_wheel.write(95); + delay(2000); + + servo_main.write(0); + digitalWrite(greenLED, LOW); + delay(2000); + +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage1/spinAWheel_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage1/spinAWheel_Stage1.ino new file mode 100644 index 00000000..bfd9df82 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage1/spinAWheel_Stage1.ino @@ -0,0 +1 @@ +/* CTC GO! MOTION PROJECT - Spin-A-Wheel This sketch is written to accompany Stage 1 of the Spin-a-Wheel project */ int button_1 = 2; int button_2 = 3; int buttonState_1; int buttonState_2; void setup() { ______(button_1, ______); ______(button_2, ______); Serial.begin(9600); } void loop() { buttonState_1 = ______(button_1); buttonState_2 = ______(button_2); if(____________ == HIGH) { Serial.println("Button 1 pressed"); delay(1000); } if(____________ == HIGH) { Serial.println("Button 2 pressed"); delay(1000); } delay(100); } \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage2/spinAWheel_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage2/spinAWheel_Stage2.ino new file mode 100644 index 00000000..6ee13fcf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage2/spinAWheel_Stage2.ino @@ -0,0 +1,53 @@ +/* + CTC GO! MOTION + PROJECT - Spin-A-Wheel + + This sketch is written to accompany Stage 2 of the Spin-a-Wheel project +*/ + +#include + +______ servo_wheel; +______ servo_pointer; + +int button_1 = 2; +int button_2 = 3; + +int buttonState_1; +int buttonState_2; + +void setup() { + +pinMode(button_1, INPUT); +pinMode(button_2, INPUT); + +servo_pointer.______(6); +servo_wheel.______(9); + +Serial.begin(9600); + +} + +void loop() { + +buttonState_1 = digitalRead(button_1); +buttonState_2 = digitalRead(button_2); + +if(buttonState_1 == HIGH) { + Serial.println("Button 1 pressed"); + servo_pointer.______(30); + delay(10); + servo_wheel.______(30); + delay(1000); +} + +if(buttonState_2 == HIGH) { + Serial.println("Button 2 pressed"); + ______.______(70); + delay(10); + ______.______(93); + delay(1000); +} + +delay(100); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage3/spinAWheel_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage3/spinAWheel_Stage3.ino new file mode 100644 index 00000000..2392fdb5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage3/spinAWheel_Stage3.ino @@ -0,0 +1,77 @@ +/* + CTC GO! MOTION + PROJECT - Spin-A-Wheel + + This sketch is written to accompany Stage 3 of the Spin-a-Wheel project +*/ + +#include + +Servo servo_wheel; +Servo servo_pointer; + +int button_1 = 2; +int button_2 = 3; + +int yellowLED = 4; +int blueLED = 5; +int piezo = 8; + +int buttonState_1; +int buttonState_2; + +void setup() +{ + pinMode(button_1, INPUT); + pinMode(button_2, INPUT); + ______(yellowLED, ______); + ______(blueLED, ______); + ______(piezo, ______); + + servo_pointer.attach(6); + servo_wheel.attach(9); + + Serial.begin(9600); +} + + +void loop() +{ + buttonState_1 = digitalRead(button_1); + buttonState_2 = digitalRead(button_2); + + if(buttonState_1 == HIGH) { + Serial.println("Button 1 pressed"); + servo_pointer.write(30); + delay(10); + servo_wheel.write(30); + ______(blueLED, HIGH); + ______(yellowLED, LOW); + tone(______, ______); + delay(1000); + noTone(______); + + } + + if(buttonState_2 == HIGH) { + Serial.println("Button 2 pressed"); + servo_pointer.write(70); + delay(10); + servo_wheel.write(93); + ______(blueLED, ______); + ______(yellowLED, ______); + tone(______, ______); + delay(1000); + noTone(______); + } + + delay(100); +} + + + + + + + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage5/spinAWheel_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage5/spinAWheel_Stage5.ino new file mode 100644 index 00000000..fd8b0b0f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/SpinAWheel/spinAWheel_Stage5/spinAWheel_Stage5.ino @@ -0,0 +1,115 @@ +/* + CTC GO! MOTION + PROJECT - SPIN-A-WHEEL + + This sketch is written to accompany Stage 5 of the SPIN-A-WHEEL project +*/ + +#include + +Servo servo_wheel; +Servo servo_pointer; + +int button_1 = 2; +int button_2 = 3; +int yellowLED = 4; +int blueLED = 5; +int piezo = 8; + +int buttonState_1; +int buttonState_2; + +int counter; + +void setup() { + +pinMode(button_1, INPUT); +pinMode(button_2, INPUT); + +pinMode(yellowLED, OUTPUT); +pinMode(blueLED, OUTPUT); + +servo_pointer.attach(6); +servo_wheel.attach(9); + +Serial.begin(9600); + +} + +void loop() { + + buttonState_1 = digitalRead(button_1); + buttonState_2 = digitalRead(button_2); + + if(buttonState_1 == HIGH) + { + Serial.println("Button 1 pressed"); + servo_pointer.write(30); + delay(10); + servo_wheel.write(30); + delay(1000); + } + + if(buttonState_2 == HIGH) + { + Serial.println("Button 2 pressed"); + servo_pointer.write(70); + delay(10); + servo_wheel.write(93); + delay(1000); + ____________(); + } + +} + +void ____________() { + + ______++; + + if(counter <= 2) + { + digitalWrite(yellowLED, HIGH); + digitalWrite(blueLED, LOW); + } + + else if(counter == 3) + { + ______(); + counter++; + digitalWrite(blueLED, HIGH); + digitalWrite(yellowLED, LOW); + } + + else if(counter >= 4 && counter <= 6) + { + digitalWrite(blueLED, HIGH); + digitalWrite(yellowLED, LOW); + } + + else if(counter == 7) + { + ______(); + ______ = 0; + digitalWrite(blueLED, LOW); + digitalWrite(yellowLED, HIGH); + } + + delay(100); +} + +void ______() { + tone(______, 500); + delay(300); + ______(______); + delay(300); + + tone(______, 1200); + delay(500); + ______(______); + delay(300); + + tone(______, 200); + delay(700); + ______(______); + delay(300); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage1/waveGenerator_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage1/waveGenerator_Stage1.ino new file mode 100644 index 00000000..25d5f3cb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage1/waveGenerator_Stage1.ino @@ -0,0 +1 @@ +/* CTC GO! MOTION PROJECT - Wave Generator This sketch is written to accompany Stage 1 of the Wave Generator project */ int potPin = A0; int lightSensor = A1; int lightValue = 0; int potValue = 0; void setup() { ______(9600); } void loop() { _____ = analogRead(_____); Serial._____("Light Value: "); Serial.println(_____); delay(20); _____ = analogRead(____); Serial._____("Pot Value: "); Serial.println(_____); delay(20); Serial.println(" "); delay(250); } \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage2/waveGenerator_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage2/waveGenerator_Stage2.ino new file mode 100644 index 00000000..3a96fa05 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage2/waveGenerator_Stage2.ino @@ -0,0 +1 @@ +/* CTC GO! MOTION PROJECT - Wave Generator This sketch is written to accompany Stage 2 of the Wave Generator project */ #include _____ servo_rotate; _____ servo_arm; int lightSensor = A1; int potPin = A0; int lightValue = 0; int potValue = 0; int new_potValue; int new_lightValue; void setup(){ servo_rotate._____(6); servo_arm._____(9); Serial.begin(9600); } void loop() { lightValue = analogRead(lightSensor); Serial.print("Light Value: "); Serial.println(lightValue); new_lightValue = map(lightValue, 100, 900, ____, _____); servo_arm.____(____); delay(20); potValue = analogRead(potPin); Serial.print("Pot Value: "); Serial.println(potValue); new_potValue = map(potValue, 0, 1023, ____, ____); servo_rotate._____(____); delay(20); Serial.println(""); //delay(250); } \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage3/waveGenerator_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage3/waveGenerator_Stage3.ino new file mode 100644 index 00000000..2d34ce6f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage3/waveGenerator_Stage3.ino @@ -0,0 +1 @@ +/* CTC GO! MOTION PROJECT - Wave Generator This sketch is written to accompany Stage 3 of the Wave Generator project */ #include Servo servo_rotate; Servo servo_arm; int button = 2; int lightSensor = A1; int potPin = A0; int lightValue = 0; int potValue = 0; int new_potValue; int new_lightValue; int buttonState = LOW; _____ previousState = LOW; _____ isButtonPressed = false; int modeCounter = 1; void setup() { pinMode(button, _____); servo_rotate.attach(6); servo_arm.attach(9); Serial.begin(9600); } void loop() { potValue = analogRead(potPin); Serial.println(potValue); new_potValue = map(potValue, 100, 900, 0, 180); servo_rotate.write(new_potValue); delay(20); lightValue = analogRead(lightSensor); Serial.println(lightValue); new_lightValue = map(lightValue, 0, 1023, 0, 180); servo_arm.write(new_lightValue); delay(20); Serial.println(""); //delay(250); buttonState = digitalRead(_____); if (prevButtonState != buttonState) { isButtonPressed = buttonState; } if (isButtonPressed == true) { updateModeCounter(); isButtonPressed = false; } prevButtonState = buttonState; } void updateModeCounter() { if(modeCounter < 2) { modeCounter ++ ; Serial.println("Counter value : "); Serial.println(modeCounter); } else { modeCounter = 1 ; Serial.println("Counter value: "); Serial.println(modeCounter); } } \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage5/waveGenerator_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage5/waveGenerator_Stage5.ino new file mode 100644 index 00000000..5b4a64fd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/WaveGenerator/waveGenerator_Stage5/waveGenerator_Stage5.ino @@ -0,0 +1 @@ +/* CTC GO! MOTION PROJECT - Wave Generator This sketch is written to accompany Stage 5 of the Wave Generator project */ #include Servo servo_rotate; Servo servo_arm; int button = 2; int potPin = A0; int lightSensor = A1; int potValue = 0; int lightValue = 0; int new_potValue; int new_lightValue; int timing_lightValue; int buttonState = LOW; int isButtonPressed = LOW; boolean isButtonPressed = false; int modeCounter = 1; void setup() { pinMode(button, INPUT); servo_rotate.attach(6); servo_arm.attach(9); Serial.begin(9600); } void loop() { potValue = analogRead(potPin); Serial.println(potValue); new_potValue = map(potValue, 0, 1023, 0, 180); servo_rotate.write(new_potValue); delay(20); lightValue = analogRead(lightSensor); Serial.println(lightValue); // new_lightValue = map(lightValue, 100, 900, 0, 180); // servo_arm.write(new_lightValue); // delay(20); Serial.println(""); //delay(250); buttonState = digitalRead(button); if (prevButtonState != buttonState) { isButtonPressed = buttonState; } if (isButtonPressed == true) { updateModeCounter(); isButtonPressed = false; } prevButtonState = buttonState; switch(_____) { case 1: Serial.println("mode 1"); _____; break; case 2: Serial.println("mode 2"); _____; break; } } void updateModeCounter() { if(modeCounter < 2) { modeCounter ++ ; } else { modeCounter = 1 ; } } void modeOne() { new_lightValue = map(lightValue, 100, 900, 0, 180); servo_arm.write(new_lightValue); delay(20); } void modeTwo() { timing_lightValue = map(_____, 100, 900, 0, 500); servo_arm.write(10); delay(_____); servo_arm.write(70); delay(____); } \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage1/Wiggler_Stage1.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage1/Wiggler_Stage1.ino new file mode 100644 index 00000000..09296210 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage1/Wiggler_Stage1.ino @@ -0,0 +1 @@ +/* CTC GO! MOTION PROJECT - Wiggler This sketch is written to accompany Stage 1 of the Wiggler project */ int lightSensor_1 = A0; int lightSensor_2 = A1; int lightValue_1 = 0; int lightValue_2 = 0; void setup() { Serial.begin(9600); } void loop() { lightValue_1 = ______(______); lightValue_2 = ______(______); Serial.print("First Light Value: "); Serial.println(______); Serial.print("Second Light Value: "); Serial.println(______); delay(1000); } \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage2/Wiggler_Stage2.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage2/Wiggler_Stage2.ino new file mode 100644 index 00000000..9a3b4fa8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage2/Wiggler_Stage2.ino @@ -0,0 +1 @@ +/* CTC GO! MOTION PROJECT - Wiggler This sketch is written to accompany Stage 2 of the Wiggler project */ #include Servo servo_drive; Servo servo_steer; int lightSensor_1 = A0; int lightSensor_2 = A1; int lightValue_1 = 0; int lightValue_2 = 0; void setup() { servo_steer.______(6); servo_drive.____(9); Serial.begin(9600); } void loop() { lightValue_1 = analogRead(lightSensor_1); lightValue_2 = analogRead(lightSensor_2); Serial.print("First Light Value: "); Serial.println(lightValue_1); Serial.print("Second Light Value: "); Serial.println(lightValue_2); servo_drive.______(120); servo_steer.______(30); delay(500); servo_steer.______(150); delay(500); } \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage3/Wiggler_Stage3.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage3/Wiggler_Stage3.ino new file mode 100644 index 00000000..43d680d4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage3/Wiggler_Stage3.ino @@ -0,0 +1,55 @@ +/* + CTC GO! MOTION + PROJECT - Wiggler + + This sketch is written to accompany Stage 3 of the Wiggler project +*/ + +#include + +Servo servo_drive; +Servo servo_steer; + +int lightSensor_1 = A0; +int lightSensor_2 = A1; + +int lightValue_1 = 0; +int lightValue_2 = 0; + +void setup() +{ + servo_steer.attach(6); + servo_drive.attach(9); + Serial.begin(9600); +} + +void loop() +{ + lightValue_1 = analogRead(lightSensor_1); + lightValue_2 = analogRead(lightSensor_2); + + Serial.print("First Light Value: "); + Serial.println(lightValue_1); + Serial.print("Second Light Value: "); + Serial.println(lightValue_2); + + + servo_drive.write(120); + servo_steer.write(90); + delay(15); + + if (______ >= 900) + { + ______.write(60); + ______.write(30); + delay(3000); + } + + if (______ >= 900) + { + ______.write(60); + ______.write(150); + delay(3000); + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage5/Wiggler_Stage5.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage5/Wiggler_Stage5.ino new file mode 100644 index 00000000..7237b5a0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/CTC-Go-Motions-Expansion/examples/Projects/Wiggler/Wiggler_Stage5/Wiggler_Stage5.ino @@ -0,0 +1 @@ +/* CTC GO! MOTION PROJECT - Wiggler This sketch is written to accompany Stage 5 of the Wiggler project */ #include Servo servo_drive; Servo servo_steer; int lightSensor_1 = A0; int lightSensor_2 = A1; int lightValue_1 = 0; int lightValue_2 = 0; int ______ = 30; int ______ = 150; void setup() { servo_steer.attach(6); servo_drive.attach(9); Serial.begin(9600); } void loop() { lightValue_1 = analogRead(lightSensor_1); lightValue_2 = analogRead(lightSensor_2); Serial.print("First Light Value: "); Serial.println(lightValue_1); Serial.print("Second Light Value: "); Serial.println(lightValue_2); servo_drive.write(120); servo_steer.write(90); delay(15); if(lightValue_1 >= 900) { /*servo_drive.write(60); servo_steer.write(30); delay(3000); */ ____________(right); } if(lightValue_2 >= 900) { /*servo_drive.write(60); servo_steer.write(150); delay(3000); */ ____________(left); } if(lightValue_1 <= 50 && lightValue_2 <= 50) { ____________(); } delay(100); } void ____________(int direction) { servo_drive.write(60); delay(10); servo_steer.write(______); delay(3000); servo_steer.write(90); delay(10); } void ____________() { servo_drive.write(______); servo_steer.write(______); delay(5000); } \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/README.md new file mode 100644 index 00000000..bf1f7cbe --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/README.md @@ -0,0 +1,25 @@ +Education Shield for Arduino 101 +======== + +[![Check Arduino status](https://github.com/arduino-libraries/EducationShield/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/EducationShield/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/EducationShield/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/EducationShield/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/EducationShield/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/EducationShield/actions/workflows/spell-check.yml) + +The EducationShield library is intended to be used with the Education Shield provided in the CTC kit. It presents the necessary functions to interact with 3 and 4 pin connectors used in many sensors and actuators. Furthermore, it includes the functionality of SD-Card Reader and audio jack. + +![alt tag](references/images/EducationShield.jpg) + +CTC 101 Project +=========== + +CTC 101 is a modular STEAM program consisting of a toolbox with more than 25 projects and easy to assemble experiments, an online platform, and guided educators support. +The library is an educational project carried by Arduino LLC in Malmo. It is a collection of exercises commissioned by the Center of Resources for Education at Castilla La Mancha to be tried out in the classrooms during the Spring 2013. If you want to collaborate by adding translations to this collection of exercises, just send us a note to d.cuartielles AT arduino.cc. + +References +=========== +[Reference](references/) section which explains the functions and constants defined in the library. + +Credits +=========== + +X. Yang, M. Johansson, C. Leivas, T. Hansson, L. Balboa, K. Engdahl, T. Pham , A. Goransson , D. Cuartielles diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.1_blink/_2.1_blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.1_blink/_2.1_blink.ino new file mode 100644 index 00000000..bfad3bb0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.1_blink/_2.1_blink.ino @@ -0,0 +1,20 @@ +/* +* _2.1_blink +* +* The on-board LED blinks with a 2 second interval, +* being turned on for 1 second and then turned off for 1 second. +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + pinMode(13, OUTPUT); +} + +void loop() { + digitalWrite(13, HIGH); + delay(1000); + digitalWrite(13, LOW); + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.2_blink/_2.2_blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.2_blink/_2.2_blink.ino new file mode 100644 index 00000000..ddfde795 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.2_blink/_2.2_blink.ino @@ -0,0 +1,20 @@ +/* +* _2.2_blink +* +* An external LED blinks with a 2 second interval, +* being turned on for 1 second and then turned off for 1 second. +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + pinMode(5, OUTPUT); +} + +void loop() { + digitalWrite(5, HIGH); + delay(1000); + digitalWrite(5, LOW); + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.3_blink/_2.3_blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.3_blink/_2.3_blink.ino new file mode 100644 index 00000000..e181d0c0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.3_blink/_2.3_blink.ino @@ -0,0 +1,25 @@ +/* +* _2.3_blink +* +* An external LED blinks with a 2 second interval, +* being turned on for 1 second and then turned off for 1 second. +* +* The variable ledPin is declared to hold the value 5, the number +* of the digital pin you are using. +* +* (c) 2013-2016 Arduino LLC. +*/ + +int ledPin = 5; + +void setup() { + pinMode(ledPin, OUTPUT); +} + +void loop() { + digitalWrite(ledPin, HIGH); + delay(1000); + digitalWrite(ledPin, LOW); + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.4_beep/_2.4_beep.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.4_beep/_2.4_beep.ino new file mode 100644 index 00000000..ee1b53e7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.4_beep/_2.4_beep.ino @@ -0,0 +1,21 @@ +/* +* _2.4_beep +* +* The piezo makes clicks with a 2 second interval. +* +* (c) 2013-2016 Arduino LLC. +*/ + +int speakerPin = 8; + +void setup() { + pinMode(speakerPin, OUTPUT); +} + +void loop() { + digitalWrite(speakerPin, HIGH); + delay(1000); + digitalWrite(speakerPin, LOW); + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.5_beep/_2.5_beep.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.5_beep/_2.5_beep.ino new file mode 100644 index 00000000..2b76a685 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.5_beep/_2.5_beep.ino @@ -0,0 +1,20 @@ +/* +* _2.5_beep +* +* The piezo makes clicks with a 1 millisecond interval. +* +* (c) 2013-2016 Arduino LLC. +*/ +int speakerPin = 8; + +void setup() { + pinMode(speakerPin, OUTPUT); +} + +void loop() { + digitalWrite(speakerPin, HIGH); + delay(1); + digitalWrite(speakerPin, LOW); + delay(1); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.6_beep/_2.6_beep.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.6_beep/_2.6_beep.ino new file mode 100644 index 00000000..9da4de72 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.6_beep/_2.6_beep.ino @@ -0,0 +1,15 @@ +/* +* _2.6_beep +* +* The piezo uses the tone() function to generate an A with a frequency of 440 hertz. +* +* (c) 2013-2016 Arduino LLC. +*/ +void setup() { + tone(8, 440, 1000); +} + +void loop() { + +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.7_digital_input/_2.7_digital_input.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.7_digital_input/_2.7_digital_input.ino new file mode 100644 index 00000000..4e4d2d71 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.7_digital_input/_2.7_digital_input.ino @@ -0,0 +1,25 @@ +/* +* _2.7_digital_input +* +* The board will turn the on-board LED on or off +* +* (c) 2013-2016 Arduino LLC. +*/ + +int inputPin = 5; +int ledPin = 13; + +void setup() { + pinMode(inputPin, INPUT); + pinMode(ledPin, OUTPUT); +} + +void loop() { + if (digitalRead(inputPin) == HIGH) { + digitalWrite(ledPin, HIGH); + } + else { + digitalWrite(ledPin, LOW); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.8_digital_input/_2.8_digital_input.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.8_digital_input/_2.8_digital_input.ino new file mode 100644 index 00000000..493d2ea6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Concepts/_2.8_digital_input/_2.8_digital_input.ino @@ -0,0 +1,25 @@ +/* +* _2.8_digital_input +* +* The board will turn the on-board LED on or off, with a button module +* +* (c) 2013-2016 Arduino LLC. +*/ + +int inputPin = 6; +int ledPin = 13; + +void setup() { + pinMode(inputPin, INPUT); + pinMode(ledPin, OUTPUT); +} + +void loop() { + if (digitalRead(inputPin) == HIGH) { + digitalWrite(ledPin, HIGH); + } + else { + digitalWrite(ledPin, LOW); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/Basketball.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/Basketball.ino new file mode 100644 index 00000000..49da5abd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/Basketball.ino @@ -0,0 +1,65 @@ +/* +* Basketball +* +* Score a goal! +* +* In this game, players will try to bounce a ping pong ball +* into a cup. Make five points to win. The score is tracked +* using a LightSensor. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include +#include "pitches.h" +/* +An array of pin numbers to which LEDs are attached +the defaults are 2 to 6 but you can choose any of the digital pins +*/ +int ledPins[] = {2, 3, 4, 5, 6}; +int pinCount = 5; +VUMeter vuMeter; + +Melody piezo = Melody(8); // the piezo connected to digital pin 8 +LightSensor sensor = LightSensor(A1); //the LightSensor connected to analog pin 1 + +int score = 0; + +void setup(){ + //if your are using other pins than 2 to 6 you need to configure that here + vuMeter.config(pinCount, ledPins); + vuMeter.begin(); //does the same as pinMode, LEDs are outputs + + sensor.config(800, 600); //first run the LightSensorTest example to see what values you need to put here +} + +void loop(){ + //if the LightSensor is covered the score increases with 1 + //and a sound is played + sensor.pressed(); + score++; + vuMeter.fill(score); //Turn on as many LEDs as the score + + int melody[] = { NOTE_GS4, NOTE_C5}; + int noteDurations[] = { 8, 8}; + int numberOfNotes = 2; + piezo.play(numberOfNotes, melody, noteDurations, 1); + + delay(50); + + if(score>=pinCount) startOver(); //If the score equals the amount of LEDs you start over +} + + +void startOver(){ + score=0; //reset the score + + int melody[] = { NOTE_C5, NOTE_G4,NOTE_G4, NOTE_A4, NOTE_G4, 0, NOTE_B4, NOTE_C5}; + int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 }; + int numberOfNotes = 8; + piezo.play(numberOfNotes, melody, noteDurations, 1); + + vuMeter.blinkAll(50,10); + +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/pitches.h new file mode 100644 index 00000000..55c7d54e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Basketball/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/DigitalDie/DigitalDie.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/DigitalDie/DigitalDie.ino new file mode 100644 index 00000000..f841ab1e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/DigitalDie/DigitalDie.ino @@ -0,0 +1,148 @@ +/* +* DigitalDie +* +* Use this digital die next time you play a board game. +* +* You "throw" the die by shaking a tilt sensor. The LEDs +* will show different numbers, waiting a longer and longer +* time for each number, until it finally stops. Don't be +* too fast to cheer believing it stopped on your desired +* number or you might get disappointed ... +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//declare the pins used for LEDs, 9 LEDs in total +int pinCount=9; +int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 11, 13}; + +/* +declare the tilt switch, it's connected to TinkerKit +port 9 +*/ +TiltSwitch ts=TiltSwitch(9); + +/* + Define the patterns of die values. Each pattern is + an array of 9 integers, indicating the on/off state + of each LED. + And because there're 6 possible patterns, we need a + 2-dimensional array to define all the data. It's a + big array of 6 elements, each element is an array of + 9 integers. +*/ +int die[6][9]={ + //1 + { + 0,0,0, + 0,1,0, + 0,0,0 + }, + + //2 + { + 1,0,0, + 0,0,0, + 0,0,1 + }, + + //3 + { + 1,0,0, + 0,1,0, + 0,0,1 + }, + + //4 + { + 1,0,1, + 0,0,0, + 1,0,1 + }, + + //5 + { + 1,0,1, + 0,1,0, + 1,0,1 + }, + + //6 + { + 1,1,1, + 0,0,0, + 1,1,1 + } +}; + +/* + wait time between the die rolls to a different face. + Notice it's using float type here? Read on! +*/ +float waitTime=1; + +void setup(){ + //Configure each pin as an output. + for(int i=0;i + +//Position of the LEDs in VU-meter is represented +//by their names here. So we can use names to find LEDs later +#define YELLOW_LED_1 0 +#define GREEN_LED 1 +#define RED_LED 2 +#define YELLOW_LED_2 3 + +//An array stores which pins the VU-meter is connected +int ledPins[]={2,3,4,5}; +//How many pins are used by VU-meter +int pinCount=4; +VUMeter lights; + +TiltSwitch player_1 = TiltSwitch(6); +TiltSwitch player_2 = TiltSwitch(9); + +void setup(){ + lights.config(pinCount,ledPins); + + //Initializing components + lights.begin(); + player_1.begin(); + player_2.begin(); + + //We need this for generating random numbers later + randomSeed(analogRead(0)); +} +void loop(){ + lights.clear(); + + //Red LED means both of you should hold the tilt switch sword up right + lights.on(RED_LED); + + //Wait for a random period of time, between 3 seconds + //And 6 seconds. Get ready! + delay(random(3000,6000)); + + lights.off(RED_LED); + //When the green LED turns on, game starts + lights.on(GREEN_LED); + + //Swing your swords as fast as you can, the faster one + //will be returned by getWinner() + int winner=getWinner(); + + //The yellow LED on the side of the winner will light up + if(winner==1){ + lights.on(YELLOW_LED_1); + }else{ + lights.on(YELLOW_LED_2); + } + delay(5000); +} + +//The function below waits for either of the tilter +//switch to be swung. The first one to swing +//will be returned by its number +int getWinner(){ + do{ + if(player_1.pressed(1)){ + return 1; + }else if(player_2.pressed(1)){ + return 2; + } + }while(true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino new file mode 100644 index 00000000..90d6baef --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Pong/Pong.ino @@ -0,0 +1,82 @@ +/* +* Pong +* +* Play a simplified version of the classic arcade game, Pong! +* +* In this game, a “pong” will move across five LEDs (VU-meter) +* and bounce back and forth as players press the button. +* Players must press the button at the right time in order to +* return the pong. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include +/* + An array of pin numbers to which LEDs are attached + the defaults are 2 to 6 but you can choose any of the digital + pins. Just remember to leave digital pin 9 and 6 for the buttons. +*/ +int ledPins[] = {2, 3, 4, 5, 7}; +int pinCount = 5; +VUMeter vuMeter; + +Button button1 = Button(9); //the button connected to digital pin 9 +Button button2 = Button(6); //the button connected to digital pin 6 + +int ledTime = 100; //determines how fast the LEDs will switch +int pressTime = 200; //determines how long time a player has to press the button +int buttonNotPressed = 0; //this keeps track of who missed pressing the button + +void setup(){ + //if you are using other pins than 2 to 6 you need to configure that here + vuMeter.config(pinCount, ledPins); + + vuMeter.begin(); //does the same as pinMode, LEDs are outputs + button1.begin(); //does the same as pinMode, buttons are inputs + button2.begin(); //does the same as pinMode, buttons are inputs + + vuMeter.scrollLeft(ledTime, 1); //The game starts by scrolling the LEDs to the left +} + +void loop(){ + /* + if button1 is pressed within the press time, the game will continue + by scrolling the LEDs to the right + else if button1 is not pressed, the program will jump to gameOver() + */ + if(button1.released(pressTime)){ + vuMeter.scrollRight(ledTime, 1); + } + else{ + buttonNotPressed = 1; //Keep track of where we are in the game + gameOver(); + } + + /* + if button2 is pressed within the press time, the game will continue + by scrolling the LEDs to the left + else if button2 is not pressed, the program will jump to gameOver() + */ + if(button2.released(pressTime)){ + vuMeter.scrollLeft(ledTime, 1); + } + else{ + buttonNotPressed = 2; //Keep track of where we are in the game + gameOver(); + } +} + +/* + When a player doesn't press the right button within the right + time it is game over. Inside the function gameOver() you can + decide how the LEDs should blink. + Use vuMeter.blink(LED,delayTime,numberOfBlinks) to make one specific LED blink + Use vuMeter.blinkAll(delayTime,numberOfBlinks) to make all LEDs blink +*/ +void gameOver(){ + vuMeter.blinkAll(100,10); + + if(buttonNotPressed==1) vuMeter.scrollRight(ledTime, 1); //if button1 was not pressed, scroll LEDs to the right to start over + else if(buttonNotPressed==2) vuMeter.scrollLeft(ledTime, 1); //if button2 was not pressed, scroll LEDs to the left to start over +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Racing/Racing.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Racing/Racing.ino new file mode 100644 index 00000000..a40dfbc8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/Racing/Racing.ino @@ -0,0 +1,69 @@ +/* +* Racing +* +* Run with your fingers as fast as you can. +* +* In this game, the player must tap two sensors repeatedly +* in order to run laps. One LED will light up per lap. +* When all laps are completed, LEDs will blink in victory. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +/* + An array of pin numbers to which LEDs are attached + the defaults are 2 to 6 but you can choose any of the digital pins + just remember to leave digital pin 2,3 and 4 for the capacitive switches +*/ +int ledPins[] = {8, 9, 10, 11, 13}; +int pinCount = 5; +//This variable will let us keep track of which LED to turn on +int LED = 0; +VUMeter scoreBoard; + +//Configure the capacitive sensors +int capacitiveSensorThreshold=400; +CapacitiveSwitch leftFoot=CapacitiveSwitch(2,3); +CapacitiveSwitch rightFoot=CapacitiveSwitch(2,4); + +int score; + +void setup(){ + //initializing the game, set up all the components and variables + score=0; + + //Connect scoreboard + scoreBoard.config(pinCount,ledPins); + scoreBoard.begin(); + + //initialize left and right "foot" + leftFoot.config(capacitiveSensorThreshold); + rightFoot.config(capacitiveSensorThreshold); +} + +void loop(){ + //Wait for the left foot to be pressed + leftFoot.pressed(); + scoreBoard.on(LED); + + //Wait for the right foot to be pressed + rightFoot.pressed(); + scoreBoard.off(LED); + + score=score+1; //After both feet are pressed, add one point + + //Every 20 points light up a LED + LED =score/20; + scoreBoard.fill(LED); + + //When you get 100 points, you win + if(score>100){ + //if you win, blink all LEDs for celebration + //See vuMeter in reference list to make your own blink animation + scoreBoard.blinkAll(50,5); + //and reset the game + score=0; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/React.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/React.ino new file mode 100644 index 00000000..e2b6672b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/React.ino @@ -0,0 +1,80 @@ +/* +* React +* +* Test your reaction time! +* +* In this game, one of three LEDs will randomly light up. +* You must tap the corresponding capacitive sensor as quick +* as possible. If you don’t react fast enough, the game is over. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include +#include "pitches.h" + +//Define the 3 LEDs +int ledPins[] = {9, 10, 11}; +int pinCount = 3; +VUMeter LEDs; + +//There're 3 pads for pressing +CapacitiveSwitch pad[3]; + +//You have 500 milliseconds to press the pad +int reactTime = 500; + +// the piezo connected to digital pin 8 +Melody piezo = Melody(8); + +void setup(){ + LEDs.config(pinCount, ledPins); + LEDs.begin(); + + //Configure the pads + pad[0] = CapacitiveSwitch(2,3); + pad[1] = CapacitiveSwitch(2,4); + pad[2] = CapacitiveSwitch(2,5); + pad[0].config(100); + pad[1].config(100); + pad[2].config(100); +} + +void loop(){ + //Wait for a random time before each turn begins + delay(random(50, 2000)); + + //pick a target between the 3 pads + int target = random(0, 3); + //Light up the LED + LEDs.on(target); + + //If the pad corresponding to the LED is pressed + if(pad[target].pressed(reactTime)){ + LEDs.off(target); + + //Play the winning sound + int melody[] = { NOTE_GS4, NOTE_C5}; + int noteDurations[] = { 8, 8}; + int numberOfNotes = 2; + piezo.play(numberOfNotes, melody, noteDurations, 1); + } + else{ + //Else if the reaction is too slow, run the function gameOver() + gameOver(); + } +} + +void gameOver(){ + //Turn all LEDs on + LEDs.fill(pinCount); + + //Play a melody + int melody[] = { NOTE_E2, NOTE_C2}; + int noteDurations[] = { 2, 1}; + int numberOfNotes = 2; + piezo.play(numberOfNotes, melody, noteDurations, 1); + + LEDs.blinkAll(100, 10); + LEDs.fill(0); //Tun all LEDs off +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/pitches.h new file mode 100644 index 00000000..55c7d54e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/React/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/SimonSays/SimonSays.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/SimonSays/SimonSays.ino new file mode 100644 index 00000000..df7b4498 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block2-Sports/Projects/SimonSays/SimonSays.ino @@ -0,0 +1,119 @@ +/* +* SimonSays +* +* Test your memory with this game! +* +* LEDs will blink in a pattern that you have to remember and repeat. +* If you get it right, the game gets more and more challenging. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +#include + +/* + An array of pin numbers to which LEDs are attached + the defaults are 2 to 6 but you can choose any of the digital + pins. +*/ +int ledPins[] = {2, 3, 4, 5, 6}; +int pinCount = 5; +VUMeter vuMeter; + +Knob pot=Knob(A0);//a knob is connected to A0 + +Button button = Button(9); //a button is connected to port D9 + +Melody piezo=Melody(8);//a piezo is connected to digital pin 8 + +//Set the game parameters +int turns_begin=2;//a new game starts with 2 turns +int turns_max=10;//the most difficult game has 10 turns + +int game[10];//array for storing the "simon says" +int turns=2;//for storing the number of turns in current game +int blinkTime=500;//how fast does "simon says" blink + +void setup(){ + //initialize the components + vuMeter.config(pinCount, ledPins); + vuMeter.begin(); + pot.setLevels(5); + button.begin(); + + //Create a random seed, so we can call random() later. + randomSeed(analogRead(A5)); +} +void loop(){ + newGame(); + simonSays(); + delay(1000); + getInputs(); +} + +void newGame(){ + vuMeter.blinkAll(200, 3); + vuMeter.clear(); + delay(500); + //Generate simon says, it'll be stored in an array + //So we can compare with player's input later + for(int i=0;i 255) fade = 0; +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.3_light_sensor/_3.3_light_sensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.3_light_sensor/_3.3_light_sensor.ino new file mode 100644 index 00000000..08c61a42 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.3_light_sensor/_3.3_light_sensor.ino @@ -0,0 +1,24 @@ +/* +* _3.3_light_sensor +* +* The board changes the light intensity of an LED depending on the readings from a light sensor. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +int ledPin=9; +int lightSensorPin=A1; + +void setup() { + //nothing here +} + +void loop() { + int lightSensorValue=analogRead(lightSensorPin); + int ledValue=map(lightSensorValue,0,1023,0,255); + + analogWrite(ledPin, ledValue); + delay(10); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.4_light_sensor/_3.4_light_sensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.4_light_sensor/_3.4_light_sensor.ino new file mode 100644 index 00000000..51a6f2b4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.4_light_sensor/_3.4_light_sensor.ino @@ -0,0 +1,31 @@ +/* +* _3.4_light_sensor +* +* The light sensor acts as a switch and turns an LED on or off depending on the readings. +* With a potentiometer to set the switch threshold. +* +* (c) 2013-2016 Arduino LLC. +*/ + +int ledPin=9; +int lightSensorPin=A1; +int potPin=A5; + +void setup() { + pinMode(ledPin,OUTPUT); +} + +void loop() { + int lightSensorValue=analogRead(lightSensorPin); + int threshold=analogRead(potPin); + + if(lightSensorValue>threshold){ + digitalWrite(ledPin,LOW); + } + else{ + digitalWrite(ledPin,HIGH); + } + + delay(10); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.5_sending_serial/_3.5_sending_serial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.5_sending_serial/_3.5_sending_serial.ino new file mode 100644 index 00000000..ae0307da --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.5_sending_serial/_3.5_sending_serial.ino @@ -0,0 +1,17 @@ +/* +* _3.5_sending_serial +* +* The board will send a text message from the board to the computer and Serial Monitor +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.println("Hello World"); + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.6_sending_serial/_3.6_sending_serial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.6_sending_serial/_3.6_sending_serial.ino new file mode 100644 index 00000000..29a10680 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.6_sending_serial/_3.6_sending_serial.ino @@ -0,0 +1,19 @@ +/* +* _3.6_sending_serial +* +* The board will read the analog value from a light sensor and print that value to the Serial Monitor. +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + Serial.begin(9600); +} + +void loop() { + int sensorValue = analogRead(A1); + + Serial.println(sensorValue); + delay(100); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.7_receiving_serial/_3.7_receiving_serial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.7_receiving_serial/_3.7_receiving_serial.ino new file mode 100644 index 00000000..be940a81 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Concepts/_3.7_receiving_serial/_3.7_receiving_serial.ino @@ -0,0 +1,29 @@ +/* +* _3.7_receiving_serial +* +* The board turns the on-board LED on or off by sending an ‘H’ or ‘L’ to the control board from the Serial Monitor +* +* (c) 2013-2016 Arduino LLC. +*/ + +int ledPin=13; +int incomingByte; + +void setup() { + Serial.begin(9600); + pinMode(ledPin,OUTPUT); +} +void loop() { + if(Serial.available()>0){ + incomingByte=Serial.read(); + + if(incomingByte=='H'){ + digitalWrite(ledPin, HIGH); + } + if(incomingByte=='L'){ + digitalWrite(ledPin,LOW); + } + + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/BinaryLP.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/BinaryLP.ino new file mode 100644 index 00000000..92ef9dff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/BinaryLP.ino @@ -0,0 +1,87 @@ +/* +* BinaryLP +* +* This sort of works as an LP player. The difference is +* that instead of using a needle on a plastic disc, +* we use three IR sensors in a row to read a pattern from +* a paper disc. +* +* If you are both musically and digitally inclined, +* you will have lots of fun creating melodies with this. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +#include +#include "pitches.h" + +//IRArray(left, middle, right); +IRArray ir = IRArray(A1, A2, A3); + +int piezo = 8; //Piezo pin +int lastReading = 0; + +void setup(){ + pinMode(piezo, OUTPUT); + + //Use this line to set the threshold of the IR sensors. + //If you are using the Uno board, set the threshold to 380. If you're using the 101 board, set it to 530. + //Use ir.test() to check the values of each sensor in the loop() + ir.setThreshold(530); + + Serial.begin(9600); +} + +void loop(){ + //Use this line to check the values from each IR sensor + //ir.test(); + + //Read the binary pattern and get a number from 0 to 7 + int reading = ir.readBinary(); + + //Play a note depending on the read value + playNote(reading); + +} + +void playNote(int r){ + //If the last note we played is the same as the new note + //we make a short break so that two notes are distinguished + if(lastReading==r){ + noTone(piezo); + delay(20); + } + + //Play a different note depending on the value of r. + //Check pitches.h to see which notes you can use. + //In this case the scale is C Major. + switch (r){ + case 0: + break; + case 1: + tone(piezo, NOTE_C4); + break; + case 2: + tone(piezo, NOTE_D4); + break; + case 3: + tone(piezo, NOTE_E4); + break; + case 4: + tone(piezo, NOTE_F4); + break; + case 5: + tone(piezo, NOTE_G4); + break; + case 6: + tone(piezo, NOTE_A4); + break; + case 7: + tone(piezo, NOTE_B4); + break; + } + + //If r is more than 0 we save that value to lastReading + if(r>0)lastReading = r; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/pitches.h new file mode 100644 index 00000000..55c7d54e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/BinaryLP_Workshop.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/BinaryLP_Workshop.ino new file mode 100644 index 00000000..92ef9dff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/BinaryLP_Workshop.ino @@ -0,0 +1,87 @@ +/* +* BinaryLP +* +* This sort of works as an LP player. The difference is +* that instead of using a needle on a plastic disc, +* we use three IR sensors in a row to read a pattern from +* a paper disc. +* +* If you are both musically and digitally inclined, +* you will have lots of fun creating melodies with this. +* +* (c) 2013-2016 Arduino LLC. +*/ + + +#include +#include "pitches.h" + +//IRArray(left, middle, right); +IRArray ir = IRArray(A1, A2, A3); + +int piezo = 8; //Piezo pin +int lastReading = 0; + +void setup(){ + pinMode(piezo, OUTPUT); + + //Use this line to set the threshold of the IR sensors. + //If you are using the Uno board, set the threshold to 380. If you're using the 101 board, set it to 530. + //Use ir.test() to check the values of each sensor in the loop() + ir.setThreshold(530); + + Serial.begin(9600); +} + +void loop(){ + //Use this line to check the values from each IR sensor + //ir.test(); + + //Read the binary pattern and get a number from 0 to 7 + int reading = ir.readBinary(); + + //Play a note depending on the read value + playNote(reading); + +} + +void playNote(int r){ + //If the last note we played is the same as the new note + //we make a short break so that two notes are distinguished + if(lastReading==r){ + noTone(piezo); + delay(20); + } + + //Play a different note depending on the value of r. + //Check pitches.h to see which notes you can use. + //In this case the scale is C Major. + switch (r){ + case 0: + break; + case 1: + tone(piezo, NOTE_C4); + break; + case 2: + tone(piezo, NOTE_D4); + break; + case 3: + tone(piezo, NOTE_E4); + break; + case 4: + tone(piezo, NOTE_F4); + break; + case 5: + tone(piezo, NOTE_G4); + break; + case 6: + tone(piezo, NOTE_A4); + break; + case 7: + tone(piezo, NOTE_B4); + break; + } + + //If r is more than 0 we save that value to lastReading + if(r>0)lastReading = r; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/pitches.h new file mode 100644 index 00000000..55c7d54e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BinaryLP_Workshop/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BoomBox/BoomBox.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BoomBox/BoomBox.ino new file mode 100644 index 00000000..b27d2344 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/BoomBox/BoomBox.ino @@ -0,0 +1,65 @@ +/* +* BoomBox +* +* This is your first step towards these kinds of skills: +* http://www.youtube.com/watch?v=FcJCxe1VSLA&noredirect=1 +* The boom box is a small sample player you can use to make music, +* or just random sound. It comes with three prerecorded samples +* but we probably don’t have the same creative cleverness when it +* comes to recording as you do so you should definitely record your +* own samples too! +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare a button group with 3 buttons. The +//sound player secretly takes pin 3, 4 and 11, +//so don't use them. +ButtonGroup bg; +int buttons[]={5,6,7}; + +//There're 3 buttons in the button group. +int buttonsCount=3; + +//Declare the sound player +Player player=Player(); + +void setup(){ + // Open serial communications and wait for port to open: + Serial.begin(9600); + + // Initialize the sound player. Open the Serial Monitor to see + //the sound files found on your micro SD card + player.begin(); + + //Initialize the button group. + bg.begin(buttonsCount,buttons); +} + +void loop(){ + //Wait for one of the buttons to be pressed. + //According to which button is pressed, it + //returns either 0, 1 or 2 + int pressedButton=bg.pressed(); + + //Play a different sound according to the + //button pressed. + switch(pressedButton){ + case 0: + Serial.println("sound 0"); + player.play("0.wav"); + break; + case 1: + Serial.println("sound 1"); + player.play("1.wav"); + break; + case 2: + Serial.println("sound 2"); + player.play("2.wav"); + break; + } + +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/CookieMonster/CookieMonster.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/CookieMonster/CookieMonster.ino new file mode 100644 index 00000000..2a5c5e26 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/CookieMonster/CookieMonster.ino @@ -0,0 +1,47 @@ +/* +* CookieMonster +* +* Someone is eating our cookies, let's gather some proof +* about that person and get him/her to confess. +* +* (c) 2013-2016 Arduino LLC. B&D Cuartielles +* +* This code is Free Software, licensed under GPLv3 +* Based on code by Paul Badger 2008 +* +*/ + + +#include + +//Define the capacitive sensor +CapacitiveSwitch sensor=CapacitiveSwitch(2,3); + +//Define the LED +int led = 6; + +void setup() +{ + // configure the serial port + Serial.begin(9600); + + //initialize components + sensor.config(200); + pinMode(led, OUTPUT); + } + +void loop(){ + //When someone attempts to open the + //cookie jar, the sensor is activated + if(sensor.pressed()){ + //Turn on the LED + digitalWrite(led, HIGH); + //Sends signal to processing, so a picture + //will be captured + Serial.print('p'); + //Wait 2 seconds before turning the LED off + delay(2000); + digitalWrite(led, LOW); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/Drawdio.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/Drawdio.ino new file mode 100644 index 00000000..04f9885b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/Drawdio.ino @@ -0,0 +1,59 @@ +/* +* Drawdio +* +* Draw audio with drawdio. You might think that this pen is magic, +* and it might just be. Drawdio turns (almost) everything that is +* conductive into an instrument. You can either make music by +* drawing a picture or by touching the tip of it to different +* conductive things around you. +* +* (c) 2013-2016 Arduino LLC. +* Inspiration from Jay Siver's DRAWDIO +* http://web.media.mit.edu/~silver/drawdio/ +* +*/ + +#include +#include "pitches.h" + +//Capacitive switch connected between 2 and 3 +CapacitiveSwitch me=CapacitiveSwitch(2,3); + +//A piezo speaker connected to digital pin 8 +Melody speaker=Melody(8); + +//The range of capacitive sensor values to be +//mapped to music tones. See example +//"Help/CapacitiveSwitchTest" for how to get +//the values +int lowerThreshold=80; +int upperThreshold=900; + +//Define the lowest and highest tone. Defined +//in pitches.h +int toneLow=NOTE_C3; +int toneHigh=NOTE_B6; + +void setup(){ + //Nothing to do here. Magic? +} +void loop(){ + //Get value of the sensor. If it's smaller + //than the threshold, it'll be 0 + int value=me.getValue(lowerThreshold); + + //map the sensor value to tones. The map() + //function maps values smaller than lower + //threshold to the lowest desired value. If + //you want to keep drawdio quiet when you're + //not playing, you have to deal with 0 separately + int pitch; + if(value>0){ + pitch=map(value,lowerThreshold,upperThreshold,toneLow,toneHigh); + }else{ + pitch=0; + } + + //Play the tone to the speaker. + speaker.playTone(pitch,10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/pitches.h new file mode 100644 index 00000000..55c7d54e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Drawdio/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/KnockKnockBox/KnockKnockBox.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/KnockKnockBox/KnockKnockBox.ino new file mode 100644 index 00000000..e0f6ed38 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/KnockKnockBox/KnockKnockBox.ino @@ -0,0 +1,104 @@ +/* +* KnockKnockBox +* +* Knock on this coffin to awake the dead. Don’t worry, +* the skeleton won’t get out and come after you but it +* will reply from inside. +* +* Ok, we know that you know that there isn’t a real +* skeleton there. It's really a piezo used as a knock +* sensor. After you've made this project you might +* think of a handy way to use this sensor in other ways. +* Check out this secret knock detecting lock for some +* inspiration: http://www.youtube.com/watch?v=zE5PGeh2K9k +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The number of knocks that can be recorded +#define MAX_KNOCKS 30 + +PiezoKnockSensor sensor=PiezoKnockSensor(A0); +int speaker = 8; + +//An array for remembering the knock pattern +long timer[MAX_KNOCKS]; + +//If it has started recording +boolean started; + +//Used for calculating if you have finished the pattern +long timeoutBase; + +//If you stop knocking for the period of timeout, it'll +//stop recording +long timeout=2000; + +//Keep track of the number of knocks you've knocked +int currentKnock; + +void setup(){ + //define the threshold and debounce time of the knock + //sensor. Threshold defines how hard you need to knock, + //debounce time prevents the sensor from detecting + //false knocks, but also limits how rapid you can knock. + sensor.config(100,80); + + //initializing the values + started=false; + timeoutBase=0; + currentKnock=0; + clearArray(); +} + +void loop(){ + //Knock sensor waits for a short time if a knock is detected + //and then move on. + if(sensor.knocked(20)){ + //If it's the first knock in the round, start recording + if(!started){ + started=true; + } + + long currentTime=millis(); + //Reset timeout + timeoutBase=currentTime; + //Save the amount of milliseconds that have + //passed since the last knock + timer[currentKnock]=currentTime; + currentKnock++; + } + if(started){ + //If recording has started and you stop + //knocking for the time of "timeout", it'll + //stop recording and play it back to you. + if(millis()-timeoutBase>timeout){ + playback(); + //reset the parameters, so a new round begins + started=false; + clearArray(); + currentKnock=0; + } + } +} +void clearArray(){ + //clean up values in the timer array + for(int i=0;i +/* +An array of pin numbers to which LEDs are attached +the defaults are 2 to 6 but you can choose any of the digital pins +*/ +int ledPins[] = {2, 3, 4, 5, 6}; +int pinCount = 5; +VUMeter vuMeter; + +int rowCount = 0; // Stores the number of rows +int rowLength = 22; // Width of the message, copy this number to the message array +int delayTime = 9; // Time it takes to show a row in milliseconds + +// The message where 0 is LOW and 1 is HIGH +boolean message[5][22]={ + // H H H H O O O O L L L L A A A A + {0,1,0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,1,1,0,0,0}, + {0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,1,0,0}, + {0,1,1,1,1,0,1,0,0,1,0,1,0,0,0,0,1,1,1,1,0,0}, + {0,1,0,0,1,0,1,0,0,1,0,1,0,0,0,0,1,0,0,1,0,0}, + {0,1,0,0,1,0,0,1,1,0,0,1,1,1,1,0,1,0,0,1,0,0} + +}; + +void setup(){ + // If your are using other pins than 2 to 6 you need to configure that here + vuMeter.config(pinCount, ledPins); + + vuMeter.begin(); //does the same as pinMode, LEDs are outputs +} + +void loop(){ + // If the whole array has been drawn + if(rowCount == rowLength) { + rowCount = 0; // Reset the rowCount + } else { + // Shows the message + for (int i = 0; i < pinCount; i++) { + // Checks if the array says HIGH + if (message[i][rowCount] == 1) { + vuMeter.on(i); + } else { + vuMeter.off(i); + } + } + rowCount++; + } + + delay(delayTime);// This is the delay per row + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Sequencer/Sequencer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Sequencer/Sequencer.ino new file mode 100644 index 00000000..f28e59fb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block3-Magic/Projects/Sequencer/Sequencer.ino @@ -0,0 +1,115 @@ +/* +* Sequencer +* +* Play beats and change the sequence in real time. Basically +* all you need to become a hiphop artist. That, and rapping +* skills. But that's another course. +* +* (c) 2013-2016 Arduino LLC. +*/ +#include + +//Declare the sound player +Player player=Player(); + +//There're 4 slots for 4 sequences. We use 4 analog pins +//to read them. +int analog_pins[]={3,2,1,0}; +int pin_count=4; +int analog_values[4]; + +//Template for the music file names. +char filename[]="seq0.wav"; + +void setup(){ + // Open serial communications and wait for port to open: + Serial.begin(9600); + + //The system automatically calibrates itself + calibrate(); + + // Initialize the sound player. Open the Serial Monitor to see + //the sound files found on your micro SD card + player.begin(); + +} +void loop(){ + //Loop through 4 pins and play the right sequence accordingly + for(int i=0;i1010); + analog_values[i]=val; + } + for(int i=0;i<4;i++){ + for(int j=i;j<4;j++){ + if(analog_values[i]>analog_values[j]){ + int temp=analog_values[i]; + analog_values[i]=analog_values[j]; + analog_values[j]=temp; + } + } + } + Serial.println("Done Calibration"); +} + +int getSeq(int analogVal){ + for(int i=0;i<4;i++){ + if(analogVal>analog_values[i]-50 && analogVal200 && analogVal<300){ //220 Ohm + return 1; + }else if(analogVal>360 && analogVal<460){ //470 Ohm + return 2; + }else if(analogVal>480 && analogVal<580){ //680 Ohm + return 3; + }else if(analogVal>600 && analogVal<700){ //1k2 Ohm + return 4; + }else{ //No resistor + return 0; + } +*/ + //If you're using Arduino 101, the same resistors give + //different analog read values. Use the following code + //instead. + /* + if(analogVal>200 && analogVal<300){ //220 Ohm + return 1; + }else if(analogVal>400 && analogVal<500){ //470 Ohm + return 2; + }else if(analogVal>600 && analogVal<700){ //680 Ohm + return 3; + }else if(analogVal>800 && analogVal<900){ //1k2 Ohm + return 4; + }else{ //No resistor + return 0; + }*/ +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.1_standard_servo/_4.1_standard_servo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.1_standard_servo/_4.1_standard_servo.ino new file mode 100644 index 00000000..ff1c4b9a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.1_standard_servo/_4.1_standard_servo.ino @@ -0,0 +1,23 @@ +/* +* _4.1_standard_servo +* +* The board will control the servo to repeatedly move its arm between 0 and 180 degrees. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo myservo; + +void setup() { + myservo.attach(6); +} + +void loop() { + myservo.write(0); + delay(1000); + myservo.write(180); + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.2_continuous_servo/_4.2_continuous_servo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.2_continuous_servo/_4.2_continuous_servo.ino new file mode 100644 index 00000000..ec768144 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.2_continuous_servo/_4.2_continuous_servo.ino @@ -0,0 +1,23 @@ +/* +* _4.2_continuous_servo +* +* The board will control the continuous rotation servo by writing a speed to it instead of a position. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo myservo; + +void setup() { + myservo.attach(6); +} + +void loop() { + myservo.write(0); + delay(1000); + myservo.write(180); + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.3_input_controlled_servo/_4.3_input_controlled_servo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.3_input_controlled_servo/_4.3_input_controlled_servo.ino new file mode 100644 index 00000000..28a1a79b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.3_input_controlled_servo/_4.3_input_controlled_servo.ino @@ -0,0 +1,26 @@ +/* +* _4.3_input_controlled_servo +* +* The board will use a potentiometer to control the position of a standard servo. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo myservo; +int potPin = A5; +int val; + +void setup() { + myservo.attach(6); +} + +void loop() { + val = analogRead(potPin); + val = map(val, 0, 1023, 0, 179); + + myservo.write(val); + delay(15); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.4_two_servos/_4.4_two_servos.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.4_two_servos/_4.4_two_servos.ino new file mode 100644 index 00000000..623cce64 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Concepts/_4.4_two_servos/_4.4_two_servos.ino @@ -0,0 +1,33 @@ +/* +* _4.4_two_servos +* +* The board will control two servos, moving one at a time to make sure that it can provide enough current. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo myservo1, myservo2; + +void setup() { + myservo1.attach(6); + myservo2.attach(9); +} + +void loop() { + myservo2.detach(); + myservo1.attach(6); + myservo1.write(70); + delay(1000); + myservo1.write(120); + delay(1000); + + myservo1.detach(); + myservo2.attach(9); + myservo2.write(70); + delay(1000); + myservo2.write(120); + delay(1000); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino new file mode 100644 index 00000000..b8908342 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CameraRobot/CameraRobot.ino @@ -0,0 +1,58 @@ +/* +* CameraRobot +* +* Spy on your cat with this robot camera. Mount the camera robot and +* control it with a small joystick. You can run everything from the +* computer and when you see your cat doing something suspicious, +* take a picture! +* +* You need to run the processing sketch included in the sketch folder +* to be able to take photos with a webcam connected to your computer. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The joystick uses two analog pins. Here pin A0 and A1 +Joystick joystick = Joystick(A1,A0);//Joystick(XanalogPin, YanalogPin) + +Servo pan, tilt; + +int panAngle = 90; //Pan angle starts in the middle position +int tiltAngle = 90; //Tilt angle starts in the middle position + +int panJoystick = 0; +int tiltJoystick = 0; + +void setup(){ + //servos are initialized + pan.attach(6); + tilt.attach(9); +} +void loop(){ + panJoystick = joystick.getX(); //Get X value from joystick + tiltJoystick = joystick.getY(); //Get Y value from joystick + + //If the joysticks X value isn't 0 we will pan + if(panJoystick!=0){ + //If the X value from the joystick equals 1 and + //panAngle is less than 180 degrees, increase panAngle with 1 + if(panJoystick==1 && panAngle<180) panAngle++; + //If the X value from the joystick equals -1 and + //panAngle is more than 0 degrees, decrease panAngle with 1 + else if(panJoystick==-1 && panAngle>0) panAngle--; + } + //If the joysYicks Y value is 0 we will tilt + if(tiltJoystick!=0){ + //If the Y value from the joystick equals 1 and + //tiltAngle is less than 180 degrees, increase tiltAngle with 1 + if(tiltJoystick==1 && tiltAngle<180) tiltAngle++; + //If the Y value from the joystick equals -1 and + //tiltAngle is more than 0 degrees, decrease tiltAngle with 1 + else if(tiltJoystick==-1 && tiltAngle>0) tiltAngle--; + } + pan.write(panAngle); //Set position of the pan servo + tilt.write(tiltAngle); //Set position of the tilt servo + delay(5); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CrawlingRobot/CrawlingRobot.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CrawlingRobot/CrawlingRobot.ino new file mode 100644 index 00000000..964003a4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/CrawlingRobot/CrawlingRobot.ino @@ -0,0 +1,35 @@ +/* +* CrawlingRobot +* +* This small robot can crawl. It’s all it can do, and it isn’t +* very good at it. But it is super cute and great fun. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo front, back; + +void setup(){ + //servos are initialized + front.attach(6); + back.attach(9); +} + +void loop(){ + //Make the robot crawl by setting the servos to opposite angles. + //90 is the middle angle + + //First step of each pair of legs + front.write(110); + delay(200); + back.write(70); + delay(200); + + //Second step of each pair of legs + front.write(70); + delay(200); + back.write(110); + delay(200); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LightChaser/LightChaser.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LightChaser/LightChaser.ino new file mode 100644 index 00000000..27f520b8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LightChaser/LightChaser.ino @@ -0,0 +1,41 @@ +/* +* LightChaser +* +* This little vehicle is on an impossible, never ending +* mission to catch the light. You can make it follow you +* by pointing a flashlight at it. (The one on your mobile +* phone eg.) It will always turn towards the light. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the two wheels of robot, left wheel to D6 and +// right wheel to D9 +Wheels wheels=Wheels(6, 9); + +//Declare the two LightSensor +LightSensor sensorLeft=LightSensor(A0); +LightSensor sensorRight=LightSensor(A2); + +void setup(){ + //initialize the LightSensor + sensorLeft.config(600,800); + sensorRight.config(600,800); + + //initialize the servo motors + wheels.begin(); +} +void loop(){ + if(sensorLeft.getState()){ + //Left LightSensor detects strong light, the vehicle turns left + wheels.turnLeft(); + }else if(sensorRight.getState()){ + //Right LightSensor detects strong light, the vehicle turns right + wheels.turnRight(); + }else{ + //No strong light detected, the vehicle goes straight + wheels.goForward(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LineFollower/LineFollower.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LineFollower/LineFollower.ino new file mode 100644 index 00000000..f1e091e8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/LineFollower/LineFollower.ino @@ -0,0 +1,30 @@ +/* +* LineFollower +* The Line Follower does exactly what the name suggests, +* it follows a line. Make it go wherever you want by +* showing the way with a 3 cm wide, black line. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//IRArray(IR1, IR2, IR3) +IRArray ir = IRArray(A1, A2, A3); +//Wheels(left, right) +Wheels wheels=Wheels(6, 9); + +void setup(){ + wheels.begin(); + + //Use this line to set the threshold of the IR sensors. The default is 380. If you're using Arduino 101 board, use 530 instead. + //Use test() to check the values of each sensor in loop() + ir.setThreshold(530); + + delay(1000); +} + +void loop(){ + int dir = ir.readLine(); + wheels.follow(dir); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/MagicBox/MagicBox.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/MagicBox/MagicBox.ino new file mode 100644 index 00000000..8c535961 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/MagicBox/MagicBox.ino @@ -0,0 +1,44 @@ +/* +* MagicBox +* +* MagicBox is an open source box that contains open source +* electronics. Oh, and it automatically opens when you +* knock on it. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the piezo knock sensor. Connected to A0 +PiezoKnockSensor sensor=PiezoKnockSensor(A0); + +//Declare the servo motor for opening the lid +Servo lidOpener; + +void setup(){ + //define the threshold and debounce time of the knock + //sensor. Threshold defines how hard you need to knock, + //debounce time prevents the sensor from detecting + //false knocks, but also limits how rapid you can knock. + //See the PiezoKnockSensor sketch in the help folder + //to make sure your values are correct + sensor.config(100,80); + + //initialize the servo + lidOpener.attach(9); + //Rotate servo to close lid + lidOpener.write(60); +} +void loop(){ + + if(sensor.knocked(20)){ + //rotate the servo motor to open the lid + lidOpener.write(0); + delay(3000); //Wait for 3 seconds + //close the lid + lidOpener.write(60); + delay(200); + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/TickleRobot/TickleRobot.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/TickleRobot/TickleRobot.ino new file mode 100644 index 00000000..62e395d5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block4-Robots/Projects/TickleRobot/TickleRobot.ino @@ -0,0 +1,38 @@ +/* +* TickleRobot +* +* This is just a regular ticklish robot in a rocking chair. +* Come to think of it, that doesn't sound very regular at all. +* Tickle the robot on its heart and it will start to wiggle like crazy. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the servo for controlling the string robot +Servo pull; + +//Declare the capacitive sensor +CapacitiveSwitch sensor=CapacitiveSwitch(2,3); + +void setup(){ + //initialize the capacitive sensor. Threshold is 400 + //See the example CapacitiveSwitchTest in the Help folder + //to find the right threshold + sensor.config(400); + + //initialize the servo motor + pull.attach(9); +} +void loop(){ + if(sensor.getState()){ + //If the capacitive sensor is touched, pull the strings + pull.write(0); + }else{ + //Otherwise, loosen the strings + pull.write(90); + } + delay(30); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.1_gyro_demo/_5.1_gyro_demo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.1_gyro_demo/_5.1_gyro_demo.ino new file mode 100644 index 00000000..94c6f5a7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.1_gyro_demo/_5.1_gyro_demo.ino @@ -0,0 +1,86 @@ +/* +* _5.1_gyro_demo +* +* The Piezo will play sound based on how fast you tilt the board in the X and Y axes. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + +IMU imu; // the IMU + +const int piezoPin = 8; //piezo + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + + +void setup() { + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed + + + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + + imu.begin(); + + + + + // blink the LED again to show that the calibration is done + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + + pinMode(piezoPin, OUTPUT); +} + +void loop() { + // start the IMU read + imu.run(); + + // read raw gyro measurements from the IMU device + int gx = imu.getGyroX(); + int gy = imu.getGyroY(); + + // map the raw value to be on a smaller scale + gx = map(gx, -36044 , 36043 , -360, 360); + gy = map(gy, -36044 , 36043 , -360, 360); + + + // print the measurements + Serial.print(gx); + Serial.print("\t"); + Serial.println(gy); + + + + //Computes the absolute value of the IMU read + gx = abs(gx); + gy = abs(gy); + + + + // add together the 2 values and use them for setting the frequency for the speaker to play + int frequency = gx + gy; + frequency = frequency / 2; + frequency = map(frequency, 0, 360, 0, 1000); + + // only play a sound if the frequency is not too low or the IMU is still + if (frequency > 50) { + tone(piezoPin, frequency); + } else { + noTone(piezoPin);// stop the sound + } + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.2_acc_demo/_5.2_acc_demo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.2_acc_demo/_5.2_acc_demo.ino new file mode 100644 index 00000000..c4e53d3b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.2_acc_demo/_5.2_acc_demo.ino @@ -0,0 +1,87 @@ +/* +* _5.2_acc_demo +* +* The Piezo will play sound based on how fast you move the board in the X and Y axes. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + + +IMU imu; // the IMU + +const int piezoPin = 8; //piezo + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + + +void setup() { + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed + + + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + + imu.begin(); + + + + + // blink the LED again to show that the calibration is done + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + + pinMode(piezoPin, OUTPUT); +} + +void loop() { + // start the IMU read + imu.run(); + + // read raw accel measurements from the IMU device + int ax = imu.getAccelerometerX(); + int ay = imu.getAccelerometerY(); + + // map the raw value to be on a smaller scale + ax = map(ax, -36044 , 36043 , -360, 360); + ay = map(ay, -36044 , 36043 , -360, 360); + + + // print the measurements + Serial.print(ax); + Serial.print("\t"); + Serial.println(ay); + + + + //Computes the absolute value of the IMU read + ax = abs(ax); + ay = abs(ay); + + + + // add together the 2 values and use them for setting the frequency for the speaker to play + int frequency = ax + ay; + frequency = frequency / 2; + frequency = map(frequency, 0, 360, 0, 1000); + + // only play a sound if the frequency is not too low or the IMU is still + if (frequency > 50) { + tone(piezoPin, frequency); + } else { + noTone(piezoPin);// stop the sound + } + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.3_pitchroll_demo/_5.3_pitchroll_demo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.3_pitchroll_demo/_5.3_pitchroll_demo.ino new file mode 100644 index 00000000..7db7dfc2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.3_pitchroll_demo/_5.3_pitchroll_demo.ino @@ -0,0 +1,82 @@ +/* +* _5.3_pitchroll_demo +* +* The Piezo will now play sound based on how you angle the board in the two axes +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + + +IMU imu; // the IMU + +const int piezoPin = 8; //piezo + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + + +void setup() { + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on led to show that the board has executed + + + Serial.begin(9600); // initialize Serial communication + while (!Serial); // wait for the serial port to open + + + imu.begin(); + + + + + // blink the LED again to show that the calibration is done + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + + pinMode(piezoPin, OUTPUT); +} + +void loop() { + // start the IMU read + imu.run(); + + // get the pitch and roll result from the filter + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + // print the measurements + Serial.print(pitch); + Serial.print("\t"); + Serial.println(roll); + + + + //Computes the absolute value of the IMU read + pitch = abs(pitch); + roll = abs(roll); + + + + // add together the 2 values and use them for setting the frequency for the speaker to play + int frequency = pitch + roll; + frequency = frequency / 2; + frequency = map(frequency, 0, 360, 0, 1000); + + // only play a sound if the frequency is not too low or the IMU is still + if (frequency > 50) { + tone(piezoPin, frequency); + } else { + noTone(piezoPin);// stop the sound + } + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.4_ble_demo/_5.4_ble_demo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.4_ble_demo/_5.4_ble_demo.ino new file mode 100644 index 00000000..59757514 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.4_ble_demo/_5.4_ble_demo.ino @@ -0,0 +1,44 @@ + +/* +* _5.4_ble_demo +* +* The board will now store a message that is sent to it and send it back to anyone connecting to it +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +BLEuart ble=BLEuart(TYPE_MESSENGER); + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + ble.setName("Message"); + ble.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + if(ble.searchCentral()){ + Serial.println("Connected to central "); + while(ble.connected()){ + + //When receiving data from mobile app, write it + //back to the sender + if(ble.dataReceived()){ + ble.fetchData(); + Serial.println(ble.receivedString()); + char data[20]; + int length=ble.getReceivedLength(); + for(int i=0;i + +BLEuart ble=BLEuart(); + +Button button(9); + +int count; + +void setup() { + Serial.begin(9600); + + // Curie BLE setup + // set advertised local name + ble.setName("valDisp"); + ble.begin(); + + button.begin(); + + count=0; +} + +void loop() { + // if a central is connected to peripheral: + if(ble.searchCentral()){ + Serial.println("Connected to central "); + // while the central is still connected to peripheral: + while(ble.connected()){ + //Get readings from sensors + int buttonValue=button.getState(); + int lightValue=analogRead(A1); + + //Value Display can only pass numbers smaller than 255 + lightValue=map(lightValue,0,1023,0,255); + + //Check if the button is being pressed, and update the + //counter accordingly + if(button.isPressed()){ + count++; + } + + + //Note the sequence of data being sent, the phone app displays + //the values in the same sequence. + ble.addValue(buttonValue); + ble.addValue(count); + ble.addValue(lightValue); + ble.send(); + + } + // when the central disconnects, print it out: + Serial.println(F("Disconnected from central ")); + + } + +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.6_ble_CustomControl/_5.6_ble_CustomControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.6_ble_CustomControl/_5.6_ble_CustomControl.ino new file mode 100644 index 00000000..0ee78579 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Concepts/_5.6_ble_CustomControl/_5.6_ble_CustomControl.ino @@ -0,0 +1,44 @@ +/* +* _5.5_ble_valueDisplay +* +* This example shows how to receive data in the Arduino 101. When you tap the buttons in the CTC app Custom +* Control interface, the values associated with the buttons will be received by 101 in the form of a +* one char sized array. The value is displayed to Serial Monitor afterwards. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +BLEuart ble=BLEuart(); + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + + // Curie BLE setup + // set advertised local name + ble.setName("CustomC"); + ble.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + if(ble.searchCentral()){ + Serial.println("Connected to central "); + while(ble.connected()){ + + //If data is sent through BLE to 101 board + if(ble.dataReceived()){ + //Fetch all data from BLE + ble.fetchData(); + + //Read the 1 byte data received + unsigned char data=ble.getValueAt(0); + Serial.println(data); + } + } + Serial.println(F("Disconnected from central ")); + + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/AsteroidAttack/AsteroidAttack.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/AsteroidAttack/AsteroidAttack.ino new file mode 100644 index 00000000..1bf10bf9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/AsteroidAttack/AsteroidAttack.ino @@ -0,0 +1,71 @@ +/* +* AsteroidAttack +* +* You will create a retro style space +* shooter game, and learn about how to use classes and functions. In the end you will be able to +* tweak values and rewrite the program to redesign the game so it suits your taste. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + +IMU imu; // the IMU + +Button button(6); +int buttonState = 0; + + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + +void setup() { + Serial.begin(9600); // initialize Serial communication + + imu.begin(); + button.begin(); + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on led to show that the board has executed +} + +void loop() { + + // read raw gyro measurements from device + imu.run(); + + + // get the gyro result from the filter and convert them into INT + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + //Check buttons + if(button.isPressed()){ + buttonState=true; + } + + // when Serial is open, send a "s" to processing + if (Serial.available() > 0) { + int val = Serial.read(); + if (val == 's') { // if incoming serial is "s" + Serial.print(roll); Serial.print(","); + + + Serial.print(buttonState); Serial.print(","); + Serial.println(""); + + buttonState=0; + + } + } + + + + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/NovaBeam/NovaBeam.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/NovaBeam/NovaBeam.ino new file mode 100644 index 00000000..c6d8472d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/NovaBeam/NovaBeam.ino @@ -0,0 +1,122 @@ +/* +* NovaBeam +* +* Ever wondered what it might be like to swing a laser beam? Then this project is for you! See +* yourself play with the Nova Beam on screen, and listen to the awesome sounds it makes. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +IMU imu; // the IMU +Button toggleButton(10); + +int piezoPin = 8; //piezo + +bool toggleState = false; + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + +//smoothing function +const int numReadings = 50; +int readings[numReadings]; // the readings from the analog input +int readIndex = 0; // the index of the current reading + +//int total2,average2; + +void setup() { + Serial.begin(9600); // initialize Serial communication + + imu.begin(); + toggleButton.begin(); + + //smoothing function + // initialize all the readings to 0: + for (int i = 0; i < numReadings; i++) { + readings[i] = 0; + } + + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed + +} + +void loop() { + // start the IMU read + imu.run(); + + // read raw accel measurements from the IMU device + int ay = imu.getAccelerometerY(); + + // map the raw value to be on a smaller scale + ay = map(ay, -36044 , 36043 , -360, 360); + + // read from the sensor: + readings[readIndex] = ay; + // advance to the next position in the array: + readIndex = readIndex + 1; + // if we're at the end of the array... + if (readIndex >= numReadings) { + // ...wrap around to the beginning: + readIndex = 0; + } + + // get the total of last 10 readings + int total=0; + for(int i=0;i 0) { + int val = Serial.read(); + if (val == 's') { // if incoming serial is "s" + + // print the roll,pitch and toggleState to the Procssing + Serial.print(average); + Serial.print(","); + Serial.print(pitch); + Serial.print(","); + Serial.print(toggleState); + Serial.print(","); + Serial.println(""); + + } + } + + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + delay(30); + +} + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/PlanetFinder/PlanetFinder.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/PlanetFinder/PlanetFinder.ino new file mode 100644 index 00000000..09309008 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/PlanetFinder/PlanetFinder.ino @@ -0,0 +1,150 @@ +/* +* PlanetFinder +* +* The universe is big, really big, so if you are ever going to be able to find any planets then you'll +* need a tool track them down for you. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + + +IMU imu; // the IMU + +bool blinkState = false; // state of the LED +const int ledPin = 13; // activity LED pin +const int piezoPin = 8; //piezo +const int redPin = 6; // the red LED +int piezoState = LOW; // piezoState used to set the piezo + +bool newGame = true; +int x = 0; +int y = 0; +const int errorMargin=10; + +unsigned long previousMillis = 0; // last time the click played, in ms + + +// notes in the melody: +int melody[] = { + 196, 196, 262 +}; + +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations[] = { + 8, 8, 4 +}; + + +void setup() { + Serial.begin(9600); // initialize Serial communication + + + imu.begin(); + + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on LED to show that the board has executed + + pinMode(piezoPin, OUTPUT); // sets piezo + pinMode(redPin, OUTPUT); // sets red LED + randomSeed(analogRead(0)); // initializes the pseudo-random number generator + +} + +void loop() { + + // start the IMU read + imu.run(); + + // get the pitch and roll result from the filter + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + + // new round the game + if (newGame) { + + //pick goal + x = random(-180, 180); + y = random(-90, 90); + newGame = false; + } + + + // print the roll/pitch and the target roll/pitch needed for debugging only + Serial.print("roll:"); + Serial.print(roll); + Serial.print("\t"); + Serial.print("pitch:"); + Serial.print(pitch); + Serial.print("\t"); + + Serial.print("Target roll:"); + Serial.print(x); + Serial.print("\t"); + Serial.print("Target pitch:"); + Serial.println(y); + + + // calculate how close the gyro is to the goal values + + //Computes the value of the IMU reads and the goal target + int absoluteRollDiff = abs(roll - x); + int absolutePitchDiff = abs(pitch - y); + int closeTogoal = absoluteRollDiff + absolutePitchDiff; + + + + // click in shorter intervals the closer the gyro read is to the goal + unsigned long currentMillis = millis(); + if (currentMillis - previousMillis >= closeTogoal ) { + // save the last time you clicked the piezo + previousMillis = currentMillis; + + // if the piezo is off turn it on and vice-versa: + if (piezoState == LOW) { + piezoState = HIGH; + } else { + piezoState = LOW; + } + + digitalWrite(piezoPin, piezoState); + digitalWrite(redPin, piezoState); + } + + // if the gyro value is at the goal + if (closeTogoal <= errorMargin) { + + Serial.print("Win"); + + + // play the win tune + for (int thisNote = 0; thisNote < 3; thisNote++) { + + // to calculate the note duration, take one second + // divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 1000 / noteDurations[thisNote]; + tone(piezoPin, melody[thisNote], noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.30; + delay(pauseBetweenNotes); + // stop the tone playing: + noTone(piezoPin); + + } + // a new goal and new game round is needed + newGame = true; + } + + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ShipNavigator/ShipNavigator.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ShipNavigator/ShipNavigator.ino new file mode 100644 index 00000000..85a78603 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ShipNavigator/ShipNavigator.ino @@ -0,0 +1,170 @@ +/* +* ShipNavigator +* +* To find your way around space safely, your ship will need a navigator. Follow your ship’s AI +* instructions to navigate your ship without crashing it into anything. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Player player = Player(); // for playing sounds +IMU imu; // the IMU + + +const int ledPin = 13; // activity LED pin +boolean blinkState = false; // state of the LED + +bool up, down, left, right; //used for checking if the board has been moved in any direction +int moveTask = 1; //used for picking what direction should be done +bool newMove = false; // used for checking if a newMove is needed + +long lastTimer; //used for saving millis() + +void setup() { + + // configure Arduino LED for activity indicator + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); // turn on led to show that the board has executed + + + Serial.begin(9600); // initialize Serial communication + + + imu.begin(); + + + //Initialize the sound player + player.begin(); + + randomSeed(analogRead(0));// initializes the pseudo-random number generator + + +} + +void loop() { + // read raw rollro measurements from device + imu.run(); + // get the pitch and roll result from the filter + int pitch = imu.getPitch(); + int roll = imu.getRoll(); + + Serial.print("roll:"); + Serial.print(pitch); + Serial.print("\t"); + Serial.print("pitch:"); + Serial.println(roll); + + // short pause before the next round start + if (!newMove) { + Serial.println("New round"); + + delay(1000); + + } + + + + + // check if the board has been tilted in any direction and set the direction bools accordingly + if (pitch < -45) { + up = true; + down = false; + left = false; + right = false; + } else if (pitch > 45) { + up = false; + down = true; + left = false; + right = false; + } else if (roll < -45) { + up = false; + down = false; + left = true; + right = false; + } else if (roll > 45) { + up = false; + down = false; + left = false; + right = true; + } else { + up = false; + down = false; + left = false; + right = false; + } + + + // if a new move is needed, generate random direction and play the sound for that direction + if (!newMove) { + // picks a random number from 1 to 4 + moveTask = random(1, 5); + + //Playsound + if (moveTask == 1) { + Serial.println("move up"); + player.play("up.wav"); + + } else if (moveTask == 2) { + Serial.println("move down"); + player.play("down.wav"); + + } else if (moveTask == 3) { + Serial.println("move left"); + player.play("left.wav"); + + } else if (moveTask == 4) { + Serial.println("move right"); + player.play("right.wav"); + + } + + newMove = true; // a new move is created + lastTimer = millis(); // reset the 3 sec timer + + } + + // check if the random direction and the direction the board moved in is the same + if (up && moveTask == 1) { + Serial.println("up"); + newMove = false; + } + if (down && moveTask == 2) { + Serial.println("down"); + newMove = false; + } + if (left && moveTask == 3) { + Serial.println("left"); + newMove = false; + } + if (right && moveTask == 4) { + Serial.println("right"); + newMove = false; + } + + + // if the right move is not done before the 3 sec timer, reset the newMove bool and the timer to start a new round + if (millis() - lastTimer >= 3000) { + + if (newMove) { + Serial.println("To slow"); + //Play the sound for being too slow + player.play("slow.wav"); + newMove = false; + } + + lastTimer = millis(); + + } + + + + + + // blink LED to indicate activity + blinkState = !blinkState; + digitalWrite(ledPin, blinkState); + + delay(250); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/SpaceRover/SpaceRover.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/SpaceRover/SpaceRover.ino new file mode 100644 index 00000000..bb732fdd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/SpaceRover/SpaceRover.ino @@ -0,0 +1,75 @@ +/* +* SpaceRover +* +* Getting around on alien planets can be difficult. +* You are going to need a rover to investigate these new alien worlds. +* Now you will be able to control the rover to explore alien planets. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +BLEuart ble = BLEuart(TYPE_LOGOROBOT); + +Wheels wheels = Wheels(6, 9); + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + ble.setName("Rover"); + ble.begin(); + + wheels.begin(); +} + +void loop() { + // put your main code here, to run repeatedly: + if (ble.searchCentral()) { + Serial.println("Connected to central "); + while (ble.connected()) { + if (ble.dataReceived()) { + ble.fetchData(); + + Serial.print("Received number of commands: "); + Serial.println(ble.getReceivedLength()); + + for (int i = 0; i < ble.getReceivedLength(); i++) { + unsigned char n = ble.receivedString()[i]; + + Serial.print(n); + + logoMove(n); + } + Serial.println(); + } + } + Serial.println(F("Disconnected from central ")); + + } +} + +void logoMove(unsigned char direction) { + switch (direction) { + case 1: //forward + wheels.goForward(); + delay(750); + break; + case 2: //backwards + wheels.goBackwards(); + delay(750); + break; + case 3: //left + wheels.turnLeft(); + delay(250); + break; + case 4: //right + wheels.turnRight(); + delay(250); + break; + } + wheels.standStill(); + delay(300); +} + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ZazzTheAlien/ZazzTheAlien.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ZazzTheAlien/ZazzTheAlien.ino new file mode 100644 index 00000000..da0d69b8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Block5-Space(101-only)/Projects/ZazzTheAlien/ZazzTheAlien.ino @@ -0,0 +1,105 @@ +/* +* ZazzTheAlien +* +* It is a lot of responsibility, but now you will have to take care of the alien baby. This particular +* alien baby communicates with Bluetooth. You need to make sure it has proper exercises, gets +* enough food and sleep. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +BLEuart ble=BLEuart(TYPE_TAMAGOTCHI); +IMU imu; + +//const int lightPin = A0; //phototransistor +LightSensor sleepSensor(A1); + +Button foodButton(9); + +int exerciseLv, foodLv, sleepLv; // the saved stats that will go down over time + +long sleepTimer; +long updateTimer; + +void setup() { + Serial.begin(9600); + + // Curie IMU setup + imu.begin(); + imu.detectShock(); + imu.attachCallback(shockCallback); + + // set advertised local name + ble.setName("Zazz"); + ble.begin(); + + foodButton.begin(); + + sleepSensor.config(1000,200); + + //Set initial values for the three states + exerciseLv = 100; + foodLv = 100; + sleepLv = 100; + + updateTimer = millis(); + sleepTimer = millis(); +} + +void loop() { + + updateStatus(); // used to update the stats values + + // if a central is connected to peripheral: + if(ble.searchCentral()){ + Serial.println("Connected to central "); + // while the central is still connected to peripheral: + while(ble.connected()){ + updateStatus();// used to update the stats values + Serial.println("Sending data"); + ble.addValue(exerciseLv); + ble.addValue(foodLv); + ble.addValue(sleepLv); + ble.send(); + } + // when the central disconnects, print it out: + Serial.println(F("Disconnected from central ")); + + } + +} + +void updateStatus() { + // if the light level is low, add 1 to the sleepLv + if(sleepSensor.getState() && millis()-sleepTimer>200){ + sleepLv++; + sleepTimer=millis(); + } + + //Fill the food stat when the button is being pressed + if(foodButton.isPressed()){ + foodLv+=5; + } + + // every 3 sec update and lower the 3 stats in different rates + if (millis() - updateTimer >= 3000) { + exerciseLv = exerciseLv - 1; + foodLv = foodLv - 2; + sleepLv = sleepLv - 3; + + updateTimer = millis(); + } + + //Constrain the values so they don't exceed 100 or go below 0 + exerciseLv=constrain(exerciseLv,0,100); + foodLv=constrain(foodLv,0,100); + sleepLv=constrain(sleepLv,0,100); +} + +// this is called when the IMU detects a shock in any direction +static void shockCallback(void) { + //add 1 to the exerciseLv + exerciseLv++; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Button/Button.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Button/Button.ino new file mode 100644 index 00000000..b50f297b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Button/Button.ino @@ -0,0 +1,60 @@ +/* +* Button +* A button is a digital input. This means that it can have two +* states, either HIGH (5 V in Uno, 3 V in 101) or LOW (0 V). When +* you connect a button to your control board you can read these +* states as 1 or 0. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the button component. +//6 is the pin number. If it's a button module, use 6 or 9. +//HIGH can be ignored mostly, which means when the button is +//pressed, what state it is in. +Button me=Button(6,HIGH); + +void setup(){ + Serial.begin(9600); + + while(!Serial); + + //Initialize the component. Must be called. + me.begin(); +} +void loop(){ + Serial.println("Please press..."); + //pressed(timeout) + // timeout: milliseconds within which the button should + // be pressed. If pressed within time, the function + // returns 1, otherwise 0. If not used, it waits + // until being pressed. + // + //Wait until the button is pressed. + Serial.println(me.pressed()); + + + Serial.println("Please release..."); + //released(timeout) + // timeout: same as in pressed(timeout). + // + //Wait until the button is released. + Serial.println(me.released()); + + Serial.println("Press a few times..."); + //beenPressed() + // + //Check if the button has been pressed without blocking the + //sketch execution. Useful when press detection is not part + //of the main program logic. + long timer=millis(); + int counter=0; + while(millis()-timer<3000){ + if(me.isPressed()){ + counter++; + } + } + Serial.println(counter); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/ButtonGroup/ButtonGroup.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/ButtonGroup/ButtonGroup.ino new file mode 100644 index 00000000..0d3418fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/ButtonGroup/ButtonGroup.ino @@ -0,0 +1,38 @@ +/* +* ButtonGroup +* ButtonGroup is used for making a few buttons work together. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declaring the button group +ButtonGroup bg; + +//Declaring the pins to which the buttons are connected +int buttons[]={4,5,6}; + +void setup(){ + Serial.begin(9600); + + while(!Serial); + + //initialize the button group. The first parameter is + //number of buttons, the second is the array containing + //pins used by these buttons. + bg.begin(3,buttons); +} +void loop(){ + Serial.println("Please press a button"); + //pressed(timeout) + // timeout:milliseconds within which one button should + // be pressed. If pressed within time, the function + // returns number of the button within initial list. + // Otherwise -1. If not used, it waits until being + // pressed. + // + //Wait until one button is pressed. + Serial.println(bg.pressed()); + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitch/CapacitiveSwitch.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitch/CapacitiveSwitch.ino new file mode 100644 index 00000000..64caffd5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitch/CapacitiveSwitch.ino @@ -0,0 +1,63 @@ +/* CapacitiveSwitch +* +* CapacitiveSwitch can be constructed in various ways. +* Typically a 1 million ohm resistor between sender pin +* and receiver pin(we use 2 as sender, 3 as receiver +* here), and conductive material connected to the receive +* pin. +* +* When you touch the conductive material with your hand, or +* other objects (should be conductive), the sensor will +* get a different reading. +* +* The library includes some features for using the +* capacitive sensor as a button, or getting values directly. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The sensor is connected between 2 and 3 by default +CapacitiveSwitch me=CapacitiveSwitch(2,3); + +void setup(){ + Serial.begin(9600); + + while(!Serial); + + //Config the sensor, set threshold for the sensor used as + //button. If sensor reading passes it, it's counted as + //being pressed/released + me.config(400); +} +void loop(){ + Serial.println("Please press..."); + //pressed(timeout) + // timeout: milliseconds within which the sensor should + // be pressed. If pressed within time, the function + // returns 1, otherwise 0. If not used, it waits + // until being pressed. + // + //Wait until the capacitive sensor is pressed. + Serial.println(me.pressed()); + + delay(1000); + + Serial.println("Please release..."); + //released(timeout) + // timeout: same as in pressed(timeout). + // + //Wait until the capacitive sensor is released. + Serial.println(me.released()); + + do{ + //getValue(minimum) + // minimum: minimum value that needs to be returned. If + // the sensor reading is smaller than minimum, it'll + // return 0. + // + //Print values bigger than 20. Print 0 otherwise. + Serial.println(me.getValue(20)); + }while(true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitchTest/CapacitiveSwitchTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitchTest/CapacitiveSwitchTest.ino new file mode 100644 index 00000000..7ae3756a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/CapacitiveSwitchTest/CapacitiveSwitchTest.ino @@ -0,0 +1,30 @@ +/* CapacitiveSwitch Test +* +* When making use of sensor readings from CapacitiveSwitch, +* This sketch helps you decide the threshold by showing +* capacitive values of different materials. +* +* Just touch the objects you're going to experiment with, +* take note of the biggest and smallest values. In your +* project code, use these values to map to your desired +* outcome. +* +* It can also be used for adjusting the threshold when using +* capacitive sensor as a button. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The sensor is connected between 2 and 3 by default +CapacitiveSwitch me=CapacitiveSwitch(2,3); + +void setup(){ + Serial.begin(9600); +} +void loop(){ + //Print out the value of the sensor + me.test(); + delay(30); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/ContinuousServo/ContinuousServo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/ContinuousServo/ContinuousServo.ino new file mode 100644 index 00000000..3a130113 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/ContinuousServo/ContinuousServo.ino @@ -0,0 +1,36 @@ +/* ContinuousServo +* +* Continuous servo looks the same as a standard servo, but it's +* capable of rotating continuously like a normal motor. You can not +* control which angle it's pointing to, but you can specify how +* fast it spins, and which direction it spins. +* +* To control two servos as wheels on a vehicle please see the +* example Wheels in the Help folder. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo me; + +void setup(){ + //Servo is initialized, + //in this example connected to digital pin 9 + me.attach(9); +} + +void loop(){ + //write(speed): + // speed: the speed in which you want to rotate + // the servo. It is ranged between 0 and 180. + // 180 is fastest speed in one direction and 0 + // fastest speed in the opposite direction. + // 90 should make it stand still. This exact + // value is slightly different for each servo. + // + //Make the servo rotate in speed 120. + me.write(120); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/IRArray/IRArray.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/IRArray/IRArray.ino new file mode 100644 index 00000000..9b448187 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/IRArray/IRArray.ino @@ -0,0 +1,35 @@ +/* +* IRArray +* This program will print each IR sensor reading to the +* Serial Monitor. +* +* When you hold the IRarray over a white surface all sensors +* should give you a value of 400. When held over a black surface +* it should go down to around 330. Make sure that you've +* connected all sensor pins right by alternate each sensor +* between black and white and see the that values of the +* corresponding IR sensor is changing. E.g. if you move IR1 from +* black to white but only the value of IR2 is changed you need +* to either change the analog pins in the code or change the +* connections to the analog pins on the control board. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//IRArray(IR1, IR2, IR3) +IRArray ir = IRArray(A1, A2, A3); + +void setup(){ + + //Use this line to set the threshold of the IR sensors. The default is 380. If you're using Arduino 101 board, use 530 instead. + //Use test() to check the values of each sensor in loop() + ir.setThreshold(530); + + Serial.begin(9600); +} + +void loop(){ + ir.test(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Joystick/Joystick.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Joystick/Joystick.ino new file mode 100644 index 00000000..4b597d9d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Joystick/Joystick.ino @@ -0,0 +1,25 @@ +/* Joystick +* The joystick is one component but uses two analog sensors and +* gives you two values. One x value and one y value. The value +* for each direction is zero if it’s in the middle, -1 on one side +* and 1 on the other side. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//The joystick uses two analog pins. One for X and one for Y. +Joystick me=Joystick(A1,A0); + +void setup(){ + //Start serial communication to be able to print values to the Serial Monitor + Serial.begin(9600); +} +void loop(){ + Serial.print("X: "); + Serial.print(me.getX()); //Get the X value and print it. + Serial.print(" Y: "); + Serial.println(me.getY()); //Get the Y value and print it. + delay(200); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Knob/Knob.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Knob/Knob.ino new file mode 100644 index 00000000..5b97e197 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Knob/Knob.ino @@ -0,0 +1,47 @@ +/* +* Knob +* +* The Knob class is used for working with potentiometers. It provides +* functionalities to divide the raw value into a set amount of levels, +* which is helpful when a set of options are picked by the level of +* the knob. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Knob pot=Knob(A5);//a knob is connected to A5 + +void setup(){ + Serial.begin(9600); + + //setLevels(levels) + // levels: the amount of levels needed. So the possible output of the + // knob will be between 0 and levels + // + //Initializing the knob with total number of levels + pot.setLevels(10); + +} + +void loop(){ + //getValue() + // + //Return the current reading of the knob. Same as analogRead() + int a = pot.getValue(); + + //getLevel() + // + //Return the current level. It ranges between 0 and the max levels, as + //pre-configured by Knob.setLevels(). + int b = pot.getLevel(); + + Serial.print("Analog: "); + Serial.print(a); + Serial.print(" Level: "); + Serial.println(b); + + delay(100); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/LightSensor/LightSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/LightSensor/LightSensor.ino new file mode 100644 index 00000000..f930e576 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/LightSensor/LightSensor.ino @@ -0,0 +1,69 @@ +/* +* LightSensor +* +* LightSensor is a sensor that reads the intensity of light. +* It gives analog reading. When connected with analog +* pins, its value ranges from 0 to 1023 depending on the amount +* of light shining on it. +* +* The EducationShield library includes some features for +* using the LightSensor as a button, or get values directly. See +* the example LightSensorTest for more information about how to +* configure it correctly. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Phototransistor component is connected to analog 1. +LightSensor sensor = LightSensor(A1); + +void setup(){ + + Serial.begin(9600); + + //LDR needs to be configured with baseValue + //and threshold. See LightSensorTest sketch for + //details. + sensor.config(700,900); +} + +void loop(){ + Serial.println("Please press..."); + + //pressed(timeout) + // timeout: milliseconds within which the + // phototransistor should be cover-uncovered. If + // cover-uncovered within time, the + // function returns 1, otherwise 0. If + // not used, it waits until being + // cover-uncovered. + // + //Wait until the phototransistor gets cover-uncovered. + Serial.println(sensor.pressed()); + + Serial.println("Please release..."); + + //released(timeout) + // timeout: same as in pressed(timeout). + // + //Wait until the phototransistor gets uncover-covered. + Serial.println(sensor.released()); + + + while(true){ + //getState() + // returns whether the sensor readings has + // passed the threshold. Returns true if the + // threshold has been passed, false if not. + // Unlike pressed or released, this function + // does not stop the whole program. + // + //Continuously output whether the sensor has + //passed threshold. + Serial.println(sensor.getState()); + delay(30); + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/LightSensorTest/LightSensorTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/LightSensorTest/LightSensorTest.ino new file mode 100644 index 00000000..023ba0f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/LightSensorTest/LightSensorTest.ino @@ -0,0 +1,40 @@ +/* LightSensor test +* This sketch should be used prior to using the component in +* Projects. Projects suitable for this library should have 2 +* states: uncovered and covered. That is to say, you want to +* track objects covering/moving past the sensor. +* +* HOW-TO: +* Upload this sketch to the control board, open the Serial Monitor. You +* will see the current value of the phototransistor. +* +* Make sure the sensor is in its desired setting and not +* moving. When the value gets stable, take note of it (we call +* it "baseValue"). +* +* Now cover the sensor with desired object. When the value +* gets stable, take note of it (topValue). Remember these values +* and use them when configuring. +* +* "baseValue" and "threshold" will be used for defining the +* LightSensor switch in your project. You can fine tune the +* threshold to make the sensor more/less sensitive. The closer +* to baseValue, the more sensitive it is. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Phototransistor module is connected to analog 1. +LightSensor sensor = LightSensor(A1); + +void setup(){ + Serial.begin(9600); +} + +void loop(){ + //test() prints data to Serial port. + sensor.test(); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Melody/Melody.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Melody/Melody.ino new file mode 100644 index 00000000..e749985c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Melody/Melody.ino @@ -0,0 +1,69 @@ +/* Melody +* +* For playing sound with a piezo. +* +* Connect one pin of the piezo to a digital pin +* (8 in this example) and the other pin to ground. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//pitches.h includes the definition of notes. Put it in your sketch +//folder if you want to play music. +#include "pitches.h" + +//Declaring the component. 8 is the pin the piezo is connected to. +Melody me=Melody(8); + +void setup(){ +} + +void loop(){ + //Defining the notes used in the music. No more than 30. + int notes[] = { + NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; + + //Duration of each note. should be corresponding to the notes above. + int noteDurations[] = { + 4, 8, 8, 4,4,4,4,4 }; + + //play(length, notes, duration, speed) + // length: number of notes in your music. + // notes: the array of notes. + // noteDuration: the array of note duration + // speed: how fast the music plays. No less than 1.0, the bigger the slower + // + //Play the notes defined above + me.play(8,notes,noteDurations,1.4); + + delay(3000); + + //beep(length) + // length: how long the beep goes. Default to 30. + // + //Make a beep sound + me.beep(); + + delay(1000); + //effect_win() + // + //Make a win sound effect + me.effect_win(); + + delay(1000); + //effect_gameover() + // + //Make a gameover sound effect + me.effect_gameover(); + + delay(1000); + //effect_score() + // + //Make a scoring sound effect + me.effect_score(); + + + delay(3000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Melody/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Melody/pitches.h new file mode 100644 index 00000000..55c7d54e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Melody/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + * Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/PiezoKnockSensor/PiezoKnockSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/PiezoKnockSensor/PiezoKnockSensor.ino new file mode 100644 index 00000000..b85f0f30 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/PiezoKnockSensor/PiezoKnockSensor.ino @@ -0,0 +1,43 @@ +/* +* Piezo Knock Sensor +* Piezo can play music, as well as be used as knock sensor. +* +* Connect the red pin of the piezo to a 1M ohm resistor, +* and the resistor to an analog pin (A5 in this example), +* the other pin to GND. Connect a 3.3 V Zener diode in +* parallel to the piezo and resistor circuit, with its +* anode to GND, cathode to A5. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Remember: Piezo as speaker is connected to digital pin +//while piezo as knock sensor is connected to analog pin. +PiezoKnockSensor sensor=PiezoKnockSensor(A0); + +void setup(){ + Serial.begin(9600); + + while(!Serial); + + //define the threshold and debounce time of the knock + //sensor. Threshold defines how hard you need to knock, + //debounce time prevents the sensor from returning several + //hits from one knock, but also limits how rapid you can knock. + sensor.config(120,80); + +} +void loop(){ + Serial.println("Please knock..."); + + //knocked(timeout) + // timeout: milliseconds within which the sensor should + // be knocked. If knocked within time, the function + // returns 1, otherwise 0. If not used, it waits + // until being knocked. + // + //Wait until the button is knocked. + Serial.println(sensor.knocked()); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Player/Player.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Player/Player.ino new file mode 100644 index 00000000..e76802a4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Player/Player.ino @@ -0,0 +1,29 @@ +/* Player +* You can play a sound from an SD card using the Player class. +* The sound file need to be 8bit, uncompressed WAV. Follow this +* tutorial to record and prepare your sound correctly: +* http://web.archive.org/web/20150731231913/http://cuartielles.com/verkstad/en/Reference/PrepareWavSound +* +* Or use one of the .wav files in the BoomBox example. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Player player=Player(); + +void setup(){ + //Initialize the sound player + player.begin(); +} + +void loop(){ + //play(filename) + // filename: filename of the sound stored in SD card + // must be a .wav file + // + //Play the file named "0.wav" on SD card + player.play("0.wav"); + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Serialportsend/Serialportsend.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Serialportsend/Serialportsend.ino new file mode 100644 index 00000000..28cd5e94 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Serialportsend/Serialportsend.ino @@ -0,0 +1,19 @@ +/* Serialportsend +* +* connect a potentiometer to your board and you will check its value by using Processing +* +* (c) 2013-2016 Arduino LLC. +*/ + +void setup() { + +Serial.begin(9600); + +} + +void loop() { +// send to port + Serial.write(analogRead(A5)/4); + delay(1); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/StandardServo/StandardServo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/StandardServo/StandardServo.ino new file mode 100644 index 00000000..4049f7fb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/StandardServo/StandardServo.ino @@ -0,0 +1,32 @@ +/* +* StandardServo +* + * 180º standard servos are a type of motor which have a limited +* rotation angle. It has precise control over the angle of rotation. +* +* The ones provided for Education Shield projects are +* microservos. Microservos behave the same as a standard servo, +* but are slimmer in size and exert less turning power. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +Servo me; + +void setup(){ + //Servo is initialized, + //in this example connected to digital pin 9 + me.attach(9); +} + +void loop(){ + //write(angle): + // angle: the angle to which you want to rotate + // the servo. It is ranged between 0 and 180. + // + //Make the servo rotate to 76 degrees. + me.write(76); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/TiltSwitch/TiltSwitch.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/TiltSwitch/TiltSwitch.ino new file mode 100644 index 00000000..dbb581a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/TiltSwitch/TiltSwitch.ino @@ -0,0 +1,35 @@ +/* TiltSwitch +* +* Tilt Switch is a component that detects if it’s right side up +* or tilted. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the tilt switch. A tilt switch module can be +//connected to D6 or D9 (We use D9 here). +TiltSwitch me=TiltSwitch(9); + +void setup(){ + Serial.begin(9600); + + while(!Serial); + + //Initialize the component. Must be called. + me.begin(); +} +void loop(){ + Serial.println("Please tilt..."); + + //pressed(timeout) + // timeout: milliseconds within which the tilt switch should + // be tilted. If tilted within time, the function + // returns 1, otherwise 0. If not used, it waits + // until being pressed. + // + //Wait until the tilt switch is tilted. + Serial.println(me.pressed()); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/UltrasonicSensor/UltrasonicSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/UltrasonicSensor/UltrasonicSensor.ino new file mode 100644 index 00000000..7169cfc8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/UltrasonicSensor/UltrasonicSensor.ino @@ -0,0 +1,35 @@ +/* +* Ultrasonic Sensor +* An ultrasonic sensor is used to detect the distance to the +* closest object in front of the sensor. It uses ultrasound, +* sound with a frequency higher than humans can hear. As you +* probably know, sound can reflect from surfaces creating an +* echo. This echo is what the sensor uses to estimate the +* distance. The sensor sends out a burst of ultrasound and +* then waits for the echo. By knowing the speed of sound and +* the time between the burst and the detection we can +* calculate the distance. The shorter time it takes to detect +* the echo, the closer the object is. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the ultrasonic sensor with the trigger pin connected to +// digital pin 11, and the echo pin to digital pin 12. +UltrasonicSensor us = UltrasonicSensor(11, 12); + +void setup(){ + //Initialize the serial communication + Serial.begin(9600); +} + +void loop(){ + //Get the distance in cm + int distance = us.getDistance(); + + //Print out the distance to the Serial Monitor + Serial.println(distance); + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Wheels/Wheels.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Wheels/Wheels.ino new file mode 100644 index 00000000..ac74d4d1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/Wheels/Wheels.ino @@ -0,0 +1,45 @@ +/* +* Wheels +* +* If you ever want to use two continuous rotation servos as a pair +* of wheels we've made it easy for you. +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Wheels(left, right) +// Declares the wheels. +// left: the digital pin where you connect the left wheel +// right: the digital pin where you connect the right wheel +Wheels wheels=Wheels(6, 9); + +void setup(){ + //Initialize the servo wheels + wheels.begin(); +} + +void loop(){ + //Makes the wheel spin forward + wheels.goForward(); + delay(2000); + + //Makes the wheels spin backwards + wheels.goBackwards(); + delay(2000); + + //Makes the wheels spin in opposite direction so that + //the vehicle will spin left + wheels.turnLeft(); + delay(2000); + + //Makes the wheels spin in opposite direction so that + //the vehicle will spin right + wheels.turnRight(); + delay(2000); + + //Makes the wheels stop + wheels.standStill(); + delay(2000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/vuMeter/vuMeter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/vuMeter/vuMeter.ino new file mode 100644 index 00000000..670aa3b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/EducationShield/examples/Help/vuMeter/vuMeter.ino @@ -0,0 +1,110 @@ +/* +* VU-Meter +* VU-Meter is a few LEDs grouped together into a line. +* +* This library has some features that makes it easy to control +* several LEDs. Functions to use are: +* +* clear() - turns all LEDs off. +* on(LEDindex) - turns one LED on +* off(LEDindex) - turns one LED off +* scrollRight(speed, startIndex) - one LED lights up at a time from left to right +* scrollLeft(speed, startIndex) - one LED lights up at a time from right to left +* blink(LEDindex,speed, times) - one LED blinks +* blinkAll(speed, times) - all LEDs blink +* fillFrom(startIndex, stopIndex) - turns LEDs from startIndex to stopIndex on +* fill(numberOfLEDs) - turns LEDs on from first to numberOfLEDs +* +* (c) 2013-2016 Arduino LLC. +*/ + +#include + +//Declare the VUMeter +VUMeter me; + +//The pins used by the VUMeter, default to 2-5 and 7. Can be +//customized as you wish, but do change the pinCount if the +//number of LEDs are changed. +int pins[]={2,3,4,5,7}; + +//How many pins are used. Should reflect the pins array above. +int pinCount=5; + +void setup(){ + //Configure the VU meter using parameters defined previously. + me.config(pinCount,pins); + + //initialize the component. Must be called. + me.begin(); + +} +void loop(){ + //fill(number) + // number: how many LEDs from first pin shall be turned on + // + //Fill 5 LEDs + me.fill(5); + delay(3000); + + //clear() + // + //turn all the LEDs off + me.clear(); + delay(1000); + + //on(index) + // index: which LED being turned on + // + //Turn the 3rd LED on + me.on(2); + delay(1000); + + //off(index) + // index: which LED being turned off + // + //Turn the 3rd LED off + me.off(2); + delay(1000); + + //scrollRight(speed, startIndex) + // speed: milliseconds before the next LED turns on + // startIndex: from which LED to the left it starts + // scrolling. If not specified, it's 1. + // + //One LED lights up at a time, scrolling from left to right + me.scrollRight(700); + + //scrollLeft(speed, startIndex) + // speed: milliseconds before the next LED turns on + // startIndex: from which LED TO THE RIGHT it starts + // scrolling. If not specified, it's 1. + // + //And then scroll back from the 2nd on the right + me.scrollLeft(700,1); + + //blink(index, speed, times) + // index: which LED should blink + // speed: milliseconds, of which the LED lights on and off + // times: how many times the LED blinks. Defaults to 1 + // + //the 3rd LED will be blinking 10 times, each time + //with 100 milliseconds on and 100 milliseconds off + me.blink(2,100,10); + + //blinkAll(speed, times) + // speed: milliseconds, of which all LEDs light on and off + // times: how many times the LED blinks. Defaults to 1 + // + //All LEDs will be blinking 10 times + me.blinkAll(100,10); + + //fillFrom(leftIndex,rightIndex) + // leftIndex: start filling from which LED + // rightIndex: end filling to which LED + // + //The 2nd to 4th LED will light up + me.fillFrom(1,3); + delay(2000); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/AUTHORS b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/AUTHORS new file mode 100644 index 00000000..1faeec41 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/AUTHORS @@ -0,0 +1,36 @@ +Alberto Panu https://github.com/bigjohnson +Alasdair Allan https://github.com/aallan +Alice Pintus https://github.com/00alis +Adrian McEwen https://github.com/amcewen +Arduino LLC https://arduino.cc/ +Arnie97 https://github.com/Arnie97 +Arturo Guadalupi https://github.com/agdl +Bjoern Hartmann https://people.eecs.berkeley.edu/~bjoern/ +chaveiro https://github.com/chaveiro +Cristian Maglie https://github.com/cmaglie +David A. Mellis https://github.com/damellis +Dino Tinitigan https://github.com/bigdinotech +Eddy https://github.com/eddyst +Federico Vanzati https://github.com/Fede85 +Federico Fissore https://github.com/ffissore +Jack Christensen https://github.com/JChristensen +Johann Richard https://github.com/johannrichard +Jordan Terrell https://github.com/iSynaptic +Justin Paulin https://github.com/interwho +lathoub https://github.com/lathoub +Martino Facchin https://github.com/facchinm +Matthias Hertel https://github.com/mathertel +Matthijs Kooijman https://github.com/matthijskooijman +Matt Robinson https://github.com/ribbons +MCQN Ltd. http://mcqn.com/ +Michael Amie https://github.com/michaelamie +Michael Margolis https://github.com/michaelmargolis +Norbert Truchsess https://github.com/ntruchsess +Paul Stoffregen https://github.com/PaulStoffregen +per1234 https://github.com/per1234 +Richard Sim +Scott Fitzgerald https://github.com/shfitz +Thibaut Viard https://github.com/aethaniel +Tom Igoe https://github.com/tigoe +WIZnet http://www.wiznet.co.kr +Zach Eveland https://github.com/zeveland diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/README.adoc new file mode 100644 index 00000000..ed937b1b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/README.adoc @@ -0,0 +1,31 @@ +:repository-owner: arduino-libraries +:repository-name: Ethernet + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +With the Arduino Ethernet Shield, this library allows an Arduino board to connect to the internet. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2010 Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino new file mode 100644 index 00000000..c97a9589 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino @@ -0,0 +1,119 @@ +/* + Advanced Chat Server + + A more advanced server that distributes any incoming messages + to all connected clients but the client the message comes from. + To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino WIZnet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + redesigned to make use of operator== 25 Nov 2013 + by Norbert Truchsess + + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); + +EthernetClient clients[8]; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // initialize the Ethernet device + Ethernet.begin(mac, ip, myDns, gateway, subnet); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // check for any new client connecting, and say hello (before any incoming data) + EthernetClient newClient = server.accept(); + if (newClient) { + for (byte i=0; i < 8; i++) { + if (!clients[i]) { + Serial.print("We have a new client #"); + Serial.println(i); + newClient.print("Hello, client number: "); + newClient.println(i); + // Once we "accept", the client is no longer tracked by EthernetServer + // so we must store it into our list of clients + clients[i] = newClient; + break; + } + } + } + + // check for incoming data from all clients + for (byte i=0; i < 8; i++) { + if (clients[i] && clients[i].available() > 0) { + // read bytes from a client + byte buffer[80]; + int count = clients[i].read(buffer, 80); + // write the bytes to all other connected clients + for (byte j=0; j < 8; j++) { + if (j != i && clients[j].connected()) { + clients[j].write(buffer, count); + } + } + } + } + + // stop any clients which disconnect + for (byte i=0; i < 8; i++) { + if (clients[i] && !clients[i].connected()) { + Serial.print("disconnect client #"); + Serial.println(i); + clients[i].stop(); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino new file mode 100644 index 00000000..831f17fc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino @@ -0,0 +1,247 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Serves the output of a Barometric Pressure Sensor as a web page. + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + TODO: this hardware is long obsolete. This example program should + be rewritten to use https://www.sparkfun.com/products/9721 + + Circuit: + SCP1000 sensor attached to pins 6,7, and 11 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + by Tom Igoe + */ + +#include +// the sensor communicates using SPI, so include the library: +#include + + +// assign a MAC address for the Ethernet controller. +// fill in your address here: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +// assign an IP address for the controller: +IPAddress ip(192, 168, 1, 20); + + +// Initialize the Ethernet server library +// with the IP address and port you want to use +// (port 80 is default for HTTP): +EthernetServer server(80); + + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading + +// pins used for the connection with the sensor +// the others you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +float temperature = 0.0; +long pressure = 0; +long lastReadingTime = 0; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // start the SPI library: + SPI.begin(); + + // start the Ethernet connection + Ethernet.begin(mac, ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + // initialize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + + // give the sensor and Ethernet shield time to set up: + delay(1000); + + //Set the sensor to high resolution mode to start readings: + writeRegister(0x03, 0x0A); + +} + +void loop() { + // check for a reading no more than once a second. + if (millis() - lastReadingTime > 1000) { + // if there's a reading ready, read it: + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + getData(); + // timestamp the last time you got a reading: + lastReadingTime = millis(); + } + } + + // listen for incoming Ethernet connections: + listenForEthernetClients(); +} + + +void getData() { + Serial.println("Getting reading"); + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to Celsius and display it: + temperature = (float)tempData / 20.0; + + //Read the pressure data highest 3 bits: + byte pressureDataHigh = readRegister(0x1F, 1); + pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressureDataLow = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4; + + Serial.print("Temperature: "); + Serial.print(temperature); + Serial.println(" degrees C"); + Serial.print("Pressure: " + String(pressure)); + Serial.println(" Pa"); +} + +void listenForEthernetClients() { + // listen for incoming clients + EthernetClient client = server.available(); + if (client) { + Serial.println("Got a client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println(); + // print the current readings, in HTML format: + client.print("Temperature: "); + client.print(temperature); + client.print(" degrees C"); + client.println("
    "); + client.print("Pressure: " + String(pressure)); + client.print(" Pa"); + client.println("
    "); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + } +} + + +//Send a write command to SCP1000 +void writeRegister(byte registerName, byte registerValue) { + // SCP1000 expects the register name in the upper 6 bits + // of the byte: + registerName <<= 2; + // command (read or write) goes in the lower two bits: + registerName |= 0b00000010; //Write command + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(registerName); //Send register location + SPI.transfer(registerValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} + + +//Read register from the SCP1000: +unsigned int readRegister(byte registerName, int numBytes) { + byte inByte = 0; // incoming from the SPI read + unsigned int result = 0; // result to return + + // SCP1000 expects the register name in the upper 6 bits + // of the byte: + registerName <<= 2; + // command (read or write) goes in the lower two bits: + registerName &= 0b11111100; //Read command + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(registerName); + // send a value of 0 to read the first byte returned: + inByte = SPI.transfer(0x00); + + result = inByte; + // if there's more than one byte returned, + // shift the first byte then get the second byte: + if (numBytes > 1) { + result = inByte << 8; + inByte = SPI.transfer(0x00); + result = result | inByte; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/ChatServer/ChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/ChatServer/ChatServer.ino new file mode 100644 index 00000000..3e280607 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -0,0 +1,96 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino WIZnet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); +bool alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // initialize the Ethernet device + Ethernet.begin(mac, ip, myDns, gateway, subnet); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clear out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino new file mode 100644 index 00000000..612106f9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino @@ -0,0 +1,94 @@ +/* + DHCP-based IP printer + + This sketch uses the DHCP extensions to the Ethernet library + to get an IP address via DHCP and print the address obtained. + using an Arduino WIZnet Ethernet shield. + + Circuit: + Ethernet shield attached to pins 10, 11, 12, 13 + + created 12 April 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // no point in carrying on, so do nothing forevermore: + while (true) { + delay(1); + } + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); +} + +void loop() { + switch (Ethernet.maintain()) { + case 1: + //renewed fail + Serial.println("Error: renewed fail"); + break; + + case 2: + //renewed success + Serial.println("Renewed success"); + //print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + break; + + case 3: + //rebind fail + Serial.println("Error: rebind fail"); + break; + + case 4: + //rebind success + Serial.println("Rebind success"); + //print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + break; + + default: + //nothing happened + break; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino new file mode 100644 index 00000000..01cd8140 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -0,0 +1,101 @@ +/* + DHCP Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino WIZnet Ethernet shield. + + THis version attempts to get an IP address using DHCP + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 21 May 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + Based on ChatServer example by David A. Mellis + + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + +// telnet defaults to port 23 +EthernetServer server(23); +bool gotAMessage = false; // whether or not you got a message from the client yet + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Trying to get an IP address using DHCP"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // initialize the Ethernet device not using DHCP: + Ethernet.begin(mac, ip, myDns, gateway, subnet); + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + + // start listening for clients + server.begin(); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!gotAMessage) { + Serial.println("We have a new client"); + client.println("Hello, client!"); + gotAMessage = true; + } + + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.print(thisChar); + Ethernet.maintain(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/LinkStatus/LinkStatus.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/LinkStatus/LinkStatus.ino new file mode 100644 index 00000000..84651d09 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/LinkStatus/LinkStatus.ino @@ -0,0 +1,44 @@ +/* + Link Status + + This sketch prints the Ethernet link status. When the + Ethernet cable is connected the link status should go to "ON". + NOTE: Only WIZnet W5200 and W5500 are capable of reporting + the link status. W5100 will report "Unknown". + Hardware: + - Ethernet shield or equivalent board/shield with WIZnet W5200/W5500 + Written by Cristian Maglie + This example is public domain. +*/ + +#include +#include + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + Serial.begin(9600); +} + +void loop() { + auto link = Ethernet.linkStatus(); + Serial.print("Link status: "); + switch (link) { + case Unknown: + Serial.println("Unknown"); + break; + case LinkON: + Serial.println("ON"); + break; + case LinkOFF: + Serial.println("OFF"); + break; + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/PagerServer/PagerServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/PagerServer/PagerServer.ino new file mode 100644 index 00000000..e17ae6ed --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/PagerServer/PagerServer.ino @@ -0,0 +1,71 @@ +/* + Pager Server + + A simple server that echoes any incoming messages to all + connected clients. Connect two or more telnet sessions + to see how server.available() and server.print() works. + + created in September 2020 for the Ethernet library + by Juraj Andrassy https://github.com/jandrassy + +*/ +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 0, 177); + +EthernetServer server(2323); + +void setup() { + + Serial.begin(9600); + while (!Serial); + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to configure using IP address instead of DHCP: + Ethernet.begin(mac, ip); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + + server.begin(); + + IPAddress ip = Ethernet.localIP(); + Serial.println(); + Serial.print("To access the server, connect with Telnet client to "); + Serial.print(ip); + Serial.println(" 2323"); +} + +void loop() { + + EthernetClient client = server.available(); // returns first client which has data to read or a 'false' client + if (client) { // client is true only if it is connected and has data to read + String s = client.readStringUntil('\n'); // read the message incoming from one of the clients + s.trim(); // trim eventual \r + Serial.println(s); // print the message to Serial Monitor + client.print("echo: "); // this is only for the sending client + server.println(s); // send the message to all connected clients +#ifndef ARDUINO_ARCH_SAM + server.flush(); // flush the buffers +#endif /* !defined(ARDUINO_ARCH_SAM) */ + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/TelnetClient/TelnetClient.ino new file mode 100644 index 00000000..ff554a5c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -0,0 +1,109 @@ +/* + Telnet client + + This sketch connects to a telnet server (http://www.google.com) + using an Arduino WIZnet Ethernet shield. You'll need a telnet server + to test this with. + Processing's ChatServer example (part of the Network library) works well, + running on port 10002. It can be found as part of the examples + in the Processing application, available at + https://processing.org/ + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 14 Sep 2010 + modified 9 Apr 2012 + by Tom Igoe + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +// Enter the IP address of the server you're connecting to: +IPAddress server(1, 1, 1, 1); + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 23 is default for telnet; +// if you're using Processing's ChatServer, use port 10002): +EthernetClient client; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // start the Ethernet connection: + Ethernet.begin(mac, ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + while (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + delay(500); + } + + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, 10002)) { + Serial.println("connected"); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // as long as there are bytes in the serial queue, + // read them and send them out the socket if it's open: + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (client.connected()) { + client.print(inChar); + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + // do nothing: + while (true) { + delay(1); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino new file mode 100644 index 00000000..3995b331 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino @@ -0,0 +1,138 @@ +/* + UDPSendReceiveString + + This sketch receives UDP message strings, prints them to the serial port + and sends an "acknowledge" string back to the sender + + A Processing sketch is included at the end of file that can be used to send + and receive messages for testing with a computer. + + created 21 Aug 2010 + by Michael Margolis + + This code is in the public domain. + */ + + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +unsigned int localPort = 8888; // local port to listen on + +// buffers for receiving and sending data +char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet, +char ReplyBuffer[] = "acknowledged"; // a string to send back + +// An EthernetUDP instance to let us send and receive packets over UDP +EthernetUDP Udp; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // start the Ethernet + Ethernet.begin(mac, ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start UDP + Udp.begin(localPort); +} + +void loop() { + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remote = Udp.remoteIP(); + for (int i=0; i < 4; i++) { + Serial.print(remote[i], DEC); + if (i < 3) { + Serial.print("."); + } + } + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBuffer + Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } + delay(10); +} + + +/* + Processing sketch to run with this example + ===================================================== + + // Processing UDP example to send and receive string data from Arduino + // press any key to send the "Hello Arduino" message + + + import hypermedia.net.*; + + UDP udp; // define the UDP object + + + void setup() { + udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000 + //udp.log( true ); // <-- printout the connection activity + udp.listen( true ); // and wait for incoming message + } + + void draw() + { + } + + void keyPressed() { + String ip = "192.168.1.177"; // the remote IP address + int port = 8888; // the destination port + + udp.send("Hello World", ip, port ); // the message to send + + } + + void receive( byte[] data ) { // <-- default handler + //void receive( byte[] data, String ip, int port ) { // <-- extended handler + + for(int i=0; i < data.length; i++) + print(char(data[i])); + println(); + } + */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino new file mode 100644 index 00000000..1455b40d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -0,0 +1,145 @@ +/* + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see https://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + This code is in the public domain. + + */ + +#include +#include +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; + +unsigned int localPort = 8888; // local port to listen for UDP packets + +const char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +EthernetUDP Udp; + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start Ethernet and UDP + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // no point in carrying on, so do nothing forevermore: + while (true) { + delay(1); + } + } + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + // the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); + Ethernet.maintain(); +} + +// send an NTP request to the time server at the given address +void sendNTPpacket(const char * address) { + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); // NTP requests are to port 123 + Udp.write(packetBuffer, NTP_PACKET_SIZE); + Udp.endPacket(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebClient/WebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebClient/WebClient.ino new file mode 100644 index 00000000..f4a5d02a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebClient/WebClient.ino @@ -0,0 +1,136 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using an Arduino WIZnet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe, based on work by Adrian McEwen + + */ + +#include +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 0, 177); +IPAddress myDns(192, 168, 0, 1); + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +EthernetClient client; + +// Variables to measure the speed +unsigned long beginMicros, endMicros; +unsigned long byteCount = 0; +bool printWebData = true; // set to false for better speed measurement + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to configure using IP address instead of DHCP: + Ethernet.begin(mac, ip, myDns); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.print("connecting to "); + Serial.print(server); + Serial.println("..."); + + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.print("connected to "); + Serial.println(client.remoteIP()); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } + beginMicros = micros(); +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + int len = client.available(); + if (len > 0) { + byte buffer[80]; + if (len > 80) len = 80; + client.read(buffer, len); + if (printWebData) { + Serial.write(buffer, len); // show in the serial monitor (slows some boards) + } + byteCount = byteCount + len; + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + endMicros = micros(); + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + Serial.print("Received "); + Serial.print(byteCount); + Serial.print(" bytes in "); + float seconds = (float)(endMicros - beginMicros) / 1000000.0; + Serial.print(seconds, 4); + float rate = (float)byteCount / seconds / 1000.0; + Serial.print(", rate = "); + Serial.print(rate); + Serial.print(" kbytes/second"); + Serial.println(); + + // do nothing forevermore: + while (true) { + delay(1); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino new file mode 100644 index 00000000..1fb11e10 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino @@ -0,0 +1,126 @@ +/* + Repeating Web client + + This sketch connects to a web server and makes a request + using a WIZnet Ethernet shield. You can use the Arduino Ethernet Shield, or + the Adafruit Ethernet shield, either one will work, as long as it's got + a WIZnet Ethernet module on board. + + This example uses DNS, by assigning the Ethernet client with a MAC address, + IP address, and DNS address. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 19 Apr 2012 + by Tom Igoe + modified 21 Jan 2014 + by Federico Vanzati + + https://www.arduino.cc/en/Tutorial/WebClientRepeating + This code is in the public domain. + + */ + +#include +#include + +// assign a MAC address for the Ethernet controller. +// fill in your address here: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 0, 177); +IPAddress myDns(192, 168, 0, 1); + +// initialize the library instance: +EthernetClient client; + +char server[] = "www.arduino.cc"; // also change the Host line in httpRequest() +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // start serial port: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to configure using IP address instead of DHCP: + Ethernet.begin(mac, ip, myDns); + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + if (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } + +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the Ethernet shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET /latest.txt HTTP/1.1"); + client.println("Host: www.arduino.cc"); + client.println("User-Agent: arduino-ethernet"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebServer/WebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebServer/WebServer.ino new file mode 100644 index 00000000..f3929d2d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Ethernet/examples/WebServer/WebServer.ino @@ -0,0 +1,122 @@ +/* + Web Server + + A simple web server that shows the value of the analog input pins. + using an Arduino WIZnet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + * Analog inputs attached to pins A0 through A5 (optional) + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include + +// Enter a MAC address and IP address for your controller below. +// The IP address will be dependent on your local network: +byte mac[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED +}; +IPAddress ip(192, 168, 1, 177); + +// Initialize the Ethernet server library +// with the IP address and port you want to use +// (port 80 is default for HTTP): +EthernetServer server(80); + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH Shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit FeatherWing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit FeatherWing Ethernet + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.println("Ethernet WebServer Example"); + + // start the Ethernet connection and the server: + Ethernet.begin(mac, ip); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start the server + server.begin(); + Serial.print("server is at "); + Serial.println(Ethernet.localIP()); +} + + +void loop() { + // listen for incoming clients + EthernetClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
    "); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/LICENSE new file mode 100644 index 00000000..0a041280 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/README.adoc new file mode 100644 index 00000000..9b5f9baa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/README.adoc @@ -0,0 +1,31 @@ +:repository-owner: arduino-libraries +:repository-name: Keyboard + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino board with USB capabilities to act as a keyboard. + +For more information about this library please visit us at +https://www.arduino.cc/reference/en/language/functions/usb/keyboard/ + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/examples/Serial/Serial.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/examples/Serial/Serial.ino new file mode 100644 index 00000000..050bb18c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Keyboard/examples/Serial/Serial.ino @@ -0,0 +1,39 @@ +/* + Keyboard test + + For the Arduino Leonardo, Micro or Due + + Reads a byte from the serial port, sends a keystroke back. + The sent keystroke is one higher than what's received, e.g. if you send a, + you get b, send A you get B, and so forth. + + The circuit: + - none + + created 21 Oct 2011 + modified 27 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardSerial +*/ + +#include "Keyboard.h" + +void setup() { + // open the serial port: + Serial.begin(9600); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + // check for incoming serial data: + if (Serial.available() > 0) { + // read incoming serial data: + char inChar = Serial.read(); + // Type the next ASCII value from what you received: + Keyboard.write(inChar + 1); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/README.adoc new file mode 100644 index 00000000..a46cd034 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/README.adoc @@ -0,0 +1,33 @@ +:repository-owner: arduino-libraries +:repository-name: LiquidCrystal + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino board to control liquid crystal displays (LCDs) based on the Hitachi HD44780 (or a compatible) chipset, which is found on most text-based LCDs. + +For more information about this library please visit us at + +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. +Copyright (c) 2010 Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino new file mode 100644 index 00000000..e5f369b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Autoscroll/Autoscroll.ino @@ -0,0 +1,77 @@ +/* + LiquidCrystal Library - Autoscroll + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates the use of the autoscroll() + and noAutoscroll() functions to make new text scroll or not. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalAutoscroll + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); +} + +void loop() { + // set the cursor to (0,0): + lcd.setCursor(0, 0); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + + // set the cursor to (16,1): + lcd.setCursor(16, 1); + // set the display to automatically scroll: + lcd.autoscroll(); + // print from 0 to 9: + for (int thisChar = 0; thisChar < 10; thisChar++) { + lcd.print(thisChar); + delay(500); + } + // turn off automatic scrolling + lcd.noAutoscroll(); + + // clear screen for the next loop: + lcd.clear(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Blink/Blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Blink/Blink.ino new file mode 100644 index 00000000..fd79e5a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Blink/Blink.ino @@ -0,0 +1,63 @@ +/* + LiquidCrystal Library - Blink + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD and makes the + cursor block blink. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalBlink + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the blinking cursor: + lcd.noBlink(); + delay(3000); + // Turn on the blinking cursor: + lcd.blink(); + delay(3000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Cursor/Cursor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Cursor/Cursor.ino new file mode 100644 index 00000000..3132a19d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Cursor/Cursor.ino @@ -0,0 +1,64 @@ +/* + LiquidCrystal Library - Cursor + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD and + uses the cursor() and noCursor() methods to turn + on and off the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalCursor + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the cursor: + lcd.noCursor(); + delay(500); + // Turn on the cursor: + lcd.cursor(); + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino new file mode 100644 index 00000000..761a1f1b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/CustomCharacter/CustomCharacter.ino @@ -0,0 +1,148 @@ +/* + LiquidCrystal Library - Custom Characters + + Demonstrates how to add custom characters on an LCD display. + The LiquidCrystal library works with all LCD displays that are + compatible with the Hitachi HD44780 driver. There are many of + them out there, and you can usually tell them by the 16-pin interface. + + This sketch prints "I Arduino!" and a little dancing man + to the LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + * 10K potentiometer on pin A0 + + created 21 Mar 2011 + by Tom Igoe + modified 11 Nov 2013 + by Scott Fitzgerald + modified 7 Nov 2016 + by Arturo Guadalupi + modified 17 Mar 2020 + by Deepak Khatri + + Based on Adafruit's example at + https://github.com/adafruit/SPI_VFD/blob/master/examples/createChar/createChar.pde + + This example code is in the public domain. + + Also useful: + https://maxpromer.github.io/LCD-Character-Creator/ + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +// make some custom characters: +byte heart[8] = { + 0b00000, + 0b01010, + 0b11111, + 0b11111, + 0b11111, + 0b01110, + 0b00100, + 0b00000 +}; + +byte smiley[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b10001, + 0b01110, + 0b00000 +}; + +byte frownie[8] = { + 0b00000, + 0b00000, + 0b01010, + 0b00000, + 0b00000, + 0b00000, + 0b01110, + 0b10001 +}; + +byte armsDown[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b00100, + 0b01110, + 0b10101, + 0b00100, + 0b01010 +}; + +byte armsUp[8] = { + 0b00100, + 0b01010, + 0b00100, + 0b10101, + 0b01110, + 0b00100, + 0b00100, + 0b01010 +}; + +void setup() { + // initialize LCD and set up the number of columns and rows: + lcd.begin(16, 2); + + // create a new character + lcd.createChar(0, heart); + // create a new character + lcd.createChar(1, smiley); + // create a new character + lcd.createChar(2, frownie); + // create a new character + lcd.createChar(3, armsDown); + // create a new character + lcd.createChar(4, armsUp); + + // set the cursor to the top left + lcd.setCursor(0, 0); + + // Print a message to the LCD. + lcd.print("I "); + lcd.write(byte(0)); // when calling lcd.write() '0' must be cast as a byte + lcd.print(" Arduino! "); + lcd.write((byte)1); + +} + +void loop() { + // read the potentiometer on A0: + int sensorReading = analogRead(A0); + // map the result to 200 - 1000: + int delayTime = map(sensorReading, 0, 1023, 200, 1000); + // set the cursor to the bottom row, 5th position: + lcd.setCursor(4, 1); + // draw the little man, arms down: + lcd.write(3); + delay(delayTime); + lcd.setCursor(4, 1); + // draw him arms up: + lcd.write(4); + delay(delayTime); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Display/Display.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Display/Display.ino new file mode 100644 index 00000000..fe1a4527 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Display/Display.ino @@ -0,0 +1,64 @@ +/* + LiquidCrystal Library - display() and noDisplay() + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD and uses the + display() and noDisplay() functions to turn on and off + the display. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalDisplay + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // Turn off the display: + lcd.noDisplay(); + delay(500); + // Turn on the display: + lcd.display(); + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino new file mode 100644 index 00000000..4fdc5e58 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/HelloWorld/HelloWorld.ino @@ -0,0 +1,64 @@ +/* + LiquidCrystal Library - Hello World + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD + and shows the time. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * LCD VSS pin to ground + * LCD VCC pin to 5V + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/HelloWorld + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); +} + +void loop() { + // set the cursor to column 0, line 1 + // (note: line 1 is the second row, since counting begins with 0): + lcd.setCursor(0, 1); + // print the number of seconds since reset: + lcd.print(millis() / 1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Scroll/Scroll.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Scroll/Scroll.ino new file mode 100644 index 00000000..c72e54f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/Scroll/Scroll.ino @@ -0,0 +1,88 @@ +/* + LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints "hello, world!" to the LCD and uses the + scrollDisplayLeft() and scrollDisplayRight() methods to scroll + the text. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalScroll + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // Print a message to the LCD. + lcd.print("hello, world!"); + delay(1000); +} + +void loop() { + // scroll 13 positions (string length) to the left + // to move it offscreen left: + for (int positionCounter = 0; positionCounter < 13; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // scroll 29 positions (string length + display length) to the right + // to move it offscreen right: + for (int positionCounter = 0; positionCounter < 29; positionCounter++) { + // scroll one position right: + lcd.scrollDisplayRight(); + // wait a bit: + delay(150); + } + + // scroll 16 positions (display length + string length) to the left + // to move it back to center: + for (int positionCounter = 0; positionCounter < 16; positionCounter++) { + // scroll one position left: + lcd.scrollDisplayLeft(); + // wait a bit: + delay(150); + } + + // delay at the end of the full loop: + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino new file mode 100644 index 00000000..ae93e21f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/SerialDisplay/SerialDisplay.ino @@ -0,0 +1,69 @@ +/* + LiquidCrystal Library - Serial Input + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch displays text sent over the serial port + (e.g. from the Serial Monitor) on an attached LCD. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystalSerialDisplay + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // initialize the serial communications: + Serial.begin(9600); +} + +void loop() { + // when characters arrive over the serial port... + if (Serial.available()) { + // wait a bit for the entire message to arrive + delay(100); + // clear the screen + lcd.clear(); + // read all the available characters + while (Serial.available() > 0) { + // display each character to the LCD + lcd.write(Serial.read()); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino new file mode 100644 index 00000000..37be1d45 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/TextDirection/TextDirection.ino @@ -0,0 +1,82 @@ +/* + LiquidCrystal Library - TextDirection + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch demonstrates how to use leftToRight() and rightToLeft() + to move the cursor. + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + http://www.arduino.cc/en/Tutorial/LiquidCrystalTextDirection + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +int thisChar = 'a'; + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(16, 2); + // turn on the cursor: + lcd.cursor(); +} + +void loop() { + // reverse directions at 'm': + if (thisChar == 'm') { + // go right for the next letter + lcd.rightToLeft(); + } + // reverse again at 's': + if (thisChar == 's') { + // go left for the next letter + lcd.leftToRight(); + } + // reset at 'z': + if (thisChar > 'z') { + // go to (0,0): + lcd.home(); + // start again at 0 + thisChar = 'a'; + } + // print the character + lcd.write(thisChar); + // wait a second: + delay(1000); + // increment the letter: + thisChar++; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/setCursor/setCursor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/setCursor/setCursor.ino new file mode 100644 index 00000000..a0878637 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/LiquidCrystal/examples/setCursor/setCursor.ino @@ -0,0 +1,74 @@ +/* + LiquidCrystal Library - setCursor + + Demonstrates the use of a 16x2 LCD display. The LiquidCrystal + library works with all LCD displays that are compatible with the + Hitachi HD44780 driver. There are many of them out there, and you + can usually tell them by the 16-pin interface. + + This sketch prints to all the positions of the LCD using the + setCursor() method: + + The circuit: + * LCD RS pin to digital pin 12 + * LCD Enable pin to digital pin 11 + * LCD D4 pin to digital pin 5 + * LCD D5 pin to digital pin 4 + * LCD D6 pin to digital pin 3 + * LCD D7 pin to digital pin 2 + * LCD R/W pin to ground + * 10K or 100K potentiometer: + * ends to +5V and ground + * wiper to LCD VO pin (pin 3) + + Library originally added 18 Apr 2008 + by David A. Mellis + library modified 5 Jul 2009 + by Limor Fried (http://www.ladyada.net) + example added 9 Jul 2009 + by Tom Igoe + modified 22 Nov 2010 + by Tom Igoe + modified 7 Nov 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/LibraryExamples/LiquidCrystalSetCursor + +*/ + +// include the library code: +#include + +// initialize the library by associating any needed LCD interface pin +// with the Arduino pin number it is connected to +const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; +LiquidCrystal lcd(rs, en, d4, d5, d6, d7); + +// these constants won't change. But you can change the size of +// your LCD using them: +const int numRows = 2; +const int numCols = 16; + +void setup() { + // set up the LCD's number of columns and rows: + lcd.begin(numCols, numRows); +} + +void loop() { + // loop from ASCII 'a' to ASCII 'z': + for (int thisLetter = 'a'; thisLetter <= 'z'; thisLetter++) { + // loop over the columns: + for (int thisRow = 0; thisRow < numRows; thisRow++) { + // loop over the rows: + for (int thisCol = 0; thisCol < numCols; thisCol++) { + // set the cursor position: + lcd.setCursor(thisCol, thisRow); + // print the letter: + lcd.write(thisLetter); + delay(200); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/README.adoc new file mode 100644 index 00000000..90f43c98 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/README.adoc @@ -0,0 +1,46 @@ +:repository-owner: arduino-libraries +:repository-name: MIDIUSB + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino board with USB capabilities to act as a MIDI instrument over USB. The library is based on PluggableUSB, so is only compatible with Arduino IDE 1.6.6 and newer. + +Furthermore, since PluggableUSB only targets boards with native USB capabilities, this library only supports these boards (eg. Leonardo, Micro, Due, Zero and so on) + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== Test procedure (Linux) == + +Load the correct driver (`sudo modprobe snd_seq_midi`) + +Flash the board with `MIDIUSB_loop` example, then execute `aseqdump -l`; the output will be something similar to +```bash +Port Client name Port name + 0:0 System Timer + 0:1 System Announce + 14:0 Midi Through Midi Through Port-0 + 20:0 Arduino Micro Arduino Micro MIDI 1 +``` +Port `20` is the one we'll use in the following examples. + +Start `fluidsynth` inside a shell with a soundbank +```bash +fluidsynth --server --audio-driver=alsa -o audio.alsa.device=hw:0 ~/Synth.SF2 +``` + +In another shell, execute +```bash +aconnect 20 128 +``` +to connect our MIDI device with fluidsynth + +Then, execute +```bash +aplaymidi --port=20:0 ~/some_midi_file.mid +``` +and the file will be played after a complete roundtrip to the board. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_buzzer/MIDIUSB_buzzer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_buzzer/MIDIUSB_buzzer.ino new file mode 100644 index 00000000..8660bf8d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_buzzer/MIDIUSB_buzzer.ino @@ -0,0 +1,99 @@ +/* + * MIDIUSB_buzzer.ino + * + * Author: Paulo Costa + */ + +#include +#include "pitchToFrequency.h" + +#define BUZZ_PIN 9 + +const char* pitch_name(byte pitch) { + static const char* names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"}; + return names[pitch % 12]; +} + +int pitch_octave(byte pitch) { + return (pitch / 12) - 1; +} + +void noteOn(byte channel, byte pitch, byte velocity) { + tone(BUZZ_PIN, pitchFrequency[pitch]); + + Serial.print("Note On: "); + Serial.print(pitch_name(pitch)); + Serial.print(pitch_octave(pitch)); + Serial.print(", channel="); + Serial.print(channel); + Serial.print(", velocity="); + Serial.println(velocity); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + noTone(BUZZ_PIN); + + Serial.print("Note Off: "); + Serial.print(pitch_name(pitch)); + Serial.print(pitch_octave(pitch)); + Serial.print(", channel="); + Serial.print(channel); + Serial.print(", velocity="); + Serial.println(velocity); +} + +void controlChange(byte channel, byte control, byte value) { + Serial.print("Control change: control="); + Serial.print(control); + Serial.print(", value="); + Serial.print(value); + Serial.print(", channel="); + Serial.println(channel); +} + +void setup() { + Serial.begin(115200); +} + +void loop() { + midiEventPacket_t rx = MidiUSB.read(); + switch (rx.header) { + case 0: + break; //No pending events + + case 0x9: + noteOn( + rx.byte1 & 0xF, //channel + rx.byte2, //pitch + rx.byte3 //velocity + ); + break; + + case 0x8: + noteOff( + rx.byte1 & 0xF, //channel + rx.byte2, //pitch + rx.byte3 //velocity + ); + break; + + case 0xB: + controlChange( + rx.byte1 & 0xF, //channel + rx.byte2, //control + rx.byte3 //value + ); + break; + + default: + Serial.print("Unhandled MIDI message: "); + Serial.print(rx.header, HEX); + Serial.print("-"); + Serial.print(rx.byte1, HEX); + Serial.print("-"); + Serial.print(rx.byte2, HEX); + Serial.print("-"); + Serial.println(rx.byte3, HEX); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_clock/MIDIUSB_clock.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_clock/MIDIUSB_clock.ino new file mode 100644 index 00000000..5dcf74e9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_clock/MIDIUSB_clock.ino @@ -0,0 +1,69 @@ +/* + * MIDIUSB_clock.ino + * + * Simple example of beat clock based on MIDI pulse messages + * received from software. + * + * Tested on Leonardo with Ableton. + * + * In preferences go to MIDI Sync. Select device Output + * and toggle Sync button, change clock type to Pattern. + * Usually changing Sync Delay is required. + * + * Created: 19/12/2016 + * Author: Ernest Warzocha + */ + +#include "MIDIUSB.h" + +//Pulse per quarter note. Each beat has 24 pulses. +//Tempo is based on software inner BPM. +int ppqn = 0; + +void noteOn(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity}; + MidiUSB.sendMIDI(noteOn); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity}; + MidiUSB.sendMIDI(noteOff); +} + +void setup() { + Serial.begin(115200); +} + +void loop() { + + midiEventPacket_t rx; + + do { + rx = MidiUSB.read(); + + //Count pulses and send note + if(rx.byte1 == 0xF8){ + ++ppqn; + + if(ppqn == 24){ + noteOn(1,48,127); + MidiUSB.flush(); + ppqn = 0; + }; + } + //Clock start byte + else if(rx.byte1 == 0xFA){ + noteOn(1,48,127); + MidiUSB.flush(); + ppqn = 0; + } + //Clock stop byte + else if(rx.byte1 == 0xFC){ + noteOff(1,48,0); + MidiUSB.flush(); + ppqn = 0; + }; + + } while (rx.header != 0); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_loop/MIDIUSB_loop.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_loop/MIDIUSB_loop.ino new file mode 100644 index 00000000..f68e715f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_loop/MIDIUSB_loop.ino @@ -0,0 +1,54 @@ +/* + * MIDIUSB_loop.ino + * + * Created: 4/6/2015 10:47:08 AM + * Author: gurbrinder grewal + * Modified by Arduino LLC (2015) + */ + +#include "MIDIUSB.h" + +// First parameter is the event type (0x09 = note on, 0x08 = note off). +// Second parameter is note-on/note-off, combined with the channel. +// Channel can be anything between 0-15. Typically reported to the user as 1-16. +// Third parameter is the note number (48 = middle C). +// Fourth parameter is the velocity (64 = normal, 127 = fastest). + +void noteOn(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity}; + MidiUSB.sendMIDI(noteOn); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity}; + MidiUSB.sendMIDI(noteOff); +} + +void setup() { + Serial.begin(115200); + pinMode(LED_BUILTIN, OUTPUT); +} + +// First parameter is the event type (0x0B = control change). +// Second parameter is the event type, combined with the channel. +// Third parameter is the control number number (0-119). +// Fourth parameter is the control value (0-127). + +void controlChange(byte channel, byte control, byte value) { + midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value}; + MidiUSB.sendMIDI(event); +} + +void loop() { + //MidiUSB.accept(); + //delayMicroseconds(1); + midiEventPacket_t rx; + do { + rx = MidiUSB.read(); + if (rx.header != 0) { + //send back the received MIDI command + MidiUSB.sendMIDI(rx); + MidiUSB.flush(); + } + } while (rx.header != 0); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_read/MIDIUSB_read.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_read/MIDIUSB_read.ino new file mode 100644 index 00000000..89f6498d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_read/MIDIUSB_read.ino @@ -0,0 +1,56 @@ +/* + * MIDIUSB_test.ino + * + * Created: 4/6/2015 10:47:08 AM + * Author: gurbrinder grewal + * Modified by Arduino LLC (2015) + */ + +#include "MIDIUSB.h" + +// First parameter is the event type (0x09 = note on, 0x08 = note off). +// Second parameter is note-on/note-off, combined with the channel. +// Channel can be anything between 0-15. Typically reported to the user as 1-16. +// Third parameter is the note number (48 = middle C). +// Fourth parameter is the velocity (64 = normal, 127 = fastest). + +void noteOn(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity}; + MidiUSB.sendMIDI(noteOn); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity}; + MidiUSB.sendMIDI(noteOff); +} + +void setup() { + Serial.begin(115200); +} + +// First parameter is the event type (0x0B = control change). +// Second parameter is the event type, combined with the channel. +// Third parameter is the control number number (0-119). +// Fourth parameter is the control value (0-127). + +void controlChange(byte channel, byte control, byte value) { + midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value}; + MidiUSB.sendMIDI(event); +} + +void loop() { + midiEventPacket_t rx; + do { + rx = MidiUSB.read(); + if (rx.header != 0) { + Serial.print("Received: "); + Serial.print(rx.header, HEX); + Serial.print("-"); + Serial.print(rx.byte1, HEX); + Serial.print("-"); + Serial.print(rx.byte2, HEX); + Serial.print("-"); + Serial.println(rx.byte3, HEX); + } + } while (rx.header != 0); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_write/MIDIUSB_write.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_write/MIDIUSB_write.ino new file mode 100644 index 00000000..dd24f2c3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MIDIUSB/examples/MIDIUSB_write/MIDIUSB_write.ino @@ -0,0 +1,52 @@ +/* + * MIDIUSB_test.ino + * + * Created: 4/6/2015 10:47:08 AM + * Author: gurbrinder grewal + * Modified by Arduino LLC (2015) + */ + +#include "MIDIUSB.h" + +// First parameter is the event type (0x09 = note on, 0x08 = note off). +// Second parameter is note-on/note-off, combined with the channel. +// Channel can be anything between 0-15. Typically reported to the user as 1-16. +// Third parameter is the note number (48 = middle C). +// Fourth parameter is the velocity (64 = normal, 127 = fastest). + +void noteOn(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity}; + MidiUSB.sendMIDI(noteOn); +} + +void noteOff(byte channel, byte pitch, byte velocity) { + midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity}; + MidiUSB.sendMIDI(noteOff); +} + +void setup() { + Serial.begin(115200); +} + +// First parameter is the event type (0x0B = control change). +// Second parameter is the event type, combined with the channel. +// Third parameter is the control number number (0-119). +// Fourth parameter is the control value (0-127). + +void controlChange(byte channel, byte control, byte value) { + midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value}; + MidiUSB.sendMIDI(event); +} + +void loop() { + Serial.println("Sending note on"); + noteOn(0, 48, 64); // Channel 0, middle C, normal velocity + MidiUSB.flush(); + delay(500); + Serial.println("Sending note off"); + noteOff(0, 48, 64); // Channel 0, middle C, normal velocity + MidiUSB.flush(); + delay(1500); + + // controlChange(0, 10, 65); // Set the value of controller 10 on channel 0 to 65 +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/README.adoc new file mode 100644 index 00000000..29a1b28b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: MKRGSM + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library enables an Arduino MKR GSM 1400 board to do most of the operations you can do with a GSM phone: place and receive voice calls, send and receive SMS, and connect to the internet over a GPRS network. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSPing/GPRSPing.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSPing/GPRSPing.ino new file mode 100644 index 00000000..7e18182e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSPing/GPRSPing.ino @@ -0,0 +1,74 @@ +/* + + This uses an MKR GSM 1400 to continuously ping a host specified by IP Address or name. + +Circuit: +* MKR GSM 1400 board +* Antenna +* SIM card with a data plan + + created 06 Dec 2017 + by Arturo Guadalupi +*/ +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; + +// Specify IP address or hostname +String hostName = "www.google.com"; +int pingResult; + +void setup() { + // Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino GPRS ping."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } +} + +void loop() { + Serial.print("Pinging "); + Serial.print(hostName); + Serial.print(": "); + + pingResult = gprs.ping(hostName); + + if (pingResult >= 0) { + Serial.print("SUCCESS! RTT = "); + Serial.print(pingResult); + Serial.println(" ms"); + } else { + Serial.print("FAILED! Error code: "); + Serial.println(pingResult); + } + + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSPing/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSPing/arduino_secrets.h new file mode 100644 index 00000000..e1c4da91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSPing/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino new file mode 100644 index 00000000..cd45301f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino @@ -0,0 +1,157 @@ +/* + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + modified 6 Dec 2017 ported from WiFi101 to MKRGSM + by Arturo Guadalupi + + This code is in the public domain. + +*/ + +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// initialize the library instance +GSMClient client; +GPRS gprs; +GSM gsmAccess; + +// A UDP instance to let us send and receive packets over UDP +GSMUDP Udp; + +void setup() +{ + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino GPRS NTP client."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() +{ + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if ( Udp.parsePacket() ) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = " ); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if ( ((epoch % 3600) / 60) < 10 ) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ( (epoch % 60) < 10 ) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) +{ + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/arduino_secrets.h new file mode 100644 index 00000000..e1c4da91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GPRSUdpNtpClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmLocation/GsmLocation.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmLocation/GsmLocation.ino new file mode 100644 index 00000000..c3e205dc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmLocation/GsmLocation.ino @@ -0,0 +1,77 @@ +/* + Location + + This sketch uses the celluar network to determine the location of a MKR GSM 1400 board + and prints it to the Serial Monitor. The location is based on the cellular towers in + range, and requires a GPRS data connection to be enabled. + + Circuit: + MKR GSM 1400 board + Antenna + SIM card with a data plan + + created 15 Dec 2017 + by Sandeep Mistry +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMLocation location; +GPRS gprs; +GSM gsmAccess; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting GSM location."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + location.begin(); +} + +void loop() { + if (location.available()) { + Serial.print("Location: "); + Serial.print(location.latitude(), 7); + Serial.print(", "); + Serial.println(location.longitude(), 7); + + Serial.print("Altitude: "); + Serial.print(location.altitude()); + Serial.println("m"); + + Serial.print("Accuracy: +/- "); + Serial.print(location.accuracy()); + Serial.println("m"); + + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmLocation/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmLocation/arduino_secrets.h new file mode 100644 index 00000000..e1c4da91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmLocation/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/GsmSSLWebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/GsmSSLWebClient.ino new file mode 100644 index 00000000..6e57c757 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/GsmSSLWebClient.ino @@ -0,0 +1,99 @@ +/* + Web client + + This sketch connects to a website using SSL through a MKR GSM 1400 board. Specifically, + this example downloads the URL "http://www.arduino.cc/asciilogo.txt" and + prints it to the Serial Monitor. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; + +// URL, path and port (for example: arduino.cc) +char server[] = "arduino.cc"; +char path[] = "/asciilogo.txt"; +int port = 443; // port 443 is the default for HTTPS + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET "); + client.print(path); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/arduino_secrets.h new file mode 100644 index 00000000..e1c4da91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmSSLWebClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/GsmWebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/GsmWebClient.ino new file mode 100644 index 00000000..0cad8d76 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/GsmWebClient.ino @@ -0,0 +1,99 @@ +/* + Web client + + This sketch connects to a website through a MKR GSM 1400 board. Specifically, + this example downloads the URL "http://www.example.org/" and + prints it to the Serial Monitor. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMClient client; +GPRS gprs; +GSM gsmAccess; + +// URL, path and port (for example: example.org) +char server[] = "example.org"; +char path[] = "/"; +int port = 80; // port 80 is the default for HTTP + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET "); + client.print(path); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/arduino_secrets.h new file mode 100644 index 00000000..e1c4da91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/GsmWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/GsmWebServer.ino new file mode 100644 index 00000000..56e836a1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/GsmWebServer.ino @@ -0,0 +1,115 @@ +/* + GSM Web Server + + A simple web server that shows the value of the analog input pins. + using a MKR GSM 1400 board. + + Circuit: + * MKR GSM 1400 board + * Antenna + * Analog inputs attached to pins A0 through A5 (optional) + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + + +// initialize the library instance +GPRS gprs; +GSM gsmAccess; // include a 'true' parameter for debug enabled +GSMServer server(80); // port 80 (http default) + +// timeout +const unsigned long __TIMEOUT__ = 10 * 1000; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected to GPRS network"); + + // start server + server.begin(); + + //Get IP. + IPAddress LocalIP = gprs.getIPAddress(); + Serial.println("Server IP address="); + Serial.println(LocalIP); +} + +void loop() { + + + // listen for incoming clients + GSMClient client = server.available(); + + + + if (client) { + while (client.connected()) { + if (client.available()) { + Serial.println("Receiving request!"); + bool sendResponse = false; + while (int c = client.read()) { + if (c == -1) { + break; + } else if (c == '\n') { + sendResponse = true; + } + } + + // if you've gotten to the end of the line (received a newline + // character) + if (sendResponse) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println(); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(analogRead(analogChannel)); + client.println("
    "); + } + client.println(""); + //necessary delay + delay(1000); + client.stop(); + } + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/arduino_secrets.h new file mode 100644 index 00000000..e1c4da91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/GsmWebServer/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/MakeVoiceCall.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/MakeVoiceCall.ino new file mode 100644 index 00000000..d3514f30 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/MakeVoiceCall.ino @@ -0,0 +1,104 @@ +/* + Make Voice Call + + This sketch, for the MKR GSM 1400 board, puts a voice call to + a remote phone number that you enter through the Serial Monitor. + To make it work, open the Serial Monitor, and when you see the + READY message, type a phone number. Make sure the Serial Monitor + is set to send a just newline when you press return. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card that can send voice calls + + + created Mar 2012 + by Javier Zorzano +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; // include a 'true' parameter for debug enabled +GSMVoiceCall vcs; + +String remoteNumber = ""; // the number you will call +char charbuffer[20]; + +void setup() { + + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Make Voice Call"); + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("GSM initialized."); + Serial.println("Enter phone number to call."); + +} + +void loop() { + + // add any incoming characters to the String: + while (Serial.available() > 0) { + char inChar = Serial.read(); + // if it's a newline, that means you should make the call: + if (inChar == '\n') { + // make sure the phone number is not too long: + if (remoteNumber.length() < 20) { + // let the user know you're calling: + Serial.print("Calling to : "); + Serial.println(remoteNumber); + Serial.println(); + + // Call the remote number + remoteNumber.toCharArray(charbuffer, 20); + + + // Check if the receiving end has picked up the call + if (vcs.voiceCall(charbuffer)) { + Serial.println("Call Established. Enter line to end"); + // Wait for some input from the line + while (Serial.read() != '\n' && (vcs.getvoiceCallStatus() == TALKING)); + // And hang up + vcs.hangCall(); + } + Serial.println("Call Finished"); + remoteNumber = ""; + Serial.println("Enter phone number to call."); + } else { + Serial.println("That's too long for a phone number. I'm forgetting it"); + remoteNumber = ""; + } + } else { + // add the latest character to the message to send: + if (inChar != '\r') { + remoteNumber += inChar; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/MakeVoiceCall/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/ReceiveSMS.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/ReceiveSMS.ino new file mode 100644 index 00000000..b2a4f0b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/ReceiveSMS.ino @@ -0,0 +1,89 @@ +/* + SMS receiver + + This sketch, for the MKR GSM 1400 board, waits for a SMS message + and displays it through the Serial port. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card that can receive SMS messages + + created 25 Feb 2012 + by Javier Zorzano / TD +*/ + +// include the GSM library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instances +GSM gsmAccess; +GSM_SMS sms; + +// Array to hold the number a SMS is retrieved from +char senderNumber[20]; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("SMS Messages Receiver"); + + // connection state + bool connected = false; + + // Start GSM connection + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("GSM initialized"); + Serial.println("Waiting for messages"); +} + +void loop() { + int c; + + // If there are any SMSs available() + if (sms.available()) { + Serial.println("Message received from:"); + + // Get remote number + sms.remoteNumber(senderNumber, 20); + Serial.println(senderNumber); + + // An example of message disposal + // Any messages starting with # should be discarded + if (sms.peek() == '#') { + Serial.println("Discarded SMS"); + sms.flush(); + } + + // Read message bytes and print them + while ((c = sms.read()) != -1) { + Serial.print((char)c); + } + + Serial.println("\nEND OF MESSAGE"); + + // Delete message from modem memory + sms.flush(); + Serial.println("MESSAGE DELETED"); + } + + delay(1000); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveSMS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino new file mode 100644 index 00000000..5f46c0dd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/ReceiveVoiceCall.ino @@ -0,0 +1,93 @@ +/* + Receive Voice Call + + This sketch, for the MKR GSM 1400 board, receives voice calls, + displays the calling number, waits a few seconds then hangs up. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card that can accept voice calls + + created Mar 2012 + by Javier Zorzano +*/ + +// Include the GSM library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; +GSMVoiceCall vcs; + +// Array to hold the number for the incoming call +char numtel[20]; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Receive Voice Call"); + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + // This makes sure the modem correctly reports incoming events + vcs.hangCall(); + + Serial.println("Waiting for a call"); +} + +void loop() { + // Check the status of the voice call + switch (vcs.getvoiceCallStatus()) { + case IDLE_CALL: // Nothing is happening + + break; + + case RECEIVINGCALL: // Yes! Someone is calling us + + Serial.println("RECEIVING CALL"); + + // Retrieve the calling number + vcs.retrieveCallingNumber(numtel, 20); + + // Print the calling number + Serial.print("Number:"); + Serial.println(numtel); + + // Answer the call, establish the call + vcs.answerCall(); + break; + + case TALKING: // In this case the call would be established + + Serial.println("TALKING. Press enter to hang up."); + while (Serial.read() != '\n') { + delay(100); + } + vcs.hangCall(); + Serial.println("Hanging up and waiting for the next call."); + break; + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/ReceiveVoiceCall/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/SSLCertificateManagement.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/SSLCertificateManagement.ino new file mode 100644 index 00000000..4adc865a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/SSLCertificateManagement.ino @@ -0,0 +1,125 @@ +/* + ArduinoMqttClient - SSLCertificateManagement + + This example shows how to upload a self signed certificate + by GSMSSLClient's APIs, connect to a MQTT broker, + and publish a message to a topic once a second. + + The circuit: + - Arduino MKR GSM 1400 + + This example code is in the public domain. +*/ + +#include +#include +#include "arduino_secrets.h" + + +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; +MqttClient mqttClient(client); + +// replace with your broker, port and topic +const char broker[] = ""; +int port = 8883; +const char topic[] = ""; + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + + +void setup() { + // Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + bool connected = false; + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("You're connected to the network"); + Serial.println(); + + // eraseAllCertificates erases all the certificates stored in the onboard + // GSM module + client.eraseAllCertificates(); + + client.setUserRoots(SECRET_GSM_ROOT_CERTS, SECRET_GSM_ROOT_SIZE); + client.setSignedCertificate(SECRET_CERT, "MKRGSM01", sizeof(SECRET_CERT)); + client.setPrivateKey(SECRET_KEY, "MKRGSMKEY01", sizeof(SECRET_KEY)); + + client.useSignedCertificate("MKRGSM01"); + client.usePrivateKey("MKRGSMKEY01"); + client.setTrustedRoot("Let_s_Encrypt_Authority_X3"); + + + Serial.print("Attempting to connect to the MQTT broker: "); + Serial.println(broker); + + if (!mqttClient.connect(broker, port)) { + + Serial.print("MQTT connection failed! Error code = "); + Serial.println(mqttClient.connectError()); + + while (1); + } + + Serial.println("You're connected to the MQTT broker!"); + Serial.println(); + + +} + +void loop() { + // call poll() regularly to allow the library to send MQTT keep alives which + // avoids being disconnected by the broker + mqttClient.poll(); + + // to avoid having delays in loop, we'll use the strategy from BlinkWithoutDelay + // see: File -> Examples -> 02.Digital -> BlinkWithoutDelay for more info + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time a message was sent + previousMillis = currentMillis; + + Serial.print("Sending message to topic: "); + Serial.println(topic); + Serial.print("hello "); + Serial.println(count); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage(topic); + mqttClient.print("hello "); + mqttClient.print(count); + if (!mqttClient.endMessage()) { + Serial.println("transmission error"); + } + + Serial.println(); + + count++; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/arduino_secrets.h new file mode 100644 index 00000000..b0076aac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SSLCertificateManagement/arduino_secrets.h @@ -0,0 +1,311 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + + +// Replace with your client.crt certificate in DER format +const uint8_t SECRET_CERT[] = { + /*0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0x02, 0x09, 0x00, 0xc2, + 0x68, 0x43, 0x0c, 0x54, 0xae, 0xfe, 0x3a, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x62, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x54, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x05, + 0x49, 0x74, 0x61, 0x6c, 0x79, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, + 0x04, 0x07, 0x0c, 0x05, 0x54, 0x75, 0x72, 0x69, 0x6e, 0x31, 0x10, 0x30, + 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x41, 0x72, 0x64, 0x75, + 0x69, 0x6e, 0x6f, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b, + 0x0c, 0x03, 0x4d, 0x6e, 0x78, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, + 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x69, 0x75, 0x6d, + 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x36, 0x31, 0x36, + 0x31, 0x35, 0x32, 0x39, 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, + 0x36, 0x31, 0x36, 0x31, 0x35, 0x32, 0x39, 0x30, 0x31, 0x5a, 0x30, 0x63, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x54, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x08, + 0x50, 0x69, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x74, 0x31, 0x0e, 0x30, 0x0c, + 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x05, 0x54, 0x75, 0x72, 0x69, 0x6e, + 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x03, 0x4d, + 0x6e, 0x78, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, + 0x07, 0x41, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x31, 0x11, 0x30, 0x0f, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x08, 0x4d, 0x4b, 0x52, 0x47, 0x53, + 0x4d, 0x30, 0x31, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xb6, 0xb7, 0xa2, 0x73, 0x9e, 0x8b, 0xcc, 0x7f, 0x55, 0xb3, 0xb4, 0xad, + 0xfe, 0x6a, 0xbc, 0xa7, 0xe5, 0xec, 0x02, 0xd0, 0x4b, 0x25, 0xa4, 0xd3, + 0xc4, 0x33, 0x37, 0xa7, 0x76, 0xdf, 0xa3, 0x9f, 0xdd, 0x42, 0x3e, 0xb5, + 0xe2, 0xbc, 0x89, 0xe4, 0x18, 0x02, 0xb6, 0x62, 0xe4, 0x3b, 0xa6, 0x74, + 0x76, 0xf8, 0x73, 0xe7, 0x80, 0xea, 0x5d, 0x93, 0x9d, 0x61, 0x2a, 0x24, + 0x06, 0x4c, 0x6b, 0x68, 0xea, 0x63, 0x1d, 0x3a, 0xce, 0x8b, 0x31, 0x05, + 0x72, 0xe9, 0xdc, 0xce, 0x05, 0x8c, 0x7a, 0xc1, 0xf5, 0xd6, 0xe1, 0xd0, + 0x6d, 0x73, 0x4e, 0xc1, 0x8a, 0x16, 0x49, 0x4d, 0xac, 0x21, 0xfb, 0x2d, + 0x12, 0xdd, 0x1e, 0xef, 0x9b, 0xb3, 0x6d, 0x20, 0x69, 0xfb, 0xaa, 0x3c, + 0x2c, 0x8f, 0x0d, 0x7c, 0x09, 0x1c, 0x1a, 0xa5, 0x23, 0x83, 0x98, 0x10, + 0xf4, 0x0c, 0x78, 0xa4, 0xa0, 0x4b, 0x1a, 0x71, 0x52, 0x4b, 0xb3, 0x8b, + 0x4c, 0x29, 0xfe, 0x6f, 0x24, 0x88, 0x7e, 0xd6, 0xf0, 0x6a, 0x2c, 0x3c, + 0x6c, 0xad, 0x54, 0x0c, 0xb6, 0x7b, 0xa4, 0x76, 0x38, 0xbf, 0x35, 0xc6, + 0x66, 0xde, 0x6a, 0x92, 0x43, 0x26, 0x31, 0xae, 0x76, 0xb5, 0xf6, 0x15, + 0x87, 0x02, 0x37, 0x7e, 0x7b, 0x92, 0xda, 0x3f, 0x45, 0x1e, 0x89, 0xb7, + 0x26, 0xb3, 0x8d, 0x3c, 0xf6, 0x49, 0x25, 0xe9, 0x1e, 0x52, 0x6f, 0x40, + 0x2e, 0xb6, 0x7d, 0x5c, 0x2a, 0x8a, 0x9c, 0x7d, 0x2c, 0x09, 0xce, 0xde, + 0x73, 0x5d, 0x3b, 0x7d, 0x4f, 0x3f, 0x4b, 0xdc, 0xeb, 0x8b, 0x93, 0xd1, + 0xc2, 0xf3, 0x29, 0x08, 0x98, 0x06, 0x8c, 0x46, 0x38, 0xe1, 0xd5, 0x30, + 0xc1, 0xf0, 0x3c, 0x74, 0x58, 0xf0, 0x20, 0x8b, 0xea, 0x30, 0x43, 0xd8, + 0x3d, 0x19, 0xc4, 0xd1, 0x04, 0xc8, 0xe5, 0x76, 0x31, 0x36, 0x4a, 0xae, + .. .. .. .. .. .. .. .. .. .. .. .. + 0xd3, 0xb2, 0x75, 0x2b, 0x85, 0x71, 0x02, 0x9a, 0x51, 0x38, 0x08, 0x61, + 0xf8, 0x8b, 0x8b, 0x36, 0xf5, 0x10, 0x6e, 0xd9, 0xda, 0xf5, 0x3a, 0xf1, + 0xf1, 0x6f, 0xc4, 0xd7, 0x52, 0x6f, 0x22, 0x38, 0x8a, 0xff, 0x75, 0x82, + 0x93, 0x94, 0xc9, 0x45, 0xcf, 0xa3, 0x23, 0x04, 0x6f, 0x3a, 0x58, 0xe1, + 0xca, 0xfa, 0xa8, 0x1f, 0xd3, 0x87, 0x6e, 0xcb, 0xe3*/ +}; + +// Replace with your client.key certificate in DER format +uint8_t SECRET_KEY[] = { + /*0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xb6, 0xb7, 0xa2, 0x73, 0x9e, 0x8b, 0xcc, 0x7f, 0x55, 0xb3, 0xb4, 0xad, + 0xfe, 0x6a, 0xbc, 0xa7, 0xe5, 0xec, 0x02, 0xd0, 0x4b, 0x25, 0xa4, 0xd3, + 0xc4, 0x33, 0x37, 0xa7, 0x76, 0xdf, 0xa3, 0x9f, 0xdd, 0x42, 0x3e, 0xb5, + 0xe2, 0xbc, 0x89, 0xe4, 0x18, 0x02, 0xb6, 0x62, 0xe4, 0x3b, 0xa6, 0x74, + 0x76, 0xf8, 0x73, 0xe7, 0x80, 0xea, 0x5d, 0x93, 0x9d, 0x61, 0x2a, 0x24, + 0x06, 0x4c, 0x6b, 0x68, 0xea, 0x63, 0x1d, 0x3a, 0xce, 0x8b, 0x31, 0x05, + 0x72, 0xe9, 0xdc, 0xce, 0x05, 0x8c, 0x7a, 0xc1, 0xf5, 0xd6, 0xe1, 0xd0, + 0x6d, 0x73, 0x4e, 0xc1, 0x8a, 0x16, 0x49, 0x4d, 0xac, 0x21, 0xfb, 0x2d, + 0x12, 0xdd, 0x1e, 0xef, 0x9b, 0xb3, 0x6d, 0x20, 0x69, 0xfb, 0xaa, 0x3c, + 0x2c, 0x8f, 0x0d, 0x7c, 0x09, 0x1c, 0x1a, 0xa5, 0x23, 0x83, 0x98, 0x10, + 0xf4, 0x0c, 0x78, 0xa4, 0xa0, 0x4b, 0x1a, 0x71, 0x52, 0x4b, 0xb3, 0x8b, + 0x4c, 0x29, 0xfe, 0x6f, 0x24, 0x88, 0x7e, 0xd6, 0xf0, 0x6a, 0x2c, 0x3c, + 0x6c, 0xad, 0x54, 0x0c, 0xb6, 0x7b, 0xa4, 0x76, 0x38, 0xbf, 0x35, 0xc6, + 0x66, 0xde, 0x6a, 0x92, 0x43, 0x26, 0x31, 0xae, 0x76, 0xb5, 0xf6, 0x15, + 0x87, 0x02, 0x37, 0x7e, 0x7b, 0x92, 0xda, 0x3f, 0x45, 0x1e, 0x89, 0xb7, + 0x26, 0xb3, 0x8d, 0x3c, 0xf6, 0x49, 0x25, 0xe9, 0x1e, 0x52, 0x6f, 0x40, + 0x2e, 0xb6, 0x7d, 0x5c, 0x2a, 0x8a, 0x9c, 0x7d, 0x2c, 0x09, 0xce, 0xde, + 0x73, 0x5d, 0x3b, 0x7d, 0x4f, 0x3f, 0x4b, 0xdc, 0xeb, 0x8b, 0x93, 0xd1, + 0xc2, 0xf3, 0x29, 0x08, 0x98, 0x06, 0x8c, 0x46, 0x38, 0xe1, 0xd5, 0x30, + 0xc1, 0xf0, 0x3c, 0x74, 0x58, 0xf0, 0x20, 0x8b, 0xea, 0x30, 0x43, 0xd8, + 0x3d, 0x19, 0xc4, 0xd1, 0x04, 0xc8, 0xe5, 0x76, 0x31, 0x36, 0x4a, 0xae, + 0xf4, 0x21, 0x41, 0x0b, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, + 0x00, 0x7b, 0xe7, 0x87, 0x58, 0x54, 0x59, 0x84, 0xf1, 0x8c, 0x92, 0x72, + 0xa1, 0xd2, 0xf7, 0x5a, 0xbb, 0x98, 0xa5, 0x35, 0x3b, 0x3e, 0xda, 0x66, + 0x2d, 0xdc, 0xcc, 0xc6, 0x9e, 0xdf, 0x73, 0xc4, 0xa7, 0xb2, 0x09, 0x2c, + 0x31, 0x77, 0x72, 0x57, 0x27, 0xc0, 0x48, 0x86, 0x9a, 0x05, 0x1f, 0x96, + 0x3f, 0x40, 0x36, 0x37, 0x92, 0xf3, 0xce, 0xfa, 0x6a, 0x11, 0xbd, 0x44, + 0x30, 0x6d, 0xbd, 0x00, 0xd1, 0x82, 0xb0, 0x77, 0xaf, 0xdb, 0x44, 0x74, + 0x97, 0xb7, 0x57, 0x73, 0x8e, 0x9a, 0x20, 0xab, 0x56, 0x40, 0x79, 0xd9, + 0x63, 0xd7, 0xf4, 0xeb, 0xa1, 0x3f, 0x1c, 0xe1, 0xd4, 0xb4, 0x37, 0xce, + 0xf6, 0xbf, 0xe6, 0x07, 0x06, 0x81, 0x55, 0x69, 0x59, 0x23, 0xc5, 0xaf, + 0xa9, 0x62, 0xa6, 0x17, 0x84, 0xd7, 0x40, 0xa1, 0xa8, 0xfe, 0xae, 0x4c, + 0x3e, 0xa2, 0xe0, 0x9a, 0x27, 0x39, 0x33, 0xf4, 0xd7, 0x62, 0x94, 0xac, + 0x58, 0xb8, 0x45, 0x03, 0xdf, 0x19, 0x21, 0x5b, 0xf8, 0x0c, 0xfb, 0x44, + 0x7e, 0xc7, 0x94, 0x15, 0xc1, 0xb5, 0x34, 0xfe, 0x1a, 0x35, 0xf7, 0x73, + 0x7a, 0xf4, 0x5f, 0x15, 0xaf, 0x6e, 0x93, 0x46, 0xbc, 0xae, 0x16, 0x32, + 0xed, 0x37, 0x73, 0x69, 0x17, 0xd7, 0xcc, 0x41, 0x6a, 0x25, 0x17, 0xa6, + 0x35, 0x58, 0x46, 0xb6, 0x2f, 0x13, 0x64, 0x1b, 0x04, 0x02, 0xdc, 0x5d, + 0x06, 0xe6, 0xf3, 0xb8, 0xf5, 0x93, 0xee, 0x39, 0xff, 0x0a, 0xa3, 0x33, + 0x9b, 0x30, 0x63, 0x5e, 0xf8, 0xfd, 0xd6, 0x45, 0x56, 0xe8, 0xdf, 0x64, + 0x62, 0x23, 0xa0, 0xf1, 0x1e, 0x6a, 0x4c, 0xc0, 0xc1, 0x95, 0x47, 0x05, + 0xb7, 0x5a, 0xb3, 0xda, 0xa5, 0x91, 0x81, 0x49, 0xef, 0x1d, 0x36, 0x14, + 0x55, 0x0f, 0x00, 0x9e, 0x28, 0x1b, 0x15, 0x77, 0x6c, 0x24, 0xd0, 0xe8, + 0x3f, 0x79, 0x37, 0x6a, 0xd1, 0x02, 0x81, 0x81, 0x00, 0xdb, 0x95, 0x25, + 0xee, 0x4f, 0x77, 0x20, 0xcf, 0xf8, 0xc4, 0x3a, 0xa5, 0xcf, 0x15, 0x28, + 0x4f, 0xdf, 0x16, 0xbb, 0xfc, 0x10, 0xaa, 0xa5, 0x7f, 0x0d, 0xea, 0x93, + 0xe2, 0xaf, 0x91, 0x9c, 0x77, 0xcc, 0x51, 0x8e, 0xb0, 0x79, 0xc8, 0xba, + 0xe4, 0x75, 0xcb, 0x07, 0x47, 0x04, 0xab, 0xb5, 0xd0, 0x75, 0x6f, 0x61, + 0xa4, 0x98, 0x2d, 0x15, 0xa9, 0x8a, 0xa2, 0x44, 0xde, 0x4c, 0xd7, 0x7f, + 0x01, 0xb7, 0xb4, 0x71, 0x21, 0x6e, 0xff, 0x0b, 0x15, 0x46, 0x81, 0xd8, + 0x53, 0x11, 0x1d, 0x7c, 0x8f, 0x48, 0x6a, 0xd0, 0x1c, 0xe8, 0xe0, 0x7d, + 0xed, 0x44, 0x17, 0x30, 0xcb, 0xed, 0xfc, 0x65, 0x92, 0x21, 0x62, 0x75, + 0x1f, 0x5c, 0x6a, 0x32, 0x4f, 0xc9, 0xb8, 0x98, 0x11, 0xc7, 0x54, 0x18, + .. .. .. .. .. .. .. .. .. .. .. .. + 0x3b, 0x25, 0x36, 0xc2, 0xcd, 0x02, 0x81, 0x81, 0x00, 0xd5, 0x05, 0x4a, + 0x96, 0xf5, 0x50, 0xc4, 0x46, 0x95*/ +}; + + +static const GSMRootCert SECRET_GSM_ROOT_CERTS[] = { + { + "DST_Root_CA_X3", + (const uint8_t[]){ + 0x30, 0x82, 0x03, 0x4a, 0x30, 0x82, 0x02, 0x32, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x44, 0xaf, 0xb0, 0x80, 0xd6, 0xa3, 0x27, 0xba, 0x89, + 0x30, 0x39, 0x86, 0x2e, 0xf8, 0x40, 0x6b, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3f, + 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43, + 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, + 0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x30, 0x30, 0x39, 0x33, + 0x30, 0x32, 0x31, 0x31, 0x32, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x31, + 0x30, 0x39, 0x33, 0x30, 0x31, 0x34, 0x30, 0x31, 0x31, 0x35, 0x5a, 0x30, + 0x3f, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, + 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, + 0x43, 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x13, 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, + 0x41, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, + 0x00, 0xdf, 0xaf, 0xe9, 0x97, 0x50, 0x08, 0x83, 0x57, 0xb4, 0xcc, 0x62, + 0x65, 0xf6, 0x90, 0x82, 0xec, 0xc7, 0xd3, 0x2c, 0x6b, 0x30, 0xca, 0x5b, + 0xec, 0xd9, 0xc3, 0x7d, 0xc7, 0x40, 0xc1, 0x18, 0x14, 0x8b, 0xe0, 0xe8, + 0x33, 0x76, 0x49, 0x2a, 0xe3, 0x3f, 0x21, 0x49, 0x93, 0xac, 0x4e, 0x0e, + 0xaf, 0x3e, 0x48, 0xcb, 0x65, 0xee, 0xfc, 0xd3, 0x21, 0x0f, 0x65, 0xd2, + 0x2a, 0xd9, 0x32, 0x8f, 0x8c, 0xe5, 0xf7, 0x77, 0xb0, 0x12, 0x7b, 0xb5, + 0x95, 0xc0, 0x89, 0xa3, 0xa9, 0xba, 0xed, 0x73, 0x2e, 0x7a, 0x0c, 0x06, + 0x32, 0x83, 0xa2, 0x7e, 0x8a, 0x14, 0x30, 0xcd, 0x11, 0xa0, 0xe1, 0x2a, + 0x38, 0xb9, 0x79, 0x0a, 0x31, 0xfd, 0x50, 0xbd, 0x80, 0x65, 0xdf, 0xb7, + 0x51, 0x63, 0x83, 0xc8, 0xe2, 0x88, 0x61, 0xea, 0x4b, 0x61, 0x81, 0xec, + 0x52, 0x6b, 0xb9, 0xa2, 0xe2, 0x4b, 0x1a, 0x28, 0x9f, 0x48, 0xa3, 0x9e, + 0x0c, 0xda, 0x09, 0x8e, 0x3e, 0x17, 0x2e, 0x1e, 0xdd, 0x20, 0xdf, 0x5b, + 0xc6, 0x2a, 0x8a, 0xab, 0x2e, 0xbd, 0x70, 0xad, 0xc5, 0x0b, 0x1a, 0x25, + 0x90, 0x74, 0x72, 0xc5, 0x7b, 0x6a, 0xab, 0x34, 0xd6, 0x30, 0x89, 0xff, + 0xe5, 0x68, 0x13, 0x7b, 0x54, 0x0b, 0xc8, 0xd6, 0xae, 0xec, 0x5a, 0x9c, + 0x92, 0x1e, 0x3d, 0x64, 0xb3, 0x8c, 0xc6, 0xdf, 0xbf, 0xc9, 0x41, 0x70, + 0xec, 0x16, 0x72, 0xd5, 0x26, 0xec, 0x38, 0x55, 0x39, 0x43, 0xd0, 0xfc, + 0xfd, 0x18, 0x5c, 0x40, 0xf1, 0x97, 0xeb, 0xd5, 0x9a, 0x9b, 0x8d, 0x1d, + 0xba, 0xda, 0x25, 0xb9, 0xc6, 0xd8, 0xdf, 0xc1, 0x15, 0x02, 0x3a, 0xab, + 0xda, 0x6e, 0xf1, 0x3e, 0x2e, 0xf5, 0x5c, 0x08, 0x9c, 0x3c, 0xd6, 0x83, + 0x69, 0xe4, 0x10, 0x9b, 0x19, 0x2a, 0xb6, 0x29, 0x57, 0xe3, 0xe5, 0x3d, + 0x9b, 0x9f, 0xf0, 0x02, 0x5d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42, + 0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, + 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, + 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, + 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc4, 0xa7, + 0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, 0xe1, 0x4b, 0x90, 0x75, 0xff, + 0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, + 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, + 0x01, 0x00, 0xa3, 0x1a, 0x2c, 0x9b, 0x17, 0x00, 0x5c, 0xa9, 0x1e, 0xee, + 0x28, 0x66, 0x37, 0x3a, 0xbf, 0x83, 0xc7, 0x3f, 0x4b, 0xc3, 0x09, 0xa0, + 0x95, 0x20, 0x5d, 0xe3, 0xd9, 0x59, 0x44, 0xd2, 0x3e, 0x0d, 0x3e, 0xbd, + 0x8a, 0x4b, 0xa0, 0x74, 0x1f, 0xce, 0x10, 0x82, 0x9c, 0x74, 0x1a, 0x1d, + 0x7e, 0x98, 0x1a, 0xdd, 0xcb, 0x13, 0x4b, 0xb3, 0x20, 0x44, 0xe4, 0x91, + 0xe9, 0xcc, 0xfc, 0x7d, 0xa5, 0xdb, 0x6a, 0xe5, 0xfe, 0xe6, 0xfd, 0xe0, + 0x4e, 0xdd, 0xb7, 0x00, 0x3a, 0xb5, 0x70, 0x49, 0xaf, 0xf2, 0xe5, 0xeb, + 0x02, 0xf1, 0xd1, 0x02, 0x8b, 0x19, 0xcb, 0x94, 0x3a, 0x5e, 0x48, 0xc4, + 0x18, 0x1e, 0x58, 0x19, 0x5f, 0x1e, 0x02, 0x5a, 0xf0, 0x0c, 0xf1, 0xb1, + 0xad, 0xa9, 0xdc, 0x59, 0x86, 0x8b, 0x6e, 0xe9, 0x91, 0xf5, 0x86, 0xca, + 0xfa, 0xb9, 0x66, 0x33, 0xaa, 0x59, 0x5b, 0xce, 0xe2, 0xa7, 0x16, 0x73, + 0x47, 0xcb, 0x2b, 0xcc, 0x99, 0xb0, 0x37, 0x48, 0xcf, 0xe3, 0x56, 0x4b, + 0xf5, 0xcf, 0x0f, 0x0c, 0x72, 0x32, 0x87, 0xc6, 0xf0, 0x44, 0xbb, 0x53, + 0x72, 0x6d, 0x43, 0xf5, 0x26, 0x48, 0x9a, 0x52, 0x67, 0xb7, 0x58, 0xab, + 0xfe, 0x67, 0x76, 0x71, 0x78, 0xdb, 0x0d, 0xa2, 0x56, 0x14, 0x13, 0x39, + 0x24, 0x31, 0x85, 0xa2, 0xa8, 0x02, 0x5a, 0x30, 0x47, 0xe1, 0xdd, 0x50, + 0x07, 0xbc, 0x02, 0x09, 0x90, 0x00, 0xeb, 0x64, 0x63, 0x60, 0x9b, 0x16, + 0xbc, 0x88, 0xc9, 0x12, 0xe6, 0xd2, 0x7d, 0x91, 0x8b, 0xf9, 0x3d, 0x32, + 0x8d, 0x65, 0xb4, 0xe9, 0x7c, 0xb1, 0x57, 0x76, 0xea, 0xc5, 0xb6, 0x28, + 0x39, 0xbf, 0x15, 0x65, 0x1c, 0xc8, 0xf6, 0x77, 0x96, 0x6a, 0x0a, 0x8d, + 0x77, 0x0b, 0xd8, 0x91, 0x0b, 0x04, 0x8e, 0x07, 0xdb, 0x29, 0xb6, 0x0a, + 0xee, 0x9d, 0x82, 0x35, 0x35, 0x10 + }, + 846 + }, + { + "Let_s_Encrypt_Authority_X3", + (const uint8_t[]){ + 0x30, 0x82, 0x04, 0x92, 0x30, 0x82, 0x03, 0x7a, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x0a, 0x01, 0x41, 0x42, 0x00, 0x00, 0x01, 0x53, 0x85, + 0x73, 0x6a, 0x0b, 0x85, 0xec, 0xa7, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3f, + 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43, + 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, + 0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x33, 0x31, + 0x37, 0x31, 0x36, 0x34, 0x30, 0x34, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x31, + 0x30, 0x33, 0x31, 0x37, 0x31, 0x36, 0x34, 0x30, 0x34, 0x36, 0x5a, 0x30, + 0x4a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + 0x55, 0x53, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, + 0x0d, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x31, 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x1a, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, + 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, + 0x9c, 0xd3, 0x0c, 0xf0, 0x5a, 0xe5, 0x2e, 0x47, 0xb7, 0x72, 0x5d, 0x37, + 0x83, 0xb3, 0x68, 0x63, 0x30, 0xea, 0xd7, 0x35, 0x26, 0x19, 0x25, 0xe1, + 0xbd, 0xbe, 0x35, 0xf1, 0x70, 0x92, 0x2f, 0xb7, 0xb8, 0x4b, 0x41, 0x05, + 0xab, 0xa9, 0x9e, 0x35, 0x08, 0x58, 0xec, 0xb1, 0x2a, 0xc4, 0x68, 0x87, + 0x0b, 0xa3, 0xe3, 0x75, 0xe4, 0xe6, 0xf3, 0xa7, 0x62, 0x71, 0xba, 0x79, + 0x81, 0x60, 0x1f, 0xd7, 0x91, 0x9a, 0x9f, 0xf3, 0xd0, 0x78, 0x67, 0x71, + 0xc8, 0x69, 0x0e, 0x95, 0x91, 0xcf, 0xfe, 0xe6, 0x99, 0xe9, 0x60, 0x3c, + 0x48, 0xcc, 0x7e, 0xca, 0x4d, 0x77, 0x12, 0x24, 0x9d, 0x47, 0x1b, 0x5a, + 0xeb, 0xb9, 0xec, 0x1e, 0x37, 0x00, 0x1c, 0x9c, 0xac, 0x7b, 0xa7, 0x05, + 0xea, 0xce, 0x4a, 0xeb, 0xbd, 0x41, 0xe5, 0x36, 0x98, 0xb9, 0xcb, 0xfd, + 0x6d, 0x3c, 0x96, 0x68, 0xdf, 0x23, 0x2a, 0x42, 0x90, 0x0c, 0x86, 0x74, + 0x67, 0xc8, 0x7f, 0xa5, 0x9a, 0xb8, 0x52, 0x61, 0x14, 0x13, 0x3f, 0x65, + 0xe9, 0x82, 0x87, 0xcb, 0xdb, 0xfa, 0x0e, 0x56, 0xf6, 0x86, 0x89, 0xf3, + 0x85, 0x3f, 0x97, 0x86, 0xaf, 0xb0, 0xdc, 0x1a, 0xef, 0x6b, 0x0d, 0x95, + 0x16, 0x7d, 0xc4, 0x2b, 0xa0, 0x65, 0xb2, 0x99, 0x04, 0x36, 0x75, 0x80, + 0x6b, 0xac, 0x4a, 0xf3, 0x1b, 0x90, 0x49, 0x78, 0x2f, 0xa2, 0x96, 0x4f, + 0x2a, 0x20, 0x25, 0x29, 0x04, 0xc6, 0x74, 0xc0, 0xd0, 0x31, 0xcd, 0x8f, + 0x31, 0x38, 0x95, 0x16, 0xba, 0xa8, 0x33, 0xb8, 0x43, 0xf1, 0xb1, 0x1f, + 0xc3, 0x30, 0x7f, 0xa2, 0x79, 0x31, 0x13, 0x3d, 0x2d, 0x36, 0xf8, 0xe3, + 0xfc, 0xf2, 0x33, 0x6a, 0xb9, 0x39, 0x31, 0xc5, 0xaf, 0xc4, 0x8d, 0x0d, + 0x1d, 0x64, 0x16, 0x33, 0xaa, 0xfa, 0x84, 0x29, 0xb6, 0xd4, 0x0b, 0xc0, + 0xd8, 0x7d, 0xc3, 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, + 0x7d, 0x30, 0x82, 0x01, 0x79, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, + 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, + 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, + 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x7f, 0x06, 0x08, 0x2b, 0x06, 0x01, + 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x73, 0x30, 0x71, 0x30, 0x32, 0x06, + 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x26, 0x68, + 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x69, 0x73, 0x72, 0x67, 0x2e, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x69, 0x64, 0x2e, 0x6f, 0x63, 0x73, 0x70, 0x2e, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, 0x2e, 0x63, 0x6f, + 0x6d, 0x30, 0x3b, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, + 0x02, 0x86, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x61, 0x70, + 0x70, 0x73, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x6f, 0x6f, 0x74, 0x73, 0x2f, 0x64, + 0x73, 0x74, 0x72, 0x6f, 0x6f, 0x74, 0x63, 0x61, 0x78, 0x33, 0x2e, 0x70, + 0x37, 0x63, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, + 0x16, 0x80, 0x14, 0xc4, 0xa7, 0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, + 0xe1, 0x4b, 0x90, 0x75, 0xff, 0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, + 0x54, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x4d, 0x30, 0x4b, 0x30, 0x08, + 0x06, 0x06, 0x67, 0x81, 0x0c, 0x01, 0x02, 0x01, 0x30, 0x3f, 0x06, 0x0b, + 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xdf, 0x13, 0x01, 0x01, 0x01, 0x30, + 0x30, 0x30, 0x2e, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, + 0x01, 0x16, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x70, + 0x73, 0x2e, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x78, 0x31, 0x2e, 0x6c, 0x65, + 0x74, 0x73, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2e, 0x6f, 0x72, + 0x67, 0x30, 0x3c, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x35, 0x30, 0x33, + 0x30, 0x31, 0xa0, 0x2f, 0xa0, 0x2d, 0x86, 0x2b, 0x68, 0x74, 0x74, 0x70, + 0x3a, 0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x44, 0x53, 0x54, + 0x52, 0x4f, 0x4f, 0x54, 0x43, 0x41, 0x58, 0x33, 0x43, 0x52, 0x4c, 0x2e, + 0x63, 0x72, 0x6c, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, + 0x04, 0x14, 0xa8, 0x4a, 0x6a, 0x63, 0x04, 0x7d, 0xdd, 0xba, 0xe6, 0xd1, + 0x39, 0xb7, 0xa6, 0x45, 0x65, 0xef, 0xf3, 0xa8, 0xec, 0xa1, 0x30, 0x0d, + 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, + 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0xdd, 0x33, 0xd7, 0x11, 0xf3, 0x63, + 0x58, 0x38, 0xdd, 0x18, 0x15, 0xfb, 0x09, 0x55, 0xbe, 0x76, 0x56, 0xb9, + 0x70, 0x48, 0xa5, 0x69, 0x47, 0x27, 0x7b, 0xc2, 0x24, 0x08, 0x92, 0xf1, + 0x5a, 0x1f, 0x4a, 0x12, 0x29, 0x37, 0x24, 0x74, 0x51, 0x1c, 0x62, 0x68, + 0xb8, 0xcd, 0x95, 0x70, 0x67, 0xe5, 0xf7, 0xa4, 0xbc, 0x4e, 0x28, 0x51, + 0xcd, 0x9b, 0xe8, 0xae, 0x87, 0x9d, 0xea, 0xd8, 0xba, 0x5a, 0xa1, 0x01, + 0x9a, 0xdc, 0xf0, 0xdd, 0x6a, 0x1d, 0x6a, 0xd8, 0x3e, 0x57, 0x23, 0x9e, + 0xa6, 0x1e, 0x04, 0x62, 0x9a, 0xff, 0xd7, 0x05, 0xca, 0xb7, 0x1f, 0x3f, + 0xc0, 0x0a, 0x48, 0xbc, 0x94, 0xb0, 0xb6, 0x65, 0x62, 0xe0, 0xc1, 0x54, + 0xe5, 0xa3, 0x2a, 0xad, 0x20, 0xc4, 0xe9, 0xe6, 0xbb, 0xdc, 0xc8, 0xf6, + 0xb5, 0xc3, 0x32, 0xa3, 0x98, 0xcc, 0x77, 0xa8, 0xe6, 0x79, 0x65, 0x07, + 0x2b, 0xcb, 0x28, 0xfe, 0x3a, 0x16, 0x52, 0x81, 0xce, 0x52, 0x0c, 0x2e, + 0x5f, 0x83, 0xe8, 0xd5, 0x06, 0x33, 0xfb, 0x77, 0x6c, 0xce, 0x40, 0xea, + 0x32, 0x9e, 0x1f, 0x92, 0x5c, 0x41, 0xc1, 0x74, 0x6c, 0x5b, 0x5d, 0x0a, + 0x5f, 0x33, 0xcc, 0x4d, 0x9f, 0xac, 0x38, 0xf0, 0x2f, 0x7b, 0x2c, 0x62, + 0x9d, 0xd9, 0xa3, 0x91, 0x6f, 0x25, 0x1b, 0x2f, 0x90, 0xb1, 0x19, 0x46, + 0x3d, 0xf6, 0x7e, 0x1b, 0xa6, 0x7a, 0x87, 0xb9, 0xa3, 0x7a, 0x6d, 0x18, + 0xfa, 0x25, 0xa5, 0x91, 0x87, 0x15, 0xe0, 0xf2, 0x16, 0x2f, 0x58, 0xb0, + 0x06, 0x2f, 0x2c, 0x68, 0x26, 0xc6, 0x4b, 0x98, 0xcd, 0xda, 0x9f, 0x0c, + 0xf9, 0x7f, 0x90, 0xed, 0x43, 0x4a, 0x12, 0x44, 0x4e, 0x6f, 0x73, 0x7a, + 0x28, 0xea, 0xa4, 0xaa, 0x6e, 0x7b, 0x4c, 0x7d, 0x87, 0xdd, 0xe0, 0xc9, + 0x02, 0x44, 0xa7, 0x87, 0xaf, 0xc3, 0x34, 0x5b, 0xb4, 0x42 + }, + 1174 + } +}; + + +#define SECRET_GSM_ROOT_SIZE (sizeof(SECRET_GSM_ROOT_CERTS)/sizeof(SECRET_GSM_ROOT_CERTS[0])) diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SendSMS/SendSMS.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SendSMS/SendSMS.ino new file mode 100644 index 00000000..7f21b68a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SendSMS/SendSMS.ino @@ -0,0 +1,100 @@ +/* + SMS sender + + This sketch, for the MKR GSM 1400 board,sends an SMS message + you enter in the Serial Monitor. Connect your Arduino with the + GSM shield and SIM card, open the Serial Monitor, and wait for + the "READY" message to appear in the monitor. Next, type a + message to send and press "return". Make sure the serial + monitor is set to send a newline when you press return. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card that can send SMS + + created 25 Feb 2012 + by Tom Igoe +*/ + +// Include the GSM library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; +GSM_SMS sms; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("SMS Messages Sender"); + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("GSM initialized"); +} + +void loop() { + + Serial.print("Enter a mobile number: "); + char remoteNum[20]; // telephone number to send SMS + readSerial(remoteNum); + Serial.println(remoteNum); + + // SMS text + Serial.print("Now, enter SMS content: "); + char txtMsg[200]; + readSerial(txtMsg); + Serial.println("SENDING"); + Serial.println(); + Serial.println("Message:"); + Serial.println(txtMsg); + + // send the message + sms.beginSMS(remoteNum); + sms.print(txtMsg); + sms.endSMS(); + Serial.println("\nCOMPLETE!\n"); +} + +/* + Read input serial + */ +int readSerial(char result[]) { + int i = 0; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + result[i] = '\0'; + Serial.flush(); + return 0; + } + if (inChar != '\r') { + result[i] = inChar; + i++; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SendSMS/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SendSMS/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/SendSMS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/BandManagement/BandManagement.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/BandManagement/BandManagement.ino new file mode 100644 index 00000000..2777ccdc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/BandManagement/BandManagement.ino @@ -0,0 +1,116 @@ +/* + Band Management + + This sketch, for the MKR GSM 1400 board, checks the band + currently configured in the modem and allows you to change + it. + + Please check http://www.worldtimezone.com/gsm.html + Usual configurations: + Europe, Africa, Middle East: E-GSM(900)+DCS(1800) + USA, Canada, South America: GSM(850)+PCS(1900) + Mexico: PCS(1900) + Brazil: GSM(850)+E-GSM(900)+DCS(1800)+PCS(1900) + + + Circuit: + * MKR GSM 1400 board + * Antenna + + created 12 June 2012 + by Javier Zorzano, Scott Fitzgerald +*/ + +// libraries +#include + +// initialize the library instance +GSMBand band; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Beginning the band manager restarts the modem + Serial.println("Restarting modem..."); + band.begin(); + Serial.println("Modem restarted."); + +}; + + +void loop() { + // Get current band + String bandName = band.getBand(); // Get and print band name + Serial.print("Current band:"); + Serial.println(bandName); + Serial.println("Want to change the band you’re on?"); + String newBandName; + newBandName = askUser(); + // Tell the user what we are about to do… + Serial.print("\nConfiguring band "); + Serial.println(newBandName); + // Change the band + bool operationSuccess; + operationSuccess = band.setBand(newBandName); + // Tell the user if the operation was OK + if (operationSuccess) { + Serial.println("Success"); + } else { + Serial.println("Error while changing band"); + } + + if (operationSuccess) { + while (true); + } +} + +// This function offers the user different options +// through the Serial interface +// The user selects one +String askUser() { + String newBand; + Serial.println("Select band:"); + // Print the different options + Serial.println("1 : E-GSM(900)"); + Serial.println("2 : DCS(1800)"); + Serial.println("3 : PCS(1900)"); + Serial.println("4 : E-GSM(900)+DCS(1800) ex: Europe"); + Serial.println("5 : GSM(850)+PCS(1900) Ex: USA, South Am."); + Serial.println("6 : GSM800(800)+GSM(850)+E-GSM(900)+PCS(1900)"); + Serial.println("7 : UMTS(2100)"); + Serial.println("8 : GSM(850)+E-GSM(900)+PCS(1900)+UMTS(2100)"); + + // Empty the incoming buffer + while (Serial.available()) { + Serial.read(); + } + + // Wait for an answer, just look at the first character + while (!Serial.available()); + char c = Serial.read(); + if (c == '1') { + newBand = GSM_MODE_EGSM; + } else if (c == '2') { + newBand = GSM_MODE_DCS; + } else if (c == '3') { + newBand = GSM_MODE_PCS; + } else if (c == '4') { + newBand = GSM_MODE_EGSM_DCS; + } else if (c == '5') { + newBand = GSM_MODE_GSM850_PCS; + } else if (c == '6') { + newBand = GSM_MODE_GSM850_EGSM_DCS_PCS; + } else if (c == '7') { + newBand = GSM_MODE_UMTS; + } else if (c == '8') { + newBand = GSM_MODE_GSM850_EGSM_PCS_UMTS; + } else { + newBand = "GSM_MODE_UNDEFINED"; + } + + return newBand; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino new file mode 100644 index 00000000..292e3252 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino @@ -0,0 +1,130 @@ +/* + Radio Access Technology selection for Arduino MKR GSM 1400 + + This sketch allows you to select your preferred Radio Access + Technology (RAT). + + You can choose among 2G, 3G/UTMS or a combination of both. + + The chosen configuration will be saved to the modem's internal memory + and will be preserved through MKR GSM 1400 sketch uploads. + + In order to change the RAT, you will need to run this sketch again. + + Circuit: + - MKR GSM 1400 board + - Antenna + - SIM card + + Created 19 August 2019 + by Riccardo Rizzo + +*/ + +#include + + +void setup() { + Serial.begin(9600); + while (!Serial); + + MODEM.begin(); + while (!MODEM.noop()); + + for (int i = 0; i < 80; i++) Serial.print("*"); + Serial.println(); + Serial.println("This sketch allows you to select your preferred"); + Serial.println("GSM Radio Access Technology (RAT)."); + Serial.println(); + Serial.println("You can choose among 2G, 3G/UMTS or a combination of both."); + Serial.println(); + Serial.println("The chosen configuration will be saved to the modem's internal memory"); + Serial.println("and will be preserved through MKR GSM 1400 sketch uploads."); + Serial.println(); + Serial.println("In order to change the RAT, you will need to run this sketch again."); + for (int i = 0; i < 80; i++) Serial.print("*"); + + Serial.println(); + Serial.println(); + Serial.println("Please choose your Radio Access Technology:"); + Serial.println(); + Serial.println(" 0 - 2G only"); + Serial.println(" 1 - 3G/UMTS only"); + Serial.println(" 2 - 2G preferred, 3G/UMTS as failover"); + Serial.println(" 3 - 3G/UMTS preferred, 2G as failover (default)"); + Serial.println(); +} + +void loop() { + String uratChoice; + + Serial.print("> "); + + Serial.setTimeout(-1); + while (Serial.available() == 0); + String uratInput = Serial.readStringUntil('\n'); + uratInput.trim(); + int urat = uratInput.toInt(); + Serial.println(urat); + + switch (urat) { + case 0: + uratChoice = "0"; + break; + case 1: + uratChoice = "2"; + break; + case 2: + uratChoice = "1,0"; + break; + case 3: + uratChoice = "1,2"; + break; + default: + Serial.println("Invalid input. Please, retry."); + return; + } + + setRAT(uratChoice); + apply(); + + Serial.println(); + Serial.println("Radio Access Technology selected."); + Serial.println("Now you can upload your 2G or 3G application sketch."); + while (true); +} + +bool setRAT(String choice) +{ + String response; + + Serial.print("Disconnecting from network: "); + MODEM.sendf("AT+COPS=2"); + MODEM.waitForResponse(10000); + Serial.println("done."); + + Serial.print("Setting Radio Access Technology: "); + MODEM.sendf("AT+URAT=%s", choice.c_str()); + MODEM.waitForResponse(10000, &response); + Serial.println("done."); + + return true; +} + +bool apply() +{ + Serial.print("Applying changes and saving configuration: "); + MODEM.reset(); + delay(5000); + Serial.println("Modem restart"); + MODEM.begin(true); + + do { + delay(1000); + MODEM.noop(); + } while (MODEM.waitForResponse(1000) != 1); + + Serial.println("done."); + + return true; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/FileUtilsHttpDownload.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/FileUtilsHttpDownload.ino new file mode 100644 index 00000000..baecb933 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/FileUtilsHttpDownload.ino @@ -0,0 +1,217 @@ +/* + Download a large file and store it into the GSM module filesystem. + + This sketch connects to a website through a MKR GSM 1400 board and + downloads a large file and stores it into the filesystem of the GSM + module. + + The file is processed in blocks of 512 bytes in order to save RAM. + A block of data is read from the GSM module and the appended to a + file created by the sketch. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + created 19 June 2020 + by Giampaolo Mancini +*/ + +// libraries +#include + +GSMFileUtils fileUtils(false); + +#include "Helpers.h" + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMClient client; +GPRS gprs; +GSM gsmAccess; + +// URL, path and port (for example: example.org) + +void setup() +{ + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + + fileUtils.begin(); + + // List files on the GSM module's filesystem + auto numberOfFiles = fileUtils.fileCount(); + Serial.print("Number of Files: "); + Serial.println(numberOfFiles); + Serial.println(); + + printFiles(fileUtils); + + auto server = promptAndReadLine("Please, enter server name:", "arduino.cc"); + auto port = promptAndReadInt("Please, enter server port:", 80); + auto filename = promptAndReadLine("Please, enter file name:", "asciilogo.txt"); + auto filesize = promptAndReadInt("Please, enter file size:", 2263); + Serial.println("Connecting..."); + + // connection state + bool connected = false; + + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + // if you get a connection, report back via serial: + if (client.connect(server.c_str(), port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET /"); + client.print(filename); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("Connection failed"); + } + + // Download and store block-by-block + storeFileBuffered(filename, filesize); + + auto updateBinSize = fileUtils.listFile(filename); + Serial.print(filename); + Serial.print(" downloaded size: "); + Serial.println(updateBinSize); + + numberOfFiles = fileUtils.fileCount(); + Serial.print("Number of Files: "); + Serial.println(numberOfFiles); + Serial.println(); + + printFiles(fileUtils); + +} + +void loop() +{ + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char r = client.read(); + if (r < 16) + Serial.print(0); + Serial.print(r, HEX); + + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} + +void storeFileBuffered(String filename, uint32_t totalLen) +{ + Serial.print("Ready to download \""); + Serial.print(filename); + Serial.print("\" - len: "); + Serial.print(totalLen); + Serial.println(" bytes."); + + constexpr uint32_t len { 512 }; + + uint32_t cycles = totalLen / len; + uint32_t spares = totalLen % len; + + int totalRead { 0 }; + + fileUtils.deleteFile(filename); + + Serial.print("Saving file in "); + Serial.print(cycles + 1); + Serial.print(" blocks. ["); + Serial.print(cycles); + Serial.print(' '); + Serial.print(len); + Serial.print(" -bytes blocks and "); + Serial.print(spares); + Serial.println(" bytes]."); + + bool is_header_complete = false; + String http_header; + + // Skip the HTTP header + while (!is_header_complete) { + while (client.available()) { + const char c = client.read(); + http_header += c; + if (http_header.endsWith("\r\n\r\n")) { + Serial.println("Header Complete"); + is_header_complete = true; + break; + } + } + } + + // Define download and save lambda + auto downloadAndSaveTrunk = [filename](uint32_t len) { + char buf[len] { 0 }; + uint32_t written { 0 }; + + if (client.available()) + written = client.readBytes(buf, len); + + fileUtils.appendFile(filename, buf, written); + return written; + }; + + // Define wrapper function + auto saveTrunk = [&totalRead, downloadAndSaveTrunk](size_t iter, uint32_t len) { + Serial.print("Block "); + if (iter < 10) Serial.print(' '); if (iter < 100) Serial.print(' '); + Serial.print(iter); + + totalRead += downloadAndSaveTrunk(len); + + Serial.print(": "); + Serial.print(len); + Serial.print(" - "); + Serial.print(totalRead); + Serial.println(); + }; + + // Download and save complete trunks + spares + for (auto c = 0; c <= cycles; c++) + saveTrunk(c, len); + + Serial.println(); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/Helpers.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/Helpers.h new file mode 100644 index 00000000..f4b0fb70 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/Helpers.h @@ -0,0 +1,124 @@ +#pragma once +#include + +String readLine() +{ + String line; + + while (1) + { + if (Serial.available()) + { + char c = Serial.read(); + + if (c == '\r') + { + // ignore + } + else if (c == '\n') + { + break; + } + + line += c; + } + } + + line.trim(); + + return line; +} + +String promptAndReadLine(const char* prompt, const char* defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + + if (s.length() == 0) { + s = defaultValue; + } + + Serial.println(s); + + return s; +} + +int promptAndReadInt(const char* prompt, const int defaultValue) { + Serial.print(prompt); + Serial.print(" ["); + Serial.print(defaultValue); + Serial.print("]: "); + + String s = readLine(); + int r; + + if (s.length() == 0) { + r = defaultValue; + } else { + r = s.toInt(); + } + + Serial.println(r); + + return r; +} + +String promptAndReadLine(const char *prompt) +{ + Serial.print(prompt); + String s = readLine(); + Serial.println(s); + + return s; +} + +int promptAndReadInt(const char *prompt) +{ + Serial.print(prompt); + String s = readLine(); + Serial.println(s); + + return s.toInt(); +} + + +String toHex(char c) +{ + String hex; + + hex = "0x"; + if (c < 16) + hex += "0"; + hex += String(c, HEX); + + return hex; +} + +void printHex(const String& buf, const unsigned int cols) +{ + for (size_t i = 0; i < buf.length(); i++) { + String hex = toHex(buf[i]); + hex += " "; + Serial.print(hex); + if (i % cols == (cols - 1)) + Serial.println(); + } + Serial.println(); +} + +void printHex(const uint8_t* buf, const size_t len, const unsigned int cols) +{ + for (size_t i = 0; i < len; i++) { + // Serial.print("0x"); + if (buf[i] < 16) + Serial.print(0); + Serial.print(buf[i], HEX); + // if (i != len - 1) Serial.print(", "); + if (i % cols == (cols - 1)) + Serial.println(); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/arduino_secrets.h new file mode 100644 index 00000000..e1c4da91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsHttpDownload/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/Config.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/Config.h new file mode 100644 index 00000000..b70769d7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/Config.h @@ -0,0 +1,68 @@ +#pragma once + +#include + + +// Make the struct Printable to allow Serial.print-ing +struct Config : public Printable { + String deviceId; + int timestamp; + + String toJson() + { + JSONVar conf; + + conf["deviceId"] = deviceId; + conf["timestamp"] = timestamp; + + return JSON.stringify(conf); + } + + bool fromJSON(const String buf) + { + auto conf = JSON.parse(buf); + + if (!checkProperty(conf, "deviceId", "string")) + return false; + + if (!checkProperty(conf, "timestamp", "number")) + return false; + + deviceId = conf["deviceId"]; + timestamp = int { conf["timestamp"] }; + + return true; + } + + virtual size_t printTo(Print& p) const + { + size_t written { 0 }; + + written += p.print("DeviceId: "); + written += p.println(deviceId); + written += p.print("Timestamp: "); + written += p.println(timestamp); + + return written; + } + +private: + bool checkProperty(JSONVar json, String property, String type) + { + if (!json.hasOwnProperty(property)) { + Serial.print(property); + Serial.println(" not found"); + return false; + } + + if (JSON.typeof(json[property]) != type) { + Serial.print(property); + Serial.print(" != \""); + Serial.print(type); + Serial.println("\""); + return false; + } + + return true; + } +}; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/FileUtilsJsonFile.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/FileUtilsJsonFile.ino new file mode 100644 index 00000000..8c6ac1c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsJsonFile/FileUtilsJsonFile.ino @@ -0,0 +1,121 @@ +/* + Manage JSON configurations via GSM module filesystem. + + This sketch demonstrates how to use the internal filesystem + of the GSM module to store and retrieve data and configurations + both as JSON objects or C++ structs. + + Circuit: + * MKR GSM 1400 board + + created 19 June 2020 + by Giampaolo Mancini +*/ + +#include +#include + +#include "Config.h" + +GSMFileUtils fileUtils; + +void setup() +{ + Serial.begin(9600); + + while (!Serial) + ; + + Serial.println("Store and Retrieve JSON data to GSM module storage."); + Serial.println(); + + fileUtils.begin(); + + simpleDemo(); + structDemo(); + + while (true) + ; +} + +void loop() +{ +} + +void simpleDemo() +{ + + Serial.println(); + Serial.println("========================"); + Serial.println("Running simple JSON demo"); + Serial.println(); + + JSONVar myObject; + + myObject["hello"] = "world"; + myObject["true"] = true; + myObject["x"] = 42; + + String jsonString = JSON.stringify(myObject); + + Serial.println("Saving JSON file (test.json): "); + Serial.println(jsonString); + Serial.println(); + fileUtils.downloadFile("test.json", jsonString); + + printFiles(fileUtils); + Serial.println(); + + String jsonData; + Serial.println("Reading JSON file (test.json): "); + fileUtils.readFile("test.json", &jsonData); + + Serial.println("File contents:"); + Serial.println(jsonData); + Serial.println(); + + Serial.println("Parsing JSON contents:"); + JSONVar myConf = JSON.parse(jsonData); + Serial.print("myConf[\"hello\"]: "); + Serial.println(myConf["hello"]); + Serial.print("myConf[\"true\"]: "); + Serial.println(myConf["true"]); + Serial.print("myConf[\"x\"]: "); + Serial.println(myConf["x"]); +} + +void structDemo() +{ + GSMModem modem; + + Serial.println(); + Serial.println("========================"); + Serial.println("Running Configuration via struct and JSON demo"); + Serial.println(); + Serial.println("Creating configuration struct:"); + + Config conf; + conf.deviceId = modem.getICCID(); + conf.timestamp = millis(); + + Serial.print(conf); + + fileUtils.downloadFile("conf.json", conf.toJson()); + + Serial.println(); + printFiles(fileUtils); + Serial.println(); + + Serial.println("Reading configuration file:"); + + String jsonConf; + fileUtils.readFile("conf.json", &jsonConf); + Serial.println(jsonConf); + Serial.println(); + + Serial.println("Reading configuration struct:"); + Config newConf; + newConf.fromJSON(jsonConf); + + Serial.print(newConf); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsReadBlock/FileUtilsReadBlock.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsReadBlock/FileUtilsReadBlock.ino new file mode 100644 index 00000000..74da10b6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/FileUtilsReadBlock/FileUtilsReadBlock.ino @@ -0,0 +1,66 @@ +/* + Read large files block-by-block from the GSM module filesystem. + + This sketch allows you to read large (max 2.5 MB) files from the + module's internal filesystem using successive block-by-block reads. + + The contents of the file are printed to the Serial port as an + hexadecimal string which can be later converted to the original + content using an external tool, such as 'xxd', eg. + + 'xxd -p -r sketch_output.txt data.bin' + + Circuit: + - MKR GSM 1400 board + + Created 19 June 2020 + by Giampaolo Mancini + +*/ + +#include + +GSMFileUtils fileUtils(false); + +// An existing file +constexpr char* filename { "update.bin" }; + +// Read block size +constexpr unsigned int blockSize { 512 }; + +void setup() +{ + Serial.begin(115200); + while (!Serial) + ; + + fileUtils.begin(); + + auto size = fileUtils.listFile(filename); + auto cycles = (size / blockSize) + 1; + + uint32_t totalRead { 0 }; + + for (auto i = 0; i < cycles; i++) { + uint8_t block[blockSize] { 0 }; + auto read = fileUtils.readBlock(filename, i * blockSize, blockSize, block); + totalRead += read; + for (auto j = 0; j < read; j++) { + if (block[j] < 16) + Serial.print(0); + Serial.print(block[j], HEX); + } + Serial.println(); + } + + if (totalRead != size) { + Serial.print("ERROR - File size: "); + Serial.print(size); + Serial.print(" Bytes read: "); + Serial.println(totalRead); + } +} + +void loop() +{ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino new file mode 100644 index 00000000..2dc439d1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/GsmScanNetworks.ino @@ -0,0 +1,90 @@ +/* + + GSM Scan Networks + + This example prints out the IMEI number of the modem, + then checks to see if it's connected to a carrier. If so, + it prints the phone number associated with the card. + Then it scans for nearby networks and prints out their signal strengths. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card + + Created 8 Mar 2012 + by Tom Igoe, implemented by Javier Carazo + Modified 4 Feb 2013 + by Scott Fitzgerald +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; // include a 'true' parameter to enable debugging +GSMScanner scannerNetworks; +GSMModem modemTest; + +// Save data variables +String IMEI = ""; + +// Serial Monitor result messages +String errortext = "ERROR"; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("GSM networks scanner"); + scannerNetworks.begin(); + + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (gsmAccess.begin(PINNUMBER) == GSM_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + // get modem parameters + // IMEI, modem unique identifier + Serial.print("Modem IMEI: "); + IMEI = modemTest.getIMEI(); + IMEI.replace("\n", ""); + if (IMEI != NULL) { + Serial.println(IMEI); + } +} + +void loop() { + // scan for existing networks, displays a list of networks + Serial.println("Scanning available networks. May take some seconds."); + Serial.println(scannerNetworks.readNetworks()); + + // currently connected carrier + Serial.print("Current carrier: "); + Serial.println(scannerNetworks.getCurrentCarrier()); + + // returns strength and BER + // signal strength in 0-31 scale. 31 means power > 51 dBm + // BER is the Bit Error Rate. 0-7 scale. 99=not detectable + Serial.print("Signal Strength: "); + Serial.print(scannerNetworks.getSignalStrength()); + Serial.println(" [0-31]"); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/GsmScanNetworks/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/HttpUtilsGet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/HttpUtilsGet.ino new file mode 100644 index 00000000..dbc011bb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/HttpUtilsGet.ino @@ -0,0 +1,88 @@ +/* + This sketch shows how to use the HTTP command to + make an HTTP request and store the result in the + SARA-U201 internal storage + + Circuit: + - MKR GSM 1400 board + + Created 3 September 2020 + by Riccardo Rizzo + +*/ + +#include +#include +#include "arduino_secrets.h" + + +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMHttpUtils httpClient; +GPRS gprs; +GSM gsmAccess; + +GSMFileUtils fileUtils(false); + +// URL, path and port (for example: example.org) +char server[] = "example.org"; +char path[] = "/"; +int port = 80; // port 80 is the default for HTTP + +// An existing file +constexpr char* filename { "get.ffs" }; + +// Read block size +constexpr unsigned int blockSize { 512 }; + + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + bool connected = false; + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + fileUtils.begin(false); + + // configure all the parameters to make the http request + httpClient.configServer(server, port); + httpClient.get(path, filename); +} + +void loop() { + if (httpClient.responseStatus()) { + Serial.println("received"); + String fileList[10]; + auto size = fileUtils.listFiles(fileList); + for (int i = 0; i < size && i <10; i++) { + if (fileList[i] == filename) { + Serial.print("file found: "); + Serial.println(fileList[i]); + } + } + while (1); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/arduino_secrets.h new file mode 100644 index 00000000..dd5d8139 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsGet/arduino_secrets.h @@ -0,0 +1,5 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/HttpUtilsSSLGet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/HttpUtilsSSLGet.ino new file mode 100644 index 00000000..ad766105 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/HttpUtilsSSLGet.ino @@ -0,0 +1,97 @@ +/* + This sketch shows how to use the HTTP command to + make an HTTP request to the HTTPS end point and store + the result in the SARA-U201 internal storage + + Circuit: + - MKR GSM 1400 board + + Created 3 September 2020 + by Riccardo Rizzo + +*/ + +#include +#include +#include "arduino_secrets.h" + + +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// initialize the library instance +GSMHttpUtils httpClient; +GPRS gprs; +GSM gsmAccess; + +GSMFileUtils fileUtils(false); + +// URL, path and port (for example: example.org) +char server[] = "google.com"; +char path[] = "/"; +int port = 443; // port 80 is the default for HTTP + +// An existing file +constexpr char* filename { "get.ffs" }; + + +// Read block size +constexpr unsigned int blockSize { 512 }; + + +const long interval = 1000; +unsigned long previousMillis = 0; + +int count = 0; + +void readFile(); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + bool connected = false; + // After starting the modem with GSM.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + fileUtils.begin(false); + + httpClient.enableSSL(); + httpClient.configServer(server, port); + httpClient.get(path, filename); +} + +void loop() { + if (httpClient.responseStatus()) { + Serial.println("received"); + + readFile(); + while (1); + } +} + +void readFile() { + String fileList[10]; + auto size = fileUtils.listFiles(fileList); + for (int i = 0; i < size && i <10; i++) { + if (fileList[i] == filename) { + Serial.print("file found: "); + Serial.println(fileList[i]); + } + + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/arduino_secrets.h new file mode 100644 index 00000000..b0076aac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/HttpUtilsSSLGet/arduino_secrets.h @@ -0,0 +1,311 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + + +// Replace with your client.crt certificate in DER format +const uint8_t SECRET_CERT[] = { + /*0x30, 0x82, 0x03, 0x41, 0x30, 0x82, 0x02, 0x29, 0x02, 0x09, 0x00, 0xc2, + 0x68, 0x43, 0x0c, 0x54, 0xae, 0xfe, 0x3a, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x62, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x54, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x05, + 0x49, 0x74, 0x61, 0x6c, 0x79, 0x31, 0x0e, 0x30, 0x0c, 0x06, 0x03, 0x55, + 0x04, 0x07, 0x0c, 0x05, 0x54, 0x75, 0x72, 0x69, 0x6e, 0x31, 0x10, 0x30, + 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x07, 0x41, 0x72, 0x64, 0x75, + 0x69, 0x6e, 0x6f, 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0b, + 0x0c, 0x03, 0x4d, 0x6e, 0x78, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, + 0x04, 0x03, 0x0c, 0x0a, 0x63, 0x6c, 0x65, 0x61, 0x6e, 0x69, 0x75, 0x6d, + 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x36, 0x31, 0x36, + 0x31, 0x35, 0x32, 0x39, 0x30, 0x31, 0x5a, 0x17, 0x0d, 0x32, 0x31, 0x30, + 0x36, 0x31, 0x36, 0x31, 0x35, 0x32, 0x39, 0x30, 0x31, 0x5a, 0x30, 0x63, + 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x49, + 0x54, 0x31, 0x11, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x08, + 0x50, 0x69, 0x65, 0x64, 0x6d, 0x6f, 0x6e, 0x74, 0x31, 0x0e, 0x30, 0x0c, + 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x05, 0x54, 0x75, 0x72, 0x69, 0x6e, + 0x31, 0x0c, 0x30, 0x0a, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x03, 0x4d, + 0x6e, 0x78, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x0c, + 0x07, 0x41, 0x72, 0x64, 0x75, 0x69, 0x6e, 0x6f, 0x31, 0x11, 0x30, 0x0f, + 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x08, 0x4d, 0x4b, 0x52, 0x47, 0x53, + 0x4d, 0x30, 0x31, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xb6, 0xb7, 0xa2, 0x73, 0x9e, 0x8b, 0xcc, 0x7f, 0x55, 0xb3, 0xb4, 0xad, + 0xfe, 0x6a, 0xbc, 0xa7, 0xe5, 0xec, 0x02, 0xd0, 0x4b, 0x25, 0xa4, 0xd3, + 0xc4, 0x33, 0x37, 0xa7, 0x76, 0xdf, 0xa3, 0x9f, 0xdd, 0x42, 0x3e, 0xb5, + 0xe2, 0xbc, 0x89, 0xe4, 0x18, 0x02, 0xb6, 0x62, 0xe4, 0x3b, 0xa6, 0x74, + 0x76, 0xf8, 0x73, 0xe7, 0x80, 0xea, 0x5d, 0x93, 0x9d, 0x61, 0x2a, 0x24, + 0x06, 0x4c, 0x6b, 0x68, 0xea, 0x63, 0x1d, 0x3a, 0xce, 0x8b, 0x31, 0x05, + 0x72, 0xe9, 0xdc, 0xce, 0x05, 0x8c, 0x7a, 0xc1, 0xf5, 0xd6, 0xe1, 0xd0, + 0x6d, 0x73, 0x4e, 0xc1, 0x8a, 0x16, 0x49, 0x4d, 0xac, 0x21, 0xfb, 0x2d, + 0x12, 0xdd, 0x1e, 0xef, 0x9b, 0xb3, 0x6d, 0x20, 0x69, 0xfb, 0xaa, 0x3c, + 0x2c, 0x8f, 0x0d, 0x7c, 0x09, 0x1c, 0x1a, 0xa5, 0x23, 0x83, 0x98, 0x10, + 0xf4, 0x0c, 0x78, 0xa4, 0xa0, 0x4b, 0x1a, 0x71, 0x52, 0x4b, 0xb3, 0x8b, + 0x4c, 0x29, 0xfe, 0x6f, 0x24, 0x88, 0x7e, 0xd6, 0xf0, 0x6a, 0x2c, 0x3c, + 0x6c, 0xad, 0x54, 0x0c, 0xb6, 0x7b, 0xa4, 0x76, 0x38, 0xbf, 0x35, 0xc6, + 0x66, 0xde, 0x6a, 0x92, 0x43, 0x26, 0x31, 0xae, 0x76, 0xb5, 0xf6, 0x15, + 0x87, 0x02, 0x37, 0x7e, 0x7b, 0x92, 0xda, 0x3f, 0x45, 0x1e, 0x89, 0xb7, + 0x26, 0xb3, 0x8d, 0x3c, 0xf6, 0x49, 0x25, 0xe9, 0x1e, 0x52, 0x6f, 0x40, + 0x2e, 0xb6, 0x7d, 0x5c, 0x2a, 0x8a, 0x9c, 0x7d, 0x2c, 0x09, 0xce, 0xde, + 0x73, 0x5d, 0x3b, 0x7d, 0x4f, 0x3f, 0x4b, 0xdc, 0xeb, 0x8b, 0x93, 0xd1, + 0xc2, 0xf3, 0x29, 0x08, 0x98, 0x06, 0x8c, 0x46, 0x38, 0xe1, 0xd5, 0x30, + 0xc1, 0xf0, 0x3c, 0x74, 0x58, 0xf0, 0x20, 0x8b, 0xea, 0x30, 0x43, 0xd8, + 0x3d, 0x19, 0xc4, 0xd1, 0x04, 0xc8, 0xe5, 0x76, 0x31, 0x36, 0x4a, 0xae, + .. .. .. .. .. .. .. .. .. .. .. .. + 0xd3, 0xb2, 0x75, 0x2b, 0x85, 0x71, 0x02, 0x9a, 0x51, 0x38, 0x08, 0x61, + 0xf8, 0x8b, 0x8b, 0x36, 0xf5, 0x10, 0x6e, 0xd9, 0xda, 0xf5, 0x3a, 0xf1, + 0xf1, 0x6f, 0xc4, 0xd7, 0x52, 0x6f, 0x22, 0x38, 0x8a, 0xff, 0x75, 0x82, + 0x93, 0x94, 0xc9, 0x45, 0xcf, 0xa3, 0x23, 0x04, 0x6f, 0x3a, 0x58, 0xe1, + 0xca, 0xfa, 0xa8, 0x1f, 0xd3, 0x87, 0x6e, 0xcb, 0xe3*/ +}; + +// Replace with your client.key certificate in DER format +uint8_t SECRET_KEY[] = { + /*0x30, 0x82, 0x04, 0xa4, 0x02, 0x01, 0x00, 0x02, 0x82, 0x01, 0x01, 0x00, + 0xb6, 0xb7, 0xa2, 0x73, 0x9e, 0x8b, 0xcc, 0x7f, 0x55, 0xb3, 0xb4, 0xad, + 0xfe, 0x6a, 0xbc, 0xa7, 0xe5, 0xec, 0x02, 0xd0, 0x4b, 0x25, 0xa4, 0xd3, + 0xc4, 0x33, 0x37, 0xa7, 0x76, 0xdf, 0xa3, 0x9f, 0xdd, 0x42, 0x3e, 0xb5, + 0xe2, 0xbc, 0x89, 0xe4, 0x18, 0x02, 0xb6, 0x62, 0xe4, 0x3b, 0xa6, 0x74, + 0x76, 0xf8, 0x73, 0xe7, 0x80, 0xea, 0x5d, 0x93, 0x9d, 0x61, 0x2a, 0x24, + 0x06, 0x4c, 0x6b, 0x68, 0xea, 0x63, 0x1d, 0x3a, 0xce, 0x8b, 0x31, 0x05, + 0x72, 0xe9, 0xdc, 0xce, 0x05, 0x8c, 0x7a, 0xc1, 0xf5, 0xd6, 0xe1, 0xd0, + 0x6d, 0x73, 0x4e, 0xc1, 0x8a, 0x16, 0x49, 0x4d, 0xac, 0x21, 0xfb, 0x2d, + 0x12, 0xdd, 0x1e, 0xef, 0x9b, 0xb3, 0x6d, 0x20, 0x69, 0xfb, 0xaa, 0x3c, + 0x2c, 0x8f, 0x0d, 0x7c, 0x09, 0x1c, 0x1a, 0xa5, 0x23, 0x83, 0x98, 0x10, + 0xf4, 0x0c, 0x78, 0xa4, 0xa0, 0x4b, 0x1a, 0x71, 0x52, 0x4b, 0xb3, 0x8b, + 0x4c, 0x29, 0xfe, 0x6f, 0x24, 0x88, 0x7e, 0xd6, 0xf0, 0x6a, 0x2c, 0x3c, + 0x6c, 0xad, 0x54, 0x0c, 0xb6, 0x7b, 0xa4, 0x76, 0x38, 0xbf, 0x35, 0xc6, + 0x66, 0xde, 0x6a, 0x92, 0x43, 0x26, 0x31, 0xae, 0x76, 0xb5, 0xf6, 0x15, + 0x87, 0x02, 0x37, 0x7e, 0x7b, 0x92, 0xda, 0x3f, 0x45, 0x1e, 0x89, 0xb7, + 0x26, 0xb3, 0x8d, 0x3c, 0xf6, 0x49, 0x25, 0xe9, 0x1e, 0x52, 0x6f, 0x40, + 0x2e, 0xb6, 0x7d, 0x5c, 0x2a, 0x8a, 0x9c, 0x7d, 0x2c, 0x09, 0xce, 0xde, + 0x73, 0x5d, 0x3b, 0x7d, 0x4f, 0x3f, 0x4b, 0xdc, 0xeb, 0x8b, 0x93, 0xd1, + 0xc2, 0xf3, 0x29, 0x08, 0x98, 0x06, 0x8c, 0x46, 0x38, 0xe1, 0xd5, 0x30, + 0xc1, 0xf0, 0x3c, 0x74, 0x58, 0xf0, 0x20, 0x8b, 0xea, 0x30, 0x43, 0xd8, + 0x3d, 0x19, 0xc4, 0xd1, 0x04, 0xc8, 0xe5, 0x76, 0x31, 0x36, 0x4a, 0xae, + 0xf4, 0x21, 0x41, 0x0b, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x82, 0x01, + 0x00, 0x7b, 0xe7, 0x87, 0x58, 0x54, 0x59, 0x84, 0xf1, 0x8c, 0x92, 0x72, + 0xa1, 0xd2, 0xf7, 0x5a, 0xbb, 0x98, 0xa5, 0x35, 0x3b, 0x3e, 0xda, 0x66, + 0x2d, 0xdc, 0xcc, 0xc6, 0x9e, 0xdf, 0x73, 0xc4, 0xa7, 0xb2, 0x09, 0x2c, + 0x31, 0x77, 0x72, 0x57, 0x27, 0xc0, 0x48, 0x86, 0x9a, 0x05, 0x1f, 0x96, + 0x3f, 0x40, 0x36, 0x37, 0x92, 0xf3, 0xce, 0xfa, 0x6a, 0x11, 0xbd, 0x44, + 0x30, 0x6d, 0xbd, 0x00, 0xd1, 0x82, 0xb0, 0x77, 0xaf, 0xdb, 0x44, 0x74, + 0x97, 0xb7, 0x57, 0x73, 0x8e, 0x9a, 0x20, 0xab, 0x56, 0x40, 0x79, 0xd9, + 0x63, 0xd7, 0xf4, 0xeb, 0xa1, 0x3f, 0x1c, 0xe1, 0xd4, 0xb4, 0x37, 0xce, + 0xf6, 0xbf, 0xe6, 0x07, 0x06, 0x81, 0x55, 0x69, 0x59, 0x23, 0xc5, 0xaf, + 0xa9, 0x62, 0xa6, 0x17, 0x84, 0xd7, 0x40, 0xa1, 0xa8, 0xfe, 0xae, 0x4c, + 0x3e, 0xa2, 0xe0, 0x9a, 0x27, 0x39, 0x33, 0xf4, 0xd7, 0x62, 0x94, 0xac, + 0x58, 0xb8, 0x45, 0x03, 0xdf, 0x19, 0x21, 0x5b, 0xf8, 0x0c, 0xfb, 0x44, + 0x7e, 0xc7, 0x94, 0x15, 0xc1, 0xb5, 0x34, 0xfe, 0x1a, 0x35, 0xf7, 0x73, + 0x7a, 0xf4, 0x5f, 0x15, 0xaf, 0x6e, 0x93, 0x46, 0xbc, 0xae, 0x16, 0x32, + 0xed, 0x37, 0x73, 0x69, 0x17, 0xd7, 0xcc, 0x41, 0x6a, 0x25, 0x17, 0xa6, + 0x35, 0x58, 0x46, 0xb6, 0x2f, 0x13, 0x64, 0x1b, 0x04, 0x02, 0xdc, 0x5d, + 0x06, 0xe6, 0xf3, 0xb8, 0xf5, 0x93, 0xee, 0x39, 0xff, 0x0a, 0xa3, 0x33, + 0x9b, 0x30, 0x63, 0x5e, 0xf8, 0xfd, 0xd6, 0x45, 0x56, 0xe8, 0xdf, 0x64, + 0x62, 0x23, 0xa0, 0xf1, 0x1e, 0x6a, 0x4c, 0xc0, 0xc1, 0x95, 0x47, 0x05, + 0xb7, 0x5a, 0xb3, 0xda, 0xa5, 0x91, 0x81, 0x49, 0xef, 0x1d, 0x36, 0x14, + 0x55, 0x0f, 0x00, 0x9e, 0x28, 0x1b, 0x15, 0x77, 0x6c, 0x24, 0xd0, 0xe8, + 0x3f, 0x79, 0x37, 0x6a, 0xd1, 0x02, 0x81, 0x81, 0x00, 0xdb, 0x95, 0x25, + 0xee, 0x4f, 0x77, 0x20, 0xcf, 0xf8, 0xc4, 0x3a, 0xa5, 0xcf, 0x15, 0x28, + 0x4f, 0xdf, 0x16, 0xbb, 0xfc, 0x10, 0xaa, 0xa5, 0x7f, 0x0d, 0xea, 0x93, + 0xe2, 0xaf, 0x91, 0x9c, 0x77, 0xcc, 0x51, 0x8e, 0xb0, 0x79, 0xc8, 0xba, + 0xe4, 0x75, 0xcb, 0x07, 0x47, 0x04, 0xab, 0xb5, 0xd0, 0x75, 0x6f, 0x61, + 0xa4, 0x98, 0x2d, 0x15, 0xa9, 0x8a, 0xa2, 0x44, 0xde, 0x4c, 0xd7, 0x7f, + 0x01, 0xb7, 0xb4, 0x71, 0x21, 0x6e, 0xff, 0x0b, 0x15, 0x46, 0x81, 0xd8, + 0x53, 0x11, 0x1d, 0x7c, 0x8f, 0x48, 0x6a, 0xd0, 0x1c, 0xe8, 0xe0, 0x7d, + 0xed, 0x44, 0x17, 0x30, 0xcb, 0xed, 0xfc, 0x65, 0x92, 0x21, 0x62, 0x75, + 0x1f, 0x5c, 0x6a, 0x32, 0x4f, 0xc9, 0xb8, 0x98, 0x11, 0xc7, 0x54, 0x18, + .. .. .. .. .. .. .. .. .. .. .. .. + 0x3b, 0x25, 0x36, 0xc2, 0xcd, 0x02, 0x81, 0x81, 0x00, 0xd5, 0x05, 0x4a, + 0x96, 0xf5, 0x50, 0xc4, 0x46, 0x95*/ +}; + + +static const GSMRootCert SECRET_GSM_ROOT_CERTS[] = { + { + "DST_Root_CA_X3", + (const uint8_t[]){ + 0x30, 0x82, 0x03, 0x4a, 0x30, 0x82, 0x02, 0x32, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x44, 0xaf, 0xb0, 0x80, 0xd6, 0xa3, 0x27, 0xba, 0x89, + 0x30, 0x39, 0x86, 0x2e, 0xf8, 0x40, 0x6b, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3f, + 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43, + 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, + 0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x30, 0x30, 0x39, 0x33, + 0x30, 0x32, 0x31, 0x31, 0x32, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x31, + 0x30, 0x39, 0x33, 0x30, 0x31, 0x34, 0x30, 0x31, 0x31, 0x35, 0x5a, 0x30, + 0x3f, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, + 0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, + 0x43, 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, + 0x13, 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, + 0x41, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, + 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, + 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, + 0x00, 0xdf, 0xaf, 0xe9, 0x97, 0x50, 0x08, 0x83, 0x57, 0xb4, 0xcc, 0x62, + 0x65, 0xf6, 0x90, 0x82, 0xec, 0xc7, 0xd3, 0x2c, 0x6b, 0x30, 0xca, 0x5b, + 0xec, 0xd9, 0xc3, 0x7d, 0xc7, 0x40, 0xc1, 0x18, 0x14, 0x8b, 0xe0, 0xe8, + 0x33, 0x76, 0x49, 0x2a, 0xe3, 0x3f, 0x21, 0x49, 0x93, 0xac, 0x4e, 0x0e, + 0xaf, 0x3e, 0x48, 0xcb, 0x65, 0xee, 0xfc, 0xd3, 0x21, 0x0f, 0x65, 0xd2, + 0x2a, 0xd9, 0x32, 0x8f, 0x8c, 0xe5, 0xf7, 0x77, 0xb0, 0x12, 0x7b, 0xb5, + 0x95, 0xc0, 0x89, 0xa3, 0xa9, 0xba, 0xed, 0x73, 0x2e, 0x7a, 0x0c, 0x06, + 0x32, 0x83, 0xa2, 0x7e, 0x8a, 0x14, 0x30, 0xcd, 0x11, 0xa0, 0xe1, 0x2a, + 0x38, 0xb9, 0x79, 0x0a, 0x31, 0xfd, 0x50, 0xbd, 0x80, 0x65, 0xdf, 0xb7, + 0x51, 0x63, 0x83, 0xc8, 0xe2, 0x88, 0x61, 0xea, 0x4b, 0x61, 0x81, 0xec, + 0x52, 0x6b, 0xb9, 0xa2, 0xe2, 0x4b, 0x1a, 0x28, 0x9f, 0x48, 0xa3, 0x9e, + 0x0c, 0xda, 0x09, 0x8e, 0x3e, 0x17, 0x2e, 0x1e, 0xdd, 0x20, 0xdf, 0x5b, + 0xc6, 0x2a, 0x8a, 0xab, 0x2e, 0xbd, 0x70, 0xad, 0xc5, 0x0b, 0x1a, 0x25, + 0x90, 0x74, 0x72, 0xc5, 0x7b, 0x6a, 0xab, 0x34, 0xd6, 0x30, 0x89, 0xff, + 0xe5, 0x68, 0x13, 0x7b, 0x54, 0x0b, 0xc8, 0xd6, 0xae, 0xec, 0x5a, 0x9c, + 0x92, 0x1e, 0x3d, 0x64, 0xb3, 0x8c, 0xc6, 0xdf, 0xbf, 0xc9, 0x41, 0x70, + 0xec, 0x16, 0x72, 0xd5, 0x26, 0xec, 0x38, 0x55, 0x39, 0x43, 0xd0, 0xfc, + 0xfd, 0x18, 0x5c, 0x40, 0xf1, 0x97, 0xeb, 0xd5, 0x9a, 0x9b, 0x8d, 0x1d, + 0xba, 0xda, 0x25, 0xb9, 0xc6, 0xd8, 0xdf, 0xc1, 0x15, 0x02, 0x3a, 0xab, + 0xda, 0x6e, 0xf1, 0x3e, 0x2e, 0xf5, 0x5c, 0x08, 0x9c, 0x3c, 0xd6, 0x83, + 0x69, 0xe4, 0x10, 0x9b, 0x19, 0x2a, 0xb6, 0x29, 0x57, 0xe3, 0xe5, 0x3d, + 0x9b, 0x9f, 0xf0, 0x02, 0x5d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42, + 0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, + 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55, + 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, + 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc4, 0xa7, + 0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, 0xe1, 0x4b, 0x90, 0x75, 0xff, + 0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, + 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01, + 0x01, 0x00, 0xa3, 0x1a, 0x2c, 0x9b, 0x17, 0x00, 0x5c, 0xa9, 0x1e, 0xee, + 0x28, 0x66, 0x37, 0x3a, 0xbf, 0x83, 0xc7, 0x3f, 0x4b, 0xc3, 0x09, 0xa0, + 0x95, 0x20, 0x5d, 0xe3, 0xd9, 0x59, 0x44, 0xd2, 0x3e, 0x0d, 0x3e, 0xbd, + 0x8a, 0x4b, 0xa0, 0x74, 0x1f, 0xce, 0x10, 0x82, 0x9c, 0x74, 0x1a, 0x1d, + 0x7e, 0x98, 0x1a, 0xdd, 0xcb, 0x13, 0x4b, 0xb3, 0x20, 0x44, 0xe4, 0x91, + 0xe9, 0xcc, 0xfc, 0x7d, 0xa5, 0xdb, 0x6a, 0xe5, 0xfe, 0xe6, 0xfd, 0xe0, + 0x4e, 0xdd, 0xb7, 0x00, 0x3a, 0xb5, 0x70, 0x49, 0xaf, 0xf2, 0xe5, 0xeb, + 0x02, 0xf1, 0xd1, 0x02, 0x8b, 0x19, 0xcb, 0x94, 0x3a, 0x5e, 0x48, 0xc4, + 0x18, 0x1e, 0x58, 0x19, 0x5f, 0x1e, 0x02, 0x5a, 0xf0, 0x0c, 0xf1, 0xb1, + 0xad, 0xa9, 0xdc, 0x59, 0x86, 0x8b, 0x6e, 0xe9, 0x91, 0xf5, 0x86, 0xca, + 0xfa, 0xb9, 0x66, 0x33, 0xaa, 0x59, 0x5b, 0xce, 0xe2, 0xa7, 0x16, 0x73, + 0x47, 0xcb, 0x2b, 0xcc, 0x99, 0xb0, 0x37, 0x48, 0xcf, 0xe3, 0x56, 0x4b, + 0xf5, 0xcf, 0x0f, 0x0c, 0x72, 0x32, 0x87, 0xc6, 0xf0, 0x44, 0xbb, 0x53, + 0x72, 0x6d, 0x43, 0xf5, 0x26, 0x48, 0x9a, 0x52, 0x67, 0xb7, 0x58, 0xab, + 0xfe, 0x67, 0x76, 0x71, 0x78, 0xdb, 0x0d, 0xa2, 0x56, 0x14, 0x13, 0x39, + 0x24, 0x31, 0x85, 0xa2, 0xa8, 0x02, 0x5a, 0x30, 0x47, 0xe1, 0xdd, 0x50, + 0x07, 0xbc, 0x02, 0x09, 0x90, 0x00, 0xeb, 0x64, 0x63, 0x60, 0x9b, 0x16, + 0xbc, 0x88, 0xc9, 0x12, 0xe6, 0xd2, 0x7d, 0x91, 0x8b, 0xf9, 0x3d, 0x32, + 0x8d, 0x65, 0xb4, 0xe9, 0x7c, 0xb1, 0x57, 0x76, 0xea, 0xc5, 0xb6, 0x28, + 0x39, 0xbf, 0x15, 0x65, 0x1c, 0xc8, 0xf6, 0x77, 0x96, 0x6a, 0x0a, 0x8d, + 0x77, 0x0b, 0xd8, 0x91, 0x0b, 0x04, 0x8e, 0x07, 0xdb, 0x29, 0xb6, 0x0a, + 0xee, 0x9d, 0x82, 0x35, 0x35, 0x10 + }, + 846 + }, + { + "Let_s_Encrypt_Authority_X3", + (const uint8_t[]){ + 0x30, 0x82, 0x04, 0x92, 0x30, 0x82, 0x03, 0x7a, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x10, 0x0a, 0x01, 0x41, 0x42, 0x00, 0x00, 0x01, 0x53, 0x85, + 0x73, 0x6a, 0x0b, 0x85, 0xec, 0xa7, 0x08, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x3f, + 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44, + 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61, + 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43, + 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, + 0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x33, 0x31, + 0x37, 0x31, 0x36, 0x34, 0x30, 0x34, 0x36, 0x5a, 0x17, 0x0d, 0x32, 0x31, + 0x30, 0x33, 0x31, 0x37, 0x31, 0x36, 0x34, 0x30, 0x34, 0x36, 0x5a, 0x30, + 0x4a, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + 0x55, 0x53, 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, + 0x0d, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x31, 0x23, 0x30, 0x21, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, + 0x1a, 0x4c, 0x65, 0x74, 0x27, 0x73, 0x20, 0x45, 0x6e, 0x63, 0x72, 0x79, + 0x70, 0x74, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, + 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, + 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, + 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00, + 0x9c, 0xd3, 0x0c, 0xf0, 0x5a, 0xe5, 0x2e, 0x47, 0xb7, 0x72, 0x5d, 0x37, + 0x83, 0xb3, 0x68, 0x63, 0x30, 0xea, 0xd7, 0x35, 0x26, 0x19, 0x25, 0xe1, + 0xbd, 0xbe, 0x35, 0xf1, 0x70, 0x92, 0x2f, 0xb7, 0xb8, 0x4b, 0x41, 0x05, + 0xab, 0xa9, 0x9e, 0x35, 0x08, 0x58, 0xec, 0xb1, 0x2a, 0xc4, 0x68, 0x87, + 0x0b, 0xa3, 0xe3, 0x75, 0xe4, 0xe6, 0xf3, 0xa7, 0x62, 0x71, 0xba, 0x79, + 0x81, 0x60, 0x1f, 0xd7, 0x91, 0x9a, 0x9f, 0xf3, 0xd0, 0x78, 0x67, 0x71, + 0xc8, 0x69, 0x0e, 0x95, 0x91, 0xcf, 0xfe, 0xe6, 0x99, 0xe9, 0x60, 0x3c, + 0x48, 0xcc, 0x7e, 0xca, 0x4d, 0x77, 0x12, 0x24, 0x9d, 0x47, 0x1b, 0x5a, + 0xeb, 0xb9, 0xec, 0x1e, 0x37, 0x00, 0x1c, 0x9c, 0xac, 0x7b, 0xa7, 0x05, + 0xea, 0xce, 0x4a, 0xeb, 0xbd, 0x41, 0xe5, 0x36, 0x98, 0xb9, 0xcb, 0xfd, + 0x6d, 0x3c, 0x96, 0x68, 0xdf, 0x23, 0x2a, 0x42, 0x90, 0x0c, 0x86, 0x74, + 0x67, 0xc8, 0x7f, 0xa5, 0x9a, 0xb8, 0x52, 0x61, 0x14, 0x13, 0x3f, 0x65, + 0xe9, 0x82, 0x87, 0xcb, 0xdb, 0xfa, 0x0e, 0x56, 0xf6, 0x86, 0x89, 0xf3, + 0x85, 0x3f, 0x97, 0x86, 0xaf, 0xb0, 0xdc, 0x1a, 0xef, 0x6b, 0x0d, 0x95, + 0x16, 0x7d, 0xc4, 0x2b, 0xa0, 0x65, 0xb2, 0x99, 0x04, 0x36, 0x75, 0x80, + 0x6b, 0xac, 0x4a, 0xf3, 0x1b, 0x90, 0x49, 0x78, 0x2f, 0xa2, 0x96, 0x4f, + 0x2a, 0x20, 0x25, 0x29, 0x04, 0xc6, 0x74, 0xc0, 0xd0, 0x31, 0xcd, 0x8f, + 0x31, 0x38, 0x95, 0x16, 0xba, 0xa8, 0x33, 0xb8, 0x43, 0xf1, 0xb1, 0x1f, + 0xc3, 0x30, 0x7f, 0xa2, 0x79, 0x31, 0x13, 0x3d, 0x2d, 0x36, 0xf8, 0xe3, + 0xfc, 0xf2, 0x33, 0x6a, 0xb9, 0x39, 0x31, 0xc5, 0xaf, 0xc4, 0x8d, 0x0d, + 0x1d, 0x64, 0x16, 0x33, 0xaa, 0xfa, 0x84, 0x29, 0xb6, 0xd4, 0x0b, 0xc0, + 0xd8, 0x7d, 0xc3, 0x93, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x82, 0x01, + 0x7d, 0x30, 0x82, 0x01, 0x79, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, + 0x01, 0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, + 0x00, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, + 0x04, 0x03, 0x02, 0x01, 0x86, 0x30, 0x7f, 0x06, 0x08, 0x2b, 0x06, 0x01, + 0x05, 0x05, 0x07, 0x01, 0x01, 0x04, 0x73, 0x30, 0x71, 0x30, 0x32, 0x06, + 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x86, 0x26, 0x68, + 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x69, 0x73, 0x72, 0x67, 0x2e, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x69, 0x64, 0x2e, 0x6f, 0x63, 0x73, 0x70, 0x2e, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, 0x2e, 0x63, 0x6f, + 0x6d, 0x30, 0x3b, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, + 0x02, 0x86, 0x2f, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x61, 0x70, + 0x70, 0x73, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x72, 0x75, 0x73, 0x74, + 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x72, 0x6f, 0x6f, 0x74, 0x73, 0x2f, 0x64, + 0x73, 0x74, 0x72, 0x6f, 0x6f, 0x74, 0x63, 0x61, 0x78, 0x33, 0x2e, 0x70, + 0x37, 0x63, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, + 0x16, 0x80, 0x14, 0xc4, 0xa7, 0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, + 0xe1, 0x4b, 0x90, 0x75, 0xff, 0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, + 0x54, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x4d, 0x30, 0x4b, 0x30, 0x08, + 0x06, 0x06, 0x67, 0x81, 0x0c, 0x01, 0x02, 0x01, 0x30, 0x3f, 0x06, 0x0b, + 0x2b, 0x06, 0x01, 0x04, 0x01, 0x82, 0xdf, 0x13, 0x01, 0x01, 0x01, 0x30, + 0x30, 0x30, 0x2e, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, + 0x01, 0x16, 0x22, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x63, 0x70, + 0x73, 0x2e, 0x72, 0x6f, 0x6f, 0x74, 0x2d, 0x78, 0x31, 0x2e, 0x6c, 0x65, + 0x74, 0x73, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x2e, 0x6f, 0x72, + 0x67, 0x30, 0x3c, 0x06, 0x03, 0x55, 0x1d, 0x1f, 0x04, 0x35, 0x30, 0x33, + 0x30, 0x31, 0xa0, 0x2f, 0xa0, 0x2d, 0x86, 0x2b, 0x68, 0x74, 0x74, 0x70, + 0x3a, 0x2f, 0x2f, 0x63, 0x72, 0x6c, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x72, 0x75, 0x73, 0x74, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x44, 0x53, 0x54, + 0x52, 0x4f, 0x4f, 0x54, 0x43, 0x41, 0x58, 0x33, 0x43, 0x52, 0x4c, 0x2e, + 0x63, 0x72, 0x6c, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, + 0x04, 0x14, 0xa8, 0x4a, 0x6a, 0x63, 0x04, 0x7d, 0xdd, 0xba, 0xe6, 0xd1, + 0x39, 0xb7, 0xa6, 0x45, 0x65, 0xef, 0xf3, 0xa8, 0xec, 0xa1, 0x30, 0x0d, + 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, + 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0xdd, 0x33, 0xd7, 0x11, 0xf3, 0x63, + 0x58, 0x38, 0xdd, 0x18, 0x15, 0xfb, 0x09, 0x55, 0xbe, 0x76, 0x56, 0xb9, + 0x70, 0x48, 0xa5, 0x69, 0x47, 0x27, 0x7b, 0xc2, 0x24, 0x08, 0x92, 0xf1, + 0x5a, 0x1f, 0x4a, 0x12, 0x29, 0x37, 0x24, 0x74, 0x51, 0x1c, 0x62, 0x68, + 0xb8, 0xcd, 0x95, 0x70, 0x67, 0xe5, 0xf7, 0xa4, 0xbc, 0x4e, 0x28, 0x51, + 0xcd, 0x9b, 0xe8, 0xae, 0x87, 0x9d, 0xea, 0xd8, 0xba, 0x5a, 0xa1, 0x01, + 0x9a, 0xdc, 0xf0, 0xdd, 0x6a, 0x1d, 0x6a, 0xd8, 0x3e, 0x57, 0x23, 0x9e, + 0xa6, 0x1e, 0x04, 0x62, 0x9a, 0xff, 0xd7, 0x05, 0xca, 0xb7, 0x1f, 0x3f, + 0xc0, 0x0a, 0x48, 0xbc, 0x94, 0xb0, 0xb6, 0x65, 0x62, 0xe0, 0xc1, 0x54, + 0xe5, 0xa3, 0x2a, 0xad, 0x20, 0xc4, 0xe9, 0xe6, 0xbb, 0xdc, 0xc8, 0xf6, + 0xb5, 0xc3, 0x32, 0xa3, 0x98, 0xcc, 0x77, 0xa8, 0xe6, 0x79, 0x65, 0x07, + 0x2b, 0xcb, 0x28, 0xfe, 0x3a, 0x16, 0x52, 0x81, 0xce, 0x52, 0x0c, 0x2e, + 0x5f, 0x83, 0xe8, 0xd5, 0x06, 0x33, 0xfb, 0x77, 0x6c, 0xce, 0x40, 0xea, + 0x32, 0x9e, 0x1f, 0x92, 0x5c, 0x41, 0xc1, 0x74, 0x6c, 0x5b, 0x5d, 0x0a, + 0x5f, 0x33, 0xcc, 0x4d, 0x9f, 0xac, 0x38, 0xf0, 0x2f, 0x7b, 0x2c, 0x62, + 0x9d, 0xd9, 0xa3, 0x91, 0x6f, 0x25, 0x1b, 0x2f, 0x90, 0xb1, 0x19, 0x46, + 0x3d, 0xf6, 0x7e, 0x1b, 0xa6, 0x7a, 0x87, 0xb9, 0xa3, 0x7a, 0x6d, 0x18, + 0xfa, 0x25, 0xa5, 0x91, 0x87, 0x15, 0xe0, 0xf2, 0x16, 0x2f, 0x58, 0xb0, + 0x06, 0x2f, 0x2c, 0x68, 0x26, 0xc6, 0x4b, 0x98, 0xcd, 0xda, 0x9f, 0x0c, + 0xf9, 0x7f, 0x90, 0xed, 0x43, 0x4a, 0x12, 0x44, 0x4e, 0x6f, 0x73, 0x7a, + 0x28, 0xea, 0xa4, 0xaa, 0x6e, 0x7b, 0x4c, 0x7d, 0x87, 0xdd, 0xe0, 0xc9, + 0x02, 0x44, 0xa7, 0x87, 0xaf, 0xc3, 0x34, 0x5b, 0xb4, 0x42 + }, + 1174 + } +}; + + +#define SECRET_GSM_ROOT_SIZE (sizeof(SECRET_GSM_ROOT_CERTS)/sizeof(SECRET_GSM_ROOT_CERTS[0])) diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/PinManagement/PinManagement.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/PinManagement/PinManagement.ino new file mode 100644 index 00000000..d095c2b4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/PinManagement/PinManagement.ino @@ -0,0 +1,142 @@ +/* + + This example enables you to change or remove the PIN number of + a SIM card inserted into a GSM shield. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card + + Created 12 Jun 2012 + by David del Peral +*/ + +// libraries +#include + +// pin manager object +GSMPIN PINManager; + +// save input in serial by user +String user_input = ""; + +// authenticated with PIN code +bool auth = false; + +// Serial Monitor result messages +String oktext = "OK"; +String errortext = "ERROR"; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Change PIN example\n"); + PINManager.begin(); + + // check if the SIM has pin lock + while (!auth) { + int pin_query = PINManager.isPIN(); + if (pin_query == 1) { + // if SIM is locked, enter PIN code + Serial.print("Enter PIN code: "); + user_input = readSerial(); + // check PIN code + if (PINManager.checkPIN(user_input) == 0) { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } else { + // if PIN code was incorrect + Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); + } + } else if (pin_query == -1) { + // PIN code is locked, user must enter PUK code + Serial.println("PIN locked. Enter PUK code: "); + String puk = readSerial(); + Serial.print("Now, enter a new PIN code: "); + user_input = readSerial(); + // check PUK code + if (PINManager.checkPUK(puk, user_input) == 0) { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } else { + // if PUK or the new PIN are incorrect + Serial.println("Incorrect PUK or invalid new PIN. Try again!."); + } + } else if (pin_query == -2) { + // the worst case, PIN and PUK are locked + Serial.println("PIN and PUK locked. Use PIN2/PUK2 in a mobile phone."); + while (true); + } else { + // SIM does not require authentication + Serial.println("No pin necessary."); + auth = true; + } + } + + // start GSM shield + Serial.print("Checking register in GSM network..."); + if (PINManager.checkReg() == 0) { + Serial.println(oktext); + } + // if you are connected by roaming + else if (PINManager.checkReg() == 1) { + Serial.println("ROAMING " + oktext); + } else { + // error connection + Serial.println(errortext); + while (true); + } +} + +void loop() { + // Function loop implements pin management user menu + // Only if your SIM uses pin lock can you change the PIN code + // user_op variables save user option + + Serial.println("Choose an option:\n1 - On/Off PIN."); + if (PINManager.getPINUsed()) { + Serial.println("2 - Change PIN."); + } + String user_op = readSerial(); + if (user_op == "1") { + Serial.println("Enter your PIN code:"); + user_input = readSerial(); + // activate/deactivate PIN lock + PINManager.switchPIN(user_input); + } else if (user_op == "2" && PINManager.getPINUsed()) { + Serial.println("Enter your actual PIN code:"); + String oldPIN = readSerial(); + Serial.println("Now, enter your new PIN code:"); + String newPIN = readSerial(); + // change PIN + PINManager.changePIN(oldPIN, newPIN); + } else { + Serial.println("Incorrect option. Try again!."); + } + delay(1000); +} + +/* + Read input serial + */ +String readSerial() { + String text = ""; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + return text; + } + if (inChar != '\r') { + text += inChar; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/SerialGSMPassthrough/SerialGSMPassthrough.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/SerialGSMPassthrough/SerialGSMPassthrough.ino new file mode 100644 index 00000000..203967b3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/SerialGSMPassthrough/SerialGSMPassthrough.ino @@ -0,0 +1,44 @@ +/* + SerialGSMPassthrough sketch + + This sketch allows you to send AT commands from the USB CDC serial port + of the MKR GSM 1400 board to the onboard u-blox SARA-U201 celluar module. + + For a list of supported AT commands see: + https://www.u-blox.com/sites/default/files/u-blox-CEL_ATCommands_%28UBX-13002752%29.pdf + + Circuit: + - MKR GSM 1400 board + - Antenna + - 1500 mAh or higher LiPo battery connected + - SIM card + + Make sure the Serial Monitor's line ending is set to "Both NL and CR" + + create 11 December 2017 + Sandeep Mistry +*/ + +// baud rate used for both Serial ports +unsigned long baud = 115200; + +void setup() { + // reset the u-blox module + pinMode(GSM_RESETN, OUTPUT); + digitalWrite(GSM_RESETN, HIGH); + delay(100); + digitalWrite(GSM_RESETN, LOW); + + Serial.begin(baud); + SerialGSM.begin(baud); +} + +void loop() { + if (Serial.available()) { + SerialGSM.write(Serial.read()); + } + + if (SerialGSM.available()) { + Serial.write(SerialGSM.read()); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/TestGPRS.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/TestGPRS.ino new file mode 100644 index 00000000..a3121981 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/TestGPRS.ino @@ -0,0 +1,188 @@ +/* + + This sketch tests the MKR GSM 1400 board's ability to connect to a + GPRS network. It asks for APN information through the + Serial Monitor and tries to connect to example.org. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with data plan + + Created 18 Jun 2012 + by David del Peral +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +GSM gsmAccess; // GSM access: include a 'true' parameter for debug enabled +GPRS gprsAccess; // GPRS access +GSMClient client; // Client service for TCP connection + +// messages for Serial Monitor response +String oktext = "OK"; +String errortext = "ERROR"; + +// URL and path (for example: example.org) +char url[] = "example.org"; +char urlproxy[] = "http://www.example.org"; +char path[] = "/"; + +// variable for save response obtained +String response = ""; + +// use a proxy +bool use_proxy = false; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } +} + +void loop() { + use_proxy = false; + + // start GSM shield + // if your SIM has PIN, pass it as a parameter of begin() in quotes + Serial.print("Connecting GSM network..."); + if (gsmAccess.begin(PINNUMBER) != GSM_READY) { + Serial.println(errortext); + while (true); + } + Serial.println(oktext); + + // read APN introduced by user + char apn[50]; + Serial.print("Enter your APN: "); + readSerial(apn); + Serial.println(apn); + + // Read APN login introduced by user + char login[50]; + Serial.print("Now, enter your login: "); + readSerial(login); + Serial.println(login); + + // read APN password introduced by user + char password[20]; + Serial.print("Finally, enter your password: "); + readSerial(password); + + // attach GPRS + Serial.println("Attaching to GPRS with your APN..."); + if (gprsAccess.attachGPRS(apn, login, password) != GPRS_READY) { + Serial.println(errortext); + } else { + + Serial.println(oktext); + + // read proxy introduced by user + char proxy[100]; + Serial.print("If your carrier uses a proxy, enter it, if not press enter: "); + readSerial(proxy); + Serial.println(proxy); + + // if user introduced a proxy, asks them for proxy port + int pport; + if (proxy[0] != '\0') { + // read proxy port introduced by user + char proxyport[10]; + Serial.print("Enter the proxy port: "); + readSerial(proxyport); + // cast proxy port introduced to integer + pport = (int) proxyport; + use_proxy = true; + Serial.println(proxyport); + } + + // connection with example.org and realize HTTP request + Serial.print("Connecting and sending GET request to example.org..."); + int res_connect; + + // if using a proxy, connect with it + if (use_proxy) { + res_connect = client.connect(proxy, pport); + } else { + res_connect = client.connect(url, 80); + } + + if (res_connect) { + // make a HTTP 1.0 GET request (client sends the request) + client.print("GET "); + + // if using a proxy, the path is the example.org URL + if (use_proxy) { + client.print(urlproxy); + } else { + client.print(path); + } + + client.println(" HTTP/1.0"); + client.println(); + Serial.println(oktext); + } else { + // if you didn't get a connection to the server + Serial.println(errortext); + } + Serial.print("Receiving response..."); + + bool test = true; + while (test) { + // if there are incoming bytes available + // from the server, read and check them + if (client.available()) { + char c = client.read(); + response += c; + + // cast response obtained from string to char array + char responsechar[response.length() + 1]; + response.toCharArray(responsechar, response.length() + 1); + + // if response includes a "200 OK" substring + if (strstr(responsechar, "200 OK") != NULL) { + Serial.println(oktext); + Serial.println("TEST COMPLETE!"); + test = false; + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + test = false; + } + } + } +} + +/* + Read input serial + */ +int readSerial(char result[]) { + int i = 0; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + result[i] = '\0'; + return 0; + } + if (inChar != '\r') { + result[i] = inChar; + i++; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestGPRS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestModem/TestModem.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestModem/TestModem.ino new file mode 100644 index 00000000..1852e1ba --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestModem/TestModem.ino @@ -0,0 +1,65 @@ +/* + + This example tests to see if the modem of the + MKR GSM 1400 board is working correctly. You do not need + a SIM card for this example. + + Circuit: + * MKR GSM 1400 board + * Antenna + + Created 12 Jun 2012 + by David del Peral + modified 21 Nov 2012 + by Tom Igoe +*/ + +// libraries +#include + +// modem verification object +GSMModem modem; + +// IMEI variable +String IMEI = ""; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start modem test (reset and check response) + Serial.print("Starting modem test..."); + if (modem.begin()) { + Serial.println("modem.begin() succeeded"); + } else { + Serial.println("ERROR, no modem answer."); + } +} + +void loop() { + // get modem IMEI + Serial.print("Checking IMEI..."); + IMEI = modem.getIMEI(); + + // check IMEI response + if (IMEI != NULL) { + // show IMEI in Serial Monitor + Serial.println("Modem's IMEI: " + IMEI); + // reset modem to check booting: + Serial.print("Resetting modem..."); + modem.begin(); + // get and check IMEI one more time + if (modem.getIMEI() != NULL) { + Serial.println("Modem is functioning properly"); + } else { + Serial.println("Error: getIMEI() failed after modem.begin()"); + } + } else { + Serial.println("Error: Could not get IMEI"); + } + // do nothing: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/TestWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/TestWebServer.ino new file mode 100644 index 00000000..f68960f3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/TestWebServer.ino @@ -0,0 +1,79 @@ +/* + Basic Web Server + + A simple web server that replies with nothing, but prints the client's request + and the server IP address. + + Circuit: + * MKR GSM 1400 board + * Antenna + + created + by David Cuartielles + modified 21 Nov 2012 + by Tom Igoe +*/ +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + + +// initialize the library instance +GPRS gprs; +GSM gsmAccess; // include a 'true' parameter for debug enabled +GSMServer server(80); // port 80 (http default) + +// timeout +const unsigned long __TIMEOUT__ = 10 * 1000; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("starting,.."); + // connection state + bool connected = false; + + // Start GSM shield + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && + (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected to GPRS network"); + + // start server + server.begin(); + + //Get IP. + IPAddress LocalIP = gprs.getIPAddress(); + Serial.println("Server IP address="); + Serial.println(LocalIP); +} + +void loop() { + GSMClient client = server.available(); + + if (client) { + if (client.available()) { + Serial.write(client.read()); + } + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/arduino_secrets.h new file mode 100644 index 00000000..e1c4da91 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRGSM/examples/Tools/TestWebServer/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/README.adoc new file mode 100644 index 00000000..96e35b9b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/README.adoc @@ -0,0 +1,10 @@ +:repository-owner: arduino-libraries +:repository-name: MKRIMU + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Allows you to read the acceleration, gyroscope, magnetic fields and Euler angles from the IMU on your MKR IMU Shield. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleAccelerometer/SimpleAccelerometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleAccelerometer/SimpleAccelerometer.ino new file mode 100644 index 00000000..8b4a5b7c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleAccelerometer/SimpleAccelerometer.ino @@ -0,0 +1,47 @@ +/* + MKR IMU Shield - Simple Accelerometer + + This example reads the acceleration values from the IMU + on the MKR IMU Shield and continuously prints them to the + Serial Monitor. + + The circuit: + - Arduino MKR board + - Arduino MKR IMU Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1); + } + + Serial.print("Accelerometer sample rate = "); + Serial.print(IMU.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Acceleration in g's"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.accelerationAvailable()) { + IMU.readAcceleration(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleEulerAngles/SimpleEulerAngles.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleEulerAngles/SimpleEulerAngles.ino new file mode 100644 index 00000000..3ec52306 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleEulerAngles/SimpleEulerAngles.ino @@ -0,0 +1,47 @@ +/* + MKR IMU Shield - Simple Euler Angles + + This example reads the Euler angle values from the IMU + on the MKR IMU Shield and continuously prints them to the + Serial Monitor. + + The circuit: + - Arduino MKR board + - Arduino MKR IMU Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1); + } + + Serial.print("Euler Angles sample rate = "); + Serial.print(IMU.eulerAnglesSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Euler Angles in degrees"); + Serial.println("Heading\tRoll\tPitch"); +} + +void loop() { + float heading, roll, pitch; + + if (IMU.eulerAnglesAvailable()) { + IMU.readEulerAngles(heading, roll, pitch); + + Serial.print(heading); + Serial.print('\t'); + Serial.print(roll); + Serial.print('\t'); + Serial.println(pitch); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleGyroscope/SimpleGyroscope.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleGyroscope/SimpleGyroscope.ino new file mode 100644 index 00000000..77fef7d6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleGyroscope/SimpleGyroscope.ino @@ -0,0 +1,47 @@ +/* + MKR IMU Shield - Simple Gyroscope + + This example reads the gyroscope values from the IMU + on the MKR IMU Shield and continuously prints them to the + Serial Monitor. + + The circuit: + - Arduino MKR board + - Arduino MKR IMU Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1); + } + + Serial.print("Gyroscope sample rate = "); + Serial.print(IMU.gyroscopeSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Gyroscope in degrees/second"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.gyroscopeAvailable()) { + IMU.readGyroscope(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleMagnetometer/SimpleMagnetometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleMagnetometer/SimpleMagnetometer.ino new file mode 100644 index 00000000..91ec1392 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRIMU/examples/SimpleMagnetometer/SimpleMagnetometer.ino @@ -0,0 +1,47 @@ +/* + MKR IMU Shield - Simple Magnetometer + + This example reads the magnetic field values from the IMU + on the MKR IMU Shield and continuously prints them to the + Serial Monitor. + + The circuit: + - Arduino MKR board + - Arduino MKR IMU Shield attached + + This example code is in the public domain. +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + + while (1); + } + + Serial.print("Magnetic Field sample rate = "); + Serial.print(IMU.magneticFieldSampleRate()); + Serial.println(" Hz"); + Serial.println(); + Serial.println("Magnetic Field in uT"); + Serial.println("X\tY\tZ"); +} + +void loop() { + float x, y, z; + + if (IMU.magneticFieldAvailable()) { + IMU.readMagneticField(x, y, z); + + Serial.print(x); + Serial.print('\t'); + Serial.print(y); + Serial.print('\t'); + Serial.println(z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/README.adoc new file mode 100644 index 00000000..2f6bc234 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/README.adoc @@ -0,0 +1,31 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: MKRNB + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/workflows/Compile%20Examples/badge.svg["Compile Examples Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Compile+Examples"] +image:https://github.com/{repository-owner}/{repository-name}/workflows/Spell%20Check/badge.svg["Spell Check Status", link="https://github.com/{repository-owner}/{repository-name}/actions?workflow=Spell+Check"] + +This library enables an Arduino MKR NB 1500 board to connect to the internet over a NarrowBand IoT or LTE Cat M1 network. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino new file mode 100644 index 00000000..fdc7969e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/GPRSUdpNtpClient.ino @@ -0,0 +1,153 @@ +/* + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP write and parsePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + modified 6 Dec 2017 ported from WiFi101 to MKRGSM + by Arturo Guadalupi + + This code is in the public domain. + +*/ + +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// initialize the library instance +NBClient client; +GPRS gprs; +NB nbAccess; + +// A UDP instance to let us send and receive packets over UDP +NBUDP Udp; + +void setup() +{ + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino GPRS NTP client."); + // connection state + boolean connected = false; + + // After starting the modem with NB.begin() + // attach the shield to the GPRS network with the APN, login and password + while (!connected) { + if ((nbAccess.begin(PINNUMBER) == NB_READY) && + (gprs.attachGPRS() == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() +{ + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if ( Udp.parsePacket() ) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = " ); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if ( ((epoch % 3600) / 60) < 10 ) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ( (epoch % 60) < 10 ) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) +{ + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/GPRSUdpNtpClient/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/NBSSLWebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/NBSSLWebClient.ino new file mode 100644 index 00000000..6f3ae3a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/NBSSLWebClient.ino @@ -0,0 +1,95 @@ +/* + SSL Web client + + This sketch connects to a website using SSL through a MKR NB 1500 board. Specifically, + this example downloads the URL "https://www.arduino.cc/asciilogo.txt" and + prints it to the Serial monitor. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card with a data plan + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NBSSLClient client; +GPRS gprs; +NB nbAccess; + +// URL, path and port (for example: arduino.cc) +char server[] = "arduino.cc"; +char path[] = "/asciilogo.txt"; +int port = 443; // port 443 is the default for HTTPS + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + // connection state + boolean connected = false; + + // After starting the modem with NB.begin() + // attach to the GPRS network with the APN, login and password + while (!connected) { + if ((nbAccess.begin(PINNUMBER) == NB_READY) && + (gprs.attachGPRS() == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET "); + client.print(path); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBSSLWebClient/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBWebClient/NBWebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBWebClient/NBWebClient.ino new file mode 100644 index 00000000..3e1e13db --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBWebClient/NBWebClient.ino @@ -0,0 +1,94 @@ +/* + Web client + + This sketch connects to a website through a MKR NB 1500 board. Specifically, + this example downloads the URL "http://example.org/" and + prints it to the Serial monitor. + + Circuit: + - MKR NB 1500 board + - Antenna + - SIM card with a data plan + + created 8 Mar 2012 + by Tom Igoe +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NBClient client; +GPRS gprs; +NB nbAccess; + +// URL, path and port (for example: example.org) +char server[] = "example.org"; +char path[] = "/"; +int port = 80; // port 80 is the default for HTTP + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Starting Arduino web client."); + // connection state + boolean connected = false; + + // After starting the modem with NB.begin() + // attach to the GPRS network with the APN, login and password + while (!connected) { + if ((nbAccess.begin(PINNUMBER) == NB_READY) && + (gprs.attachGPRS() == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected"); + // Make a HTTP request: + client.print("GET "); + client.print(path); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + Serial.print((char)client.read()); + } + + // if the server's disconnected, stop the client: + if (!client.available() && !client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + + // do nothing forevermore: + for (;;) + ; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBWebClient/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/NBWebClient/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/ReceiveSMS.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/ReceiveSMS.ino new file mode 100644 index 00000000..7a822c92 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/ReceiveSMS.ino @@ -0,0 +1,89 @@ +/* + SMS receiver + + This sketch, for the MKR NB 1500 board, waits for a SMS message + and displays it through the Serial port. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card that can receive SMS messages + + created 25 Feb 2012 + by Javier Zorzano / TD +*/ + +// include the NB library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instances +NB nbAccess; +NB_SMS sms; + +// Array to hold the number an SMS is retrieved from +char senderNumber[20]; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("SMS Messages Receiver"); + + // connection state + bool connected = false; + + // Start GSM connection + while (!connected) { + if (nbAccess.begin(PINNUMBER) == NB_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("NB initialized"); + Serial.println("Waiting for messages"); +} + +void loop() { + int c; + + // If there are any SMSs available() + if (sms.available()) { + Serial.println("Message received from:"); + + // Get remote number + sms.remoteNumber(senderNumber, 20); + Serial.println(senderNumber); + + // An example of message disposal + // Any messages starting with # should be discarded + if (sms.peek() == '#') { + Serial.println("Discarded SMS"); + sms.flush(); + } + + // Read message bytes and print them + while ((c = sms.read()) != -1) { + Serial.print((char)c); + } + + Serial.println("\nEND OF MESSAGE"); + + // Delete message from modem memory + sms.flush(); + Serial.println("MESSAGE DELETED"); + } + + delay(1000); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/ReceiveSMS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/SendSMS/SendSMS.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/SendSMS/SendSMS.ino new file mode 100644 index 00000000..662e40ff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/SendSMS/SendSMS.ino @@ -0,0 +1,100 @@ +/* + SMS sender + + This sketch, for the MKR NB 1500 board, sends an SMS message + you enter in the serial monitor. Connect your Arduino with the + SIM card, open the serial monitor, and wait for + the "READY" message to appear in the monitor. Next, type a + message to send and press "return". Make sure the serial + monitor is set to send a newline when you press return. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card that can send SMS + + created 25 Feb 2012 + by Tom Igoe +*/ + +// Include the NB library +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NB nbAccess; +NB_SMS sms; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("SMS Messages Sender"); + + // connection state + bool connected = false; + + // Start NB module + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (nbAccess.begin(PINNUMBER) == NB_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("NB initialized"); +} + +void loop() { + + Serial.print("Enter a mobile number: "); + char remoteNum[20]; // telephone number to send SMS + readSerial(remoteNum); + Serial.println(remoteNum); + + // SMS text + Serial.print("Now, enter SMS content: "); + char txtMsg[200]; + readSerial(txtMsg); + Serial.println("SENDING"); + Serial.println(); + Serial.println("Message:"); + Serial.println(txtMsg); + + // send the message + sms.beginSMS(remoteNum); + sms.print(txtMsg); + sms.endSMS(); + Serial.println("\nCOMPLETE!\n"); +} + +/* + Read input serial + */ +int readSerial(char result[]) { + int i = 0; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + result[i] = '\0'; + Serial.flush(); + return 0; + } + if (inChar != '\r') { + result[i] = inChar; + i++; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/SendSMS/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/SendSMS/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/SendSMS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino new file mode 100644 index 00000000..d3e5414a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/ChooseRadioAccessTechnology/ChooseRadioAccessTechnology.ino @@ -0,0 +1,133 @@ +/* + Radio Access Technology selection for Arduino MKR NB 1500 + + This sketch allows you to select your preferred 4G + Narrowband Radio Access Technology (RAT). + + You can choose among CAT-M1, NB-IoT or a combination of both. + + Selecting JUST ONE technology will speed up the modem's network + registration A LOT! + + The chosen configuration will be saved to modem's internal memory + and will be preserved through MKR NB 1500 sketch uploads. + + In order to change the RAT, you will need to run this sketch again. + + Circuit: + - MKR NB 1500 board + - Antenna + - SIM card + + Created 26 November 2018 + by Giampaolo Mancini + +*/ + +#include + +void setup() { + Serial.begin(115200); + while (!Serial); + + MODEM.begin(); + while (!MODEM.noop()); + + for (int i = 0; i < 80; i++) Serial.print("*"); + Serial.println(); + Serial.println("This sketch allows you to select your preferred"); + Serial.println("4G Narrowband Radio Access Technology (RAT)."); + Serial.println(); + Serial.println("You can choose among CAT-M1, NB-IoT or a combination of both."); + Serial.println(); + Serial.println("Selecting JUST ONE technology will speed up the modem's network registration A LOT!"); + Serial.println(); + Serial.println("The chosen configuration will be saved to modem's internal memory"); + Serial.println("and will be preserved through MKR NB 1500 sketch uploads."); + Serial.println(); + Serial.println("In order to change the RAT, you will need to run this sketch again."); + for (int i = 0; i < 80; i++) Serial.print("*"); + + Serial.println(); + Serial.println(); + Serial.println("Please choose your Radio Access Technology:"); + Serial.println(); + Serial.println(" 0 - CAT M1 only"); + Serial.println(" 1 - NB IoT only"); + Serial.println(" 2 - CAT M1 preferred, NB IoT as failover (default)"); + Serial.println(" 3 - NB IoT preferred, CAT M1 as failover"); + Serial.println(); +} + +void loop() { + String uratChoice; + + Serial.print("> "); + + Serial.setTimeout(-1); + while (Serial.available() == 0); + String uratInput = Serial.readStringUntil('\n'); + uratInput.trim(); + int urat = uratInput.toInt(); + Serial.println(urat); + + switch (urat) { + case 0: + uratChoice = "7"; + break; + case 1: + uratChoice = "8"; + break; + case 2: + uratChoice = "7,8"; + break; + case 3: + uratChoice = "8,7"; + break; + default: + Serial.println("Invalid input. Please, retry."); + return; + } + + setRAT(uratChoice); + apply(); + + Serial.println(); + Serial.println("Radio Access Technology selected."); + Serial.println("Now you can upload your 4G application sketch."); + while (true); +} + +bool setRAT(String choice) +{ + String response; + + Serial.print("Disconnecting from network: "); + MODEM.sendf("AT+COPS=2"); + MODEM.waitForResponse(2000); + Serial.println("done."); + + Serial.print("Setting Radio Access Technology: "); + MODEM.sendf("AT+URAT=%s", choice.c_str()); + MODEM.waitForResponse(2000, &response); + Serial.println("done."); + + return true; +} + +bool apply() +{ + Serial.print("Applying changes and saving configuration: "); + MODEM.send("AT+CFUN=15"); + MODEM.waitForResponse(5000); + delay(5000); + + do { + delay(1000); + MODEM.noop(); + } while (MODEM.waitForResponse(1000) != 1); + + Serial.println("done."); + + return true; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/NBScanNetworks.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/NBScanNetworks.ino new file mode 100644 index 00000000..0caaf86b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/NBScanNetworks.ino @@ -0,0 +1,90 @@ +/* + + NB Scan Networks + + This example prints out the IMEI number of the modem, + then checks to see if it's connected to a carrier. + Then it scans for nearby networks and prints out their signal strengths. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card + + Created 8 Mar 2012 + by Tom Igoe, implemented by Javier Carazo + Modified 4 Feb 2013 + by Scott Fitzgerald +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NB nbAccess; // include a 'true' parameter to enable debugging +NBScanner scannerNetworks; +NBModem modemTest; + +// Save data variables +String IMEI = ""; + +// serial monitor result messages +String errortext = "ERROR"; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + Serial.println("NB IoT/LTE Cat M1 networks scanner"); + scannerNetworks.begin(); + + // connection state + boolean connected = false; + + // Start module + // If your SIM has PIN, pass it as a parameter of begin() in quotes + while (!connected) { + if (nbAccess.begin(PINNUMBER) == NB_READY) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + // get modem parameters + // IMEI, modem unique identifier + Serial.print("Modem IMEI: "); + IMEI = modemTest.getIMEI(); + IMEI.replace("\n", ""); + if (IMEI != NULL) { + Serial.println(IMEI); + } +} + +void loop() { + // currently connected carrier + Serial.print("Current carrier: "); + Serial.println(scannerNetworks.getCurrentCarrier()); + + // returns strength and BER + // signal strength in 0-31 scale. 31 means power > 51dBm + // BER is the Bit Error Rate. 0-7 scale. 99=not detectable + Serial.print("Signal Strength: "); + Serial.print(scannerNetworks.getSignalStrength()); + Serial.println(" [0-31]"); + + // scan for existing networks, displays a list of networks + Serial.println("Scanning available networks. May take some seconds."); + Serial.println(scannerNetworks.readNetworks()); + // wait ten seconds before scanning again + delay(10000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/NBScanNetworks/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/PinManagement/PinManagement.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/PinManagement/PinManagement.ino new file mode 100644 index 00000000..425a15f3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/PinManagement/PinManagement.ino @@ -0,0 +1,142 @@ +/* + + This example enables you to change or remove the PIN number of + a SIM card inserted into a MKR NB 1500 board. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card + + Created 12 Jun 2012 + by David del Peral +*/ + +// libraries +#include + +// pin manager object +NBPIN PINManager; + +// save input in serial by user +String user_input = ""; + +// authenticated with PIN code +boolean auth = false; + +// serial monitor result messages +String oktext = "OK"; +String errortext = "ERROR"; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + Serial.println("Change PIN example\n"); + PINManager.begin(); + + // check if the SIM have pin lock + while (!auth) { + int pin_query = PINManager.isPIN(); + if (pin_query == 1) { + // if SIM is locked, enter PIN code + Serial.print("Enter PIN code: "); + user_input = readSerial(); + // check PIN code + if (PINManager.checkPIN(user_input) == 0) { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } else { + // if PIN code was incorrected + Serial.println("Incorrect PIN. Remember that you have 3 opportunities."); + } + } else if (pin_query == -1) { + // PIN code is locked, user must enter PUK code + Serial.println("PIN locked. Enter PUK code: "); + String puk = readSerial(); + Serial.print("Now, enter a new PIN code: "); + user_input = readSerial(); + // check PUK code + if (PINManager.checkPUK(puk, user_input) == 0) { + auth = true; + PINManager.setPINUsed(true); + Serial.println(oktext); + } else { + // if PUK o the new PIN are incorrect + Serial.println("Incorrect PUK or invalid new PIN. Try again!."); + } + } else if (pin_query == -2) { + // the worst case, PIN and PUK are locked + Serial.println("PIN and PUK locked. Use PIN2/PUK2 in a mobile phone."); + while (true); + } else { + // SIM does not requires authentication + Serial.println("No pin necessary."); + auth = true; + } + } + + // start module + Serial.print("Checking register in NB IoT / LTE Cat M1 network..."); + if (PINManager.checkReg() == 0) { + Serial.println(oktext); + } + // if you are connect by roaming + else if (PINManager.checkReg() == 1) { + Serial.println("ROAMING " + oktext); + } else { + // error connection + Serial.println(errortext); + while (true); + } +} + +void loop() { + // Function loop implements pin management user menu + // You can only change PIN code if your SIM uses pin lock + + Serial.println("Choose an option:\n1 - On/Off PIN."); + if (PINManager.getPINUsed()) { + Serial.println("2 - Change PIN."); + } + // save user input to user_op variable + String user_op = readSerial(); + if (user_op == "1") { + Serial.println("Enter your PIN code:"); + user_input = readSerial(); + // activate/deactivate PIN lock + PINManager.switchPIN(user_input); + } else if (user_op == "2" && PINManager.getPINUsed()) { + Serial.println("Enter your actual PIN code:"); + String oldPIN = readSerial(); + Serial.println("Now, enter your new PIN code:"); + String newPIN = readSerial(); + // change PIN + PINManager.changePIN(oldPIN, newPIN); + } else { + Serial.println("Incorrect option. Try again!."); + } + delay(1000); +} + +/* + Read serial input + */ +String readSerial() { + String text = ""; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + return text; + } + if (inChar != '\r') { + text += inChar; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/SerialSARAPassthrough/SerialSARAPassthrough.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/SerialSARAPassthrough/SerialSARAPassthrough.ino new file mode 100644 index 00000000..661d65ac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/SerialSARAPassthrough/SerialSARAPassthrough.ino @@ -0,0 +1,47 @@ +/* + SerialSARAPassthrough sketch + + This sketch allows you to send AT commands from the USB CDC serial port + of the MKR NB 1500 board to the onboard ublox SARA-R410 cellular module. + + For a list of supported AT commands see: + https://www.u-blox.com/sites/default/files/u-blox-CEL_ATCommands_%28UBX-13002752%29.pdf + + Circuit: + - MKR NB 1500 board + - Antenna + - SIM card + + Make sure the Serial Monitor's line ending is set to "Both NL and CR" or "Carriage Return" + + created 11 December 2017 + Sandeep Mistry +*/ + +// baud rate used for both Serial ports +unsigned long baud = 115200; + +void setup() { + // NEVER EVER use RESET_N + pinMode(SARA_RESETN, OUTPUT); + digitalWrite(SARA_RESETN, LOW); + + // Send Poweron pulse + pinMode(SARA_PWR_ON, OUTPUT); + digitalWrite(SARA_PWR_ON, HIGH); + delay(150); + digitalWrite(SARA_PWR_ON, LOW); + + Serial.begin(baud); + SerialSARA.begin(baud); +} + +void loop() { + if (Serial.available()) { + SerialSARA.write(Serial.read()); + } + + if (SerialSARA.available()) { + Serial.write(SerialSARA.read()); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/TestGPRS.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/TestGPRS.ino new file mode 100644 index 00000000..9485f5cf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/TestGPRS.ino @@ -0,0 +1,174 @@ +/* + + This sketch tests the MKR NB 1500 board's ability to connect to a + GPRS network. It asks for APN information through the + serial monitor and tries to connect to example.org. + + Circuit: + * MKR NB 1500 board + * Antenna + * SIM card with data plan + + Created 18 Jun 2012 + by David del Peral +*/ + +// libraries +#include + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +// PIN Number +const char PINNUMBER[] = SECRET_PINNUMBER; + +// initialize the library instance +NB nbAccess; // NB access: include a 'true' parameter for debug enabled +GPRS gprsAccess; // GPRS access +NBClient client; // Client service for TCP connection + +// messages for serial monitor response +String oktext = "OK"; +String errortext = "ERROR"; + +// URL and path (for example: example.org) +char url[] = "example.org"; +char urlproxy[] = "http://example.org"; +char path[] = "/"; + +// variable to save obtained response +String response = ""; + +// use a proxy +boolean use_proxy = false; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } +} + +void loop() { + use_proxy = false; + + // start module + // if your SIM has PIN, pass it as a parameter of begin() in quotes + Serial.print("Connecting NB IoT / LTE Cat M1 network..."); + if (nbAccess.begin(PINNUMBER) != NB_READY) { + Serial.println(errortext); + while (true); + } + Serial.println(oktext); + + // attach GPRS + Serial.println("Attaching to GPRS..."); + if (gprsAccess.attachGPRS() != GPRS_READY) { + Serial.println(errortext); + } else { + + Serial.println(oktext); + + // read proxy introduced by user + char proxy[100]; + Serial.print("If your carrier uses a proxy, enter it, if not press enter: "); + readSerial(proxy); + Serial.println(proxy); + + // if user introduced a proxy, asks them for proxy port + int pport; + if (proxy[0] != '\0') { + // read proxy port introduced by user + char proxyport[10]; + Serial.print("Enter the proxy port: "); + readSerial(proxyport); + // cast proxy port introduced to integer + pport = (int) proxyport; + use_proxy = true; + Serial.println(proxyport); + } + + // connection with example.org and realize HTTP request + Serial.print("Connecting and sending GET request to example.org..."); + int res_connect; + + // if use a proxy, connect with it + if (use_proxy) { + res_connect = client.connect(proxy, pport); + } else { + res_connect = client.connect(url, 80); + } + + if (res_connect) { + // make a HTTP 1.0 GET request (client sends the request) + client.print("GET "); + + // if using a proxy, the path is example.org URL + if (use_proxy) { + client.print(urlproxy); + } else { + client.print(path); + } + + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(url); + client.println("Connection: close"); + client.println(); + Serial.println(oktext); + } else { + // if you didn't get a connection to the server + Serial.println(errortext); + } + Serial.print("Receiving response..."); + + boolean test = true; + while (test) { + // if there are incoming bytes available + // from the server, read and check them + if (client.available()) { + char c = client.read(); + response += c; + + // cast response obtained from string to char array + char responsechar[response.length() + 1]; + response.toCharArray(responsechar, response.length() + 1); + + // if response includes a "200 OK" substring + if (strstr(responsechar, "200 OK") != NULL) { + Serial.println(oktext); + Serial.println("TEST COMPLETE!"); + test = false; + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + test = false; + } + } + } +} + +/* + Read input serial + */ +int readSerial(char result[]) { + int i = 0; + while (1) { + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (inChar == '\n') { + result[i] = '\0'; + return 0; + } + if (inChar != '\r') { + result[i] = inChar; + i++; + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/arduino_secrets.h new file mode 100644 index 00000000..9dca07aa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestGPRS/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_PINNUMBER "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestModem/TestModem.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestModem/TestModem.ino new file mode 100644 index 00000000..cb466155 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRNB/examples/Tools/TestModem/TestModem.ino @@ -0,0 +1,65 @@ +/* + + This example tests to see if the modem of the + MKR NB 1500 board is working correctly. You do not need + a SIM card for this example. + + Circuit: + * MKR NB 1500 board + * Antenna + + Created 12 Jun 2012 + by David del Peral + modified 21 Nov 2012 + by Tom Igoe +*/ + +// libraries +#include + +// modem verification object +NBModem modem; + +// IMEI variable +String IMEI = ""; + +void setup() { + // initialize serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for Leonardo only + } + + // start modem test (reset and check response) + Serial.print("Starting modem test..."); + if (modem.begin()) { + Serial.println("modem.begin() succeeded"); + } else { + Serial.println("ERROR, no modem answer."); + } +} + +void loop() { + // get modem IMEI + Serial.print("Checking IMEI..."); + IMEI = modem.getIMEI(); + + // check IMEI response + if (IMEI != NULL) { + // show IMEI in serial monitor + Serial.println("Modem's IMEI: " + IMEI); + // reset modem to check booting: + Serial.print("Resetting modem..."); + modem.begin(); + // get and check IMEI one more time + if (modem.getIMEI() != NULL) { + Serial.println("Modem is functioning properly"); + } else { + Serial.println("Error: getIMEI() failed after modem.begin()"); + } + } else { + Serial.println("Error: Could not get IMEI"); + } + // do nothing: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/COPYING b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/COPYING new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/COPYING.LESSER b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/COPYING.LESSER new file mode 100644 index 00000000..0a041280 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/README.md new file mode 100644 index 00000000..06ee544d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/README.md @@ -0,0 +1,32 @@ +# MKRWAN + +[![Check Arduino status](https://github.com/arduino-libraries/MKRWAN/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/MKRWAN/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/MKRWAN/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN/actions/workflows/spell-check.yml) + +Provides APIs to communicate with LoRa and LoRaWAN networks + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/MKRWAN + +If you are looking for the firmware running on Murata CMWX1ZZABZ-078 module, the complete source code is hosted at https://github.com/arduino/mkrwan1300-fw + +## License + +Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) + +Based on the TinyGSM library https://github.com/vshymanskyy/TinyGSM +Copyright (c) 2016 Volodymyr Shymanskyy + +MKR WAN library is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MKR WAN library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with MKR WAN library. If not, see . diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/DumbModemLoraSender/DumbModemLoraSender.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/DumbModemLoraSender/DumbModemLoraSender.ino new file mode 100644 index 00000000..73951c8a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/DumbModemLoraSender/DumbModemLoraSender.ino @@ -0,0 +1,54 @@ +/* This example shows how to use the SX1272 chip + * (part of Murata module) without any external stack. + * To achieve this, we must setup the modem in dumb mode + * and use LORA_IRQ_DUMB pin as chip select and SPI1 as communication port. + * + * The example is based on LoraSender by @sandeepmistry arduino-LoRa library + * https://github.com/sandeepmistry/arduino-LoRa + * + * Starting from https://github.com/sandeepmistry/arduino-LoRa/commit/5f62ed2ce9d1623bfc12f468b8152ba1878b5b16, + * LoRa library knows about MKR WAN 1300/1310 and automatically restarts the module in dumb mode, uses SPI1 and the correct GPIOs. + * + * Since there is no IRQ pin available, the host must poll for data (unfortunately) + * + */ + +#include +#include +//#include + +int counter = 0; + +//LoRaModem modem; + +void setup() { + Serial.begin(9600); + while (!Serial); + + // No need to call modem.dumb() with arduino-LoRa >= 0.5.0 + //modem.dumb(); + + Serial.println("LoRa Sender"); + + // Configure LoRa module to transmit and receive at 915 MHz (915*10^6) + // Replace 915E6 with the frequency you need (eg. 433E6 for 433 MHz) + if (!LoRa.begin(915E6)) { + Serial.println("Starting LoRa failed!"); + while (1); + } +} + +void loop() { + Serial.print("Sending packet: "); + Serial.println(counter); + + // send packet + LoRa.beginPacket(); + LoRa.print("hello "); + LoRa.print(counter); + LoRa.endPacket(); + + counter++; + + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/FWUpdaterBridge/FWUpdaterBridge.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/FWUpdaterBridge/FWUpdaterBridge.ino new file mode 100644 index 00000000..59a6e32c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/FWUpdaterBridge/FWUpdaterBridge.ino @@ -0,0 +1,63 @@ +/* + FW Updater Bridge + This sketch demonstrates how to update the FW on the MKR WAN 1300/1310 LoRa module. + Once flashed it should be used in conjunction with stm32flash utility (https://github.com/facchinm/stm32flash) + + This example code is in the public domain. +*/ + +#define Serial1 Serial + +void setup() { + Serial1.begin(115200, SERIAL_8E1); + Serial2.begin(115200, SERIAL_8E1); + + delay(1000); + + pinMode(LED_BUILTIN, OUTPUT); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(200); + digitalWrite(LORA_RESET, LOW); + delay(200); + digitalWrite(LORA_RESET, HIGH); +} + +void resetModule() { + Serial.println("resetting module"); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + + while (!Serial); +} + +char rx_buf[512]; +char tx_buf[512]; + +int rx = 0; +int tx = 0; + +void loop() { + while (Serial1.available()) { // If anything comes in Serial (USB), + tx_buf[tx++] = Serial1.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (tx > 0) { + Serial2.write(tx_buf, tx); + tx = 0; + } + + while (Serial2.available()) { // If anything comes in Serial (USB), + rx_buf[rx++] = Serial2.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (rx > 0) { + Serial1.write(rx_buf, rx); + rx = 0; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/FirstConfiguration/FirstConfiguration.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/FirstConfiguration/FirstConfiguration.ino new file mode 100644 index 00000000..987bbc7a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/FirstConfiguration/FirstConfiguration.ino @@ -0,0 +1,106 @@ +/* + First Configuration + This sketch demonstrates the usage of MKR WAN 1300/1310 LoRa module. + This example code is in the public domain. +*/ + +#include + +LoRaModem modem; + +// Uncomment if using the Murata chip as a module +// LoRaModem modem(Serial1); + +String appEui; +String appKey; +String devAddr; +String nwkSKey; +String appSKey; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial); + Serial.println("Welcome to MKR WAN 1300/1310 first configuration sketch"); + Serial.println("Register to your favourite LoRa network and we are ready to go!"); + // change this to your regional band (eg. US915, AS923, ...) + if (!modem.begin(EU868)) { + Serial.println("Failed to start module"); + while (1) {} + }; + Serial.print("Your module version is: "); + Serial.println(modem.version()); + if (modem.version() != ARDUINO_FW_VERSION) { + Serial.println("Please make sure that the latest modem firmware is installed."); + Serial.println("To update the firmware upload the 'MKRWANFWUpdate_standalone.ino' sketch."); + } + Serial.print("Your device EUI is: "); + Serial.println(modem.deviceEUI()); + + int mode = 0; + while (mode != 1 && mode != 2) { + Serial.println("Are you connecting via OTAA (1) or ABP (2)?"); + while (!Serial.available()); + mode = Serial.readStringUntil('\n').toInt(); + } + + int connected; + if (mode == 1) { + Serial.println("Enter your APP EUI"); + while (!Serial.available()); + appEui = Serial.readStringUntil('\n'); + + Serial.println("Enter your APP KEY"); + while (!Serial.available()); + appKey = Serial.readStringUntil('\n'); + + appKey.trim(); + appEui.trim(); + + connected = modem.joinOTAA(appEui, appKey); + } else if (mode == 2) { + + Serial.println("Enter your Device Address"); + while (!Serial.available()); + devAddr = Serial.readStringUntil('\n'); + + Serial.println("Enter your NWS KEY"); + while (!Serial.available()); + nwkSKey = Serial.readStringUntil('\n'); + + Serial.println("Enter your APP SKEY"); + while (!Serial.available()); + appSKey = Serial.readStringUntil('\n'); + + devAddr.trim(); + nwkSKey.trim(); + appSKey.trim(); + + connected = modem.joinABP(devAddr, nwkSKey, appSKey); + } + + if (!connected) { + Serial.println("Something went wrong; are you indoor? Move near a window and retry"); + while (1) {} + } + + delay(5000); + + int err; + modem.setPort(3); + modem.beginPacket(); + modem.print("HeLoRA world!"); + err = modem.endPacket(true); + if (err > 0) { + Serial.println("Message sent correctly!"); + } else { + Serial.println("Error sending message :("); + } +} + +void loop() { + while (modem.available()) { + Serial.write(modem.read()); + } + modem.poll(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/LoraSendAndReceive.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/LoraSendAndReceive.ino new file mode 100644 index 00000000..a10845fe --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/LoraSendAndReceive.ino @@ -0,0 +1,91 @@ +/* + Lora Send And Receive + This sketch demonstrates how to send and receive data with the MKR WAN 1300/1310 LoRa module. + This example code is in the public domain. +*/ + +#include + +LoRaModem modem; + +// Uncomment if using the Murata chip as a module +// LoRaModem modem(Serial1); + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +String appEui = SECRET_APP_EUI; +String appKey = SECRET_APP_KEY; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial); + // change this to your regional band (eg. US915, AS923, ...) + if (!modem.begin(EU868)) { + Serial.println("Failed to start module"); + while (1) {} + }; + Serial.print("Your module version is: "); + Serial.println(modem.version()); + Serial.print("Your device EUI is: "); + Serial.println(modem.deviceEUI()); + + int connected = modem.joinOTAA(appEui, appKey); + if (!connected) { + Serial.println("Something went wrong; are you indoor? Move near a window and retry"); + while (1) {} + } + + // Set poll interval to 60 secs. + modem.minPollInterval(60); + // NOTE: independent of this setting, the modem will + // not allow sending more than one message every 2 minutes, + // this is enforced by firmware and can not be changed. +} + +void loop() { + Serial.println(); + Serial.println("Enter a message to send to network"); + Serial.println("(make sure that end-of-line 'NL' is enabled)"); + + while (!Serial.available()); + String msg = Serial.readStringUntil('\n'); + + Serial.println(); + Serial.print("Sending: " + msg + " - "); + for (unsigned int i = 0; i < msg.length(); i++) { + Serial.print(msg[i] >> 4, HEX); + Serial.print(msg[i] & 0xF, HEX); + Serial.print(" "); + } + Serial.println(); + + int err; + modem.beginPacket(); + modem.print(msg); + err = modem.endPacket(true); + if (err > 0) { + Serial.println("Message sent correctly!"); + } else { + Serial.println("Error sending message :("); + Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength"); + Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)"); + } + delay(1000); + if (!modem.available()) { + Serial.println("No downlink message received at this time."); + return; + } + char rcv[64]; + int i = 0; + while (modem.available()) { + rcv[i++] = (char)modem.read(); + } + Serial.print("Received: "); + for (unsigned int j = 0; j < i; j++) { + Serial.print(rcv[j] >> 4, HEX); + Serial.print(rcv[j] & 0xF, HEX); + Serial.print(" "); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/arduino_secrets.h new file mode 100644 index 00000000..3abaf3f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/LoraSendAndReceive/arduino_secrets.h @@ -0,0 +1,3 @@ +// Replace with keys obtained from TheThingsNetwork console +#define SECRET_APP_EUI "xxxxxxxxxxxxx" +#define SECRET_APP_KEY "yyyyyyyyyyyyyyyyyyyyyyy" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino new file mode 100644 index 00000000..bf5c49d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino @@ -0,0 +1,376 @@ +/* + * STANDALONE FIRMWARE UPDATE FOR MKR WAN 1300/1310 + * This sketch implements STM32 bootloader protocol + * It is based on stm32flash (mirrored here git@github.com:facchinm/stm32flash.git) + * with as little modifications as possible. + * + * To generate it after a firmware update, execute + * + * echo -n "const " > fw.h && xxd -i mlm32l07x01.bin >> fw.h + * + */ + + +#include "fw.h" +#include "stm32.h" +#include "serial_arduino.h" +#include + +/* device globals */ +stm32_t *stm = NULL; +void *p_st = NULL; + +int ret = -1; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + + while (!Serial); + + struct port_interface port; + struct port_options port_opts = { + .baudRate = 115200, + .serial_mode = SERIAL_8E1 + }; + + port.flags = PORT_CMD_INIT | PORT_GVR_ETX | PORT_BYTE | PORT_RETRY; + port.dev = &SerialLoRa; + port.ops = &port_opts; + + assignCallbacks(&port); + + pinMode(LED_BUILTIN, OUTPUT); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(200); + digitalWrite(LORA_RESET, LOW); + delay(200); + digitalWrite(LORA_RESET, HIGH); + delay(200); + + Serial.println("Press a key to start FW update"); + port.open(&port); + //port.flush(&port); + + stm = stm32_init(&port, 1); + + fprintf(diag, "Version : 0x%02x\n", stm->bl_version); + if (port.flags & PORT_GVR_ETX) { + fprintf(diag, "Option 1 : 0x%02x\n", stm->option1); + fprintf(diag, "Option 2 : 0x%02x\n", stm->option2); + } + fprintf(diag, "Device ID : 0x%04x (%s)\n", stm->pid, stm->dev->name); + fprintf(diag, "- RAM : Up to %dKiB (%db reserved by bootloader)\n", (stm->dev->ram_end - 0x20000000) / 1024, stm->dev->ram_start - 0x20000000); + fprintf(diag, "- Flash : Up to %dKiB (size first sector: %dx%d)\n", (stm->dev->fl_end - stm->dev->fl_start ) / 1024, stm->dev->fl_pps, stm->dev->fl_ps[0]); + fprintf(diag, "- Option RAM : %db\n", stm->dev->opt_end - stm->dev->opt_start + 1); + fprintf(diag, "- System RAM : %dKiB\n", (stm->dev->mem_end - stm->dev->mem_start) / 1024); + + uint8_t buffer[256]; + uint32_t addr, start, end; + unsigned int len; + int failed = 0; + int first_page, num_pages; + + int npages = mlm32l07x01_bin_len / 128 + 1; + int spage = 0; + bool verify = 1; + int retry = 10; + bool reset_flag = 0; + bool exec_flag = 1; + int execute = 0; // address + + /* + Cleanup addresses: + + Starting from options + start_addr, readwrite_len, spage, npages + and using device memory size, compute + start, end, first_page, num_pages + */ + if (!npages) { + start = stm->dev->fl_start; + end = stm->dev->fl_end; + first_page = 0; + num_pages = STM32_MASS_ERASE; + } else { + first_page = spage; + start = flash_page_to_addr(first_page); + if (start > stm->dev->fl_end) { + fprintf(stderr, "Address range exceeds flash size.\n"); + ret = -1; + return; + } + + if (npages) { + num_pages = npages; + end = flash_page_to_addr(first_page + num_pages); + if (end > stm->dev->fl_end) + end = stm->dev->fl_end; + } else { + end = stm->dev->fl_end; + num_pages = flash_addr_to_page_ceil(end) - first_page; + } + + if (!first_page && end == stm->dev->fl_end) + num_pages = STM32_MASS_ERASE; + } + + ret = 0; + int s_err; + +#if 0 + fprintf(diag, "Erasing flash\n"); + + if (num_pages != STM32_MASS_ERASE && + (start != flash_page_to_addr(first_page) + || end != flash_page_to_addr(first_page + num_pages))) { + fprintf(stderr, "Specified start & length are invalid (must be page aligned)\n"); + ret = 1; + return; + } + + s_err = stm32_erase_memory(stm, first_page, num_pages); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to erase memory\n"); + ret = 1; + return; + } + ret = 0; + +#endif + + fprintf(diag, "Write to memory\n"); + + off_t offset = 0; + ssize_t r; + unsigned int size; + unsigned int max_wlen, max_rlen; + +#define STM32_MAX_RX_FRAME 256 /* cmd read memory */ +#define STM32_MAX_TX_FRAME (1 + 256 + 1) /* cmd write memory */ + + max_wlen = STM32_MAX_TX_FRAME - 2; /* skip len and crc */ + max_wlen &= ~3; /* 32 bit aligned */ + + max_rlen = STM32_MAX_RX_FRAME; + max_rlen = max_rlen < max_wlen ? max_rlen : max_wlen; + + /* Assume data from stdin is whole device */ + size = end - start; + + // TODO: It is possible to write to non-page boundaries, by reading out flash + // from partial pages and combining with the input data + // if ((start % stm->dev->fl_ps[i]) != 0 || (end % stm->dev->fl_ps[i]) != 0) { + // fprintf(stderr, "Specified start & length are invalid (must be page aligned)\n"); + // goto close; + // } + + // TODO: If writes are not page aligned, we should probably read out existing flash + // contents first, so it can be preserved and combined with new data + if (num_pages) { + fprintf(diag, "Erasing memory\n"); + s_err = stm32_erase_memory(stm, first_page, num_pages); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to erase memory\n"); + ret = -1; + return; + } + } + + addr = start; + while (addr < end && offset < size) { + uint32_t left = end - addr; + len = max_wlen > left ? left : max_wlen; + len = len > size - offset ? size - offset : len; + + memcpy(buffer, &mlm32l07x01_bin[offset], len); + + if (len == 0) { + fprintf(stderr, "Failed to read input file\n"); + ret = -1; + return; + } + +again: + s_err = stm32_write_memory(stm, addr, buffer, len); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to write memory at address 0x%08x\n", addr); + ret = -1; + return; + } + + if (verify) { + uint8_t compare[len]; + unsigned int offset, rlen; + + offset = 0; + while (offset < len) { + rlen = len - offset; + rlen = rlen < max_rlen ? rlen : max_rlen; + s_err = stm32_read_memory(stm, addr + offset, compare + offset, rlen); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to read memory at address 0x%08x\n", addr + offset); + ret = -1; + return; + } + offset += rlen; + } + + for (r = 0; r < len; ++r) + if (buffer[r] != compare[r]) { + if (failed == retry) { + fprintf(stderr, "Failed to verify at address 0x%08x, expected 0x%02x and found 0x%02x\n", + (uint32_t)(addr + r), + buffer [r], + compare[r] + ); + ret = -1; + return; + } + ++failed; + goto again; + } + + failed = 0; + } + + addr += len; + offset += len; + + fprintf(diag, + "Wrote %saddress 0x%08x (%d%%)\n ", + verify ? "and verified " : "", + addr, + 100 * offset / size + ); + + } + + fprintf(diag, "Done.\n"); + ret = 0; + + if (stm && exec_flag && ret == 0) { + if (execute == 0) + execute = stm->dev->fl_start; + + fprintf(diag, "\nStarting execution at address 0x%08x... ", execute); + if (stm32_go(stm, execute) == STM32_ERR_OK) { + reset_flag = 0; + fprintf(diag, "done.\n"); + } else + fprintf(diag, "failed.\n"); + } +} + +void resetModuleRunning() { + digitalWrite(LORA_BOOT0, LOW); + SerialLoRa.end(); + SerialLoRa.begin(19200); + delay(100); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + delay(100); +} + +void loop() { + // put your main code here, to run repeatedly: + if (ret == 0) { + Serial.println("Flashing ok :)"); + SerialLoRa.end(); + LoRaModem* modem = new LoRaModem(); + modem->begin(EU868); + Serial.println(modem->version()); + } + while (1); +} + +static int is_addr_in_ram(uint32_t addr) +{ + return addr >= stm->dev->ram_start && addr < stm->dev->ram_end; +} + +static int is_addr_in_flash(uint32_t addr) +{ + return addr >= stm->dev->fl_start && addr < stm->dev->fl_end; +} + +static int is_addr_in_opt_bytes(uint32_t addr) +{ + /* option bytes upper range is inclusive in our device table */ + return addr >= stm->dev->opt_start && addr <= stm->dev->opt_end; +} + +static int is_addr_in_sysmem(uint32_t addr) +{ + return addr >= stm->dev->mem_start && addr < stm->dev->mem_end; +} + +/* returns the page that contains address "addr" */ +static int flash_addr_to_page_floor(uint32_t addr) +{ + int page; + uint32_t *psize; + + if (!is_addr_in_flash(addr)) + return 0; + + page = 0; + addr -= stm->dev->fl_start; + psize = stm->dev->fl_ps; + + while (addr >= psize[0]) { + addr -= psize[0]; + page++; + if (psize[1]) + psize++; + } + + return page; +} + +/* returns the first page whose start addr is >= "addr" */ +int flash_addr_to_page_ceil(uint32_t addr) +{ + int page; + uint32_t *psize; + + if (!(addr >= stm->dev->fl_start && addr <= stm->dev->fl_end)) + return 0; + + page = 0; + addr -= stm->dev->fl_start; + psize = stm->dev->fl_ps; + + while (addr >= psize[0]) { + addr -= psize[0]; + page++; + if (psize[1]) + psize++; + } + + return addr ? page + 1 : page; +} + +/* returns the lower address of flash page "page" */ +static uint32_t flash_page_to_addr(int page) +{ + int i; + uint32_t addr, *psize; + + addr = stm->dev->fl_start; + psize = stm->dev->fl_ps; + + for (i = 0; i < page; i++) { + addr += psize[0]; + if (psize[1]) + psize++; + } + + return addr; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.cpp new file mode 100644 index 00000000..6f12c57a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.cpp @@ -0,0 +1,45 @@ +#include "serial_arduino.h" + + +static port_err_t arduino_serial_open(struct port_interface *port) { + port->dev->begin(port->ops->baudRate, port->ops->serial_mode); + return PORT_ERR_OK; +} + +static port_err_t arduino_close(struct port_interface *port) { + return PORT_ERR_OK; +} + +static port_err_t arduino_flush(struct port_interface *port) { + port->dev->flush(); + return PORT_ERR_OK; +} + +static port_err_t arduino_read(struct port_interface *port, void *buf, size_t nbyte) { + uint8_t *pos = (uint8_t*)buf; + while (nbyte) { + if (port->dev->available()) { + int c = port->dev->read(); + if (c < 0) { + return PORT_ERR_UNKNOWN; + } + pos[0] = (uint8_t)c; + nbyte--; + pos++; + } + } + return PORT_ERR_OK; +} + +static port_err_t arduino_write(struct port_interface *port, void *buf, size_t nbyte) { + port->dev->write((uint8_t*)buf, nbyte); + return PORT_ERR_OK; +} + +void assignCallbacks(struct port_interface *port) { + port->open = arduino_serial_open; + port->close = arduino_close; + port->flush = arduino_flush; + port->read = arduino_read; + port->write = arduino_write; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.h new file mode 100644 index 00000000..1467f26b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/serial_arduino.h @@ -0,0 +1,69 @@ +#ifndef _H_PORT +#define _H_PORT + +#include "Arduino.h" + +#define usleep(x) delayMicroseconds(x) + +#ifndef __MBED__ +#include "Uart.h" +#define UART Uart +#endif + +#define fprintf(output, ...) { \ + do { \ + char string[100]; \ + sprintf (string, __VA_ARGS__); \ + Serial.print(string); \ + } while (0); \ + } + +/* flags */ +#define PORT_BYTE (1 << 0) /* byte (not frame) oriented */ +#define PORT_GVR_ETX (1 << 1) /* cmd GVR returns protection status */ +#define PORT_CMD_INIT (1 << 2) /* use INIT cmd to autodetect speed */ +#define PORT_RETRY (1 << 3) /* allowed read() retry after timeout */ +#define PORT_STRETCH_W (1 << 4) /* warning for no-stretching commands */ + +/* all options and flags used to open and configure an interface */ +struct port_options { + int baudRate; + int serial_mode; +}; + +/* + * Specify the length of reply for command GET + * This is helpful for frame-oriented protocols, e.g. i2c, to avoid time + * consuming try-fail-timeout-retry operation. + * On byte-oriented protocols, i.e. UART, this information would be skipped + * after read the first byte, so not needed. + */ +struct varlen_cmd { + uint8_t version; + uint8_t length; +}; + +typedef enum { + PORT_ERR_OK = 0, + PORT_ERR_NODEV, /* No such device */ + PORT_ERR_TIMEDOUT, /* Operation timed out */ + PORT_ERR_UNKNOWN, +} port_err_t; + +struct port_interface { + const char *name; + unsigned flags; + port_err_t (*open)(struct port_interface *port); + port_err_t (*close)(struct port_interface *port); + port_err_t (*flush)(struct port_interface *port); + port_err_t (*read)(struct port_interface *port, void *buf, size_t nbyte); + port_err_t (*write)(struct port_interface *port, void *buf, size_t nbyte); + struct varlen_cmd *cmd_get_reply = NULL; + UART *dev; + struct port_options *ops; +}; + +void assignCallbacks(struct port_interface *port); + + +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/stm32.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/stm32.h new file mode 100644 index 00000000..9df91fd0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/stm32.h @@ -0,0 +1,90 @@ +/* + stm32flash - Open Source ST STM32 flash program for *nix + Copyright (C) 2010 Geoffrey McRae + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + + +#ifndef _STM32_H +#define _STM32_H + +#include + +#define STM32_MAX_RX_FRAME 256 /* cmd read memory */ +#define STM32_MAX_TX_FRAME (1 + 256 + 1) /* cmd write memory */ + +#define STM32_MAX_PAGES 0x0000ffff +#define STM32_MASS_ERASE 0x00100000 /* > 2 x max_pages */ + +typedef enum { + STM32_ERR_OK = 0, + STM32_ERR_UNKNOWN, /* Generic error */ + STM32_ERR_NACK, + STM32_ERR_NO_CMD, /* Command not available in bootloader */ +} stm32_err_t; + +typedef enum { + F_NO_ME = 1 << 0, /* Mass-Erase not supported */ + F_OBLL = 1 << 1, /* OBL_LAUNCH required */ +} flags_t; + +typedef struct stm32 stm32_t; +typedef struct stm32_cmd stm32_cmd_t; +typedef struct stm32_dev stm32_dev_t; + +struct stm32 { + struct port_interface *port; + uint8_t bl_version; + uint8_t version; + uint8_t option1, option2; + uint16_t pid; + stm32_cmd_t *cmd; + const stm32_dev_t *dev; +}; + +struct stm32_dev { + uint16_t id; + const char *name; + uint32_t ram_start, ram_end; + uint32_t fl_start, fl_end; + uint16_t fl_pps; // pages per sector + uint32_t *fl_ps; // page size + uint32_t opt_start, opt_end; + uint32_t mem_start, mem_end; + uint32_t flags; +}; + +stm32_t *stm32_init(struct port_interface *port, const char init); +void stm32_close(stm32_t *stm); +stm32_err_t stm32_read_memory(const stm32_t *stm, uint32_t address, + uint8_t data[], unsigned int len); +stm32_err_t stm32_write_memory(const stm32_t *stm, uint32_t address, + const uint8_t data[], unsigned int len); +stm32_err_t stm32_wunprot_memory(const stm32_t *stm); +stm32_err_t stm32_wprot_memory(const stm32_t *stm); +stm32_err_t stm32_erase_memory(const stm32_t *stm, uint32_t spage, + int32_t pages); +stm32_err_t stm32_go(const stm32_t *stm, uint32_t address); +stm32_err_t stm32_reset_device(const stm32_t *stm); +stm32_err_t stm32_readprot_memory(const stm32_t *stm); +stm32_err_t stm32_runprot_memory(const stm32_t *stm); +stm32_err_t stm32_crc_memory(const stm32_t *stm, uint32_t address, + uint32_t length, uint32_t *crc); +stm32_err_t stm32_crc_wrapper(const stm32_t *stm, uint32_t address, + uint32_t length, uint32_t *crc); +uint32_t stm32_sw_crc(uint32_t crc, uint8_t *buf, unsigned int len); + +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.c b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.c new file mode 100644 index 00000000..271bb3ed --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.c @@ -0,0 +1,45 @@ +/* + stm32flash - Open Source ST STM32 flash program for *nix + Copyright (C) 2010 Geoffrey McRae + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + +#include +#include "utils.h" + +/* detect CPU endian */ +char cpu_le() { + const uint32_t cpu_le_test = 0x12345678; + return ((const unsigned char*)&cpu_le_test)[0] == 0x78; +} + +uint32_t be_u32(const uint32_t v) { + if (cpu_le()) + return ((v & 0xFF000000) >> 24) | + ((v & 0x00FF0000) >> 8) | + ((v & 0x0000FF00) << 8) | + ((v & 0x000000FF) << 24); + return v; +} + +uint32_t le_u32(const uint32_t v) { + if (!cpu_le()) + return ((v & 0xFF000000) >> 24) | + ((v & 0x00FF0000) >> 8) | + ((v & 0x0000FF00) << 8) | + ((v & 0x000000FF) << 24); + return v; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.h new file mode 100644 index 00000000..07395d31 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN/examples/MKRWANFWUpdate_standalone/utils.h @@ -0,0 +1,33 @@ +/* + stm32flash - Open Source ST STM32 flash program for *nix + Copyright (C) 2010 Geoffrey McRae + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +*/ + + +#ifndef _H_UTILS +#define _H_UTILS + +#include +#include + +char cpu_le(); +uint32_t be_u32(const uint32_t v); +uint32_t le_u32(const uint32_t v); + +void printStatus(FILE *fd, int condition); + +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/COPYING b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/COPYING new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/COPYING @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/COPYING.LESSER b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/COPYING.LESSER new file mode 100644 index 00000000..0a041280 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/COPYING.LESSER @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/README.md new file mode 100644 index 00000000..d9294d67 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/README.md @@ -0,0 +1,36 @@ +# MKRWAN_v2 + +[![Check Arduino status](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/MKRWAN_v2/actions/workflows/spell-check.yml) + +Provides APIs to communicate with LoRa and LoraWAN networks + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/MKRWAN + +If you are looking for the firmware running on Murata CMWX1ZZABZ-078 module, the complete source code is hosted at https://github.com/arduino/mkrwan1300-fw + +This version of the library tracks https://github.com/arduino/mkrwan1300-fw/tree/master-1.3.1 , which is based on almost clean ST sources. + +The firmware update sketch should be flashed accordingly to the MKRWAN_v2 library version in use. + +## License + +Copyright (C) 2017 Arduino AG (http://www.arduino.cc/) + +Based on the TinyGSM library https://github.com/vshymanskyy/TinyGSM +Copyright (c) 2016 Volodymyr Shymanskyy + +MKRWAN_v2 library is free software: you can redistribute it and/or modify +it under the terms of the GNU Lesser General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +MKRWAN_v2 library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public License +along with MKRWAN_v2 library. If not, see . diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/FWUpdaterBridge/FWUpdaterBridge.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/FWUpdaterBridge/FWUpdaterBridge.ino new file mode 100644 index 00000000..59a6e32c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/FWUpdaterBridge/FWUpdaterBridge.ino @@ -0,0 +1,63 @@ +/* + FW Updater Bridge + This sketch demonstrates how to update the FW on the MKR WAN 1300/1310 LoRa module. + Once flashed it should be used in conjunction with stm32flash utility (https://github.com/facchinm/stm32flash) + + This example code is in the public domain. +*/ + +#define Serial1 Serial + +void setup() { + Serial1.begin(115200, SERIAL_8E1); + Serial2.begin(115200, SERIAL_8E1); + + delay(1000); + + pinMode(LED_BUILTIN, OUTPUT); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(200); + digitalWrite(LORA_RESET, LOW); + delay(200); + digitalWrite(LORA_RESET, HIGH); +} + +void resetModule() { + Serial.println("resetting module"); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + + while (!Serial); +} + +char rx_buf[512]; +char tx_buf[512]; + +int rx = 0; +int tx = 0; + +void loop() { + while (Serial1.available()) { // If anything comes in Serial (USB), + tx_buf[tx++] = Serial1.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (tx > 0) { + Serial2.write(tx_buf, tx); + tx = 0; + } + + while (Serial2.available()) { // If anything comes in Serial (USB), + rx_buf[rx++] = Serial2.read(); // read it and send it out Serial1 (pins 0 & 1) + } + + if (rx > 0) { + Serial1.write(rx_buf, rx); + rx = 0; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/FirstConfiguration/FirstConfiguration.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/FirstConfiguration/FirstConfiguration.ino new file mode 100644 index 00000000..3c8646b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/FirstConfiguration/FirstConfiguration.ino @@ -0,0 +1,102 @@ +/* + First Configuration + This sketch demonstrates the usage of MKR WAN 1300/1310 LoRa module. + This example code is in the public domain. +*/ + +#include + +LoRaModem modem; + +// Uncomment if using the Murata chip as a module +// LoRaModem modem(Serial1); + +String appEui; +String appKey; +String devAddr; +String nwkSKey; +String appSKey; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial); + Serial.println("Welcome to MKR WAN 1300/1310 first configuration sketch"); + Serial.println("Register to your favourite LoRa network and we are ready to go!"); + // change this to your regional band (eg. US915, AS923, ...) + if (!modem.begin(EU868)) { + Serial.println("Failed to start module"); + while (1) {} + }; + Serial.print("Your module version is: "); + Serial.println(modem.version()); + Serial.print("Your device EUI is: "); + Serial.println(modem.deviceEUI()); + + int mode = 0; + while (mode != 1 && mode != 2) { + Serial.println("Are you connecting via OTAA (1) or ABP (2)?"); + while (!Serial.available()); + mode = Serial.readStringUntil('\n').toInt(); + } + + int connected; + if (mode == 1) { + Serial.println("Enter your APP EUI"); + while (!Serial.available()); + appEui = Serial.readStringUntil('\n'); + + Serial.println("Enter your APP KEY"); + while (!Serial.available()); + appKey = Serial.readStringUntil('\n'); + + appKey.trim(); + appEui.trim(); + + connected = modem.joinOTAA(appEui, appKey); + } else if (mode == 2) { + + Serial.println("Enter your Device Address"); + while (!Serial.available()); + devAddr = Serial.readStringUntil('\n'); + + Serial.println("Enter your NWS KEY"); + while (!Serial.available()); + nwkSKey = Serial.readStringUntil('\n'); + + Serial.println("Enter your APP SKEY"); + while (!Serial.available()); + appSKey = Serial.readStringUntil('\n'); + + devAddr.trim(); + nwkSKey.trim(); + appSKey.trim(); + + connected = modem.joinABP(devAddr, nwkSKey, appSKey); + } + + if (!connected) { + Serial.println("Something went wrong; are you indoor? Move near a window and retry"); + while (1) {} + } + + delay(5000); + + int err; + modem.setPort(3); + modem.beginPacket(); + modem.print("HeLoRA world!"); + err = modem.endPacket(true); + if (err > 0) { + Serial.println("Message sent correctly!"); + } else { + Serial.println("Error sending message :("); + } +} + +void loop() { + while (modem.available()) { + Serial.write(modem.read()); + } + modem.poll(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/LoraSendAndReceive.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/LoraSendAndReceive.ino new file mode 100644 index 00000000..0bc5a21a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/LoraSendAndReceive.ino @@ -0,0 +1,91 @@ +/* + Lora Send And Receive + This sketch demonstrates how to send and receive data with the MKR WAN 1300/1310 LoRa module. + This example code is in the public domain. +*/ + +#include + +LoRaModem modem; + +// Uncomment if using the Murata chip as a module +// LoRaModem modem(Serial1); + +#include "arduino_secrets.h" +// Please enter your sensitive data in the Secret tab or arduino_secrets.h +String appEui = SECRET_APP_EUI; +String appKey = SECRET_APP_KEY; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial); + // change this to your regional band (eg. US915, AS923, ...) + if (!modem.begin(EU868)) { + Serial.println("Failed to start module"); + while (1) {} + }; + Serial.print("Your module version is: "); + Serial.println(modem.version()); + Serial.print("Your device EUI is: "); + Serial.println(modem.deviceEUI()); + + int connected = modem.joinOTAA(appEui, appKey); + if (!connected) { + Serial.println("Something went wrong; are you indoor? Move near a window and retry"); + while (1) {} + } + + // Set poll interval to 60 secs. + modem.minPollInterval(60); + // NOTE: independently by this setting the modem will + // not allow to send more than one message every 2 minutes, + // this is enforced by firmware and can not be changed. +} + +void loop() { + Serial.println(); + Serial.println("Enter a message to send to network"); + Serial.println("(make sure that end-of-line 'NL' is enabled)"); + + while (!Serial.available()); + String msg = Serial.readStringUntil('\n'); + + Serial.println(); + Serial.print("Sending: " + msg + " - "); + for (unsigned int i = 0; i < msg.length(); i++) { + Serial.print(msg[i] >> 4, HEX); + Serial.print(msg[i] & 0xF, HEX); + Serial.print(" "); + } + Serial.println(); + + int err; + modem.beginPacket(); + modem.print(msg); + err = modem.endPacket(true); + if (err > 0) { + Serial.println("Message sent correctly!"); + } else { + Serial.println("Error sending message :("); + Serial.println("(you may send a limited amount of messages per minute, depending on the signal strength"); + Serial.println("it may vary from 1 message every couple of seconds to 1 message every minute)"); + } + delay(1000); + if (!modem.available()) { + Serial.println("No downlink message received at this time."); + return; + } + char rcv[64]; + int i = 0; + while (modem.available()) { + rcv[i++] = (char)modem.read(); + } + Serial.print("Received: "); + for (unsigned int j = 0; j < i; j++) { + Serial.print(rcv[j] >> 4, HEX); + Serial.print(rcv[j] & 0xF, HEX); + Serial.print(" "); + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/arduino_secrets.h new file mode 100644 index 00000000..3abaf3f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/LoraSendAndReceive/arduino_secrets.h @@ -0,0 +1,3 @@ +// Replace with keys obtained from TheThingsNetwork console +#define SECRET_APP_EUI "xxxxxxxxxxxxx" +#define SECRET_APP_KEY "yyyyyyyyyyyyyyyyyyyyyyy" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino new file mode 100644 index 00000000..10c332b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MKRWAN_v2/examples/MKRWANFWUpdate_standalone/MKRWANFWUpdate_standalone.ino @@ -0,0 +1,376 @@ +/* + * STANDALONE FIRMWARE UPDATE FOR MKR WAN 1300/1310 + * This sketch implements STM32 bootloader protocol + * It is based on stm32flash (mirrored here git@github.com:facchinm/stm32flash.git) + * with as little modifications as possible. + * + * To generate it after a firmware update, execute + * + * echo -n "const " > fw.h && xxd -i mlm32l07x01.bin >> fw.h + * + */ + + +#include "fw.h" +#include "stm32.h" +#include "serial_arduino.h" +#include + +/* device globals */ +stm32_t *stm = NULL; +void *p_st = NULL; + +int ret = -1; + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + + while (!Serial); + + struct port_interface port; + struct port_options port_opts = { + .baudRate = 115200, + .serial_mode = SERIAL_8E1 + }; + + port.flags = PORT_CMD_INIT | PORT_GVR_ETX | PORT_BYTE | PORT_RETRY; + port.dev = &SerialLoRa; + port.ops = &port_opts; + + assignCallbacks(&port); + + pinMode(LED_BUILTIN, OUTPUT); + pinMode(LORA_BOOT0, OUTPUT); + digitalWrite(LORA_BOOT0, HIGH); + pinMode(LORA_RESET, OUTPUT); + digitalWrite(LORA_RESET, HIGH); + delay(200); + digitalWrite(LORA_RESET, LOW); + delay(200); + digitalWrite(LORA_RESET, HIGH); + delay(200); + + Serial.println("Press a key to start FW update"); + port.open(&port); + //port.flush(&port); + + stm = stm32_init(&port, 1); + + fprintf(diag, "Version : 0x%02x\n", stm->bl_version); + if (port.flags & PORT_GVR_ETX) { + fprintf(diag, "Option 1 : 0x%02x\n", stm->option1); + fprintf(diag, "Option 2 : 0x%02x\n", stm->option2); + } + fprintf(diag, "Device ID : 0x%04x (%s)\n", stm->pid, stm->dev->name); + fprintf(diag, "- RAM : Up to %dKiB (%db reserved by bootloader)\n", (stm->dev->ram_end - 0x20000000) / 1024, stm->dev->ram_start - 0x20000000); + fprintf(diag, "- Flash : Up to %dKiB (size first sector: %dx%d)\n", (stm->dev->fl_end - stm->dev->fl_start ) / 1024, stm->dev->fl_pps, stm->dev->fl_ps[0]); + fprintf(diag, "- Option RAM : %db\n", stm->dev->opt_end - stm->dev->opt_start + 1); + fprintf(diag, "- System RAM : %dKiB\n", (stm->dev->mem_end - stm->dev->mem_start) / 1024); + + uint8_t buffer[256]; + uint32_t addr, start, end; + unsigned int len; + int failed = 0; + int first_page, num_pages; + + int npages = mlm32l07x01_bin_len / 128 + 1; + int spage = 0; + bool verify = 1; + int retry = 10; + bool reset_flag = 0; + bool exec_flag = 1; + int execute = 0; // address + + /* + Cleanup addresses: + + Starting from options + start_addr, readwrite_len, spage, npages + and using device memory size, compute + start, end, first_page, num_pages + */ + if (!npages) { + start = stm->dev->fl_start; + end = stm->dev->fl_end; + first_page = 0; + num_pages = STM32_MASS_ERASE; + } else { + first_page = spage; + start = flash_page_to_addr(first_page); + if (start > stm->dev->fl_end) { + fprintf(stderr, "Address range exceeds flash size.\n"); + ret = -1; + return; + } + + if (npages) { + num_pages = npages; + end = flash_page_to_addr(first_page + num_pages); + if (end > stm->dev->fl_end) + end = stm->dev->fl_end; + } else { + end = stm->dev->fl_end; + num_pages = flash_addr_to_page_ceil(end) - first_page; + } + + if (!first_page && end == stm->dev->fl_end) + num_pages = STM32_MASS_ERASE; + } + + ret = 0; + int s_err; + +#if 0 + fprintf(diag, "Erasing flash\n"); + + if (num_pages != STM32_MASS_ERASE && + (start != flash_page_to_addr(first_page) + || end != flash_page_to_addr(first_page + num_pages))) { + fprintf(stderr, "Specified start & length are invalid (must be page aligned)\n"); + ret = 1; + return; + } + + s_err = stm32_erase_memory(stm, first_page, num_pages); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to erase memory\n"); + ret = 1; + return; + } + ret = 0; + +#endif + + fprintf(diag, "Write to memory\n"); + + off_t offset = 0; + ssize_t r; + unsigned int size; + unsigned int max_wlen, max_rlen; + +#define STM32_MAX_RX_FRAME 256 /* cmd read memory */ +#define STM32_MAX_TX_FRAME (1 + 256 + 1) /* cmd write memory */ + + max_wlen = STM32_MAX_TX_FRAME - 2; /* skip len and crc */ + max_wlen &= ~3; /* 32 bit aligned */ + + max_rlen = STM32_MAX_RX_FRAME; + max_rlen = max_rlen < max_wlen ? max_rlen : max_wlen; + + /* Assume data from stdin is whole device */ + size = end - start; + + // TODO: It is possible to write to non-page boundaries, by reading out flash + // from partial pages and combining with the input data + // if ((start % stm->dev->fl_ps[i]) != 0 || (end % stm->dev->fl_ps[i]) != 0) { + // fprintf(stderr, "Specified start & length are invalid (must be page aligned)\n"); + // goto close; + // } + + // TODO: If writes are not page aligned, we should probably read out existing flash + // contents first, so it can be preserved and combined with new data + if (num_pages) { + fprintf(diag, "Erasing memory\n"); + s_err = stm32_erase_memory(stm, first_page, num_pages); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to erase memory\n"); + ret = -1; + return; + } + } + + addr = start; + while (addr < end && offset < size) { + uint32_t left = end - addr; + len = max_wlen > left ? left : max_wlen; + len = len > size - offset ? size - offset : len; + + memcpy(buffer, &mlm32l07x01_bin[offset], len); + + if (len == 0) { + fprintf(stderr, "Failed to read input file\n"); + ret = -1; + return; + } + +again: + s_err = stm32_write_memory(stm, addr, buffer, len); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to write memory at address 0x%08x\n", addr); + ret = -1; + return; + } + + if (verify) { + uint8_t compare[len]; + unsigned int offset, rlen; + + offset = 0; + while (offset < len) { + rlen = len - offset; + rlen = rlen < max_rlen ? rlen : max_rlen; + s_err = stm32_read_memory(stm, addr + offset, compare + offset, rlen); + if (s_err != STM32_ERR_OK) { + fprintf(stderr, "Failed to read memory at address 0x%08x\n", addr + offset); + ret = -1; + return; + } + offset += rlen; + } + + for (r = 0; r < len; ++r) + if (buffer[r] != compare[r]) { + if (failed == retry) { + fprintf(stderr, "Failed to verify at address 0x%08x, expected 0x%02x and found 0x%02x\n", + (uint32_t)(addr + r), + buffer [r], + compare[r] + ); + ret = -1; + return; + } + ++failed; + goto again; + } + + failed = 0; + } + + addr += len; + offset += len; + + fprintf(diag, + "Wrote %saddress 0x%08x (%d%%)\n ", + verify ? "and verified " : "", + addr, + 100 * offset / size + ); + + } + + fprintf(diag, "Done.\n"); + ret = 0; + + if (stm && exec_flag && ret == 0) { + if (execute == 0) + execute = stm->dev->fl_start; + + fprintf(diag, "\nStarting execution at address 0x%08x... ", execute); + if (stm32_go(stm, execute) == STM32_ERR_OK) { + reset_flag = 0; + fprintf(diag, "done.\n"); + } else + fprintf(diag, "failed.\n"); + } +} + +void resetModuleRunning() { + digitalWrite(LORA_BOOT0, LOW); + SerialLoRa.end(); + SerialLoRa.begin(19200); + delay(100); + digitalWrite(LORA_RESET, HIGH); + delay(100); + digitalWrite(LORA_RESET, LOW); + delay(100); + digitalWrite(LORA_RESET, HIGH); + delay(100); +} + +void loop() { + // put your main code here, to run repeatedly: + if (ret == 0) { + Serial.println("Flashing ok :)"); + SerialLoRa.end(); + LoRaModem* modem = new LoRaModem(); + modem->begin(EU868); + Serial.println(modem->version()); + } + while (1); +} + +static int is_addr_in_ram(uint32_t addr) +{ + return addr >= stm->dev->ram_start && addr < stm->dev->ram_end; +} + +static int is_addr_in_flash(uint32_t addr) +{ + return addr >= stm->dev->fl_start && addr < stm->dev->fl_end; +} + +static int is_addr_in_opt_bytes(uint32_t addr) +{ + /* option bytes upper range is inclusive in our device table */ + return addr >= stm->dev->opt_start && addr <= stm->dev->opt_end; +} + +static int is_addr_in_sysmem(uint32_t addr) +{ + return addr >= stm->dev->mem_start && addr < stm->dev->mem_end; +} + +/* returns the page that contains address "addr" */ +static int flash_addr_to_page_floor(uint32_t addr) +{ + int page; + uint32_t *psize; + + if (!is_addr_in_flash(addr)) + return 0; + + page = 0; + addr -= stm->dev->fl_start; + psize = stm->dev->fl_ps; + + while (addr >= psize[0]) { + addr -= psize[0]; + page++; + if (psize[1]) + psize++; + } + + return page; +} + +/* returns the first page whose start addr is >= "addr" */ +int flash_addr_to_page_ceil(uint32_t addr) +{ + int page; + uint32_t *psize; + + if (!(addr >= stm->dev->fl_start && addr <= stm->dev->fl_end)) + return 0; + + page = 0; + addr -= stm->dev->fl_start; + psize = stm->dev->fl_ps; + + while (addr >= psize[0]) { + addr -= psize[0]; + page++; + if (psize[1]) + psize++; + } + + return addr ? page + 1 : page; +} + +/* returns the lower address of flash page "page" */ +static uint32_t flash_page_to_addr(int page) +{ + int i; + uint32_t addr, *psize; + + addr = stm->dev->fl_start; + psize = stm->dev->fl_ps; + + for (i = 0; i < page; i++) { + addr += psize[0]; + if (psize[1]) + psize++; + } + + return addr; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MadgwickAHRS/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MadgwickAHRS/README.adoc new file mode 100644 index 00000000..774aff4c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MadgwickAHRS/README.adoc @@ -0,0 +1,37 @@ +:repository-owner: arduino-libraries +:repository-name: MadgwickAHRS + += Madgwick Library = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library wraps the official implementation of MadgwickAHRS algorithm to get orientation of an object based on accelerometer and gyroscope readings + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Implementation of Madgwick's IMU and AHRS algorithms. +See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms + +Date Author Notes +29/09/2011 SOH Madgwick Initial release +02/10/2011 SOH Madgwick Optimised for reduced CPU load +19/02/2012 SOH Madgwick Magnetometer measurement is normalised diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MadgwickAHRS/examples/Visualize101/Visualize101.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MadgwickAHRS/examples/Visualize101/Visualize101.ino new file mode 100644 index 00000000..b3f8c792 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/MadgwickAHRS/examples/Visualize101/Visualize101.ino @@ -0,0 +1,85 @@ +#include +#include + +Madgwick filter; +unsigned long microsPerReading, microsPrevious; +float accelScale, gyroScale; + +void setup() { + Serial.begin(9600); + + // start the IMU and filter + CurieIMU.begin(); + CurieIMU.setGyroRate(25); + CurieIMU.setAccelerometerRate(25); + filter.begin(25); + + // Set the accelerometer range to 2 g + CurieIMU.setAccelerometerRange(2); + // Set the gyroscope range to 250 degrees/second + CurieIMU.setGyroRange(250); + + // initialize variables to pace updates to correct rate + microsPerReading = 1000000 / 25; + microsPrevious = micros(); +} + +void loop() { + int aix, aiy, aiz; + int gix, giy, giz; + float ax, ay, az; + float gx, gy, gz; + float roll, pitch, heading; + unsigned long microsNow; + + // check if it's time to read data and update the filter + microsNow = micros(); + if (microsNow - microsPrevious >= microsPerReading) { + + // read raw data from CurieIMU + CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz); + + // convert from raw data to gravity and degrees/second units + ax = convertRawAcceleration(aix); + ay = convertRawAcceleration(aiy); + az = convertRawAcceleration(aiz); + gx = convertRawGyro(gix); + gy = convertRawGyro(giy); + gz = convertRawGyro(giz); + + // update the filter, which computes orientation + filter.updateIMU(gx, gy, gz, ax, ay, az); + + // print the heading, pitch and roll + roll = filter.getRoll(); + pitch = filter.getPitch(); + heading = filter.getYaw(); + Serial.print("Orientation: "); + Serial.print(heading); + Serial.print(" "); + Serial.print(pitch); + Serial.print(" "); + Serial.println(roll); + + // increment previous time, so we keep proper pace + microsPrevious = microsPrevious + microsPerReading; + } +} + +float convertRawAcceleration(int aRaw) { + // since we are using 2 g range + // -2 g maps to a raw value of -32768 + // +2 g maps to a raw value of 32767 + + float a = (aRaw * 2.0) / 32768.0; + return a; +} + +float convertRawGyro(int gRaw) { + // since we are using 250 degrees/seconds range + // -250 maps to a raw value of -32768 + // +250 maps to a raw value of 32767 + + float g = (gRaw * 250.0) / 32768.0; + return g; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/README.md new file mode 100644 index 00000000..f83882ce --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/README.md @@ -0,0 +1,52 @@ +# NTPClient + +[![Check Arduino status](https://github.com/arduino-libraries/NTPClient/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/NTPClient/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/NTPClient/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/NTPClient/actions/workflows/spell-check.yml) + +Connect to a NTP server, here is how: + +```cpp +#include +// change next line to use with another board/shield +#include +//#include // for WiFi shield +//#include // for WiFi 101 shield or MKR1000 +#include + +const char *ssid = ""; +const char *password = ""; + +WiFiUDP ntpUDP; + +// By default 'pool.ntp.org' is used with 60 seconds update interval and +// no offset +NTPClient timeClient(ntpUDP); + +// You can specify the time server pool and the offset, (in seconds) +// additionally you can specify the update interval (in milliseconds). +// NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); + +void setup(){ + Serial.begin(115200); + WiFi.begin(ssid, password); + + while ( WiFi.status() != WL_CONNECTED ) { + delay ( 500 ); + Serial.print ( "." ); + } + + timeClient.begin(); +} + +void loop() { + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + + delay(1000); +} +``` + +## Function documentation +`getEpochTime` returns the Unix epoch, which are the seconds elapsed since 00:00:00 UTC on 1 January 1970 (leap seconds are ignored, every day is treated as having 86400 seconds). **Attention**: If you have set a time offset this time offset will be added to your epoch timestamp. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/Advanced/Advanced.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/Advanced/Advanced.ino new file mode 100644 index 00000000..18a6a971 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/Advanced/Advanced.ino @@ -0,0 +1,37 @@ +#include +// change next line to use with another board/shield +#include +//#include // for WiFi shield +//#include // for WiFi 101 shield or MKR1000 +#include + +const char *ssid = ""; +const char *password = ""; + +WiFiUDP ntpUDP; + +// You can specify the time server pool and the offset (in seconds, can be +// changed later with setTimeOffset() ). Additionally you can specify the +// update interval (in milliseconds, can be changed using setUpdateInterval() ). +NTPClient timeClient(ntpUDP, "europe.pool.ntp.org", 3600, 60000); + +void setup(){ + Serial.begin(115200); + + WiFi.begin(ssid, password); + + while ( WiFi.status() != WL_CONNECTED ) { + delay ( 500 ); + Serial.print ( "." ); + } + + timeClient.begin(); +} + +void loop() { + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/Basic/Basic.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/Basic/Basic.ino new file mode 100644 index 00000000..f0a2a7cd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/Basic/Basic.ino @@ -0,0 +1,33 @@ +#include +// change next line to use with another board/shield +#include +//#include // for WiFi shield +//#include // for WiFi 101 shield or MKR1000 +#include + +const char *ssid = ""; +const char *password = ""; + +WiFiUDP ntpUDP; +NTPClient timeClient(ntpUDP); + +void setup(){ + Serial.begin(115200); + + WiFi.begin(ssid, password); + + while ( WiFi.status() != WL_CONNECTED ) { + delay ( 500 ); + Serial.print ( "." ); + } + + timeClient.begin(); +} + +void loop() { + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/IsTimeSet/IsTimeSet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/IsTimeSet/IsTimeSet.ino new file mode 100644 index 00000000..619bfde0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/NTPClient/examples/IsTimeSet/IsTimeSet.ino @@ -0,0 +1,53 @@ +#include +// change next line to use with another board/shield +#include +//#include // for WiFi shield +//#include // for WiFi 101 shield or MKR1000 +#include + +const char *ssid = ""; +const char *password = ""; + +WiFiUDP ntpUDP; +// initialized to a time offset of 10 hours +NTPClient timeClient(ntpUDP,"pool.ntp.org", 36000, 60000); +// HH:MM:SS +// timeClient initializes to 10:00:00 if it does not receive an NTP packet +// before the 100ms timeout. +// without isTimeSet() the LED would be switched on, although the time +// was not yet set correctly. + +// blue LED on ESP-12F +const int led = 2; +const int hour = 10; +const int minute = 0; + +void setup(){ + Serial.begin(115200); + + pinMode(led, OUTPUT); + // led is off when pin is high + digitalWrite(led, 1); + + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + delay (500); + Serial.print ("."); + } + + timeClient.begin(); +} + +void loop() { + timeClient.update(); + + Serial.println(timeClient.getFormattedTime()); + if(timeClient.isTimeSet()) { + if (hour == timeClient.getHours() && minute == timeClient.getMinutes()) { + digitalWrite(led, 0); + } + } + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/README.adoc new file mode 100644 index 00000000..e33e6b94 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: RTCZero + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The RTCZero library enables an Arduino Zero or MKR1000 board to take control of the internal RTC. + +For more information about this library please visit us at +http://arduino.cc/en/Reference/RTC diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/Epoch/Epoch.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/Epoch/Epoch.ino new file mode 100644 index 00000000..5b6f9492 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/Epoch/Epoch.ino @@ -0,0 +1,59 @@ +/* + Epoch time example for Arduino Zero and MKR1000 + + Demonstrates how to set time using epoch for the Arduino Zero and MKR1000 + + This example code is in the public domain + + created by Sandeep Mistry + 31 Dec 2015 + modified + 18 Feb 2016 +*/ + +#include + +/* Create an RTCZero object */ +RTCZero rtc; + +void setup() { + Serial.begin(9600); + + rtc.begin(); // initialize RTC + + rtc.setEpoch(1451606400); // Jan 1, 2016 +} + +void loop() { + Serial.print("Unix time = "); + Serial.println(rtc.getEpoch()); + + Serial.print("Seconds since Jan 1 2000 = "); + Serial.println(rtc.getY2kEpoch()); + + // Print date... + Serial.print(rtc.getDay()); + Serial.print("/"); + Serial.print(rtc.getMonth()); + Serial.print("/"); + Serial.print(rtc.getYear()); + Serial.print("\t"); + + // ...and time + print2digits(rtc.getHours()); + Serial.print(":"); + print2digits(rtc.getMinutes()); + Serial.print(":"); + print2digits(rtc.getSeconds()); + + Serial.println(); + + delay(1000); +} + +void print2digits(int number) { + if (number < 10) { + Serial.print("0"); + } + Serial.print(number); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SimpleRTC/SimpleRTC.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SimpleRTC/SimpleRTC.ino new file mode 100644 index 00000000..07aa7296 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SimpleRTC/SimpleRTC.ino @@ -0,0 +1,83 @@ +/* + Simple RTC for Arduino Zero and MKR1000 + + Demonstrates the use of the RTC library for the Arduino Zero and MKR1000 + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SimpleRTC + + created by Arturo Guadalupi + 15 Jun 2015 + modified + 18 Feb 2016 + modified by Andrea Richetta + 24 Aug 2016 +*/ + +#include + +/* Create an RTCZero object */ +RTCZero rtc; + +/* Change these values to set the current initial time */ +const byte seconds = 0; +const byte minutes = 0; +const byte hours = 16; + +/* Change these values to set the current initial date */ +const byte day = 15; +const byte month = 6; +const byte year = 15; + +void setup() +{ + Serial.begin(9600); + + rtc.begin(); // initialize RTC + + // Set the time + rtc.setHours(hours); + rtc.setMinutes(minutes); + rtc.setSeconds(seconds); + + // Set the date + rtc.setDay(day); + rtc.setMonth(month); + rtc.setYear(year); + + // you can use also + //rtc.setTime(hours, minutes, seconds); + //rtc.setDate(day, month, year); +} + +void loop() +{ + // Print date... + print2digits(rtc.getDay()); + Serial.print("/"); + print2digits(rtc.getMonth()); + Serial.print("/"); + print2digits(rtc.getYear()); + Serial.print(" "); + + // ...and time + print2digits(rtc.getHours()); + Serial.print(":"); + print2digits(rtc.getMinutes()); + Serial.print(":"); + print2digits(rtc.getSeconds()); + + Serial.println(); + + delay(1000); +} + + + +void print2digits(int number) { + if (number < 10) { + Serial.print("0"); // print a 0 before if the number is < than 10 + } + Serial.print(number); +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SimpleRTCAlarm/SimpleRTCAlarm.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SimpleRTCAlarm/SimpleRTCAlarm.ino new file mode 100644 index 00000000..1427fd06 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SimpleRTCAlarm/SimpleRTCAlarm.ino @@ -0,0 +1,55 @@ +/* + Simple RTC Alarm for Arduino Zero and MKR1000 + + Demonstrates how to set an RTC alarm for the Arduino Zero and MKR1000 + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SimpleRTCAlarm + + created by Arturo Guadalupi + 25 Sept 2015 + + modified + 21 Oct 2015 +*/ + +#include + +/* Create an RTCZero object */ +RTCZero rtc; + +/* Change these values to set the current initial time */ +const byte seconds = 0; +const byte minutes = 0; +const byte hours = 16; + +/* Change these values to set the current initial date */ +const byte day = 25; +const byte month = 9; +const byte year = 15; + +void setup() +{ + Serial.begin(9600); + + rtc.begin(); // initialize RTC 24H format + + rtc.setTime(hours, minutes, seconds); + rtc.setDate(day, month, year); + + rtc.setAlarmTime(16, 0, 10); + rtc.enableAlarm(rtc.MATCH_HHMMSS); + + rtc.attachInterrupt(alarmMatch); +} + +void loop() +{ + +} + +void alarmMatch() +{ + Serial.println("Alarm Match!"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SleepRTCAlarm/SleepRTCAlarm.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SleepRTCAlarm/SleepRTCAlarm.ino new file mode 100644 index 00000000..b89c4311 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RTCZero/examples/SleepRTCAlarm/SleepRTCAlarm.ino @@ -0,0 +1,62 @@ +/* + Sleep RTC Alarm for Arduino Zero + + Demonstrates the use of an alarm to wake up an Arduino Zero from Standby mode + + This example code is in the public domain + + http://arduino.cc/en/Tutorial/SleepRTCAlarm + + created by Arturo Guadalupi + 17 Nov 2015 + modified + 01 Mar 2016 + + NOTE: + If you use this sketch with a MKR1000 you will see no output on the serial monitor. + This happens because the USB clock is stopped so the USB connection is stopped too. + **To see again the USB port you have to double tap on the reset button!** +*/ + +#include + +/* Create an RTCZero object */ +RTCZero rtc; + +/* Change these values to set the current initial time */ +const byte seconds = 0; +const byte minutes = 00; +const byte hours = 17; + +/* Change these values to set the current initial date */ +const byte day = 17; +const byte month = 11; +const byte year = 15; + +void setup() +{ + pinMode(LED_BUILTIN, OUTPUT); + digitalWrite(LED_BUILTIN, LOW); + + rtc.begin(); + + rtc.setTime(hours, minutes, seconds); + rtc.setDate(day, month, year); + + rtc.setAlarmTime(17, 00, 10); + rtc.enableAlarm(rtc.MATCH_HHMMSS); + + rtc.attachInterrupt(alarmMatch); + + rtc.standbyMode(); +} + +void loop() +{ + rtc.standbyMode(); // Sleep until next alarm match +} + +void alarmMatch() +{ + digitalWrite(LED_BUILTIN, HIGH); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/LICENSE.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/LICENSE.md new file mode 100644 index 00000000..39465391 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/LICENSE.md @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) [year] [fullname] + +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/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/README.md new file mode 100644 index 00000000..e55e315e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/README.md @@ -0,0 +1,154 @@ +# Warning + +Documentation needs to be updated because of massive changes in API + +I have changed the original code to allow the library to be used with any network connection + +# RestClient for Arduino + +HTTP Request library for Arduino derived from https://github.com/csquared/arduino-restclient + +# Usage + +### Include + + + +```c++ +#include +#include +#include "RestClient.h" +``` + +### RestClient(host/ip, [port]) + +Constructor to create an RestClient object to make requests against. + +Use domain name and default to port 80: +```c++ +RestClient client = RestClient("arduino-http-lib-test.herokuapp.com"); +``` + +Use a local IP and an explicit port: +```c++ +RestClient client = RestClient("192.168.1.50",5000); +``` + +### dhcp() + +Sets up `EthernetClient` with a mac address of `DEADBEEFFEED` + +```c++ + client.dhcp() +``` + +Note: you can have multiple RestClient objects but only need to call +this once. + +Note: if you have multiple Arduinos on the same network, you'll need +to give each one a different mac address. + +### begin(byte mac[]) + +It just wraps the `EthernetClient` call to `begin` and DHCPs. +Use this if you need to explicitly set the mac address. + +```c++ + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + if (client.begin(mac) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + } +``` + +### Manual Ethernet Setup + +You can skip the above methods and just configure the EthernetClient yourself: + +```c++ + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + //the IP address for the shield: + byte ip[] = { 192, 168, 2, 11 }; + Ethernet.begin(mac,ip); +``` + +```c++ + byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + Ethernet.begin(mac); +``` + +This is especially useful for debugging network connection issues. + +## RESTful methods + +All methods return an HTTP status code or 0 if there was an error. + +### `get(const char* path)` +### `get(const char* path, String* response)` + +Start making requests! + +```c++ +int statusCode = client.get("/")); +``` + +Pass in a string *by reference* for the response: +``` +String response = ""; +int statusCode = client.get("/", &response); +``` + +### post(const char* path, const char* body) +### post(const char* path, String* response) +### post(const char* path, const char* body, String* response) + +``` +String response = ""; +int statusCode = client.post("/", &response); +statusCode = client.post("/", "foo=bar"); +response = ""; +statusCode = client.post("/", "foo=bar", &response); +``` + +### put(const char* path, const char* body) +### put(const char* path, String* response) +### put(const char* path, const char* body, String* response) + +``` +String response = ""; +int statusCode = client.put("/", &response); +statusCode = client.put("/", "foo=bar"); +response = ""; +statusCode = client.put("/", "foo=bar", &response); +``` + +### del(const char* path) +### del(const char* path, const char* body) +### del(const char* path, String* response) +### del(const char* path, const char* body, String* response) + +``` +String response = ""; +int statusCode = client.del("/", &response); +``` + +## Full Example + +I test every way of calling the library (against a public heroku app)[https://github.com/csquared/arduino-http-test]. + +You can find the file in File->Examples->RestClient->full_test_suite + +## Debug Mode + +If you're having trouble, you can always open `RestClient.cpp` and throw at the top: + +```c++ +#define HTTP_DEBUG +``` + +Everything happening in the client will get printed to the Serial port. + +# Thanks + +[ricardochimal](https://github.com/ricardochimal) For all his c++ help. Couldn't have done this without you! + +[theycallmeswift](https://github.com/theycallmeswift) Helping incept and debug v1.0 diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetGet/DweetGet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetGet/DweetGet.ino new file mode 100644 index 00000000..d98a17bf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetGet/DweetGet.ino @@ -0,0 +1,106 @@ +/* + Dweet.io GET client for RestClient library + Connects to dweet.io once every ten seconds, + sends a GET request and a request body. Uses SSL + + Shows how to use Strings to assemble path and parse content + from response. dweet.io expects: + https://dweet.io/get/latest/dweet/for/thingName + + For more on dweet.io, see https://dweet.io/play/ + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 15 Feb 2016 + updated 16 Feb 2016 + by Tom Igoe + + this example is in the public domain +*/ +#include +#include +#include "config.h" + +char serverAddress[] = "dweet.io"; // server address +int port = 80; +String dweetName = "scandalous-cheese-hoarder"; // use your own thing name here + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + // assemble the path for the POST message: + String path = "/get/latest/dweet/for/" + dweetName; + + // assemble the body of the POST message: + int sensorValue = analogRead(A0); + + Serial.println("making GET request"); + client.setContentType("application/json"); + statusCode = client.get(path); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + /* + Typical response is: + {"this":"succeeded", + "by":"getting", + "the":"dweets", + "with":[{"thing":"my-thing-name", + "created":"2016-02-16T05:10:36.589Z", + "content":{"sensorValue":456}}]} + + You want "content": numberValue + */ + // now parse the response looking for "content": + int labelStart = response.indexOf("content\":"); + // find the first { after "content": + int contentStart = response.indexOf("{", labelStart); + // find the following } and get what's between the braces: + int contentEnd = response.indexOf("}", labelStart); + String content = response.substring(contentStart + 1, contentEnd); + Serial.println(content); + + // now get the value after the colon, and convert to an int: + int valueStart = content.indexOf(":"); + String valueString = content.substring(valueStart + 1); + int number = valueString.toInt(); + Serial.print("Value string: "); + Serial.println(valueString); + Serial.print("Actual value: "); + Serial.println(number); + + Serial.println("Wait ten seconds\n"); + delay(10000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetPost/DweetPost.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetPost/DweetPost.ino new file mode 100644 index 00000000..cf7a9875 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetPost/DweetPost.ino @@ -0,0 +1,75 @@ +/* + Dweet.io POST client for RestClient library + Connects to dweet.io once every ten seconds, + sends a POST request and a request body. Uses SSL + + Shows how to use Strings to assemble path and body + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 15 Feb 2016 + by Tom Igoe + + this example is in the public domain +*/ +#include +#include +#include "config.h" + +char serverAddress[] = "dweet.io"; // server address +int port = 80; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while(!Serial); + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + // assemble the path for the POST message: + String dweetName = "scandalous-cheese-hoarder"; + String path = "/dweet/for/" + dweetName; + + // assemble the body of the POST message: + int sensorValue = analogRead(A0); + String postData = "{\"sensorValue\":\""; + postData += sensorValue; + postData += "\"}"; + + Serial.println("making POST request"); + client.setContentType("application/json"); + statusCode = client.post(path, postData); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + Serial.println("Wait ten seconds\n"); + delay(10000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetPost/config.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetPost/config.h new file mode 100644 index 00000000..b72117f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/DweetPost/config.h @@ -0,0 +1,3 @@ + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/HueBlink/HueBlink.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/HueBlink/HueBlink.ino new file mode 100644 index 00000000..8ca4839f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/HueBlink/HueBlink.ino @@ -0,0 +1,93 @@ +/* HueBlink example for RestClient library + + Uses ResClient library to control Philips Hue + For more on Hue developer API see http://developer.meethue.com + + To control a light, the Hue expects a HTTP PUT request to: + + http://hue.hub.address/api/hueUserName/lights/lightNumber/state + + The body of the PUT request looks like this: + {"on": true} or {"on":false} + + This example shows how to concatenate Strings to assemble the + PUT request and the body of the request. + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + modified 15 Feb 2016 + by Tom Igoe (tigoe) to match new API +*/ + +#include +#include +#include +#include "config.h" + +int status = WL_IDLE_STATUS; // the Wifi radio's status +char hueHubIP[] = "192.168.0.3"; // IP address of the HUE bridge +String hueUserName = "huebridgeusername"; // hue bridge username + +// make a wifi instance and a RestClient instance: +WiFiClient wifi; +RestClient restClient = RestClient(wifi, hueHubIP); + + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial); // wait for serial port to connect. + + // attempt to connect to Wifi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network IP = "); + IPAddress ip = WiFi.localIP(); + Serial.println(ip); +} + +void loop() { + sendRequest(3, "on", "true"); // turn light on + delay(2000); // wait 2 seconds + sendRequest(3, "on", "false"); // turn light off + delay(2000); // wait 2 seconds +} + +void sendRequest(int light, String cmd, String value) { + // make a String for the HTTP request path: + String request = "/api/" + hueUserName; + request += "/lights/"; + request += light; + request += "/state/"; + + // make a string for the JSON command: + String hueCmd = "{\"" + cmd; + hueCmd += "\":"; + hueCmd += value; + hueCmd += "}"; + // see what you assembled to send: + Serial.print("PUT request to server: "); + Serial.println(request); + Serial.print("JSON command to server: "); + + // make the PUT request to the hub: + int statusCode = restClient.put(request, hueCmd); + Serial.println(hueCmd); + Serial.print("Status code from server: "); + Serial.println(statusCode); + Serial.print("Server response: "); + Serial.println(restClient.readResponse()); + Serial.println(); +} + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/HueBlink/config.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/HueBlink/config.h new file mode 100644 index 00000000..c2637667 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/HueBlink/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleDelete/SimpleDelete.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleDelete/SimpleDelete.ino new file mode 100644 index 00000000..ad9bb5cd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleDelete/SimpleDelete.ino @@ -0,0 +1,62 @@ +/* + Simple DELETE client for RestClient library + Connects to server once every five seconds, sends a DELETE request + and a request body + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 14 Feb 2016 + by Tom Igoe + + this example is in the public domain + */ + #include +#include +#include "config.h" + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + Serial.println("making DELETE request"); + String delData = "name=light&age=46"; + statusCode = client.del("/", delData); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + Serial.println("Wait five seconds"); + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleDelete/config.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleDelete/config.h new file mode 100644 index 00000000..c2637667 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleDelete/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleGet/SimpleGet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleGet/SimpleGet.ino new file mode 100644 index 00000000..eaf85c7b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleGet/SimpleGet.ino @@ -0,0 +1,61 @@ +/* + Simple GET client for RestClient library + Connects to server once every five seconds, sends a GET request + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 14 Feb 2016 + by Tom Igoe + + this example is in the public domain + */ +#include +#include +#include "config.h" + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + statusCode = client.get("/"); +} + +void loop() { + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.println("making GET request"); + + statusCode = client.get("/"); + response = client.readResponse(); + Serial.print("Response: "); + Serial.println(response); + Serial.println("Wait five seconds"); + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleGet/config.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleGet/config.h new file mode 100644 index 00000000..c2637667 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimpleGet/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePost/SimplePost.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePost/SimplePost.ino new file mode 100644 index 00000000..2da46252 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePost/SimplePost.ino @@ -0,0 +1,62 @@ +/* + Simple POST client for RestClient library + Connects to server once every five seconds, sends a POST request + and a request body + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 14 Feb 2016 + by Tom Igoe + + this example is in the public domain + */ +#include +#include +#include "config.h" + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + Serial.println("making POST request"); + String postData = "name=Alice&age=12"; + statusCode = client.post("/", postData); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + Serial.println("Wait five seconds"); + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePost/config.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePost/config.h new file mode 100644 index 00000000..c2637667 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePost/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePut/SimplePut.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePut/SimplePut.ino new file mode 100644 index 00000000..5b9714c1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePut/SimplePut.ino @@ -0,0 +1,62 @@ +/* + Simple PUT client for RestClient library + Connects to server once every five seconds, sends a PUT request + and a request body + + note: WiFi SSID and password are stored in config.h file. + If it is not present, add a new tab, call it "config.h" + and add the following variables: + char ssid[] = "ssid"; // your network SSID (name) + char pass[] = "password"; // your network password + + created 14 Feb 2016 + by Tom Igoe + + this example is in the public domain + */ +#include +#include +#include "config.h" + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; +String response; +int statusCode = 0; + +void setup() { + Serial.begin(9600); + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + +void loop() { + Serial.println("making PUT request"); + String putData = "name=light&age=46"; + statusCode = client.put("/", putData); + response = client.readResponse(); + Serial.print("Status code: "); + Serial.println(statusCode); + Serial.print("Response: "); + Serial.println(response); + + Serial.println("Wait five seconds"); + delay(5000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePut/config.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePut/config.h new file mode 100644 index 00000000..c2637667 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/SimplePut/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/full_test_suite/config.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/full_test_suite/config.h new file mode 100644 index 00000000..c2637667 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/full_test_suite/config.h @@ -0,0 +1,2 @@ +char ssid[] = "ssid"; // your network SSID (name) +char pass[] = "password"; // your network password diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/full_test_suite/full_test_suite.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/full_test_suite/full_test_suite.ino new file mode 100644 index 00000000..bc6fdf63 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/RestClient/examples/full_test_suite/full_test_suite.ino @@ -0,0 +1,187 @@ +/* RestClient full test suite + + Every REST method is called. + + by Chris Continanza (csquared) + modified by Massimo Banzi (mbanzi) to support more network devices + modified by Tom Igoe to match new API +*/ + +#include +#include +#include "config.h" + +int test_delay = 1000; //so we don't spam the API +bool describe_tests = true; + +char serverAddress[] = "192.168.0.3"; // server address +int port = 8080; + +WiFiClient wifi; +RestClient client = RestClient(wifi, serverAddress, port); +int status = WL_IDLE_STATUS; + +void setup() { + Serial.begin(9600); + while(!Serial); + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + } + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); +} + + +void test_status(int statusCode) { + delay(test_delay); + if (statusCode == 200) { + Serial.print("TEST RESULT: ok ("); + Serial.print(statusCode); + Serial.println(")"); + } else { + Serial.print("TEST RESULT: failure ("); + Serial.print(statusCode); + Serial.println(")"); + } +} + +void test_response(String response) { + //Serial.println(response); + if (response == "OK") { + Serial.println("TEST RESULT: ok (response body)"); + } else { + Serial.println("TEST RESULT: fail (response body = " + response + ")"); + } +} + +void describe(String description) { + if (describe_tests) Serial.println(description); +} + +//reusable test variables +String post_body = "POSTDATA"; + +void GET_tests() { + describe("Test GET with path"); + test_status(client.get("/get")); + + describe("Test GET with path and response"); + test_status(client.get("/get")); + test_response(client.readResponse()); + + describe("Test GET with path and query"); + test_status(client.get("/get?name=Bob&age=13")); + + + describe("Test GET with path and header"); + client.setHeader("X-Test-Header: true"); + test_status(client.get("/get-header")); + + describe("Test GET with path and header and response"); + client.setHeader("X-Test-Header: true"); + test_status(client.get("/get-header")); + test_response(client.readResponse()); + + describe("Test GET with 2 headers and response"); + client.setHeader("X-Test-Header1: one"); + client.setHeader("X-Test-Header2: two"); + test_status(client.get("/get-headers")); + test_response(client.readResponse()); +} + +void POST_tests() { + // POST TESTS + describe("Test POST with path and body"); + test_status(client.post("/data", post_body)); + + describe("Test POST with path and body and response"); + test_status(client.post("/data", post_body)); + test_response(client.readResponse()); + + describe("Test POST with path and body and header"); + client.setHeader("X-Test-Header: true"); + test_status(client.post("/data-header", post_body)); + + describe("Test POST with path and body and header and response"); + client.setHeader("X-Test-Header: true"); + test_status(client.post("/data-header", post_body)); + test_response(client.readResponse()); + + describe("Test POST with 2 headers and response"); + client.setHeader("X-Test-Header1: one"); + client.setHeader("X-Test-Header2: two"); + test_status(client.post("/data-headers", post_body)); + test_response(client.readResponse()); +} + +void PUT_tests() { + describe("Test PUT with path and body"); + test_status(client.put("/data", post_body)); + + describe("Test PUT with path and body and response"); + test_status(client.put("/data", post_body)); + test_response(client.readResponse()); + + describe("Test PUT with path and body and header"); + client.setHeader("X-Test-Header: true"); + test_status(client.put("/data-header", post_body)); + + describe("Test PUT with path and body and header and response"); + client.setHeader("X-Test-Header: true"); + test_status(client.put("/data-header", post_body)); + test_response(client.readResponse()); + + describe("Test PUT with 2 headers and response"); + client.setHeader("X-Test-Header1: one"); + client.setHeader("X-Test-Header2: two"); + test_status(client.put("/data-headers", post_body)); + test_response(client.readResponse()); +} + +void DELETE_tests() { + describe("Test DELETE with path"); + //note: requires a special endpoint + test_status(client.del("/del")); + + describe("Test DELETE with path and body"); + test_status(client.del("/data", post_body)); + + describe("Test DELETE with path and body and response"); + test_status(client.del("/data", post_body)); + test_response(client.readResponse()); + + describe("Test DELETE with path and body and header"); + client.setHeader("X-Test-Header: true"); + test_status(client.del("/data-header", post_body)); + + describe("Test DELETE with path and body and header and response"); + client.setHeader("X-Test-Header: true"); + test_status(client.del("/data-header", post_body)); + test_response(client.readResponse()); + + describe("Test DELETE with 2 headers and response"); + client.setHeader("X-Test-Header1: one"); + client.setHeader("X-Test-Header2: two"); + test_status(client.del("/data-headers", post_body)); + test_response(client.readResponse()); +} + + +// Run the tests! +void loop() { + GET_tests(); + POST_tests(); + PUT_tests(); + DELETE_tests(); + while(true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/LICENSE.txt new file mode 100644 index 00000000..f288702d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/LICENSE.txt @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/README.adoc new file mode 100644 index 00000000..ab370cba --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: SD + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The SD library allows for reading from and writing to SD cards. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/CardInfo/CardInfo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/CardInfo/CardInfo.ino new file mode 100644 index 00000000..ceef52ac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/CardInfo/CardInfo.ino @@ -0,0 +1,118 @@ +/* + SD card test + + This example shows how use the utility libraries on which the + SD library is based in order to get info about your SD card. + Very useful for testing a card when you're not sure whether its working or not. + Pin numbers reflect the default SPI pins for Uno and Nano models. + The circuit: + SD card attached to SPI bus as follows: + ** SDO - pin 11 on Arduino Uno/Duemilanove/Diecimila + ** SDI - pin 12 on Arduino Uno/Duemilanove/Diecimila + ** CLK - pin 13 on Arduino Uno/Duemilanove/Diecimila + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + + created 28 Mar 2011 + by Limor Fried + modified 24 July 2020 + by Tom Igoe +*/ +// include the SD library: +#include +#include + +// set up variables using the SD utility library functions: +Sd2Card card; +SdVolume volume; +SdFile root; + +// change this to match your SD shield or module; +// Default SPI on Uno and Nano: pin 10 +// Arduino Ethernet shield: pin 4 +// Adafruit SD shields and modules: pin 10 +// Sparkfun SD shield: pin 8 +// MKR Zero SD: SDCARD_SS_PIN +const int chipSelect = 10; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + Serial.print("\nInitializing SD card..."); + + // we'll use the initialization code from the utility libraries + // since we're just testing if the card is working! + if (!card.init(SPI_HALF_SPEED, chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("* is a card inserted?"); + Serial.println("* is your wiring correct?"); + Serial.println("* did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (1); + } else { + Serial.println("Wiring is correct and a card is present."); + } + + // print the type of card + Serial.println(); + Serial.print("Card type: "); + switch (card.type()) { + case SD_CARD_TYPE_SD1: + Serial.println("SD1"); + break; + case SD_CARD_TYPE_SD2: + Serial.println("SD2"); + break; + case SD_CARD_TYPE_SDHC: + Serial.println("SDHC"); + break; + default: + Serial.println("Unknown"); + } + + // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 + if (!volume.init(card)) { + Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); + while (1); + } + + Serial.print("Clusters: "); + Serial.println(volume.clusterCount()); + Serial.print("Blocks x Cluster: "); + Serial.println(volume.blocksPerCluster()); + + Serial.print("Total Blocks: "); + Serial.println(volume.blocksPerCluster() * volume.clusterCount()); + Serial.println(); + + // print the type and size of the first FAT-type volume + uint32_t volumesize; + Serial.print("Volume type is: FAT"); + Serial.println(volume.fatType(), DEC); + + volumesize = volume.blocksPerCluster(); // clusters are collections of blocks + volumesize *= volume.clusterCount(); // we'll have a lot of clusters + volumesize /= 2; // SD card blocks are always 512 bytes (2 blocks are 1 KB) + Serial.print("Volume size (KB): "); + Serial.println(volumesize); + Serial.print("Volume size (MB): "); + volumesize /= 1024; + Serial.println(volumesize); + Serial.print("Volume size (GB): "); + Serial.println((float)volumesize / 1024.0); + + Serial.println("\nFiles found on the card (name, date and size in bytes): "); + root.openRoot(volume); + + // list all files in the card with date and size + root.ls(LS_R | LS_DATE | LS_SIZE); + root.close(); +} + +void loop(void) { +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/Datalogger/Datalogger.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/Datalogger/Datalogger.ino new file mode 100644 index 00000000..c5a509cc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/Datalogger/Datalogger.ino @@ -0,0 +1,79 @@ +/* + SD card datalogger + + This example shows how to log data from three analog sensors + to an SD card using the SD library. Pin numbers reflect the default + SPI pins for Uno and Nano models + + The circuit: + analog sensors on analog pins 0, 1, and 2 + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + created 24 Nov 2010 + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. + +*/ + +#include +#include + +const int chipSelect = 10; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial); + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true); + } + + Serial.println("initialization done."); +} + +void loop() { + // make a string for assembling the data to log: + String dataString = ""; + + // read three sensors and append to the string: + for (int analogPin = 0; analogPin < 3; analogPin++) { + int sensor = analogRead(analogPin); + dataString += String(sensor); + if (analogPin < 2) { + dataString += ","; + } + } + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + File dataFile = SD.open("datalog.txt", FILE_WRITE); + + // if the file is available, write to it: + if (dataFile) { + dataFile.println(dataString); + dataFile.close(); + // print to the serial port too: + Serial.println(dataString); + } + // if the file isn't open, pop up an error: + else { + Serial.println("error opening datalog.txt"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/DumpFile/DumpFile.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/DumpFile/DumpFile.ino new file mode 100644 index 00000000..b6e99444 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/DumpFile/DumpFile.ino @@ -0,0 +1,65 @@ +/* + SD card file dump + + This example shows how to read a file from the SD card using the + SD library and send it over the serial port. + Pin numbers reflect the default SPI pins for Uno and Nano models. + + The circuit: + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + created 22 December 2010 + by Limor Fried + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. +*/ +#include + +const int chipSelect = 10; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial); + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true); + } + + Serial.println("initialization done."); + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + File dataFile = SD.open("datalog.txt"); + + // if the file is available, write to it: + if (dataFile) { + while (dataFile.available()) { + Serial.write(dataFile.read()); + } + dataFile.close(); + } + // if the file isn't open, pop up an error: + else { + Serial.println("error opening datalog.txt"); + } +} + +void loop() { +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/Files/Files.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/Files/Files.ino new file mode 100644 index 00000000..2df02691 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/Files/Files.ino @@ -0,0 +1,76 @@ +/* + SD card basic file example + + This example shows how to create and destroy an SD card file. + The circuit. Pin numbers reflect the default + SPI pins for Uno and Nano models: + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + created Nov 2010 + by David A. Mellis + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. +*/ +#include + +const int chipSelect = 10; +File myFile; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: +while (!Serial); + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this serial monitor after fixing your issue!"); + while (1); + } + Serial.println("initialization done."); + + if (SD.exists("example.txt")) { + Serial.println("example.txt exists."); + } else { + Serial.println("example.txt doesn't exist."); + } + + // open a new file and immediately close it: + Serial.println("Creating example.txt..."); + myFile = SD.open("example.txt", FILE_WRITE); + myFile.close(); + + // Check to see if the file exists: + if (SD.exists("example.txt")) { + Serial.println("example.txt exists."); + } else { + Serial.println("example.txt doesn't exist."); + } + + // delete the file: + Serial.println("Removing example.txt..."); + SD.remove("example.txt"); + + if (SD.exists("example.txt")) { + Serial.println("example.txt exists."); + } else { + Serial.println("example.txt doesn't exist."); + } +} + +void loop() { + // nothing happens after setup finishes. +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/NonBlockingWrite/NonBlockingWrite.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/NonBlockingWrite/NonBlockingWrite.ino new file mode 100644 index 00000000..101bfd05 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/NonBlockingWrite/NonBlockingWrite.ino @@ -0,0 +1,118 @@ +/* + Non-blocking Write + + This example demonstrates how to perform non-blocking writes + to a file on a SD card. The file will contain the current millis() + value every 10ms. If the SD card is busy, the data will be dataBuffered + in order to not block the sketch. + + If data is successfully written, the built in LED will flash. After a few + seconds, check the card for a file called datalog.txt + + NOTE: myFile.availableForWrite() will automatically sync the + file contents as needed. You may lose some unsynced data + still if myFile.sync() or myFile.close() is not called. + + Pin numbers reflect the default SPI pins for Uno and Nano models + Updated for clarity and uniformity with other examples + + The circuit: + analog sensors on analog ins 0, 1, and 2 + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. +*/ +#include + +const int chipSelect = 10; + +// file name to use for writing +const char filename[] = "datalog.txt"; + +// File object to represent file +File myFile; +// string to buffer output +String dataBuffer; +// last time data was written to card: +unsigned long lastMillis = 0; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // reserve 1 kB for String used as a dataBuffer + dataBuffer.reserve(1024); + + // set LED pin to output, used to blink when writing + pinMode(LED_BUILTIN, OUTPUT); + + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial); + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true); + } + + Serial.println("initialization done."); + + // If you want to start from an empty file, + // uncomment the next line: + // SD.remove(filename); + // try to open the file for writing + + myFile = SD.open(filename, FILE_WRITE); + if (!myFile) { + Serial.print("error opening "); + Serial.println(filename); + while (true); + } + + // add some new lines to start + myFile.println(); + myFile.println("Hello World!"); + Serial.println("Starting to write to file..."); +} + +void loop() { + // check if it's been over 10 ms since the last line added + unsigned long now = millis(); + if ((now - lastMillis) >= 10) { + // add a new line to the dataBuffer + dataBuffer += "Hello "; + dataBuffer += now; + dataBuffer += "\r\n"; + // print the buffer length. This will change depending on when + // data is actually written to the SD card file: + Serial.print("Unsaved data buffer length (in bytes): "); + Serial.println(dataBuffer.length()); + // note the time that the last line was added to the string + lastMillis = now; + } + + // check if the SD card is available to write data without blocking + // and if the dataBuffered data is enough for the full chunk size + unsigned int chunkSize = myFile.availableForWrite(); + if (chunkSize && dataBuffer.length() >= chunkSize) { + // write to file and blink LED + digitalWrite(LED_BUILTIN, HIGH); + myFile.write(dataBuffer.c_str(), chunkSize); + digitalWrite(LED_BUILTIN, LOW); + // remove written data from dataBuffer + dataBuffer.remove(0, chunkSize); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/ReadWrite/ReadWrite.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/ReadWrite/ReadWrite.ino new file mode 100644 index 00000000..b505a274 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/ReadWrite/ReadWrite.ino @@ -0,0 +1,80 @@ +/* + SD card read/write + + This example shows how to read and write data to and from an SD card file + The circuit. Pin numbers reflect the default + SPI pins for Uno and Nano models: + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - pin 4 (For For Uno, Nano: pin 10. For MKR Zero SD: SDCARD_SS_PIN) + + created Nov 2010 + by David A. Mellis + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. + +*/ +#include + +const int chipSelect = 10; +File myFile; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial); + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true); + } + + Serial.println("initialization done."); + + // open the file. note that only one file can be open at a time, + // so you have to close this one before opening another. + myFile = SD.open("test.txt", FILE_WRITE); + + // if the file opened okay, write to it: + if (myFile) { + Serial.print("Writing to test.txt..."); + myFile.println("testing 1, 2, 3."); + // close the file: + myFile.close(); + Serial.println("done."); + } else { + // if the file didn't open, print an error: + Serial.println("error opening test.txt"); + } + + // re-open the file for reading: + myFile = SD.open("test.txt"); + if (myFile) { + Serial.println("test.txt:"); + + // read from the file until there's nothing else in it: + while (myFile.available()) { + Serial.write(myFile.read()); + } + // close the file: + myFile.close(); + } else { + // if the file didn't open, print an error: + Serial.println("error opening test.txt"); + } +} + +void loop() { + // nothing happens after setup +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/listfiles/listfiles.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/listfiles/listfiles.ino new file mode 100644 index 00000000..ded9b13f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SD/examples/listfiles/listfiles.ino @@ -0,0 +1,86 @@ +/* + Listfiles + + This example shows how to print out the files in a + directory on a SD card. Pin numbers reflect the default + SPI pins for Uno and Nano models + + The circuit: + SD card attached to SPI bus as follows: + ** SDO - pin 11 + ** SDI - pin 12 + ** CLK - pin 13 + ** CS - depends on your SD card shield or module. + Pin 10 used here for consistency with other Arduino examples + (for MKR Zero SD: SDCARD_SS_PIN) + + created Nov 2010 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + modified 2 Feb 2014 + by Scott Fitzgerald + modified 24 July 2020 + by Tom Igoe + + This example code is in the public domain. + +*/ +#include + +const int chipSelect = 10; +File root; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + // wait for Serial Monitor to connect. Needed for native USB port boards only: + while (!Serial); + + Serial.print("Initializing SD card..."); + + if (!SD.begin(chipSelect)) { + Serial.println("initialization failed. Things to check:"); + Serial.println("1. is a card inserted?"); + Serial.println("2. is your wiring correct?"); + Serial.println("3. did you change the chipSelect pin to match your shield or module?"); + Serial.println("Note: press reset button on the board and reopen this Serial Monitor after fixing your issue!"); + while (true); + } + + Serial.println("initialization done."); + + root = SD.open("/"); + + printDirectory(root, 0); + + Serial.println("done!"); +} + +void loop() { + // nothing happens after setup finishes. +} + +void printDirectory(File dir, int numTabs) { + while (true) { + + File entry = dir.openNextFile(); + if (! entry) { + // no more files + break; + } + for (uint8_t i = 0; i < numTabs; i++) { + Serial.print('\t'); + } + Serial.print(entry.name()); + if (entry.isDirectory()) { + Serial.println("/"); + printDirectory(entry, numTabs + 1); + } else { + // files have sizes, directories do not + Serial.print("\t\t"); + Serial.println(entry.size(), DEC); + } + entry.close(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Scheduler/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Scheduler/README.adoc new file mode 100644 index 00000000..ddb56b07 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Scheduler/README.adoc @@ -0,0 +1,29 @@ +:repository-owner: arduino-libraries +:repository-name: Scheduler + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The Scheduler library enables the Arduino link:https://store.arduino.cc/arduino-due[Due], link:https://store.arduino.cc/arduino-zero[Zero], and link:https://store.arduino.cc/arduino-mkr1000-wifi[MKR1000] to run multiple functions at the same time. This allows tasks to happen without interrupting each other. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2012 The Android Open Source Project. All right reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino new file mode 100644 index 00000000..ffa32827 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino @@ -0,0 +1,81 @@ +/* + Multiple Blinks + + Demonstrates the use of the Scheduler library for the Arduino Due + + Hardware required : + * LEDs connected to pins 11, 12, and 13 + + created 8 Oct 2012 + by Cristian Maglie + Modified by + Scott Fitzgerald 19 Oct 2012 + + This example code is in the public domain + + http://www.arduino.cc/en/Tutorial/MultipleBlinks +*/ + +// Include Scheduler since we want to manage multiple tasks. +#include + +int led1 = 13; +int led2 = 12; +int led3 = 11; + +void setup() { + Serial.begin(9600); + + // Setup the 3 pins as OUTPUT + pinMode(led1, OUTPUT); + pinMode(led2, OUTPUT); + pinMode(led3, OUTPUT); + + // Add "loop2" and "loop3" to scheduling. + // "loop" is always started by default. + Scheduler.startLoop(loop2); + Scheduler.startLoop(loop3); +} + +// Task no.1: blink LED with 1 second delay. +void loop() { + digitalWrite(led1, HIGH); + + // IMPORTANT: + // When multiple tasks are running 'delay' passes control to + // other tasks while waiting and guarantees they get executed. + delay(1000); + + digitalWrite(led1, LOW); + delay(1000); +} + +// Task no.2: blink LED with 0.1 second delay. +void loop2() { + digitalWrite(led2, HIGH); + delay(100); + digitalWrite(led2, LOW); + delay(100); +} + +// Task no.3: accept commands from Serial port +// '0' turns off LED +// '1' turns on LED +void loop3() { + if (Serial.available()) { + char c = Serial.read(); + if (c == '0') { + digitalWrite(led3, LOW); + Serial.println("LED turned off!"); + } + if (c == '1') { + digitalWrite(led3, HIGH); + Serial.println("LED turned on!"); + } + } + + // IMPORTANT: + // We must call 'yield' at a regular basis to pass + // control to other tasks. + yield(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/README.adoc new file mode 100644 index 00000000..b16b16b5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: Servo + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino board to control RC (hobby) servo motors. + +For more information about this library please visit us at +https://www.arduino.cc/reference/en/libraries/servo/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Knob/Knob.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Knob/Knob.ino new file mode 100644 index 00000000..0015a468 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Knob/Knob.ino @@ -0,0 +1,26 @@ +/* + Controlling a servo position using a potentiometer (variable resistor) + by Michal Rinott + + modified on 8 Nov 2013 + by Scott Fitzgerald + http://www.arduino.cc/en/Tutorial/Knob +*/ + +#include + +Servo myservo; // create servo object to control a servo + +int potpin = A0; // analog pin used to connect the potentiometer +int val; // variable to read the value from the analog pin + +void setup() { + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + +void loop() { + val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) + val = map(val, 0, 1023, 0, 180); // scale it for use with the servo (value between 0 and 180) + myservo.write(val); // sets the servo position according to the scaled value + delay(15); // waits for the servo to get there +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Knob/readme.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Knob/readme.md new file mode 100644 index 00000000..7dc37ddb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Knob/readme.md @@ -0,0 +1,35 @@ +# Knob + +Control the position of a RC (hobby) [servo motor](http://en.wikipedia.org/wiki/Servo_motor#RC_servos) with your Arduino and a potentiometer. + +This example makes use of the Arduino `Servo` library. + +## Hardware Required + +* an Arduino board +* Servo motor +* 10k ohm potentiometer +* hook-up wires + +## Circuit + +Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow or orange and should be connected to pin 9 on the board. + +The potentiometer should be wired so that its two outer pins are connected to power (+5V) and ground, and its middle pin is connected to analog input 0 on the board. + +![](images/knob_BB.png) + +(Images developed using Fritzing. For more circuit examples, see the [Fritzing project page](http://fritzing.org/projects/)) + +## Schematic + +![](images/knob_schem.png) + +## See also + +* [attach()](/docs/api.md#attach) +* [write()](/docs/api.md#write) +* [map()](https://www.arduino.cc/en/Reference/Map) +* [analogRead()](https://www.arduino.cc/en/Reference/AnalogRead) +* [Servo library reference](/docs/readme.md) +* [Sweep](../Sweep) - Sweep the shaft of a servo motor back and forth diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Sweep/Sweep.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Sweep/Sweep.ino new file mode 100644 index 00000000..e988bbd8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Sweep/Sweep.ino @@ -0,0 +1,31 @@ +/* Sweep + by BARRAGAN + This example code is in the public domain. + + modified 8 Nov 2013 + by Scott Fitzgerald + https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep +*/ + +#include + +Servo myservo; // create servo object to control a servo +// twelve servo objects can be created on most boards + +int pos = 0; // variable to store the servo position + +void setup() { + myservo.attach(9); // attaches the servo on pin 9 to the servo object +} + +void loop() { + for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees + // in steps of 1 degree + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15 ms for the servo to reach the position + } + for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees + myservo.write(pos); // tell servo to go to position in variable 'pos' + delay(15); // waits 15 ms for the servo to reach the position + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Sweep/readme.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Sweep/readme.md new file mode 100644 index 00000000..bb07d5a1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Servo/examples/Sweep/readme.md @@ -0,0 +1,29 @@ +# Sweep + +Sweeps the shaft of a RC [servo motor](http://en.wikipedia.org/wiki/Servo_motor#RC_servos) back and forth across 180 degrees. + +## Hardware Required + +* Arduino Board +* Servo Motor +* Hook-up wires + +## Circuit + +Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow, orange or white and should be connected to pin 9 on the board. + +![](images/sweep_bb.png) + +(Images developed using Fritzing. For more circuit examples, see the [Fritzing project page](http://fritzing.org/projects/)) + +## Schematic + +![](images/sweep_schem.png) + +## See also + +* [attach()](/docs/api.md#attach) +* [write()](/docs/api.md#write) +* [map()](https://www.arduino.cc/en/Reference/Map) +* [Servo library reference](/docs/readme.md) +* [Knob](../Knob) - Control the position of a servo with a potentiometer diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/README.md b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/README.md new file mode 100644 index 00000000..76c135ce --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/README.md @@ -0,0 +1,154 @@ +# SigFox Library + +[![Check Arduino status](https://github.com/arduino-libraries/SigFox/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino-libraries/SigFox/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/compile-examples.yml) +[![Spell Check status](https://github.com/arduino-libraries/SigFox/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/SigFox/actions/workflows/spell-check.yml) + +## Description + +This library allows you to use the ATMEL SigFox transceiver (ATAB8520E) on the Arduino MKRFOX1200 board. For additional information on the Arduino MKR Fox 1200 board, see the [Getting Started page](https://www.arduino.cc/en/Guide/MKRFox1200) and the [product page](https://store.arduino.cc/arduino-mkr-fox-1200-1408). + +SigFox employs a cellular system that enables remote devices to connect using Ultra-Narrow Band (UNB) technology. It requires little energy, being termed Low-power Wide-area network (LPWAN). + +## Installation + +![image](https://user-images.githubusercontent.com/36513474/67494578-d9213100-f692-11e9-9cc2-e18e69ae7d3c.png) + +### First Method + +1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries +1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. +1. Then search for SigFox using the search bar. +1. Click on the text area and then select the specific version and install it. + +### Second Method + +1. Navigate to the Releases page. +1. Download the latest release. +1. Extract the zip file +1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library + +## Features + +- ### Ultra Narrowband + + This library enables remote devices to use UNB. The benefit of using ultra narrowband receiver is that it rejects noise and interference which may enter the receiver, enabling an acceptable signal-to-noise ratio to be achieved with a relatively weak received signal + +- ### LPWAN + + SigFox library requires Low Powered Wide Area Network. This technology connects low-bandwidth devices with low rate of bits over long ranges. + +- ### Good fit for small applications + + This library is a good fit for any application that needs to send small, infrequent bursts of data. Things like basic alarm systems, location monitoring, and simple metering are all examples of one-way systems that might make sense for this network. + +- ### Give back + + SigFox is free for everyone. The licensed document can be copied, redistributed and used in the projects, assignments or anywhere. + +- ### Licensed Document + + Library is licensed under GNU lesser General Public License. It's not allowed to make changes in the functions or anything. The user simply has to import the library in the project and can use any of its functions by just calling it. + +## Functions + +- begin() +- beginPacket() +- write() +- print() +- endPacket() +- parsePacket() +- statusCode() +- AtmVersion() +- SigVersion() +- ID() +- PAC() +- reset() +- internalTemperature() +- debug() +- noDebug() +- end() +- peek() +- available() +- read() + +For further functions description visit [SigFox](https://www.arduino.cc/en/Reference/SigFox) + +## Example + +There are many examples implemented where this library is used. You can find other examples from [Github-SigFox](https://github.com/arduino-libraries/SigFox/tree/master/examples) and [Arduino-Reference](https://www.arduino.cc/en/Reference/SigFox) + +- ### Send Boolean + + This sketch demonstrates how to send a simple binary data ( 0 or 1 ) using a MKR Fox 1200. If the application only needs to send one bit of information the transmission time (and thus power consumption) will be much lower than sending a full 12 bytes packet. + +``` C++ +#include + +bool value_to_send = true; + +#define DEBUG 1 + +void setup() { + + if (DEBUG){ + Serial.begin(9600); + while (!Serial) {}; + } + + if (!SigFox.begin()) { + if (DEBUG){ + Serial.println("Sigfox module unavailable !"); + } + return; + } + + if (DEBUG){ + SigFox.debug(); + Serial.println("ID = " + SigFox.ID()); + } + + delay(100); + + SigFox.beginPacket(); + SigFox.write(value_to_send); + int ret = SigFox.endPacket(); + + if (DEBUG){ + Serial.print("Status : "); + Serial.println(ret); + } +} + +void loop(){} +``` + +## Contributing + +If you want to contribute to this project: + +- Report bugs and errors +- Ask for enhancements +- Create issues and pull requests +- Tell others about this library +- Contribute new protocols + +Please read [CONTRIBUTING.md](https://github.com/arduino-libraries/SigFox/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. + +## Credits + +The Library created and maintained by Arduino LLC + +Based on previous work by: + +- M. Facchin +- N. Lesconnec +- N. Barcucci + +## Current stable version + +**version:** v1.0.4 + +## License + +This library is licensed under [GNU LGPL](https://www.gnu.org/licenses/lgpl-3.0.en.html). diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/EventTrigger/EventTrigger.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/EventTrigger/EventTrigger.ino new file mode 100644 index 00000000..f83f00c8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/EventTrigger/EventTrigger.ino @@ -0,0 +1,104 @@ +/* + SigFox Event Trigger tutorial + + This sketch demonstrates the usage of a MKR Fox 1200 + to build a battery-powered alarm sensor with email notifications + + A couple of sensors (normally open) should be wired between pins 1 and 2 and GND. + + This example code is in the public domain. +*/ + +#include +#include + +// Set debug to false to enable continuous mode +// and disable serial prints +int debug = true; + +volatile int alarm_source = 0; + +void setup() { + + if (debug == true) { + + // We are using Serial1 instead of Serial because we are going into standby + // and the USB port could get confused during wakeup. To read the debug prints, + // connect pins 13-14 (TX-RX) to a 3.3 V USB-to-serial converter + + Serial1.begin(115200); + while (!Serial1) {} + } + + if (!SigFox.begin()) { + //something is really wrong, try rebooting + reboot(); + } + + //Send module to standby until we need to send a message + SigFox.end(); + + if (debug == true) { + // Enable debug prints and LED indication if we are testing + SigFox.debug(); + } + + // attach pin 0 and 1 to a switch and enable the interrupt on voltage falling event + pinMode(0, INPUT_PULLUP); + LowPower.attachInterruptWakeup(0, alarmEvent1, FALLING); + + pinMode(1, INPUT_PULLUP); + LowPower.attachInterruptWakeup(1, alarmEvent2, FALLING); +} + +void loop() +{ + // Sleep until an event is recognized + LowPower.sleep(); + + // if we get here it means that an event was received + + SigFox.begin(); + + if (debug == true) { + Serial1.println("Alarm event on sensor " + String(alarm_source)); + } + delay(100); + + // 3 bytes (ALM) + 8 bytes (ID as String) + 1 byte (source) < 12 bytes + String to_be_sent = "ALM" + SigFox.ID() + String(alarm_source); + + SigFox.beginPacket(); + SigFox.print(to_be_sent); + int ret = SigFox.endPacket(); + + // shut down module, back to standby + SigFox.end(); + + if (debug == true) { + if (ret > 0) { + Serial1.println("No transmission"); + } else { + Serial1.println("Transmission ok"); + } + + Serial1.println(SigFox.status(SIGFOX)); + Serial1.println(SigFox.status(ATMEL)); + + // Loop forever if we are testing for a single event + while (1) {}; + } +} + +void alarmEvent1() { + alarm_source = 1; +} + +void alarmEvent2() { + alarm_source = 2; +} + +void reboot() { + NVIC_SystemReset(); + while (1); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/FirstConfiguration/FirstConfiguration.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/FirstConfiguration/FirstConfiguration.ino new file mode 100644 index 00000000..9e182ebb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/FirstConfiguration/FirstConfiguration.ino @@ -0,0 +1,145 @@ +/* + SigFox First Configuration + + This sketch demonstrates the usage of MKR Fox 1200 Sigfox module. + Since the board is designed with low power in mind, it depends directly on the ArduinoLowPower library + + This example code is in the public domain. +*/ + +#include +#include + +void setup() { + Serial.begin(9600); + while (!Serial) {}; + + // Uncomment this line and comment begin() if you are working with a custom board + //if (!SigFox.begin(SPI1, 30, 31, 33, 28, LED_BUILTIN)) { + if (!SigFox.begin()) { + Serial.println("Shield error or not present!"); + return; + } + // Enable debug LED and disable automatic deep sleep + // Comment this line when shipping your project :) + SigFox.debug(); + + String version = SigFox.SigVersion(); + String ID = SigFox.ID(); + String PAC = SigFox.PAC(); + + // Display module information + Serial.println("MKR Fox 1200 Sigfox first configuration"); + Serial.println("SigFox FW version " + version); + Serial.println("ID = " + ID); + Serial.println("PAC = " + PAC); + + Serial.println(""); + + Serial.print("Module temperature: "); + Serial.println(SigFox.internalTemperature()); + + Serial.println("Register your board on https://buy.sigfox.com/activate with provided ID and PAC"); + Serial.println("The displayed PAC is the factory value. It is a throw-away value, which can only be used once for registration."); + Serial.println("If this device has already been registered, you can retrieve the updated PAC value on https://backend.sigfox.com/device/list"); + Serial.println("Join the Sigfox Builders Slack community to exchange with other developers, get help .. and find new ideas! https://builders.iotagency.sigfox.com/"); + delay(100); + + // Send the module to the deepest sleep + SigFox.end(); + + Serial.println("Type the message to be sent"); + while (!Serial.available()); + + String message; + while (Serial.available()) { + message += (char)Serial.read(); + } + + // Every SigFox packet cannot exceed 12 bytes + // If the string is longer, only the first 12 bytes will be sent + + if (message.length() > 12) { + Serial.println("Message too long, only first 12 bytes will be sent"); + } + + Serial.println("Sending " + message); + + // Remove EOL + message.trim(); + + // Example of message that can be sent + // sendString(message); + + Serial.println("Getting the response will take up to 50 seconds"); + Serial.println("The LED will blink while the operation is ongoing"); + + // Example of send and read response + sendStringAndGetResponse(message); +} + +void loop() +{ +} + +void sendString(String str) { + // Start the module + SigFox.begin(); + // Wait at least 30mS after first configuration (100mS before) + delay(100); + // Clears all pending interrupts + SigFox.status(); + delay(1); + + SigFox.beginPacket(); + SigFox.print(str); + + int ret = SigFox.endPacket(); // send buffer to SIGFOX network + if (ret > 0) { + Serial.println("No transmission"); + } else { + Serial.println("Transmission ok"); + } + + Serial.println(SigFox.status(SIGFOX)); + Serial.println(SigFox.status(ATMEL)); + SigFox.end(); +} + +void sendStringAndGetResponse(String str) { + // Start the module + SigFox.begin(); + // Wait at least 30mS after first configuration (100mS before) + delay(100); + // Clears all pending interrupts + SigFox.status(); + delay(1); + + SigFox.beginPacket(); + SigFox.print(str); + + int ret = SigFox.endPacket(true); // send buffer to SIGFOX network and wait for a response + if (ret > 0) { + Serial.println("No transmission"); + } else { + Serial.println("Transmission ok"); + } + + Serial.println(SigFox.status(SIGFOX)); + Serial.println(SigFox.status(ATMEL)); + + if (SigFox.parsePacket()) { + Serial.println("Response from server:"); + while (SigFox.available()) { + Serial.print("0x"); + Serial.println(SigFox.read(), HEX); + } + } else { + Serial.println("Could not get any response from the server"); + Serial.println("Check the Sigfox coverage in your area"); + Serial.println("If you are indoor, check the 20 dB coverage or move near a window"); + } + Serial.println(); + + SigFox.end(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/SendBoolean/SendBoolean.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/SendBoolean/SendBoolean.ino new file mode 100644 index 00000000..384612be --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/SendBoolean/SendBoolean.ino @@ -0,0 +1,55 @@ +/* + SigFox Send Boolean tutorial + + This sketch demonstrates how to send a simple binary data ( 0 or 1 ) using a MKR Fox 1200. + If the application only needs to send one bit of information the transmission time + (and thus power consumption) will be much lower than sending a full 12 bytes packet. + + This example code is in the public domain. +*/ + +#include + +// We want to send a Boolean value to signal a binary event +// like open/close or on/off + +bool value_to_send = true; + +#define DEBUG 1 + +void setup() { + + if (DEBUG){ + Serial.begin(9600); + while (!Serial) {}; + } + + // Initialize the Sigfox module + if (!SigFox.begin()) { + if (DEBUG){ + Serial.println("Sigfox module unavailable !"); + } + return; + } + + // If we want to to debug the application, print the device ID to easily find it in the backend + if (DEBUG){ + SigFox.debug(); + Serial.println("ID = " + SigFox.ID()); + } + + delay(100); + + // Compose a message as usual; the single bit transmission will be performed transparently + // if the data we want to send is suitable + SigFox.beginPacket(); + SigFox.write(value_to_send); + int ret = SigFox.endPacket(); + + if (DEBUG){ + Serial.print("Status : "); + Serial.println(ret); + } +} + +void loop(){} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitor/WeatherMonitor.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitor/WeatherMonitor.ino new file mode 100644 index 00000000..bd73d0a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitor/WeatherMonitor.ino @@ -0,0 +1,171 @@ +/* + SigFox Simple Weather Station + + This sketch demonstrates the usage of MKR Fox 1200 as a simple weather station. + It uses + the onboard temperature sensor + HTU21D I2C sensor to get humidity + Bosch BMP280 to get the barometric pressure + TSL2561 Light Sensor to get luminosity + + Download the needed libraries from the following links + http://librarymanager/all#BMP280&Adafruit + http://librarymanager/all#HTU21D&Adafruit + http://librarymanager/all#TSL2561&Adafruit + http://librarymanager/all#adafruit&sensor&abstraction + + Since the Sigfox network can send a maximum of 120 messages per day (depending on your plan) + we'll optimize the readings and send data in compact binary format + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include +#include +#include "conversions.h" + +// Set oneshot to false to trigger continuous mode when you finished setting up the whole flow +int oneshot = true; + +Adafruit_BMP280 bmp; +Adafruit_HTU21DF htu = Adafruit_HTU21DF(); +Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); + +#define STATUS_OK 0 +#define STATUS_BMP_KO 1 +#define STATUS_HTU_KO 2 +#define STATUS_TSL_KO 4 + +/* + ATTENTION - the structure we are going to send MUST + be declared "packed" otherwise we'll get padding mismatch + on the sent data - see http://www.catb.org/esr/structure-packing/#_structure_alignment_and_padding + for more details +*/ +typedef struct __attribute__ ((packed)) sigfox_message { + uint8_t status; + int16_t moduleTemperature; + int16_t bmpTemperature; + uint16_t bmpPressure; + uint16_t htuHumidity; + uint16_t tlsLight; + uint8_t lastMessageStatus; +} SigfoxMessage; + +// stub for message which will be sent +SigfoxMessage msg; + +void setup() { + + if (oneshot == true) { + // Wait for the serial + Serial.begin(115200); + while (!Serial) {} + } + + if (!SigFox.begin()) { + // Something is really wrong, try rebooting + // Reboot is useful if we are powering the board using an unreliable power source + // (eg. solar panels or other energy harvesting methods) + reboot(); + } + + //Send module to standby until we need to send a message + SigFox.end(); + + if (oneshot == true) { + // Enable debug prints and LED indication if we are testing + SigFox.debug(); + } + + // Configure the sensors and populate the status field + if (!bmp.begin()) { + msg.status |= STATUS_BMP_KO; + } else { + Serial.println("BMP OK"); + } + + if (!htu.begin()) { + msg.status |= STATUS_HTU_KO; + } else { + Serial.println("HTU OK"); + } + + if (!tsl.begin()) { + msg.status |= STATUS_TSL_KO; + } else { + Serial.println("TLS OK"); + tsl.enableAutoRange(true); + tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); + } +} + +void loop() { + // Every 15 minutes, read all the sensors and send them + // Let's try to optimize the data format + // Only use floats as intermediate representation, don't send them directly + + sensors_event_t event; + + float pressure = bmp.readPressure(); + msg.bmpPressure = convertoFloatToUInt16(pressure, 200000); + float temperature = bmp.readTemperature(); + msg.bmpTemperature = convertoFloatToInt16(temperature, 60, -60); + + tsl.getEvent(&event); + if (event.light) { + msg.tlsLight = convertoFloatToUInt16(event.light, 100000); + } + + float humidity = htu.readHumidity(); + msg.htuHumidity = convertoFloatToUInt16(humidity, 110); + + // Start the module + SigFox.begin(); + // Wait at least 30 ms after first configuration (100 ms before) + delay(100); + + // We can only read the module temperature before SigFox.end() + temperature = SigFox.internalTemperature(); + msg.moduleTemperature = convertoFloatToInt16(temperature, 60, -60); + + if (oneshot == true) { + Serial.println("Pressure: " + String(pressure)); + Serial.println("External temperature: " + String(temperature)); + Serial.println("Internal temp: " + String(temperature)); + Serial.println("Light: " + String(event.light)); + Serial.println("Humidity: " + String(humidity)); + } + + // Clears all pending interrupts + SigFox.status(); + delay(1); + + SigFox.beginPacket(); + SigFox.write((uint8_t*)&msg, 12); + + msg.lastMessageStatus = SigFox.endPacket(); + + if (oneshot == true) { + Serial.println("Status: " + String(msg.lastMessageStatus)); + } + + SigFox.end(); + + if (oneshot == true) { + // spin forever, so we can test that the backend is behaving correctly + while (1) {} + } + + //Sleep for 15 minutes + LowPower.sleep(15 * 60 * 1000); +} + +void reboot() { + NVIC_SystemReset(); + while (1); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitor/conversions.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitor/conversions.h new file mode 100644 index 00000000..d54070ad --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitor/conversions.h @@ -0,0 +1,13 @@ + +#define UINT16_t_MAX 65536 +#define INT16_t_MAX UINT16_t_MAX/2 + +int16_t convertoFloatToInt16(float value, long max, long min) { + float conversionFactor = (float) (INT16_t_MAX) / (float)(max - min); + return (int16_t)(value * conversionFactor); +} + +uint16_t convertoFloatToUInt16(float value, long max, long min = 0) { + float conversionFactor = (float) (UINT16_t_MAX) / (float)(max - min); + return (uint16_t)(value * conversionFactor); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/WeatherMonitorStream.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/WeatherMonitorStream.ino new file mode 100644 index 00000000..9685b9a3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/WeatherMonitorStream.ino @@ -0,0 +1,145 @@ +/* + SigFox Simple Weather Station + + This sketch demonstrates the usage of MKR Fox 1200 as a simple weather station. + It uses + the onboard temperature sensor + HTU21D I2C sensor to get humidity + Bosch BMP280 to get the barometric pressure + TSL2561 Light Sensor to get luminosity + + Download the needed libraries from the following links + http://librarymanager/all#BMP280&Adafruit + http://librarymanager/all#HTU21D&Adafruit + http://librarymanager/all#TSL2561&Adafruit + http://librarymanager/all#adafruit&sensor&abstraction + + Since the Sigfox network can send a maximum of 120 messages per day (depending on your plan) + we'll optimize the readings and send data in compact binary format + + This sketch shows how to use the Stream APIs of the library. + Refer to the WeatherMonitor sketch for an example using data structures. + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include +#include +#include "conversions.h" + +// Set oneshot to false to trigger continuous mode when you finished setting up the whole flow +int oneshot = true; + +Adafruit_BMP280 bmp; +Adafruit_HTU21DF htu = Adafruit_HTU21DF(); +Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345); + +#define STATUS_OK 0 +#define STATUS_BMP_KO 1 +#define STATUS_HTU_KO 2 +#define STATUS_TSL_KO 4 + +byte status; + +void setup() { + + if (oneshot == true) { + // Wait for the serial + Serial.begin(115200); + while (!Serial) {} + } + + if (!SigFox.begin()) { + // Something is really wrong, try rebooting + // Reboot is useful if we are powering the board using an unreliable power source + // (eg. solar panels or other energy harvesting methods) + reboot(); + } + + //Send module to standby until we need to send a message + SigFox.end(); + + if (oneshot == true) { + // Enable debug prints and LED indication if we are testing + SigFox.debug(); + } + + // Configure the sensors and populate the status field + if (!bmp.begin()) { + status |= STATUS_BMP_KO; + } else { + Serial.println("BMP OK"); + } + + if (!htu.begin()) { + status |= STATUS_HTU_KO; + } else { + Serial.println("HTU OK"); + } + + if (!tsl.begin()) { + status |= STATUS_TSL_KO; + } else { + Serial.println("TLS OK"); + tsl.enableAutoRange(true); + tsl.setIntegrationTime(TSL2561_INTEGRATIONTIME_13MS); + } +} + +void loop() { + // Every 15 minutes, read all the sensors and send them + // Let's try to optimize the data format + // Only use floats as intermediate representation, don't send them directly + + sensors_event_t event; + + float pressure = bmp.readPressure(); + float temperature = bmp.readTemperature(); + float humidity = htu.readHumidity(); + + tsl.getEvent(&event); + float light = event.light; + + // Start the module + SigFox.begin(); + // Wait at least 30 ms after first configuration (100 ms before) + delay(100); + + // Prepare the packet using the Stream APIs + SigFox.beginPacket(); + SigFox.write((byte)status); + SigFox.write((short)convertoFloatToInt16(temperature, 60, -60)); + SigFox.write((unsigned short)convertoFloatToUInt16(pressure, 200000)); + SigFox.write((unsigned short)convertoFloatToUInt16(humidity, 110)); + SigFox.write((unsigned short)convertoFloatToUInt16(light, 100000)); + + int ret = SigFox.endPacket(); + + if (oneshot == true) { + Serial.println("Pressure: " + String(pressure)); + Serial.println("External temperature: " + String(temperature)); + Serial.println("Light: " + String(event.light)); + Serial.println("Humidity: " + String(humidity)); + Serial.println("Status: " + String(ret)); + } + + // Shut down the module + SigFox.end(); + + if (oneshot == true) { + // spin forever, so we can test that the backend is behaving correctly + while (1) {} + } + + //Sleep for 15 minutes + LowPower.sleep(15 * 60 * 1000); +} + +void reboot() { + NVIC_SystemReset(); + while (1); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/conversions.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/conversions.h new file mode 100644 index 00000000..d54070ad --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/SigFox/examples/WeatherMonitorStream/conversions.h @@ -0,0 +1,13 @@ + +#define UINT16_t_MAX 65536 +#define INT16_t_MAX UINT16_t_MAX/2 + +int16_t convertoFloatToInt16(float value, long max, long min) { + float conversionFactor = (float) (INT16_t_MAX) / (float)(max - min); + return (int16_t)(value * conversionFactor); +} + +uint16_t convertoFloatToUInt16(float value, long max, long min = 0) { + float conversionFactor = (float) (UINT16_t_MAX) / (float)(max - min); + return (uint16_t)(value * conversionFactor); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/README.adoc new file mode 100644 index 00000000..55b91a88 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/README.adoc @@ -0,0 +1,33 @@ +:repository-owner: arduino-libraries +:repository-name: Stepper + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows you to control unipolar or bipolar stepper motors. To use it you will need a stepper motor, and the appropriate hardware to control it. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) Arduino LLC. All right reserved. +Copyright (c) Sebastian Gassner. All right reserved. +Copyright (c) Noah Shibley. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/MotorKnob/MotorKnob.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/MotorKnob/MotorKnob.ino new file mode 100644 index 00000000..d0141472 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/MotorKnob/MotorKnob.ino @@ -0,0 +1,39 @@ +/* + * MotorKnob + * + * A stepper motor follows the turns of a potentiometer + * (or other sensor) on analog input 0. + * + * https://docs.arduino.cc/learn/electronics/stepper-motors + * This example code is in the public domain. + */ + +#include + +// change this to the number of steps on your motor +#define STEPS 100 + +// create an instance of the Stepper class, specifying +// the number of steps of the motor and the pins it's +// attached to +Stepper stepper(STEPS, 8, 9, 10, 11); + +// the previous reading from the analog input +int previous = 0; + +void setup() { + // set the speed of the motor to 30 RPMs + stepper.setSpeed(30); +} + +void loop() { + // get the sensor value + int val = analogRead(0); + + // move a number of steps equal to the change in the + // sensor reading + stepper.step(val - previous); + + // remember the previous value of the sensor + previous = val; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino new file mode 100644 index 00000000..2567a791 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_oneRevolution/stepper_oneRevolution.ino @@ -0,0 +1,42 @@ +/* + Stepper Motor Control - one revolution + + This program drives a unipolar or bipolar stepper motor. + The motor is attached to digital pins 8 - 11 of the Arduino. + + The motor should revolve one revolution in one direction, then + one revolution in the other direction. + + + Created 11 Mar. 2007 + Modified 30 Nov. 2009 + by Tom Igoe + + */ + +#include + +const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution +// for your motor + +// initialize the Stepper library on pins 8 through 11: +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); + +void setup() { + // set the speed at 60 rpm: + myStepper.setSpeed(60); + // initialize the serial port: + Serial.begin(9600); +} + +void loop() { + // step one revolution in one direction: + Serial.println("clockwise"); + myStepper.step(stepsPerRevolution); + delay(500); + + // step one revolution in the other direction: + Serial.println("counterclockwise"); + myStepper.step(-stepsPerRevolution); + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino new file mode 100644 index 00000000..cf86df5c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_oneStepAtATime/stepper_oneStepAtATime.ino @@ -0,0 +1,42 @@ +/* + Stepper Motor Control - one step at a time + + This program drives a unipolar or bipolar stepper motor. + The motor is attached to digital pins 8 - 11 of the Arduino. + + The motor will step one step at a time, very slowly. You can use this to + test that you've got the four wires of your stepper wired to the correct + pins. If wired correctly, all steps should be in the same direction. + + Use this also to count the number of steps per revolution of your motor, + if you don't know it. Then plug that number into the oneRevolution + example to see if you got it right. + + Created 30 Nov. 2009 + by Tom Igoe + + */ + +#include + +const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution +// for your motor + +// initialize the Stepper library on pins 8 through 11: +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); + +int stepCount = 0; // number of steps the motor has taken + +void setup() { + // initialize the serial port: + Serial.begin(9600); +} + +void loop() { + // step one step: + myStepper.step(1); + Serial.print("steps:"); + Serial.println(stepCount); + stepCount++; + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino new file mode 100644 index 00000000..27a709a9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Stepper/examples/stepper_speedControl/stepper_speedControl.ino @@ -0,0 +1,45 @@ +/* + Stepper Motor Control - speed control + + This program drives a unipolar or bipolar stepper motor. + The motor is attached to digital pins 8 - 11 of the Arduino. + A potentiometer is connected to analog input 0. + + The motor will rotate in a clockwise direction. The higher the potentiometer value, + the faster the motor speed. Because setSpeed() sets the delay between steps, + you may notice the motor is less responsive to changes in the sensor value at + low speeds. + + Created 30 Nov. 2009 + Modified 28 Oct 2010 + by Tom Igoe + + */ + +#include + +const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution +// for your motor + + +// initialize the Stepper library on pins 8 through 11: +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); + +int stepCount = 0; // number of steps the motor has taken + +void setup() { + // nothing to do inside the setup +} + +void loop() { + // read the sensor value: + int sensorReading = analogRead(A0); + // map it to a range from 0 to 100: + int motorSpeed = map(sensorReading, 0, 1023, 0, 100); + // set the motor speed: + if (motorSpeed > 0) { + myStepper.setSpeed(motorSpeed); + // step 1/100 of a revolution: + myStepper.step(stepsPerRevolution / 100); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/LICENSE.txt new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/LICENSE.txt @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/README.adoc new file mode 100644 index 00000000..5cfb3d27 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/README.adoc @@ -0,0 +1,13 @@ +:repository-owner: arduino-libraries +:repository-name: TFT + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library enables an Arduino board to communicate with the Arduino TFT LCD screen. It simplifies the process for drawing shapes, lines, images, and text to the screen. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/TFTLibrary diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino new file mode 100644 index 00000000..910cd698 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTBitmapLogo/TFTBitmapLogo.ino @@ -0,0 +1,108 @@ +/* + + Arduino TFT Bitmap Logo example + + This example reads an image file from a micro-SD card + and draws it on the screen, at random locations. + + In this sketch, the Arduino logo is read from a micro-SD card. + There is a .bmp file included with this sketch. + - open the sketch folder (Ctrl-K or Cmd-K) + - copy the "arduino.bmp" file to a micro-SD + - put the SD into the SD slot of the Arduino TFT module. + + This example code is in the public domain. + + Created 19 April 2013 by Enrico Gueli + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTBitmapLogo + + */ + +// include the necessary libraries +#include +#include +#include // Arduino LCD library + +// pin definitions for the Uno +#define sd_cs 4 +#define lcd_cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +//#define sd_cs 8 +//#define lcd_cs 7 +//#define dc 0 +//#define rst 1 + +TFT TFTscreen = TFT(lcd_cs, dc, rst); + +// this variable represents the image to be drawn on screen +PImage logo; + + +void setup() { + // initialize the GLCD and show a message + // asking the user to open the serial line + TFTscreen.begin(); + TFTscreen.background(255, 255, 255); + + TFTscreen.stroke(0, 0, 255); + TFTscreen.println(); + TFTscreen.println(F("Arduino TFT Bitmap Example")); + TFTscreen.stroke(0, 0, 0); + TFTscreen.println(F("Open Serial Monitor")); + TFTscreen.println(F("to run the sketch")); + + // initialize the serial port: it will be used to + // print some diagnostic info + Serial.begin(9600); + while (!Serial) { + // wait for serial port to connect. Needed for native USB port only + } + + // clear the GLCD screen before starting + TFTscreen.background(255, 255, 255); + + // try to access the SD card. If that fails (e.g. + // no card present), the setup process will stop. + Serial.print(F("Initializing SD card...")); + if (!SD.begin(sd_cs)) { + Serial.println(F("failed!")); + return; + } + Serial.println(F("OK!")); + + // initialize and clear the GLCD screen + TFTscreen.begin(); + TFTscreen.background(255, 255, 255); + + // now that the SD card can be accessed, try to load the + // image file. + logo = TFTscreen.loadImage("arduino.bmp"); + if (!logo.isValid()) { + Serial.println(F("error while loading arduino.bmp")); + } +} + +void loop() { + // don't do anything if the image wasn't loaded correctly. + if (logo.isValid() == false) { + return; + } + + Serial.println(F("drawing image")); + + // get a random location to draw the image at. + // To avoid the image being drawn outside the screen, + // take into account the image size. + int x = random(TFTscreen.width() - logo.width()); + int y = random(TFTscreen.height() - logo.height()); + + // draw the image to the screen + TFTscreen.image(logo, x, y); + + // wait a little bit before drawing again + delay(1500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino new file mode 100644 index 00000000..f0c602d7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTColorPicker/TFTColorPicker.ino @@ -0,0 +1,66 @@ +/* + + TFT Color Picker + + This example for the Arduino screen reads the input of + potentiometers or analog sensors attached to A0, A1, + and A2 and uses the values to change the screen's color. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTColorPicker + + */ + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +#include // Arduino LCD library +#include + +TFT TFTscreen = TFT(cs, dc, rst); + +void setup() { + // begin serial communication + Serial.begin(9600); + + // initialize the display + TFTscreen.begin(); + + // set the background to white + TFTscreen.background(255, 255, 255); + +} + +void loop() { + + // read the values from your sensors and scale them to 0-255 + int redVal = map(analogRead(A0), 0, 1023, 0, 255); + int greenVal = map(analogRead(A1), 0, 1023, 0, 255); + int blueVal = map(analogRead(A2), 0, 1023, 0, 255); + + // draw the background based on the mapped values + TFTscreen.background(redVal, greenVal, blueVal); + + // send the values to the Serial Monitor + Serial.print("background("); + Serial.print(redVal); + Serial.print(" , "); + Serial.print(greenVal); + Serial.print(" , "); + Serial.print(blueVal); + Serial.println(")"); + + // wait for a moment + delay(33); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino new file mode 100644 index 00000000..db16f77d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTDisplayText/TFTDisplayText.ino @@ -0,0 +1,73 @@ +/* + Arduino TFT text example + + This example demonstrates how to draw text on the + TFT with an Arduino. The Arduino reads the value + of an analog sensor attached to pin A0, and writes + the value to the LCD screen, updating every + quarter second. + + This example code is in the public domain + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTDisplayText + + */ + +#include // Arduino LCD library +#include + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); + +// char array to print to the screen +char sensorPrintout[4]; + +void setup() { + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // write the static text to the screen + // set the font color to white + TFTscreen.stroke(255, 255, 255); + // set the font size + TFTscreen.setTextSize(2); + // write the text to the top left corner of the screen + TFTscreen.text("Sensor Value :\n ", 0, 0); + // set the font size very large for the loop + TFTscreen.setTextSize(5); +} + +void loop() { + + // Read the value of the sensor on A0 + String sensorVal = String(analogRead(A0)); + + // convert the reading to a char array + sensorVal.toCharArray(sensorPrintout, 4); + + // set the font color + TFTscreen.stroke(255, 255, 255); + // print the sensor value + TFTscreen.text(sensorPrintout, 0, 20); + // wait for a moment + delay(250); + // erase the text you just wrote + TFTscreen.stroke(0, 0, 0); + TFTscreen.text(sensorPrintout, 0, 20); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino new file mode 100644 index 00000000..41c02002 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTEtchASketch/TFTEtchASketch.ino @@ -0,0 +1,83 @@ +/* + + TFT EtchASketch + + This example for the Arduino screen draws a white point + on the GLCD based on the values of 2 potentiometers. + To clear the screen, press a button attached to pin 2. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTEtchASketch + + */ + +#include // Arduino LCD library +#include + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +TFT TFTscreen = TFT(cs, dc, rst); + +// initial position of the cursor +int xPos = TFTscreen.width() / 2; +int yPos = TFTscreen.height() / 2; + +// pin the erase switch is connected to +int erasePin = 2; + +void setup() { + // declare inputs + pinMode(erasePin, INPUT); + // initialize the screen + TFTscreen.begin(); + // make the background black + TFTscreen.background(0, 0, 0); +} + +void loop() { + // read the potentiometers on A0 and A1 + int xValue = analogRead(A0); + int yValue = analogRead(A1); + + // map the values and update the position + xPos = xPos + (map(xValue, 0, 1023, 2, -2)); + yPos = yPos + (map(yValue, 0, 1023, -2, 2)); + + // don't let the point go past the screen edges + if (xPos > 159) { + (xPos = 159); + } + + if (xPos < 0) { + (xPos = 0); + } + if (yPos > 127) { + (yPos = 127); + } + + if (yPos < 0) { + (yPos = 0); + } + + // draw the point + TFTscreen.stroke(255, 255, 255); + TFTscreen.point(xPos, yPos); + + // read the value of the pin, and erase the screen if pressed + if (digitalRead(erasePin) == HIGH) { + TFTscreen.background(0, 0, 0); + } + + delay(33); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino new file mode 100644 index 00000000..2a9c0f0c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTGraph/TFTGraph.ino @@ -0,0 +1,69 @@ +/* + + TFT Graph + + This example for an Arduino screen reads + the value of an analog sensor on A0, and + graphs the values on the screen. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTGraph + + */ + +#include // Arduino LCD library +#include + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +TFT TFTscreen = TFT(cs, dc, rst); + +// position of the line on screen +int xPos = 0; + +void setup() { + // initialize the serial port + Serial.begin(9600); + + // initialize the display + TFTscreen.begin(); + + // clear the screen with a pretty color + TFTscreen.background(250, 16, 200); +} + +void loop() { + // read the sensor and map it to the screen height + int sensor = analogRead(A0); + int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height()); + + // print out the height to the Serial Monitor + Serial.println(drawHeight); + + // draw a line in a nice color + TFTscreen.stroke(250, 180, 10); + TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height()); + + // if the graph has reached the screen edge + // erase the screen and start again + if (xPos >= 160) { + xPos = 0; + TFTscreen.background(250, 16, 200); + } else { + // increment the horizontal position: + xPos++; + } + + delay(16); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino new file mode 100644 index 00000000..ccdb33c3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Arduino/TFTPong/TFTPong.ino @@ -0,0 +1,133 @@ +/* + + TFT Pong + + This example for the Arduino screen reads the values + of 2 potentiometers to move a rectangular platform + on the x and y axes. The platform can intersect + with a ball causing it to bounce. + + This example code is in the public domain. + + Created by Tom Igoe December 2012 + Modified 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTPong + + */ + +#include // Arduino LCD library +#include + +// pin definitions for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definitions for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +TFT TFTscreen = TFT(cs, dc, rst); + +// variables for the position of the ball and paddle +int paddleX = 0; +int paddleY = 0; +int oldPaddleX, oldPaddleY; +int ballDirectionX = 1; +int ballDirectionY = 1; + +int ballSpeed = 10; // lower numbers are faster + +int ballX, ballY, oldBallX, oldBallY; + +void setup() { + // initialize the display + TFTscreen.begin(); + // black background + TFTscreen.background(0, 0, 0); +} + +void loop() { + + // save the width and height of the screen + int myWidth = TFTscreen.width(); + int myHeight = TFTscreen.height(); + + // map the paddle's location to the position of the potentiometers + paddleX = map(analogRead(A0), 512, -512, 0, myWidth) - 20 / 2; + paddleY = map(analogRead(A1), 512, -512, 0, myHeight) - 5 / 2; + + // set the fill color to black and erase the previous + // position of the paddle if different from present + TFTscreen.fill(0, 0, 0); + + if (oldPaddleX != paddleX || oldPaddleY != paddleY) { + TFTscreen.rect(oldPaddleX, oldPaddleY, 20, 5); + } + + // draw the paddle on screen, save the current position + // as the previous. + TFTscreen.fill(255, 255, 255); + + TFTscreen.rect(paddleX, paddleY, 20, 5); + oldPaddleX = paddleX; + oldPaddleY = paddleY; + + // update the ball's position and draw it on screen + if (millis() % ballSpeed < 2) { + moveBall(); + } +} + +// this function determines the ball's position on screen +void moveBall() { + // if the ball goes offscreen, reverse the direction: + if (ballX > TFTscreen.width() || ballX < 0) { + ballDirectionX = -ballDirectionX; + } + + if (ballY > TFTscreen.height() || ballY < 0) { + ballDirectionY = -ballDirectionY; + } + + // check if the ball and the paddle occupy the same space on screen + if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) { + ballDirectionX = -ballDirectionX; + ballDirectionY = -ballDirectionY; + } + + // update the ball's position + ballX += ballDirectionX; + ballY += ballDirectionY; + + // erase the ball's previous position + TFTscreen.fill(0, 0, 0); + + if (oldBallX != ballX || oldBallY != ballY) { + TFTscreen.rect(oldBallX, oldBallY, 5, 5); + } + + + // draw the ball's current position + TFTscreen.fill(255, 255, 255); + TFTscreen.rect(ballX, ballY, 5, 5); + + oldBallX = ballX; + oldBallY = ballY; + +} + +// this function checks the position of the ball +// to see if it intersects with the paddle +bool inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { + bool result = false; + + if ((x >= rectX && x <= (rectX + rectWidth)) && + (y >= rectY && y <= (rectY + rectHeight))) { + result = true; + } + + return result; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino new file mode 100644 index 00000000..a732480c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTBitmapLogo/EsploraTFTBitmapLogo.ino @@ -0,0 +1,101 @@ +/* + + Esplora TFT Bitmap Logos + + This example for the Arduino TFT screen is for use + with an Arduino Esplora. + + This example reads an image file from a micro-SD card + and draws it on the screen, at random locations. + + There is a .bmp file included with this sketch. + - open the sketch folder (Ctrl-K or Cmd-K) + - copy the "arduino.bmp" file to a micro-SD + - put the SD into the SD slot of the Arduino LCD module. + + This example code is in the public domain. + + Created 19 April 2013 by Enrico Gueli + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTBitmapLogo + + */ + +// include the necessary libraries +#include +#include +#include +#include // Arduino LCD library + +// the Esplora pin connected to the chip select line for SD card +#define SD_CS 8 + +// this variable represents the image to be drawn on screen +PImage logo; + +void setup() { + // initialize the GLCD and show a message + // asking the user to open the serial line + EsploraTFT.begin(); + EsploraTFT.background(255, 255, 255); + + EsploraTFT.stroke(0, 0, 255); + EsploraTFT.println(); + EsploraTFT.println(F("Arduino LCD Bitmap Example")); + EsploraTFT.stroke(0, 0, 0); + EsploraTFT.println(F("Open Serial Monitor")); + EsploraTFT.println(F("to run the sketch")); + + // initialize the serial port: it will be used to + // print some diagnostic info + Serial.begin(9600); + while (!Serial) { + // wait for serial port to connect. Needed for native USB port only + } + + // try to access the SD card. If that fails (e.g. + // no card present), the Esplora's LED will turn red. + Serial.print(F("Initializing SD card...")); + if (!SD.begin(SD_CS)) { + Serial.println(F("failed!")); + Esplora.writeRed(255); + return; + } + Serial.println("OK!"); + + // clear the GLCD screen before starting + EsploraTFT.background(255, 255, 255); + + // now that the SD card can be accessed, try to load the + // image file. The Esplora LED will turn green or red if + // the loading went OK or not. + Esplora.writeRGB(0, 0, 0); + logo = EsploraTFT.loadImage("arduino.bmp"); + if (logo.isValid()) { + Esplora.writeGreen(255); + } else { + Esplora.writeRed(255); + } + +} + +void loop() { + // don't do anything if the image wasn't loaded correctly. + if (logo.isValid() == false) { + return; + } + + Serial.println(F("drawing image")); + + // get a random location to draw the image at. + // To avoid the image being drawn outside the screen, + // take into account the image size. + int x = random(EsploraTFT.width() - logo.width()); + int y = random(EsploraTFT.height() - logo.height()); + + // draw the image to the screen + EsploraTFT.image(logo, x, y); + + // wait a little bit before drawing again + delay(1500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino new file mode 100644 index 00000000..8767ae0a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTColorPicker/EsploraTFTColorPicker.ino @@ -0,0 +1,53 @@ +/* + + Esplora TFT Color Picker + + This example for the Esplora with an Arduino TFT reads + the input of the joystick and slider, using the values + to change the screen's color. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/TFTColorPicker + + */ + +#include +#include // Arduino LCD library +#include + +void setup() { + Serial.begin(9600); + + // initialize the LCD + EsploraTFT.begin(); + + // start out with a white screen + EsploraTFT.background(255, 255, 255); + +} + +void loop() { + + // map the values from sensors + int xValue = map(Esplora.readJoystickX(), -512, 512, 0, 255); // read the joystick's X position + int yValue = map(Esplora.readJoystickY(), -512, 512, 0, 255); // read the joystick's Y position + int slider = map(Esplora.readSlider(), 0, 1023, 0, 255); // read the slider's position + + // change the background color based on the mapped values + EsploraTFT.background(xValue, yValue, slider); + + // print the mapped values to the Serial Monitor + Serial.print("background("); + Serial.print(xValue); + Serial.print(" , "); + Serial.print(yValue); + Serial.print(" , "); + Serial.print(slider); + Serial.println(")"); + + delay(33); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino new file mode 100644 index 00000000..2a3613dd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTEtchASketch/EsploraTFTEtchASketch.ino @@ -0,0 +1,79 @@ +/* + + Esplora TFT EtchASketch + + This example for the Arduino TFT and Esplora draws + a white line on the screen, based on the position + of the joystick. To clear the screen, shake the + Esplora, using the values from the accelerometer. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTEtchASketch + + */ + +#include +#include // Arduino LCD library +#include + +// initial position of the cursor +int xPos = EsploraTFT.width() / 2; +int yPos = EsploraTFT.height() / 2; + +void setup() { + // initialize the display + EsploraTFT.begin(); + + // clear the background + EsploraTFT.background(0, 0, 0); +} + +void loop() { + + int xAxis = Esplora.readJoystickX(); // read the X axis + int yAxis = Esplora.readJoystickY(); // read the Y axis + + // update the position of the line + // depending on the position of the joystick + if (xAxis < 10 && xAxis > -10) { + xPos = xPos; + } else { + xPos = xPos + (map(xAxis, -512, 512, 2, -2)); + } + if (yAxis < 10 && yAxis > -10) { + yAxis = yAxis; + } else { + yPos = yPos + (map(yAxis, -512, 512, -2, 2)); + } + + // don't let the point go past the screen edges + if (xPos > 159) { + (xPos = 159); + } + + if (xPos < 0) { + (xPos = 0); + } + if (yPos > 127) { + (yPos = 127); + } + + if (yPos < 0) { + (yPos = 0); + } + + // draw the point + EsploraTFT.stroke(255, 255, 255); + EsploraTFT.point(xPos, yPos); + + // check the accelerometer values and clear + // the screen if it is being shaken + if (abs(Esplora.readAccelerometer(X_AXIS)) > 200 || abs(Esplora.readAccelerometer(Y_AXIS)) > 200) { + EsploraTFT.background(0, 0, 0); + } + + delay(33); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino new file mode 100644 index 00000000..56fcd52f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTGraph/EsploraTFTGraph.ino @@ -0,0 +1,55 @@ +/* + + Esplora TFT Graph + + This example for the Esplora with an Arduino TFT reads + the value of the light sensor, and graphs the values on + the screen. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTGraph + + */ + +#include +#include // Arduino LCD library +#include + +// position of the line on screen +int xPos = 0; + +void setup() { + + // initialize the screen + EsploraTFT.begin(); + + // clear the screen with a nice color + EsploraTFT.background(250, 16, 200); +} + +void loop() { + + // read the sensor value + int sensor = Esplora.readLightSensor(); + // map the sensor value to the height of the screen + int graphHeight = map(sensor, 0, 1023, 0, EsploraTFT.height()); + + // draw the line in a pretty color + EsploraTFT.stroke(250, 180, 10); + EsploraTFT.line(xPos, EsploraTFT.height() - graphHeight, xPos, EsploraTFT.height()); + + // if the graph reaches the edge of the screen + // erase it and start over from the other side + if (xPos >= 160) { + xPos = 0; + EsploraTFT.background(250, 16, 200); + } else { + // increment the horizontal position: + xPos++; + } + + delay(16); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino new file mode 100644 index 00000000..dbfcad78 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTHorizon/EsploraTFTHorizon.ino @@ -0,0 +1,62 @@ +/* + + Esplora TFT Horizon + + This example for the Arduino TFT and Esplora draws + a line on the screen that stays level with the ground + as you tilt the Esplora side to side + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTHorizon + + */ + +#include +#include // Arduino LCD library +#include + +// horizontal start and end positions +int yStart = EsploraTFT.height() / 2; +int yEnd = EsploraTFT.height() / 2; + +// previous start and end positions +int oldEndY; +int oldStartY; + +void setup() { + // initialize the display + EsploraTFT.begin(); + // make the background black + EsploraTFT.background(0, 0, 0); +} + +void loop() { + // read the x-axis of the accelerometer + int tilt = Esplora.readAccelerometer(X_AXIS); + + // the values are 100 when tilted to the left + // and -100 when tilted to the right + // map these values to the start and end points + yStart = map(tilt, -100, 100, EsploraTFT.height(), 0); + yEnd = map(tilt, -100, 100, 0, EsploraTFT.height()); + + // if the previous values are different than the current values + // erase the previous line + if (oldStartY != yStart || oldEndY != yEnd) { + EsploraTFT.stroke(0, 0, 0); + EsploraTFT.line(0, oldStartY, EsploraTFT.width(), oldEndY); + } + + // draw the line in magenta + EsploraTFT.stroke(255, 0, 255); + EsploraTFT.line(0, yStart, EsploraTFT.width(), yEnd); + + // save the current start and end points + // to compare in the next loop + oldStartY = yStart; + oldEndY = yEnd; + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino new file mode 100644 index 00000000..83af301f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTPong/EsploraTFTPong.ino @@ -0,0 +1,126 @@ +/* + + Esplora TFT Pong + + This example for the Esplora with an Arduino TFT screen reads + the value of the joystick to move a rectangular platform + on the x and y axes. The platform can intersect with a ball + causing it to bounce. The Esplora's slider adjusts the speed + of the ball. + + This example code is in the public domain. + + Created by Tom Igoe December 2012 + Modified 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTPong + + */ + +#include +#include // Arduino LCD library +#include + +// variables for the position of the ball and paddle +int paddleX = 0; +int paddleY = 0; +int oldPaddleX, oldPaddleY; +int ballDirectionX = 1; +int ballDirectionY = 1; + +int ballX, ballY, oldBallX, oldBallY; + +void setup() { + + Serial.begin(9600); + + // initialize the display + EsploraTFT.begin(); + // set the background to black + EsploraTFT.background(0, 0, 0); +} + +void loop() { + // save the width and height of the screen + int myWidth = EsploraTFT.width(); + int myHeight = EsploraTFT.height(); + + // map the paddle's location to the joystick's position + paddleX = map(Esplora.readJoystickX(), 512, -512, 0, myWidth) - 20 / 2; + paddleY = map(Esplora.readJoystickY(), -512, 512, 0, myHeight) - 5 / 2; + Serial.print(paddleX); + Serial.print(" "); + Serial.println(paddleY); + + // set the fill color to black and erase the previous + // position of the paddle if different from present + EsploraTFT.fill(0, 0, 0); + + if (oldPaddleX != paddleX || oldPaddleY != paddleY) { + EsploraTFT.rect(oldPaddleX, oldPaddleY, 20, 5); + } + + // draw the paddle on screen, save the current position + // as the previous. + EsploraTFT.fill(255, 255, 255); + EsploraTFT.rect(paddleX, paddleY, 20, 5); + oldPaddleX = paddleX; + oldPaddleY = paddleY; + + // read the slider to determine the speed of the ball + int ballSpeed = map(Esplora.readSlider(), 0, 1023, 0, 80) + 1; + if (millis() % ballSpeed < 2) { + moveBall(); + } +} + + +// this function determines the ball's position on screen +void moveBall() { + // if the ball goes offscreen, reverse the direction: + if (ballX > EsploraTFT.width() || ballX < 0) { + ballDirectionX = -ballDirectionX; + } + + if (ballY > EsploraTFT.height() || ballY < 0) { + ballDirectionY = -ballDirectionY; + } + + // check if the ball and the paddle occupy the same space on screen + if (inPaddle(ballX, ballY, paddleX, paddleY, 20, 5)) { + ballDirectionY = -ballDirectionY; + } + + // update the ball's position + ballX += ballDirectionX; + ballY += ballDirectionY; + + // erase the ball's previous position + EsploraTFT.fill(0, 0, 0); + + if (oldBallX != ballX || oldBallY != ballY) { + EsploraTFT.rect(oldBallX, oldBallY, 5, 5); + } + + // draw the ball's current position + EsploraTFT.fill(255, 255, 255); + + EsploraTFT.rect(ballX, ballY, 5, 5); + + oldBallX = ballX; + oldBallY = ballY; + +} + +// this function checks the position of the ball +// to see if it intersects with the paddle +bool inPaddle(int x, int y, int rectX, int rectY, int rectWidth, int rectHeight) { + bool result = false; + + if ((x >= rectX && x <= (rectX + rectWidth)) && + (y >= rectY && y <= (rectY + rectHeight))) { + result = true; + } + + return result; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino new file mode 100644 index 00000000..8af405ef --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/TFT/examples/Esplora/EsploraTFTTemp/EsploraTFTTemp.ino @@ -0,0 +1,64 @@ +/* + + Esplora TFT Temperature Display + + This example for the Arduino TFT screen is for use + with an Arduino Esplora. + + This example reads the temperature of the Esplora's + on board thermisistor and displays it on an attached + LCD screen, updating every second. + + This example code is in the public domain. + + Created 15 April 2013 by Scott Fitzgerald + + https://www.arduino.cc/en/Tutorial/LibraryExamples/EsploraTFTTemp + + */ + +// include the necessary libraries +#include +#include // Arduino LCD library +#include + +char tempPrintout[3]; // array to hold the temperature data + +void setup() { + + // Put this line at the beginning of every sketch that uses the GLCD + EsploraTFT.begin(); + + // clear the screen with a black background + EsploraTFT.background(0, 0, 0); + + // set the text color to magenta + EsploraTFT.stroke(200, 20, 180); + // set the text to size 2 + EsploraTFT.setTextSize(2); + // start the text at the top left of the screen + // this text is going to remain static + EsploraTFT.text("Degrees in C :\n ", 0, 0); + + // set the text in the loop to size 5 + EsploraTFT.setTextSize(5); +} + +void loop() { + + // read the temperature in Celsius and store it in a String + String temperature = String(Esplora.readTemperature(DEGREES_C)); + + // convert the string to a char array + temperature.toCharArray(tempPrintout, 3); + + // set the text color to white + EsploraTFT.stroke(255, 255, 255); + // print the temperature one line below the static text + EsploraTFT.text(tempPrintout, 0, 30); + + delay(1000); + // erase the text for the next loop + EsploraTFT.stroke(0, 0, 0); + EsploraTFT.text(tempPrintout, 0, 30); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/README.adoc new file mode 100644 index 00000000..36e6305d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/README.adoc @@ -0,0 +1,39 @@ +:repository-owner: arduino-libraries +:repository-name: Temboo + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows an Arduino to connect to the Temboo service. + +== License == + +Copyright 2017, Temboo Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +either express or implied. See the License for the specific +language governing permissions and limitations under the License. + +This library includes elements of the Paho MQTT client, used +with permission under the Eclipse Public License - v1.0: + +http://www.eclipse.org/legal/epl-v10.html + +and the Eclipse Distribution License v1.0: + +http://www.eclipse.org/org/documents/edl-v10.php + +The Eclipse MQTT Paho client source is available here: + +http://www.eclipse.org/paho/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/GetYahooWeatherReport.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/GetYahooWeatherReport.ino new file mode 100644 index 00000000..c99e45f7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/GetYahooWeatherReport.ino @@ -0,0 +1,115 @@ +/* + GetYahooWeatherReport + + Demonstrates making a request to the Yahoo! Weather API using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + + +// the address for which a weather forecast will be retrieved +String ADDRESS_FOR_FORECAST = "104 Franklin St., New York NY 10013"; + +int numRuns = 1; // execution count, so that this doesn't run forever +int maxRuns = 10; // max number of times the Yahoo WeatherByAddress Choreo should be run + + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + Bridge.begin(); + +} + +void loop() +{ + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running GetWeatherByAddress - Run #" + String(numRuns++) + "..."); + + // create a TembooChoreo object to send a Choreo request to Temboo + TembooChoreo GetWeatherByAddressChoreo; + + // invoke the Temboo client + GetWeatherByAddressChoreo.begin(); + + // add your Temboo account info + GetWeatherByAddressChoreo.setAccountName(TEMBOO_ACCOUNT); + GetWeatherByAddressChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + GetWeatherByAddressChoreo.setAppKey(TEMBOO_APP_KEY); + + // set the name of the Choreo we want to run + GetWeatherByAddressChoreo.setChoreo("/Library/Yahoo/Weather/GetWeatherByAddress"); + + // set Choreo inputs; in this case, the address for which to retrieve weather data + // the Temboo client provides standardized calls to 100+ cloud APIs + GetWeatherByAddressChoreo.addInput("Address", ADDRESS_FOR_FORECAST); + + // add an output filter to extract the name of the city. + GetWeatherByAddressChoreo.addOutputFilter("city", "/rss/channel/yweather:location/@city", "Response"); + + // add an output filter to extract the current temperature + GetWeatherByAddressChoreo.addOutputFilter("temperature", "/rss/channel/item/yweather:condition/@temp", "Response"); + + // add an output filter to extract the date and time of the last report. + GetWeatherByAddressChoreo.addOutputFilter("date", "/rss/channel/item/yweather:condition/@date", "Response"); + + // run the Choreo + GetWeatherByAddressChoreo.run(); + + // when the Choreo results are available, print them to the Serial Monitor + while(GetWeatherByAddressChoreo.available()) { + + char c = GetWeatherByAddressChoreo.read(); + Serial.print(c); + } + GetWeatherByAddressChoreo.close(); + + } + + Serial.println("Waiting..."); + Serial.println(""); + delay(30000); // wait 30 seconds between GetWeatherByAddress calls +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/TembooAccount.h new file mode 100644 index 00000000..c58b4479 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/GetYahooWeatherReport/TembooAccount.h @@ -0,0 +1,4 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/ReadATweet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/ReadATweet.ino new file mode 100644 index 00000000..49c21a75 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/ReadATweet.ino @@ -0,0 +1,173 @@ +/* + ReadATweet + + Demonstrates retrieving the most recent Tweet from a user's home timeline + using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + In order to run this sketch, you'll need to register an application using + the Twitter dev console at https://dev.twitter.com. After creating the + app, you'll find OAuth credentials for that application under the "OAuth Tool" tab. + Substitute these values for the placeholders below. + + This example assumes basic familiarity with Arduino sketches, and that your Yún + is connected to the Internet. + + Want to use another social API with your Arduino Yún? We've got Facebook, + Instagram, Tumblr and more in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. +const String TWITTER_ACCESS_TOKEN = "your-twitter-access-token"; +const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret"; +const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key"; +const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret"; + +int numRuns = 1; // execution count, so this doesn't run forever +int maxRuns = 10; // the max number of times the Twitter HomeTimeline Choreo should run + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while(!Serial); + Bridge.begin(); +} +void loop() +{ + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + Serial.println("Running ReadATweet - Run #" + String(numRuns++)); + + TembooChoreo HomeTimelineChoreo; + + // invoke the Temboo client. + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + HomeTimelineChoreo.begin(); + + // set Temboo account credentials + HomeTimelineChoreo.setAccountName(TEMBOO_ACCOUNT); + HomeTimelineChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + HomeTimelineChoreo.setAppKey(TEMBOO_APP_KEY); + + // tell the Temboo client which Choreo to run (Twitter > Timelines > HomeTimeline) + HomeTimelineChoreo.setChoreo("/Library/Twitter/Timelines/HomeTimeline"); + + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Twitter/Timelines/HomeTimeline/ + // for complete details about the inputs for this Choreo + + HomeTimelineChoreo.addInput("Count", "1"); // the max number of Tweets to return from each request + HomeTimelineChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); + HomeTimelineChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); + HomeTimelineChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + HomeTimelineChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); + + // next, we'll define two output filters that let us specify the + // elements of the response from Twitter that we want to receive. + // see the examples at http://www.temboo.com/arduino + // for more on using output filters + + // we want the text of the tweet + HomeTimelineChoreo.addOutputFilter("tweet", "/[1]/text", "Response"); + + // and the name of the author + HomeTimelineChoreo.addOutputFilter("author", "/[1]/user/screen_name", "Response"); + + + // tell the Process to run and wait for the results. The + // return code will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = HomeTimelineChoreo.run(); + + // a response code of 0 means success; print the API response + if(returnCode == 0) { + + String author; // a String to hold the tweet author's name + String tweet; // a String to hold the text of the tweet + + + // Choreo outputs are returned as key/value pairs, delimited with + // newlines and record/field terminator characters, for example: + // Name1\n\x1F + // Value1\n\x1E + // Name2\n\x1F + // Value2\n\x1E + + // see the examples at http://www.temboo.com/arduino for more details + // we can read this format into separate variables, as follows: + + while(HomeTimelineChoreo.available()) { + // read the name of the output item + String name = HomeTimelineChoreo.readStringUntil('\x1F'); + name.trim(); + + // read the value of the output item + String data = HomeTimelineChoreo.readStringUntil('\x1E'); + data.trim(); + + // assign the value to the appropriate String + if (name == "tweet") { + tweet = data; + } else if (name == "author") { + author = data; + } + } + + Serial.println("@" + author + " - " + tweet); + + } else { + // there was an error + // print the raw output from the Choreo + while(HomeTimelineChoreo.available()) { + char c = HomeTimelineChoreo.read(); + Serial.print(c); + } + } + + HomeTimelineChoreo.close(); + + } + + Serial.println("Waiting..."); + delay(90000); // wait 90 seconds between HomeTimeline calls +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/TembooAccount.h new file mode 100644 index 00000000..c58b4479 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ReadATweet/TembooAccount.h @@ -0,0 +1,4 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/SendATweet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/SendATweet.ino new file mode 100644 index 00000000..6aabb605 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/SendATweet.ino @@ -0,0 +1,138 @@ +/* + SendATweet + + Demonstrates sending a tweet via a Twitter account using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + In order to run this sketch, you'll need to register an application using + the Twitter dev console at https://dev.twitter.com. Note that since this + sketch creates a new tweet, your application will need to be configured with + read+write permissions. After creating the app, you'll find OAuth credentials + for that application under the "OAuth Tool" tab. Substitute these values for + the placeholders below. + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Want to use another social API with your Arduino Yún? We've got Facebook, + Instagram, Tumblr and more in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. +const String TWITTER_ACCESS_TOKEN = "your-twitter-access-token"; +const String TWITTER_ACCESS_TOKEN_SECRET = "your-twitter-access-token-secret"; +const String TWITTER_CONSUMER_KEY = "your-twitter-consumer-key"; +const String TWITTER_CONSUMER_SECRET = "your-twitter-consumer-secret"; + +int numRuns = 1; // execution count, so this sketch doesn't run forever +int maxRuns = 3; // the max number of times the Twitter Update Choreo should run + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + + Bridge.begin(); +} + +void loop() +{ + // only try to send the tweet if we haven't already sent it successfully + if (numRuns <= maxRuns) { + + Serial.println("Running SendATweet - Run #" + String(numRuns++) + "..."); + + // define the text of the tweet we want to send + String tweetText("My Arduino Yun has been running for " + String(millis()) + " milliseconds."); + + + TembooChoreo StatusesUpdateChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + StatusesUpdateChoreo.begin(); + + // set Temboo account credentials + StatusesUpdateChoreo.setAccountName(TEMBOO_ACCOUNT); + StatusesUpdateChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + StatusesUpdateChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Twitter > Tweets > StatusesUpdate) + StatusesUpdateChoreo.setChoreo("/Library/Twitter/Tweets/StatusesUpdate"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Twitter/Tweets/StatusesUpdate/ + // for complete details about the inputs for this Choreo + + // add the Twitter account information + StatusesUpdateChoreo.addInput("AccessToken", TWITTER_ACCESS_TOKEN); + StatusesUpdateChoreo.addInput("AccessTokenSecret", TWITTER_ACCESS_TOKEN_SECRET); + StatusesUpdateChoreo.addInput("ConsumerKey", TWITTER_CONSUMER_KEY); + StatusesUpdateChoreo.addInput("ConsumerSecret", TWITTER_CONSUMER_SECRET); + + // and the tweet we want to send + StatusesUpdateChoreo.addInput("StatusUpdate", tweetText); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = StatusesUpdateChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! Tweet sent!"); + } else { + // a non-zero return code means there was an error + // read and print the error message + while (StatusesUpdateChoreo.available()) { + char c = StatusesUpdateChoreo.read(); + Serial.print(c); + } + } + StatusesUpdateChoreo.close(); + + // do nothing for the next 90 seconds + Serial.println("Waiting..."); + delay(90000); + } +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/TembooAccount.h new file mode 100644 index 00000000..c58b4479 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendATweet/TembooAccount.h @@ -0,0 +1,4 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/SendAnEmail.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/SendAnEmail.ino new file mode 100644 index 00000000..e89e9c3c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/SendAnEmail.ino @@ -0,0 +1,166 @@ +/* + SendAnEmail + + Demonstrates sending an email via a Google Gmail account using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and tutorials at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + Instructions: + + 1. Create a Temboo account: http://www.temboo.com + + 2. Retrieve your Temboo application details: http://www.temboo.com/account/applications + + 3. Replace the values in the TembooAccount.h tab with your Temboo application details + + 4. You'll also need a Gmail account. Update the placeholder Gmail address in the code + below with your own details. + + https://www.gmail.com + + 5. Once you have a Gmail account, turn on 2-step authentication, and create an application-specific + password to allow Temboo to access your Google account: https://www.google.com/landing/2step/. + + 6. After you've enabled 2-Step authentication, you'll need to create an App Password: + https://security.google.com/settings/security/apppasswords + + 7. In the "Select app" dropdown menu, choose "Other", and give your app a name (e.g., TembooApp). + + 8. Click "Generate". You'll be given a 16-digit passcode that can be used to access your Google Account from Temboo. + + 9. Copy and paste this password into the code below, updating the GMAIL_APP_PASSWORD variable + + 10. Upload the sketch to your Arduino Yún and open the Serial Monitor + + NOTE: You can test this Choreo and find the latest instructions on our website: + https://temboo.com/library/Library/Google/Gmail/SendEmail + + You can also find an in-depth version of this example here: + https://temboo.com/arduino/yun/send-an-email + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. + +// your Gmail username, formatted as a complete email address, eg "bob.smith@gmail.com" +const String GMAIL_USER_NAME = "xxxxxxxxxx"; + +// your application specific password (see instructions above) +const String GMAIL_APP_PASSWORD = "xxxxxxxxxx"; + +// the email address you want to send the email to, eg "jane.doe@temboo.com" +const String TO_EMAIL_ADDRESS = "xxxxxxxxxx"; + +// a flag to indicate whether we've tried to send the email yet or not +bool attempted = false; + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + + Bridge.begin(); +} + +void loop() +{ + // only try to send the email if we haven't already tried + if (!attempted) { + + Serial.println("Running SendAnEmail..."); + + TembooChoreo SendEmailChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked, and repopulated with + // appropriate arguments, each time its run() method is called. + SendEmailChoreo.begin(); + + // set Temboo account credentials + SendEmailChoreo.setAccountName(TEMBOO_ACCOUNT); + SendEmailChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SendEmailChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Google > Gmail > SendEmail) + SendEmailChoreo.setChoreo("/Library/Google/Gmail/SendEmail"); + + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Google/Gmail/SendEmail/ + // for complete details about the inputs for this Choreo + + // the first input is your Gmail email address. + SendEmailChoreo.addInput("Username", GMAIL_USER_NAME); + // next is your application specific password + SendEmailChoreo.addInput("Password", GMAIL_APP_PASSWORD); + // who to send the email to + SendEmailChoreo.addInput("ToAddress", TO_EMAIL_ADDRESS); + // then a subject line + SendEmailChoreo.addInput("Subject", "ALERT: Greenhouse Temperature"); + + // next comes the message body, the main content of the email + SendEmailChoreo.addInput("MessageBody", "Hey! The greenhouse is too cold!"); + + // tell the Choreo to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SendEmailChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! Email sent!"); + } else { + // a non-zero return code means there was an error + // read and print the error message + while (SendEmailChoreo.available()) { + char c = SendEmailChoreo.read(); + Serial.print(c); + } + } + SendEmailChoreo.close(); + + // set the flag showing we've tried + attempted = true; + } +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/TembooAccount.h new file mode 100644 index 00000000..c58b4479 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnEmail/TembooAccount.h @@ -0,0 +1,4 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/SendAnSMS.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/SendAnSMS.ino new file mode 100644 index 00000000..b0b0c8ba --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/SendAnSMS.ino @@ -0,0 +1,154 @@ +/* + SendAnSMS + + Demonstrates sending an SMS via Twilio using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + Since this sketch uses Twilio to send the SMS, you'll also need a valid + Twilio account. You can create one for free at https://www.twilio.com. + + The sketch needs your Twilio phone number, along with + the Account SID and Auth Token you get when you register with Twilio. + Make sure to use the Account SID and Auth Token from your Twilio Dashboard + (not your test credentials from the Dev Tools panel). + + Also note that if you're using a free Twilio account, you'll need to verify + the phone number to which messages are being sent by going to twilio.com and following + the instructions under the "Numbers > Verified Caller IDs" tab (this restriction + doesn't apply if you have a paid Twilio account). + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + + + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. + +// the Account SID from your Twilio account +const String TWILIO_ACCOUNT_SID = "xxxxxxxxxx"; + +// the Auth Token from your Twilio account +const String TWILIO_AUTH_TOKEN = "xxxxxxxxxx"; + +// your Twilio phone number, e.g., "+1 555-222-1212" +const String TWILIO_NUMBER = "xxxxxxxxxx"; + +// the number to which the SMS should be sent, e.g., "+1 555-222-1212" +const String RECIPIENT_NUMBER = "xxxxxxxxxx"; + +// a flag to indicate whether we've attempted to send the SMS yet or not +bool attempted = false; + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + + Bridge.begin(); +} + +void loop() +{ + // only try to send the SMS if we haven't already sent it successfully + if (!attempted) { + + Serial.println("Running SendAnSMS..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo SendSMSChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + SendSMSChoreo.begin(); + + // set Temboo account credentials + SendSMSChoreo.setAccountName(TEMBOO_ACCOUNT); + SendSMSChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SendSMSChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Twilio > SMSMessages > SendSMS) + SendSMSChoreo.setChoreo("/Library/Twilio/SMSMessages/SendSMS"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Twilio/SMSMessages/SendSMS/ + // for complete details about the inputs for this Choreo + + // the first input is a your AccountSID + SendSMSChoreo.addInput("AccountSID", TWILIO_ACCOUNT_SID); + + // next is your Auth Token + SendSMSChoreo.addInput("AuthToken", TWILIO_AUTH_TOKEN); + + // next is your Twilio phone number + SendSMSChoreo.addInput("From", TWILIO_NUMBER); + + // next, what number to send the SMS to + SendSMSChoreo.addInput("To", RECIPIENT_NUMBER); + + // finally, the text of the message to send + SendSMSChoreo.addInput("Body", "Hey, there! This is a message from your Arduino Yun!"); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SendSMSChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! SMS sent!"); + } else { + // a non-zero return code means there was an error + // read and print the error message + while (SendSMSChoreo.available()) { + char c = SendSMSChoreo.read(); + Serial.print(c); + } + } + SendSMSChoreo.close(); + + // set the flag indicating we've tried once. + attempted=true; + } +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/TembooAccount.h new file mode 100644 index 00000000..8d7dcfb7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendAnSMS/TembooAccount.h @@ -0,0 +1,5 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino new file mode 100644 index 00000000..830b3d3b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/SendDataToGoogleSpreadsheet.ino @@ -0,0 +1,200 @@ +/* + SendDataToGoogleSpreadsheet + + Demonstrates appending a row of data to a Google spreadsheet using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and tutorials at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + Instructions: + + 1. Create a Temboo account: http://www.temboo.com + + 2. Retrieve your Temboo application details: http://www.temboo.com/account/applications + + 3. Replace the values in the TembooAccount.h tab with your Temboo application details + + 4. You'll also need a Google Spreadsheet that includes a title in the first row + of each column that data will be written to. This example assumes there are two columns. + The first column is the time (in milliseconds) that the row was appended, and the second + column is a sensor value. In other words, your spreadsheet should look like: + + Time | Sensor Value | + ------+----------------- + | | + + 5. Google Spreadsheets requires you to authenticate via OAuth. Follow the steps + in the link below to find your ClientID, ClientSecret, and RefreshToken, and then + use those values to overwrite the placeholders in the code below. + + https://temboo.com/library/Library/Google/OAuth/ + + For the scope field, you need to use: https://www.googleapis.com/auth/spreadsheets + + Here's a video outlines how Temboo helps with the OAuth process: + + https://www.temboo.com/videos#oauthchoreos + + And here's a more in-depth version of this example on our website: + + https://temboo.com/arduino/yun/update-google-spreadsheet + + 6. Next, upload the sketch to your Arduino Yún and open the Serial Monitor + + Note: you can test this Choreo and find the latest instructions on our website: + https://temboo.com/library/Library/Google/Sheets/AppendValues/ + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. + +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information, + // as described in the footer comment below + + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. + +// the clientID found in Google's Developer Console under API Manager > Credentials +const String CLIENT_ID = "your-client-id"; + +// the clientSecret found in Google's Developer Console under API Manager > Credentials +const String CLIENT_SECRET = "your-client-secret"; + +// returned after running FinalizeOAuth +const String REFRESH_TOKEN = "your-oauth-refresh-token"; + +// The ID of the spreadsheet you want to send data to +// which can be found in the URL when viewing your spreadsheet at Google. For example, +// the ID in the URL below is: "1tvFW2n-xFFJCE1q5j0HTetOsDhhgw7_998_K4sFtk" +// Sample URL: https://docs.google.com/spreadsheets/d/1tvFW2n-xFFJCE1q5j0HTetOsDhhgw7_998_K4sFtk/edit +const String SPREADSHEET_ID = "your-spreadsheet-id"; + +const unsigned long RUN_INTERVAL_MILLIS = 60000; // how often to run the Choreo (in milliseconds) + +// the last time we ran the Choreo +// (initialized to 60 seconds ago so the +// Choreo is run immediately when we start up) +unsigned long lastRun = (unsigned long)-60000; + +void setup() { + + // for debugging, wait until a serial console is connected + Serial.begin(9600); + delay(4000); + while(!Serial); + + Serial.print("Initializing the bridge..."); + Bridge.begin(); + Serial.println("Done"); +} + +void loop() +{ + // get the number of milliseconds this sketch has been running + unsigned long now = millis(); + + // run again if it's been 60 seconds since we last ran + if (now - lastRun >= RUN_INTERVAL_MILLIS) { + + // remember 'now' as the last time we ran the Choreo + lastRun = now; + + Serial.println("Getting sensor value..."); + + // get the value we want to append to our spreadsheet + unsigned long sensorValue = getSensorValue(); + + Serial.println("Appending value to spreadsheet..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo AppendValuesChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + AppendValuesChoreo.begin(); + + // set Temboo account credentials + AppendValuesChoreo.setAccountName(TEMBOO_ACCOUNT); + AppendValuesChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + AppendValuesChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Google > Sheets > AppendValues) + AppendValuesChoreo.setChoreo("/Library/Google/Sheets/AppendValues"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Google/Sheets/AppendValues/ + // for complete details about the inputs for this Choreo + + // your Google application client ID + AppendValuesChoreo.addInput("ClientID", CLIENT_ID); + // your Google application client secret + AppendValuesChoreo.addInput("ClientSecret", CLIENT_SECRET); + // your Google OAuth refresh token + AppendValuesChoreo.addInput("RefreshToken", REFRESH_TOKEN); + + // the ID of the spreadsheet you want to append to + AppendValuesChoreo.addInput("SpreadsheetID", SPREADSHEET_ID); + + // convert the time and sensor values to a comma separated string + String rowData = "[[\"" + String(now) + "\", \"" + String(sensorValue) + "\"]]"; + + // add the RowData input item + AppendValuesChoreo.addInput("Values", rowData); + + // run the Choreo and wait for the results + // The return code (returnCode) will indicate success or failure + unsigned int returnCode = AppendValuesChoreo.run(); + + // return code of zero (0) means success + if (returnCode == 0) { + Serial.println("Success! Appended " + rowData); + Serial.println(""); + } else { + // return code of anything other than zero means failure + // read and display any error messages + while (AppendValuesChoreo.available()) { + char c = AppendValuesChoreo.read(); + Serial.print(c); + } + } + + AppendValuesChoreo.close(); + } +} + +// this function simulates reading the value of a sensor +unsigned long getSensorValue() { + return analogRead(A0); +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/TembooAccount.h new file mode 100644 index 00000000..8d7dcfb7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/SendDataToGoogleSpreadsheet/TembooAccount.h @@ -0,0 +1,5 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/TembooDeviceConfig/TembooDeviceConfig.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/TembooDeviceConfig/TembooDeviceConfig.ino new file mode 100644 index 00000000..ad584155 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/TembooDeviceConfig/TembooDeviceConfig.ino @@ -0,0 +1,97 @@ +// Copyright 2017, Temboo Inc. + +#include + +void setup() { + // initialize the Bridge + Bridge.begin(); + Serial.begin(9600); + Process p; + + //intro message + Serial.println("**** Temboo Cloud Controls ****\n"); + + // update the package list + Serial.print("Updating package listings..."); + p.runShellCommand("opkg update"); + int returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed. Make sure your device is connected to the internet properly."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + // upgrade the Temboo package + Serial.print("Updating Temboo..."); + p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/temboo_1.4.0-1_ar71xx.ipk"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // install python openssl to allow for SSL connections + Serial.print("Installing python-openssl..."); + p.runShellCommand("opkg install python-openssl"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // Installing twisted web to work with CoAP gateway + Serial.print("Installing twisted-web..."); + p.runShellCommand("opkg install twisted-web"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // Configuring zope + Serial.print("Configuring zope..."); + p.runShellCommand("touch /usr/lib/python2.7/site-packages/zope/__init__.py"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + Serial.println("Update Complete - your Yun is ready for Cloud Controls!"); +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/TembooAccount.h new file mode 100644 index 00000000..8d7dcfb7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/TembooAccount.h @@ -0,0 +1,5 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino new file mode 100644 index 00000000..3a331be7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/ToxicFacilitiesSearch/ToxicFacilitiesSearch.ino @@ -0,0 +1,171 @@ +/* + ToxicFacilitiesSearch + + Demonstrates making a request to the Envirofacts API using Temboo from an Arduino Yún. + This example retrieves the names and addresses of EPA-regulated facilities in the + Toxins Release Inventory (TRI) database within a given zip code. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + +// the zip code to search for toxin-emitting facilities +String US_ZIP_CODE = "11215"; + +int numRuns = 1; // execution count, so that this doesn't run forever +int maxRuns = 10; // max number of times the Envirofacts FacilitiesSearch Choreo should be run + +void setup() { + Serial.begin(9600); + + // for debugging, wait until a serial console is connected + delay(4000); + while(!Serial); + Bridge.begin(); +} + +void loop() +{ + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running ToxicFacilitiesSearch - Run #" + String(numRuns++) + "..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo FacilitiesSearchByZipChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + FacilitiesSearchByZipChoreo.begin(); + + // set Temboo account credentials + FacilitiesSearchByZipChoreo.setAccountName(TEMBOO_ACCOUNT); + FacilitiesSearchByZipChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + FacilitiesSearchByZipChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (EnviroFacts > Toxins > FacilitiesSearchByZip) + FacilitiesSearchByZipChoreo.setChoreo("/Library/EnviroFacts/Toxins/FacilitiesSearchByZip"); + + // set Choreo inputs; in this case, the US zip code for which to retrieve toxin release data + // the Temboo client provides standardized calls to 100+ cloud APIs + FacilitiesSearchByZipChoreo.addInput("Zip", US_ZIP_CODE); + + // specify two output filters, to help simplify the Envirofacts API results. + // see the tutorials on using Temboo SDK output filters at http://www.temboo.com/arduino + FacilitiesSearchByZipChoreo.addOutputFilter("fac", "FACILITY_NAME", "Response"); + + FacilitiesSearchByZipChoreo.addOutputFilter("addr", "STREET_ADDRESS", "Response"); + + // run the Choreo + unsigned int returnCode = FacilitiesSearchByZipChoreo.run(); + if (returnCode == 0) { + String facilities; + String addresses; + + // when the Choreo results are available, process them. + // the output filters we specified will return comma delimited + // lists containing the name and street address of the facilities + // located in the specified zip code. + while(FacilitiesSearchByZipChoreo.available()) { + String name = FacilitiesSearchByZipChoreo.readStringUntil('\x1F'); + name.trim(); + + String data = FacilitiesSearchByZipChoreo.readStringUntil('\x1E'); + data.trim(); + + if (name == "fac") { + facilities = data; + } else if (name == "addr") { + addresses = data; + } + } + FacilitiesSearchByZipChoreo.close(); + + // parse the comma delimited lists of facilities to join the + // name with the address and print it to the Serial Monitor + if (facilities.length() > 0) { + int i = -1; + int facilityStart = 0; + int addressStart = 0; + String facility; + String address; + do { + i = facilities.indexOf(',', facilityStart); + if (i >= 0) { + facility = facilities.substring(facilityStart, i); + facilityStart = i + 1; + } + + i = addresses.indexOf(',', addressStart); + if (i >= 0) { + address = addresses.substring(addressStart, i); + addressStart = i + 1; + } + + if (i >= 0) { + printResult(facility, address); + } + + }while (i >= 0); + facility = facilities.substring(facilityStart); + address = addresses.substring(addressStart); + printResult(facility, address); + } else { + Serial.println("No facilities found in zip code " + US_ZIP_CODE); + } + } else { + while(FacilitiesSearchByZipChoreo.available()) { + char c = FacilitiesSearchByZipChoreo.read(); + Serial.print(c); + } + } + } + Serial.println("Waiting..."); + Serial.println(""); + delay(30000); // wait 30 seconds between calls +} + +// a simple utility function, to output the facility name and address in the Serial Monitor. +void printResult(String facility, String address) { + Serial.print(facility); + Serial.print(" - "); + Serial.println(address); +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/TembooAccount.h new file mode 100644 index 00000000..8d7dcfb7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/TembooAccount.h @@ -0,0 +1,5 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/UpdateFacebookStatus.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/UpdateFacebookStatus.ino new file mode 100644 index 00000000..895df4bc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UpdateFacebookStatus/UpdateFacebookStatus.ino @@ -0,0 +1,132 @@ +/* + UpdateFacebookStatus + + Demonstrates sending a Facebook status update using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + In order to run this sketch, you'll need to register an application using + the Facebook dev console at https://developers.facebook.com/apps -- after creating + the app, log in to Temboo and visit https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/ + to use our OAuth Wizard (or OAuth Choreos) to obtain a Facebook access token. + Substitute your access token for the placeholder value of FACEBOOK_ACCESS_TOKEN below. + + This example assumes basic familiarity with Arduino sketches, and that your Yún + is connected to the Internet. + + Want to use another social API with your Arduino Yún? We've got Twitter, + Instagram, Tumblr and more in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information, + // as described in the footer comment below + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use a #define statement to specify this value in a .h file. + +// the Facebook Access Token, which can be obtained using the Temboo OAuth Wizard or Choreos +const String FACEBOOK_ACCESS_TOKEN = "xxxxxxxxxx"; + + +int numRuns = 1; // execution count, so this sketch doesn't run forever +int maxRuns = 10; // the max number of times the Facebook SetStatus Choreo should run + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while(!Serial); + Bridge.begin(); +} + +void loop() { + // while we haven't reached the max number of runs... + if (numRuns <= maxRuns) { + + // print status + Serial.println("Running UpdateFacebookStatus - Run #" + String(numRuns++) + "..."); + + // Define the status message we want to post on Facebook; since Facebook + // doesn't allow duplicate status messages, we'll include a changing value. + String statusMsg = "My Arduino Yun has been running for " + String(millis()) + " milliseconds!"; + + // define the Process that will be used to call the "temboo" client + TembooChoreo SetStatusChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + SetStatusChoreo.begin(); + + // set Temboo account credentials + SetStatusChoreo.setAccountName(TEMBOO_ACCOUNT); + SetStatusChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + SetStatusChoreo.setAppKey(TEMBOO_APP_KEY); + + // tell the Temboo client which Choreo to run (Facebook > Publishing > SetStatus) + SetStatusChoreo.setChoreo("/Library/Facebook/Publishing/SetStatus"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Facebook/Publishing/SetStatus/ + // for complete details about the inputs for this Choreo + + SetStatusChoreo.addInput("AccessToken", FACEBOOK_ACCESS_TOKEN); + SetStatusChoreo.addInput("Message", statusMsg); + + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = SetStatusChoreo.run(); + + // print the response code and API response. + Serial.println("Response code: " + String(returnCode)); + + // note that in this case, we're just printing the raw response from Facebook. + // see the examples on using Temboo SDK output filters at http://www.temboo.com/arduino + // for information on how to filter this data + while(SetStatusChoreo.available()) { + char c = SetStatusChoreo.read(); + Serial.print(c); + } + + SetStatusChoreo.close(); + } + + Serial.println("Waiting..."); + Serial.println(""); + + delay(30000); // wait 30 seconds between SetStatus calls +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/TembooAccount.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/TembooAccount.h new file mode 100644 index 00000000..8d7dcfb7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/TembooAccount.h @@ -0,0 +1,5 @@ +#define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name +#define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name +#define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/UploadToDropbox.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/UploadToDropbox.ino new file mode 100644 index 00000000..699b0b1d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/ArduinoYun/UploadToDropbox/UploadToDropbox.ino @@ -0,0 +1,208 @@ +/* + UploadToDropbox + + Demonstrates uploading a file to a Dropbox account using Temboo from an Arduino Yún. + + Check out the latest Arduino & Temboo examples and support docs at http://www.temboo.com/arduino + + A Temboo account and application key are necessary to run all Temboo examples. + If you don't already have one, you can register for a free Temboo account at + http://www.temboo.com + + You'll also need a valid Dropbox app and accompanying OAuth credentials. + To create a Dropbox app, visit https://www.dropbox.com/developers/apps and + do the following: + + 1. Create a "Dropbox API app" + 2. Select "Files and datastores" + 3. Select "Yes - my app only needs access to the files it creates." + + Once you've created your app, follow the instructions at + https://www.temboo.com/library/Library/Dropbox/OAuth/ to run the Initialize and Finalize + OAuth Choreos. These Choreos complete the OAuth handshake and retrieve your Dropbox OAuth access tokens. + + This example assumes basic familiarity with Arduino sketches, and that your Yún is connected + to the Internet. + + Looking for another API to use with your Arduino Yún? We've got over 100 in our Library! + + This example code is in the public domain. +*/ + +#include +#include +#include "TembooAccount.h" // contains Temboo account information + // as described in the footer comment below + + +/*** SUBSTITUTE YOUR VALUES BELOW: ***/ + +// Note that for additional security and reusability, you could +// use #define statements to specify these values in a .h file. + +// your Dropbox app key, available on the Dropbox developer console after registering an app +const String DROPBOX_APP_KEY = "xxxxxxxxxx"; + +// your Dropbox app secret, available on the Dropbox developer console after registering an app +const String DROPBOX_APP_SECRET = "xxxxxxxxxx"; + +// your Dropbox access token, which is returned by the FinalizeOAuth Choreo +const String DROPBOX_ACCESS_TOKEN = "xxxxxxxxxx"; + +// your Dropbox access token secret, which is returned by the FinalizeOAuth Choreo +const String DROPBOX_ACCESS_TOKEN_SECRET = "xxxxxxxxxx"; + + +bool success = false; // a flag to indicate whether we've uploaded the file yet + +void setup() { + Serial.begin(9600); + + // For debugging, wait until a serial console is connected. + delay(4000); + while(!Serial); + Bridge.begin(); +} + +void loop() +{ + // only try to upload the file if we haven't already done so + if (!success) { + + Serial.println("Base64 encoding data to upload..."); + + // base64 encode the data to upload + String base64EncodedData = base64Encode("Hello, Arduino!"); + + + Serial.println("Uploading data to Dropbox..."); + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo UploadFileChoreo; + + // invoke the Temboo client + // NOTE that the client must be reinvoked and repopulated with + // appropriate arguments each time its run() method is called. + UploadFileChoreo.begin(); + + // set Temboo account credentials + UploadFileChoreo.setAccountName(TEMBOO_ACCOUNT); + UploadFileChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + UploadFileChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Dropbox > FilesAndMetadata > UploadFile) + UploadFileChoreo.setChoreo("/Library/Dropbox/FilesAndMetadata/UploadFile"); + + // set the required Choreo inputs + // see https://www.temboo.com/library/Library/Dropbox/FilesAndMetadata/UploadFile/ + // for complete details about the inputs for this Choreo + + // first specify the name of the file to create/update on Dropbox + UploadFileChoreo.addInput("FileName", "ArduinoTest.txt"); + + // next, the root folder on Dropbox relative to which the file path is specified. + // to work with the Dropbox app you created earlier, this should be left as "sandbox" + // if your Dropbox app has full access to your files, specify "dropbox" + UploadFileChoreo.addInput("Root","sandbox"); + + // next, the Base64 encoded file data to upload + UploadFileChoreo.addInput("FileContents", base64EncodedData); + + // finally, the Dropbox OAuth credentials defined above + UploadFileChoreo.addInput("AppSecret", DROPBOX_APP_SECRET); + UploadFileChoreo.addInput("AccessToken", DROPBOX_ACCESS_TOKEN); + UploadFileChoreo.addInput("AccessTokenSecret", DROPBOX_ACCESS_TOKEN_SECRET); + UploadFileChoreo.addInput("AppKey", DROPBOX_APP_KEY); + + // tell the Process to run and wait for the results. The + // return code (returnCode) will tell us whether the Temboo client + // was able to send our request to the Temboo servers + unsigned int returnCode = UploadFileChoreo.run(); + + // a return code of zero (0) means everything worked + if (returnCode == 0) { + Serial.println("Success! File uploaded!"); + success = true; + } else { + // a non-zero return code means there was an error + Serial.println("Uh-oh! Something went wrong!"); + } + + // print out the full response to the Serial Monitor in all + // cases, just for debugging + while (UploadFileChoreo.available()) { + char c = UploadFileChoreo.read(); + Serial.print(c); + } + UploadFileChoreo.close(); + + Serial.println("Waiting..."); + } + + delay(30000); // wait 30 seconds between upload attempts +} + + +/* + A utility function to Base64 encode the specified string + by calling a Temboo Utilities Choreo. +*/ +String base64Encode(String toEncode) { + + // we need a Process object to send a Choreo request to Temboo + TembooChoreo Base64EncodeChoreo; + + // invoke the Temboo client + Base64EncodeChoreo.begin(); + + // set Temboo account credentials + Base64EncodeChoreo.setAccountName(TEMBOO_ACCOUNT); + Base64EncodeChoreo.setAppKeyName(TEMBOO_APP_KEY_NAME); + Base64EncodeChoreo.setAppKey(TEMBOO_APP_KEY); + + // identify the Temboo Library Choreo to run (Utilities > Encoding > Base64Encode) + Base64EncodeChoreo.setChoreo("/Library/Utilities/Encoding/Base64Encode"); + + // set Choreo inputs + Base64EncodeChoreo.addInput("Text", toEncode); + + // run the Choreo + Base64EncodeChoreo.run(); + + // read in the Choreo results, and return the "Base64EncodedText" output value. + // see http://www.temboo.com/arduino for more details on using Choreo outputs. + while(Base64EncodeChoreo.available()) { + // read the name of the output item + String name = Base64EncodeChoreo.readStringUntil('\x1F'); + name.trim(); + + // read the value of the output item + String data = Base64EncodeChoreo.readStringUntil('\x1E'); + data.trim(); + + if(name == "Base64EncodedText") { + return data; + } + } +} + +/* + IMPORTANT NOTE: TembooAccount.h: + + TembooAccount.h is a file referenced by this sketch that contains your Temboo account information. + You'll need to edit the placeholder version of TembooAccount.h included with this example sketch, + by inserting your own Temboo account name and app key information. The contents of the file should + look like: + + #define TEMBOO_ACCOUNT "myTembooAccountName" // your Temboo account name + #define TEMBOO_APP_KEY_NAME "myFirstApp" // your Temboo app key name + #define TEMBOO_APP_KEY "xxx-xxx-xxx-xx-xxx" // your Temboo app key + + You can find your Temboo App Key information on the Temboo website, + under My Account > Application Keys + + The same TembooAccount.h file settings can be used for all Temboo SDK sketches. + + Keeping your account information in a separate file means you can share the main .ino file without worrying + that you forgot to delete your credentials. +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/YunShield/TembooDeviceConfig/TembooDeviceConfig.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/YunShield/TembooDeviceConfig/TembooDeviceConfig.ino new file mode 100644 index 00000000..d0001df6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/Temboo/examples/YunShield/TembooDeviceConfig/TembooDeviceConfig.ino @@ -0,0 +1,99 @@ +// Copyright 2017, Temboo Inc. + +#include + +void setup() { + // initialize the Bridge + Bridge.begin(); + Serial.begin(9600); + Process p; + + //intro message + Serial.println("**** Temboo Cloud Controls ****\n"); + + // update the package list + Serial.print("Updating package listings..."); + p.runShellCommand("opkg update"); + int returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed. Make sure your device is connected to the internet properly."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + // upgrade the Temboo package + Serial.print("Updating Temboo..."); + p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/temboo_1.3.1-1_ar71xx.ipk --force-depends"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + Serial.println("Error number: " +String(returnCode)); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // install python openssl to allow for for SSL connections + Serial.print("Installing python-openssl..."); + p.runShellCommand("opkg install python-openssl"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // Installing twisted web to work with CoAP gateway + Serial.print("Installing twisted-web..."); + p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/twisted-web_2.5.0-1_ar71xx.ipk --force-depends"); + returnCode = p.exitValue(); + if (returnCode == 0) { + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + Serial.println(); + + // Configuring zope + Serial.print("Configuring zope..."); + p.runShellCommand("opkg install http://downloads.arduino.cc/openwrtyun/1/packages/zope-interface_2.5.0-1_ar71xx.ipk --force-depends"); + returnCode = p.exitValue(); + if (returnCode == 0) { + p.runShellCommand("touch /usr/lib/python2.7/site-packages/zope/__init__.py"); + Serial.println("Success!"); + } else { + Serial.println("Failed."); + while(p.available()) { + char c = p.read(); + Serial.print(c); + } + return; + } + + Serial.println("Update Complete - your Yun is ready for Cloud Controls!"); +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/README.adoc new file mode 100644 index 00000000..9a06c1bf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/README.adoc @@ -0,0 +1,32 @@ +:repository-owner: arduino-libraries +:repository-name: USBHost + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +The USBHost library allows an Arduino Due board to appear as a USB host, enabling it to communicate with peripherals like USB mice and keyboards. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2012 Arduino LLC. All right reserved. +Copyright (c) 2011 Circuits At Home, LTD. All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino new file mode 100644 index 00000000..3ee5b20c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino @@ -0,0 +1,65 @@ +/* + + ADK Terminal Test + + This demonstrates USB Host connectivity between an + Android phone and an Arduino Due. + + The ADK for the Arduino Due is a work in progress + For additional information on the Arduino ADK visit + https://web.archive.org/web/20170503104018/http://labs.arduino.cc/ADK/Index + + created 27 June 2012 + by Cristian Maglie + +*/ + +#include "variant.h" +#include +#include + +// Accessory descriptor. It's how Arduino identifies itself to Android. +char applicationName[] = "Arduino_Terminal"; // the app on your phone +char accessoryName[] = "Arduino Due"; // your Arduino board +char companyName[] = "Arduino SA"; + +// Make up anything you want for these +char versionNumber[] = "1.0"; +char serialNumber[] = "1"; +char url[] = "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk"; + +USBHost Usb; +ADK adk(&Usb, companyName, applicationName, accessoryName, versionNumber, url, serialNumber); + +void setup() { + cpu_irq_enable(); + printf("\r\nADK demo start\r\n"); + delay(200); +} + +#define RCVSIZE 128 + +void loop() { + uint8_t buf[RCVSIZE]; + uint32_t nbread = 0; + char helloworld[] = "Hello World!\r\n"; + + Usb.Task(); + + if (adk.isReady()) { + /* Write hello string to ADK */ + adk.write(strlen(helloworld), (uint8_t *)helloworld); + + delay(1000); + + /* Read data from ADK and print to UART */ + adk.read(&nbread, RCVSIZE, buf); + if (nbread > 0) { + printf("RCV: "); + for (uint32_t i = 0; i < nbread; ++i) { + printf("%c", (char)buf[i]); + } + printf("\r\n"); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/KeyboardController/KeyboardController.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/KeyboardController/KeyboardController.ino new file mode 100644 index 00000000..667f2d46 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/KeyboardController/KeyboardController.ino @@ -0,0 +1,89 @@ +/* + Keyboard Controller Example + + Shows the output of a USB Keyboard connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + http://www.arduino.cc/en/Tutorial/KeyboardController + + This sample code is part of the public domain. + */ + + +// Require keyboard control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach keyboard controller to USB +KeyboardController keyboard(usb); + +// This function intercepts key press +void keyPressed() { + Serial.print("Pressed: "); + printKey(); +} + +// This function intercepts key release +void keyReleased() { + Serial.print("Released: "); + printKey(); +} + +void printKey() { + // getOemKey() returns the OEM-code associated with the key + Serial.print(" key:"); + Serial.print(keyboard.getOemKey()); + + // getModifiers() returns a bits field with the modifiers-keys + int mod = keyboard.getModifiers(); + Serial.print(" mod:"); + Serial.print(mod); + + Serial.print(" => "); + + if (mod & LeftCtrl) { + Serial.print("L-Ctrl "); + } + if (mod & LeftShift) { + Serial.print("L-Shift "); + } + if (mod & Alt) { + Serial.print("Alt "); + } + if (mod & LeftCmd) { + Serial.print("L-Cmd "); + } + if (mod & RightCtrl) { + Serial.print("R-Ctrl "); + } + if (mod & RightShift) { + Serial.print("R-Shift "); + } + if (mod & AltGr) { + Serial.print("AltGr "); + } + if (mod & RightCmd) { + Serial.print("R-Cmd "); + } + + // getKey() returns the ASCII translation of OEM key + // combined with modifiers. + Serial.write(keyboard.getKey()); + Serial.println(); +} + +void setup() { + Serial.begin(9600); + Serial.println("Program started"); + delay(200); +} + +void loop() { + // Process USB tasks + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/MouseController/MouseController.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/MouseController/MouseController.ino new file mode 100644 index 00000000..ef0754d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/USBHost/examples/MouseController/MouseController.ino @@ -0,0 +1,91 @@ +/* + Mouse Controller Example + + Shows the output of a USB Mouse connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + http://www.arduino.cc/en/Tutorial/MouseController + + This sample code is part of the public domain. + */ + +// Require mouse control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach mouse controller to USB +MouseController mouse(usb); + +// variables for mouse button states +bool leftButton = false; +bool middleButton = false; +bool rightButton = false; + +// This function intercepts mouse movements +void mouseMoved() { + Serial.print("Move: "); + Serial.print(mouse.getXChange()); + Serial.print(", "); + Serial.println(mouse.getYChange()); +} + +// This function intercepts mouse movements while a button is pressed +void mouseDragged() { + Serial.print("DRAG: "); + Serial.print(mouse.getXChange()); + Serial.print(", "); + Serial.println(mouse.getYChange()); +} + +// This function intercepts mouse button press +void mousePressed() { + Serial.print("Pressed: "); + if (mouse.getButton(LEFT_BUTTON)) { + Serial.print("L"); + leftButton = true; + } + if (mouse.getButton(MIDDLE_BUTTON)) { + Serial.print("M"); + middleButton = true; + } + if (mouse.getButton(RIGHT_BUTTON)) { + Serial.print("R"); + Serial.println(); + rightButton = true; + } +} + +// This function intercepts mouse button release +void mouseReleased() { + Serial.print("Released: "); + if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) { + Serial.print("L"); + leftButton = false; + } + if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) { + Serial.print("M"); + middleButton = false; + } + if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) { + Serial.print("R"); + rightButton = false; + } + Serial.println(); +} + +void setup() { + Serial.begin(9600); + Serial.println("Program started"); + delay(200); +} + +void loop() { + // Process USB tasks + usb.Task(); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/README.adoc new file mode 100644 index 00000000..057e684b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/README.adoc @@ -0,0 +1,34 @@ +:repository-owner: arduino-libraries +:repository-name: WiFi + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +With the Arduino WiFi Shield, this library allows an Arduino board to connect to the internet. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) 2011-2014 Arduino LLC. All right reserved. +Copyright (C) 2006-2008, Atmel Corporation All rights reserved. +Copyright (c) 2001-2004 Swedish Institute of Computer Science. +Copyright (c) 2009-2010, H&D Wireless AB All rights reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino new file mode 100644 index 00000000..7ad942dc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -0,0 +1,126 @@ +/* + + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +char ssid[] = "yourNetwork"; // the name of your network +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to open SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + Serial.print(mac[5], HEX); + Serial.print(":"); + Serial.print(mac[4], HEX); + Serial.print(":"); + Serial.print(mac[3], HEX); + Serial.print(":"); + Serial.print(mac[2], HEX); + Serial.print(":"); + Serial.print(mac[1], HEX); + Serial.print(":"); + Serial.println(mac[0], HEX); + + // print your subnet mask: + IPAddress subnet = WiFi.subnetMask(); + Serial.print("NetMask: "); + Serial.println(subnet); + + // print your gateway address: + IPAddress gateway = WiFi.gatewayIP(); + Serial.print("Gateway: "); + Serial.println(gateway); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5], HEX); + Serial.print(":"); + Serial.print(bssid[4], HEX); + Serial.print(":"); + Serial.print(bssid[3], HEX); + Serial.print(":"); + Serial.print(bssid[2], HEX); + Serial.print(":"); + Serial.print(bssid[1], HEX); + Serial.print(":"); + Serial.println(bssid[0], HEX); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino new file mode 100644 index 00000000..0bcf7e90 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -0,0 +1,129 @@ +/* + + This example connects to a WEP-encrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + + If you use 40-bit WEP, you need a key that is 10 characters long, + and the characters must be hexadecimal (0-9 or A-F). + e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work + (too short) and ABBAISDEAF won't work (I and S are not + hexadecimal characters). + + For 128-bit, you need a string that is 26 characters long. + D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, + all in the 0-9, A-F range. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key +int keyIndex = 0; // your network key Index number +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WEP network, SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, keyIndex, key); + + // wait 10 seconds for connection: + delay(10000); + } + + // once you are connected : + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + Serial.print(mac[5], HEX); + Serial.print(":"); + Serial.print(mac[4], HEX); + Serial.print(":"); + Serial.print(mac[3], HEX); + Serial.print(":"); + Serial.print(mac[2], HEX); + Serial.print(":"); + Serial.print(mac[1], HEX); + Serial.print(":"); + Serial.println(mac[0], HEX); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5], HEX); + Serial.print(":"); + Serial.print(bssid[4], HEX); + Serial.print(":"); + Serial.print(bssid[3], HEX); + Serial.print(":"); + Serial.print(bssid[2], HEX); + Serial.print(":"); + Serial.print(bssid[1], HEX); + Serial.print(":"); + Serial.println(bssid[0], HEX); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino new file mode 100644 index 00000000..1bff6843 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -0,0 +1,121 @@ +/* + + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); + +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + Serial.print(mac[5], HEX); + Serial.print(":"); + Serial.print(mac[4], HEX); + Serial.print(":"); + Serial.print(mac[3], HEX); + Serial.print(":"); + Serial.print(mac[2], HEX); + Serial.print(":"); + Serial.print(mac[1], HEX); + Serial.print(":"); + Serial.println(mac[0], HEX); + +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + Serial.print(bssid[5], HEX); + Serial.print(":"); + Serial.print(bssid[4], HEX); + Serial.print(":"); + Serial.print(bssid[3], HEX); + Serial.print(":"); + Serial.print(bssid[2], HEX); + Serial.print(":"); + Serial.print(bssid[1], HEX); + Serial.print(":"); + Serial.println(bssid[0], HEX); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino new file mode 100644 index 00000000..743dcb1f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/ScanNetworks/ScanNetworks.ino @@ -0,0 +1,116 @@ +/* + + This example prints the WiFi shield's MAC address, and + scans for available WiFi networks using the WiFi shield. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 21 Junn 2012 + by Tom Igoe and Jaymes Dec + */ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // Print WiFi MAC address: + printMacAddress(); +} + +void loop() { + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); + delay(10000); +} + +void printMacAddress() { + // the MAC address of your WiFi shield + byte mac[6]; + + // print your MAC address: + WiFi.macAddress(mac); + Serial.print("MAC: "); + Serial.print(mac[5], HEX); + Serial.print(":"); + Serial.print(mac[4], HEX); + Serial.print(":"); + Serial.print(mac[3], HEX); + Serial.print(":"); + Serial.print(mac[2], HEX); + Serial.print(":"); + Serial.print(mac[1], HEX); + Serial.print(":"); + Serial.println(mac[0], HEX); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) { + Serial.println("Couldn't get a WiFi connection"); + while (true); + } + + // print the list of networks seen: + Serial.print("number of available networks:"); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet); + Serial.print(") "); + Serial.print(WiFi.SSID(thisNet)); + Serial.print("\tSignal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + } +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.println("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.println("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.println("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.println("None"); + break; + case ENC_TYPE_AUTO: + Serial.println("Auto"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino new file mode 100644 index 00000000..2467542a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino @@ -0,0 +1,132 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will print the IP address of your WiFi Shield (once connected) + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 9. + + If the IP address of your shield is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi shield attached + * LED attached to pin 9 + + created 25 Nov 2012 + by Tom Igoe + */ +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + Serial.begin(9600); // initialize serial communication + pinMode(9, OUTPUT); // set the LED pin mode + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + while (true); // don't continue + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); // start the web server on port 80 + printWifiStatus(); // you're connected now, so print out the status +} + + +void loop() { + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the Serial Monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on pin 9 on
    "); + client.print("Click here turn the LED on pin 9 off
    "); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(9, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(9, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino new file mode 100644 index 00000000..9b9707a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiChatServer/WiFiChatServer.ino @@ -0,0 +1,115 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the Serial Monitor as well. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + + Circuit: + * WiFi shield attached + + created 18 Dec 2009 + by David A. Mellis + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) + +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(23); + +bool alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // start the server: + server.begin(); + // you're connected now, so print out the status: + printWifiStatus(); +} + + +void loop() { + // wait for a new client: + WiFiClient client = server.available(); + + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clear out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino new file mode 100644 index 00000000..5294dcc5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -0,0 +1,172 @@ +/* + + UDP NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + This code is in the public domain. + + */ + +#include +#include +#include + +int status = WL_IDLE_STATUS; +char ssid[] = "mynetwork"; // your network SSID (name) +char pass[] = "mypassword"; // your network password +int keyIndex = 0; // your network key Index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) { + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino new file mode 100644 index 00000000..f8fdab11 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -0,0 +1,113 @@ +/* + WiFi UDP Send and Receive String + + This sketch wait an UDP packet on localPort using a WiFi shield. + When a packet is received an Acknowledge packet is sent to the client on port remotePort + + Circuit: + * WiFi shield attached + + created 30 December 2012 + by dlf (Metodo2 srl) + + */ + + +#include +#include +#include + +int status = WL_IDLE_STATUS; +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen on + +char packetBuffer[255]; //buffer to hold incoming packet +char ReplyBuffer[] = "acknowledged"; // a string to send back + +WiFiUDP Udp; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + Udp.begin(localPort); +} + +void loop() { + + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remoteIp = Udp.remoteIP(); + Serial.print(remoteIp); + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBufffer + int len = Udp.read(packetBuffer, 255); + if (len > 0) { + packetBuffer[len] = 0; + } + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply, to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino new file mode 100644 index 00000000..d2af1c42 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino @@ -0,0 +1,120 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using a WiFi shield. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ + + +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino new file mode 100644 index 00000000..221008af --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -0,0 +1,129 @@ +/* + Repeating WiFi Web Client + + This sketch connects to a a web server and makes a request + using an Arduino WiFi shield. + + Circuit: + * WiFi shield attached to pins SPI pins and pin 7 + + created 23 April 2012 + modified 31 May 2012 + by Tom Igoe + modified 13 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating + This code is in the public domain. + */ + +#include +#include + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +// Initialize the WiFi client library +WiFiClient client; + +// server address: +char server[] = "www.arduino.cc"; +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } + +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the WiFi shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP PUT request: + client.println("GET /latest.txt HTTP/1.1"); + client.println("Host: www.arduino.cc"); + client.println("User-Agent: ArduinoWiFi/1.1"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino new file mode 100644 index 00000000..80ae8710 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi/examples/WiFiWebServer/WiFiWebServer.ino @@ -0,0 +1,137 @@ +/* + WiFi Web Server + + A simple web server that shows the value of the analog input pins. + using a WiFi shield. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi shield attached + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + + +char ssid[] = "yourNetwork"; // your network SSID (name) +char pass[] = "secretPassword"; // your network password +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv != "1.1.0") { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); + // you're connected now, so print out the status: + printWifiStatus(); +} + + +void loop() { + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
    "); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/README.adoc new file mode 100644 index 00000000..ec967410 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/README.adoc @@ -0,0 +1,33 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: WiFi101 + += {repository-name} library for for the Arduino WiFi Shield 101 and MKR1000 board = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library implements a network driver for devices based +on the ATMEL WINC1500 WiFi module. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/{repository-name} + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino new file mode 100644 index 00000000..c2e064dd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino @@ -0,0 +1,179 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will create a new access point (with no password). + It will then launch a new server and print out the IP address + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 13. + + If the IP address of your shield is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + created 25 Nov 2012 + by Tom Igoe + adapted to WiFi AP by Adafruit + */ + +#include +#include +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int led = LED_BUILTIN; +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Access Point Web Server"); + + pinMode(led, OUTPUT); // set the LED pin mode + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue + while (true); + } + + // by default the local IP address of will be 192.168.1.1 + // you can override it with the following: + // WiFi.config(IPAddress(10, 0, 0, 1)); + + // print the network name (SSID); + Serial.print("Creating access point named: "); + Serial.println(ssid); + + // Create open network. Change this line if you want to create a WEP network: + status = WiFi.beginAP(ssid); + if (status != WL_AP_LISTENING) { + Serial.println("Creating access point failed"); + // don't continue + while (true); + } + + // wait 10 seconds for connection: + delay(10000); + + // start the web server on port 80 + server.begin(); + + // you're connected now, so print out the status + printWiFiStatus(); +} + + +void loop() { + // compare the previous status to the current status + if (status != WiFi.status()) { + // it has changed, so update the variable + status = WiFi.status(); + + if (status == WL_AP_CONNECTED) { + byte remoteMac[6]; + + // a device has connected to the AP + Serial.print("Device connected to AP, MAC address: "); + WiFi.APClientMacAddress(remoteMac); + printMacAddress(remoteMac); + } else { + // a device has disconnected from the AP, and we are back in listening mode + Serial.println("Device disconnected from AP"); + } + } + + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there are bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on
    "); + client.print("Click here turn the LED off
    "); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } + else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } + else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(led, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(led, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); + +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/AP_SimpleWebServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/CheckWifi101FirmwareVersion/CheckWifi101FirmwareVersion.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/CheckWifi101FirmwareVersion/CheckWifi101FirmwareVersion.ino new file mode 100644 index 00000000..db4967e8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/CheckWifi101FirmwareVersion/CheckWifi101FirmwareVersion.ino @@ -0,0 +1,66 @@ +/* + * This example checks if the firmware loaded on the WiFi101 + * shield is updated. + * + * Circuit: + * - WiFi 101 Shield attached + * + * Created 29 July 2015 by Cristian Maglie + * This code is in the public domain. + */ +#include +#include +#include + +void setup() { + // Initialize serial + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Print a welcome message + Serial.println("WiFi101 firmware check."); + Serial.println(); + + // Check for the presence of the shield + Serial.print("WiFi 101 Shield: "); + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("NOT PRESENT"); + return; // don't continue + } + Serial.println("DETECTED"); + + // Print firmware version on the shield + String fv = WiFi.firmwareVersion(); + String latestFv; + Serial.print("Firmware version installed: "); + Serial.println(fv); + + if (REV(GET_CHIPID()) >= REV_3A0) { + // model B + latestFv = WIFI_FIRMWARE_LATEST_MODEL_B; + } else { + // model A + latestFv = WIFI_FIRMWARE_LATEST_MODEL_A; + } + + // Print required firmware version + Serial.print("Latest firmware version available : "); + Serial.println(latestFv); + + // Check if the latest version is installed + Serial.println(); + if (fv >= latestFv) { + Serial.println("Check result: PASSED"); + } else { + Serial.println("Check result: NOT PASSED"); + Serial.println(" - The firmware version on the shield does not match the"); + Serial.println(" version required by the library, you may experience"); + Serial.println(" issues or failures."); + } +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/ConnectNoEncryption.ino new file mode 100644 index 00000000..59135a9e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -0,0 +1,115 @@ +/* + + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi 101 Shield, + the IP address obtained, and other network details. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to open SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWiFiData() { + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); + + // print your subnet mask: + IPAddress subnet = WiFi.subnetMask(); + Serial.print("NetMask: "); + Serial.println(subnet); + + // print your gateway address: + IPAddress gateway = WiFi.gatewayIP(); + Serial.print("Gateway: "); + Serial.println(gateway); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/arduino_secrets.h new file mode 100644 index 00000000..07c11487 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectNoEncryption/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_SSID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/ConnectWithWEP.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/ConnectWithWEP.ino new file mode 100644 index 00000000..9009c3a3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -0,0 +1,119 @@ +/* + + This example connects to a WEP-encrypted WiFi network. + Then it prints the MAC address of the WiFi 101 Shield, + the IP address obtained, and other network details. + + If you use 40-bit WEP, you need a key that is 10 characters long, + and the characters must be hexadecimal (0-9 or A-F). + e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work + (too short) and ABBAISDEAF won't work (I and S are not + hexadecimal characters). + + For 128-bit, you need a string that is 26 characters long. + D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, + all in the 0-9, A-F range. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char key[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to WEP network, SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, keyIndex, key); + + // wait 10 seconds for connection: + delay(10000); + } + + // once you are connected : + Serial.print("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWiFiData() { + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWEP/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/ConnectWithWPA.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/ConnectWithWPA.ino new file mode 100644 index 00000000..5352db9b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -0,0 +1,111 @@ +/* + + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi 101 Shield, + the IP address obtained, and other network details. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWiFiData(); + +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWiFiData() { + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); + +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ConnectWithWPA/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/Endianness.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/Endianness.ino new file mode 100644 index 00000000..873b02bf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/Endianness.ino @@ -0,0 +1,61 @@ +/* + Endianness.ino - Network byte order conversion functions. + Copyright (c) 2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + + +bool isBigEndian() { + uint32_t test = 0x11223344; + uint8_t *pTest = reinterpret_cast(&test); + return pTest[0] == 0x11; +} + +uint32_t fromNetwork32(uint32_t from) { + static const bool be = isBigEndian(); + if (be) { + return from; + } else { + uint8_t *pFrom = reinterpret_cast(&from); + uint32_t to; + to = pFrom[0]; to <<= 8; + to |= pFrom[1]; to <<= 8; + to |= pFrom[2]; to <<= 8; + to |= pFrom[3]; + return to; + } +} + +uint16_t fromNetwork16(uint16_t from) { + static bool be = isBigEndian(); + if (be) { + return from; + } else { + uint8_t *pFrom = reinterpret_cast(&from); + uint16_t to; + to = pFrom[0]; to <<= 8; + to |= pFrom[1]; + return to; + } +} + +uint32_t toNetwork32(uint32_t to) { + return fromNetwork32(to); +} + +uint16_t toNetwork16(uint16_t to) { + return fromNetwork16(to); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/FirmwareUpdater.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/FirmwareUpdater.ino new file mode 100644 index 00000000..3e8afbe0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/FirmwareUpdater/FirmwareUpdater.ino @@ -0,0 +1,127 @@ +/* + FirmwareUpdate.h - Firmware Updater for WiFi101 / WINC1500. + Copyright (c) 2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include + +typedef struct __attribute__((__packed__)) { + uint8_t command; + uint32_t address; + uint32_t arg1; + uint16_t payloadLength; + + // payloadLength bytes of data follows... +} UartPacket; + +static const int MAX_PAYLOAD_SIZE = 1024; + +#define CMD_READ_FLASH 0x01 +#define CMD_WRITE_FLASH 0x02 +#define CMD_ERASE_FLASH 0x03 +#define CMD_MAX_PAYLOAD_SIZE 0x50 +#define CMD_HELLO 0x99 + +void setup() { + Serial.begin(115200); + + nm_bsp_init(); + if (m2m_wifi_download_mode() != M2M_SUCCESS) { + Serial.println(F("Failed to put the WiFi module in download mode")); + while (true) + ; + } +} + +void receivePacket(UartPacket *pkt, uint8_t *payload) { + // Read command + uint8_t *p = reinterpret_cast(pkt); + uint16_t l = sizeof(UartPacket); + while (l > 0) { + int c = Serial.read(); + if (c == -1) + continue; + *p++ = c; + l--; + } + + // Convert parameters from network byte order to cpu byte order + pkt->address = fromNetwork32(pkt->address); + pkt->arg1 = fromNetwork32(pkt->arg1); + pkt->payloadLength = fromNetwork16(pkt->payloadLength); + + // Read payload + l = pkt->payloadLength; + while (l > 0) { + int c = Serial.read(); + if (c == -1) + continue; + *payload++ = c; + l--; + } +} + +// Allocated statically so the compiler can tell us +// about the amount of used RAM +static UartPacket pkt; +static uint8_t payload[MAX_PAYLOAD_SIZE]; + +void loop() { + receivePacket(&pkt, payload); + + if (pkt.command == CMD_HELLO) { + if (pkt.address == 0x11223344 && pkt.arg1 == 0x55667788) + Serial.print("v10000"); + } + + if (pkt.command == CMD_MAX_PAYLOAD_SIZE) { + uint16_t res = toNetwork16(MAX_PAYLOAD_SIZE); + Serial.write(reinterpret_cast(&res), sizeof(res)); + } + + if (pkt.command == CMD_READ_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.arg1; + if (spi_flash_read(payload, address, len) != M2M_SUCCESS) { + Serial.println("ER"); + } else { + Serial.write(payload, len); + Serial.print("OK"); + } + } + + if (pkt.command == CMD_WRITE_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.payloadLength; + if (spi_flash_write(payload, address, len) != M2M_SUCCESS) { + Serial.print("ER"); + } else { + Serial.print("OK"); + } + } + + if (pkt.command == CMD_ERASE_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.arg1; + if (spi_flash_erase(address, len) != M2M_SUCCESS) { + Serial.print("ER"); + } else { + Serial.print("OK"); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/MDNS_WiFiWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/MDNS_WiFiWebServer.ino new file mode 100644 index 00000000..a3b48def --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/MDNS_WiFiWebServer.ino @@ -0,0 +1,170 @@ +/* + MDNS WiFi Web Server + + A simple web server that shows the value of the analog input pins, + and exposes itself on the MDNS name 'wifi101.local'. + + On Linux (like Ubuntu 15.04) or OSX you can access the web page + on the device in a browser at 'http://wifi101.local/'. + + On Windows you'll first need to install the Bonjour Printer Services + from: + https://support.apple.com/kb/dl999?locale=en_US + Then you can access the device in a browser at 'http://wifi101.local/'. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi 101 Shield attached + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + modified 27 January 2016 + by Tony DiCola + +*/ + +#include +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +char mdnsName[] = "wifi101"; // the MDNS name that the board will respond to +// Note that the actual MDNS name will have '.local' after +// the name above, so "wifi101" will be accessible on +// the MDNS name "wifi101.local". + +int status = WL_IDLE_STATUS; + +// Create a MDNS responder to listen and respond to MDNS name requests. +WiFiMDNSResponder mdnsResponder; + +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + // you're connected now, so print out the status: + printWiFiStatus(); + + server.begin(); + + // Setup the MDNS responder to listen to the configured name. + // NOTE: You _must_ call this _after_ connecting to the WiFi network and + // being assigned an IP address. + if (!mdnsResponder.begin(mdnsName)) { + Serial.println("Failed to start MDNS responder!"); + while(1); + } + + Serial.print("Server listening at http://"); + Serial.print(mdnsName); + Serial.println(".local/"); +} + + +void loop() { + // Call the update() function on the MDNS responder every loop iteration to + // make sure it can detect and respond to name requests. + mdnsResponder.poll(); + + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
    "); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } + else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/MDNS_WiFiWebServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/Provisioning_WiFiWebServer/Provisioning_WiFiWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/Provisioning_WiFiWebServer/Provisioning_WiFiWebServer.ino new file mode 100644 index 00000000..b51f859b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/Provisioning_WiFiWebServer/Provisioning_WiFiWebServer.ino @@ -0,0 +1,166 @@ +/* + WiFi Web Server + + A simple web server that shows the value of the analog input pins. + using a WiFi 101 Shield. + + This example is written to configure the WiFi settings using provisioning mode. + It also sets up an mDNS server so the IP address of the board doesn't have to + be obtained via the serial monitor. + + Circuit: + WiFi 101 Shield attached + Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + +*/ + +#include +#include +#include + +const int ledPin = 6; // LED pin for connectivity status indicator + +char mdnsName[] = "wifi101"; // the MDNS name that the board will respond to + // after WiFi settings have been provisioned +// Note that the actual MDNS name will have '.local' after +// the name above, so "wifi101" will be accessible on +// the MDNS name "wifi101.local". + +WiFiServer server(80); + +// Create a MDNS responder to listen and respond to MDNS name requests. +WiFiMDNSResponder mdnsResponder; + +void setup() { + //Initialize serial: + Serial.begin(9600); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // configure the LED pin for output mode + pinMode(ledPin, OUTPUT); + + // Start in provisioning mode: + // 1) This will try to connect to a previously associated access point. + // 2) If this fails, an access point named "wifi101-XXXX" will be created, where XXXX + // is the last 4 digits of the boards MAC address. Once you are connected to the access point, + // you can configure an SSID and password by visiting http://wifi101/ + WiFi.beginProvision(); + + while (WiFi.status() != WL_CONNECTED) { + // wait while not connected + + // blink the led to show an unconnected status + digitalWrite(ledPin, HIGH); + delay(500); + digitalWrite(ledPin, LOW); + delay(500); + } + + // connected, make the LED stay on + digitalWrite(ledPin, HIGH); + + server.begin(); + + // Setup the MDNS responder to listen to the configured name. + // NOTE: You _must_ call this _after_ connecting to the WiFi network and + // being assigned an IP address. + if (!mdnsResponder.begin(mdnsName)) { + Serial.println("Failed to start MDNS responder!"); + while(1); + } + + Serial.print("Server listening at http://"); + Serial.print(mdnsName); + Serial.println(".local/"); + + // you're connected now, so print out the status: + printWiFiStatus(); +} + + +void loop() { + // Call the update() function on the MDNS responder every loop iteration to + // make sure it can detect and respond to name requests. + mdnsResponder.poll(); + + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
    "); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } + else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ScanNetworks/ScanNetworks.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ScanNetworks/ScanNetworks.ino new file mode 100644 index 00000000..0d87700b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ScanNetworks/ScanNetworks.ino @@ -0,0 +1,120 @@ +/* + + This example prints the WiFi 101 Shield's MAC address, and + scans for available WiFi networks using the WiFi 101 Shield. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 21 Junn 2012 + by Tom Igoe and Jaymes Dec + */ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // Print WiFi MAC address: + printMacAddress(); + + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void loop() { + delay(10000); + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void printMacAddress() { + // the MAC address of your WiFi 101 Shield + byte mac[6]; + + // print your MAC address: + WiFi.macAddress(mac); + Serial.print("MAC: "); + printMacAddress(mac); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) + { + Serial.println("Couldn't get a WiFi connection"); + while (true); + } + + // print the list of networks seen: + Serial.print("number of available networks:"); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet); + Serial.print(") "); + Serial.print(WiFi.SSID(thisNet)); + Serial.print("\tSignal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + Serial.flush(); + } +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.println("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.println("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.println("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.println("None"); + break; + case ENC_TYPE_AUTO: + Serial.println("Auto"); + break; + } +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino new file mode 100644 index 00000000..1f135550 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino @@ -0,0 +1,129 @@ +/* + + This example prints the WiFi 101 Shield or MKR1000 MAC address, and + scans for available WiFi networks using the WiFi 101 Shield or MKR1000 board. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + BSSID and WiFi channel are printed + + Circuit: + WiFi 101 Shield attached or MKR1000 board + + This example is based on ScanNetworks + + created 1 Mar 2017 + by Arturo Guadalupi +*/ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC: "); + printMacAddress(mac); + + // scan for existing networks: + Serial.println(); + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void loop() { + delay(10000); + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) + { + Serial.println("Couldn't get a WiFi connection"); + while (true); + } + + // print the list of networks seen: + Serial.print("number of available networks: "); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet + 1); + Serial.print(") "); + Serial.print("Signal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tChannel: "); + Serial.print(WiFi.channel(thisNet)); + byte bssid[6]; + Serial.print("\t\tBSSID: "); + printMacAddress(WiFi.BSSID(thisNet, bssid)); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + Serial.print("\t\tSSID: "); + Serial.println(WiFi.SSID(thisNet)); + Serial.flush(); + } + Serial.println(); +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.print("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.print("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.print("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.print("None"); + break; + case ENC_TYPE_AUTO: + Serial.print("Auto"); + break; + } +} + +void print2Digits(byte thisByte) { + if (thisByte < 0xF) { + Serial.print("0"); + } + Serial.print(thisByte, HEX); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino new file mode 100644 index 00000000..50755ab9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino @@ -0,0 +1,131 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will print the IP address of your WiFi 101 Shield (once connected) + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 9. + + If the IP address of your shield is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi 101 Shield attached + * LED attached to pin 9 + + created 25 Nov 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + Serial.begin(9600); // initialize serial communication + pinMode(9, OUTPUT); // set the LED pin mode + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + while (true); // don't continue + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); // start the web server on port 80 + printWiFiStatus(); // you're connected now, so print out the status +} + + +void loop() { + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there are bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on pin 9 on
    "); + client.print("Click here turn the LED on pin 9 off
    "); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } + else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } + else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(9, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(9, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/SimpleWebServerWiFi/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/WiFiChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/WiFiChatServer.ino new file mode 100644 index 00000000..34656f42 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/WiFiChatServer.ino @@ -0,0 +1,112 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + + Circuit: + * WiFi 101 Shield attached + + created 18 Dec 2009 + by David A. Mellis + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(23); + +bool alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // start the server: + server.begin(); + // you're connected now, so print out the status: + printWiFiStatus(); +} + + +void loop() { + // wait for a new client: + WiFiClient client = server.available(); + + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clead out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiChatServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiPing/WiFiPing.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiPing/WiFiPing.ino new file mode 100644 index 00000000..09e5cdff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiPing/WiFiPing.ino @@ -0,0 +1,132 @@ +/* + + This example connects to a encrypted WiFi network (WPA/WPA2). + Then it prints the MAC address of the WiFi 101 Shield, + the IP address obtained, and other network details. + Then it continuously pings given host specified by IP Address or name. + + Circuit: + WiFi 101 Shield attached / MKR1000 + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 09 June 2016 + by Petar Georgiev +*/ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +// Specify IP address or hostname +String hostName = "www.google.com"; +int pingResult; + +void setup() { + // Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 5 seconds for connection: + delay(5000); + } + + // you're connected now, so print out the data: + Serial.println("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + Serial.print("Pinging "); + Serial.print(hostName); + Serial.print(": "); + + pingResult = WiFi.ping(hostName); + + if (pingResult >= 0) { + Serial.print("SUCCESS! RTT = "); + Serial.print(pingResult); + Serial.println(" ms"); + } else { + Serial.print("FAILED! Error code: "); + Serial.println(pingResult); + } + + delay(5000); +} + +void printWiFiData() { + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP address : "); + Serial.println(ip); + + Serial.print("Subnet mask: "); + Serial.println((IPAddress)WiFi.subnetMask()); + + Serial.print("Gateway IP : "); + Serial.println((IPAddress)WiFi.gatewayIP()); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI): "); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type: "); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiPing/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiPing/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiPing/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/WiFiSSLClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/WiFiSSLClient.ino new file mode 100644 index 00000000..299c588e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/WiFiSSLClient.ino @@ -0,0 +1,107 @@ +/* +This example creates a client object that connects and transfers +data using always SSL. + +It is compatible with the methods normally related to plain +connections, like client.connect(host, port). + +Written by Arturo Guadalupi +last revision November 2015 + +*/ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiSSLClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 443)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiSSLClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino new file mode 100644 index 00000000..7118fb5a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -0,0 +1,172 @@ +/* + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + This code is in the public domain. + + */ + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(129, 6, 15, 28); // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +void setup() +{ + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() +{ + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if ( Udp.parsePacket() ) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = " ); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if ( ((epoch % 3600) / 60) < 10 ) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ( (epoch % 60) < 10 ) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) +{ + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpNtpClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino new file mode 100644 index 00000000..b1710a1a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -0,0 +1,108 @@ +/* + WiFi UDP Send and Receive String + + This sketch waits for an UDP packet on localPort using a WiFi 101 Shield. + When a packet is received an Acknowledge packet is sent to the client on port remotePort + + Circuit: + * WiFi 101 Shield attached + + created 30 December 2012 + by dlf (Metodo2 srl) + + */ + + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen on + +char packetBuffer[255]; //buffer to hold incoming packet +char ReplyBuffer[] = "acknowledged"; // a string to send back + +WiFiUDP Udp; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + Udp.begin(localPort); +} + +void loop() { + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) + { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remoteIp = Udp.remoteIP(); + Serial.print(remoteIp); + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBufffer + int len = Udp.read(packetBuffer, 255); + if (len > 0) packetBuffer[len] = 0; + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply, to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiUdpSendReceiveString/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/WiFiWebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/WiFiWebClient.ino new file mode 100644 index 00000000..d4de8c36 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/WiFiWebClient.ino @@ -0,0 +1,116 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using a WiFi 101 Shield. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi 101 Shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ + + +#include +#include +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino new file mode 100644 index 00000000..a036b6be --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -0,0 +1,127 @@ +/* + Repeating WiFi Web Client + + This sketch connects to a a web server and makes a request + using an Arduino WiFi 101 Shield. + + Circuit: + * WiFi 101 Shield attached to pins SPI pins and pin 7 + + created 23 April 2012 + modified 31 May 2012 + by Tom Igoe + modified 13 Jan 2014 + by Federico Vanzati + + http://arduino.cc/en/Tutorial/WiFiWebClientRepeating + This code is in the public domain. + */ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +// Initialize the WiFi client library +WiFiClient client; + +// server address: +char server[] = "example.org"; +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + // you're connected now, so print out the status: + printWiFiStatus(); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } + +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before sending a new request. + // This will free the socket on the WiFi 101 Shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP PUT request: + client.println("GET / HTTP/1.1"); + client.println("Host: example.org"); + client.println("User-Agent: ArduinoWiFi/1.1"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } + else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebClientRepeating/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/WiFiWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/WiFiWebServer.ino new file mode 100644 index 00000000..c7dddd2b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/WiFiWebServer.ino @@ -0,0 +1,135 @@ +/* + WiFi Web Server + + A simple web server that shows the value of the analog input pins. + using a WiFi 101 Shield. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * WiFi 101 Shield attached + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi 101 Shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); + // you're connected now, so print out the status: + printWiFiStatus(); +} + + +void loop() { + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + bool currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
    "); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } + else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi 101 Shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101/examples/WiFiWebServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/README.adoc new file mode 100644 index 00000000..ca878e8b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/README.adoc @@ -0,0 +1,32 @@ +:repository-owner: arduino-libraries +:repository-name: WiFi101OTA + += {repository-name} Library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +This library allows you to update sketches on your board over WiFi. +It requires an Arduino SAMD board like the Zero or MKR1000. + +For more information about this library please visit us at +https://www.arduino.cc/en/Reference/WiFi101OTA + +== License == + +Copyright (c) Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/WiFi101_OTA.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/WiFi101_OTA.ino new file mode 100644 index 00000000..06942290 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/WiFi101_OTA.ino @@ -0,0 +1,81 @@ +/* + + This example connects to an WPA encrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + It then polls for sketch updates over WiFi. Sketches + can be updated by selecting a network port from within + the Arduino IDE: Tools -> Port -> Network Ports ... + + Circuit: + * WiFi shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + modified 16 January 2017 + by Sandeep Mistry + */ + +#include +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +/////// WiFi Settings /////// +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password + +int status = WL_IDLE_STATUS; + +void setup() { + //Initialize serial: + Serial.begin(9600); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + } + + // start the WiFi OTA library with internal (flash) based storage + WiFiOTA.begin("Arduino", "password", InternalStorage); + + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // check for WiFi OTA updates + WiFiOTA.poll(); + + // add your normal loop code below ... +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/arduino_secrets.h new file mode 100644 index 00000000..a8ff904d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_OTA/arduino_secrets.h @@ -0,0 +1,3 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino new file mode 100644 index 00000000..e0e914ee --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/WiFi101_SD_OTA.ino @@ -0,0 +1,93 @@ +/* + + This example connects to an WPA encrypted WiFi network. + Then it prints the MAC address of the WiFi shield, + the IP address obtained, and other network details. + It then polls for sketch updates over WiFi. Sketches + can be updated by selecting a network port from within + the Arduino IDE: Tools -> Port -> Network Ports ... + + Circuit: + * WiFi shield attached + * SD shield attached + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + modified 16 January 2017 + by Sandeep Mistry + */ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +/////// WiFi Settings /////// +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password + +int status = WL_IDLE_STATUS; + +void setup() { + //Initialize serial: + Serial.begin(9600); + + // setup SD card + Serial.print("Initializing SD card..."); + if (!SD.begin(SDCARD_SS_PIN)) { + Serial.println("initialization failed!"); + // don't continue: + while (true); + } + Serial.println("initialization done."); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + } + + // start the WiFi OTA library with SD based storage + WiFiOTA.begin("Arduino", "password", SDStorage); + + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // check for WiFi OTA updates + WiFiOTA.poll(); + + // add your normal loop code below ... +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/arduino_secrets.h new file mode 100644 index 00000000..a8ff904d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFi101OTA/examples/WiFi101_SD_OTA/arduino_secrets.h @@ -0,0 +1,3 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/README.adoc new file mode 100644 index 00000000..aaaf6e80 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/README.adoc @@ -0,0 +1,35 @@ +// Define the repository information in these attributes +:repository-owner: arduino-libraries +:repository-name: WiFiNINA + += {repository-name} library for Arduino = + +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml/badge.svg["Check Arduino status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-arduino.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml/badge.svg["Compile Examples status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/compile-examples.yml"] +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml/badge.svg["Spell Check status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/spell-check.yml"] + +Enables network connection (local and Internet) with the Arduino MKR WiFi 1010, Arduino MKR VIDOR 4000 and Arduino UNO WiFi Rev.2. + +With this library you can instantiate Servers, Clients and send/receive UDP packets through WiFi. The board can connect either to open or encrypted networks (WEP, WPA). The IP address can be assigned statically or through a DHCP. The library can also manage DNS. + +For more information about this library please visit us at +https://www.arduino.cc/reference/en/libraries/wifinina/ + +== License == + +Copyright (c) 2018 Arduino SA. All rights reserved. +Copyright (c) 2011-2014 Arduino LLC. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino new file mode 100644 index 00000000..17d72d19 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/AP_SimpleWebServer.ino @@ -0,0 +1,163 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will create a new access point (with no password). + It will then launch a new server and print out the IP address + to the Serial Monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 13. + + If the IP address of your board is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + created 25 Nov 2012 + by Tom Igoe + adapted to WiFi AP by Adafruit + */ + +#include +#include +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int led = LED_BUILTIN; +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("Access Point Web Server"); + + pinMode(led, OUTPUT); // set the LED pin mode + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // by default the local IP address will be 192.168.4.1 + // you can override it with the following: + // WiFi.config(IPAddress(10, 0, 0, 1)); + + // print the network name (SSID); + Serial.print("Creating access point named: "); + Serial.println(ssid); + + // Create open network. Change this line if you want to create an WEP network: + status = WiFi.beginAP(ssid, pass); + if (status != WL_AP_LISTENING) { + Serial.println("Creating access point failed"); + // don't continue + while (true); + } + + // wait 10 seconds for connection: + delay(10000); + + // start the web server on port 80 + server.begin(); + + // you're connected now, so print out the status + printWiFiStatus(); +} + + +void loop() { + // compare the previous status to the current status + if (status != WiFi.status()) { + // it has changed update the variable + status = WiFi.status(); + + if (status == WL_AP_CONNECTED) { + // a device has connected to the AP + Serial.println("Device connected to AP"); + } else { + // a device has disconnected from the AP, and we are back in listening mode + Serial.println("Device disconnected from AP"); + } + } + + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + delayMicroseconds(10); // This is required for the Arduino Nano RP2040 Connect - otherwise it will loop so fast that SPI will never be served. + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on
    "); + client.print("Click here turn the LED off
    "); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } + else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } + else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(led, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(led, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your WiFi shield's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/arduino_secrets.h new file mode 100644 index 00000000..493b719c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/AP_SimpleWebServer/arduino_secrets.h @@ -0,0 +1,3 @@ +// Both SSID and password must be 8 characters or longer +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/ConnectNoEncryption.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/ConnectNoEncryption.ino new file mode 100644 index 00000000..22ba35ad --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/ConnectNoEncryption.ino @@ -0,0 +1,116 @@ +/* + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the board, + the IP address obtained, and other network details. + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to open SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); + + // print your subnet mask: + IPAddress subnet = WiFi.subnetMask(); + Serial.print("NetMask: "); + Serial.println(subnet); + + // print your gateway address: + IPAddress gateway = WiFi.gatewayIP(); + Serial.print("Gateway: "); + Serial.println(gateway); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/arduino_secrets.h new file mode 100644 index 00000000..07c11487 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectNoEncryption/arduino_secrets.h @@ -0,0 +1 @@ +#define SECRET_SSID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/ConnectWithWEP.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/ConnectWithWEP.ino new file mode 100644 index 00000000..5f65ce4b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/ConnectWithWEP.ino @@ -0,0 +1,120 @@ +/* + This example connects to a WEP-encrypted WiFi network. + Then it prints the MAC address of the WiFi module, + the IP address obtained, and other network details. + + If you use 40-bit WEP, you need a key that is 10 characters long, + and the characters must be hexadecimal (0-9 or A-F). + e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work + (too short) and ABBAISDEAF won't work (I and S are not + hexadecimal characters). + + For 128-bit, you need a string that is 26 characters long. + D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters, + all in the 0-9, A-F range. + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WEP network, SSID: "); + Serial.println(ssid); + status = WiFi.begin(ssid, keyIndex, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // once you are connected : + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWEP/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/ConnectWithWPA.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/ConnectWithWPA.ino new file mode 100644 index 00000000..2e2b95e1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/ConnectWithWPA.ino @@ -0,0 +1,111 @@ +/* + This example connects to an unencrypted WiFi network. + Then it prints the MAC address of the WiFi module, + the IP address obtained, and other network details. + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); + +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino new file mode 100644 index 00000000..fcf090ba --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/ConnectWithWPA2Enterprise.ino @@ -0,0 +1,110 @@ +/* + This example connects to a WPA2 Enterprise WiFi network. + Then it prints the MAC address of the WiFi module, + the IP address obtained, and other network details. + + Based on ConnectWithWPA.ino by dlf (Metodo2 srl) and Tom Igoe +*/ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your WPA2 enterprise network SSID (name) +char user[] = SECRET_USER; // your WPA2 enterprise username +char pass[] = SECRET_PASS; // your WPA2 enterprise password +int status = WL_IDLE_STATUS; // the WiFi radio's status + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA2 enterprise network: + // - You can optionally provide additional identity and CA cert (string) parameters if your network requires them: + // WiFi.beginEnterprise(ssid, user, pass, identity, caCert) + status = WiFi.beginEnterprise(ssid, user, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // you're connected now, so print out the data: + Serial.print("You're connected to the network"); + printCurrentNet(); + printWifiData(); + +} + +void loop() { + // check the network connection once every 10 seconds: + delay(10000); + printCurrentNet(); +} + +void printWifiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type:"); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/arduino_secrets.h new file mode 100644 index 00000000..d1310bbd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ConnectWithWPA2Enterprise/arduino_secrets.h @@ -0,0 +1,3 @@ +#define SECRET_SSID "" +#define SECRET_USER "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ScanNetworks/ScanNetworks.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ScanNetworks/ScanNetworks.ino new file mode 100644 index 00000000..e90bc7ec --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ScanNetworks/ScanNetworks.ino @@ -0,0 +1,116 @@ +/* + This example prints the board's MAC address, and + scans for available WiFi networks using the NINA module. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 21 Junn 2012 + by Tom Igoe and Jaymes Dec + */ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC: "); + printMacAddress(mac); +} + +void loop() { + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); + delay(10000); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) { + Serial.println("Couldn't get a WiFi connection"); + while (true); + } + + // print the list of networks seen: + Serial.print("number of available networks:"); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet); + Serial.print(") "); + Serial.print(WiFi.SSID(thisNet)); + Serial.print("\tSignal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + } +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.println("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.println("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.println("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.println("None"); + break; + case ENC_TYPE_AUTO: + Serial.println("Auto"); + break; + case ENC_TYPE_UNKNOWN: + default: + Serial.println("Unknown"); + break; + } +} + + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino new file mode 100644 index 00000000..9a32862e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/ScanNetworksAdvanced/ScanNetworksAdvanced.ino @@ -0,0 +1,137 @@ +/* + This example prints the board's MAC address, and + scans for available WiFi networks using the NINA module. + Every ten seconds, it scans again. It doesn't actually + connect to any network, so no encryption scheme is specified. + BSSID and WiFi channel are printed + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + This example is based on ScanNetworks + + created 1 Mar 2017 + by Arturo Guadalupi +*/ + + +#include +#include + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC: "); + printMacAddress(mac); + + // scan for existing networks: + Serial.println(); + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void loop() { + delay(10000); + // scan for existing networks: + Serial.println("Scanning available networks..."); + listNetworks(); +} + +void listNetworks() { + // scan for nearby networks: + Serial.println("** Scan Networks **"); + int numSsid = WiFi.scanNetworks(); + if (numSsid == -1) + { + Serial.println("Couldn't get a WiFi connection"); + while (true); + } + + // print the list of networks seen: + Serial.print("number of available networks: "); + Serial.println(numSsid); + + // print the network number and name for each network found: + for (int thisNet = 0; thisNet < numSsid; thisNet++) { + Serial.print(thisNet + 1); + Serial.print(") "); + Serial.print("Signal: "); + Serial.print(WiFi.RSSI(thisNet)); + Serial.print(" dBm"); + Serial.print("\tChannel: "); + Serial.print(WiFi.channel(thisNet)); + byte bssid[6]; + Serial.print("\t\tBSSID: "); + printMacAddress(WiFi.BSSID(thisNet, bssid)); + Serial.print("\tEncryption: "); + printEncryptionType(WiFi.encryptionType(thisNet)); + Serial.print("\t\tSSID: "); + Serial.println(WiFi.SSID(thisNet)); + Serial.flush(); + } + Serial.println(); +} + +void printEncryptionType(int thisType) { + // read the encryption type and print out the name: + switch (thisType) { + case ENC_TYPE_WEP: + Serial.print("WEP"); + break; + case ENC_TYPE_TKIP: + Serial.print("WPA"); + break; + case ENC_TYPE_CCMP: + Serial.print("WPA2"); + break; + case ENC_TYPE_NONE: + Serial.print("None"); + break; + case ENC_TYPE_AUTO: + Serial.print("Auto"); + break; + case ENC_TYPE_UNKNOWN: + default: + Serial.print("Unknown"); + break; + } +} + +void print2Digits(byte thisByte) { + if (thisByte < 0xF) { + Serial.print("0"); + } + Serial.print(thisByte, HEX); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino new file mode 100644 index 00000000..6f9eef16 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/SimpleWebServerWiFi.ino @@ -0,0 +1,135 @@ +/* + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will print the IP address of your WiFi module (once connected) + to the Serial Monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 9. + + If the IP address of your board is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + * LED attached to pin 9 + + created 25 Nov 2012 + by Tom Igoe + */ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +WiFiServer server(80); + +void setup() { + Serial.begin(9600); // initialize serial communication + pinMode(9, OUTPUT); // set the LED pin mode + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to Network named: "); + Serial.println(ssid); // print the network name (SSID); + + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); // start the web server on port 80 + printWifiStatus(); // you're connected now, so print out the status +} + + +void loop() { + WiFiClient client = server.available(); // listen for incoming clients + + if (client) { // if you get a client, + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on pin 9 on
    "); + client.print("Click here turn the LED on pin 9 off
    "); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(LED_BUILTIN, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/SimpleWebServerWiFi/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino new file mode 100644 index 00000000..1a30163e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/CheckFirmwareVersion/CheckFirmwareVersion.ino @@ -0,0 +1,58 @@ +/* + * This example checks if the firmware loaded on the NINA module + * is updated. + * + * Circuit: + * - Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + * + * Created 17 October 2018 by Riccardo Rosario Rizzo + * This code is in the public domain. + */ +#include +#include + +void setup() { + // Initialize serial + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Print a welcome message + Serial.println("WiFiNINA firmware check."); + Serial.println(); + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + // Print firmware version on the module + String fv = WiFi.firmwareVersion(); + String latestFv; + Serial.print("Firmware version installed: "); + Serial.println(fv); + + latestFv = WIFI_FIRMWARE_LATEST_VERSION; + + // Print required firmware version + Serial.print("Latest firmware version available : "); + Serial.println(latestFv); + + // Check if the latest version is installed + Serial.println(); + if (fv >= latestFv) { + Serial.println("Check result: PASSED"); + } else { + Serial.println("Check result: NOT PASSED"); + Serial.println(" - The firmware version on the module does not match the"); + Serial.println(" version required by the library, you may experience"); + Serial.println(" issues or failures."); + } +} + +void loop() { + // do nothing +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.cpp b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.cpp new file mode 100644 index 00000000..320f245f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.cpp @@ -0,0 +1,335 @@ +/* + ESP32BootROM - part of the Firmware Updater for the + Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. + + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifdef ARDUINO_SAMD_MKRVIDOR4000 +#include + +#define NINA_GPIO0 FPGA_NINA_GPIO0 +#define NINA_RESETN FPGA_SPIWIFI_RESET +#endif + + +#include "ESP32BootROM.h" + +ESP32BootROMClass::ESP32BootROMClass(HardwareSerial& serial, int gpio0Pin, int resetnPin) : + _serial(&serial), + _gpio0Pin(gpio0Pin), + _resetnPin(resetnPin) +{ + +} + +int ESP32BootROMClass::begin(unsigned long baudrate) +{ +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.begin(); + + _serial->begin(119400); + + FPGA.pinMode(_gpio0Pin, OUTPUT); + FPGA.pinMode(_resetnPin, OUTPUT); + + FPGA.digitalWrite(_gpio0Pin, LOW); + + FPGA.digitalWrite(_resetnPin, LOW); + delay(10); + FPGA.digitalWrite(_resetnPin, HIGH); + delay(100); + +#elif defined(ARDUINO_AVR_UNO_WIFI_REV2) + _serial->begin(119400); + + pinMode(_gpio0Pin, OUTPUT); + pinMode(_resetnPin, OUTPUT); + + digitalWrite(_gpio0Pin, LOW); + + digitalWrite(_resetnPin, LOW); + delay(100); + digitalWrite(_resetnPin, HIGH); + delay(100); + digitalWrite(_resetnPin, LOW); +#else + _serial->begin(115200); + + pinMode(_gpio0Pin, OUTPUT); + pinMode(_resetnPin, OUTPUT); + + digitalWrite(_gpio0Pin, LOW); + + digitalWrite(_resetnPin, HIGH); + delay(10); + digitalWrite(_resetnPin, LOW); + delay(100); +#if defined(ARDUINO_SAMD_NANO_33_IOT) ||defined(ARDUINO_NANO_RP2040_CONNECT) + digitalWrite(_resetnPin, HIGH); + delay(100); +#endif +#endif + + int synced = 0; + + for (int retries = 0; !synced && (retries < 5); retries++) { + synced = sync(); + } + + if (!synced) { + return 0; + } + +#if defined(ARDUINO_SAMD_MKRVIDOR4000) || defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined(ARDUINO_NANO_RP2040_CONNECT) + (void)baudrate; +#else + if (baudrate != 115200) { + if (!changeBaudrate(baudrate)) { + return 0; + } + + delay(100); + + _serial->end(); + _serial->begin(baudrate); + } +#endif + + if (!spiAttach()) { + return 0; + } + + return 1; +} + +void ESP32BootROMClass::end() { + _serial->end(); +} + +int ESP32BootROMClass::sync() +{ + const uint8_t data[] = { + 0x07, 0x07, 0x12, 0x20, + 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55 + }; + + command(0x08, data, sizeof(data)); + + int results[8]; + + for (int i = 0; i < 8; i++) { + results[i] = response(0x08, 100); + } + + return (results[0] == 0); +} + +int ESP32BootROMClass::changeBaudrate(unsigned long baudrate) +{ + const uint32_t data[2] = { + baudrate, + 0 + }; + + command(0x0f, data, sizeof(data)); + + return (response(0x0f, 3000) == 0); +} + +int ESP32BootROMClass::spiAttach() +{ + const uint8_t data[] = { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + + command(0x0d, data, sizeof(data)); + + return (response(0x0d, 3000) == 0); +} + +int ESP32BootROMClass::beginFlash(uint32_t offset, uint32_t size, uint32_t chunkSize) { + const uint32_t data[4] = { + size, + size / chunkSize, + chunkSize, + offset + }; + + command(0x02, data, sizeof(data)); + + _flashSequenceNumber = 0; + _chunkSize = chunkSize; + + return (response(0x02, 120000) == 0); +} + +int ESP32BootROMClass::dataFlash(const void* data, uint32_t length) +{ + uint32_t cmdData[4 + (_chunkSize / 4)]; + + cmdData[0] = length; + cmdData[1] = _flashSequenceNumber++; + cmdData[2] = 0; + cmdData[3] = 0; + + memcpy(&cmdData[4], data, length); + + if (length < _chunkSize) { + memset(&cmdData[4 + (length / 4)], 0xff, _chunkSize - length); + } + + command(0x03, cmdData, sizeof(cmdData)); + + return (response(0x03, 3000) == 0); +} + +int ESP32BootROMClass::endFlash(uint32_t reboot) { + const uint32_t data[1] = { + reboot + }; + + command(0x04, data, sizeof(data)); + + return (response(0x04, 3000) == 0); +} + +int ESP32BootROMClass::md5Flash(uint32_t offset, uint32_t size, uint8_t* result) +{ + const uint32_t data[4] = { + offset, + size, + 0, + 0 + }; + + command(0x13, data, sizeof(data)); + + uint8_t asciiResult[32]; + + if (response(0x13, 3000, asciiResult) != 0) { + return 0; + } + + char temp[3] = { 0, 0, 0 }; + + for (int i = 0; i < 16; i++) { + temp[0] = asciiResult[i * 2]; + temp[1] = asciiResult[i * 2 + 1]; + + result[i] = strtoul(temp, NULL, 16); + } + + return 1; +} + +void ESP32BootROMClass::command(int opcode, const void* data, uint16_t length) +{ + uint32_t checksum = 0; + + if (opcode == 0x03) { + checksum = 0xef; // seed + + for (uint16_t i = 16; i < length; i++) { + checksum ^= ((const uint8_t*)data)[i]; + } + } + + _serial->write(0xc0); + _serial->write((uint8_t)0x00); // direction + _serial->write(opcode); + _serial->write((uint8_t*)&length, sizeof(length)); + writeEscapedBytes((uint8_t*)&checksum, sizeof(checksum)); + writeEscapedBytes((uint8_t*)data, length); + _serial->write(0xc0); +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + // _serial->flush(); // doesn't work! +#else + _serial->flush(); +#endif +} + +int ESP32BootROMClass::response(int opcode, unsigned long timeout, void* body) +{ + uint8_t data[10 + 256]; + uint16_t index = 0; + + uint8_t responseLength = 4; + + for (unsigned long start = millis(); (index < (uint16_t)(10 + responseLength)) && (millis() - start) < timeout;) { + if (_serial->available()) { + data[index] = _serial->read(); + + if (index == 3) { + responseLength = data[index]; + } + + index++; + } + } + +#ifdef DEBUG + if (index) { + for (int i = 0; i < index; i++) { + byte b = data[i]; + + if (b < 0x10) { + Serial.print('0'); + } + + Serial.print(b, HEX); + Serial.print(' '); + } + Serial.println(); + } +#endif + + if (index != (uint16_t)(10 + responseLength)) { + return -1; + } + + if (data[0] != 0xc0 || data[1] != 0x01 || data[2] != opcode || data[responseLength + 5] != 0x00 || data[responseLength + 6] != 0x00 || data[responseLength + 9] != 0xc0) { + return -1; + } + + if (body) { + memcpy(body, &data[9], responseLength - 4); + } + + return data[responseLength + 5]; +} + +void ESP32BootROMClass::writeEscapedBytes(const uint8_t* data, uint16_t length) +{ + uint16_t written = 0; + + while (written < length) { + uint8_t b = data[written++]; + + if (b == 0xdb) { + _serial->write(0xdb); + _serial->write(0xdd); + } else if (b == 0xc0) { + _serial->write(0xdb); + _serial->write(0xdc); + } else { + _serial->write(b); + } + } +} + +ESP32BootROMClass ESP32BootROM(SerialNina, NINA_GPIO0, NINA_RESETN); diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.h new file mode 100644 index 00000000..578b4ec0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/ESP32BootROM.h @@ -0,0 +1,56 @@ +/* + ESP32BootROM - part of the Firmware Updater for the + Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. + + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include + +class ESP32BootROMClass { + public: + ESP32BootROMClass(HardwareSerial& hwSerial, int gpio0Pin, int resetnPin); + + int begin(unsigned long baudrate); + void end(); + + int beginFlash(uint32_t offset, uint32_t size, uint32_t chunkSize); + int dataFlash(const void* data, uint32_t length); + int endFlash(uint32_t reboot); + + int md5Flash(uint32_t offset, uint32_t size, uint8_t* result); + + private: + int sync(); + int changeBaudrate(unsigned long baudrate); + int spiAttach(); + + void command(int opcode, const void* data, uint16_t length); + int response(int opcode, unsigned long timeout, void* body = NULL); + + void writeEscapedBytes(const uint8_t* data, uint16_t length); + + private: + HardwareSerial* _serial; + int _gpio0Pin; + int _resetnPin; + + uint32_t _flashSequenceNumber; + uint32_t _chunkSize; +}; + +extern ESP32BootROMClass ESP32BootROM; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/Endianess.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/Endianess.ino new file mode 100644 index 00000000..d55cacb6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/Endianess.ino @@ -0,0 +1,60 @@ +/* + Endianess.ino - Network byte order conversion functions. + Copyright (c) 2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +bool isBigEndian() { + uint32_t test = 0x11223344; + uint8_t *pTest = reinterpret_cast(&test); + return pTest[0] == 0x11; +} + +uint32_t fromNetwork32(uint32_t from) { + static const bool be = isBigEndian(); + if (be) { + return from; + } else { + uint8_t *pFrom = reinterpret_cast(&from); + uint32_t to; + to = pFrom[0]; to <<= 8; + to |= pFrom[1]; to <<= 8; + to |= pFrom[2]; to <<= 8; + to |= pFrom[3]; + return to; + } +} + +uint16_t fromNetwork16(uint16_t from) { + static bool be = isBigEndian(); + if (be) { + return from; + } else { + uint8_t *pFrom = reinterpret_cast(&from); + uint16_t to; + to = pFrom[0]; to <<= 8; + to |= pFrom[1]; + return to; + } +} + +uint32_t toNetwork32(uint32_t to) { + return fromNetwork32(to); +} + +uint16_t toNetwork16(uint16_t to) { + return fromNetwork16(to); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/FirmwareUpdater.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/FirmwareUpdater.ino new file mode 100644 index 00000000..acf80fd7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/FirmwareUpdater/FirmwareUpdater.ino @@ -0,0 +1,142 @@ +/* + FirmwareUpdater - Firmware Updater for the + Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. + + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include "ESP32BootROM.h" + +typedef struct __attribute__((__packed__)) { + uint8_t command; + uint32_t address; + uint32_t arg1; + uint16_t payloadLength; + + // payloadLength bytes of data follows... +} UartPacket; + +static const int MAX_PAYLOAD_SIZE = 1024; + +#define CMD_READ_FLASH 0x01 +#define CMD_WRITE_FLASH 0x02 +#define CMD_ERASE_FLASH 0x03 +#define CMD_MD5_FLASH 0x04 +#define CMD_MAX_PAYLOAD_SIZE 0x50 +#define CMD_HELLO 0x99 + +void setup() { + Serial.begin(1000000); + + if (!ESP32BootROM.begin(921600)) { + Serial.println("Unable to communicate with ESP32 boot ROM!"); + while (1); + } +} + +void receivePacket(UartPacket *pkt, uint8_t *payload) { + // Read command + uint8_t *p = reinterpret_cast(pkt); + uint16_t l = sizeof(UartPacket); + while (l > 0) { + int c = Serial.read(); + if (c == -1) + continue; + *p++ = c; + l--; + } + + // Convert parameters from network byte order to cpu byte order + pkt->address = fromNetwork32(pkt->address); + pkt->arg1 = fromNetwork32(pkt->arg1); + pkt->payloadLength = fromNetwork16(pkt->payloadLength); + + // Read payload + l = pkt->payloadLength; + while (l > 0) { + int c = Serial.read(); + if (c == -1) + continue; + *payload++ = c; + l--; + } +} + +// Allocated statically so the compiler can tell us +// about the amount of used RAM +static UartPacket pkt; +static uint8_t payload[MAX_PAYLOAD_SIZE]; + +void loop() { + receivePacket(&pkt, payload); + + if (pkt.command == CMD_HELLO) { + if (pkt.address == 0x11223344 && pkt.arg1 == 0x55667788) + Serial.print("v10000"); + } + + if (pkt.command == CMD_MAX_PAYLOAD_SIZE) { + uint16_t res = toNetwork16(MAX_PAYLOAD_SIZE); + Serial.write(reinterpret_cast(&res), sizeof(res)); + } + + if (pkt.command == CMD_READ_FLASH) { + // not supported! + Serial.println("ER"); + } + + if (pkt.command == CMD_WRITE_FLASH) { + uint32_t len = pkt.payloadLength; + if (!ESP32BootROM.dataFlash(payload, len)) { + Serial.print("ER"); + } else { + Serial.print("OK"); + } + } + + if (pkt.command == CMD_ERASE_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.arg1; + if (!ESP32BootROM.beginFlash(address, len, MAX_PAYLOAD_SIZE)) { + Serial.print("ER"); + } else { + Serial.print("OK"); + } + } + + if (pkt.command == CMD_MD5_FLASH) { + uint32_t address = pkt.address; + uint32_t len = pkt.arg1; + + if (!ESP32BootROM.endFlash(1)) { + Serial.print("ER"); + } else { + ESP32BootROM.end(); + + uint8_t md5[16]; + + if (!ESP32BootROM.begin(921600)) { + Serial.print("ER"); + } else if (!ESP32BootROM.md5Flash(address, len, md5)) { + Serial.print("ER"); + } else { + Serial.print("OK"); + Serial.write(md5, sizeof(md5)); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/SerialNINAPassthrough/SerialNINAPassthrough.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/SerialNINAPassthrough/SerialNINAPassthrough.ino new file mode 100644 index 00000000..acfd078c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/Tools/SerialNINAPassthrough/SerialNINAPassthrough.ino @@ -0,0 +1,105 @@ +/* + SerialNINAPassthrough - Use esptool to flash the u-blox NINA (ESP32) module + Arduino MKR WiFi 1010, Arduino MKR Vidor 4000, and Arduino UNO WiFi Rev.2. + + Copyright (c) 2018 Arduino SA. All rights reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifdef ARDUINO_SAMD_MKRVIDOR4000 +#include + +unsigned long baud = 119400; +#else +unsigned long baud = 115200; +#endif + +int rts = -1; +int dtr = -1; + +void setup() { + Serial.begin(baud); + +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.begin(); +#endif + + SerialNina.begin(baud); + +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.pinMode(FPGA_NINA_GPIO0, OUTPUT); + FPGA.pinMode(FPGA_SPIWIFI_RESET, OUTPUT); +#else + pinMode(NINA_GPIO0, OUTPUT); + pinMode(NINA_RESETN, OUTPUT); +#endif + +#ifdef ARDUINO_AVR_UNO_WIFI_REV2 + // manually put the NINA in upload mode + digitalWrite(NINA_GPIO0, LOW); + + digitalWrite(NINA_RESETN, LOW); + delay(100); + digitalWrite(NINA_RESETN, HIGH); + delay(100); + digitalWrite(NINA_RESETN, LOW); +#endif +} + +void loop() { +#ifndef ARDUINO_AVR_UNO_WIFI_REV2 + if (rts != Serial.rts()) { +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.digitalWrite(FPGA_SPIWIFI_RESET, (Serial.rts() == 1) ? LOW : HIGH); +#elif defined(ARDUINO_SAMD_NANO_33_IOT) + digitalWrite(NINA_RESETN, Serial.rts() ? LOW : HIGH); +#else + digitalWrite(NINA_RESETN, Serial.rts()); +#endif + rts = Serial.rts(); + } + + if (dtr != Serial.dtr()) { +#ifdef ARDUINO_SAMD_MKRVIDOR4000 + FPGA.digitalWrite(FPGA_NINA_GPIO0, (Serial.dtr() == 1) ? HIGH : LOW); +#else + digitalWrite(NINA_GPIO0, (Serial.dtr() == 0) ? HIGH : LOW); +#endif + dtr = Serial.dtr(); + } +#endif + + if (Serial.available()) { + SerialNina.write(Serial.read()); + } + + if (SerialNina.available()) { + Serial.write(SerialNina.read()); + } + +#ifndef ARDUINO_AVR_UNO_WIFI_REV2 + // check if the USB virtual serial wants a new baud rate + if (Serial.baud() != baud) { + rts = -1; + dtr = -1; + + baud = Serial.baud(); +#ifndef ARDUINO_SAMD_MKRVIDOR4000 + SerialNina.begin(baud); +#endif + } +#endif +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/WiFiChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/WiFiChatServer.ino new file mode 100644 index 00000000..c608016f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/WiFiChatServer.ino @@ -0,0 +1,117 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 18 Dec 2009 + by David A. Mellis + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) + +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(23); + +boolean alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + // start the server: + server.begin(); + // you're connected now, so print out the status: + printWifiStatus(); +} + + +void loop() { + // wait for a new client: + WiFiClient client = server.available(); + + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clear out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiChatServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/WiFiPing.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/WiFiPing.ino new file mode 100644 index 00000000..48ad458a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/WiFiPing.ino @@ -0,0 +1,135 @@ +/* + This example connects to an encrypted WiFi network (WPA/WPA2). + Then it prints the MAC address of the board, + the IP address obtained, and other network details. + Then it continuously pings given host specified by IP Address or name. + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 09 June 2016 + by Petar Georgiev +*/ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int status = WL_IDLE_STATUS; // the WiFi radio's status + +// Specify IP address or hostname +String hostName = "www.google.com"; +int pingResult; + +void setup() { + // Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to WPA SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network: + status = WiFi.begin(ssid, pass); + + // wait 5 seconds for connection: + delay(5000); + } + + // you're connected now, so print out the data: + Serial.println("You're connected to the network"); + printCurrentNet(); + printWiFiData(); +} + +void loop() { + Serial.print("Pinging "); + Serial.print(hostName); + Serial.print(": "); + + pingResult = WiFi.ping(hostName); + + if (pingResult >= 0) { + Serial.print("SUCCESS! RTT = "); + Serial.print(pingResult); + Serial.println(" ms"); + } else { + Serial.print("FAILED! Error code: "); + Serial.println(pingResult); + } + + delay(5000); +} + +void printWiFiData() { + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP address : "); + Serial.println(ip); + + Serial.print("Subnet mask: "); + Serial.println((IPAddress)WiFi.subnetMask()); + + Serial.print("Gateway IP : "); + Serial.println((IPAddress)WiFi.gatewayIP()); + + // print your MAC address: + byte mac[6]; + WiFi.macAddress(mac); + Serial.print("MAC address: "); + printMacAddress(mac); +} + +void printCurrentNet() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print the MAC address of the router you're attached to: + byte bssid[6]; + WiFi.BSSID(bssid); + Serial.print("BSSID: "); + printMacAddress(bssid); + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI): "); + Serial.println(rssi); + + // print the encryption type: + byte encryption = WiFi.encryptionType(); + Serial.print("Encryption Type: "); + Serial.println(encryption, HEX); + Serial.println(); +} + +void printMacAddress(byte mac[]) { + for (int i = 5; i >= 0; i--) { + if (mac[i] < 16) { + Serial.print("0"); + } + Serial.print(mac[i], HEX); + if (i > 0) { + Serial.print(":"); + } + } + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiPing/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/WiFiSSLClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/WiFiSSLClient.ino new file mode 100644 index 00000000..003fbf07 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/WiFiSSLClient.ino @@ -0,0 +1,112 @@ +/* +This example creates a client object that connects and transfers +data using always SSL. + +It is compatible with the methods normally related to plain +connections, like client.connect(host, port). + +Written by Arturo Guadalupi +last revision November 2015 + +*/ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiSSLClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWiFiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 443)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiSSLClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiStorage/WiFiStorage.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiStorage/WiFiStorage.ino new file mode 100644 index 00000000..5fd627b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiStorage/WiFiStorage.ino @@ -0,0 +1,42 @@ +/* + This example shows how to interact with NINA internal memory partition + APIs are modeled on SerialFlash library (not on SD) to speedup operations and avoid buffers. +*/ + +#include + +void setup() { + + Serial.begin(115200); + while (!Serial); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + WiFiStorageFile file = WiFiStorage.open("/fs/testfile"); + + if (file) { + file.erase(); + } + + String test = "Cantami o Diva del pelide Achille"; + file.write(test.c_str(), test.length()); + + if (file) { + file.seek(0); + while (file.available()) { + uint8_t buf[128]; + int ret = file.read(buf, 128); + Serial.write(buf, ret); + } + } +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino new file mode 100644 index 00000000..c091a5b6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/WiFiUdpNtpClient.ino @@ -0,0 +1,173 @@ +/* + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + + This code is in the public domain. + + */ + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen for UDP packets + +IPAddress timeServer(162, 159, 200, 123); // pool.ntp.org NTP server + +const int NTP_PACKET_SIZE = 48; // NTP timestamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +WiFiUDP Udp; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + Udp.begin(localPort); +} + +void loop() { + sendNTPpacket(timeServer); // send an NTP packet to a time server + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + Serial.println("packet received"); + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + //the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +unsigned long sendNTPpacket(IPAddress& address) { + //Serial.println("1"); + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + //Serial.println("2"); + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + //Serial.println("3"); + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); //NTP requests are to port 123 + //Serial.println("4"); + Udp.write(packetBuffer, NTP_PACKET_SIZE); + //Serial.println("5"); + Udp.endPacket(); + //Serial.println("6"); +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpNtpClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino new file mode 100644 index 00000000..d022e278 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/WiFiUdpSendReceiveString.ino @@ -0,0 +1,112 @@ +/* + WiFi UDP Send and Receive String + + This sketch waits for a UDP packet on localPort using the WiFi module. + When a packet is received an Acknowledge packet is sent to the client on port remotePort + + created 30 December 2012 + by dlf (Metodo2 srl) + + */ + + +#include +#include +#include + +int status = WL_IDLE_STATUS; +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +unsigned int localPort = 2390; // local port to listen on + +char packetBuffer[256]; //buffer to hold incoming packet +char ReplyBuffer[] = "acknowledged"; // a string to send back + +WiFiUDP Udp; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + Udp.begin(localPort); +} + +void loop() { + + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remoteIp = Udp.remoteIP(); + Serial.print(remoteIp); + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBufffer + int len = Udp.read(packetBuffer, 255); + if (len > 0) { + packetBuffer[len] = 0; + } + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply, to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiUdpSendReceiveString/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/WiFiWebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/WiFiWebClient.ino new file mode 100644 index 00000000..86a1a46f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/WiFiWebClient.ino @@ -0,0 +1,122 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using the WiFi module. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * Board with NINA module (Arduino MKR WiFi 1010, MKR VIDOR 4000 and UNO WiFi Rev.2) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ + + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + Serial.println("Connected to WiFi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino new file mode 100644 index 00000000..efd96631 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/WiFiWebClientRepeating.ino @@ -0,0 +1,128 @@ +/* + Repeating WiFi Web Client + + This sketch connects to a a web server and makes a request + using a WiFi equipped Arduino board. + + created 23 April 2012 + modified 31 May 2012 + by Tom Igoe + modified 13 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WifiWebClientRepeating + This code is in the public domain. + */ + +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +// Initialize the WiFi client library +WiFiClient client; + +// server address: +char server[] = "example.org"; +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10L * 1000L; // delay between updates, in milliseconds + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + // you're connected now, so print out the status: + printWifiStatus(); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } + +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the NINA module + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET / HTTP/1.1"); + client.println("Host: example.org"); + client.println("User-Agent: ArduinoWiFi/1.1"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebClientRepeating/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/WiFiWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/WiFiWebServer.ino new file mode 100644 index 00000000..9e1200bb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/WiFiWebServer.ino @@ -0,0 +1,137 @@ +/* + WiFi Web Server + + A simple web server that shows the value of the analog input pins. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the WiFi.begin() call accordingly. + + Circuit: + * Analog inputs attached to pins A0 through A5 (optional) + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + + */ + +#include +#include + + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key index number (needed only for WEP) + +int status = WL_IDLE_STATUS; + +WiFiServer server(80); + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_MODULE) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + String fv = WiFi.firmwareVersion(); + if (fv < WIFI_FIRMWARE_LATEST_VERSION) { + Serial.println("Please upgrade the firmware"); + } + + // attempt to connect to WiFi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 10 seconds for connection: + delay(10000); + } + server.begin(); + // you're connected now, so print out the status: + printWifiStatus(); +} + + +void loop() { + // listen for incoming clients + WiFiClient client = server.available(); + if (client) { + Serial.println("new client"); + // an HTTP request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the HTTP request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard HTTP response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
    "); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino-libraries/WiFiNINA/examples/WiFiWebServer/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/README.adoc new file mode 100644 index 00000000..26a5c0e9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/README.adoc @@ -0,0 +1,12 @@ += Arduino Cloud Provider Examples = + +Examples of how to connect various Arduino boards to cloud providers. + +Related tutorials on Arduino Project Hub: + +* AWS: +** https://create.arduino.cc/projecthub/132016/securely-connecting-an-arduino-mkr-wifi-1010-to-aws-iot-core-a9f365[Securely connecting an Arduino MKR WiFi 1010 to AWS IoT Core] +* Azure +** https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-nb-1500-to-azure-iot-hub-af6470[Securely Connecting an Arduino NB 1500 to Azure IoT Hub] +* Google Cloud +** https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-mkr-gsm-1400-to-gcp-iot-core-b8b628[Securely Connecting an Arduino MKR GSM 1400 to GCP IoT Core] diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/AWS_IoT_GSM.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/AWS_IoT_GSM.ino new file mode 100644 index 00000000..20f26d33 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/AWS_IoT_GSM.ino @@ -0,0 +1,158 @@ +/* + AWS IoT GSM + + This sketch securely connects to an AWS IoT using MQTT over GSM/3G. + It uses a private key stored in the ATECC508A and a public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to arduino/outgoing + topic and subscribes to messages on the arduino/incoming + topic. + + The circuit: + - MKR GSM 1400 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char gprs_apn[] = SECRET_GPRS_APN; +const char gprs_login[] = SECRET_GPRS_LOGIN; +const char gprs_password[] = SECRET_GPRS_PASSWORD; +const char broker[] = SECRET_BROKER; +const char* certificate = SECRET_CERTIFICATE; + +GSM gsmAccess; +GPRS gprs; + +GSMClient gsmClient; // Used for the TCP socket connection +BearSSLClient sslClient(gsmClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(115200); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, certificate); + + // Optional, set the client id used for MQTT, + // each device that is connected to the broker + // must have a unique client id. The MQTTClient will generate + // a client id for you based on the millis() value if not set + // + // mqttClient.setId("clientId"); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (gsmAccess.status() != GSM_READY || gprs.status() != GPRS_READY) { + connectGSM(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the GSM module + return gsmAccess.getTime(); +} + +void connectGSM() { + Serial.println("Attempting to connect to the cellular network"); + + while ((gsmAccess.begin(pinnumber) != GSM_READY) || + (gprs.attachGPRS(gprs_apn, gprs_login, gprs_password) != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("arduino/incoming"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("arduino/outgoing"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/arduino_secrets.h new file mode 100644 index 00000000..dcf38c16 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_GSM/arduino_secrets.h @@ -0,0 +1,15 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + +// Fill in the hostname of your AWS IoT broker +#define SECRET_BROKER "xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com" + +// Fill in the boards public certificate +const char SECRET_CERTIFICATE[] = R"( +-----BEGIN CERTIFICATE----- + +-----END CERTIFICATE----- +)"; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/AWS_IoT_NB.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/AWS_IoT_NB.ino new file mode 100644 index 00000000..73fe1541 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/AWS_IoT_NB.ino @@ -0,0 +1,155 @@ +/* + AWS IoT NB + + This sketch securely connects to an AWS IoT using MQTT over NB IoT/LTE Cat M1. + It uses a private key stored in the ATECC508A and a public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to arduino/outgoing + topic and subscribes to messages on the arduino/incoming + topic. + + The circuit: + - MKR NB 1500 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char broker[] = SECRET_BROKER; +const char* certificate = SECRET_CERTIFICATE; + +NB nbAccess; +GPRS gprs; + +NBClient nbClient; // Used for the TCP socket connection +BearSSLClient sslClient(nbClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(115200); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, certificate); + + // Optional, set the client id used for MQTT, + // each device that is connected to the broker + // must have a unique client id. The MQTTClient will generate + // a client id for you based on the millis() value if not set + // + // mqttClient.setId("clientId"); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (nbAccess.status() != NB_READY || gprs.status() != GPRS_READY) { + connectNB(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the NB module + return nbAccess.getTime(); +} + +void connectNB() { + Serial.println("Attempting to connect to the cellular network"); + + while ((nbAccess.begin(pinnumber) != NB_READY) || + (gprs.attachGPRS() != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("arduino/incoming"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("arduino/outgoing"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/arduino_secrets.h new file mode 100644 index 00000000..1e568792 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_NB/arduino_secrets.h @@ -0,0 +1,12 @@ +// NB settings +#define SECRET_PINNUMBER "" + +// Fill in the hostname of your AWS IoT broker +#define SECRET_BROKER "xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com" + +// Fill in the boards public certificate +const char SECRET_CERTIFICATE[] = R"( +-----BEGIN CERTIFICATE----- + +-----END CERTIFICATE----- +)"; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/AWS_IoT_WiFi.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/AWS_IoT_WiFi.ino new file mode 100644 index 00000000..f283b0db --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/AWS_IoT_WiFi.ino @@ -0,0 +1,157 @@ +/* + AWS IoT WiFi + + This sketch securely connects to an AWS IoT using MQTT over WiFi. + It uses a private key stored in the ATECC508A and a public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to arduino/outgoing + topic and subscribes to messages on the arduino/incoming + topic. + + The circuit: + - Arduino MKR WiFi 1010 or MKR1000 + + The following tutorial on Arduino Project Hub can be used + to setup your AWS account and the MKR board: + + https://create.arduino.cc/projecthub/132016/securely-connecting-an-arduino-mkr-wifi-1010-to-aws-iot-core-a9f365 + + This example code is in the public domain. +*/ + +#include +#include +#include +#include // change to #include for MKR1000 + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char ssid[] = SECRET_SSID; +const char pass[] = SECRET_PASS; +const char broker[] = SECRET_BROKER; +const char* certificate = SECRET_CERTIFICATE; + +WiFiClient wifiClient; // Used for the TCP socket connection +BearSSLClient sslClient(wifiClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(115200); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, certificate); + + // Optional, set the client id used for MQTT, + // each device that is connected to the broker + // must have a unique client id. The MQTTClient will generate + // a client id for you based on the millis() value if not set + // + // mqttClient.setId("clientId"); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (WiFi.status() != WL_CONNECTED) { + connectWiFi(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void connectWiFi() { + Serial.print("Attempting to connect to SSID: "); + Serial.print(ssid); + Serial.print(" "); + + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("arduino/incoming"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("arduino/outgoing"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/arduino_secrets.h new file mode 100644 index 00000000..c89feb07 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/AWS IoT/AWS_IoT_WiFi/arduino_secrets.h @@ -0,0 +1,13 @@ +// Fill in your WiFi networks SSID and password +#define SECRET_SSID "" +#define SECRET_PASS "" + +// Fill in the hostname of your AWS IoT broker +#define SECRET_BROKER "xxxxxxxxxxxxxx.iot.xx-xxxx-x.amazonaws.com" + +// Fill in the boards public certificate +const char SECRET_CERTIFICATE[] = R"( +-----BEGIN CERTIFICATE----- + +-----END CERTIFICATE----- +)"; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/Azure_IoT_Hub_GSM.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/Azure_IoT_Hub_GSM.ino new file mode 100644 index 00000000..05387f3b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/Azure_IoT_Hub_GSM.ino @@ -0,0 +1,171 @@ +/* + Azure IoT Hub GSM + + This sketch securely connects to an Azure IoT Hub using MQTT over GSM/3G. + It uses a private key stored in the ATECC508A and a self signed public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to "devices/{deviceId}/messages/events/" topic + and subscribes to messages on the "devices/{deviceId}/messages/devicebound/#" + topic. + + The circuit: + - MKR GSM 1400 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char gprs_apn[] = SECRET_GPRS_APN; +const char gprs_login[] = SECRET_GPRS_LOGIN; +const char gprs_password[] = SECRET_GPRS_PASSWORD; +const char broker[] = SECRET_BROKER; +String deviceId = SECRET_DEVICE_ID; + +GSM gsmAccess; +GPRS gprs; + +GSMClient gsmClient; // Used for the TCP socket connection +BearSSLClient sslClient(gsmClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // reconstruct the self signed cert + ECCX08SelfSignedCert.beginReconstruction(0, 8); + ECCX08SelfSignedCert.setCommonName(ECCX08.serialNumber()); + ECCX08SelfSignedCert.endReconstruction(); + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, ECCX08SelfSignedCert.bytes(), ECCX08SelfSignedCert.length()); + + // Set the client id used for MQTT as the device id + mqttClient.setId(deviceId); + + // Set the username to "//api-version=2018-06-30" and empty password + String username; + + username += broker; + username += "/"; + username += deviceId; + username += "/api-version=2018-06-30"; + + mqttClient.setUsernamePassword(username, ""); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (gsmAccess.status() != GSM_READY || gprs.status() != GPRS_READY) { + connectGSM(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the cellular module + return gsmAccess.getTime(); +} + +void connectGSM() { + Serial.println("Attempting to connect to the cellular network"); + + while ((gsmAccess.begin(pinnumber) != GSM_READY) || + (gprs.attachGPRS(gprs_apn, gprs_login, gprs_password) != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + Serial.println(mqttClient.connectError()); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/#"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("devices/" + deviceId + "/messages/events/"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/arduino_secrets.h new file mode 100644 index 00000000..753e2dc2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_GSM/arduino_secrets.h @@ -0,0 +1,11 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + +// Fill in the hostname of your Azure IoT Hub broker +#define SECRET_BROKER ".azure-devices.net" + +// Fill in the device id +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/Azure_IoT_Hub_NB.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/Azure_IoT_Hub_NB.ino new file mode 100644 index 00000000..bb6ad888 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/Azure_IoT_Hub_NB.ino @@ -0,0 +1,173 @@ +/* + Azure IoT Hub NB + + This sketch securely connects to an Azure IoT Hub using MQTT over NB IoT/LTE Cat M1. + It uses a private key stored in the ATECC508A and a self signed public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to "devices/{deviceId}/messages/events/" topic + and subscribes to messages on the "devices/{deviceId}/messages/devicebound/#" + topic. + + The circuit: + - MKR NB 1500 board + - Antenna + - SIM card with a data plan + - LiPo battery + + The following tutorial on Arduino Project Hub can be used + to setup your Azure account and the MKR board: + + https://create.arduino.cc/projecthub/Arduino_Genuino/securely-connecting-an-arduino-nb-1500-to-azure-iot-hub-af6470 + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char broker[] = SECRET_BROKER; +String deviceId = SECRET_DEVICE_ID; + +NB nbAccess; +GPRS gprs; + +NBClient nbClient; // Used for the TCP socket connection +BearSSLClient sslClient(nbClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // reconstruct the self signed cert + ECCX08SelfSignedCert.beginReconstruction(0, 8); + ECCX08SelfSignedCert.setCommonName(ECCX08.serialNumber()); + ECCX08SelfSignedCert.endReconstruction(); + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, ECCX08SelfSignedCert.bytes(), ECCX08SelfSignedCert.length()); + + // Set the client id used for MQTT as the device id + mqttClient.setId(deviceId); + + // Set the username to "//api-version=2018-06-30" and empty password + String username; + + username += broker; + username += "/"; + username += deviceId; + username += "/api-version=2018-06-30"; + + mqttClient.setUsernamePassword(username, ""); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (nbAccess.status() != NB_READY || gprs.status() != GPRS_READY) { + connectNB(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the cellular module + return nbAccess.getTime(); +} + +void connectNB() { + Serial.println("Attempting to connect to the cellular network"); + + while ((nbAccess.begin(pinnumber) != NB_READY) || + (gprs.attachGPRS() != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + Serial.println(mqttClient.connectError()); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/#"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("devices/" + deviceId + "/messages/events/"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/arduino_secrets.h new file mode 100644 index 00000000..ff0f78ae --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_NB/arduino_secrets.h @@ -0,0 +1,8 @@ +// NB settings +#define SECRET_PINNUMBER "" + +// Fill in the hostname of your Azure IoT Hub broker +#define SECRET_BROKER ".azure-devices.net" + +// Fill in the device id +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/Azure_IoT_Hub_WiFi.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/Azure_IoT_Hub_WiFi.ino new file mode 100644 index 00000000..7dc9c353 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/Azure_IoT_Hub_WiFi.ino @@ -0,0 +1,165 @@ +/* + Azure IoT Hub WiFi + + This sketch securely connects to an Azure IoT Hub using MQTT over WiFi. + It uses a private key stored in the ATECC508A and a self signed public + certificate for SSL/TLS authetication. + + It publishes a message every 5 seconds to "devices/{deviceId}/messages/events/" topic + and subscribes to messages on the "devices/{deviceId}/messages/devicebound/#" + topic. + + The circuit: + - Arduino MKR WiFi 1010 or MKR1000 + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include // change to #include for MKR1000 + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char ssid[] = SECRET_SSID; +const char pass[] = SECRET_PASS; +const char broker[] = SECRET_BROKER; +String deviceId = SECRET_DEVICE_ID; + +WiFiClient wifiClient; // Used for the TCP socket connection +BearSSLClient sslClient(wifiClient); // Used for SSL/TLS connection, integrates with ECC508 +MqttClient mqttClient(sslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // reconstruct the self signed cert + ECCX08SelfSignedCert.beginReconstruction(0, 8); + ECCX08SelfSignedCert.setCommonName(ECCX08.serialNumber()); + ECCX08SelfSignedCert.endReconstruction(); + + // Set a callback to get the current time + // used to validate the servers certificate + ArduinoBearSSL.onGetTime(getTime); + + // Set the ECCX08 slot to use for the private key + // and the accompanying public certificate for it + sslClient.setEccSlot(0, ECCX08SelfSignedCert.bytes(), ECCX08SelfSignedCert.length()); + + // Set the client id used for MQTT as the device id + mqttClient.setId(deviceId); + + // Set the username to "//api-version=2018-06-30" and empty password + String username; + + username += broker; + username += "/"; + username += deviceId; + username += "/api-version=2018-06-30"; + + mqttClient.setUsernamePassword(username, ""); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (WiFi.status() != WL_CONNECTED) { + connectWiFi(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void connectWiFi() { + Serial.print("Attempting to connect to SSID: "); + Serial.print(ssid); + Serial.print(" "); + + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + Serial.println(mqttClient.connectError()); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to a topic + mqttClient.subscribe("devices/" + deviceId + "/messages/devicebound/#"); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("devices/" + deviceId + "/messages/events/"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/arduino_secrets.h new file mode 100644 index 00000000..71d56443 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Azure IoT Hub/Azure_IoT_Hub_WiFi/arduino_secrets.h @@ -0,0 +1,9 @@ +// Fill in your WiFi networks SSID and password +#define SECRET_SSID "" +#define SECRET_PASS "" + +// Fill in the hostname of your Azure IoT Hub broker +#define SECRET_BROKER ".azure-devices.net" + +// Fill in the device id +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/GCP_IoT_Core_GSM.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/GCP_IoT_Core_GSM.ino new file mode 100644 index 00000000..f9b5fda8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/GCP_IoT_Core_GSM.ino @@ -0,0 +1,199 @@ +/* + GCP (Google Cloud Platform) IoT Core GSM + + This sketch securely connects to GCP IoT Core using MQTT over GSM/3G. + It uses a private key stored in the ATECC508A and a JSON Web Token (JWT) with + a JSON Web Signature (JWS). + + It publishes a message every 5 seconds to "/devices/{deviceId}/state" topic + and subscribes to messages on the "/devices/{deviceId}/config" and + "/devices/{deviceId}/commands/#" topics. + + The circuit: + - MKR GSM 1400 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; +const char gprs_apn[] = SECRET_GPRS_APN; +const char gprs_login[] = SECRET_GPRS_LOGIN; +const char gprs_password[] = SECRET_GPRS_PASSWORD; + +const char projectId[] = SECRET_PROJECT_ID; +const char cloudRegion[] = SECRET_CLOUD_REGION; +const char registryId[] = SECRET_REGISTRY_ID; +const String deviceId = SECRET_DEVICE_ID; + +const char broker[] = "mqtt.googleapis.com"; + +GSM gsmAccess; +GPRS gprs; + +GSMSSLClient gsmSslClient; +MqttClient mqttClient(gsmSslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // Calculate and set the client id used for MQTT + String clientId = calculateClientId(); + + mqttClient.setId(clientId); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (gsmAccess.status() != GSM_READY || gprs.status() != GPRS_READY) { + connectGSM(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the cellular module + return gsmAccess.getTime(); +} + +void connectGSM() { + Serial.println("Attempting to connect to the cellular network"); + + while ((gsmAccess.begin(pinnumber) != GSM_READY) || + (gprs.attachGPRS(gprs_apn, gprs_login, gprs_password) != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to connect to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connected()) { + // Calculate the JWT and assign it as the password + String jwt = calculateJWT(); + + mqttClient.setUsernamePassword("", jwt); + + if (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to topics + mqttClient.subscribe("/devices/" + deviceId + "/config", 1); + mqttClient.subscribe("/devices/" + deviceId + "/commands/#"); +} + +String calculateClientId() { + String clientId; + + // Format: + // + // projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id} + // + + clientId += "projects/"; + clientId += projectId; + clientId += "/locations/"; + clientId += cloudRegion; + clientId += "/registries/"; + clientId += registryId; + clientId += "/devices/"; + clientId += deviceId; + + return clientId; +} + +String calculateJWT() { + unsigned long now = getTime(); + + // calculate the JWT, based on: + // https://cloud.google.com/iot/docs/how-tos/credentials/jwts + JSONVar jwtHeader; + JSONVar jwtClaim; + + jwtHeader["alg"] = "ES256"; + jwtHeader["typ"] = "JWT"; + + jwtClaim["aud"] = projectId; + jwtClaim["iat"] = now; + jwtClaim["exp"] = now + (24L * 60L * 60L); // expires in 24 hours + + return ECCX08JWS.sign(0, JSON.stringify(jwtHeader), JSON.stringify(jwtClaim)); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("/devices/" + deviceId + "/state"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/arduino_secrets.h new file mode 100644 index 00000000..4ec82da2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_GSM/arduino_secrets.h @@ -0,0 +1,11 @@ +// GSM settings +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace with your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password + +// Fill in your Google Cloud Platform - IoT Core info +#define SECRET_PROJECT_ID "" +#define SECRET_CLOUD_REGION "" +#define SECRET_REGISTRY_ID "" +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/GCP_IoT_Core_NB.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/GCP_IoT_Core_NB.ino new file mode 100644 index 00000000..f6c64062 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/GCP_IoT_Core_NB.ino @@ -0,0 +1,196 @@ +/* + GCP (Google Cloud Platform) IoT Core NB + + This sketch securely connects to GCP IoT Core using MQTT over NB IoT/LTE Cat M1. + It uses a private key stored in the ATECC508A and a JSON Web Token (JWT) with + a JSON Web Signature (JWS). + + It publishes a message every 5 seconds to "/devices/{deviceId}/state" topic + and subscribes to messages on the "/devices/{deviceId}/config" and + "/devices/{deviceId}/commands/#" topics. + + The circuit: + - MKR NB 1500 board + - Antenna + - SIM card with a data plan + - LiPo battery + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char pinnumber[] = SECRET_PINNUMBER; + +const char projectId[] = SECRET_PROJECT_ID; +const char cloudRegion[] = SECRET_CLOUD_REGION; +const char registryId[] = SECRET_REGISTRY_ID; +const String deviceId = SECRET_DEVICE_ID; + +const char broker[] = "mqtt.googleapis.com"; + +NB nbAccess; +GPRS gprs; + +NBSSLClient nbSslClient; +MqttClient mqttClient(nbSslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // Calculate and set the client id used for MQTT + String clientId = calculateClientId(); + + mqttClient.setId(clientId); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (nbAccess.status() != NB_READY || gprs.status() != GPRS_READY) { + connectNB(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the cellular module + return nbAccess.getTime(); +} + +void connectNB() { + Serial.println("Attempting to connect to the cellular network"); + + while ((nbAccess.begin(pinnumber) != NB_READY) || + (gprs.attachGPRS() != GPRS_READY)) { + // failed, retry + Serial.print("."); + delay(1000); + } + + Serial.println("You're connected to the cellular network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to connect to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connected()) { + // Calculate the JWT and assign it as the password + String jwt = calculateJWT(); + + mqttClient.setUsernamePassword("", jwt); + + if (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to topics + mqttClient.subscribe("/devices/" + deviceId + "/config", 1); + mqttClient.subscribe("/devices/" + deviceId + "/commands/#"); +} + +String calculateClientId() { + String clientId; + + // Format: + // + // projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id} + // + + clientId += "projects/"; + clientId += projectId; + clientId += "/locations/"; + clientId += cloudRegion; + clientId += "/registries/"; + clientId += registryId; + clientId += "/devices/"; + clientId += deviceId; + + return clientId; +} + +String calculateJWT() { + unsigned long now = getTime(); + + // calculate the JWT, based on: + // https://cloud.google.com/iot/docs/how-tos/credentials/jwts + JSONVar jwtHeader; + JSONVar jwtClaim; + + jwtHeader["alg"] = "ES256"; + jwtHeader["typ"] = "JWT"; + + jwtClaim["aud"] = projectId; + jwtClaim["iat"] = now; + jwtClaim["exp"] = now + (24L * 60L * 60L); // expires in 24 hours + + return ECCX08JWS.sign(0, JSON.stringify(jwtHeader), JSON.stringify(jwtClaim)); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("/devices/" + deviceId + "/state"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/arduino_secrets.h new file mode 100644 index 00000000..d00469c2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_NB/arduino_secrets.h @@ -0,0 +1,8 @@ +// NB settings +#define SECRET_PINNUMBER "" + +// Fill in your Google Cloud Platform - IoT Core info +#define SECRET_PROJECT_ID "" +#define SECRET_CLOUD_REGION "" +#define SECRET_REGISTRY_ID "" +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/GCP_IoT_Core_WiFi.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/GCP_IoT_Core_WiFi.ino new file mode 100644 index 00000000..212ac2e0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/GCP_IoT_Core_WiFi.ino @@ -0,0 +1,193 @@ +/* + GCP (Google Cloud Platform) IoT Core WiFi + + This sketch securely connects to GCP IoT Core using MQTT over WiFi. + It uses a private key stored in the ATECC508A and a JSON Web Token (JWT) with + a JSON Web Signature (JWS). + + It publishes a message every 5 seconds to "/devices/{deviceId}/state" topic + and subscribes to messages on the "/devices/{deviceId}/config" and + "/devices/{deviceId}/commands/#" topics. + + The circuit: + - Arduino MKR WiFi 1010 or MKR1000 + + This example code is in the public domain. +*/ + +#include +#include +#include +#include +#include // change to #include for MKR1000 + +#include "arduino_secrets.h" + +/////// Enter your sensitive data in arduino_secrets.h +const char ssid[] = SECRET_SSID; +const char pass[] = SECRET_PASS; + +const char projectId[] = SECRET_PROJECT_ID; +const char cloudRegion[] = SECRET_CLOUD_REGION; +const char registryId[] = SECRET_REGISTRY_ID; +const String deviceId = SECRET_DEVICE_ID; + +const char broker[] = "mqtt.googleapis.com"; + +WiFiSSLClient wifiSslClient; +MqttClient mqttClient(wifiSslClient); + +unsigned long lastMillis = 0; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!ECCX08.begin()) { + Serial.println("No ECCX08 present!"); + while (1); + } + + // Calculate and set the client id used for MQTT + String clientId = calculateClientId(); + + mqttClient.setId(clientId); + + // Set the message callback, this function is + // called when the MQTTClient receives a message + mqttClient.onMessage(onMessageReceived); +} + +void loop() { + if (WiFi.status() != WL_CONNECTED) { + connectWiFi(); + } + + if (!mqttClient.connected()) { + // MQTT client is disconnected, connect + connectMQTT(); + } + + // poll for new MQTT messages and send keep alives + mqttClient.poll(); + + // publish a message roughly every 5 seconds. + if (millis() - lastMillis > 5000) { + lastMillis = millis(); + + publishMessage(); + } +} + +unsigned long getTime() { + // get the current time from the WiFi module + return WiFi.getTime(); +} + +void connectWiFi() { + Serial.print("Attempting to connect to SSID: "); + Serial.print(ssid); + Serial.print(" "); + + while (WiFi.begin(ssid, pass) != WL_CONNECTED) { + // failed, retry + Serial.print("."); + delay(5000); + } + Serial.println(); + + Serial.println("You're connected to the network"); + Serial.println(); +} + +void connectMQTT() { + Serial.print("Attempting to connect to MQTT broker: "); + Serial.print(broker); + Serial.println(" "); + + while (!mqttClient.connected()) { + // Calculate the JWT and assign it as the password + String jwt = calculateJWT(); + + mqttClient.setUsernamePassword("", jwt); + + if (!mqttClient.connect(broker, 8883)) { + // failed, retry + Serial.print("."); + delay(5000); + } + } + Serial.println(); + + Serial.println("You're connected to the MQTT broker"); + Serial.println(); + + // subscribe to topics + mqttClient.subscribe("/devices/" + deviceId + "/config", 1); + mqttClient.subscribe("/devices/" + deviceId + "/commands/#"); +} + +String calculateClientId() { + String clientId; + + // Format: + // + // projects/{project-id}/locations/{cloud-region}/registries/{registry-id}/devices/{device-id} + // + + clientId += "projects/"; + clientId += projectId; + clientId += "/locations/"; + clientId += cloudRegion; + clientId += "/registries/"; + clientId += registryId; + clientId += "/devices/"; + clientId += deviceId; + + return clientId; +} + +String calculateJWT() { + unsigned long now = getTime(); + + // calculate the JWT, based on: + // https://cloud.google.com/iot/docs/how-tos/credentials/jwts + JSONVar jwtHeader; + JSONVar jwtClaim; + + jwtHeader["alg"] = "ES256"; + jwtHeader["typ"] = "JWT"; + + jwtClaim["aud"] = projectId; + jwtClaim["iat"] = now; + jwtClaim["exp"] = now + (24L * 60L * 60L); // expires in 24 hours + + return ECCX08JWS.sign(0, JSON.stringify(jwtHeader), JSON.stringify(jwtClaim)); +} + +void publishMessage() { + Serial.println("Publishing message"); + + // send message, the Print interface can be used to set the message contents + mqttClient.beginMessage("/devices/" + deviceId + "/state"); + mqttClient.print("hello "); + mqttClient.print(millis()); + mqttClient.endMessage(); +} + +void onMessageReceived(int messageSize) { + // we received a message, print out the topic and contents + Serial.print("Received a message with topic '"); + Serial.print(mqttClient.messageTopic()); + Serial.print("', length "); + Serial.print(messageSize); + Serial.println(" bytes:"); + + // use the Stream interface to print the contents + while (mqttClient.available()) { + Serial.print((char)mqttClient.read()); + } + Serial.println(); + + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/arduino_secrets.h new file mode 100644 index 00000000..da516682 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCloudProviderExamples/examples/Google Cloud Platform IoT Core/GCP_IoT_Core_WiFi/arduino_secrets.h @@ -0,0 +1,9 @@ +// Fill in your WiFi networks SSID and password +#define SECRET_SSID "" +#define SECRET_PASS "" + +// Fill in your Google Cloud Platform - IoT Core info +#define SECRET_PROJECT_ID "" +#define SECRET_CLOUD_REGION "" +#define SECRET_REGISTRY_ID "" +#define SECRET_DEVICE_ID "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/README.md new file mode 100644 index 00000000..42a1f043 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/README.md @@ -0,0 +1,8 @@ +# Arduino AVR Boards + +[![Check Arduino status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/check-arduino.yml) +[![Compile Examples status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/compile-platform-examples.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/compile-platform-examples.yml) +[![Spell Check status](https://github.com/arduino/ArduinoCore-avr/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino/ArduinoCore-avr/actions/workflows/spell-check.yml) + +This repository contains the source code and configuration files of the Arduino AVR Boards +[platform](https://arduino.github.io/arduino-cli/latest/platform-specification/). diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/README.md new file mode 100644 index 00000000..9ca761d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/README.md @@ -0,0 +1,139 @@ +## **EEPROM Library V2.0** for Arduino + +**Written by:** _Christopher Andrews_. + +### **What is the EEPROM library.** + +Th EEPROM library provides an easy to use interface to interact with the internal non-volatile storage found in AVR based Arduino boards. This library will work on many AVR devices like ATtiny and ATmega chips. + +### **How to use it** +The EEPROM library is included in your IDE download. To add its functionality to your sketch you'll need to reference the library header file. You do this by adding an include directive to the top of your sketch. + +```Arduino +#include + +void setup(){ + +} + +void loop(){ + +} + +``` + +The library provides a global variable named `EEPROM`, you use this variable to access the library functions. The methods provided in the EEPROM class are listed below. + +You can view all the examples [here](examples/). + +### **Library functions** + +#### **`EEPROM.read( address )`** [[_example_]](examples/eeprom_read/eeprom_read.ino) + +This function allows you to read a single byte of data from the eeprom. +Its only parameter is an `int` which should be set to the address you wish to read. + +The function returns an `unsigned char` containing the value read. + +#### **`EEPROM.write( address, value )`** [[_example_]](examples/eeprom_write/eeprom_write.ino) + +The `write()` method allows you to write a single byte of data to the EEPROM. +Two parameters are needed. The first is an `int` containing the address that is to be written, and the second is a the data to be written (`unsigned char`). + +This function does not return any value. + +#### **`EEPROM.update( address, value )`** [[_example_]](examples/eeprom_update/eeprom_update.ino) + +This function is similar to `EEPROM.write()` however this method will only write data if the cell contents pointed to by `address` is different to `value`. This method can help prevent unnecessary wear on the EEPROM cells. + +This function does not return any value. + +#### **`EEPROM.get( address, object )`** [[_example_]](examples/eeprom_get/eeprom_get.ino) + +This function will retrieve any object from the EEPROM. +Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to read. + +This function returns a reference to the `object` passed in. It does not need to be used and is only returned for convenience. + +#### **`EEPROM.put( address, object )`** [[_example_]](examples/eeprom_put/eeprom_put.ino) + +This function will write any object to the EEPROM. +Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to write. + +This function uses the _update_ method to write its data, and therefore only rewrites changed cells. + +This function returns a reference to the `object` passed in. It does not need to be used and is only returned for convenience. + +#### **Subscript operator: `EEPROM[address]`** [[_example_]](examples/eeprom_crc/eeprom_crc.ino) + +This operator allows using the identifier `EEPROM` like an array. +EEPROM cells can be read _and_ **_written_** directly using this method. + +This operator returns a reference to the EEPROM cell. + +```c++ +unsigned char val; + +//Read first EEPROM cell. +val = EEPROM[ 0 ]; + +//Write first EEPROM cell. +EEPROM[ 0 ] = val; + +//Compare contents +if( val == EEPROM[ 0 ] ){ + //Do something... +} +``` + +#### **`EEPROM.length()`** + +This function returns an `unsigned int` containing the number of cells in the EEPROM. + +--- + +### **Advanced features** + +This library uses a component based approach to provide its functionality. This means you can also use these components to design a customized approach. Two background classes are available for use: `EERef` & `EEPtr`. + +#### **`EERef` class** + +This object references an EEPROM cell. +Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM. +This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell. + +```C++ +EERef ref = EEPROM[ 10 ]; //Create a reference to 11th cell. + +ref = 4; //write to EEPROM cell. + +unsigned char val = ref; //Read referenced cell. +``` + +#### **`EEPtr` class** + +This object is a bidirectional pointer to EEPROM cells represented by `EERef` objects. +Just like a normal pointer type, this type can be dereferenced and repositioned using +increment/decrement operators. + +```C++ +EEPtr ptr = 10; //Create a pointer to 11th cell. + +*ptr = 4; //dereference and write to EEPROM cell. + +unsigned char val = *ptr; //dereference and read. + +ptr++; //Move to next EEPROM cell. +``` + +#### **`EEPROM.begin()`** + +This function returns an `EEPtr` pointing to the first cell in the EEPROM. +This is useful for STL objects, custom iteration and C++11 style ranged for loops. + +#### **`EEPROM.end()`** + +This function returns an `EEPtr` pointing at the location after the last EEPROM cell. +Used with `begin()` to provide custom iteration. + +**Note:** The `EEPtr` returned is invalid as it is out of range. In fact the hardware causes wrapping of the address (overflow) and `EEPROM.end()` actually references the first EEPROM cell. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino new file mode 100644 index 00000000..3fed10fb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino @@ -0,0 +1,39 @@ +/* + * EEPROM Clear + * + * Sets all of the bytes of the EEPROM to 0. + * Please see eeprom_iteration for a more in depth + * look at how to traverse the EEPROM. + * + * This example code is in the public domain. + */ + +#include + +void setup() { + // initialize the LED pin as an output. + pinMode(13, OUTPUT); + + /*** + Iterate through each byte of the EEPROM storage. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduino Duemilanove: 512 B EEPROM storage. + - Arduino Uno: 1 kB EEPROM storage. + - Arduino Mega: 4 kB EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + + for (int i = 0 ; i < EEPROM.length() ; i++) { + EEPROM.write(i, 0); + } + + // turn the LED on when we're done + digitalWrite(13, HIGH); +} + +void loop() { + /** Empty loop. **/ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino new file mode 100644 index 00000000..c6db85c3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino @@ -0,0 +1,52 @@ +/*** + Written by Christopher Andrews. + CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). + + A CRC is a simple way of checking whether data has changed or become corrupted. + This example calculates a CRC value directly on the EEPROM values. + The purpose of this example is to highlight how the EEPROM object can be used just like an array. +***/ + +#include +#include + +void setup() { + + //Start serial + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + //Print length of data to run CRC on. + Serial.print("EEPROM length: "); + Serial.println(EEPROM.length()); + + //Print the result of calling eeprom_crc() + Serial.print("CRC32 of EEPROM data: 0x"); + Serial.println(eeprom_crc(), HEX); + Serial.print("\n\nDone!"); +} + +void loop() { + /* Empty loop */ +} + +unsigned long eeprom_crc(void) { + + const unsigned long crc_table[16] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, + 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, + 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c + }; + + unsigned long crc = ~0L; + + for (int index = 0 ; index < EEPROM.length() ; ++index) { + crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4); + crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4); + crc = ~crc; + } + return crc; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino new file mode 100644 index 00000000..a07cee7c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino @@ -0,0 +1,68 @@ +/*** + eeprom_get example. + + This shows how to use the EEPROM.get() method. + + To pre-set the EEPROM data, run the example sketch eeprom_put. + This sketch will run without it, however, the values shown + will be shown from what ever is already on the EEPROM. + + This may cause the serial object to print out a large string + of garbage if there is no null character inside one of the strings + loaded. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + float f = 0.00f; //Variable to store data read from EEPROM. + int eeAddress = 0; //EEPROM address to start reading from + + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.print("Read float from EEPROM: "); + + //Get the float data from the EEPROM at position 'eeAddress' + EEPROM.get(eeAddress, f); + Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. + + /*** + As get also returns a reference to 'f', you can use it inline. + E.g: Serial.print( EEPROM.get( eeAddress, f ) ); + ***/ + + /*** + Get can be used with custom structures too. + I have separated this into an extra function. + ***/ + + secondTest(); //Run the next test. +} + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +void secondTest() { + int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. + + MyObject customVar; //Variable to store custom object read from EEPROM. + EEPROM.get(eeAddress, customVar); + + Serial.println("Read custom object from EEPROM: "); + Serial.println(customVar.field1); + Serial.println(customVar.field2); + Serial.println(customVar.name); +} + +void loop() { + /* Empty loop */ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino new file mode 100644 index 00000000..b5d68bee --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -0,0 +1,57 @@ +/*** + eeprom_iteration example. + + A set of example snippets highlighting the + simplest methods for traversing the EEPROM. + + Running this sketch is not necessary, this is + simply highlighting certain programming methods. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + /*** + Iterate the EEPROM using a for loop. + ***/ + + for (int index = 0 ; index < EEPROM.length() ; index++) { + + //Add one to each cell in the EEPROM + EEPROM[ index ] += 1; + } + + /*** + Iterate the EEPROM using a while loop. + ***/ + + int index = 0; + + while (index < EEPROM.length()) { + + //Add one to each cell in the EEPROM + EEPROM[ index ] += 1; + index++; + } + + /*** + Iterate the EEPROM using a do-while loop. + ***/ + + int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. + + do { + + //Add one to each cell in the EEPROM + EEPROM[ idx ] += 1; + idx++; + } while (idx < EEPROM.length()); + + +} //End of setup function. + +void loop() {} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino new file mode 100644 index 00000000..c1ba0a57 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino @@ -0,0 +1,58 @@ +/*** + eeprom_put example. + + This shows how to use the EEPROM.put() method. + Also, this sketch will pre-set the EEPROM data for the + example sketch eeprom_get. + + Note, unlike the single byte version EEPROM.write(), + the put method will use update semantics. As in a byte + will only be written to the EEPROM if the data is actually + different. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +void setup() { + + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + float f = 123.456f; //Variable to store in EEPROM. + int eeAddress = 0; //Location we want the data to be put. + + + //One simple call, with the address first and the object second. + EEPROM.put(eeAddress, f); + + Serial.println("Written float data type!"); + + /** Put is designed for use with custom structures also. **/ + + //Data to store. + MyObject customVar = { + 3.14f, + 65, + "Working!" + }; + + eeAddress += sizeof(float); //Move address to the next byte after float 'f'. + + EEPROM.put(eeAddress, customVar); + Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); +} + +void loop() { + /* Empty loop */ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino new file mode 100644 index 00000000..d4650358 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @@ -0,0 +1,56 @@ +/* + * EEPROM Read + * + * Reads the value of each byte of the EEPROM and prints it + * to the computer. + * This example code is in the public domain. + */ + +#include + +// start reading from the first byte (address 0) of the EEPROM +int address = 0; +byte value; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } +} + +void loop() { + // read a byte from the current address of the EEPROM + value = EEPROM.read(address); + + Serial.print(address); + Serial.print("\t"); + Serial.print(value, DEC); + Serial.println(); + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduino Duemilanove: 512 B EEPROM storage. + - Arduino Uno: 1 kB EEPROM storage. + - Arduino Mega: 4 kB EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + address = address + 1; + if (address == EEPROM.length()) { + address = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++address &= EEPROM.length() - 1; + ***/ + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino new file mode 100644 index 00000000..f5b0c0c7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino @@ -0,0 +1,71 @@ +/*** + EEPROM Update method + + Stores values read from analog input 0 into the EEPROM. + These values will stay in the EEPROM when the board is + turned off and may be retrieved later by another sketch. + + If a value has not changed in the EEPROM, it is not overwritten + which would reduce the life span of the EEPROM unnecessarily. + + Released using MIT licence. + ***/ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int address = 0; + +void setup() { + /** Empty setup **/ +} + +void loop() { + /*** + need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + int val = analogRead(0) / 4; + + /*** + Update the particular EEPROM cell. + these values will remain there when the board is + turned off. + ***/ + EEPROM.update(address, val); + + /*** + The function EEPROM.update(address, val) is equivalent to the following: + + if( EEPROM.read(address) != val ){ + EEPROM.write(address, val); + } + ***/ + + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduino Duemilanove: 512 B EEPROM storage. + - Arduino Uno: 1 kB EEPROM storage. + - Arduino Mega: 4 kB EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + address = address + 1; + if (address == EEPROM.length()) { + address = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++address &= EEPROM.length() - 1; + ***/ + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino new file mode 100644 index 00000000..64e835cd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino @@ -0,0 +1,60 @@ +/* + * EEPROM Write + * + * Stores values read from analog input 0 into the EEPROM. + * These values will stay in the EEPROM when the board is + * turned off and may be retrieved later by another sketch. + */ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int addr = 0; + +void setup() { + /** Empty setup. **/ +} + +void loop() { + /*** + Need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + + int val = analogRead(0) / 4; + + /*** + Write the value to the appropriate byte of the EEPROM. + these values will remain there when the board is + turned off. + ***/ + + EEPROM.write(addr, val); + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduino Duemilanove: 512 B EEPROM storage. + - Arduino Uno: 1 kB EEPROM storage. + - Arduino Mega: 4 kB EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + addr = addr + 1; + if (addr == EEPROM.length()) { + addr = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++addr &= EEPROM.length() - 1; + ***/ + + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino new file mode 100644 index 00000000..1b8ad701 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -0,0 +1,142 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + */ + +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initialize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 00000000..39e5bf92 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -0,0 +1,73 @@ +/* + Digital Pot Control + + This example controls an Analog Devices AD5206 digital potentiometer. + The AD5206 has 6 potentiometer channels. Each channel's pins are labeled + A - connect this to voltage + W - this is the pot's wiper, which changes when you set it + B - connect this to ground. + + The AD5206 is SPI-compatible,and to command it, you send two bytes, + one with the channel number (0 - 5) and one with the resistance value for the + channel (0 - 255). + + The circuit: + * All A pins of AD5206 connected to +5V + * All B pins of AD5206 connected to ground + * An LED and a 220-ohm resistor in series connected from each W pin to ground + * CS - to digital pin 10 (SS pin) + * SDI - to digital pin 11 (MOSI pin) + * CLK - to digital pin 13 (SCK pin) + + created 10 Aug 2010 + by Tom Igoe + + Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 + +*/ + + +// include the SPI library: +#include + + +// set pin 10 as the slave select for the digital pot: +const int slaveSelectPin = 10; + +void setup() { + // set the slaveSelectPin as an output: + pinMode(slaveSelectPin, OUTPUT); + // initialize SPI: + SPI.begin(); +} + +void loop() { + // go through the six channels of the digital pot: + for (int channel = 0; channel < 6; channel++) { + // change the resistance on this channel from min to max: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, level); + delay(10); + } + // wait a second at the top: + delay(100); + // change the resistance on this channel from max to min: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, 255 - level); + delay(10); + } + } + +} + +void digitalPotWrite(int address, int value) { + // take the SS pin low to select the chip: + digitalWrite(slaveSelectPin, LOW); + delay(100); + // send in the address and value via SPI: + SPI.transfer(address); + SPI.transfer(value); + delay(100); + // take the SS pin high to de-select the chip: + digitalWrite(slaveSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino new file mode 100644 index 00000000..061bb701 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -0,0 +1,54 @@ +/* + Software serial multiple serial test + + Receives from the hardware serial, sends to software serial. + Receives from software serial, sends to hardware serial. + + The circuit: + * RX is digital pin 10 (connect to TX of other device) + * TX is digital pin 11 (connect to RX of other device) + + Note: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: + 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + + Not all pins on the Leonardo and Micro support change interrupts, + so only the following can be used for RX: + 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). + + created back in the mists of time + modified 25 May 2012 + by Tom Igoe + based on Mikal Hart's example + + This example code is in the public domain. + + */ +#include + +SoftwareSerial mySerial(10, 11); // RX, TX + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(57600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + Serial.println("Goodnight moon!"); + + // set the data rate for the SoftwareSerial port + mySerial.begin(4800); + mySerial.println("Hello, world?"); +} + +void loop() { // run over and over + if (mySerial.available()) { + Serial.write(mySerial.read()); + } + if (Serial.available()) { + mySerial.write(Serial.read()); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino new file mode 100644 index 00000000..d8c064b7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -0,0 +1,85 @@ +/* + Software serial multiple serial test + + Receives from the two software serial ports, + sends to the hardware serial port. + + In order to listen on a software port, you call port.listen(). + When using two software serial ports, you have to switch ports + by listen()ing on each one in turn. Pick a logical time to switch + ports, like the end of an expected transmission, or when the + buffer is empty. This example switches ports when there is nothing + more to read from a port + + The circuit: + Two devices which communicate serially are needed. + * First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX) + * Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX) + + Note: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: + 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + + Not all pins on the Leonardo support change interrupts, + so only the following can be used for RX: + 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). + + created 18 Apr. 2011 + modified 19 March 2016 + by Tom Igoe + based on Mikal Hart's twoPortRXExample + + This example code is in the public domain. + + */ + +#include +// software serial #1: RX = digital pin 10, TX = digital pin 11 +SoftwareSerial portOne(10, 11); + +// software serial #2: RX = digital pin 8, TX = digital pin 9 +// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega +SoftwareSerial portTwo(8, 9); + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + // Start each software serial port + portOne.begin(9600); + portTwo.begin(9600); +} + +void loop() { + // By default, the last initialized port is listening. + // when you want to listen on a port, explicitly select it: + portOne.listen(); + Serial.println("Data from port one:"); + // while there is data coming in, read it + // and send to the hardware serial port: + while (portOne.available() > 0) { + char inByte = portOne.read(); + Serial.write(inByte); + } + + // blank line to separate data from the two ports: + Serial.println(); + + // Now listen on the second port + portTwo.listen(); + // while there is data coming in, read it + // and send to the hardware serial port: + Serial.println("Data from port two:"); + while (portTwo.available() > 0) { + char inByte = portTwo.read(); + Serial.write(inByte); + } + + // blank line to separate data from the two ports: + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino new file mode 100644 index 00000000..aeb1a9c5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -0,0 +1,84 @@ +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// by Nicholas Zambetti +// and James Tichenor + +// Demonstrates use of the Wire library reading data from the +// Devantech Ultrasonic Rangers SFR08 and SFR10 + +// Created 29 April 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join I2C bus (address optional for master) + Serial.begin(9600); // start serial communication at 9600 bps +} + +int reading = 0; + +void loop() { + // step 1: instruct sensor to read echoes + Wire.beginTransmission(112); // transmit to device #112 (0x70) + // the address specified in the datasheet is 224 (0xE0) + // but I2C addressing uses the high 7 bits so it's 112 + Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) + Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds + Wire.endTransmission(); // stop transmitting + + // step 2: wait for readings to happen + delay(70); // datasheet suggests at least 65 milliseconds + + // step 3: instruct sensor to return a particular echo reading + Wire.beginTransmission(112); // transmit to device #112 + Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + + // step 4: request reading from sensor + Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 + + // step 5: receive reading from sensor + if (2 <= Wire.available()) { // if two bytes were received + reading = Wire.read(); // receive high byte (overwrites previous reading) + reading = reading << 8; // shift high byte to be high 8 bits + reading |= Wire.read(); // receive low byte as lower 8 bits + Serial.println(reading); // print the reading + } + + delay(250); // wait a bit since people have to read the output :) +} + + +/* + +// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) +// usage: changeAddress(0x70, 0xE6); + +void changeAddress(byte oldAddress, byte newAddress) +{ + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA0)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xAA)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA5)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(newAddress); + Wire.endTransmission(); +} + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino new file mode 100644 index 00000000..b5da366c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -0,0 +1,33 @@ +// I2C Digital Potentiometer +// by Nicholas Zambetti +// and Shawn Bonkowski + +// Demonstrates use of the Wire library +// Controls AD5171 digital potentiometer via I2C/TWI + +// Created 31 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join I2C bus (address optional for master) +} + +byte val = 0; + +void loop() { + Wire.beginTransmission(44); // transmit to device #44 (0x2c) + // device address is specified in datasheet + Wire.write(byte(0x00)); // sends instruction byte + Wire.write(val); // sends potentiometer value byte + Wire.endTransmission(); // stop transmitting + + val++; // increment value + if (val == 64) { // if reached 64th position (max) + val = 0; // start over from lowest value + } + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino new file mode 100644 index 00000000..295edf7e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/i2c_scanner/i2c_scanner.ino @@ -0,0 +1,75 @@ +// -------------------------------------- +// i2c_scanner +// +// Version 1 +// This program (or code that looks like it) +// can be found in many places. +// For example on the Arduino.cc forum. +// The original author is not known. +// Version 2, Juni 2012, Using Arduino 1.0.1 +// Adapted to be as simple as possible by Arduino.cc user Krodal +// Version 3, Feb 26 2013 +// V3 by louarnold +// Version 4, March 3, 2013, Using Arduino 1.0.3 +// by Arduino.cc user Krodal. +// Changes by louarnold removed. +// Scanning addresses changed from 0...127 to 1...119, +// according to the i2c scanner by Nick Gammon +// https://www.gammon.com.au/forum/?id=10896 +// Version 5, March 28, 2013 +// As version 4, but address scans now to 127. +// A sensor seems to use address 120. +// Version 6, November 27, 2015. +// Added waiting for the Leonardo serial communication. +// +// +// This sketch tests the standard 7-bit addresses +// Devices with higher bit address might not be seen properly. +// + +#include + +void setup() { + Wire.begin(); + + Serial.begin(9600); + while (!Serial); // Leonardo: wait for Serial Monitor + Serial.println("\nI2C Scanner"); +} + +void loop() { + int nDevices = 0; + + Serial.println("Scanning..."); + + for (byte address = 1; address < 127; ++address) { + // The i2c_scanner uses the return value of + // the Wire.endTransmission to see if + // a device did acknowledge to the address. + Wire.beginTransmission(address); + byte error = Wire.endTransmission(); + + if (error == 0) { + Serial.print("I2C device found at address 0x"); + if (address < 16) { + Serial.print("0"); + } + Serial.print(address, HEX); + Serial.println(" !"); + + ++nDevices; + } else if (error == 4) { + Serial.print("Unknown error at address 0x"); + if (address < 16) { + Serial.print("0"); + } + Serial.println(address, HEX); + } + } + if (nDevices == 0) { + Serial.println("No I2C devices found\n"); + } else { + Serial.println("done\n"); + } + delay(5000); // Wait 5 seconds for next scan +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_reader/master_reader.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_reader/master_reader.ino new file mode 100644 index 00000000..e27cac32 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_reader/master_reader.ino @@ -0,0 +1,29 @@ +// Wire Master Reader +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Reads data from an I2C/TWI slave device +// Refer to the "Wire Slave Sender" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join I2C bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() { + Wire.requestFrom(8, 6); // request 6 bytes from slave device #8 + + while (Wire.available()) { // slave may send less than requested + char c = Wire.read(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_writer/master_writer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_writer/master_writer.ino new file mode 100644 index 00000000..7a176687 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/master_writer/master_writer.ino @@ -0,0 +1,29 @@ +// Wire Master Writer +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Writes data to an I2C/TWI slave device +// Refer to the "Wire Slave Receiver" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join I2C bus (address optional for master) +} + +byte x = 0; + +void loop() { + Wire.beginTransmission(8); // transmit to device #8 + Wire.write("x is "); // sends five bytes + Wire.write(x); // sends one byte + Wire.endTransmission(); // stop transmitting + + x++; + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino new file mode 100644 index 00000000..9b3f814f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -0,0 +1,34 @@ +// Wire Slave Receiver +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI slave device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(8); // join I2C bus with address #8 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() { + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) { + while (1 < Wire.available()) { // loop through all but the last + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_sender/slave_sender.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_sender/slave_sender.ino new file mode 100644 index 00000000..6e2ed49d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-avr/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -0,0 +1,29 @@ +// Wire Slave Sender +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Sends data as an I2C/TWI slave device +// Refer to the "Wire Master Reader" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(8); // join I2C bus with address #8 + Wire.onRequest(requestEvent); // register event +} + +void loop() { + delay(100); +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() { + Wire.write("hello "); // respond with message of 6 bytes + // as expected by master +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/README.md new file mode 100644 index 00000000..381bad63 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/README.md @@ -0,0 +1,116 @@ +# Arduino Core for mbed enabled devices + +The repository contains the Arduino APIs and IDE integration files targeting a generic mbed-enabled board + +## FAQ +### Source-Code Level Debugging +**Question**: "I want to debug my ArduinoCore-mbed based sketch using traditional debugging tools, i.e. gdb via SWD interface. However, the debugger is unable to locate the sources for all files, particular the mbed-os files." + +**Answer**: This is due to the fact that we pre-compile the mbed-os code into a static library `libmbed.a`. Information on how to recompile `libmbed.a` for source code debugging can be found [here](#recompiling-libmbed-with-source-level-debug-support). The [Arduino Documentation](https://docs.arduino.cc/) also contains articles explaining how to debug via [Segger J-Link](https://docs.arduino.cc/tutorials/portenta-breakout/breakout-jlink-setup) and [Lauterbach TRACE32](https://docs.arduino.cc/tutorials/portenta-h7/lauterbach-debugger). + +## Installation + +### Clone the repository in `$sketchbook/hardware/arduino-git` + +```bash +mkdir -p $sketchbook/hardware/arduino-git +cd $sketchbook/hardware/arduino-git +git clone git@github.com:arduino/ArduinoCore-mbed mbed +``` + +### Clone https://github.com/arduino/ArduinoCore-API into a directory of your choice. + +```bash +git clone git@github.com:arduino/ArduinoCore-API +``` + +### Update the `api` symlink + +Create a symlink to `ArduinoCore-API/api` in `$sketchbook/hardware/arduino-git/mbed/cores/arduino`. + +### Test things out + +Open the Arduino IDE. + +You should now see three new targets under the `MBED boards` label. + +*This procedure does not automatically install the required ARM compiler toolchain.* + +If the toolchain is missing, you'll see errors like this when you try to build for an mbed-os enabled board.: + +``` +fork/exec /bin/arm-none-eabi-g++: no such file or directory +``` +To install ARM build tools, use the `Boards Manager` option in the Arduino IDE to add the `Arduino mbed-enabled Boards` package. + +## mbed-os-to-arduino script + +The backbone of the packaging process is the https://github.com/arduino/ArduinoCore-mbed/blob/master/mbed-os-to-arduino script. It basically compiles a blank Mbed OS project for any supported target board, recovering the files that will be needed at compile time and copying them to the right location. + +It can be used for a variety of tasks including: + +### Recompiling libmbed with source level debug support + +``` +cd $sketchbook/hardware/arduino-git/mbed +./mbed-os-to-arduino -a -g PORTENTA_H7_M7:PORTENTA_H7_M7 +``` + +In this case `-a` applies all the patches from `patches` folder into a mainline `mbed-os` tree, and `-g` restores the debug info. + +### Selecting a different optimization profile + +``` +cd $sketchbook/hardware/arduino-git/mbed +PROFILE=release ./mbed-os-to-arduino -a NANO_RP2040_CONNECT:NANO_RP2040_CONNECT +``` + +The `PROFILE` environment variable tunes the compilation profiles (defaults to `DEVELOP`). Other available profiles are `DEBUG` and `RELEASE`. + +### Selecting a different Mbed OS tree + +``` +cd $sketchbook/hardware/arduino-git/mbed +./mbed-os-to-arduino -r /path/to/my/mbed-os-fork NICLA_VISION:NICLA_VISION +``` + +`-r` flag allows using a custom `mbed-os` fork in place of the mainline one; useful during new target development. + +### Adding a new target ([core variant](https://arduino.github.io/arduino-cli/latest/platform-specification/#core-variants)) + +Adding a target is a mostly automatic procedure. + +For boards already supported by Mbed OS, the bare minimum is: + +``` +cd $sketchbook/hardware/arduino-git/mbed +mkdir -p variants/$ALREADY_SUPPORTED_BOARD_NAME/{libs,conf} +./mbed-os-to-arduino $ALREADY_SUPPORTED_BOARD_NAME:$ALREADY_SUPPORTED_BOARD_NAME +# for example, to create a core for LPC546XX +# mkdir -p variants/LPC546XX/{libs,conf} +# ./mbed-os-to-arduino LPC546XX:LPC546XX +``` + +This will produce almost all the files needed. To complete the port, add the board specifications to [`boards.txt`](https://arduino.github.io/arduino-cli/latest/platform-specification/#boardstxt) (giving it a unique ID) and provide `pins_arduino.h` and `variants.cpp` in `variants/$ALREADY_SUPPORTED_BOARD_NAME` folder. +Feel free to take inspirations from the existing variants :) + +For boards not supported by mainline Mbed OS, the same applies but you should provide the path of your Mbed OS fork + +``` +cd $sketchbook/hardware/arduino-git/mbed +mkdir -p variants/$BRAND_NEW_BOARD_NAME/{libs,conf} +./mbed-os-to-arduino -r /path/to/mbed-os/fork/that/supports/new/board $BRAND_NEW_BOARD_NAME:$BRAND_NEW_BOARD_NAME +``` + +### Customizing Mbed OS build without modifying the code + +Most Mbed OS defines can be tuned using a project file called `mbed_app.json` . In case you need to tune a build you can add that file to your variant's `conf` folder. One example is https://github.com/arduino/ArduinoCore-mbed/blob/master/variants/PORTENTA_H7_M7/conf/mbed_app.json . +Providing an invalid json or replacing a non-existing property will make the build fail silently, so it's always better to validate that file with a standard Mbed OS project. + + +## Using this core as an mbed library + +You can use this core as a standard mbed library; all APIs are under `arduino` namespace (so they must be called like `arduino::digitalWrite()` ) + +The opposite is working as well; from any sketch you can call mbed APIs by prepending `mbed::` namespace. + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino new file mode 100644 index 00000000..c902ae3e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraCaptureRawBytes/CameraCaptureRawBytes.ino @@ -0,0 +1,65 @@ +#include "camera.h" + +#ifdef ARDUINO_NICLA_VISION + #include "gc2145.h" + GC2145 galaxyCore; + Camera cam(galaxyCore); + #define IMAGE_MODE CAMERA_RGB565 +#else + #include "himax.h" + HM01B0 himax; + Camera cam(himax); + #define IMAGE_MODE CAMERA_GRAYSCALE +#endif + +/* +Other buffer instantiation options: + FrameBuffer fb(0x30000000); + FrameBuffer fb(320,240,2); +*/ +FrameBuffer fb; + +unsigned long lastUpdate = 0; + + +void blinkLED(uint32_t count = 0xFFFFFFFF) +{ + pinMode(LED_BUILTIN, OUTPUT); + while (count--) { + digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level) + delay(50); // wait for a second + digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW + delay(50); // wait for a second + } +} + +void setup() { + // Init the cam QVGA, 30FPS + if (!cam.begin(CAMERA_R320x240, IMAGE_MODE, 30)) { + blinkLED(); + } + + blinkLED(5); +} + +void loop() { + if(!Serial) { + Serial.begin(921600); + while(!Serial); + } + + // Time out after 2 seconds and send new data + bool timeoutDetected = millis() - lastUpdate > 2000; + + // Wait for sync byte. + if(!timeoutDetected && Serial.read() != 1) return; + + lastUpdate = millis(); + + // Grab frame and write to serial + if (cam.grabFrame(fb, 3000) == 0) { + Serial.write(fb.getBuffer(), cam.frameSize()); + } else { + blinkLED(20); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraMotionDetect/CameraMotionDetect.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraMotionDetect/CameraMotionDetect.ino new file mode 100644 index 00000000..c920b0e0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Camera/examples/CameraMotionDetect/CameraMotionDetect.ino @@ -0,0 +1,63 @@ +#include "camera.h" +#include "himax.h" +HM01B0 himax; +Camera cam(himax); + +#ifdef ARDUINO_NICLA_VISION + #error "GalaxyCore camera module does not support Motion Detection" +#endif + +bool motion_detected = false; + +void blinkLED(uint32_t count = 0xFFFFFFFF) +{ + pinMode(LED_BUILTIN, OUTPUT); + while (count--) { + digitalWrite(LED_BUILTIN, LOW); // turn the LED on (HIGH is the voltage level) + delay(50); // wait for a second + digitalWrite(LED_BUILTIN, HIGH); // turn the LED off by making the voltage LOW + delay(50); // wait for a second + } +} + +void on_motion() +{ + motion_detected = true; +} + +void setup() { + Serial.begin(115200); + + pinMode(LEDB, OUTPUT); + digitalWrite(LEDB, HIGH); + + // Init the cam QVGA, 30FPS + if (!cam.begin(CAMERA_R320x240, CAMERA_GRAYSCALE, 30)) { + blinkLED(); + } + + // Set motion detection threshold (0 -> 255). + // The lower the threshold the higher the sensitivity. + cam.setMotionDetectionThreshold(0); + + // Set motion detection window/ROI. + cam.setMotionDetectionWindow(0, 0, 320, 240); + + // The detection can also be enabled without any callback + cam.enableMotionDetection(on_motion); +} + +void loop() { + + if (motion_detected) { + Serial.println("Motion Detected!"); + digitalWrite(LEDB, LOW); + delay(500); + + // Clear the detection flag + cam.motionDetected(); + motion_detected = false; + digitalWrite(LEDB, HIGH); + } + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/README.adoc new file mode 100644 index 00000000..1301ec2e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/README.adoc @@ -0,0 +1,24 @@ += Ethernet Library for Arduino = + +Enable Ethernet connectivity for Arduino Portenta and a shield/carrier with Ethernet connector. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/Ethernet + +== License == + +Copyright (c) 2020 Arduino SA. All right reserved. + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino new file mode 100644 index 00000000..630f2724 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/AdvancedChatServer/AdvancedChatServer.ino @@ -0,0 +1,109 @@ +/* + Advanced Chat Server + + A more advanced server that distributes any incoming messages + to all connected clients but the client the message comes from. + To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + redesigned to make use of operator== 25 Nov 2013 + by Norbert Truchsess + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 255, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); + +EthernetClient clients[8]; + +void setup() { + + // initialize the Ethernet device + Ethernet.begin(ip, myDns, gateway, subnet); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // check for any new client connecting, and say hello (before any incoming data) + EthernetClient newClient = server.available(); + if (newClient) { + for (byte i=0; i < 8; i++) { + if (!clients[i]) { + Serial.print("We have a new client #"); + Serial.println(i); + newClient.print("Hello, client number: "); + newClient.println(i); + // Once we "accept", the client is no longer tracked by EthernetServer + // so we must store it into our list of clients + clients[i] = newClient; + break; + } + } + } + + // check for incoming data from all clients + for (byte i=0; i < 8; i++) { + if (clients[i] && clients[i].available() > 0) { + // read bytes from a client + byte buffer[80]; + int count = clients[i].read(buffer, 80); + // write the bytes to all other connected clients + for (byte j=0; j < 8; j++) { + if (j != i && clients[j].connected()) { + clients[j].write(buffer, count); + } + } + } + } + + // stop any clients which disconnect + for (byte i=0; i < 8; i++) { + if (clients[i] && !clients[i].connected()) { + Serial.print("disconnect client #"); + Serial.println(i); + clients[i].stop(); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino new file mode 100644 index 00000000..6f26ef88 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/BarometricPressureWebServer/BarometricPressureWebServer.ino @@ -0,0 +1,236 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Serves the output of a Barometric Pressure Sensor as a web page. + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + TODO: this hardware is long obsolete. This example program should + be rewritten to use https://www.sparkfun.com/products/9721 + + Circuit: + SCP1000 sensor attached to pins 6,7, and 11 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + by Tom Igoe + */ + +#include +#include +// the sensor communicates using SPI, so include the library: +#include + + +// assign an IP address for the controller: +IPAddress ip(192, 168, 1, 20); + + +// Initialize the Ethernet server library +// with the IP address and port you want to use +// (port 80 is default for HTTP): +EthernetServer server(80); + + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading + +// pins used for the connection with the sensor +// the others you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +float temperature = 0.0; +long pressure = 0; +long lastReadingTime = 0; + +void setup() { + + // start the SPI library: + SPI.begin(); + + // start the Ethernet connection + Ethernet.begin(ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + // initalize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + + // give the sensor and Ethernet shield time to set up: + delay(1000); + + //Set the sensor to high resolution mode tp start readings: + writeRegister(0x03, 0x0A); + +} + +void loop() { + // check for a reading no more than once a second. + if (millis() - lastReadingTime > 1000) { + // if there's a reading ready, read it: + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + getData(); + // timestamp the last time you got a reading: + lastReadingTime = millis(); + } + } + + // listen for incoming Ethernet connections: + listenForEthernetClients(); +} + + +void getData() { + Serial.println("Getting reading"); + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + temperature = (float)tempData / 20.0; + + //Read the pressure data highest 3 bits: + byte pressureDataHigh = readRegister(0x1F, 1); + pressureDataHigh &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressureDataLow = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + pressure = ((pressureDataHigh << 16) | pressureDataLow) / 4; + + Serial.print("Temperature: "); + Serial.print(temperature); + Serial.println(" degrees C"); + Serial.print("Pressure: " + String(pressure)); + Serial.println(" Pa"); +} + +void listenForEthernetClients() { + // listen for incoming clients + EthernetClient client = server.available(); + if (client) { + Serial.println("Got a client"); + // an http request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the http request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println(); + // print the current readings, in HTML format: + client.print("Temperature: "); + client.print(temperature); + client.print(" degrees C"); + client.println("
    "); + client.print("Pressure: " + String(pressure)); + client.print(" Pa"); + client.println("
    "); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + } +} + + +//Send a write command to SCP1000 +void writeRegister(byte registerName, byte registerValue) { + // SCP1000 expects the register name in the upper 6 bits + // of the byte: + registerName <<= 2; + // command (read or write) goes in the lower two bits: + registerName |= 0b00000010; //Write command + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(registerName); //Send register location + SPI.transfer(registerValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} + + +//Read register from the SCP1000: +unsigned int readRegister(byte registerName, int numBytes) { + byte inByte = 0; // incoming from the SPI read + unsigned int result = 0; // result to return + + // SCP1000 expects the register name in the upper 6 bits + // of the byte: + registerName <<= 2; + // command (read or write) goes in the lower two bits: + registerName &= 0b11111100; //Read command + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + int command = SPI.transfer(registerName); + // send a value of 0 to read the first byte returned: + inByte = SPI.transfer(0x00); + + result = inByte; + // if there's more than one byte returned, + // shift the first byte then get the second byte: + if (numBytes > 1) { + result = inByte << 8; + inByte = SPI.transfer(0x00); + result = result | inByte; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/ChatServer/ChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/ChatServer/ChatServer.ino new file mode 100644 index 00000000..bfc310b9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/ChatServer/ChatServer.ino @@ -0,0 +1,97 @@ +/* + Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + + +// telnet defaults to port 23 +EthernetServer server(23); +boolean alreadyConnected = false; // whether or not the client was connected previously + +void setup() { + // You can use Ethernet.init(pin) to configure the CS pin + //Ethernet.init(10); // Most Arduino shields + //Ethernet.init(5); // MKR ETH shield + //Ethernet.init(0); // Teensy 2.0 + //Ethernet.init(20); // Teensy++ 2.0 + //Ethernet.init(15); // ESP8266 with Adafruit Featherwing Ethernet + //Ethernet.init(33); // ESP32 with Adafruit Featherwing Ethernet + + // initialize the ethernet device + Ethernet.begin(ip, myDns, gateway, subnet); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start listening for clients + server.begin(); + + Serial.print("Chat server address:"); + Serial.println(Ethernet.localIP()); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!alreadyConnected) { + // clear out the input buffer: + client.flush(); + Serial.println("We have a new client"); + client.println("Hello, client!"); + alreadyConnected = true; + } + + if (client.available() > 0) { + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.write(thisChar); + } + } +} + + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino new file mode 100644 index 00000000..5cadfe2e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpAddressPrinter/DhcpAddressPrinter.ino @@ -0,0 +1,82 @@ +/* + DHCP-based IP printer + + This sketch uses the DHCP extensions to the Ethernet library + to get an IP address via DHCP and print the address obtained. + using an Arduino Wiznet Ethernet shield. + + Circuit: + Ethernet shield attached to pins 10, 11, 12, 13 + + created 12 April 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include +#include + +void setup() +{ + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // no point in carrying on, so do nothing forevermore: + while (true) { + delay(1); + } + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); +} + +void loop() +{ + if (Ethernet.status() != 0) { + Serial.println(Ethernet.status()); + connectEth(); + } +} + +void connectEth() +{ + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + + Serial.println("You're connected to the network"); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino new file mode 100644 index 00000000..cbf2dead --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/DhcpChatServer/DhcpChatServer.ino @@ -0,0 +1,91 @@ +/* + DHCP Chat Server + + A simple server that distributes any incoming messages to all + connected clients. To use, telnet to your device's IP address and type. + You can see the client's input in the serial monitor as well. + Using an Arduino Wiznet Ethernet shield. + + THis version attempts to get an IP address using DHCP + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 21 May 2011 + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + Based on ChatServer example by David A. Mellis + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network. +// gateway and subnet are optional: +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + +// telnet defaults to port 23 +EthernetServer server(23); +boolean gotAMessage = false; // whether or not you got a message from the client yet + +void setup() { + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Trying to get an IP address using DHCP"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // initialize the Ethernet device not using DHCP: + Ethernet.begin(ip, myDns, gateway, subnet); + } + // print your local IP address: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + + // start listening for clients + server.begin(); +} + +void loop() { + // wait for a new client: + EthernetClient client = server.available(); + + // when the client sends the first byte, say hello: + if (client) { + if (!gotAMessage) { + Serial.println("We have a new client"); + client.println("Hello, client!"); + gotAMessage = true; + } + + // read the bytes incoming from the client: + char thisChar = client.read(); + // echo the bytes back to the client: + server.write(thisChar); + // echo the bytes to the server as well: + Serial.print(thisChar); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/LinkStatus/LinkStatus.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/LinkStatus/LinkStatus.ino new file mode 100644 index 00000000..b0397b7d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/LinkStatus/LinkStatus.ino @@ -0,0 +1,36 @@ +/* + Link Status + This sketch prints the ethernet link status. When the + ethernet cable is connected the link status should go to "ON". + NOTE: Only WizNet W5200 and W5500 are capable of reporting + the link status. W5100 will report "Unknown". + Hardware: + - Ethernet shield or equivalent board/shield with WizNet 5200/5500 + Written by Cristian Maglie + This example is public domain. +*/ + +#include +#include +#include + +void setup() { + Serial.begin(9600); +} + +void loop() { + auto link = Ethernet.linkStatus(); + Serial.print("Link status: "); + switch (link) { + case Unknown: + Serial.println("Unknown"); + break; + case LinkON: + Serial.println("ON"); + break; + case LinkOFF: + Serial.println("OFF"); + break; + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino new file mode 100644 index 00000000..bffb8f47 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/TelnetClient/TelnetClient.ino @@ -0,0 +1,103 @@ +/* + Telnet client + + This sketch connects to a a telnet server (http://www.google.com) + using an Arduino Wiznet Ethernet shield. You'll need a telnet server + to test this with. + Processing's ChatServer example (part of the network library) works well, + running on port 10002. It can be found as part of the examples + in the Processing application, available at + http://processing.org/ + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 14 Sep 2010 + modified 9 Apr 2012 + by Tom Igoe + */ + +#include +#include +#include + +// The IP address will be dependent on your local network: +IPAddress ip(192, 168, 1, 177); + +// Enter the IP address of the server you're connecting to: +IPAddress server(1, 1, 1, 1); + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 23 is default for telnet; +// if you're using Processing's ChatServer, use port 10002): +EthernetClient client; + +void setup() { + + // start the Ethernet connection: + Ethernet.begin(ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + while (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + delay(500); + } + + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.println("connecting..."); + + // if you get a connection, report back via serial: + if (client.connect(server, 10002)) { + Serial.println("connected"); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + if (client.available()) { + char c = client.read(); + Serial.print(c); + } + + // as long as there are bytes in the serial queue, + // read them and send them out the socket if it's open: + while (Serial.available() > 0) { + char inChar = Serial.read(); + if (client.connected()) { + client.print(inChar); + } + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + // do nothing: + while (true) { + delay(1); + } + } +} + + + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino new file mode 100644 index 00000000..61886994 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UDPSendReceiveString/UDPSendReceiveString.ino @@ -0,0 +1,128 @@ +/* + UDPSendReceiveString: + This sketch receives UDP message strings, prints them to the serial port + and sends an "acknowledge" string back to the sender + + A Processing sketch is included at the end of file that can be used to send + and received messages for testing with a computer. + + created 21 Aug 2010 + by Michael Margolis + + This code is in the public domain. + */ + +#include +#include +#include + +// The IP address will be dependent on your local network: +IPAddress ip(192, 168, 1, 177); + +unsigned int localPort = 8888; // local port to listen on + +// buffers for receiving and sending data +char packetBuffer[UDP_TX_PACKET_MAX_SIZE]; // buffer to hold incoming packet, +char ReplyBuffer[] = "acknowledged"; // a string to send back + +// An EthernetUDP instance to let us send and receive packets over UDP +EthernetUDP Udp; + +void setup() { + + // start the Ethernet + Ethernet.begin(ip); + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start UDP + Udp.begin(localPort); +} + +void loop() { + // if there's data available, read a packet + int packetSize = Udp.parsePacket(); + if (packetSize) { + Serial.print("Received packet of size "); + Serial.println(packetSize); + Serial.print("From "); + IPAddress remote = Udp.remoteIP(); + for (int i=0; i < 4; i++) { + Serial.print(remote[i], DEC); + if (i < 3) { + Serial.print("."); + } + } + Serial.print(", port "); + Serial.println(Udp.remotePort()); + + // read the packet into packetBufffer + Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE); + Serial.println("Contents:"); + Serial.println(packetBuffer); + + // send a reply to the IP address and port that sent us the packet we received + Udp.beginPacket(Udp.remoteIP(), Udp.remotePort()); + Udp.write(ReplyBuffer); + Udp.endPacket(); + } + delay(10); +} + + +/* + Processing sketch to run with this example + ===================================================== + + // Processing UDP example to send and receive string data from Arduino + // press any key to send the "Hello Arduino" message + + + import hypermedia.net.*; + + UDP udp; // define the UDP object + + + void setup() { + udp = new UDP( this, 6000 ); // create a new datagram connection on port 6000 + //udp.log( true ); // <-- printout the connection activity + udp.listen( true ); // and wait for incoming message + } + + void draw() + { + } + + void keyPressed() { + String ip = "192.168.1.177"; // the remote IP address + int port = 8888; // the destination port + + udp.send("Hello World", ip, port ); // the message to send + + } + + void receive( byte[] data ) { // <-- default handler + //void receive( byte[] data, String ip, int port ) { // <-- extended handler + + for(int i=0; i < data.length; i++) + print(char(data[i])); + println(); + } + */ + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino new file mode 100644 index 00000000..627cf2cc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/UdpNtpClient/UdpNtpClient.ino @@ -0,0 +1,170 @@ +/* + + Udp NTP Client + + Get the time from a Network Time Protocol (NTP) time server + Demonstrates use of UDP sendPacket and ReceivePacket + For more on NTP time servers and the messages needed to communicate with them, + see http://en.wikipedia.org/wiki/Network_Time_Protocol + + created 4 Sep 2010 + by Michael Margolis + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + This code is in the public domain. + + */ + +#include +#include +#include +#include + +unsigned int localPort = 8888; // local port to listen for UDP packets + +const char timeServer[] = "time.nist.gov"; // time.nist.gov NTP server + +const int NTP_PACKET_SIZE = 48; // NTP time stamp is in the first 48 bytes of the message + +byte packetBuffer[NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets + +// A UDP instance to let us send and receive packets over UDP +EthernetUDP Udp; + +void setup() { + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start Ethernet and UDP + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + } else if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // no point in carrying on, so do nothing forevermore: + while (true) { + delay(1); + } + } + Udp.begin(localPort); +} + +void loop() { + if (Ethernet.status() != 0) { + Serial.println(Ethernet.status()); + connectEth(); + } + sendNTPpacket(timeServer); // send an NTP packet to a time server + + // wait to see if a reply is available + delay(1000); + if (Udp.parsePacket()) { + // We've received a packet, read the data from it + Udp.read(packetBuffer, NTP_PACKET_SIZE); // read the packet into the buffer + + // the timestamp starts at byte 40 of the received packet and is four bytes, + // or two words, long. First, extract the two words: + + unsigned long highWord = word(packetBuffer[40], packetBuffer[41]); + unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]); + // combine the four bytes (two words) into a long integer + // this is NTP time (seconds since Jan 1 1900): + unsigned long secsSince1900 = highWord << 16 | lowWord; + Serial.print("Seconds since Jan 1 1900 = "); + Serial.println(secsSince1900); + + // now convert NTP time into everyday time: + Serial.print("Unix time = "); + // Unix time starts on Jan 1 1970. In seconds, that's 2208988800: + const unsigned long seventyYears = 2208988800UL; + // subtract seventy years: + unsigned long epoch = secsSince1900 - seventyYears; + // print Unix time: + Serial.println(epoch); + + + // print the hour, minute and second: + Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT) + Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day) + Serial.print(':'); + if (((epoch % 3600) / 60) < 10) { + // In the first 10 minutes of each hour, we'll want a leading '0' + Serial.print('0'); + } + Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute) + Serial.print(':'); + if ((epoch % 60) < 10) { + // In the first 10 seconds of each minute, we'll want a leading '0' + Serial.print('0'); + } + Serial.println(epoch % 60); // print the second + } + // wait ten seconds before asking for the time again + delay(10000); +} + +// send an NTP request to the time server at the given address +void sendNTPpacket(const char * address) { + // set all bytes in the buffer to 0 + memset(packetBuffer, 0, NTP_PACKET_SIZE); + // Initialize values needed to form NTP request + // (see URL above for details on the packets) + packetBuffer[0] = 0b11100011; // LI, Version, Mode + packetBuffer[1] = 0; // Stratum, or type of clock + packetBuffer[2] = 6; // Polling Interval + packetBuffer[3] = 0xEC; // Peer Clock Precision + // 8 bytes of zero for Root Delay & Root Dispersion + packetBuffer[12] = 49; + packetBuffer[13] = 0x4E; + packetBuffer[14] = 49; + packetBuffer[15] = 52; + + // all NTP fields have been given values, now + // you can send a packet requesting a timestamp: + Udp.beginPacket(address, 123); // NTP requests are to port 123 + Udp.write(packetBuffer, NTP_PACKET_SIZE); + Udp.endPacket(); +} + +void connectEth() +{ + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(nullptr) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + + Serial.println("You're connected to the network"); + Serial.println(); +} + + + + + + + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClient/WebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClient/WebClient.ino new file mode 100644 index 00000000..62b506df --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClient/WebClient.ino @@ -0,0 +1,133 @@ +/* + Web client + + This sketch connects to a website (http://www.google.com) + using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe, based on work by Adrian McEwen + + */ + +#include +#include +#include + +// Enter a MAC address for your controller below. +// Newer Ethernet shields have a MAC address printed on a sticker on the shield +// byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; + +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS) +char server[] = "www.google.com"; // name address for Google (using DNS) + +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 2, 177); +IPAddress myDns(192, 168, 2, 1); + +// Initialize the Ethernet client library +// with the IP address and port of the server +// that you want to connect to (port 80 is default for HTTP): +EthernetClient client; + +// Variables to measure the speed +unsigned long beginMicros, endMicros; +unsigned long byteCount = 0; +bool printWebData = true; // set to false for better speed measurement + +void setup() +{ + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to congifure using IP address instead of DHCP: + Ethernet.begin(ip, myDns); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); + Serial.print("connecting to "); + Serial.print(server); + Serial.println("..."); + + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.print("connected to "); + Serial.println(client.remoteIP()); + // Make a HTTP request: + client.println("GET /search?q=arduino HTTP/1.1"); + client.println("Host: www.google.com"); + client.println("Connection: close"); + client.println(); + } else { + // if you didn't get a connection to the server: + Serial.println("connection failed"); + } + beginMicros = micros(); +} + +void loop() +{ + // if there are incoming bytes available + // from the server, read them and print them: + int len = client.available(); + if (len > 0) { + byte buffer[80]; + if (len > 80) + len = 80; + client.read(buffer, len); + if (printWebData) { + Serial.write(buffer, len); // show in the serial monitor (slows some boards) + } + byteCount = byteCount + len; + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + endMicros = micros(); + Serial.println(); + Serial.println("disconnecting."); + client.stop(); + Serial.print("Received "); + Serial.print(byteCount); + Serial.print(" bytes in "); + float seconds = (float)(endMicros - beginMicros) / 1000000.0; + Serial.print(seconds, 4); + float rate = (float)byteCount / seconds / 1000.0; + Serial.print(", rate = "); + Serial.print(rate); + Serial.print(" kbytes/second"); + Serial.println(); + + // do nothing forevermore: + while (true) { + delay(1); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino new file mode 100644 index 00000000..a5ffdf1f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeating/WebClientRepeating.ino @@ -0,0 +1,120 @@ +/* + Repeating Web client + + This sketch connects to a a web server and makes a request + using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or + the Adafruit Ethernet shield, either one will work, as long as it's got + a Wiznet Ethernet module on board. + + This example uses DNS, by assigning the Ethernet client with a MAC address, + IP address, and DNS address. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 19 Apr 2012 + by Tom Igoe + modified 21 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WebClientRepeating + This code is in the public domain. + + */ + +#include +#include +#include + +// Set the static IP address to use if the DHCP fails to assign +IPAddress ip(192, 168, 0, 177); +IPAddress myDns(192, 168, 0, 1); + +// initialize the library instance: +EthernetClient client; + +char server[] = "www.arduino.cc"; // also change the Host line in httpRequest() +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds + +void setup() { + + + // start serial port: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to congifure using IP address instead of DHCP: + Ethernet.begin(ip, myDns); + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); +} + +void loop() { + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + if (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } + +} + +// this method makes a HTTP connection to the server: +void httpRequest() { + // close any connection before send a new request. + // This will free the socket on the WiFi shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET /latest.txt HTTP/1.1"); + client.println("Host: www.arduino.cc"); + client.println("User-Agent: arduino-ethernet"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + + + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingManual/WebClientRepeatingManual.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingManual/WebClientRepeatingManual.ino new file mode 100644 index 00000000..def9a130 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingManual/WebClientRepeatingManual.ino @@ -0,0 +1,147 @@ +/* + Repeating Web client + + This sketch connects to a a web server and makes a request + using a Wiznet Ethernet shield. You can use the Arduino Ethernet shield, or + the Adafruit Ethernet shield, either one will work, as long as it's got + a Wiznet Ethernet module on board. + + This example uses DNS, by assigning the Ethernet client with a MAC address, + IP address, and DNS address. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + + created 19 Apr 2012 + by Tom Igoe + modified 21 Jan 2014 + by Federico Vanzati + + http://www.arduino.cc/en/Tutorial/WebClientRepeating + This code is in the public domain. + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network. +// DNS, gateway and subnet are optional: +IPAddress ip(192, 168, 1, 177); +IPAddress myDns(192, 168, 1, 1); +IPAddress gateway(192, 168, 1, 1); +IPAddress subnet(255, 255, 0, 0); + +// initialize the library instance: +EthernetClient client; + +char server[] = "www.arduino.cc"; // also change the Host line in httpRequest() +//IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds + +void setup() +{ + // start serial port: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + delay(2500); + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with Static IP Address:"); + if (Ethernet.begin(ip, myDns, gateway, subnet) == 0) { + Serial.println("Failed to configure Ethernet with Static IP Address"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + } + + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to congifure using IP address instead of DHCP: + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + Serial.print("My Gateway IP address: "); + Serial.println(Ethernet.gatewayIP()); + Serial.print("My DNS Server IP address: "); + Serial.println(Ethernet.dnsServerIP()); + // give the Ethernet shield a second to initialize: + delay(2500); +} + +void loop() +{ + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + if (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() +{ + // close any connection before send a new request. + // This will free the socket on the WiFi shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, 80)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET /latest.txt HTTP/1.1"); + client.println("Host: www.arduino.cc"); + client.println("User-Agent: arduino-ethernet"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} + +void connectEth() +{ + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin(nullptr) == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + + Serial.println("You're connected to the network"); + Serial.println(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingSSL/WebClientRepeatingSSL.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingSSL/WebClientRepeatingSSL.ino new file mode 100644 index 00000000..fa8585d0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebClientRepeatingSSL/WebClientRepeatingSSL.ino @@ -0,0 +1,100 @@ +/* + Repeating TLS/SSL Ethernet Web client. + + Remeber to update the CA certificates using WiFiFirmwareUpdater sketch + before using this sketch. + + */ + +#include +#include +#include + +// initialize the library instance: +EthernetSSLClient client; + +char server[] = "www.arduino.cc"; +int port = 443; +// IPAddress server(64,131,82,241); + +unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds +const unsigned long postingInterval = 10 * 1000; // delay between updates, in milliseconds + +void setup() +{ + + // start serial port: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start the Ethernet connection: + Serial.println("Initialize Ethernet with DHCP:"); + if (Ethernet.begin() == 0) { + Serial.println("Failed to configure Ethernet using DHCP"); + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + // try to congifure using IP address instead of DHCP: + Ethernet.begin(ip, myDns); + Serial.print("My IP address: "); + Serial.println(Ethernet.localIP()); + } else { + Serial.print(" DHCP assigned IP "); + Serial.println(Ethernet.localIP()); + } + // give the Ethernet shield a second to initialize: + delay(1000); +} + +void loop() +{ + // if there's incoming data from the net connection. + // send it out the serial port. This is for debugging + // purposes only: + if (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if ten seconds have passed since your last connection, + // then connect again and send data: + if (millis() - lastConnectionTime > postingInterval) { + httpRequest(); + } +} + +// this method makes a HTTP connection to the server: +void httpRequest() +{ + // close any connection before send a new request. + // This will free the socket on the WiFi shield + client.stop(); + + // if there's a successful connection: + if (client.connect(server, port)) { + Serial.println("connecting..."); + // send the HTTP GET request: + client.println("GET /latest.txt HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("User-Agent: arduino-ethernet"); + client.println("Accept: *"); + client.println("Connection: close"); + client.println(); + + // note the time that the connection was made: + lastConnectionTime = millis(); + } else { + // if you couldn't make a connection: + Serial.println("connection failed"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebServer/WebServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebServer/WebServer.ino new file mode 100644 index 00000000..6201495f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Ethernet/examples/WebServer/WebServer.ino @@ -0,0 +1,113 @@ +/* + Web Server + + A simple web server that shows the value of the analog input pins. + using an Arduino Wiznet Ethernet shield. + + Circuit: + * Ethernet shield attached to pins 10, 11, 12, 13 + * Analog inputs attached to pins A0 through A5 (optional) + + created 18 Dec 2009 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + modified 02 Sept 2015 + by Arturo Guadalupi + + */ + +#include +#include +#include + +// The IP address will be dependent on your local network: +IPAddress ip(192, 168, 1, 177); + +// Initialize the Ethernet server library +// with the IP address and port you want to use +// (port 80 is default for HTTP): +EthernetServer server(80); + +void setup() { + + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.println("Ethernet WebServer Example"); + + // start the Ethernet connection and the server: + Ethernet.begin(ip); + + // Check for Ethernet hardware present + if (Ethernet.hardwareStatus() == EthernetNoHardware) { + Serial.println("Ethernet shield was not found. Sorry, can't run without hardware. :("); + while (true) { + delay(1); // do nothing, no point running without Ethernet hardware + } + } + if (Ethernet.linkStatus() == LinkOFF) { + Serial.println("Ethernet cable is not connected."); + } + + // start the server + server.begin(); + Serial.print("server is at "); + Serial.println(Ethernet.localIP()); +} + + +void loop() { + // listen for incoming clients + EthernetClient client = server.available(); + if (client) { + Serial.println("new client"); + // an http request ends with a blank line + boolean currentLineIsBlank = true; + while (client.connected()) { + if (client.available()) { + char c = client.read(); + Serial.write(c); + // if you've gotten to the end of the line (received a newline + // character) and the line is blank, the http request has ended, + // so you can send a reply + if (c == '\n' && currentLineIsBlank) { + // send a standard http response header + client.println("HTTP/1.1 200 OK"); + client.println("Content-Type: text/html"); + client.println("Connection: close"); // the connection will be closed after completion of the response + client.println("Refresh: 5"); // refresh the page automatically every 5 sec + client.println(); + client.println(""); + client.println(""); + // output the value of each analog input pin + for (int analogChannel = 0; analogChannel < 6; analogChannel++) { + int sensorReading = analogRead(analogChannel); + client.print("analog input "); + client.print(analogChannel); + client.print(" is "); + client.print(sensorReading); + client.println("
    "); + } + client.println(""); + break; + } + if (c == '\n') { + // you're starting a new line + currentLineIsBlank = true; + } else if (c != '\r') { + // you've gotten a character on the current line + currentLineIsBlank = false; + } + } + } + // give the web browser time to receive the data + delay(1); + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/GNSSClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/GNSSClient.ino new file mode 100644 index 00000000..e263e42a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/GNSSClient.ino @@ -0,0 +1,36 @@ +#include +#include + +#include "arduino_secrets.h" +char pin[] = SECRET_PIN; +char apn[] = SECRET_APN; +char username[] = SECRET_USERNAME; +char pass[] = SECRET_PASSWORD; + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + Serial.println("Starting Carrier Network registration"); + if(!GSM.begin(pin, apn, username, pass, CATNB)){ + Serial.println("The board was not able to register to the network..."); + // do nothing forevermore: + while(1); + } + Serial.println("\nEnable GNSS Engine..."); + // GPS.begin() start and eanble the GNSS engine + GPS.begin(); + Serial.println("\nGNSS Engine enabled..."); +} + +void loop() { + // Print out raw NMEA strings. + // For parsed output look at the MicroNMEA_integration example. + if(GPS.available()){ + Serial.print((char) GPS.read()); + delay(1); + } + // After geting valid packet GPS.end() can be used to stop and + // disable the GNSS engine + // GPS.end(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/arduino_secrets.h new file mode 100644 index 00000000..8c5842fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GNSSClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_USERNAME "" +#define SECRET_PASSWORD "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/GSMClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/GSMClient.ino new file mode 100644 index 00000000..0d982061 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/GSMClient.ino @@ -0,0 +1,61 @@ +#include + +REDIRECT_STDOUT_TO(Serial); + +#include "arduino_secrets.h" +char pin[] = SECRET_PIN; +char apn[] = SECRET_APN; +char username[] = SECRET_USERNAME; +char pass[] = SECRET_PASSWORD; + +const char server[] = "www.example.com"; +const char* ip_address; +int port = 80; + +GSMClient client; + +void setup() { + Serial.begin(115200); + while(!Serial) {} + Serial.println("Starting Carrier Network registration"); + if(!GSM.begin(pin, apn, username, pass, CATNB)){ + Serial.println("The board was not able to register to the network..."); + // do nothing forevermore: + while(1); + } + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, port)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET / HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + Serial.println("unable to connect to server"); + } + +} + +void loop() { + + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/arduino_secrets.h new file mode 100644 index 00000000..8c5842fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/GSMClient/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_USERNAME "" +#define SECRET_PASSWORD "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/MicroNMEA_integration.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/MicroNMEA_integration.ino new file mode 100644 index 00000000..abded32b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/MicroNMEA_integration.ino @@ -0,0 +1,124 @@ +#include +#include +#include + +#include "arduino_secrets.h" +constexpr auto pin { SECRET_PIN }; +constexpr auto apn { SECRET_APN }; +constexpr auto username { SECRET_USERNAME }; +constexpr auto pass { SECRET_PASSWORD }; + +char nmeaBuffer[100]; +MicroNMEA nmea(nmeaBuffer, sizeof(nmeaBuffer)); + +// Keep track of NMEA string processing +auto nmeaProcessStatus { false }; + +// Check for valid fix every checkValidInterval ms +constexpr unsigned long checkValidInterval { 5000 }; +unsigned long checkValidNow {}; + +void setup() +{ + Serial.begin(115200); + for (const auto timeout = millis() + 2500; !Serial && millis() < timeout; delay(250)) + ; + + // GSM.debug(Serial); + delay(1000); + + Serial.println("Starting Carrier Network registration"); + if (!GSM.begin(pin, apn, username, pass, CATNB)) { + Serial.println("The board was not able to register to the network..."); + // do nothing forevermore: + while (1) + ; + } + Serial.println("Enable GNSS Engine..."); + // GPS.begin() start and eanble the GNSS engine + GPS.begin(); + Serial.println("GNSS Engine enabled..."); + Serial.println("Waiting for a valid fix."); + + checkValidNow = millis(); +} + +void loop() +{ + while (GPS.available()) { + char c = GPS.read(); + // process is true when a valid NMEA string has been processed + nmeaProcessStatus = nmea.process(c); + } + + if (nmeaProcessStatus && millis() > checkValidNow) { + checkValidNow = millis() + checkValidInterval; + + // Output GPS information from previous second + Serial.print("Valid fix: "); + Serial.println(nmea.isValid() ? "yes" : "no"); + + if (!nmea.isValid()) + return; + + String navSystem; + switch (nmea.getNavSystem()) { + case 'N': + navSystem = "GNSS"; + break; + case 'P': + navSystem = "GPS"; + break; + case 'L': + navSystem = "GLONASS"; + break; + case 'A': + navSystem = "Galileo"; + break; + default: + break; + } + Serial.print("Nav. system: "); + Serial.println(navSystem); + + Serial.print("Num. satellites: "); + Serial.println(nmea.getNumSatellites()); + + Serial.print("HDOP: "); + Serial.println(nmea.getHDOP() / 10., 1); + + Serial.print("Date/time: "); + Serial.print(nmea.getYear()); + Serial.print('-'); + Serial.print(int(nmea.getMonth())); + Serial.print('-'); + Serial.print(int(nmea.getDay())); + Serial.print('T'); + Serial.print(int(nmea.getHour())); + Serial.print(':'); + Serial.print(int(nmea.getMinute())); + Serial.print(':'); + Serial.println(int(nmea.getSecond())); + + long latitude_mdeg = nmea.getLatitude(); + long longitude_mdeg = nmea.getLongitude(); + Serial.print("Latitude (deg): "); + Serial.println(latitude_mdeg / 1000000., 6); + + Serial.print("Longitude (deg): "); + Serial.println(longitude_mdeg / 1000000., 6); + + long alt; + Serial.print("Altitude (m): "); + if (nmea.getAltitude(alt)) + Serial.println(alt / 1000., 3); + else + Serial.println("not available"); + + Serial.print("Speed: "); + Serial.println(nmea.getSpeed() / 1000., 3); + Serial.print("Course: "); + Serial.println(nmea.getCourse() / 1000., 3); + nmea.clear(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/arduino_secrets.h new file mode 100644 index 00000000..8c5842fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/GSM/examples/MicroNMEA_integration/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PIN "" +#define SECRET_APN "" +#define SECRET_USERNAME "" +#define SECRET_PASSWORD "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/KernelDebug/examples/KernelDebug/KernelDebug.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/KernelDebug/examples/KernelDebug/KernelDebug.ino new file mode 100644 index 00000000..85e84bb8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/KernelDebug/examples/KernelDebug/KernelDebug.ino @@ -0,0 +1,22 @@ +/* This example demonstrates how to utilize the KernelDebug library which + allows kernel debugging of the Portenta H7 with GDB over a UART serial + connection. + + To connect to the target, launch gdb with the following parameters + + arm-none-eabi-gdb -ex "set pagination off" --baud {230400} -ex "set target-charset ASCII" -ex "target remote {debug.port}" {project_name}.elf + + The baud rate needs to match the one provided in KernelDebug constructor, while {debug.port} depends on the operating system (eg. /dev/ttyUSB0 or COM15) +*/ + +#include + +KernelDebug kernelDebug(SERIAL1_TX, SERIAL1_RX, USART1_IRQn, 230400, DEBUG_BREAK_IN_SETUP); + +void setup() { + +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MCUboot/examples/confirmSketch/confirmSketch.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MCUboot/examples/confirmSketch/confirmSketch.ino new file mode 100644 index 00000000..5543a8e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MCUboot/examples/confirmSketch/confirmSketch.ino @@ -0,0 +1,27 @@ +/* + This example shows how to confirm an update Sketch after a swap + using MCUboot library. + + Circuit: + - Arduino Portenta H7 board + + This example code is in the public domain. +*/ + +#include + +// the setup function runs once when you press reset or power the board +void setup() { + // initialize digital pin LED_BUILTIN as an output. + pinMode(LED_BUILTIN, OUTPUT); + // set confirmed flag to avoid MCUboot reverts to previous application at next reset + MCUboot::confirmSketch(); +} + +// the loop function runs over and over again forever +void loop() { + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(100); // wait 100ms + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(100); // wait 100ms +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_DataLogger_FIFO/NiclaVision_DataLogger_FIFO.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_DataLogger_FIFO/NiclaVision_DataLogger_FIFO.ino new file mode 100644 index 00000000..1bd9c917 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_DataLogger_FIFO/NiclaVision_DataLogger_FIFO.ino @@ -0,0 +1,265 @@ +/* + This example exposes the second MB of Nicla Vision flash as a USB disk. + The user can interact with this disk as a bidirectional communication with the board + For example, the board could save data in a file to be retrieved later with a drag and drop. + If the user does a double tap, the firmware goes to datalogger mode (green led on). + Now the user can do another double tap to start a recording of the IMU data + (green led blinking). With another double tap the recording will be stopped (green led on). + Now the user can start/stop other recordings of the IMU data using again the double tap. + The log files are saved in flash with an increasing number suffix data_0.txt, data_1.txt, etc. + If you want to transfer the log files to the PC, you can reset the board and + wait for 10 seconds (blue led blinking). +*/ + +#include "PluggableUSBMSD.h" +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "FATFileSystem.h" +#include "LSM6DSOXSensor.h" + +#define INT_1 LSM6DS_INT +#define SENSOR_ODR 104.0f // In Hertz +#define ACC_FS 2 // In g +#define GYR_FS 2000 // In dps +#define MEASUREMENT_TIME_INTERVAL (1000.0f/SENSOR_ODR) // In ms +#define FIFO_SAMPLE_THRESHOLD 199 +#define FLASH_BUFF_LEN 8192 + +typedef enum { + DATA_STORAGE_STATE, + DATA_LOGGER_IDLE_STATE, + DATA_LOGGER_RUNNING_STATE +} demo_state_e; + +volatile demo_state_e demo_state = DATA_STORAGE_STATE; +volatile int mems_event = 0; +uint32_t file_count = 0; +unsigned long timestamp_count = 0; +bool acc_available = false; +bool gyr_available = false; +int32_t acc_value[3]; +int32_t gyr_value[3]; +char buff[FLASH_BUFF_LEN]; +uint32_t pos = 0; + +QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); +// Partition 1 is allocated to WiFi +mbed::MBRBlockDevice lsm_data(&root, 2); +static mbed::FATFileSystem lsm_fs("lsm"); + +LSM6DSOXSensor AccGyr(&SPI1, PIN_SPI_SS1); + +USBMSD MassStorage(&root); + +rtos::Thread acquisition_th; + +FILE *f = nullptr; + +void INT1Event_cb() +{ + mems_event = 1; +} + +void USBMSD::begin() +{ + int err = lsm_fs.mount(&lsm_data); + if (err) { + Serial.println("mount failed"); + err = lsm_fs.reformat(&lsm_data); + if (err) { + Serial.println("Reformat failed"); + return; + } + } +} + +mbed::FATFileSystem &USBMSD::getFileSystem() +{ + static mbed::FATFileSystem fs("lsm"); + return fs; +} + +void led_green_thd() +{ + while (1) { + if (demo_state == DATA_LOGGER_RUNNING_STATE) { + digitalWrite(LEDG, LOW); + delay(100); + digitalWrite(LEDG, HIGH); + delay(100); + } + } +} + +void Read_FIFO_Data(uint16_t samples_to_read) +{ + uint16_t i; + + for (i = 0; i < samples_to_read; i++) { + uint8_t tag; + // Check the FIFO tag + AccGyr.Get_FIFO_Tag(&tag); + switch (tag) { + // If we have a gyro tag, read the gyro data + case LSM6DSOX_GYRO_NC_TAG: { + AccGyr.Get_FIFO_G_Axes(gyr_value); + gyr_available = true; + break; + } + // If we have an acc tag, read the acc data + case LSM6DSOX_XL_NC_TAG: { + AccGyr.Get_FIFO_X_Axes(acc_value); + acc_available = true; + break; + } + // We can discard other tags + default: { + break; + } + } + // If we have the measurements of both acc and gyro, we can store them with timestamp + if (acc_available && gyr_available) { + int num_bytes; + num_bytes = snprintf(&buff[pos], (FLASH_BUFF_LEN - pos), "%lu %d %d %d %d %d %d\n", (unsigned long)((float)timestamp_count * MEASUREMENT_TIME_INTERVAL), (int)acc_value[0], (int)acc_value[1], (int)acc_value[2], (int)gyr_value[0], (int)gyr_value[1], (int)gyr_value[2]); + pos += num_bytes; + timestamp_count++; + acc_available = false; + gyr_available = false; + } + } + // We can add the termination character to the string, so we are ready to save it in flash + buff[pos] = '\0'; + pos = 0; +} + +void setup() +{ + Serial.begin(115200); + MassStorage.begin(); + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + + // Initialize SPI1 bus. + SPI1.begin(); + + //Interrupts. + attachInterrupt(INT_1, INT1Event_cb, RISING); + + // Initialize IMU. + AccGyr.begin(); + AccGyr.Enable_X(); + AccGyr.Enable_G(); + // Configure ODR and FS of the acc and gyro + AccGyr.Set_X_ODR(SENSOR_ODR); + AccGyr.Set_X_FS(ACC_FS); + AccGyr.Set_G_ODR(SENSOR_ODR); + AccGyr.Set_G_FS(GYR_FS); + // Enable the Double Tap event + AccGyr.Enable_Double_Tap_Detection(LSM6DSOX_INT1_PIN); + // Configure FIFO BDR for acc and gyro + AccGyr.Set_FIFO_X_BDR(SENSOR_ODR); + AccGyr.Set_FIFO_G_BDR(SENSOR_ODR); + // Start Led blinking thread + acquisition_th.start(led_green_thd); +} + +void loop() +{ + + if (mems_event) { + mems_event = 0; + LSM6DSOX_Event_Status_t status; + AccGyr.Get_X_Event_Status(&status); + if (status.DoubleTapStatus) { + switch (demo_state) { + case DATA_STORAGE_STATE: { + // Go to DATA_LOGGER_IDLE_STATE state + demo_state = DATA_LOGGER_IDLE_STATE; + digitalWrite(LEDG, LOW); + Serial.println("From DATA_STORAGE_STATE To DATA_LOGGER_IDLE_STATE"); + break; + } + case DATA_LOGGER_IDLE_STATE: { + char filename[32]; + // Go to DATA_LOGGER_RUNNING_STATE state + snprintf(filename, 32, "/lsm/data_%lu.txt", file_count); + Serial.print("Start writing file "); + Serial.println(filename); + // open a file to write some data + // w+ means overwrite, so every time the board is rebooted the file will be overwritten + f = fopen(filename, "w+"); + if (f != nullptr) { + // write header + fprintf(f, "Timestamp[ms] A_X [mg] A_Y [mg] A_Z [mg] G_X [mdps] G_Y [mdps] G_Z [mdps]\n"); + fflush(f); + Serial.println("From DATA_LOGGER_IDLE_STATE To DATA_LOGGER_RUNNING_STATE"); + demo_state = DATA_LOGGER_RUNNING_STATE; + digitalWrite(LEDG, HIGH); + timestamp_count = 0; + pos = 0; + acc_available = false; + gyr_available = false; + // Set FIFO in Continuous mode + AccGyr.Set_FIFO_Mode(LSM6DSOX_STREAM_MODE); + } + break; + } + case DATA_LOGGER_RUNNING_STATE: { + // Empty the FIFO + uint16_t fifo_samples; + AccGyr.Get_FIFO_Num_Samples(&fifo_samples); + Read_FIFO_Data(fifo_samples); + // Store the string in flash + fprintf(f, "%s", buff); + fflush(f); + + // Close the log file and increase the counter + fclose(f); + file_count++; + // Set FIFO in Bypass mode + AccGyr.Set_FIFO_Mode(LSM6DSOX_BYPASS_MODE); + // Go to DATA_LOGGER_IDLE_STATE state + demo_state = DATA_LOGGER_IDLE_STATE; + // Wait for the led thread ends the blinking + delay(250); + digitalWrite(LEDG, LOW); + Serial.println("From DATA_LOGGER_RUNNING_STATE To DATA_LOGGER_IDLE_STATE"); + break; + } + default: + Serial.println("Error! Invalid state"); + } + } + } + + if (demo_state == DATA_LOGGER_RUNNING_STATE) { + uint16_t fifo_samples; + + // Check the number of samples inside FIFO + AccGyr.Get_FIFO_Num_Samples(&fifo_samples); + + // If we reach the threshold we can empty the FIFO + if (fifo_samples > FIFO_SAMPLE_THRESHOLD) { + // Empty the FIFO + Read_FIFO_Data(fifo_samples); + // Store the string in flash + fprintf(f, "%s", buff); + fflush(f); + } + } + + if (demo_state == DATA_STORAGE_STATE && millis() > 10000) { + // Disable the sensor and go to Mass Storage mode + AccGyr.Disable_Double_Tap_Detection(); + AccGyr.Disable_X(); + AccGyr.Disable_G(); + while (1) { + digitalWrite(LEDB, LOW); + delay(100); + digitalWrite(LEDB, HIGH); + delay(100); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/NiclaVision_MLC_Motion_Intensity.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/NiclaVision_MLC_Motion_Intensity.ino new file mode 100644 index 00000000..b865d006 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/NiclaVision_MLC_Motion_Intensity.ino @@ -0,0 +1,134 @@ +/* + This example shows how to load the MLC bytecode for Motion Intensity on LSM6DSOX + of the Arduino Nicla Vision. +*/ + +// Includes +#include "LSM6DSOXSensor.h" +#include "lsm6dsox_motion_intensity.h" + +#define INT_1 LSM6DS_INT + +//Interrupts. +volatile int mems_event = 0; + +// Components +LSM6DSOXSensor AccGyr(&SPI1, PIN_SPI_SS1); + +// MLC +ucf_line_t *ProgramPointer; +int32_t LineCounter; +int32_t TotalNumberOfLine; + +void INT1Event_cb(); +void printMLCStatus(uint8_t status); + +void setup() +{ + // Led. + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDR, OUTPUT); + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + + // Initialize serial for output. + Serial.begin(115200); + + // Initialize I2C bus. + SPI1.begin(); + + AccGyr.begin(); + + /* Feed the program to Machine Learning Core */ + /* Motion Intensity Default program */ + ProgramPointer = (ucf_line_t *)lsm6dsox_motion_intensity; + TotalNumberOfLine = sizeof(lsm6dsox_motion_intensity) / sizeof(ucf_line_t); + Serial.println("Motion Intensity for LSM6DSOX MLC"); + Serial.print("UCF Number Line="); + Serial.println(TotalNumberOfLine); + + for (LineCounter = 0; LineCounter < TotalNumberOfLine; LineCounter++) { + if (AccGyr.Write_Reg(ProgramPointer[LineCounter].address, ProgramPointer[LineCounter].data)) { + Serial.print("Error loading the Program to LSM6DSOX at line: "); + Serial.println(LineCounter); + while (1) { + // Led blinking. + digitalWrite(LED_BUILTIN, LOW); + delay(250); + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + } + } + } + + Serial.println("Program loaded inside the LSM6DSOX MLC"); + + AccGyr.Enable_X(); + AccGyr.Set_X_ODR(104.0f); + AccGyr.Set_X_FS(2); + + //Interrupts. + pinMode(INT_1, INPUT); + attachInterrupt(INT_1, INT1Event_cb, RISING); +} + +void loop() +{ + if (mems_event) { + mems_event = 0; + LSM6DSOX_MLC_Status_t status; + AccGyr.Get_MLC_Status(&status); + if (status.is_mlc1) { + uint8_t mlc_out[8]; + AccGyr.Get_MLC_Output(mlc_out); + printMLCStatus(mlc_out[0]); + } + } +} + +void INT1Event_cb() +{ + mems_event = 1; +} + +void printMLCStatus(uint8_t status) +{ + switch (status) { + case 1: + // Reset leds status + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + // LEDB On + digitalWrite(LEDB, LOW); + Serial.println("Stationary"); + break; + case 4: + // Reset leds status + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + // LEDG On + digitalWrite(LEDG, LOW); + Serial.println("Medium Intensity"); + break; + case 8: + // Reset leds status + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + // LEDR On + digitalWrite(LEDR, LOW); + Serial.println("High Intensity"); + break; + default: + // Reset leds status + digitalWrite(LEDB, HIGH); + digitalWrite(LEDG, HIGH); + digitalWrite(LEDR, HIGH); + Serial.println("Unknown"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h new file mode 100644 index 00000000..cd669df1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/NiclaVision_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h @@ -0,0 +1,127 @@ +/* + ****************************************************************************** + * @file lsm6dsox_motion_intensity.h + * @author Sensors Software Solution Team + * @brief This file contains the configuration for lsm6dsox_motion_intensity. + * + ****************************************************************************** + * @attention + * + *

    © Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

    + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef LSM6DSOX_MOTION_INTENSITY_H +#define LSM6DSOX_MOTION_INTENSITY_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +#ifndef MEMS_UCF_SHARED_TYPES +#define MEMS_UCF_SHARED_TYPES + +/** Common data block definition **/ +typedef struct { + uint8_t address; + uint8_t data; +} ucf_line_t; + +#endif /* MEMS_UCF_SHARED_TYPES */ + +/** Configuration array generated from Unico Tool **/ +const ucf_line_t lsm6dsox_motion_intensity[] = { + {.address = 0x10, .data = 0x00,}, + {.address = 0x11, .data = 0x00,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x04, .data = 0x00,}, + {.address = 0x05, .data = 0x00,}, + {.address = 0x17, .data = 0x40,}, + {.address = 0x02, .data = 0x11,}, + {.address = 0x08, .data = 0xEA,}, + {.address = 0x09, .data = 0x46,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x09, .data = 0x50,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x0A,}, + {.address = 0x02, .data = 0x11,}, + {.address = 0x08, .data = 0xF2,}, + {.address = 0x09, .data = 0x34,}, + {.address = 0x02, .data = 0x11,}, + {.address = 0x08, .data = 0xFA,}, + {.address = 0x09, .data = 0x3C,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x09, .data = 0x52,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x09, .data = 0x5E,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x02, .data = 0x31,}, + {.address = 0x08, .data = 0x3C,}, + {.address = 0x09, .data = 0x3F,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x01,}, + {.address = 0x09, .data = 0x10,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x1F,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x02, .data = 0x31,}, + {.address = 0x08, .data = 0x52,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x01, .data = 0x00,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x17, .data = 0x40,}, + {.address = 0x02, .data = 0x31,}, + {.address = 0x08, .data = 0x5E,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x2C,}, + {.address = 0x09, .data = 0x80,}, + {.address = 0x09, .data = 0xA0,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x41,}, + {.address = 0x09, .data = 0xE0,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x17, .data = 0x00,}, + {.address = 0x04, .data = 0x00,}, + {.address = 0x05, .data = 0x10,}, + {.address = 0x02, .data = 0x01,}, + {.address = 0x01, .data = 0x00,}, + {.address = 0x5E, .data = 0x02,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x0D, .data = 0x01,}, + {.address = 0x60, .data = 0x35,}, + {.address = 0x01, .data = 0x00,}, + {.address = 0x10, .data = 0x40,}, + {.address = 0x11, .data = 0x00,} +}; + +#ifdef __cplusplus +} +#endif + +#endif /* LSM6DSOX_MOTION_INTENSITY_H */ + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_DataLogger_FIFO/RP2040_DataLogger_FIFO.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_DataLogger_FIFO/RP2040_DataLogger_FIFO.ino new file mode 100644 index 00000000..ce39211b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_DataLogger_FIFO/RP2040_DataLogger_FIFO.ino @@ -0,0 +1,258 @@ +/* + This example exposes the first MB of Rp2040 flash as a USB disk. + The user can interact with this disk as a bidirectional communication with the board + For example, the board could save data in a file to be retrieved later with a drag and drop. + If the user does a double tap, the firmware goes to datalogger mode (green led on). + Now the user can do another double tap to start a recording of the IMU data + (green led blinking). With another double tap the recording will be stopped (green led on). + Now the user can start/stop other recordings of the IMU data using again the double tap. + The log files are saved in flash with an increasing number suffix data_0.txt, data_1.txt, etc. + If you want to transfer the log files to the PC, you can reset the board and + wait for 10 seconds (blue led blinking). + You can find the video tutorial on LSM6DSOX MLC at: https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-imu-advanced +*/ + +#include "PluggableUSBMSD.h" +#include "FlashIAPBlockDevice.h" +#include "WiFiNINA.h" +#include "LSM6DSOXSensor.h" + +#define INT_1 INT_IMU +#define SENSOR_ODR 104.0f // In Hertz +#define ACC_FS 2 // In g +#define GYR_FS 2000 // In dps +#define MEASUREMENT_TIME_INTERVAL (1000.0f/SENSOR_ODR) // In ms +#define FIFO_SAMPLE_THRESHOLD 199 +#define FLASH_BUFF_LEN 8192 + +typedef enum { + DATA_STORAGE_STATE, + DATA_LOGGER_IDLE_STATE, + DATA_LOGGER_RUNNING_STATE +} demo_state_e; + +volatile demo_state_e demo_state = DATA_STORAGE_STATE; +volatile int mems_event = 0; +uint32_t file_count = 0; +unsigned long timestamp_count = 0; +bool acc_available = false; +bool gyr_available = false; +int32_t acc_value[3]; +int32_t gyr_value[3]; +char buff[FLASH_BUFF_LEN]; +uint32_t pos = 0; + +static FlashIAPBlockDevice bd(XIP_BASE + 0x100000, 0x100000); + +LSM6DSOXSensor AccGyr(&Wire, LSM6DSOX_I2C_ADD_L); + +USBMSD MassStorage(&bd); + +rtos::Thread acquisition_th; + +FILE *f = nullptr; + +void INT1Event_cb() +{ + mems_event = 1; +} + +void USBMSD::begin() +{ + int err = getFileSystem().mount(&bd); + if (err) { + err = getFileSystem().reformat(&bd); + } +} + +mbed::FATFileSystem &USBMSD::getFileSystem() +{ + static mbed::FATFileSystem fs("fs"); + return fs; +} + +void led_green_thd() +{ + while (1) { + if (demo_state == DATA_LOGGER_RUNNING_STATE) { + digitalWrite(LEDG, HIGH); + delay(100); + digitalWrite(LEDG, LOW); + delay(100); + } + } +} + +void Read_FIFO_Data(uint16_t samples_to_read) +{ + uint16_t i; + + for (i = 0; i < samples_to_read; i++) { + uint8_t tag; + // Check the FIFO tag + AccGyr.Get_FIFO_Tag(&tag); + switch (tag) { + // If we have a gyro tag, read the gyro data + case LSM6DSOX_GYRO_NC_TAG: { + AccGyr.Get_FIFO_G_Axes(gyr_value); + gyr_available = true; + break; + } + // If we have an acc tag, read the acc data + case LSM6DSOX_XL_NC_TAG: { + AccGyr.Get_FIFO_X_Axes(acc_value); + acc_available = true; + break; + } + // We can discard other tags + default: { + break; + } + } + // If we have the measurements of both acc and gyro, we can store them with timestamp + if (acc_available && gyr_available) { + int num_bytes; + num_bytes = snprintf(&buff[pos], (FLASH_BUFF_LEN - pos), "%lu %d %d %d %d %d %d\n", (unsigned long)((float)timestamp_count * MEASUREMENT_TIME_INTERVAL), (int)acc_value[0], (int)acc_value[1], (int)acc_value[2], (int)gyr_value[0], (int)gyr_value[1], (int)gyr_value[2]); + pos += num_bytes; + timestamp_count++; + acc_available = false; + gyr_available = false; + } + } + // We can add the termination character to the string, so we are ready to save it in flash + buff[pos] = '\0'; + pos = 0; +} + +void setup() +{ + Serial.begin(115200); + MassStorage.begin(); + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + + // Initialize I2C bus. + Wire.begin(); + Wire.setClock(400000); + + //Interrupts. + attachInterrupt(INT_1, INT1Event_cb, RISING); + + // Initialize IMU. + AccGyr.begin(); + AccGyr.Enable_X(); + AccGyr.Enable_G(); + // Configure ODR and FS of the acc and gyro + AccGyr.Set_X_ODR(SENSOR_ODR); + AccGyr.Set_X_FS(ACC_FS); + AccGyr.Set_G_ODR(SENSOR_ODR); + AccGyr.Set_G_FS(GYR_FS); + // Enable the Double Tap event + AccGyr.Enable_Double_Tap_Detection(LSM6DSOX_INT1_PIN); + // Configure FIFO BDR for acc and gyro + AccGyr.Set_FIFO_X_BDR(SENSOR_ODR); + AccGyr.Set_FIFO_G_BDR(SENSOR_ODR); + // Start Led blinking thread + acquisition_th.start(led_green_thd); +} + +void loop() +{ + + if (mems_event) { + mems_event = 0; + LSM6DSOX_Event_Status_t status; + AccGyr.Get_X_Event_Status(&status); + if (status.DoubleTapStatus) { + switch (demo_state) { + case DATA_STORAGE_STATE: { + // Go to DATA_LOGGER_IDLE_STATE state + demo_state = DATA_LOGGER_IDLE_STATE; + digitalWrite(LEDG, HIGH); + Serial.println("From DATA_STORAGE_STATE To DATA_LOGGER_IDLE_STATE"); + break; + } + case DATA_LOGGER_IDLE_STATE: { + char filename[32]; + // Go to DATA_LOGGER_RUNNING_STATE state + snprintf(filename, 32, "/fs/data_%lu.txt", file_count); + Serial.print("Start writing file "); + Serial.println(filename); + // open a file to write some data + // w+ means overwrite, so every time the board is rebooted the file will be overwritten + f = fopen(filename, "w+"); + if (f != nullptr) { + // write header + fprintf(f, "Timestamp[ms] A_X [mg] A_Y [mg] A_Z [mg] G_X [mdps] G_Y [mdps] G_Z [mdps]\n"); + fflush(f); + Serial.println("From DATA_LOGGER_IDLE_STATE To DATA_LOGGER_RUNNING_STATE"); + demo_state = DATA_LOGGER_RUNNING_STATE; + digitalWrite(LEDG, LOW); + timestamp_count = 0; + pos = 0; + acc_available = false; + gyr_available = false; + // Set FIFO in Continuous mode + AccGyr.Set_FIFO_Mode(LSM6DSOX_STREAM_MODE); + } + break; + } + case DATA_LOGGER_RUNNING_STATE: { + // Empty the FIFO + uint16_t fifo_samples; + AccGyr.Get_FIFO_Num_Samples(&fifo_samples); + Read_FIFO_Data(fifo_samples); + // Store the string in flash + fprintf(f, "%s", buff); + fflush(f); + + // Close the log file and increase the counter + fclose(f); + file_count++; + // Set FIFO in Bypass mode + AccGyr.Set_FIFO_Mode(LSM6DSOX_BYPASS_MODE); + // Go to DATA_LOGGER_IDLE_STATE state + demo_state = DATA_LOGGER_IDLE_STATE; + // Wait for the led thread ends the blinking + delay(250); + digitalWrite(LEDG, HIGH); + Serial.println("From DATA_LOGGER_RUNNING_STATE To DATA_LOGGER_IDLE_STATE"); + break; + } + default: + Serial.println("Error! Invalid state"); + } + } + } + + if (demo_state == DATA_LOGGER_RUNNING_STATE) { + uint16_t fifo_samples; + + // Check the number of samples inside FIFO + AccGyr.Get_FIFO_Num_Samples(&fifo_samples); + + // If we reach the threshold we can empty the FIFO + if (fifo_samples > FIFO_SAMPLE_THRESHOLD) { + // Empty the FIFO + Read_FIFO_Data(fifo_samples); + // Store the string in flash + fprintf(f, "%s", buff); + fflush(f); + } + } + + if (demo_state == DATA_STORAGE_STATE && millis() > 10000) { + // Disable the sensor and go to Mass Storage mode + AccGyr.Disable_Double_Tap_Detection(); + AccGyr.Disable_X(); + AccGyr.Disable_G(); + while (1) { + digitalWrite(LEDB, HIGH); + delay(100); + digitalWrite(LEDB, LOW); + delay(100); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/RP2040_MLC_Motion_Intensity.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/RP2040_MLC_Motion_Intensity.ino new file mode 100644 index 00000000..6b4f300f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/RP2040_MLC_Motion_Intensity.ino @@ -0,0 +1,136 @@ +/* + This example shows how to load the MLC bytecode for Motion Intensity on LSM6DSOX + of the Arduino Nano RP2040 Connect. + You can find the video tutorial on LSM6DSOX MLC at: https://docs.arduino.cc/tutorials/nano-rp2040-connect/rp2040-imu-advanced +*/ + +// Includes +#include "WiFiNINA.h" +#include "LSM6DSOXSensor.h" +#include "lsm6dsox_motion_intensity.h" + +#define INT_1 INT_IMU + +//Interrupts. +volatile int mems_event = 0; + +// Components +LSM6DSOXSensor AccGyr(&Wire, LSM6DSOX_I2C_ADD_L); + +// MLC +ucf_line_t *ProgramPointer; +int32_t LineCounter; +int32_t TotalNumberOfLine; + +void INT1Event_cb(); +void printMLCStatus(uint8_t status); + +void setup() +{ + // Led. + pinMode(LEDB, OUTPUT); + pinMode(LEDG, OUTPUT); + pinMode(LEDR, OUTPUT); + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + + // Initialize serial for output. + Serial.begin(115200); + + // Initialize I2C bus. + Wire.begin(); + + AccGyr.begin(); + + /* Feed the program to Machine Learning Core */ + /* Motion Intensity Default program */ + ProgramPointer = (ucf_line_t *)lsm6dsox_motion_intensity; + TotalNumberOfLine = sizeof(lsm6dsox_motion_intensity) / sizeof(ucf_line_t); + Serial.println("Motion Intensity for LSM6DSOX MLC"); + Serial.print("UCF Number Line="); + Serial.println(TotalNumberOfLine); + + for (LineCounter = 0; LineCounter < TotalNumberOfLine; LineCounter++) { + if (AccGyr.Write_Reg(ProgramPointer[LineCounter].address, ProgramPointer[LineCounter].data)) { + Serial.print("Error loading the Program to LSM6DSOX at line: "); + Serial.println(LineCounter); + while (1) { + // Led blinking. + digitalWrite(LED_BUILTIN, HIGH); + delay(250); + digitalWrite(LED_BUILTIN, LOW); + delay(250); + } + } + } + + Serial.println("Program loaded inside the LSM6DSOX MLC"); + + AccGyr.Enable_X(); + AccGyr.Set_X_ODR(104.0f); + AccGyr.Set_X_FS(2); + + //Interrupts. + pinMode(INT_1, INPUT); + attachInterrupt(INT_1, INT1Event_cb, RISING); +} + +void loop() +{ + if (mems_event) { + mems_event = 0; + LSM6DSOX_MLC_Status_t status; + AccGyr.Get_MLC_Status(&status); + if (status.is_mlc1) { + uint8_t mlc_out[8]; + AccGyr.Get_MLC_Output(mlc_out); + printMLCStatus(mlc_out[0]); + } + } +} + +void INT1Event_cb() +{ + mems_event = 1; +} + +void printMLCStatus(uint8_t status) +{ + switch (status) { + case 1: + // Reset leds status + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + // LEDB On + digitalWrite(LEDB, HIGH); + Serial.println("Stationary"); + break; + case 4: + // Reset leds status + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + // LEDG On + digitalWrite(LEDG, HIGH); + Serial.println("Medium Intensity"); + break; + case 8: + // Reset leds status + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + // LEDR On + digitalWrite(LEDR, HIGH); + Serial.println("High Intensity"); + break; + default: + // Reset leds status + digitalWrite(LEDB, LOW); + digitalWrite(LEDG, LOW); + digitalWrite(LEDR, LOW); + Serial.println("Unknown"); + break; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h new file mode 100644 index 00000000..98963941 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/MLC/examples/RP2040_MLC_Motion_Intensity/lsm6dsox_motion_intensity.h @@ -0,0 +1,128 @@ +/* + ****************************************************************************** + * @file lsm6dsox_motion_intensity.h + * @author Sensors Software Solution Team + * @brief This file contains the configuration for lsm6dsox_motion_intensity. + * + ****************************************************************************** + * @attention + * + *

    © Copyright (c) 2021 STMicroelectronics. + * All rights reserved.

    + * + * This software component is licensed by ST under BSD 3-Clause license, + * the "License"; You may not use this file except in compliance with the + * License. You may obtain a copy of the License at: + * opensource.org/licenses/BSD-3-Clause + * + */ + +/* Define to prevent recursive inclusion -------------------------------------*/ +#ifndef LSM6DSOX_MOTION_INTENSITY_H +#define LSM6DSOX_MOTION_INTENSITY_H + +#ifdef __cplusplus + extern "C" { +#endif + +/* Includes ------------------------------------------------------------------*/ +#include +#ifndef MEMS_UCF_SHARED_TYPES +#define MEMS_UCF_SHARED_TYPES + +/** Common data block definition **/ +typedef struct { + uint8_t address; + uint8_t data; +} ucf_line_t; + +#endif /* MEMS_UCF_SHARED_TYPES */ + +/** Configuration array generated from Unico Tool **/ +const ucf_line_t lsm6dsox_motion_intensity[] = { + {.address = 0x10, .data = 0x00,}, + {.address = 0x11, .data = 0x00,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x04, .data = 0x00,}, + {.address = 0x05, .data = 0x00,}, + {.address = 0x17, .data = 0x40,}, + {.address = 0x02, .data = 0x11,}, + {.address = 0x08, .data = 0xEA,}, + {.address = 0x09, .data = 0x46,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x09, .data = 0x50,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x0A,}, + {.address = 0x02, .data = 0x11,}, + {.address = 0x08, .data = 0xF2,}, + {.address = 0x09, .data = 0x34,}, + {.address = 0x02, .data = 0x11,}, + {.address = 0x08, .data = 0xFA,}, + {.address = 0x09, .data = 0x3C,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x09, .data = 0x52,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x09, .data = 0x5E,}, + {.address = 0x09, .data = 0x03,}, + {.address = 0x02, .data = 0x31,}, + {.address = 0x08, .data = 0x3C,}, + {.address = 0x09, .data = 0x3F,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x01,}, + {.address = 0x09, .data = 0x10,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x1F,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x02, .data = 0x31,}, + {.address = 0x08, .data = 0x52,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x01, .data = 0x00,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x17, .data = 0x40,}, + {.address = 0x02, .data = 0x31,}, + {.address = 0x08, .data = 0x5E,}, + {.address = 0x09, .data = 0x00,}, + {.address = 0x09, .data = 0x18,}, + {.address = 0x09, .data = 0x11,}, + {.address = 0x09, .data = 0xC0,}, + {.address = 0x09, .data = 0xC8,}, + {.address = 0x09, .data = 0x32,}, + {.address = 0x09, .data = 0x84,}, + {.address = 0x09, .data = 0xE0,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x17, .data = 0x00,}, + {.address = 0x04, .data = 0x00,}, + {.address = 0x05, .data = 0x10,}, + {.address = 0x02, .data = 0x01,}, + {.address = 0x01, .data = 0x00,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x60, .data = 0x35,}, + {.address = 0x01, .data = 0x00,}, + {.address = 0x10, .data = 0x40,}, + {.address = 0x11, .data = 0x00,}, + {.address = 0x5E, .data = 0x02,}, + {.address = 0x01, .data = 0x80,}, + {.address = 0x0D, .data = 0x01,}, + {.address = 0x01, .data = 0x00,} +}; + +#ifdef __cplusplus +} +#endif + +#endif /* LSM6DSOX_MOTION_INTENSITY_H */ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Nano33BLE_System/examples/Nano33_updateBLandSoftDevice/Nano33_updateBLandSoftDevice.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Nano33BLE_System/examples/Nano33_updateBLandSoftDevice/Nano33_updateBLandSoftDevice.ino new file mode 100644 index 00000000..ccbccd9a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Nano33BLE_System/examples/Nano33_updateBLandSoftDevice/Nano33_updateBLandSoftDevice.ino @@ -0,0 +1,239 @@ +/* + * This sketch allows to support Soft Devices on the Arduino Nano 33 BLE (Sense). + * + * To be able to support Soft Devices, the bootloader first needs to be updated. + * The new bootloader is fully backwards compatible with standard sketches. + * ----------------------------------------------------------------------- + * + * INSTRUCTIONS + * + * 1) Upload this sketch on the Nano 33 BLE to download the new bootloader into the flash. + * You can choose whether to update only the bootloader or the bootloader plus SoftDevice. + * Make a choice through the Serial monitor. + * + * 2) After flashing the bootloader the sketch asks if you want to upload the SoftDevice. + * This is required for the OpenMV firmware to work. + * After completion, the board will reboot and enter the bootloader mode. + * + * 3) Now you can upload a sketch that uses the SoftDevice at 0x26000, using the following bossac command + * + * /path/to/bossac -d --port=yourPort --offset=0x16000 -U -i -e -w /path/to/sketch.bin -R + * + * Or you can still upload a standard sketch from the IDE at 0x10000. This will of course overwrite the SoftDevice. + * So if you want to run a SoftDevice-related sketch, always remember to upload this sketch before and re-flash the SoftDevice. + * + * To create a custom SoftDevice follow this procedure: + * + * 1) Convert your SoftDevice binary to a SoftDevice.h . + * The nRF5-SDK website provides a SoftDevice.hex, so run the following commands: + * + * objcopy --input-target=ihex --output-target=binary --gap-fill 0xff SoftDevice.hex SoftDevice.bin + * xxd -i SoftDevice.bin > SoftDevice.h + * + * 2) Copy the content of the generated header file to SoftDevice.h + * + * 3) Run this sketch again and flash the SoftDevice. + */ + +#include "FlashIAP.h" +#include "MBR.h" +#include "bootloader.h" +#include "nrf_nvmc.h" +#include "SoftDevice.h" + +#define SOFTDEVICE_ADDR (0xA0000) +#define SOFTDEVICE_INFO_ADDR (0xFF000) +#define MBR_ADDR (0x0) +#define BOOTLOADER_ADDR (0xE0000) +#define UICR_BOOT_ADDR (0x10001014) + +#define BOOTLOADER_SIZE nano33_bootloader_hex_len +const unsigned int magic = 0x5f27a93d; + +mbed::FlashIAP flash; + +bool hasLatestBootloader(){ + //Check if the CRC32 of the flashed bootloader + //matches the CRC32 of the provided bootloader binary + return getCurrentBootloaderCrc() == getTargetBootloaderCrc(); +} + +bool getUserConfirmation(){ + while (true){ + if (Serial.available()){ + char choice = Serial.read(); + switch (choice){ + case 'y': + case 'Y': + return true; + case 'n': + case 'N': + return false; + default: + continue; + } + } + } +} + +void applyUpdate(uint32_t address, const unsigned char payload[], long len, uint32_t bin_pointer = 0) { + uint32_t flash_pointer = 0; + const uint32_t page_size = flash.get_page_size(); + char *page_buffer = new char[page_size]; + uint32_t addr = address; + + uint32_t sector_size = flash.get_sector_size(addr); + uint32_t next_sector = addr + sector_size; + bool sector_erased = false; + size_t pages_flashed = 0; + uint32_t percent_done = 0; + + while (true) { + + if (flash_pointer >= len) { + break; + } + + flash.erase(addr + flash_pointer, sector_size); + + if ((len - flash_pointer) < sector_size) { + sector_size = len - flash_pointer; + } + + // Program page + flash.program(&payload[bin_pointer], addr + flash_pointer, sector_size); + Serial.print("Flash Address = "); + Serial.println(addr + flash_pointer, HEX); + + bin_pointer = bin_pointer + sector_size; + flash_pointer = flash_pointer + sector_size; + + uint32_t percent_done = flash_pointer * 100 / len; + Serial.println("Flashed " + String(percent_done) + "%"); + } + Serial.println(); + + delete[] page_buffer; +} + +void updateBootloader(){ + Serial.println("This sketch modifies the Nano33 bootloader to support Soft Devices."); + Serial.println(); + + flash.init(); + + Serial.println("Flashing MBR..."); + applyUpdate(MBR_ADDR, MBR_bin, MBR_bin_len); + + Serial.println("Flashing bootloader..."); + applyUpdate(BOOTLOADER_ADDR, nano33_bootloader_hex, nano33_bootloader_hex_len); + + Serial.print("Bootloader 32bit CRC is: "); + uint32_t crc32 = getTargetBootloaderCrc(); + Serial.println(crc32, HEX); + + Serial.println("Writing in UICR memory the address of the new bootloader..."); + nrf_nvmc_write_word(UICR_BOOT_ADDR, BOOTLOADER_ADDR); + + flash.deinit(); + + Serial.println(); + Serial.println("Bootloader update successfully completed!\n"); +} + +void updateSoftDevice(){ + flash.init(); + + Serial.println("Storing SoftDevice length info at 0xFF000..."); + writeSoftDeviceLen(SOFTDEVICE_INFO_ADDR); + + Serial.println("Flashing SoftDevice..."); + applyUpdate(SOFTDEVICE_ADDR, Softdevice_bin, Softdevice_bin_len - 4096, 4096); + + flash.deinit(); + + Serial.println(); + Serial.println("SoftDevice update complete! The board is restarting..."); + NVIC_SystemReset(); +} + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + if(!hasLatestBootloader()){ + Serial.println("Your bootloader version is outdated (update required for Soft Device support)."); + Serial.println("Would you like to update it? Y/N"); + + if(getUserConfirmation()){ + updateBootloader(); + } + } + + if(hasLatestBootloader()){ + Serial.println("Would you like to install the Soft Device (required for OpenMV)? Y/N"); + if(getUserConfirmation()){ + updateSoftDevice(); + } + } + + Serial.println("Done. You may now disconnect the board."); +} + +uint32_t getTargetBootloaderCrc() { + uint32_t mask = 0; + uint32_t crc = 0xFFFFFFFF; + uint32_t b = 0; + uint8_t bootByte = 0; + + int iterations = BOOTLOADER_SIZE; + + for (int i=0; i Serial Plotter) + + Circuit: + - Arduino Nano 33 BLE board, or + - Arduino Nano RP2040 Connect, or + - Arduino Portenta H7 board plus Portenta Vision Shield + + This example code is in the public domain. +*/ + +#include + +// default number of output channels +static const char channels = 1; + +// default PCM output frequency +static const int frequency = 16000; + +// Buffer to read samples into, each sample is 16-bits +short sampleBuffer[512]; + +// Number of audio samples read +volatile int samplesRead; + +void setup() { + Serial.begin(9600); + while (!Serial); + + // Configure the data receive callback + PDM.onReceive(onPDMdata); + + // Optionally set the gain + // Defaults to 20 on the BLE Sense and 24 on the Portenta Vision Shield + // PDM.setGain(30); + + // Initialize PDM with: + // - one channel (mono mode) + // - a 16 kHz sample rate for the Arduino Nano 33 BLE Sense + // - a 32 kHz or 64 kHz sample rate for the Arduino Portenta Vision Shield + if (!PDM.begin(channels, frequency)) { + Serial.println("Failed to start PDM!"); + while (1); + } +} + +void loop() { + // Wait for samples to be read + if (samplesRead) { + + // Print samples to the serial monitor or plotter + for (int i = 0; i < samplesRead; i++) { + if(channels == 2) { + Serial.print("L:"); + Serial.print(sampleBuffer[i]); + Serial.print(" R:"); + i++; + } + Serial.println(sampleBuffer[i]); + } + + // Clear the read count + samplesRead = 0; + } +} + +/** + * Callback function to process the data from the PDM microphone. + * NOTE: This callback is executed as part of an ISR. + * Therefore using `Serial` to print messages inside this function isn't supported. + * */ +void onPDMdata() { + // Query the number of available bytes + int bytesAvailable = PDM.available(); + + // Read into the sample buffer + PDM.read(sampleBuffer, bytesAvailable); + + // 16-bit, 2 bytes per sample + samplesRead = bytesAvailable / 2; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDCARD/examples/TestSDCARD/TestSDCARD.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDCARD/examples/TestSDCARD/TestSDCARD.ino new file mode 100644 index 00000000..1b1b0fb5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDCARD/examples/TestSDCARD/TestSDCARD.ino @@ -0,0 +1,59 @@ +/* + Portenta - TestSDCARD + + The sketch shows how to mount an SDCARD and list its content. + + The circuit: + - Portenta H7 + Vision Shield + - Portenta H7 + Portenta Breakout + + This example code is in the public domain. +*/ +#include "SDMMCBlockDevice.h" +#include "FATFileSystem.h" + +SDMMCBlockDevice block_device; +mbed::FATFileSystem fs("fs"); + +void setup() { + Serial.begin(9600); + while (!Serial); + + Serial.println("Mounting SDCARD..."); + int err = fs.mount(&block_device); + if (err) { + // Reformat if we can't mount the filesystem + // this should only happen on the first boot + Serial.println("No filesystem found, formatting... "); + err = fs.reformat(&block_device); + } + if (err) { + Serial.println("Error formatting SDCARD "); + while(1); + } + + DIR *dir; + struct dirent *ent; + int dirIndex = 0; + + Serial.println("List SDCARD content: "); + if ((dir = opendir("/fs")) != NULL) { + // Print all the files and directories within directory (not recursively) + while ((ent = readdir (dir)) != NULL) { + Serial.println(ent->d_name); + dirIndex++; + } + closedir (dir); + } else { + // Could not open directory + Serial.println("Error opening SDCARD\n"); + while(1); + } + if(dirIndex == 0) { + Serial.println("Empty SDCARD"); + } +} + +void loop() { + // Empty +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDRAM/examples/SDRAM_operations/SDRAM_operations.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDRAM/examples/SDRAM_operations/SDRAM_operations.ino new file mode 100644 index 00000000..f6e0081f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_SDRAM/examples/SDRAM_operations/SDRAM_operations.ino @@ -0,0 +1,70 @@ +/* + How to interact with external SDRAM on Portenta H7 + + The board comes with an hefty 8MB of external fast RAM, which can be used: + - as a framebuffer (raw mode) + - as an expansion of on-chip RAM to store "standard" data + + This example shows both the usages +*/ + +#include "SDRAM.h" + +REDIRECT_STDOUT_TO(Serial); + +void nonFrameBuffer() { + // Initilize SDRAM for non-framebuffer operations + SDRAM.begin(); // is the same as SDRAM.begin(SDRAM_START_ADDRESS); + + // Now we can malloc() and free() in the whole RAM space + // For example, let's create a 7MB array + uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024); + + // and a small one + uint8_t* mySmallArray = (uint8_t*)SDRAM.malloc(128); + + // and use then as usual + for (int i = 0; i<128; i++) { + myVeryBigArray[i] = i; + mySmallArray[i] = i*2; + } + + // free the memory when you don't need them anymore + SDRAM.free(myVeryBigArray); +} + +void frameBuffer() { + // In case we want a framebuffer-like area at the beginning of the flash, + // simply initialize the memory as + + SDRAM.begin(SDRAM_START_ADDRESS + 2 * 1024 * 1024); + // 2MB of contiguous memory available at the beginning + + uint32_t* framebuffer = (uint32_t*)SDRAM_START_ADDRESS; + + // We can't allocate anymore the huge 7MB array + + uint8_t* myVeryBigArray = (uint8_t*)SDRAM.malloc(7 * 1024 * 1024); + if (myVeryBigArray == NULL) { + Serial.println("Oops, too big :)"); + } + +} + +void setup() { + Serial.begin(115200); + while (!Serial); + + frameBuffer(); + // Uncomment to test the other functionality + // nonFrameBuffer(); + + // Sort of memtest for stability, useful for testing when overclocking + if (SDRAM.test()) { + Serial.println("SDRAM completely functional"); + } +} + +void loop() { + +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_Video/examples/ArduinoLogo/ArduinoLogo.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_Video/examples/ArduinoLogo/ArduinoLogo.ino new file mode 100644 index 00000000..b675117b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_Video/examples/ArduinoLogo/ArduinoLogo.ino @@ -0,0 +1,27 @@ +#include "Portenta_lvgl.h" +#include "Portenta_Video.h" +#include "image.h" + +// Alternatively, any raw RGB565 image can be included on demand using this macro +/* +#define INCBIN_PREFIX +#include "incbin.h" +INCBIN(test, "/home/user/Downloads/test.bin"); +*/ + +int offset; + +void setup() { + portenta_init_video(); + + stm32_LCD_Clear(0); + stm32_LCD_Clear(0); + + offset = ((stm32_getXSize() - 300)) + (stm32_getXSize() * (stm32_getYSize() - 300) / 2) * sizeof(uint16_t); +} + +void loop() { + // Replace texture_raw with testData if using the INCBIN method + // Also, replace 300x300 resolution with the actual one + stm32_LCD_DrawImage((void*)texture_raw, (void *)(getNextFrameBuffer() + offset), 300, 300, DMA2D_INPUT_RGB565); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/KeyboardMouseController_rpc_m4/KeyboardMouseController_rpc_m4.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/KeyboardMouseController_rpc_m4/KeyboardMouseController_rpc_m4.ino new file mode 100644 index 00000000..ad1013ad --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/KeyboardMouseController_rpc_m4/KeyboardMouseController_rpc_m4.ino @@ -0,0 +1,115 @@ +#include "USBHost.h" +#include "RPC.h" + +#ifndef CORE_CM4 +#error "This sketch should be compiled for Portenta (M4 core)" +#endif + +USBHost usb; + +#define MOD_CTRL (0x01 | 0x10) +#define MOD_SHIFT (0x02 | 0x20) +#define MOD_ALT (0x04 | 0x40) +#define MOD_WIN (0x08 | 0x80) + +#define LED_NUM_LOCK 1 +#define LED_CAPS_LOCK 2 +#define LED_SCROLL_LOCK 4 + +static uint8_t key_leds; +static const char knum[] = "1234567890"; +static const char ksign[] = "!@#$%^&*()"; +static const char tabA[] = "\t -=[]\\#;'`,./"; +static const char tabB[] = "\t _+{}|~:\"~<>?"; +// route the key event to stdin + +static void stdin_recvchar(char ch) { + RPC.call("on_key", ch); +} + +static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) +{ + uint8_t modify = keys[0]; + uint8_t key = keys[2]; + uint8_t last_leds = key_leds; + if (key >= KEY_A && key <= KEY_Z) { + char ch = 'A' + key - KEY_A; + if ( (!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK)) ) { + ch += 'a' - 'A'; + } + stdin_recvchar(ch); + } else if (key >= KEY_1 && key <= KEY_0) { + if (modify & MOD_SHIFT) { + stdin_recvchar(ksign[key - KEY_1]); + } else { + stdin_recvchar(knum[key - KEY_1]); + } + } else if (key >= KEY_TAB && key <= KEY_SLASH) { + if (modify & MOD_SHIFT) { + stdin_recvchar(tabB[key - KEY_TAB]); + } else { + stdin_recvchar(tabA[key - KEY_TAB]); + } + } else if (key == KEY_ENTER) { + stdin_recvchar('\r'); + } else if (key == KEY_CAPSLOCK) { + key_leds ^= LED_CAPS_LOCK; + } else if (key == KEY_NUMLOCK) { + key_leds ^= LED_NUM_LOCK; + } else if (key == KEY_SCROLLLOCK) { + key_leds ^= LED_SCROLL_LOCK; + } + + if (key_leds != last_leds) { + tusbh_set_keyboard_led(ep, key_leds); + } + return 0; +} + +static int process_mouse(tusbh_ep_info_t* ep, const uint8_t* mouse) +{ + uint8_t btn = mouse[0]; + int8_t x = ((int8_t*)mouse)[1]; + int8_t y = ((int8_t*)mouse)[2]; + RPC.call("on_mouse", btn, x, y); +} + +static const tusbh_boot_key_class_t cls_boot_key = { + .backend = &tusbh_boot_keyboard_backend, + .on_key = process_key +}; + +static const tusbh_boot_mouse_class_t cls_boot_mouse = { + .backend = &tusbh_boot_mouse_backend, + .on_mouse = process_mouse +}; + +static const tusbh_hid_class_t cls_hid = { + .backend = &tusbh_hid_backend, + //.on_recv_data = process_hid_recv, + //.on_send_done = process_hid_sent, +}; + +static const tusbh_hub_class_t cls_hub = { + .backend = &tusbh_hub_backend, +}; + +static const tusbh_class_reg_t class_table[] = { + (tusbh_class_reg_t)&cls_boot_key, + (tusbh_class_reg_t)&cls_boot_mouse, + (tusbh_class_reg_t)&cls_hub, + (tusbh_class_reg_t)&cls_hid, + 0, +}; + +void setup() +{ + Serial1.begin(115200); + RPC.begin(); + usb.Init(USB_CORE_ID_HS, class_table); + //usb.Init(USB_CORE_ID_FS, class_table); +} + +void loop() { + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/Portenta_lvgl.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/Portenta_lvgl.ino new file mode 100644 index 00000000..5cdbc6ae --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/Portenta_lvgl.ino @@ -0,0 +1,15 @@ +#include "Portenta_lvgl.h" +#include "lv_demo_widgets.h" + +void setup() { + portenta_init_video(); + lv_demo_widgets(); +} + +void loop() { +#if LVGL_VERSION_MAJOR > 7 + lv_timer_handler(); +#else + lv_task_handler(); +#endif +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/lv_demo_widgets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/lv_demo_widgets.h new file mode 100644 index 00000000..164d4f0f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/Portenta_lvgl/lv_demo_widgets.h @@ -0,0 +1,38 @@ +/** + * @file lv_demo_widgets.h + * + */ + +#ifndef LV_DEMO_WIDGETS_H +#define LV_DEMO_WIDGETS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void lv_demo_widgets(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_DEMO_WIDGETS_H*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/lvgl_rpc_usb_mouse/lvgl_rpc_usb_mouse.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/lvgl_rpc_usb_mouse/lvgl_rpc_usb_mouse.ino new file mode 100644 index 00000000..a0fb69bb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Portenta_lvgl/examples/lvgl_rpc_usb_mouse/lvgl_rpc_usb_mouse.ino @@ -0,0 +1,112 @@ +#include "Portenta_lvgl.h" +#include "RPC.h" +#include "USBHost.h" + +int16_t touchpad_x = 0; +int16_t touchpad_y = 0; +uint8_t button = 0; +static lv_indev_drv_t indev_drv_mouse; +static lv_indev_drv_t indev_drv_btn; +static lv_obj_t * myCustomLabel; + +void btn_event_cb(lv_obj_t * myCustomLabel, lv_event_t event) +{ + if (event == LV_EVENT_CLICKED) { + lv_label_set_text(myCustomLabel , "ButtonClicked"); + } +} + +void on_mouse(uint8_t btn, int8_t x, int8_t y) { + Serial1.print("Mouse: "); + Serial1.print(btn); + Serial1.print(" "); + Serial1.print(x); + Serial1.print(" "); + Serial1.println(y); + touchpad_x += x; + touchpad_y += y; + if (touchpad_x < 0) { + touchpad_x = 0; + } + if (touchpad_y < 0) { + touchpad_y = 0; + } + button = btn; +} + +void on_key(char ch) { + Serial1.print("Keyboard: "); + Serial1.println(ch); +} + +bool my_input_read(lv_indev_drv_t * drv, lv_indev_data_t*data) +{ + data->point.x = touchpad_x; + data->point.y = touchpad_y; + data->state = LV_INDEV_STATE_REL; + return false; /*No buffering now so no more data read*/ +} + +bool button_read(lv_indev_drv_t * drv, lv_indev_data_t*data){ + static uint32_t last_btn = 0; /*Store the last pressed button*/ + int btn_pr = button - 1; /*Get the ID (0,1,2...) of the pressed button*/ + if(btn_pr >= 0) { /*Is there a button press? (E.g. -1 indicated no button was pressed)*/ + last_btn = btn_pr; /*Save the ID of the pressed button*/ + data->state = LV_INDEV_STATE_PR; /*Set the pressed state*/ + } else { + data->state = LV_INDEV_STATE_REL; /*Set the released state*/ + } + + data->btn_id = last_btn; /*Save the last button*/ + + return false; /*No buffering now so no more data read*/ +} +void setup() { + // put your setup code here, to run once: + RPC.begin(); + Serial1.begin(115200); + RPC.bind("on_mouse", on_mouse); + RPC.bind("on_key", on_key); + portenta_init_video(); + + // Mouse pointer init + lv_indev_drv_init(&indev_drv_mouse); /*Basic initialization*/ + indev_drv_mouse.type = LV_INDEV_TYPE_POINTER; + indev_drv_mouse.read_cb = my_input_read; + lv_indev_t * my_indev_mouse = lv_indev_drv_register(&indev_drv_mouse); + + // Mouse pointer + lv_obj_t * cursor_obj = lv_img_create(lv_scr_act(), NULL); //create object + lv_label_set_text(cursor_obj, "Sys layer"); + lv_indev_set_cursor(my_indev_mouse, cursor_obj); // connect the object to the driver + + // Mouse press + lv_indev_drv_init(&indev_drv_btn); /*Basic initialization*/ + indev_drv_btn.type = LV_INDEV_TYPE_BUTTON; + indev_drv_btn.read_cb = button_read; + lv_indev_t * my_indev_btn = lv_indev_drv_register(&indev_drv_btn); + + //Set your objects + myCustomLabel = lv_label_create(lv_scr_act(), NULL); + lv_obj_align(myCustomLabel, NULL, LV_ALIGN_CENTER, 0, 0); + lv_label_set_text(myCustomLabel , "Button"); + + /*Assign buttons to points on the screen*/ + static const lv_point_t btn_points[1] = { + {720/2, 480/2}, /*Button 0 -> x:10; y:10*/ + }; + lv_indev_set_button_points(my_indev_btn, btn_points); + + + //Create a task + //lv_task_create(label_refresher_task, 1000, LV_TASK_PRIO_MID, NULL); + + //Assign a callback to the button + lv_obj_set_event_cb(myCustomLabel, btn_event_cb); +} + +void loop() { + // put your main code here, to run repeatedly: + lv_task_handler(); + //delay(3); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/BootM4_from_SDRAM/BootM4_from_SDRAM.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/BootM4_from_SDRAM/BootM4_from_SDRAM.ino new file mode 100644 index 00000000..de446117 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/BootM4_from_SDRAM/BootM4_from_SDRAM.ino @@ -0,0 +1,85 @@ +#ifdef CORE_CM7 + +#include "SDRAM.h" +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "FATFileSystem.h" +#include "PluggableUSBMSD.h" + +QSPIFBlockDevice root; +mbed::MBRBlockDevice ota_data(&root, 2); +mbed::FATFileSystem ota_data_fs("fs"); + +void USBMSD::begin() +{ +} + +USBMSD MassStorage(&root); + +long getFileSize(FILE *fp) { + fseek(fp, 0, SEEK_END); + int size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + return size; +} + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + while (!Serial); + + SDRAM.begin(0); + + int err = ota_data_fs.mount(&ota_data); + if (err) { + Serial.println("Please run WiFiFirmwareUpdater once"); + while (1) { + delay(10000); + } + } + + // Copy M4 firmware to SDRAM + FILE* fw = fopen("/fs/fw.bin", "r"); + if (fw == NULL) { + Serial.println("Please copy a firmware for M4 core in the PORTENTA mass storage"); + Serial.println("When done, please unmount the mass storage and reset the board"); + MassStorage.begin(); + while (1) { + delay(10000); + } + } + fread((uint8_t*)CM4_BINARY_START, getFileSize(fw), 1, fw); + fclose(fw); + + bootM4(); +} + +void loop() { + // put your main code here, to run repeatedly: + delay(10000); +} + +#elif defined(CORE_CM4) + +#warning "Compiling a Blink, change the delay or the colour and then copy the .bin into PORTENTA mass storage as fw.bin" + +int led = LEDB; +int delay_ms = 1000; + +void setup() { + pinMode(led, OUTPUT); +} + +void loop() { + digitalWrite(led, HIGH); + delay(delay_ms); + digitalWrite(led, LOW); + delay(delay_ms); +} + +#else + +#error Wrong target selected + +#endif \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/PortentaX8_EchoServer/PortentaX8_EchoServer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/PortentaX8_EchoServer/PortentaX8_EchoServer.ino new file mode 100644 index 00000000..6ea35282 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/PortentaX8_EchoServer/PortentaX8_EchoServer.ino @@ -0,0 +1,42 @@ +#include "RPC.h" +#include "SerialRPC.h" + +/* + * This sketch demonstrates how to interact with the Portenta X8 Serial port (over USB) + * On the board, launch both 'proxy' and 'example' binaries (from https://github.com/arduino/portentax8-m4-proxy) + * The M4 provides the 'subtract' API (which will be invoked by 'example' + * It also provides a full duplex Serial-like interface that is proxies through the serial monitor + * Last but not leas, when you write 'echo' the corresponding function in 'example' will be triggered + */ + +int subtract(int a, int b) { + return a-b; +} + +void setup() { + // put your setup code here, to run once: + Serial.begin(115200); + RPC.bind("subtract", subtract); + delay(1000); +} + +int i = 0; +void loop() { + + //RPC.print("hello"); + //RPC.send("echo", "test"); + //auto res = RPC.call("add", 5, 8).as(); + //RPC.send("echo", String(res).c_str()); + + String str = ""; + while (Serial.available()) { + str += (char)Serial.read(); + } + if (str != "") { + Serial.print(str); + } + if (str.startsWith("echo")) { + delay(100); + RPC.send("echo", "test"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/RPC_m4/RPC_m4.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/RPC_m4/RPC_m4.ino new file mode 100644 index 00000000..5d40f382 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/RPC_m4/RPC_m4.ino @@ -0,0 +1,110 @@ +#include "Arduino.h" +#include "RPC.h" + +using namespace rtos; + +Thread subtractThread; + +/** + * Returns the CPU that's currently running the sketch (M7 or M4) + * Note that the sketch has to be uploaded to both cores. + **/ +String currentCPU() { + if (HAL_GetCurrentCPUID() == CM7_CPUID) { + return "M7"; + } else { + return "M4"; + } +} + +/** + * Adds two numbers and returns the sum + **/ +int addOnM7(int a, int b) { + Serial.println(currentCPU() + ": executing add with " + String(a) + " and " + String(b)); + delay(700); // Simulate work + return a + b; +} + +/** + * Subtracts two numbers and returns the difference + **/ +int subtractOnM7(int a, int b) { + Serial.println(currentCPU() + ": executing subtract with " + String(a) + " and " + String(b)); + delay(700); // Simulate work + return a - b; +} + +void callSubstractFromM4() { + while (true) { + delay(700); // Wait 700ms with the next calculation + int a = random(100); // Generate a random number + int b = random(100); // Generate a random number + RPC.println(currentCPU() + ": calling subtract with " + String(a) + " and " + String(b)); + + auto result = RPC.call("remoteSubtract", a, b).as(); + // Prints the result of the calculation + RPC.println(currentCPU() + ": Result is " + String(a) + " - " + String(b) + " = " + String(result)); + } +} + +void setup() { + + pinMode(LED_BUILTIN, OUTPUT); + + // Initialize RPC library; this also boots the M4 core + RPC.begin(); + Serial.begin(115200); + //while (!Serial) {} // Uncomment this to wait until the Serial connection is ready + + // Both CPUs will execute this instruction, just at different times + randomSeed(analogRead(A0)); // Initializes the pseudo-random number generator + + if (currentCPU() == "M7") { + // M7 CPU becomes the server, so it makes two functions available under the defined names + RPC.bind("remoteAdd", addOnM7); + RPC.bind("remoteSubtract", subtractOnM7); + } + + if (currentCPU() == "M4") { + // M4 CPU becomes the client, so spawns a thread that will call subtractOnM7() every 700ms + subtractThread.start(callSubstractFromM4); + } +} + +void loop() { + + if (currentCPU() == "M4") { + // On M4 let's blink an LED. While it's blinking, the callSubstractFromM4() thread is running, + // so it will execute roughly 3 times (2000 / 700 ms) + digitalWrite(LED_BUILTIN, LOW); + delay(1000); + digitalWrite(LED_BUILTIN, HIGH); + delay(1000); + + int a = random(100); + int b = random(100); + // PRC.print works like a Serial port, but it needs a receiver (in this case the M7) + // to actually print the strings to the Serial port + RPC.println(currentCPU() + ": calling add with " + String(a) + " and " + String(b)); + // Let's invoke addOnM7() and wait for a result. + // This will be delayed by the forced delay() in addOnM7() function + // Exercise: if you are not interested in the result of the operation, what operation would you invoke? + auto result = RPC.call("remoteAdd", a, b).as(); + RPC.println(currentCPU() + ": Result is " + String(a) + " + " + String(b) + " = " + String(result)); + } + + if (currentCPU() == "M7") { + // On M7, let's print everything that is received over the RPC1 stream interface + // Buffer it, otherwise all characters will be interleaved by other prints + String buffer = ""; + while (RPC.available()) { + buffer += (char)RPC.read(); // Fill the buffer with characters + } + + if (buffer.length() > 0) { + Serial.print(buffer); + } + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino new file mode 100644 index 00000000..38cf7d33 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/RPC/examples/SerialPassthrough_RPC/SerialPassthrough_RPC.ino @@ -0,0 +1,24 @@ +#include "Arduino.h" +#include "RPC.h" + +void setup() { + Serial.begin(115200); + RPC.begin(); +} + +void loop() { + String data = ""; + while (RPC.available()) { + data += (char)RPC.read(); + } + if (data != "") { + Serial.write(data.c_str(), data.length()); + } + data = ""; + while (Serial.available()) { + data += (char)Serial.read(); + } + if (data != "") { + RPC.write(data.c_str(), data.length()); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XImportPublicKey/SE05XImportPublicKey.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XImportPublicKey/SE05XImportPublicKey.ino new file mode 100644 index 00000000..25e17cb9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XImportPublicKey/SE05XImportPublicKey.ino @@ -0,0 +1,86 @@ +/* + SE05X ImportAndVerify + + This sketch uses the SE05X to generate a new EC NIST P-256 keypair + and store it with id 999, then input buffer SHA256 is signed with the private + key. The public key is imported with another id 899 into SE05X and the + signature is checked using the imported public key. + + Circuit: + - Portenta + - Nicla Vision +*/ + +#include + +const byte input[64] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f +}; + +void printBufferHex(const byte input[], size_t inputLength) { + for (int i = 0; i < inputLength; i++) { + Serial.print(input[i] >> 4, HEX); + Serial.print(input[i] & 0x0f, HEX); + } + Serial.println(); +} + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!SE05X.begin()) { + Serial.println("Failed to communicate with SE05X!"); + while (1); + } + + const int privKeyId = 999; + const int publKeyId = 899; + byte derBuf[256]; + size_t derSize; + + SE05X.generatePrivateKey(privKeyId, derBuf, sizeof(derBuf), &derSize); + + // print the input + Serial.print("Input is: "); + printBufferHex(input, sizeof(input)); + + //calculate the input SHA256 + byte sha256[256]; + size_t sha256Len; + SE05X.SHA256(input, sizeof(input), sha256, sizeof(sha256), &sha256Len); + Serial.print("Input SHA256 is: "); + printBufferHex(sha256, sha256Len); + + // calculate the signature, input MUST be SHA256 + byte signature[256]; + size_t signatureLen; + SE05X.Sign(privKeyId, sha256, sha256Len, signature, sizeof(signature), &signatureLen); + + // print the signature + Serial.print("Signature using KeyId "); + Serial.print(privKeyId); + Serial.print(" is: "); + printBufferHex(signature, signatureLen); + + Serial.println(); + + SE05X.importPublicKey(publKeyId, derBuf, derSize); + + // To make the signature verifcation fail, uncomment the next line: + // signature[0] = 0x00; + + // validate the signature + if (SE05X.Verify(publKeyId, sha256, sha256Len, signature, signatureLen)) { + Serial.println("Verified signature successfully :D"); + } else { + Serial.println("oh no! failed to verify signature :("); + } +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XPrivateKey/SE05XPrivateKey.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XPrivateKey/SE05XPrivateKey.ino new file mode 100644 index 00000000..f30ebc65 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XPrivateKey/SE05XPrivateKey.ino @@ -0,0 +1,41 @@ +/* + SE05X Private Key + + This sketch uses the SE05X to generate a new EC NIST P-256 keypair + and store it with id 999, then the public key is printed in DER format. + + Circuit: + - Portenta + - Nicla Vision +*/ + +#include + +void printBufferHex(const byte input[], size_t inputLength) { + for (int i = 0; i < inputLength; i++) { + Serial.print(input[i] >> 4, HEX); + Serial.print(input[i] & 0x0f, HEX); + } + Serial.println(); +} + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!SE05X.begin()) { + Serial.println("Failed to communicate with SE05X!"); + while (1); + } + + const int KeyId = 999; + byte derBuf[256]; + size_t derSize; + + SE05X.generatePrivateKey(KeyId, derBuf, sizeof(derBuf), &derSize); + printBufferHex(derBuf, derSize); +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XRandomNumber/SE05XRandomNumber.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XRandomNumber/SE05XRandomNumber.ino new file mode 100644 index 00000000..2a3e216c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XRandomNumber/SE05XRandomNumber.ino @@ -0,0 +1,29 @@ +/* + SE05X Random Number + + This sketch uses the SE05X to generate a random number + every second and print it to the Serial monitor + + Circuit: + - Portenta + - Nicla Vision +*/ + +#include + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!SE05X.begin()) { + Serial.println("Failed to communicate with SE05X!"); + while (1); + } +} + +void loop() { + Serial.print("Random number = "); + Serial.println(SE05X.random(65535)); + + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XSignAndVerify/SE05XSignAndVerify.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XSignAndVerify/SE05XSignAndVerify.ino new file mode 100644 index 00000000..1209ac14 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/SE05X/examples/SE05XSignAndVerify/SE05XSignAndVerify.ino @@ -0,0 +1,82 @@ +/* + SE05X SignAndVerify + + This sketch uses the SE05X to generate a new EC NIST P-256 keypair + and store it with id 999, then input buffer SHA256 is signed with the private + key and verified with the public key. + + Circuit: + - Portenta + - Nicla Vision +*/ + +#include + +const byte input[64] = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f +}; + +void printBufferHex(const byte input[], size_t inputLength) { + for (int i = 0; i < inputLength; i++) { + Serial.print(input[i] >> 4, HEX); + Serial.print(input[i] & 0x0f, HEX); + } + Serial.println(); +} + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!SE05X.begin()) { + Serial.println("Failed to communicate with SE05X!"); + while (1); + } + + const int KeyId = 999; + byte derBuf[256]; + size_t derSize; + + SE05X.generatePrivateKey(KeyId, derBuf, sizeof(derBuf), &derSize); + + // print the input + Serial.print("Input is: "); + printBufferHex(input, sizeof(input)); + + //calculate the input SHA256 + byte sha256[256]; + size_t sha256Len; + SE05X.SHA256(input, sizeof(input), sha256, sizeof(sha256), &sha256Len); + Serial.print("Input SHA256 is: "); + printBufferHex(sha256, sha256Len); + + // calculate the signature, input MUST be SHA256 + byte signature[256]; + size_t signatureLen; + SE05X.Sign(KeyId, sha256, sha256Len, signature, sizeof(signature), &signatureLen); + + // print the signature + Serial.print("Signature using KeyId "); + Serial.print(KeyId); + Serial.print(" is: "); + printBufferHex(signature, signatureLen); + + Serial.println(); + + // To make the signature verifcation fail, uncomment the next line: + // signature[0] = 0x00; + + // validate the signature + if (SE05X.Verify(KeyId, sha256, sha256Len, signature, signatureLen)) { + Serial.println("Verified signature successfully :D"); + } else { + Serial.println("oh no! failed to verify signature :("); + } +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFReadPartitions/QSPIFReadPartitions.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFReadPartitions/QSPIFReadPartitions.ino new file mode 100644 index 00000000..a2f2e2ca --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFReadPartitions/QSPIFReadPartitions.ino @@ -0,0 +1,129 @@ +#include + +struct __attribute__((packed)) mbrEntry { + uint8_t status; + uint8_t chsStart[3]; + uint8_t type; + uint8_t chsStop[3]; + uint32_t lbaOffset; + uint32_t lbaSize; +}; + +struct __attribute__((packed)) mbrTable { + mbrEntry entries[4]; + uint8_t signature[2]; +}; + +using namespace mbed; + +unsigned long allocatedSpace {}; + +void setup() +{ + Serial.begin(115200); + for (const auto timeout = millis() + 2500; !Serial && millis() < timeout; delay(250)) + ; + + auto bd = BlockDevice::get_default_instance(); + auto ret = bd->init(); + if (ret) { + Serial.println("ERROR! Unable to read the Block Device."); + while (true) + ; + } + + // Allocate smallest buffer necessary to write MBR + auto buffer_size = std::max(bd->get_program_size(), sizeof(mbrTable)); + + // Prevent alignment issues + if (buffer_size % bd->get_program_size() != 0) { + buffer_size += bd->get_program_size() - (buffer_size % bd->get_program_size()); + } + + auto buffer = new uint8_t[buffer_size]; + + // Check for existing MBR + ret = bd->read(buffer, 512 - buffer_size, buffer_size); + if (ret) { + Serial.println("ERROR! Unable to read the Master Boot Record"); + + delete[] buffer; + while (true) + ; + } + + auto table_start_offset = buffer_size - sizeof(mbrTable); + auto table = reinterpret_cast(&buffer[table_start_offset]); + + Serial.println(); + Serial.print("Looking for Partitions on the Flash Memory... "); + + if (table->signature[0] != 0x55 || table->signature[1] != 0xAA) { + Serial.println("MBR Not Found"); + Serial.println("Flash Memory doesn't have partitions."); + } else { + + Serial.println("MBR Found"); + Serial.print("Boot Signature: 0x"); + Serial.print(table->signature[0], HEX); + Serial.println(table->signature[1], HEX); + + Serial.println(); + Serial.println("Printing Partitions Table and Info..."); + + auto part { 1u }; + for (auto const& entry : table->entries) { + Serial.println("================================"); + Serial.print("Partition: "); + Serial.println(part++); + + Serial.print("Bootable: "); + Serial.println(entry.status == 0 ? "No" : "Yes"); + + Serial.print("Type: 0x"); + if (entry.type < 0x10) + Serial.print(0); + Serial.println(entry.type, HEX); + + if (entry.type == 0x00) + continue; + + Serial.print("Size [KBytes]: "); + Serial.println((entry.lbaSize * 4096) >> 10); + + allocatedSpace += entry.lbaSize * 4096; + + Serial.print("Start [C/H/S]: "); + Serial.print(entry.chsStart[0]); + Serial.print("/"); + Serial.print(entry.chsStart[1]); + Serial.print("/"); + Serial.println(entry.chsStart[2]); + + Serial.print("Stop [C/H/S]: "); + Serial.print(entry.chsStop[0]); + Serial.print("/"); + Serial.print(entry.chsStop[1]); + Serial.print("/"); + Serial.println(entry.chsStop[2]); + + Serial.println(); + } + + Serial.println(); + Serial.println("No more partitions are present."); + } + + Serial.println(); + Serial.print("Total Space [KBytes]: "); + Serial.println(bd->size() >> 10); + Serial.print("Allocated Space [KBytes]: "); + Serial.println(allocatedSpace >> 10); + Serial.print("Unallocated Space [KBytes]: "); + Serial.println((bd->size() - allocatedSpace) >> 10); +} + +void loop() +{ + delay(10000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino new file mode 100644 index 00000000..48d7018b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/QSPIFormat/QSPIFormat.ino @@ -0,0 +1,109 @@ +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "LittleFileSystem.h" +#include "FATFileSystem.h" + +#ifndef CORE_CM7 + #error Format QSPI flash by uploading the sketch to the M7 core instead of the M4 core. +#endif + + +QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); +mbed::MBRBlockDevice wifi_data(&root, 1); +mbed::MBRBlockDevice ota_data(&root, 2); +mbed::MBRBlockDevice user_data(&root, 3); +mbed::FATFileSystem wifi_data_fs("wlan"); +mbed::FATFileSystem ota_data_fs("fs"); +mbed::FileSystem * user_data_fs; + +bool waitResponse() { + bool confirmation = false; + while (confirmation == false) { + if (Serial.available()) { + char choice = Serial.read(); + switch (choice) { + case 'y': + case 'Y': + confirmation = true; + return true; + break; + case 'n': + case 'N': + confirmation = true; + return false; + break; + default: + continue; + } + } + } +} + +void setup() { + + Serial.begin(115200); + while (!Serial); + + Serial.println("Available partition schemes:"); + Serial.println("\nPartition scheme 1"); + Serial.println("Partition 1: WiFi firmware and certificates 1MB"); + Serial.println("Partition 2: OTA and user data 13MB"); + Serial.println("\nPartition scheme 2"); + Serial.println("Partition 1: WiFi firmware and certificates 1MB"); + Serial.println("Partition 2: OTA 5MB"); + Serial.println("Partition 3: User data 8MB"), + Serial.println("\nDo you want to use partition scheme 1? Y/[n]"); + Serial.println("If No, partition scheme 2 will be used."); + bool default_scheme = waitResponse(); + + Serial.println("\nWARNING! Running the sketch all the content of the QSPI flash will be erased."); + Serial.println("Do you want to proceed? Y/[n]"); + + if (true == waitResponse()) { + mbed::MBRBlockDevice::partition(&root, 1, 0x0B, 0, 1024 * 1024); + if(default_scheme) { + mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 14 * 1024 * 1024, 14 * 1024 * 1024); + mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1024 * 1024, 14 * 1024 * 1024); + // use space from 15.5MB to 16 MB for another fw, memory mapped + } else { + mbed::MBRBlockDevice::partition(&root, 2, 0x0B, 1024 * 1024, 6 * 1024 * 1024); + mbed::MBRBlockDevice::partition(&root, 3, 0x0B, 6 * 1024 * 1024, 14 * 1024 * 1024); + // use space from 15.5MB to 16 MB for another fw, memory mapped + } + + int err = wifi_data_fs.reformat(&wifi_data); + if (err) { + Serial.println("Error formatting WiFi partition"); + } + + err = ota_data_fs.reformat(&ota_data); + if (err) { + Serial.println("Error formatting OTA partition"); + } + + if(!default_scheme) { + Serial.println("\nDo you want to use LittleFS to format user data partition? Y/[n]"); + Serial.println("If No, FatFS will be used to format user partition."); + + if (true == waitResponse()) { + Serial.println("Formatting user partition with LittleFS."); + user_data_fs = new mbed::LittleFileSystem("user"); + } else { + Serial.println("Formatting user partition with FatFS."); + user_data_fs = new mbed::FATFileSystem("user"); + } + + err = user_data_fs->reformat(&user_data); + if (err) { + Serial.println("Error formatting user partition"); + } + } + Serial.println("\nQSPI Flash formatted!"); + } + + Serial.println("It's now safe to reboot or disconnect your board."); +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_getBootloaderInfo/STM32H747_getBootloaderInfo.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_getBootloaderInfo/STM32H747_getBootloaderInfo.ino new file mode 100644 index 00000000..d77203ab --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_getBootloaderInfo/STM32H747_getBootloaderInfo.ino @@ -0,0 +1,61 @@ +uint8_t* bootloader_data = (uint8_t*)(0x801F000); +uint8_t* bootloader_identification = (uint8_t*)(0x80002F0); + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + uint8_t currentBootloaderVersion = bootloader_data[1]; + String currentBootloaderIdentifier = String(bootloader_identification, 15); + + if(!currentBootloaderIdentifier.equals("MCUboot Arduino")) { + currentBootloaderIdentifier = "Arduino loader"; + } + + Serial.println(currentBootloaderIdentifier); + Serial.println("Magic Number (validation): " + String(bootloader_data[0], HEX)); + Serial.println("Bootloader version: " + String(bootloader_data[1])); + Serial.println("Clock source: " + getClockSource(bootloader_data[2])); + Serial.println("USB Speed: " + getUSBSpeed(bootloader_data[3])); + Serial.println("Has Ethernet: " + String(bootloader_data[4] == 1 ? "Yes" : "No")); + Serial.println("Has WiFi module: " + String(bootloader_data[5] == 1 ? "Yes" : "No")); + Serial.println("RAM size: " + getRAMSize(bootloader_data[6])); + Serial.println("QSPI size: " + String(bootloader_data[7]) + " MB"); + Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No")); + Serial.println("Has Crypto chip: " + String(bootloader_data[9] == 1 ? "Yes" : "No")); +} + +String getUSBSpeed(uint8_t flag) { + switch (flag){ + case 1: + return "USB 2.0/Hi-Speed (480 Mbps)"; + case 2: + return "USB 1.1/Full-Speed (12 Mbps)"; + default: + return "N/A"; + } +} + +String getClockSource(uint8_t flag) { + switch (flag){ + case 0x8: + return "External oscillator"; + case 0x4: + return "External crystal"; + case 0x2: + return "Internal clock"; + default: + return "N/A"; + } +} + +String getRAMSize(uint8_t flag) { + if (flag == 0) { + return "N/A"; + } + return (String(flag) + "MB"); +} + +void loop() { + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino new file mode 100644 index 00000000..0bcb38ba --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/STM32H747_manageBootloader.ino @@ -0,0 +1,326 @@ +#include "FlashIAP.h" +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "LittleFileSystem.h" +#include "FATFileSystem.h" +#if defined(ARDUINO_PORTENTA_H7_M7) +#include "portenta_bootloader.h" +#include "portenta_lite_bootloader.h" +#include "portenta_lite_connected_bootloader.h" +#include "mcuboot_bootloader.h" +#include "ecdsa-p256-encrypt-key.h" +#include "ecdsa-p256-signing-key.h" +#elif defined(ARDUINO_NICLA_VISION) +#include "nicla_vision_bootloader.h" +#endif + +#ifndef CORE_CM7 + #error Update the bootloader by uploading the sketch to the M7 core instead of the M4 core. +#endif + +#define BOOTLOADER_ADDR (0x8000000) +#define SIGNING_KEY_ADDR (0x8000300) +#define ENCRYPT_KEY_ADDR (0x8000400) +#define ENCRYPT_KEY_SIZE (0x0000100) +#define SIGNING_KEY_SIZE (0x0000100) + +mbed::FlashIAP flash; +QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); + +bool writeLoader = false; +bool writeKeys = false; +bool video_available = false; +bool wifi_available = false; +bool MCUboot = false; + +uint32_t bootloader_data_offset = 0x1F000; +uint8_t* bootloader_data = (uint8_t*)(BOOTLOADER_ADDR + bootloader_data_offset); + +uint32_t bootloader_identification_offset = 0x2F0; +uint8_t* bootloader_identification = (uint8_t*)(BOOTLOADER_ADDR + bootloader_identification_offset); + +const unsigned char* bootloader_ptr = &bootloader_mbed_bin[0]; +long bootloader_len = bootloader_mbed_bin_len; + +void setup() { + Serial.begin(115200); + while (!Serial) {} + + uint8_t currentBootloaderVersion = bootloader_data[1]; + String currentBootloaderIdentifier = String(bootloader_identification, 15); + + if(!currentBootloaderIdentifier.equals("MCUboot Arduino")) { + currentBootloaderIdentifier = "Arduino loader"; + } + + Serial.println(currentBootloaderIdentifier); + Serial.println("Magic Number (validation): " + String(bootloader_data[0], HEX)); + Serial.println("Bootloader version: " + String(currentBootloaderVersion)); + Serial.println("Clock source: " + getClockSource(bootloader_data[2])); + Serial.println("USB Speed: " + getUSBSpeed(bootloader_data[3])); + Serial.println("Has Ethernet: " + String(bootloader_data[4] == 1 ? "Yes" : "No")); + Serial.println("Has WiFi module: " + String(bootloader_data[5] == 1 ? "Yes" : "No")); + Serial.println("RAM size: " + getRAMSize(bootloader_data[6])); + Serial.println("QSPI size: " + String(bootloader_data[7]) + " MB"); + Serial.println("Has Video output: " + String(bootloader_data[8] == 1 ? "Yes" : "No")); + Serial.println("Has Crypto chip: " + String(bootloader_data[9] == 1 ? "Yes" : "No")); + + video_available = bootloader_data[8]; + wifi_available = bootloader_data[5]; + +#if defined(ARDUINO_PORTENTA_H7_M7) + Serial.println("\nDo you want to install/update the default Arduino bootloader? Y/[n]"); + Serial.println("Choosing \"No\", will install/update the MCUboot bootloader."); + if(!waitResponse()) { + Serial.println("\nMCUboot has been selected. Do you want to proceed? Y/[n]"); + if (waitResponse()) { + MCUboot = true; + bootloader_ptr = &mcuboot_bin[0]; + bootloader_len = mcuboot_bin_len; + } else { + Serial.println("\nProceeding with the default Arduino bootloader..."); + } + } + if (!MCUboot) { + bootloader_ptr = &bootloader_mbed_bin[0]; + bootloader_len = bootloader_mbed_bin_len; + if (!video_available) { + if (wifi_available) { + bootloader_ptr = &bootloader_mbed_lite_connected_bin[0]; + bootloader_len = bootloader_mbed_lite_connected_bin_len; + } else { + bootloader_ptr = &bootloader_mbed_lite_bin[0]; + bootloader_len = bootloader_mbed_lite_bin_len; + } + } + } +#endif + + uint8_t availableBootloaderVersion = (bootloader_ptr + bootloader_data_offset)[1]; + String availableBootloaderIdentifier = String(bootloader_ptr + bootloader_identification_offset, 15); + + if(!availableBootloaderIdentifier.equals("MCUboot Arduino")) { + availableBootloaderIdentifier = "Arduino loader"; + } + + if (currentBootloaderIdentifier == availableBootloaderIdentifier) { + if (bootloader_data[0] != 0xA0) { + Serial.println("\nA new bootloader version (v" + String(availableBootloaderVersion) + ") is available."); + Serial.println("Do you want to update the bootloader? Y/[n]"); + } else { + if (availableBootloaderVersion > currentBootloaderVersion) { + Serial.print("\nA new bootloader version is available: v" + String(availableBootloaderVersion)); + Serial.println(" (Your version: v" + String(currentBootloaderVersion) + ")"); + Serial.println("Do you want to update the bootloader? Y/[n]"); + } else if (availableBootloaderVersion < currentBootloaderVersion) { + Serial.println("\nA newer bootloader version is already installed: v" + String(currentBootloaderVersion)); + Serial.println("Do you want to downgrade the bootloader to v" + String(availableBootloaderVersion) + "? Y/[n]"); + } else { + Serial.println("\nThe latest version of the bootloader is already installed (v" + String(currentBootloaderVersion) + ")."); + Serial.println("Do you want to update the bootloader anyway? Y/[n]"); + } + } + } else { + Serial.println("\nA different bootloader type is available: v" + String(availableBootloaderVersion)); + Serial.println("Do you want to update the bootloader? Y/[n]"); + } + writeLoader = waitResponse(); + + if (writeLoader) { + if(availableBootloaderIdentifier.equals("MCUboot Arduino")) { + setupMCUBootOTAData(); + + Serial.println("\nThe bootloader comes with a set of default keys to evaluate signing and encryption process"); + Serial.println("If you load the keys, you will need to upload the future sketches with Security Settings -> Signing + Encryption."); + Serial.println("If you select Security Settings -> None, the sketches will not be executed."); + Serial.println("Do you want to load the keys? Y/[n]"); + if (waitResponse()) { + Serial.println("\nPlease notice that loading the keys will enable MCUboot Sketch swap. This will increase the sketch update time after the upload."); + Serial.println("A violet LED will blink until the sketch is ready to run."); + Serial.println("Do you want to proceed loading the default keys? Y/[n]"); + } + writeKeys = waitResponse(); + } + applyUpdate(BOOTLOADER_ADDR); + } else { + Serial.println("It's now safe to reboot or disconnect your board."); + } + +} + +String getUSBSpeed(uint8_t flag) { + switch (flag){ + case 1: + return "USB 2.0/Hi-Speed (480 Mbps)"; + case 2: + return "USB 1.1/Full-Speed (12 Mbps)"; + default: + return "N/A"; + } +} + +String getClockSource(uint8_t flag) { + switch (flag){ + case 0x8: + return "External oscillator"; + case 0x4: + return "External crystal"; + case 0x2: + return "Internal clock"; + default: + return "N/A"; + } +} + +String getRAMSize(uint8_t flag) { + if (flag == 0) { + return "N/A"; + } + return (String(flag) + "MB"); +} + +void printProgress(uint32_t offset, uint32_t size, uint32_t threshold, bool reset) { + static int percent_done = 0; + if (reset == true) { + percent_done = 0; + Serial.println("Flashed " + String(percent_done) + "%"); + } else { + uint32_t percent_done_new = offset * 100 / size; + if (percent_done_new >= percent_done + threshold) { + percent_done = percent_done_new; + Serial.println("Flashed " + String(percent_done) + "%"); + } + } +} + +bool waitResponse() { + bool confirmation = false; + while (confirmation == false) { + if (Serial.available()) { + char choice = Serial.read(); + switch (choice) { + case 'y': + case 'Y': + confirmation = true; + return true; + break; + case 'n': + case 'N': + confirmation = true; + return false; + break; + default: + continue; + } + } + } +} + +void setupMCUBootOTAData() { + mbed::MBRBlockDevice ota_data(&root, 2); + mbed::FATFileSystem ota_data_fs("fs"); + + int err = ota_data_fs.reformat(&ota_data); + if (err) { + Serial.println("Error creating MCUboot files in OTA partition."); + Serial.println("Run QSPIformat.ino sketch to format the QSPI flash and fix the issue."); + } + + FILE* fp = fopen("/fs/scratch.bin", "wb"); + const int scratch_file_size = 128 * 1024; + const char buffer[128] = {0xFF}; + int size = 0; + + Serial.println("\nCreating scratch file"); + printProgress(size, scratch_file_size, 10, true); + while (size < scratch_file_size) { + int ret = fwrite(buffer, sizeof(buffer), 1, fp); + if (ret != 1) { + Serial.println("Error writing scratch file"); + break; + } + size += sizeof(buffer); + printProgress(size, scratch_file_size, 10, false); + } + fclose(fp); + + fp = fopen("/fs/update.bin", "wb"); + const int update_file_size = 15 * 128 * 1024; + size = 0; + + Serial.println("\nCreating update file"); + printProgress(size, update_file_size, 10, true); + while (size < update_file_size) { + int ret = fwrite(buffer, sizeof(buffer), 1, fp); + if (ret != 1) { + Serial.println("Error writing scratch file"); + break; + } + size += sizeof(buffer); + printProgress(size, update_file_size, 5, false); + } + + fclose(fp); +} + +void applyUpdate(uint32_t address) { + long len = bootloader_len; + + flash.init(); + + const uint32_t page_size = flash.get_page_size(); + char *page_buffer = new char[page_size]; + uint32_t addr = address; + uint32_t next_sector = addr + flash.get_sector_size(addr); + bool sector_erased = false; + size_t pages_flashed = 0; + uint32_t percent_done = 0; + + while (true) { + + if (page_size * pages_flashed > len) { + break; + } + + // Erase this page if it hasn't been erased + if (!sector_erased) { + flash.erase(addr, flash.get_sector_size(addr)); + sector_erased = true; + } + + // Program page + flash.program(&bootloader_ptr[page_size * pages_flashed], addr, page_size); + + addr += page_size; + if (addr >= next_sector) { + next_sector = addr + flash.get_sector_size(addr); + sector_erased = false; + } + + if (++pages_flashed % 3 == 0) { + uint32_t percent_done_new = page_size * pages_flashed * 100 / len; + if (percent_done != percent_done_new) { + percent_done = percent_done_new; + Serial.println("Flashed " + String(percent_done) + "%"); + } + } + } + +#if defined(ARDUINO_PORTENTA_H7_M7) + if (writeKeys) { + flash.program(&enc_priv_key, ENCRYPT_KEY_ADDR, ENCRYPT_KEY_SIZE); + flash.program(&ecdsa_pub_key, SIGNING_KEY_ADDR, SIGNING_KEY_SIZE); + } +#endif + + Serial.println("Flashed 100%"); + + delete[] page_buffer; + + flash.deinit(); + Serial.println("\nBootloader update complete. It's now safe to reboot or disconnect your board."); +} + +void loop() { + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-encrypt-key.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-encrypt-key.h new file mode 100644 index 00000000..9af742ff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-encrypt-key.h @@ -0,0 +1,21 @@ +const unsigned char enc_priv_key[] { + 0x30, 0x81, 0x87, 0x02, 0x01, 0x00, 0x30, 0x13, + 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, + 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, + 0x03, 0x01, 0x07, 0x04, 0x6d, 0x30, 0x6b, 0x02, + 0x01, 0x01, 0x04, 0x20, 0x79, 0x72, 0xb6, 0xf3, + 0x62, 0x91, 0x09, 0xbb, 0x35, 0x22, 0xb8, 0x54, + 0x32, 0x3b, 0xfe, 0x1c, 0x9f, 0xa7, 0x10, 0x6f, + 0xba, 0xaf, 0x73, 0x64, 0xd3, 0xf5, 0x31, 0xbc, + 0x28, 0xe7, 0xc9, 0x72, 0xa1, 0x44, 0x03, 0x42, + 0x00, 0x04, 0x6a, 0xc9, 0x20, 0x4c, 0x96, 0xd6, + 0x89, 0xe8, 0xd1, 0x6e, 0x51, 0x04, 0x02, 0x86, + 0xe8, 0x95, 0x0b, 0x22, 0xc4, 0xc9, 0x95, 0x06, + 0x4f, 0xf5, 0x1b, 0xf6, 0xd0, 0xe3, 0x83, 0xd9, + 0xd1, 0x81, 0x66, 0x6e, 0xf2, 0x07, 0x3b, 0x03, + 0xdb, 0xe4, 0xd1, 0xde, 0x7c, 0x43, 0x70, 0x8d, + 0xa2, 0x89, 0xeb, 0x1b, 0xfa, 0xbe, 0x02, 0x5e, + 0x5c, 0xa0, 0x12, 0xdc, 0x23, 0x31, 0xc1, 0xe0, + 0x37, 0xb0, +}; +const unsigned int enc_priv_key_len = 138; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-signing-key.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-signing-key.h new file mode 100644 index 00000000..b57ed163 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/STM32H747_manageBootloader/ecdsa-p256-signing-key.h @@ -0,0 +1,15 @@ +const unsigned char ecdsa_pub_key[] { + 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, 0x86, + 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, + 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x03, + 0x42, 0x00, 0x04, 0xd5, 0x16, 0x35, 0x26, 0xc3, + 0x3b, 0xad, 0x4d, 0x67, 0x8e, 0x43, 0x24, 0xc4, + 0x98, 0xe9, 0x6b, 0x2e, 0xbe, 0x0d, 0xa3, 0xf1, + 0xf4, 0x97, 0x80, 0x7b, 0x31, 0x32, 0x07, 0xd9, + 0x95, 0xa7, 0x17, 0x57, 0x69, 0x43, 0x7b, 0xe9, + 0xc8, 0xaa, 0xd0, 0x0a, 0x0c, 0x86, 0x0b, 0xe3, + 0x7f, 0x99, 0x88, 0x51, 0xc4, 0xf9, 0x22, 0x98, + 0xbe, 0x5e, 0xaa, 0xfd, 0x90, 0x3c, 0xa2, 0x74, + 0x18, 0x49, 0x05, +}; +const unsigned int ecdsa_pub_key_len = 91; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/WiFiFirmwareUpdater/WiFiFirmwareUpdater.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/WiFiFirmwareUpdater/WiFiFirmwareUpdater.ino new file mode 100644 index 00000000..1c655b85 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/STM32H747_System/examples/WiFiFirmwareUpdater/WiFiFirmwareUpdater.ino @@ -0,0 +1,159 @@ +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "FATFileSystem.h" +#include "wiced_resource.h" +#include "certificates.h" + +#ifndef CORE_CM7 + #error Update the WiFi firmware by uploading the sketch to the M7 core instead of the M4 core. +#endif + +QSPIFBlockDevice root(QSPI_SO0, QSPI_SO1, QSPI_SO2, QSPI_SO3, QSPI_SCK, QSPI_CS, QSPIF_POLARITY_MODE_1, 40000000); +mbed::MBRBlockDevice wifi_data(&root, 1); +mbed::FATFileSystem wifi_data_fs("wlan"); + +long getFileSize(FILE *fp) { + fseek(fp, 0, SEEK_END); + int size = ftell(fp); + fseek(fp, 0, SEEK_SET); + + return size; +} + +void printProgress(uint32_t offset, uint32_t size, uint32_t threshold, bool reset) { + static int percent_done = 0; + if (reset == true) { + percent_done = 0; + Serial.println("Flashed " + String(percent_done) + "%"); + } else { + uint32_t percent_done_new = offset * 100 / size; + if (percent_done_new >= percent_done + threshold) { + percent_done = percent_done_new; + Serial.println("Flashed " + String(percent_done) + "%"); + } + } +} + +void setup() { + + Serial.begin(115200); + while (!Serial); + + mbed::MBRBlockDevice::partition(&root, 1, 0x0B, 0, 1024 * 1024); + // use space from 15.5MB to 16 MB for another fw, memory mapped + + int err = wifi_data_fs.mount(&wifi_data); + if (err) { + // Reformat if we can't mount the filesystem + // this should only happen on the first boot + Serial.println("No filesystem containing the WiFi firmware was found."); + Serial.println("Usually that means that the WiFi firmware has not been installed yet" + " or was overwritten with another firmware.\n"); + Serial.println("Formatting the filsystem to install the firmware and certificates...\n"); + err = wifi_data_fs.reformat(&wifi_data); + } + + DIR *dir; + struct dirent *ent; + + if ((dir = opendir("/wlan")) != NULL) { + /* print all the files and directories within directory */ + while ((ent = readdir (dir)) != NULL) { + Serial.println("Searching for WiFi firmware file " + String(ent->d_name) + " ..."); + String fullname = "/wlan/" + String(ent->d_name); + if (fullname == "/wlan/4343WA1.BIN") { + Serial.println("A WiFi firmware is already installed. " + "Do you want to install the firmware anyway? Y/[n]"); + while (1) { + if (Serial.available()) { + int c = Serial.read(); + if (c == 'Y' || c == 'y') { + wifi_data_fs.reformat(&wifi_data); + break; + } + if (c == 'N' || c == 'n') { + return; + } + } + } + } + } + closedir (dir); + } + + extern const unsigned char wifi_firmware_image_data[]; + extern const resource_hnd_t wifi_firmware_image; + FILE* fp = fopen("/wlan/4343WA1.BIN", "wb"); + const int file_size = 421098; + int chunck_size = 1024; + int byte_count = 0; + + Serial.println("Flashing /wlan/4343WA1.BIN file"); + printProgress(byte_count, file_size, 10, true); + while (byte_count < file_size) { + if(byte_count + chunck_size > file_size) + chunck_size = file_size - byte_count; + int ret = fwrite(&wifi_firmware_image_data[byte_count], chunck_size, 1, fp); + if (ret != 1) { + Serial.println("Error writing firmware data"); + break; + } + byte_count += chunck_size; + printProgress(byte_count, file_size, 10, false); + } + fclose(fp); + + chunck_size = 1024; + byte_count = 0; + const uint32_t offset = 15 * 1024 * 1024 + 1024 * 512; + + Serial.println("Flashing memory mapped firmware"); + printProgress(byte_count, file_size, 10, true); + while (byte_count < file_size) { + if(byte_count + chunck_size > file_size) + chunck_size = file_size - byte_count; + int ret = root.program(wifi_firmware_image_data, offset + byte_count, chunck_size); + if (ret != 0) { + Serial.println("Error writing firmware data"); + break; + } + byte_count += chunck_size; + printProgress(byte_count, file_size, 10, false); + } + + chunck_size = 128; + byte_count = 0; + fp = fopen("/wlan/cacert.pem", "wb"); + + Serial.println("Flashing certificates"); + printProgress(byte_count, cacert_pem_len, 10, true); + while (byte_count < cacert_pem_len) { + if(byte_count + chunck_size > cacert_pem_len) + chunck_size = cacert_pem_len - byte_count; + int ret = fwrite(&cacert_pem[byte_count], chunck_size, 1 ,fp); + if (ret != 1) { + Serial.println("Error writing certificates"); + break; + } + byte_count += chunck_size; + printProgress(byte_count, cacert_pem_len, 10, false); + } + fclose(fp); + + fp = fopen("/wlan/cacert.pem", "rb"); + char buffer[128]; + int ret = fread(buffer, 1, 128, fp); + Serial.write(buffer, ret); + while (ret == 128) { + ret = fread(buffer, 1, 128, fp); + Serial.write(buffer, ret); + } + fclose(fp); + + Serial.println("\nFirmware and certificates updated!"); + Serial.println("It's now safe to reboot or disconnect your board."); +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/README.adoc new file mode 100644 index 00000000..aef62e82 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/README.adoc @@ -0,0 +1,22 @@ += Scheduler Library for Arduino = + +The Scheduler library enables the Arduino Due to run multiple functions at the same time. This allows tasks to happen without interrupting each other. + +For more information about this library please visit us at +http://www.arduino.cc/en/Reference/Scheduler + +== License == + +Copyright (c) 2012 The Android Open Source Project. All right reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino new file mode 100644 index 00000000..d1e67e20 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/Scheduler/examples/MultipleBlinks/MultipleBlinks.ino @@ -0,0 +1,109 @@ +/* + Multiple Blinks + + Demonstrates the use of the Scheduler library for the boards: + + - Arduino Nano 33 BLE, or + - Arduino Portenta H7, or + - Arduino Nano RP2040 Connect + + Hardware required : + * None (LEDs are already conencted to RGB LED) + + ATTENTION: LEDs polarity is reversed (so loop3 will turn the LED off by writing 1) + + created 8 Oct 2012 + by Cristian Maglie + Modified by + Scott Fitzgerald 19 Oct 2012 + + This example code is in the public domain + + http://www.arduino.cc/en/Tutorial/MultipleBlinks +*/ + +// Include Scheduler since we want to manage multiple tasks. +#include + +// On Nano RP2040 Connect, RGB leds are connected to the wifi module +// The user APIs are the same, but we can't convert to int, so use defines +#if defined(ARDUINO_NANO_RP2040_CONNECT) + +#include "WiFiNINA.h" +#define led1 LEDR +#define led2 LEDG +#define led3 LEDB + +// On Nicla Sense ME, RGB leds are connected via an I2C module +// The user APIs are the same, but we can't convert to int, so use defines +#elif defined(ARDUINO_NICLA) + +#include "Nicla_System.h" +#define led1 LEDR +#define led2 LEDG +#define led3 LEDB + +#else + +int led1 = LEDR; +int led2 = LEDG; +int led3 = LEDB; + +#endif + +void setup() { + Serial.begin(9600); + + // Setup the 3 pins as OUTPUT + pinMode(led1, OUTPUT); + pinMode(led2, OUTPUT); + pinMode(led3, OUTPUT); + + // Add "loop2" and "loop3" to scheduling. + // "loop" is always started by default. + Scheduler.startLoop(loop2); + Scheduler.startLoop(loop3); +} + +// Task no.1: blink LED with 1 second delay. +void loop() { + digitalWrite(led1, HIGH); + + // IMPORTANT: + // When multiple tasks are running 'delay' passes control to + // other tasks while waiting and guarantees they get executed. + delay(1000); + + digitalWrite(led1, LOW); + delay(1000); +} + +// Task no.2: blink LED with 0.1 second delay. +void loop2() { + digitalWrite(led2, HIGH); + delay(100); + digitalWrite(led2, LOW); + delay(100); +} + +// Task no.3: accept commands from Serial port +// '0' turns off LED +// '1' turns on LED +void loop3() { + if (Serial.available()) { + char c = Serial.read(); + if (c == '0') { + digitalWrite(led3, LOW); + Serial.println("Led turned off!"); + } + if (c == '1') { + digitalWrite(led3, HIGH); + Serial.println("Led turned on!"); + } + } + + // IMPORTANT: + // We must call 'yield' at a regular basis to pass + // control to other tasks. + yield(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/ThreadDebug/examples/ThreadDebug/ThreadDebug.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/ThreadDebug/examples/ThreadDebug/ThreadDebug.ino new file mode 100644 index 00000000..c3c74ef2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/ThreadDebug/examples/ThreadDebug/ThreadDebug.ino @@ -0,0 +1,27 @@ +/* This example demonstrates how to include the ThreadMRI library which allows debugging of the Portenta H7 and Nano 33 BLE [Sense] + with GDB via a serial interface. + + To connect to the target, launch gdb with the following parameters + + arm-none-eabi-gdb -ex "set pagination off" --baud {230400} -ex "set target-charset ASCII" -ex "target remote {debug.port}" {project_name}.elf + + The baud rate needs to match the one provided in UartDebugCommInterface constructor, while {debug.port} depends on the operating system (eg. /dev/ttyUSB0 or COM15). + + If UsbDebugCommInterface is being used you can specify any baudrate. +*/ + +#include + +//UartDebugCommInterface debugComm(SERIAL1_TX, SERIAL1_RX, 230400); +//ThreadDebug threadDebug(&debugComm, DEBUG_BREAK_IN_SETUP); + +UsbDebugCommInterface debugComm(&SerialUSB); +ThreadDebug threadDebug(&debugComm, DEBUG_BREAK_IN_SETUP); + +void setup() { + +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Keyboard/Keyboard.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Keyboard/Keyboard.ino new file mode 100644 index 00000000..6b00d508 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Keyboard/Keyboard.ino @@ -0,0 +1,15 @@ +#include "PluggableUSBHID.h" +#include "USBKeyboard.h" + +USBKeyboard Keyboard; + +void setup() { + // put your setup code here, to run once: + +} + +void loop() { + // put your main code here, to run repeatedly: + delay(1000); + Keyboard.printf("Hello world\n\r"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Mouse/Mouse.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Mouse/Mouse.ino new file mode 100644 index 00000000..253b1963 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHID/examples/Mouse/Mouse.ino @@ -0,0 +1,17 @@ +#include "PluggableUSBHID.h" +#include "USBMouse.h" + +USBMouse Mouse; + +void setup() { + // put your setup code here, to run once: + +} + +void loop() { + // put your main code here, to run repeatedly: + delay(1000); + Mouse.move(100,100); + delay(1000); + Mouse.move(-100,-100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/KeyboardController/KeyboardController.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/KeyboardController/KeyboardController.ino new file mode 100644 index 00000000..c03f2673 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/KeyboardController/KeyboardController.ino @@ -0,0 +1,161 @@ +/* + _______ _ _ _____ ____ + |__ __| | | | |/ ____| _ \ + | | ___ ___ _ __ _ _| | | | (___ | |_) | + | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < + | | __/ __/ | | | |_| | |__| |____) | |_) | + |_|\___|\___|_| |_|\__, |\____/|_____/|____/ + __/ | + |___/ + + TeenyUSB - light weight usb stack for STM32 micro controllers + + Copyright (c) 2019 XToolBox - admin@xtoolbox.org + www.tusb.org + + 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. +*/ + +#include "USBHost.h" + +USBHost usb; + +static int process_key(tusbh_ep_info_t* ep, const uint8_t* key); + +static const tusbh_boot_key_class_t cls_boot_key = { + .backend = &tusbh_boot_keyboard_backend, + //.on_key = process_key +}; + +static const tusbh_boot_mouse_class_t cls_boot_mouse = { + .backend = &tusbh_boot_mouse_backend, + // .on_mouse = process_mouse +}; + +static const tusbh_hid_class_t cls_hid = { + .backend = &tusbh_hid_backend, + //.on_recv_data = process_hid_recv, + //.on_send_done = process_hid_sent, +}; + +static const tusbh_hub_class_t cls_hub = { + .backend = &tusbh_hub_backend, +}; + +static const tusbh_vendor_class_t cls_vendor = { + .backend = &tusbh_vendor_backend, + //.transfer_done = process_vendor_xfer_done +}; + +int msc_ff_mount(tusbh_interface_t* interface, int max_lun, const tusbh_block_info_t* blocks); +int msc_ff_unmount(tusbh_interface_t* interface); + +static const tusbh_msc_class_t cls_msc_bot = { + .backend = &tusbh_msc_bot_backend, + // .mount = msc_ff_mount, + // .unmount = msc_ff_unmount, +}; + +static const tusbh_cdc_acm_class_t cls_cdc_acm = { + .backend = &tusbh_cdc_acm_backend, +}; + +static const tusbh_cdc_rndis_class_t cls_cdc_rndis = { + .backend = &tusbh_cdc_rndis_backend, +}; + +static const tusbh_class_reg_t class_table[] = { + (tusbh_class_reg_t)&cls_boot_key, + (tusbh_class_reg_t)&cls_boot_mouse, + (tusbh_class_reg_t)&cls_hub, + (tusbh_class_reg_t)&cls_msc_bot, + (tusbh_class_reg_t)&cls_cdc_acm, + (tusbh_class_reg_t)&cls_cdc_rndis, + (tusbh_class_reg_t)&cls_hid, + (tusbh_class_reg_t)&cls_vendor, + 0, +}; + +void setup() +{ + Serial1.begin(115200); + usb.Init(USB_CORE_ID_HS, class_table); + //usb.Init(USB_CORE_ID_FS, class_table); +} + +void loop() { + //usb.Task(); +} + +#define MOD_CTRL (0x01 | 0x10) +#define MOD_SHIFT (0x02 | 0x20) +#define MOD_ALT (0x04 | 0x40) +#define MOD_WIN (0x08 | 0x80) + +#define LED_NUM_LOCK 1 +#define LED_CAPS_LOCK 2 +#define LED_SCROLL_LOCK 4 + +#define stdin_recvchar Serial1.write + +static uint8_t key_leds; +static const char knum[] = "1234567890"; +static const char ksign[] = "!@#$%^&*()"; +static const char tabA[] = "\t -=[]\\#;'`,./"; +static const char tabB[] = "\t _+{}|~:\"~<>?"; +// route the key event to stdin +static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) +{ + printf("\n"); + uint8_t modify = keys[0]; + uint8_t key = keys[2]; + uint8_t last_leds = key_leds; + if (key >= KEY_A && key <= KEY_Z) { + char ch = 'A' + key - KEY_A; + if ( (!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK)) ) { + ch += 'a' - 'A'; + } + stdin_recvchar(ch); + } else if (key >= KEY_1 && key <= KEY_0) { + if (modify & MOD_SHIFT) { + stdin_recvchar(ksign[key - KEY_1]); + } else { + stdin_recvchar(knum[key - KEY_1]); + } + } else if (key >= KEY_TAB && key <= KEY_SLASH) { + if (modify & MOD_SHIFT) { + stdin_recvchar(tabB[key - KEY_TAB]); + } else { + stdin_recvchar(tabA[key - KEY_TAB]); + } + } else if (key == KEY_ENTER) { + stdin_recvchar('\r'); + } else if (key == KEY_CAPSLOCK) { + key_leds ^= LED_CAPS_LOCK; + } else if (key == KEY_NUMLOCK) { + key_leds ^= LED_NUM_LOCK; + } else if (key == KEY_SCROLLLOCK) { + key_leds ^= LED_SCROLL_LOCK; + } + + if (key_leds != last_leds) { + tusbh_set_keyboard_led(ep, key_leds); + } + return 0; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/Shell.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/Shell.ino new file mode 100644 index 00000000..6b82fa16 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/Shell.ino @@ -0,0 +1,439 @@ +/* + _______ _ _ _____ ____ + |__ __| | | | |/ ____| _ \ + | | ___ ___ _ __ _ _| | | | (___ | |_) | + | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < + | | __/ __/ | | | |_| | |__| |____) | |_) | + |_|\___|\___|_| |_|\__, |\____/|_____/|____/ + __/ | + |___/ + + TeenyUSB - light weight usb stack for STM32 micro controllers + + Copyright (c) 2019 XToolBox - admin@xtoolbox.org + www.tusb.org + + 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. +*/ + +#include "USBHost.h" +#include "USB251xB.h" + +extern "C" { +#include "teeny_usb.h" +#include "class/host/tusbh.h" +#include "class/host/tusbh_vendor.h" +#include "class/host/tusbh_hub.h" +#include "class/host/tusbh_hid.h" +#include "class/host/tusbh_msc.h" +#include "class/host/tusbh_cdc_acm.h" +#include "class/host/tusbh_cdc_rndis.h" +#include "string.h" +#include "class/host/usb_key_code.h" +} + +#include "mbed.h" + +#define TEENYUSB_LOGO \ + " _______ _ _ _____ ____ \n" \ + "|__ __| | | | |/ ____| _ \\ \n" \ + " | | ___ ___ _ __ _ _| | | | (___ | |_) |\n" \ + " | |/ _ \\/ _ \\ '_ \\| | | | | | |\\___ \\| _ < \n" \ + " | | __/ __/ | | | |_| | |__| |____) | |_) |\n" \ + " |_|\\___|\\___|_| |_|\\__, |\\____/|_____/|____/ \n" \ + " __/ | \n" \ + " |___/ \n" + + +static int process_key(tusbh_ep_info_t* ep, const uint8_t* key); + +static tusbh_root_hub_t root_fs; +static tusbh_root_hub_t root_hs; +static const tusbh_boot_key_class_t cls_boot_key = { + .backend = &tusbh_boot_keyboard_backend, + //.on_key = process_key +}; + +static const tusbh_boot_mouse_class_t cls_boot_mouse = { + .backend = &tusbh_boot_mouse_backend, + // .on_mouse = process_mouse +}; + +static const tusbh_hid_class_t cls_hid = { + .backend = &tusbh_hid_backend, + //.on_recv_data = process_hid_recv, + //.on_send_done = process_hid_sent, +}; + +static const tusbh_hub_class_t cls_hub = { + .backend = &tusbh_hub_backend, +}; + +static const tusbh_vendor_class_t cls_vendor = { + .backend = &tusbh_vendor_backend, + //.transfer_done = process_vendor_xfer_done +}; + +int msc_ff_mount(tusbh_interface_t* interface, int max_lun, const tusbh_block_info_t* blocks); +int msc_ff_unmount(tusbh_interface_t* interface); + +static const tusbh_msc_class_t cls_msc_bot = { + .backend = &tusbh_msc_bot_backend, + // .mount = msc_ff_mount, + // .unmount = msc_ff_unmount, +}; + +static const tusbh_cdc_acm_class_t cls_cdc_acm = { + .backend = &tusbh_cdc_acm_backend, +}; + +static const tusbh_cdc_rndis_class_t cls_cdc_rndis = { + .backend = &tusbh_cdc_rndis_backend, +}; + +static const tusbh_class_reg_t class_table[] = { + (tusbh_class_reg_t)&cls_boot_key, + (tusbh_class_reg_t)&cls_boot_mouse, + (tusbh_class_reg_t)&cls_hub, + (tusbh_class_reg_t)&cls_msc_bot, + (tusbh_class_reg_t)&cls_cdc_acm, + (tusbh_class_reg_t)&cls_cdc_rndis, + (tusbh_class_reg_t)&cls_hid, + (tusbh_class_reg_t)&cls_vendor, + 0, +}; + + +static tusb_host_t* fs; +static tusb_host_t* hs; + +void show_memory(char* argv[], int argc); +void cmd_lsusb(char* argv[], int argc) +{ + if (fs)ls_usb(fs); + if (hs)ls_usb(hs); +} + +void cmd_ls(char* argv[], int argc); +void cmd_mkdir(char* argv[], int argc); +void cmd_mv(char* argv[], int argc); +void cmd_cat(char* argv[], int argc); +void cmd_cp(char* argv[], int argc); +void cmd_rm(char* argv[], int argc); +void cmd_append(char* argv[], int argc); + +static tusbh_interface_t* find_cdc(tusbh_device_t* dev) +{ + if (!dev)return 0; + for (int i = 0; i < dev->interface_num; i++) { + tusbh_interface_t* itf = &dev->interfaces[i]; + if (itf->cls == (tusbh_class_reg_t)&cls_cdc_acm) { + return itf; + } + } + for (int i = 0; i < TUSBH_MAX_CHILD; i++) { + tusbh_device_t* child = dev->children[i]; + if (child) { + return find_cdc(child); + } + } + return 0; +} + +__ALIGN_BEGIN static uint8_t test_cdc_data[64] __ALIGN_END = { + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, +}; + + +void cmd_cdc_test(char* argv[], int argc) +{ + tusbh_interface_t* cdc = 0; + if (fs) { + cdc = find_cdc( ((tusbh_root_hub_t*)fs->user_data)->children[0]); + } + + if (!cdc && hs) { + cdc = find_cdc( ((tusbh_root_hub_t*)hs->user_data)->children[0]); + } + + if (!cdc) { + printf("No CDC interface attached\n"); + } + + int r = tusbh_cdc_send_data(cdc, test_cdc_data, 32, 2000); + printf("Send data result = %d\n", r); + if (r < 0)return; + r = tusbh_cdc_recv_data(cdc, test_cdc_data + 32, 32, 2000); + printf("Recv data result = %d\n", r); + for (int i = 0; i < r; i++) { + printf("%02x ", test_cdc_data[32 + i]); + } + printf("\n"); +} + + +typedef struct _cli +{ + const char* cmd; + const char* desc; + void (*action)(char* argv[], int argc); +} cli_t; + + + +const cli_t commands[] = { + {"lsusb", "list usb devices", cmd_lsusb }, + {"testcdc", "testcdc test cdc loopback interface", cmd_cdc_test}, +}; + +static void process_command(char* cmd) +{ +#define MAX_ARGC 8 + char * argv[MAX_ARGC]; + for (int i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) { + const cli_t* c = &commands[i]; + if (strstr(cmd, c->cmd) == cmd && c->action) { + int argc = 1; + argv[0] = cmd; + while (*cmd) { + if (*cmd == ' ') { + while (*cmd && *cmd == ' ') { + *cmd = 0; + cmd++; + } + if (*cmd) { + if (argc < MAX_ARGC) { + argv[argc] = cmd; + argc++; + } + cmd++; + } + } else { + cmd++; + } + } + c->action(argv, argc); + return; + } + } + printf("Unkown command: %s\n", cmd); +} + +#define PROMPT "TeenyUSB > " + +static char cmd_buf[256]; +static int cmd_len; +static void command_loop(void) +{ + if (Serial1.available()) { + int ch = Serial1.read(); + if (ch == '\r') { + cmd_buf[cmd_len] = 0; + if (cmd_buf[0]) { + process_command(cmd_buf); + } + cmd_len = 0; + printf(PROMPT); + } else if (ch == '\t') { + printf("\n"); + for (int i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) { + const cli_t* c = &commands[i]; + printf("%-10s - %s\n", c->cmd, c->desc ? c->desc : ""); + } + printf(PROMPT); + cmd_len = 0; + } else { + if (cmd_len < sizeof(cmd_buf) - 1) { + cmd_buf[cmd_len] = ch; + cmd_len++; + } + } + } +} + +#include "usb_phy_api.h" +#include "Wire.h" + +tusbh_msg_q_t* mq; + +void setup() +{ + Serial1.begin(115200); + printf("\n" TEENYUSB_LOGO PROMPT); + + //get_usb_phy()->deinit(); + + mq = tusbh_mq_create(); + tusbh_mq_init(mq); + +#if defined(USB_CORE_ID_FS) + fs = tusb_get_host(USB_CORE_ID_FS); + HOST_PORT_POWER_ON_FS(); + root_fs.mq = mq; + root_fs.id = "FS"; + root_fs.support_classes = class_table; + tusb_host_init(fs, &root_fs); + tusb_open_host(fs); +#else + (void)root_fs; + fs = 0; +#endif + +#if defined(USB_CORE_ID_HS) + hs = tusb_get_host(USB_CORE_ID_HS); + HOST_PORT_POWER_ON_HS(); + root_hs.mq = mq; + root_hs.id = "HS"; + root_hs.support_classes = class_table; + tusb_host_init(hs, &root_hs); + tusb_open_host(hs); +#else + (void)root_hs; + hs = 0; +#endif + + start_hub(); + + //usb_fakeirq.start(mbed::callback(usb_irq_thread)); + + //NVIC_DisableIRQ(OTG_HS_IRQn); + + cmd_len = 0; +} + +bool once = true; + +void loop() { + if (millis() > 5000 && once) { + //cmd_lsusb(NULL, 0); + once = false; + } + //command_loop(); + + // there is only one message q for every thing + tusbh_msg_loop(mq); +} + +#define MOD_CTRL (0x01 | 0x10) +#define MOD_SHIFT (0x02 | 0x20) +#define MOD_ALT (0x04 | 0x40) +#define MOD_WIN (0x08 | 0x80) + +#define LED_NUM_LOCK 1 +#define LED_CAPS_LOCK 2 +#define LED_SCROLL_LOCK 4 + +#define stdin_recvchar Serial1.write + +static uint8_t key_leds; +static const char knum[] = "1234567890"; +static const char ksign[] = "!@#$%^&*()"; +static const char tabA[] = "\t -=[]\\#;'`,./"; +static const char tabB[] = "\t _+{}|~:\"~<>?"; +// route the key event to stdin +static int process_key(tusbh_ep_info_t* ep, const uint8_t* keys) +{ + printf("\n"); + uint8_t modify = keys[0]; + uint8_t key = keys[2]; + uint8_t last_leds = key_leds; + if (key >= KEY_A && key <= KEY_Z) { + char ch = 'A' + key - KEY_A; + if ( (!!(modify & MOD_SHIFT)) == (!!(key_leds & LED_CAPS_LOCK)) ) { + ch += 'a' - 'A'; + } + stdin_recvchar(ch); + } else if (key >= KEY_1 && key <= KEY_0) { + if (modify & MOD_SHIFT) { + stdin_recvchar(ksign[key - KEY_1]); + } else { + stdin_recvchar(knum[key - KEY_1]); + } + } else if (key >= KEY_TAB && key <= KEY_SLASH) { + if (modify & MOD_SHIFT) { + stdin_recvchar(tabB[key - KEY_TAB]); + } else { + stdin_recvchar(tabA[key - KEY_TAB]); + } + } else if (key == KEY_ENTER) { + stdin_recvchar('\r'); + } else if (key == KEY_CAPSLOCK) { + key_leds ^= LED_CAPS_LOCK; + } else if (key == KEY_NUMLOCK) { + key_leds ^= LED_NUM_LOCK; + } else if (key == KEY_SCROLLLOCK) { + key_leds ^= LED_SCROLL_LOCK; + } + + if (key_leds != last_leds) { + tusbh_set_keyboard_led(ep, key_leds); + } + return 0; +} + + + +#if 1 + +extern "C" { + +#define LOG_SIZE 1024 +static int hc_log_index; +static channel_state_t hc_log_buf[LOG_SIZE]; +static USB_OTG_HostChannelTypeDef hc_info; +static USB_OTG_HostChannelTypeDef* hc_reg; +static tusb_hc_data_t* hc_data; +static uint8_t hc_no; +void hc_log_begin(tusb_host_t* host, uint8_t hc_num) +{ + USB_OTG_GlobalTypeDef *USBx = GetUSB(host); + USB_OTG_HostChannelTypeDef* HC = USBx_HC(hc_num); + tusb_hc_data_t* hc = &host->hc[hc_num]; + hc_reg = HC; + hc_data = hc; + hc_no = hc_num; + hc_info.HCCHAR = HC->HCCHAR; + hc_info.HCSPLT = HC->HCSPLT; + hc_info.HCINTMSK = HC->HCINTMSK; + hc_info.HCTSIZ = HC->HCTSIZ; + hc_info.HCDMA = HC->HCDMA; + hc_log_index = 0; + //printf("hc_no %x\n", hc_num); + //printf("hc_info.HCCHAR %x\n", HC->HCCHAR); + //printf("hc_info.HCSPLT %x\n", HC->HCSPLT); + //printf("hc_info.HCINTMSK %x\n", HC->HCINTMSK); + //printf("hc_info.HCTSIZ %x\n", HC->HCTSIZ); + //printf("hc_info.HCDMA %x\n", HC->HCDMA); +} + +void hc_log_data(tusb_host_t* host, uint8_t hc_num, uint32_t data) +{ + if (hc_log_index < LOG_SIZE) { + hc_log_buf[hc_log_index] = (channel_state_t)data; + hc_log_index++; + } +} + +void hc_log_end(tusb_host_t* host, uint8_t hc_num) +{ +} + +} +#endif diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/readme.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/readme.md new file mode 100644 index 00000000..b49ca901 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/examples/Shell/readme.md @@ -0,0 +1,108 @@ +# 无RTOS的主机例程 + +host demo without RTOS + +通过串口进行简单的交互,默认串口配置为115200 N 8 1,当USB口接入键盘时,可以通过USB键盘做为Console的输入,不支持ANSI转义字符输入(即不支持退格键、方向键)。 + +A simple terminal through serial port with default setting "115200 N 8 1". The terminal input could be a USB keyboard. ANSI escape character is not support. + +## 简易命令行 Simple Terminal + +按下Tab键显示支持的命令。 Press Tab to show supported commands. + +``` + _______ _ _ _____ ____ +|__ __| | | | |/ ____| _ \ + | | ___ ___ _ __ _ _| | | | (___ | |_) | + | |/ _ \/ _ \ '_ \| | | | | | |\___ \| _ < + | | __/ __/ | | | |_| | |__| |____) | |_) | + |_|\___|\___|_| |_|\__, |\____/|_____/|____/ + __/ | + |___/ +TeenyUSB > +lsusb - list usb devices +showmem - show memory usage +ls - ls list dir +mkdir - mkdir create dir +mv - mv move file +cat - cat display file +cp - cp copy file +rm - rm remove file or path +append - append [data data ...] add data to file +TeenyUSB > +``` + +### 显示连接的设备 list attached device +``` +TeenyUSB > lsusb +Device of FS root hub + Device VID:058f PID:9254, Parent: ROOT FS:0 + Interface 0: HUB + Device VID:10c4 PID:ea60, Parent: Dev 01:3 + Interface 0: vendor class +Device of HS root hub + Device VID:0930 PID:6545, Parent: ROOT HS:0 + Interface 0: Mass Storage +TeenyUSB > +``` +### 显示内存使用情况 list memory usage +``` +TeenyUSB > showmem + Memory used 176, max 176 + MQ used 1 + Device used 3 + Event used 3 +TeenyUSB > +``` +### 文件操作 File operation +当连接U盘时文件操作才有效。 Effective when USB mass storage device connected. + +下面是一个mount在[0:]上的U盘例子。 A sample MSC device mount on [0:]. + +通过日志可以看到第一次获取Capacity失败,读取Sense信息后第二次获取成功。 +``` +TeenyUSB > RHUB HS:0 Connect +RHUB HS:0 Enable +DEV HS.00 Allocate pipe, in = 0, out = 1 +DEV HS.01 Re-allocate pipe, in = 0, out = 1 +DEV HS.01 HS device, VID:0930 PID:6545 +ITF HS.01.0-0 MSC lun(0) Kingston - DataTraveler G3 - PMAP +ITF HS.01.0-0 MSC ep 81 stall +ITF HS.01.0-0 MSC stall CSW res = 13, residue 8, status 1 +ITF HS.01.0-0 MSC xfer fail, res = -6, residue 8, status 1 +ITF HS.01.0-0 MSC Sense: SENSE_UNIT_ATTENTION, MEDIUM_HAVE_CHANGED, qua 0 +ITF HS.01.0-0 MSC lun(0) Block Count:7669824 Size:512 +MSC mount [0:] r = 0 +ITF HS.01.0-0 MSC interface init +DEV HS.01 Device has 1 interfaces +``` +使用文件操作U盘中的文件。 +``` +TeenyUSB > ls 0: +0:/T1 +0:/T2 +0:/T3 +0:/SYSTEM~1/WPSETT~1.DAT +0:/SYSTEM~1/INDEXE~1 +TeenyUSB > cat t1 +112233 + +TeenyUSB > cp t1 r1 +TeenyUSB > cat r1 +112233 + +TeenyUSB > mv r1 r2 +TeenyUSB > cat r2 +112233 + +TeenyUSB > append ff test_data +TeenyUSB > cat ff +test_data + +TeenyUSB > append ff 123123123 +TeenyUSB > cat ff +test_data +123123123 + +TeenyUSB > +``` diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/readme.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/readme.md new file mode 100644 index 00000000..9da40f89 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBHOST/readme.md @@ -0,0 +1,63 @@ +TeenyUSB Stack +========== + +# 设备接口函数 Device API + +普通函数 Normal function + +| function name | description | +|-------------------|-------------------------------| +|tusb_get_device | Get chip USB device handle | +|tusb_open | Open USB Device, Connect | +|tusb_close | Close USB device, Disconnect | +|tusb_send_data | Send endpoint data | +|tusb_set_rx_buffer | Set OUT endpoint recv buffer | +|tusb_set_rx_valid | Set OUT endpoint valid | + +回调函数,用户实现 Callback function + +| function name | description | +|---------------------------|-------------------------------| +|tusb_reconfig | Config endpoint here | +|tusb_class_request | Class request | +|tusb_on_rx_done | Data received | +|tusb_on_tx_done | Data send finish | +|tusb_get_report_descriptor | Report descriptor request | + +# Host API + +普通函数 Normal function + +| function name | description | +|-----------------------|--------------------------------------| +|tusb_get_host | Get chip USB host handle | +|tusb_open_host | Open USB host | +|tusb_close_host | Close USB host | +|tusb_host_port_reset | Set host port reset state | +|tusb_pipe_open | Open/allocate pipe for data transfer | +|tusb_pipe_close | Close/free pipe | +|tusb_pipe_setup | Transfer setup packet | +|tusb_pipe_xfer_data | Transfer data packet | +|tusb_pipe_wait | Wait/Get pipe transfer state | + +回调函数,用户实现 Callback function + +| function name | description | +|---------------------------|----------------------| +|tusb_host_port_changed | Port state changed | +|tusb_on_channel_event | Changed event | + +# 函数处理流程 + +## USB FS模块 + +![usb_fs_api](../images/usb_fs_api.png) + +## USB OTG模块设备模式 Device + +![otg_device_api](../images/otg_device_api.png) + +## USB OTG模块主机模式 Host + +![otg_host_api](../images/otg_host_api.png) + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/AccessFlashAsUSBDisk/AccessFlashAsUSBDisk.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/AccessFlashAsUSBDisk/AccessFlashAsUSBDisk.ino new file mode 100644 index 00000000..6046f4ee --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/AccessFlashAsUSBDisk/AccessFlashAsUSBDisk.ino @@ -0,0 +1,62 @@ +/* + QSPI as USB Mass Storage + This example shows how to expose a QSPIF BlockDevice (16MB external flash on the Portenta H7) + as an USB stick. It can be adapted to any kind of BlockDevice (FlashIAP or either RAM via HeapBlockDevice) + Before loading this example, make sure you execute WiFiFirmwareUpdater sketch + to create and format the proper partitions. +*/ + +#include "PluggableUSBMSD.h" +#include "QSPIFBlockDevice.h" +#include "MBRBlockDevice.h" +#include "FATFileSystem.h" + +static QSPIFBlockDevice root; +mbed::MBRBlockDevice wifi_data(&root, 1); +mbed::MBRBlockDevice ota_data(&root, 2); +static mbed::FATFileSystem wifi("wifi"); +static mbed::FATFileSystem ota("ota"); + +void USBMSD::begin() +{ + int err = wifi.mount(&wifi_data); + if (err) { + while (!Serial); + Serial.println("Please run WiFiFirmwareUpdater before"); + return; + } + ota.mount(&ota_data); +} + + +USBMSD MassStorage(&root); + +void setup() { + Serial.begin(115200); + MassStorage.begin(); +} + +void printDirectory(char* name) { + DIR *d; + struct dirent *p; + + d = opendir(name); + if (d != NULL) { + while ((p = readdir(d)) != NULL) { + Serial.println(p->d_name); + } + } + closedir(d); +} + +void loop() { + if (MassStorage.media_removed()) { + // list the content of the partitions + // you may need to restart the board for the list to update if you copied new files + Serial.println("Content of WiFi partition:"); + printDirectory("/wifi"); + Serial.println("Content of OTA partition:"); + printDirectory("/ota"); + } + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/Nano33BLE_FlashMassStorage/Nano33BLE_FlashMassStorage.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/Nano33BLE_FlashMassStorage/Nano33BLE_FlashMassStorage.ino new file mode 100644 index 00000000..ca201e87 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/USBMSD/examples/Nano33BLE_FlashMassStorage/Nano33BLE_FlashMassStorage.ino @@ -0,0 +1,24 @@ +/* + This example exposes the second half (512KB) of Nano 33 BLE flash + as a USB disk. + The user can interact with this disk as a bidirectional communication with the board + For example, the board could save data in a file to be retrieved later with a drag and drop +*/ + +#include "PluggableUSBMSD.h" + +void setup() { + Serial.begin(115200); + MassStorage.begin(); + + // write a file with some data + // a+ means append, so every time the board is rebooted the file will grow by a new line + FILE *f = fopen("/fs/data.txt", "a+"); + String hello = "Hello from Nano33BLE Filesystem\n"; + fwrite(hello.c_str(), hello.length(), 1, f); + fclose(f); +} + +void loop() { + delay(1000); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino new file mode 100644 index 00000000..017e1658 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/WiFiWebClient.ino @@ -0,0 +1,108 @@ +/* + Web client + + This sketch connects to a website (http://example.com) using the WiFi module. + + This example is written for a network using WPA encryption. For + WEP or WPA, change the Wifi.begin() call accordingly. + + Circuit: + * Arduino Portenta H7 + + created 13 July 2010 + by dlf (Metodo2 srl) + modified 31 May 2012 + by Tom Igoe + */ + +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) +int keyIndex = 0; // your network key Index number (needed only for WEP) + +int status = WL_IDLE_STATUS; +// if you don't want to use DNS (and reduce your sketch size) +// use the numeric IP instead of the name for the server: +// IPAddress server(93,184,216,34); // IP address for example.com (no DNS) +char server[] = "example.com"; // host name for example.com (using DNS) + +WiFiClient client; + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // check for the WiFi module: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("Communication with WiFi module failed!"); + // don't continue + while (true); + } + + // attempt to connect to Wifi network: + while (status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + + // wait 3 seconds for connection: + delay(3000); + } + Serial.println("Connected to wifi"); + printWifiStatus(); + + Serial.println("\nStarting connection to server..."); + // if you get a connection, report back via serial: + if (client.connect(server, 80)) { + Serial.println("connected to server"); + // Make a HTTP request: + client.println("GET /index.html HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } +} + +void loop() { + // if there are incoming bytes available + // from the server, read them and print them: + while (client.available()) { + char c = client.read(); + Serial.write(c); + } + + // if the server's disconnected, stop the client: + if (!client.connected()) { + Serial.println(); + Serial.println("disconnecting from server."); + client.stop(); + + // do nothing forevermore: + while (true); + } +} + +void printWifiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(WiFi.SSID()); + + // print your board's IP address: + IPAddress ip = WiFi.localIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print the received signal strength: + long rssi = WiFi.RSSI(); + Serial.print("signal strength (RSSI):"); + Serial.print(rssi); + Serial.println(" dBm"); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/arduino_secrets.h new file mode 100644 index 00000000..0c9fdd55 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/WiFi/examples/WiFiWebClient/arduino_secrets.h @@ -0,0 +1,2 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/doom/examples/Doom/Doom.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/doom/examples/Doom/Doom.ino new file mode 100644 index 00000000..2c6b25f2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-mbed/libraries/doom/examples/Doom/Doom.ino @@ -0,0 +1,57 @@ +/* + Arduino wrapper for DoomGeneric + Mouse and keyboard controls are not implemented at the moment. + + To use the internal QSPI flash as storage, run WiFiFirmwareUpdater + sketch once to create the partitions, AccessFlashAsUSBDisk to expose the QSPI flash + as a USB disk, copy DOOM1.WAD in the biggest partition, flash this sketch and you are ready to go :) +*/ + +#include "QSPIFBlockDevice.h" +#include "FATFileSystem.h" +#include "MBRBlockDevice.h" +#include "doomgeneric.h" + +QSPIFBlockDevice block_device; +// Comment previous line and uncomment these two if you want to store DOOM.WAD in an external SD card (FAT32 formatted) +// #include "SDMMCBlockDevice.h" +// SDMMCBlockDevice block_device; + +mbed::MBRBlockDevice fs_data(&block_device, 2); +static mbed::FATFileSystem fs("fs"); + +extern "C" int main_wrapper(int argc, char **argv); +char*argv[] = {"/fs/doom", "-iwad", "/fs/DOOM1.WAD"}; + +void setup() { + int err = fs.mount(&fs_data); + if (err) { + printf("No filesystem found, please run AccessFlashAsUSBDisk sketch and copy DOOM1.WAD in the big partition"); + pinMode(LEDB, OUTPUT); + while (1) { + digitalWrite(LEDB, LOW); + delay(100); + digitalWrite(LEDB, HIGH); + delay(100); + } + } + DIR *dir; + struct dirent *ent; + printf("try to open dir\n"); + if ((dir = opendir("/fs")) != NULL) { + /* print all the files and directories within directory */ + while ((ent = readdir (dir)) != NULL) { + printf ("%s\n", ent->d_name); + } + closedir (dir); + } else { + /* could not open directory */ + printf ("error\n"); + } + main_wrapper(3, argv); +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/README.md new file mode 100644 index 00000000..4090cd7e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/README.md @@ -0,0 +1,65 @@ +# Arduino Core for ATMEGA4809 CPU + +[![Compile MuxTO status](https://github.com/arduino/ArduinoCore-megaavr/actions/workflows/compile-muxto.yml/badge.svg)](https://github.com/arduino/ArduinoCore-megaavr/actions/workflows/compile-muxto.yml) + +This repository contains the source code and configuration files of the Arduino Core +for Microchip's ATMEGA4809 processor (used on the Arduino Uno WiFi Rev2 boards). + +## Installation on Arduino IDE + +This core is available as a package in the Arduino IDE cores manager. +Just open the "Boards Manager" and install the package called: + +"Arduino megaAVR Boards" + +## Support + +There is a dedicated section of the Arduino Forum for general discussion and project assistance: + +http://forum.arduino.cc/index.php?board=126.0 + +## Bugs or Issues + +If you find a bug you can submit an issue here on github: + +https://github.com/arduino/ArduinoCore-megaavr/issues + +Before posting a new issue, please check if the same problem has been already reported by someone else +to avoid duplicates. + +## Contributions + +Contributions are always welcome. The preferred way to receive code cotribution is by submitting a +Pull Request on github. + +## Developing + +1. Create an `/hardware/arduino` folder. Where `` is the location of your + Arduino sketchbook. +1. Change directories: `cd /hardware/arduino` +1. Clone this repo: `git clone https://github.com/arduino/ArduinoCore-megaavr.git megaavr` +1. Change directories: `cd megaavr/cores/arduino` +1. Copy or symlink the `api` folder from the [ArduinoCore-API](https://github.com/arduino/ArduinoCore-API) repo. +1. Restart the IDE + +## License and credits + +This core has been developed by Arduino SA in collaboration with Microchip. + +``` + Copyright (c) 2018 Arduino SA. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +``` \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/README.md new file mode 100644 index 00000000..a6241361 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/README.md @@ -0,0 +1,139 @@ +## **EEPROM Library V2.0** for Arduino + +**Written by:** _Christopher Andrews_. + +### **What is the EEPROM library.** + +Th EEPROM library provides an easy to use interface to interact with the internal non-volatile storage found in AVR based Arduino boards. This library will work on many AVR devices like ATtiny and ATmega chips. + +### **How to use it** +The EEPROM library is included in your IDE download. To add its functionality to your sketch you'll need to reference the library header file. You do this by adding an include directive to the top of your sketch. + +```Arduino +#include + +void setup(){ + +} + +void loop(){ + +} + +``` + +The library provides a global variable named `EEPROM`, you use this variable to access the library functions. The methods provided in the EEPROM class are listed below. + +You can view all the examples [here](examples/). + +### **Library functions** + +#### **`EEPROM.read( address )`** [[_example_]](examples/eeprom_read/eeprom_read.ino) + +This function allows you to read a single byte of data from the eeprom. +Its only parameter is an `int` which should be set to the address you wish to read. + +The function returns an `unsigned char` containing the value read. + +#### **`EEPROM.write( address, value )`** [[_example_]](examples/eeprom_write/eeprom_write.ino) + +The `write()` method allows you to write a single byte of data to the EEPROM. +Two parameters are needed. The first is an `int` containing the address that is to be written, and the second is a the data to be written (`unsigned char`). + +This function does not return any value. + +#### **`EEPROM.update( address, value )`** [[_example_]](examples/eeprom_update/eeprom_update.ino) + +This function is similar to `EEPROM.write()` however this method will only write data if the cell contents pointed to by `address` is different to `value`. This method can help prevent unnecessary wear on the EEPROM cells. + +This function does not return any value. + +#### **`EEPROM.get( address, object )`** [[_example_]](examples/eeprom_get/eeprom_get.ino) + +This function will retrieve any object from the EEPROM. +Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to read. + +This function returns a reference to the `object` passed in. It does not need to be used and is only returned for conveience. + +#### **`EEPROM.put( address, object )`** [[_example_]](examples/eeprom_put/eeprom_put.ino) + +This function will write any object to the EEPROM. +Two parameters are needed to call this function. The first is an `int` containing the address that is to be written, and the second is the object you would like to write. + +This function uses the _update_ method to write its data, and therefore only rewrites changed cells. + +This function returns a reference to the `object` passed in. It does not need to be used and is only returned for conveience. + +#### **Subscript operator: `EEPROM[address]`** [[_example_]](examples/eeprom_crc/eeprom_crc.ino) + +This operator allows using the identifier `EEPROM` like an array. +EEPROM cells can be read _and_ **_written_** directly using this method. + +This operator returns a reference to the EEPROM cell. + +```c++ +unsigned char val; + +//Read first EEPROM cell. +val = EEPROM[ 0 ]; + +//Write first EEPROM cell. +EEPROM[ 0 ] = val; + +//Compare contents +if( val == EEPROM[ 0 ] ){ + //Do something... +} +``` + +#### **`EEPROM.length()`** + +This function returns an `unsigned int` containing the number of cells in the EEPROM. + +--- + +### **Advanced features** + +This library uses a component based approach to provide its functionality. This means you can also use these components to design a customized approach. Two background classes are available for use: `EERef` & `EEPtr`. + +#### **`EERef` class** + +This object references an EEPROM cell. +Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM. +This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell. + +```C++ +EERef ref = EEPROM[ 10 ]; //Create a reference to 11th cell. + +ref = 4; //write to EEPROM cell. + +unsigned char val = ref; //Read referenced cell. +``` + +#### **`EEPtr` class** + +This object is a bidirectional pointer to EEPROM cells represented by `EERef` objects. +Just like a normal pointer type, this type can be dereferenced and repositioned using +increment/decrement operators. + +```C++ +EEPtr ptr = 10; //Create a pointer to 11th cell. + +*ptr = 4; //dereference and write to EEPROM cell. + +unsigned char val = *ptr; //dereference and read. + +ptr++; //Move to next EEPROM cell. +``` + +#### **`EEPROM.begin()`** + +This function returns an `EEPtr` pointing to the first cell in the EEPROM. +This is useful for STL objects, custom iteration and C++11 style ranged for loops. + +#### **`EEPROM.end()`** + +This function returns an `EEPtr` pointing at the location after the last EEPROM cell. +Used with `begin()` to provide custom iteration. + +**Note:** The `EEPtr` returned is invalid as it is out of range. Infact the hardware causes wrapping of the address (overflow) and `EEPROM.end()` actually references the first EEPROM cell. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino new file mode 100644 index 00000000..8b5121c8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_clear/eeprom_clear.ino @@ -0,0 +1,39 @@ +/* + * EEPROM Clear + * + * Sets all of the bytes of the EEPROM to 0. + * Please see eeprom_iteration for a more in depth + * look at how to traverse the EEPROM. + * + * This example code is in the public domain. + */ + +#include + +void setup() { + // initialize the LED pin as an output. + pinMode(13, OUTPUT); + + /*** + Iterate through each byte of the EEPROM storage. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + + for (int i = 0 ; i < EEPROM.length() ; i++) { + EEPROM.write(i, 0); + } + + // turn the LED on when we're done + digitalWrite(13, HIGH); +} + +void loop() { + /** Empty loop. **/ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino new file mode 100644 index 00000000..c6db85c3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_crc/eeprom_crc.ino @@ -0,0 +1,52 @@ +/*** + Written by Christopher Andrews. + CRC algorithm generated by pycrc, MIT licence ( https://github.com/tpircher/pycrc ). + + A CRC is a simple way of checking whether data has changed or become corrupted. + This example calculates a CRC value directly on the EEPROM values. + The purpose of this example is to highlight how the EEPROM object can be used just like an array. +***/ + +#include +#include + +void setup() { + + //Start serial + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + //Print length of data to run CRC on. + Serial.print("EEPROM length: "); + Serial.println(EEPROM.length()); + + //Print the result of calling eeprom_crc() + Serial.print("CRC32 of EEPROM data: 0x"); + Serial.println(eeprom_crc(), HEX); + Serial.print("\n\nDone!"); +} + +void loop() { + /* Empty loop */ +} + +unsigned long eeprom_crc(void) { + + const unsigned long crc_table[16] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, + 0x76dc4190, 0x6b6b51f4, 0x4db26158, 0x5005713c, + 0xedb88320, 0xf00f9344, 0xd6d6a3e8, 0xcb61b38c, + 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c + }; + + unsigned long crc = ~0L; + + for (int index = 0 ; index < EEPROM.length() ; ++index) { + crc = crc_table[(crc ^ EEPROM[index]) & 0x0f] ^ (crc >> 4); + crc = crc_table[(crc ^ (EEPROM[index] >> 4)) & 0x0f] ^ (crc >> 4); + crc = ~crc; + } + return crc; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino new file mode 100644 index 00000000..a07cee7c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_get/eeprom_get.ino @@ -0,0 +1,68 @@ +/*** + eeprom_get example. + + This shows how to use the EEPROM.get() method. + + To pre-set the EEPROM data, run the example sketch eeprom_put. + This sketch will run without it, however, the values shown + will be shown from what ever is already on the EEPROM. + + This may cause the serial object to print out a large string + of garbage if there is no null character inside one of the strings + loaded. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + float f = 0.00f; //Variable to store data read from EEPROM. + int eeAddress = 0; //EEPROM address to start reading from + + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + Serial.print("Read float from EEPROM: "); + + //Get the float data from the EEPROM at position 'eeAddress' + EEPROM.get(eeAddress, f); + Serial.println(f, 3); //This may print 'ovf, nan' if the data inside the EEPROM is not a valid float. + + /*** + As get also returns a reference to 'f', you can use it inline. + E.g: Serial.print( EEPROM.get( eeAddress, f ) ); + ***/ + + /*** + Get can be used with custom structures too. + I have separated this into an extra function. + ***/ + + secondTest(); //Run the next test. +} + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +void secondTest() { + int eeAddress = sizeof(float); //Move address to the next byte after float 'f'. + + MyObject customVar; //Variable to store custom object read from EEPROM. + EEPROM.get(eeAddress, customVar); + + Serial.println("Read custom object from EEPROM: "); + Serial.println(customVar.field1); + Serial.println(customVar.field2); + Serial.println(customVar.name); +} + +void loop() { + /* Empty loop */ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino new file mode 100644 index 00000000..3673b472 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_iteration/eeprom_iteration.ino @@ -0,0 +1,57 @@ +/*** + eeprom_iteration example. + + A set of example snippets highlighting the + simplest methods for traversing the EEPROM. + + Running this sketch is not necessary, this is + simply highlighting certain programming methods. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +void setup() { + + /*** + Iterate the EEPROM using a for loop. + ***/ + + for (int index = 0 ; index < EEPROM.length() ; index++) { + + //Add one to each cell in the EEPROM + EEPROM[ index ] += 1; + } + + /*** + Iterate the EEPROM using a while loop. + ***/ + + int index = 0; + + while (index < EEPROM.length()) { + + //Add one to each cell in the EEPROM + EEPROM[ index ] += 1; + index++; + } + + /*** + Iterate the EEPROM using a do-while loop. + ***/ + + int idx = 0; //Used 'idx' to avoid name conflict with 'index' above. + + do { + + //Add one to each cell in the EEPROM + EEPROM[ idx ] += 1; + idx++; + } while (idx < EEPROM.length()); + + +} //End of setup function. + +void loop() {} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino new file mode 100644 index 00000000..c1ba0a57 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_put/eeprom_put.ino @@ -0,0 +1,58 @@ +/*** + eeprom_put example. + + This shows how to use the EEPROM.put() method. + Also, this sketch will pre-set the EEPROM data for the + example sketch eeprom_get. + + Note, unlike the single byte version EEPROM.write(), + the put method will use update semantics. As in a byte + will only be written to the EEPROM if the data is actually + different. + + Written by Christopher Andrews 2015 + Released under MIT licence. +***/ + +#include + +struct MyObject { + float field1; + byte field2; + char name[10]; +}; + +void setup() { + + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + float f = 123.456f; //Variable to store in EEPROM. + int eeAddress = 0; //Location we want the data to be put. + + + //One simple call, with the address first and the object second. + EEPROM.put(eeAddress, f); + + Serial.println("Written float data type!"); + + /** Put is designed for use with custom structures also. **/ + + //Data to store. + MyObject customVar = { + 3.14f, + 65, + "Working!" + }; + + eeAddress += sizeof(float); //Move address to the next byte after float 'f'. + + EEPROM.put(eeAddress, customVar); + Serial.print("Written custom data type! \n\nView the example sketch eeprom_get to see how you can retrieve the values!"); +} + +void loop() { + /* Empty loop */ +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino new file mode 100644 index 00000000..a8a3510d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_read/eeprom_read.ino @@ -0,0 +1,56 @@ +/* + * EEPROM Read + * + * Reads the value of each byte of the EEPROM and prints it + * to the computer. + * This example code is in the public domain. + */ + +#include + +// start reading from the first byte (address 0) of the EEPROM +int address = 0; +byte value; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } +} + +void loop() { + // read a byte from the current address of the EEPROM + value = EEPROM.read(address); + + Serial.print(address); + Serial.print("\t"); + Serial.print(value, DEC); + Serial.println(); + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + address = address + 1; + if (address == EEPROM.length()) { + address = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++address &= EEPROM.length() - 1; + ***/ + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino new file mode 100644 index 00000000..5e3db5b4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_update/eeprom_update.ino @@ -0,0 +1,71 @@ +/*** + EEPROM Update method + + Stores values read from analog input 0 into the EEPROM. + These values will stay in the EEPROM when the board is + turned off and may be retrieved later by another sketch. + + If a value has not changed in the EEPROM, it is not overwritten + which would reduce the life span of the EEPROM unnecessarily. + + Released using MIT licence. + ***/ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int address = 0; + +void setup() { + /** EMpty setup **/ +} + +void loop() { + /*** + need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + int val = analogRead(0) / 4; + + /*** + Update the particular EEPROM cell. + these values will remain there when the board is + turned off. + ***/ + EEPROM.update(address, val); + + /*** + The function EEPROM.update(address, val) is equivalent to the following: + + if( EEPROM.read(address) != val ){ + EEPROM.write(address, val); + } + ***/ + + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + address = address + 1; + if (address == EEPROM.length()) { + address = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++address &= EEPROM.length() - 1; + ***/ + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino new file mode 100644 index 00000000..f9bea641 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/EEPROM/examples/eeprom_write/eeprom_write.ino @@ -0,0 +1,60 @@ +/* + * EEPROM Write + * + * Stores values read from analog input 0 into the EEPROM. + * These values will stay in the EEPROM when the board is + * turned off and may be retrieved later by another sketch. + */ + +#include + +/** the current address in the EEPROM (i.e. which byte we're going to write to next) **/ +int addr = 0; + +void setup() { + /** Empty setup. **/ +} + +void loop() { + /*** + Need to divide by 4 because analog inputs range from + 0 to 1023 and each byte of the EEPROM can only hold a + value from 0 to 255. + ***/ + + int val = analogRead(0) / 4; + + /*** + Write the value to the appropriate byte of the EEPROM. + these values will remain there when the board is + turned off. + ***/ + + EEPROM.write(addr, val); + + /*** + Advance to the next address, when at the end restart at the beginning. + + Larger AVR processors have larger EEPROM sizes, E.g: + - Arduno Duemilanove: 512b EEPROM storage. + - Arduino Uno: 1kb EEPROM storage. + - Arduino Mega: 4kb EEPROM storage. + + Rather than hard-coding the length, you should use the pre-provided length function. + This will make your code portable to all AVR processors. + ***/ + addr = addr + 1; + if (addr == EEPROM.length()) { + addr = 0; + } + + /*** + As the EEPROM sizes are powers of two, wrapping (preventing overflow) of an + EEPROM address is also doable by a bitwise and of the length - 1. + + ++addr &= EEPROM.length() - 1; + ***/ + + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino new file mode 100644 index 00000000..df73adeb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -0,0 +1,143 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + */ + +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initalize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return (result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 00000000..8719058e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -0,0 +1,73 @@ +/* + Digital Pot Control + + This example controls an Analog Devices AD5206 digital potentiometer. + The AD5206 has 6 potentiometer channels. Each channel's pins are labeled + A - connect this to voltage + W - this is the pot's wiper, which changes when you set it + B - connect this to ground. + + The AD5206 is SPI-compatible,and to command it, you send two bytes, + one with the channel number (0 - 5) and one with the resistance value for the + channel (0 - 255). + + The circuit: + * All A pins of AD5206 connected to +5V + * All B pins of AD5206 connected to ground + * An LED and a 220-ohm resisor in series connected from each W pin to ground + * CS - to digital pin 10 (SS pin) + * SDI - to digital pin 11 (MOSI pin) + * CLK - to digital pin 13 (SCK pin) + + created 10 Aug 2010 + by Tom Igoe + + Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 + +*/ + + +// inslude the SPI library: +#include + + +// set pin 10 as the slave select for the digital pot: +const int slaveSelectPin = 10; + +void setup() { + // set the slaveSelectPin as an output: + pinMode(slaveSelectPin, OUTPUT); + // initialize SPI: + SPI.begin(); +} + +void loop() { + // go through the six channels of the digital pot: + for (int channel = 0; channel < 6; channel++) { + // change the resistance on this channel from min to max: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, level); + delay(10); + } + // wait a second at the top: + delay(100); + // change the resistance on this channel from max to min: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, 255 - level); + delay(10); + } + } + +} + +void digitalPotWrite(int address, int value) { + // take the SS pin low to select the chip: + digitalWrite(slaveSelectPin, LOW); + delay(100); + // send in the address and value via SPI: + SPI.transfer(address); + SPI.transfer(value); + delay(100); + // take the SS pin high to de-select the chip: + digitalWrite(slaveSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino new file mode 100644 index 00000000..61ce88c6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/SoftwareSerialExample/SoftwareSerialExample.ino @@ -0,0 +1,55 @@ +/* + Software serial multple serial test + + Receives from the hardware serial, sends to software serial. + Receives from software serial, sends to hardware serial. + + The circuit: + * RX is digital pin 10 (connect to TX of other device) + * TX is digital pin 11 (connect to RX of other device) + + Note: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: + 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + + Not all pins on the Leonardo and Micro support change interrupts, + so only the following can be used for RX: + 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). + + created back in the mists of time + modified 25 May 2012 + by Tom Igoe + based on Mikal Hart's example + + This example code is in the public domain. + + */ +#include + +SoftwareSerial mySerial(10, 11); // RX, TX + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(57600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + Serial.println("Goodnight moon!"); + + // set the data rate for the SoftwareSerial port + mySerial.begin(4800); + mySerial.println("Hello, world?"); +} + +void loop() { // run over and over + if (mySerial.available()) { + Serial.write(mySerial.read()); + } + if (Serial.available()) { + mySerial.write(Serial.read()); + } +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino new file mode 100644 index 00000000..8d7f93e8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/SoftwareSerial/examples/TwoPortReceive/TwoPortReceive.ino @@ -0,0 +1,91 @@ +/* + Software serial multple serial test + + Receives from the two software serial ports, + sends to the hardware serial port. + + In order to listen on a software port, you call port.listen(). + When using two software serial ports, you have to switch ports + by listen()ing on each one in turn. Pick a logical time to switch + ports, like the end of an expected transmission, or when the + buffer is empty. This example switches ports when there is nothing + more to read from a port + + The circuit: + Two devices which communicate serially are needed. + * First serial device's TX attached to digital pin 10(RX), RX to pin 11(TX) + * Second serial device's TX attached to digital pin 8(RX), RX to pin 9(TX) + + Note: + Not all pins on the Mega and Mega 2560 support change interrupts, + so only the following can be used for RX: + 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69 + + Not all pins on the Leonardo support change interrupts, + so only the following can be used for RX: + 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI). + + created 18 Apr. 2011 + modified 19 March 2016 + by Tom Igoe + based on Mikal Hart's twoPortRXExample + + This example code is in the public domain. + + */ + +#include +// software serial #1: RX = digital pin 10, TX = digital pin 11 +SoftwareSerial portOne(10, 11); + +// software serial #2: RX = digital pin 8, TX = digital pin 9 +// on the Mega, use other pins instead, since 8 and 9 don't work on the Mega +SoftwareSerial portTwo(8, 9); + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + // Start each software serial port + portOne.begin(9600); + portTwo.begin(9600); +} + +void loop() { + // By default, the last intialized port is listening. + // when you want to listen on a port, explicitly select it: + portOne.listen(); + Serial.println("Data from port one:"); + // while there is data coming in, read it + // and send to the hardware serial port: + while (portOne.available() > 0) { + char inByte = portOne.read(); + Serial.write(inByte); + } + + // blank line to separate data from the two ports: + Serial.println(); + + // Now listen on the second port + portTwo.listen(); + // while there is data coming in, read it + // and send to the hardware serial port: + Serial.println("Data from port two:"); + while (portTwo.available() > 0) { + char inByte = portTwo.read(); + Serial.write(inByte); + } + + // blank line to separate data from the two ports: + Serial.println(); +} + + + + + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino new file mode 100644 index 00000000..4d0a68f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -0,0 +1,84 @@ +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// by Nicholas Zambetti +// and James Tichenor + +// Demonstrates use of the Wire library reading data from the +// Devantech Utrasonic Rangers SFR08 and SFR10 + +// Created 29 April 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial communication at 9600bps +} + +int reading = 0; + +void loop() { + // step 1: instruct sensor to read echoes + Wire.beginTransmission(112); // transmit to device #112 (0x70) + // the address specified in the datasheet is 224 (0xE0) + // but i2c adressing uses the high 7 bits so it's 112 + Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) + Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds + Wire.endTransmission(); // stop transmitting + + // step 2: wait for readings to happen + delay(70); // datasheet suggests at least 65 milliseconds + + // step 3: instruct sensor to return a particular echo reading + Wire.beginTransmission(112); // transmit to device #112 + Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + + // step 4: request reading from sensor + Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 + + // step 5: receive reading from sensor + if (2 <= Wire.available()) { // if two bytes were received + reading = Wire.read(); // receive high byte (overwrites previous reading) + reading = reading << 8; // shift high byte to be high 8 bits + reading |= Wire.read(); // receive low byte as lower 8 bits + Serial.println(reading); // print the reading + } + + delay(250); // wait a bit since people have to read the output :) +} + + +/* + +// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) +// usage: changeAddress(0x70, 0xE6); + +void changeAddress(byte oldAddress, byte newAddress) +{ + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA0)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xAA)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA5)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(newAddress); + Wire.endTransmission(); +} + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino new file mode 100644 index 00000000..dd40a252 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -0,0 +1,34 @@ +// I2C Digital Potentiometer +// by Nicholas Zambetti +// and Shawn Bonkowski + +// Demonstrates use of the Wire library +// Controls AD5171 digital potentiometer via I2C/TWI + +// Created 31 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) +} + +byte val = 0; + +void loop() { + Wire.beginTransmission(44); // transmit to device #44 (0x2c) + // device address is specified in datasheet + Wire.write(byte(0x00)); // sends instruction byte + Wire.write(val); // sends potentiometer value byte + Wire.endTransmission(); // stop transmitting + + val++; // increment value + if (val == 64) { // if reached 64th position (max) + val = 0; // start over from lowest value + } + delay(500); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_reader/master_reader.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_reader/master_reader.ino new file mode 100644 index 00000000..ecab72ab --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_reader/master_reader.ino @@ -0,0 +1,29 @@ +// Wire Master Reader +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Reads data from an I2C/TWI slave device +// Refer to the "Wire Slave Sender" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() { + Wire.requestFrom(8, 6); // request 6 bytes from slave device #8 + + while (Wire.available()) { // slave may send less than requested + char c = Wire.read(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_writer/master_writer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_writer/master_writer.ino new file mode 100644 index 00000000..5cbea117 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/master_writer/master_writer.ino @@ -0,0 +1,29 @@ +// Wire Master Writer +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Writes data to an I2C/TWI slave device +// Refer to the "Wire Slave Receiver" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(); // join i2c bus (address optional for master) +} + +byte x = 0; + +void loop() { + Wire.beginTransmission(8); // transmit to device #8 + Wire.write("x is "); // sends five bytes + Wire.write(x); // sends one byte + Wire.endTransmission(); // stop transmitting + + x++; + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_receiver/slave_receiver.ino new file mode 100644 index 00000000..8051d53a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -0,0 +1,34 @@ +// Wire Slave Receiver +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI slave device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(8); // join i2c bus with address #8 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() { + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) { + while (1 < Wire.available()) { // loop through all but the last + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_sender/slave_sender.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_sender/slave_sender.ino new file mode 100644 index 00000000..d2e72bbc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-megaavr/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -0,0 +1,29 @@ +// Wire Slave Sender +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Sends data as an I2C/TWI slave device +// Refer to the "Wire Master Reader" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() { + Wire.begin(8); // join i2c bus with address #8 + Wire.onRequest(requestEvent); // register event +} + +void loop() { + delay(100); +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() { + Wire.write("hello "); // respond with message of 6 bytes + // as expected by master +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/LICENSE new file mode 100644 index 00000000..8000a6fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/LICENSE @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 + USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random + Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/README.md new file mode 100644 index 00000000..b8bcac19 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/README.md @@ -0,0 +1,71 @@ +# Arduino Core for SAMD21 CPU + +This repository contains the source code and configuration files of the Arduino Core +for Atmel's SAMD21 processor (used on the Arduino/Genuino Zero, MKR1000 and MKRZero boards). + +## Installation on Arduino IDE + +This core is available as a package in the Arduino IDE cores manager. +Just open the "Boards Manager" and install the package called: + +"Arduino SAMD Boards (32-bit ARM Cortex-M0+)" + +## Support + +There is a dedicated section of the Arduino Forum for general discussion and project assistance: + +http://forum.arduino.cc/index.php?board=98.0 + +## Bugs or Issues + +If you find a bug you can submit an issue here on github: + +https://github.com/arduino/ArduinoCore-samd/issues + +Before posting a new issue, please check if the same problem has been already reported by someone else +to avoid duplicates. + +## Contributions + +Contributions are always welcome. The preferred way to receive code contribution is by submitting a +Pull Request on github. + +## Hourly builds + +This repository is under a Continuous Integration system that every hour checks if there are updates and +builds a release for testing (the so called "Hourly builds"). + +The hourly builds are available through Boards Manager. If you want to install them: + 1. Open the **Preferences** of the Arduino IDE. + 2. Add this URL `http://downloads.arduino.cc/Hourly/samd/package_samd-hourly-build_index.json` in the **Additional Boards Manager URLs** field, and click OK. + 3. Open the **Boards Manager** (menu Tools->Board->Board Manager...) + 4. Install **Arduino SAMD core - Hourly build** + 5. Select one of the boards under **SAMD Hourly build XX** in Tools->Board menu + 6. Compile/Upload as usual + +If you already installed an hourly build and you want to update it with the latest: + 1. Open the **Boards Manager** (menu Tools->Board->Board Manager...) + 2. Remove **Arduino SAMD core - Hourly build** + 3. Install again **Arduino SAMD core - Hourly build**, the Board Manager will download the latest build replacing the old one. + +## License and credits + +This core has been developed by Arduino LLC in collaboration with Atmel. + +``` + Copyright (c) 2015 Arduino LLC. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +``` diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino new file mode 100644 index 00000000..48b2a0a4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/InputSerialPlotter/InputSerialPlotter.ino @@ -0,0 +1,46 @@ +/* + This example reads audio data from an Invensense's ICS43432 I2S microphone + breakout board, and prints out the samples to the Serial console. The + Serial Plotter built into the Arduino IDE can be used to plot the audio + data (Tools -> Serial Plotter) + + Circuit: + * Arduino/Genuino Zero, MKR family and Nano 33 IoT + * ICS43432: + * GND connected GND + * 3.3V connected to 3.3V (Zero, Nano) or VCC (MKR) + * WS connected to pin 0 (Zero) or 3 (MKR) or A2 (Nano) + * CLK connected to pin 1 (Zero) or 2 (MKR) or A3 (Nano) + * SD connected to pin 9 (Zero) or A6 (MKR) or 4 (Nano) + + created 17 November 2016 + by Sandeep Mistry + */ + +#include + +void setup() { + // Open serial communications and wait for port to open: + // A baud rate of 115200 is used instead of 9600 for a faster data rate + // on non-native USB ports + Serial.begin(115200); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // start I2S at 8 kHz with 32-bits per sample + if (!I2S.begin(I2S_PHILIPS_MODE, 8000, 32)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } +} + +void loop() { + // read a sample + int sample = I2S.read(); + + if (sample) { + // if it's non-zero print value to serial + Serial.println(sample); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/SimpleTone/SimpleTone.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/SimpleTone/SimpleTone.ino new file mode 100644 index 00000000..de67ed98 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/I2S/examples/SimpleTone/SimpleTone.ino @@ -0,0 +1,53 @@ +/* + This example generates a square wave based tone at a specified frequency + and sample rate. Then outputs the data using the I2S interface to a + MAX08357 I2S Amp Breakout board. + + Circuit: + * Arduino/Genuino Zero, MKR family and Nano 33 IoT + * MAX08357: + * GND connected GND + * VIN connected 5V + * LRC connected to pin 0 (Zero) or 3 (MKR) or A2 (Nano) + * BCLK connected to pin 1 (Zero) or 2 (MKR) or A3 (Nano) + * DIN connected to pin 9 (Zero) or A6 (MKR) or 4 (Nano) + + created 17 November 2016 + by Sandeep Mistry + */ + +#include + +const int frequency = 440; // frequency of square wave in Hz +const int amplitude = 500; // amplitude of square wave +const int sampleRate = 8000; // sample rate in Hz + +const int halfWavelength = (sampleRate / frequency); // half wavelength of square wave + +short sample = amplitude; // current sample value +int count = 0; + +void setup() { + Serial.begin(9600); + Serial.println("I2S simple tone"); + + // start I2S at the sample rate with 16-bits per sample + if (!I2S.begin(I2S_PHILIPS_MODE, sampleRate, 16)) { + Serial.println("Failed to initialize I2S!"); + while (1); // do nothing + } +} + +void loop() { + if (count % halfWavelength == 0) { + // invert the sample every half wavelength count multiple to generate square wave + sample = -1 * sample; + } + + // write the same sample twice, once for left and once for the right channel + I2S.write(sample); + I2S.write(sample); + + // increment the counter for the next sample + count++; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SAMD_AnalogCorrection/examples/CorrectADCResponse/CorrectADCResponse.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SAMD_AnalogCorrection/examples/CorrectADCResponse/CorrectADCResponse.ino new file mode 100644 index 00000000..d4a4a647 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SAMD_AnalogCorrection/examples/CorrectADCResponse/CorrectADCResponse.ino @@ -0,0 +1,211 @@ +/* + This sketch easily and quickly finds the right ADC correction values for a particular Arduino ZERO board. + The correction values that are found are only valid for the board where the sketch is executed. + + This example code is in the public domain. + + Written 6 May 2015 by Claudio Indellicati +*/ + +/* + How to use this sketch + + 1) Remove any connection cable, shield or jumper from your Arduino ZERO + 2) Connect pin A1 to the nearest GND pin using the shortest jumper possible + 3) Connect pin A2 to the 3.3V pin using the shortest jumper possible + 4) Connect the Arduino ZERO to your PC using a USB cable plugged in the USB programming port of the board + 5) Upload this sketch and leave the board powered on for at least one minute + 6) Open the Serial Monitor and press the reset button on the Arduino ZERO + 7) At the and of the procedure you can find logged + - the offset and gain values for the board where the sketch has been just executed + - the code to copy/paste in sketches using this library +*/ + +#include "SAMD_AnalogCorrection.h" + +#define ADC_GND_PIN A1 +#define ADC_3V3_PIN A2 + +#define ADC_READS_SHIFT 8 +#define ADC_READS_COUNT (1 << ADC_READS_SHIFT) + +#define ADC_MIN_GAIN 0x0400 +#define ADC_UNITY_GAIN 0x0800 +#define ADC_MAX_GAIN (0x1000 - 1) +#define ADC_RESOLUTION_BITS 12 // do not change. This library only supports 12 bit resolution. +#define ADC_RANGE (1 << ADC_RESOLUTION_BITS) +#define ADC_TOP_VALUE (ADC_RANGE - 1) + +#define MAX_TOP_VALUE_READS 10 + +void setup() +{ + Serial.begin(9600); + + Serial.println("\r\nCalibrating ADC with factory values"); + + analogReadResolution(ADC_RESOLUTION_BITS); + + Serial.println("\r\nReading GND and 3.3V ADC levels"); + Serial.print(" "); + readGndLevel(); + Serial.print(" "); + read3V3Level(); + + int offsetCorrectionValue = 0; + uint16_t gainCorrectionValue = ADC_UNITY_GAIN; + + Serial.print("\r\nOffset correction (@gain = "); + Serial.print(gainCorrectionValue); + Serial.println(" (unity gain))"); + + // Set default correction values and enable correction + analogReadCorrection(offsetCorrectionValue, gainCorrectionValue); + + for (int offset = 0; offset < (int)(ADC_OFFSETCORR_MASK >> 1); ++offset) + { + analogReadCorrection(offset, gainCorrectionValue); + + Serial.print(" Offset = "); + Serial.print(offset); + Serial.print(", "); + + if (readGndLevel() == 0) + { + offsetCorrectionValue = offset; + break; + } + } + + Serial.println("\r\nGain correction"); + + uint8_t topValueReadsCount = 0U; + + uint16_t minGain = 0U, + maxGain = 0U; + + analogReadCorrection(offsetCorrectionValue, gainCorrectionValue); + Serial.print(" Gain = "); + Serial.print(gainCorrectionValue); + Serial.print(", "); + uint16_t highLevelRead = read3V3Level(); + + if (highLevelRead < ADC_TOP_VALUE) + { + for (uint16_t gain = ADC_UNITY_GAIN + 1; gain <= ADC_MAX_GAIN; ++gain) + { + analogReadCorrection(offsetCorrectionValue, gain); + + Serial.print(" Gain = "); + Serial.print(gain); + Serial.print(", "); + highLevelRead = read3V3Level(); + + if (highLevelRead == ADC_TOP_VALUE) + { + if (minGain == 0U) + minGain = gain; + + if (++topValueReadsCount >= MAX_TOP_VALUE_READS) + { + maxGain = minGain; + break; + } + + maxGain = gain; + } + + if (highLevelRead > ADC_TOP_VALUE) + break; + } + } + else if (highLevelRead >= ADC_TOP_VALUE) + { + if (highLevelRead == ADC_TOP_VALUE) + maxGain = ADC_UNITY_GAIN; + + for (uint16_t gain = ADC_UNITY_GAIN - 1; gain >= ADC_MIN_GAIN; --gain) + { + analogReadCorrection(offsetCorrectionValue, gain); + + Serial.print(" Gain = "); + Serial.print(gain); + Serial.print(", "); + highLevelRead = read3V3Level(); + + if (highLevelRead == ADC_TOP_VALUE) + { + if (maxGain == 0U) + maxGain = gain; + + minGain = gain; + } + + if (highLevelRead < ADC_TOP_VALUE) + break; + } + } + + gainCorrectionValue = (minGain + maxGain) >> 1; + + analogReadCorrection(offsetCorrectionValue, gainCorrectionValue); + + Serial.println("\r\nReadings after corrections"); + Serial.print(" "); + readGndLevel(); + Serial.print(" "); + read3V3Level(); + + Serial.println("\r\n=================="); + Serial.println("\r\nCorrection values:"); + Serial.print(" Offset = "); + Serial.println(offsetCorrectionValue); + Serial.print(" Gain = "); + Serial.println(gainCorrectionValue); + Serial.println("\r\nAdd the next lines to your sketch:"); + Serial.println(" analogReadResolution(12);"); + Serial.print(" analogReadCorrection("); + Serial.print(offsetCorrectionValue); + Serial.print(", "); + Serial.print(gainCorrectionValue); + Serial.println(");"); + Serial.println("\r\n=================="); +} + +void loop() +{ +} + +uint16_t readGndLevel() +{ + uint32_t readAccumulator = 0; + + for (int i = 0; i < ADC_READS_COUNT; ++i) + readAccumulator += analogRead(ADC_GND_PIN); + + uint16_t readValue = readAccumulator >> ADC_READS_SHIFT; + + Serial.print("ADC(GND) = "); + Serial.println(readValue); + + return readValue; +} + +uint16_t read3V3Level() +{ + uint32_t readAccumulator = 0; + + for (int i = 0; i < ADC_READS_COUNT; ++i) + readAccumulator += analogRead(ADC_3V3_PIN); + + uint16_t readValue = readAccumulator >> ADC_READS_SHIFT; + + if (readValue < (ADC_RANGE >> 1)) + readValue += ADC_RANGE; + + Serial.print("ADC(3.3V) = "); + Serial.println(readValue); + + return readValue; +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SAMD_BootloaderUpdater/examples/UpdateBootloader/UpdateBootloader.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SAMD_BootloaderUpdater/examples/UpdateBootloader/UpdateBootloader.ino new file mode 100644 index 00000000..1bb76bf4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SAMD_BootloaderUpdater/examples/UpdateBootloader/UpdateBootloader.ino @@ -0,0 +1,88 @@ +/* + Update Bootloader + + This sketch checks if your Arduino SAMD board is running the latest bootloader. + + If it is not, it prompts you to update it. + + Circuit: + - MKR Vidor 4000 + + This example code is in the public domain. +*/ + + +#include + +void setup() { + + Serial.begin(9600); + while (!Serial); + + Serial.println("Welcome to the Arduino SAMD bootloader updater"); + Serial.println("----------------------------------------------"); + Serial.println(); + +retry: + Serial.print("Checking if bootloader requires an update ... "); + if (SAMD_BootloaderUpdater.needsUpdate()) { + Serial.println("bootloader is already the latest version"); + Serial.println(); + Serial.println("Update is not required :)"); + + while (1); + } + + Serial.println("bootloader is NOT running the latest"); + Serial.println(); + Serial.println(); + Serial.println("Would you like to proceed with updating it? (y/N)"); + Serial.println(); + + + while (Serial.available() == 0) { + delay(100); + } + char in = Serial.read(); + if (in != 'y' && in != 'Y') { + Serial.println("That's all folks!"); + while (1); + } + + pinMode(LED_BUILTIN, OUTPUT); + + Serial.println("WARNING: DO NOT UNPLUG the USB cable during the update!!!"); + Serial.println(); + Serial.println("Updating bootloader ..."); + Serial.println(); + + if (!SAMD_BootloaderUpdater.update(onUpdateProgress)) { + Serial.println("oh no! the bootloader failed to update :("); + Serial.println(); + goto retry; + } + + Serial.println(); + Serial.println("The bootloader was successfully updated \\o/"); + Serial.println(); + Serial.println("Your board will now start blinking in joy :)"); +} + +void onUpdateProgress(float percentage) +{ + // toggle the LED + digitalWrite(LED_BUILTIN, digitalRead(LED_BUILTIN) ? LOW : HIGH); + + // print out the percentage + Serial.print(percentage); + Serial.println("%"); +} + +void loop() { + digitalWrite(LED_BUILTIN, HIGH); + delay(100); + + digitalWrite(LED_BUILTIN, LOW); + delay(100); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadBinary/SBU_LoadBinary.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadBinary/SBU_LoadBinary.ino new file mode 100644 index 00000000..12be605d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadBinary/SBU_LoadBinary.ino @@ -0,0 +1,96 @@ +#include +#include + +static char const BINARY[] = +{ + #include "Binary.h" +}; + +static char const CHECK_FILE[] = +{ + "OK" +}; + +static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK"; + +NBFileUtils fileUtils; +bool update_available = false; + +void setup() { + Serial.begin(9600); + while(!Serial) { } + + unsigned long const start = millis(); + for(unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { }; + + Serial.print("Accessing SARA Filesystem... "); + if(!fileUtils.begin(false)) { + Serial.println("failed."); + return; + + } + Serial.println("OK"); + Serial.print("Writing \"UPDATE.BIN\" ... "); + + uint32_t bytes_to_write = sizeof(BINARY); + Serial.print("Size of BINARY: "); + Serial.println(bytes_to_write); + int index = 0; + bool append = false; + int new_bytes = 0; + //int bytes_written = 0; + + for (int i=0; i<(bytes_to_write/512); i++) { + auto new_bytes = fileUtils.downloadFile("UPDATE.BIN", BINARY+index, 512, append); + if (new_bytes != 512) { + Serial.print("New_bytes = "); + Serial.print(new_bytes); + Serial.println(" != 512"); + } + index = index + new_bytes; + append = true; + } + if ((bytes_to_write%512)!=0) { + auto new_bytes = fileUtils.downloadFile("UPDATE.BIN", BINARY+index, bytes_to_write%512, append); + if (new_bytes != bytes_to_write%512) { + Serial.print("Last bytes read = "); + Serial.print(new_bytes); + Serial.print(". They should have been "); + Serial.println(bytes_to_write%512); + } + index = index + new_bytes; + } + + if(index != bytes_to_write) { + Serial.print("Written only "); + Serial.println(index); //bytes_written + Serial.print(bytes_to_write); + Serial.println(" should have been written. System is restarting..."); + delay(100); + NVIC_SystemReset(); + + } else { + Serial.print("Download complete! "); + Serial.print(index); + Serial.println(" bytes written"); + + auto status = 0; + while (status != 2) { + status = fileUtils.createFile(CHECK_FILE_NAME, CHECK_FILE, 2); + delay(100); + } + + Serial.println("Please type \"restart\" to apply the update"); + update_available = true; + } + +} + +void loop() { + if (update_available == true) { + String command = Serial.readStringUntil('\n'); + if (command.indexOf("restart") >= 0) { + NVIC_SystemReset(); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/SBU_LoadLZSS.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/SBU_LoadLZSS.ino new file mode 100644 index 00000000..6f5e8caa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/SBU_LoadLZSS.ino @@ -0,0 +1,73 @@ +#include +#include + +#include "lzssEncode.h" + +static char const BINARY[] = +{ +#include "Binary.h" +}; + +static char const CHECK_FILE[] = +{ + "OK" +}; + +static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK"; +const char * UPDATE_FILE_NAME_LZSS = "UPDATE.BIN.LZSS"; + +NBFileUtils fileUtils; +bool update_available = false; + +void setup() { + Serial.begin(9600); + while (!Serial) { } + + unsigned long const start = millis(); + for (unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { }; + + Serial.print("Accessing SARA Filesystem... "); + if (!fileUtils.begin(false)) { + Serial.println("failed."); + return; + + } + Serial.println("OK"); + + uint32_t bytes_to_write = sizeof(BINARY); + Serial.print("Size of BINARY.H: "); + Serial.println(bytes_to_write); + + Serial.print("Encoding \"BINARY.H\" into \"UPDATE.BIN.LZSS\" and writing it into the Sara-R410M module ... "); + + //Encode into .lzss and write to the Sara modem + int bytes_written = lzss_encode(BINARY, bytes_to_write); + + if (bytes_written == 0) { + Serial.println("something went wrong!"); + } else { + Serial.println("OK!"); + } + + Serial.print("Size of UPDATE.BIN.LZSS: "); + Serial.println(bytes_written); + + auto status = 0; + while (status != 2) { + status = fileUtils.createFile(CHECK_FILE_NAME, CHECK_FILE, 2); + delay(100); + } + + Serial.println("Please type \"restart\" to apply the update"); + update_available = true; +} + + +void loop() { + if (update_available == true) { + String command = Serial.readStringUntil('\n'); + if (command.indexOf("restart") >= 0) { + NVIC_SystemReset(); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp new file mode 100644 index 00000000..7f7934e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp @@ -0,0 +1,182 @@ +/************************************************************************************** + INCLUDE + **************************************************************************************/ + +#include "lzssEncode.h" + +#include +#include + +#include + +/************************************************************************************** + DEFINE + **************************************************************************************/ + +#define EI 11 /* typically 10..13 */ +#define EJ 4 /* typically 4..5 */ +#define P 1 /* If match length <= P then output one character */ +#define N (1 << EI) /* buffer size */ +#define F ((1 << EJ) + 1) /* lookahead buffer size */ + +#define LZSS_EOF (-1) + +#define FPUTC_BUF_SIZE (512) +#define FGETC_BUF_SIZE (512) + +/************************************************************************************** + GLOBAL VARIABLES + **************************************************************************************/ + +extern NBFileUtils fileUtils; +extern const char * UPDATE_FILE_NAME_LZSS; + +int bit_buffer = 0, bit_mask = 128; +unsigned long textcount = 0; +unsigned char buffer[N * 2]; + +static char write_buf[FPUTC_BUF_SIZE]; +static size_t write_buf_num_bytes = 0; +static size_t bytes_written_fputc = 0; + +bool append = false; +bool endOfFile = false; + +/************************************************************************************** + PUBLIC FUNCTIONS + **************************************************************************************/ + +void lzss_flush() +{ + bytes_written_fputc += write_buf_num_bytes; + + fileUtils.downloadFile(UPDATE_FILE_NAME_LZSS, write_buf, write_buf_num_bytes, append); //UPDATE.BIN.LZSS + append = true; + + write_buf_num_bytes = 0; +} + +/************************************************************************************** + PRIVATE FUNCTIONS + **************************************************************************************/ + +void lzss_fputc(int const c) +{ + /* Buffer the compressed data into a buffer so + * we can perform block writes and don't need to + * write every byte singly on the modem + */ + write_buf[write_buf_num_bytes] = static_cast(c); + write_buf_num_bytes++; + + /* The write buffer is full of compressed + * data, write it to the modem now. + */ + if (write_buf_num_bytes == FPUTC_BUF_SIZE || endOfFile) + lzss_flush(); +} + +/************************************************************************************** + LZSS FUNCTIONS + **************************************************************************************/ + +void putbit1(void) +{ + bit_buffer |= bit_mask; + if ((bit_mask >>= 1) == 0) { + lzss_fputc(bit_buffer); + bit_buffer = 0; bit_mask = 128; + } +} + +void putbit0(void) +{ + if ((bit_mask >>= 1) == 0) { + lzss_fputc(bit_buffer); + bit_buffer = 0; bit_mask = 128; + } +} + +void flush_bit_buffer(void) +{ + if (bit_mask != 128) { + lzss_fputc(bit_buffer); + } +} + +void output1(int c) +{ + int mask; + + putbit1(); + mask = 256; + while (mask >>= 1) { + if (c & mask) putbit1(); + else putbit0(); + } +} + +void output2(int x, int y) +{ + int mask; + + putbit0(); + mask = N; + while (mask >>= 1) { + if (x & mask) putbit1(); + else putbit0(); + } + mask = (1 << EJ); + while (mask >>= 1) { + if (y & mask) putbit1(); + else putbit0(); + } +} + +int lzss_encode(const char buf_in[], uint32_t size) +{ + int i, j, f1, x, y, r, s, bufferend, c; + + for (i = 0; i < N - F; i++) buffer[i] = ' '; + for (i = N - F; i < N * 2; i++) { + if (textcount >= size) { + endOfFile = true; + break; + } else { + buffer[i] = buf_in[textcount]; + textcount++; + } + } + bufferend = i; r = N - F; s = 0; + while (r < bufferend) { + f1 = (F <= bufferend - r) ? F : bufferend - r; + x = 0; y = 1; c = buffer[r]; + for (i = r - 1; i >= s; i--) + if (buffer[i] == c) { + for (j = 1; j < f1; j++) + if (buffer[i + j] != buffer[r + j]) break; + if (j > y) { + x = i; y = j; + } + } + if (y <= P) { y = 1; output1(c); } + else output2(x & (N - 1), y - 2); + r += y; s += y; + if (r >= N * 2 - F) { + for (i = 0; i < N; i++) buffer[i] = buffer[i + N]; + bufferend -= N; r -= N; s -= N; + while (bufferend < N * 2) { + if (textcount >= size) { + endOfFile = true; + break; + } else { + buffer[bufferend++] = buf_in[textcount]; + textcount++; + } + } + } + } + flush_bit_buffer(); + + return bytes_written_fputc; +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.h new file mode 100644 index 00000000..2212c82b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.h @@ -0,0 +1,17 @@ +#ifndef SBU_LZSS_H_ +#define SBU_LZSS_H_ + +/************************************************************************************** + INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + FUNCTION DEFINITION + **************************************************************************************/ + +void lzss_flush(); +int lzss_encode(const char buf_in[], uint32_t size); + +#endif /* SBU_LZSS_H_ */ \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_Usage/SBU_Usage.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_Usage/SBU_Usage.ino new file mode 100644 index 00000000..85d781b3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SBU/examples/SBU_Usage/SBU_Usage.ino @@ -0,0 +1,48 @@ +/* + Usage + This example demonstrates how to use the SAMD SBU library to update a + sketch on any Arduino MKR board via the storage on the SARA-R410M module. + This sketch prints out the current date and time. + Steps to update sketch: + 1) Upload this sketch or another sketch that includes the SBU library + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time. + 3) In the IDE select: Sketch -> Export compiled Binary + 4) Open the location of the sketch and convert the .bin file to a C byte array. + cat SKETCH.bin | xxd --include > Binary.h + 5) Copy Binary.h file from the sketch's folder to the SBU_LoadBinary sketch + and load it to the SARA-R410M via SBU_LoadBinary sketch. +*/ + +/* + Include the SBU library + + This will add some code to the sketch before setup() is called + to check if UPDATE.BIN and UPDATE.OK are present on the storage of + the SARA-R410M module. If this check is positive UPDATE.BIN is used to update + the sketch running on the board. + After this UPDATE.BIN and UPDATE.OK are deleted from the flash. +*/ + + +#include + +void setup() +{ + Serial.begin(9600); + while (!Serial) { } + // wait a bit + delay(1000); + String message; + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + // print out the sketch compile date and time on the serial port + Serial.println(message); +} + +void loop() +{ + // add you own code here +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SDU/examples/Usage/Usage.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SDU/examples/Usage/Usage.ino new file mode 100644 index 00000000..443a7542 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SDU/examples/Usage/Usage.ino @@ -0,0 +1,73 @@ +/* + Usage + This example demonstrates how to use the SAMD SDU library to update a + sketch on an Arduino/Genuino Zero, MKRZero or MKR1000 board using an + SD card. It prints out the date and time the sketch was compiled at + to both Serial and Serial1. + + Circuit: + * Arduino MKRZero board with SD card + OR + * Arduino/Genuino Zero or MKR1000 board + * SD shield or breakout connected with CS pin of 4 + * SD card + + Non-Arduino/Genuino Zero, MKRZero or MKR1000 board are NOT supported. + + Steps to update sketch via SD card: + + 1) Upload this sketch or another sketch that includes the SDU library + via #include + + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time so no updates are needed. + + 3) In the IDE select: Sketch -> Export compiled Binary + + 4) Copy the .bin file from the sketch's folder to the SD card and rename + the file to UPDATE.bin. Eject the SD card from your PC. + + 5) Insert the SD card into the board, shield or breakout and press the + reset button or power cycle the board. The SDU library will then update + the sketch on the board with the contents of UPDATE.bin + + created 23 March 2017 + by Sandeep Mistry +*/ + +/* + Include the SDU library + + This will add some code to the sketch before setup() is called + to check if an SD card is present and UPDATE.bin exists on the + SD card. + + If UPDATE.bin is present, the file is used to update the sketch + running on the board. After this UPDATE.bin is deleted from the + SD card. +*/ +#include + +String message; + +void setup() { + Serial.begin(9600); + Serial1.begin(9600); + + // wait a bit + delay(1000); + + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + + // print out the sketch compile date and time on the serial port + Serial.println(message); + Serial1.println(message); +} + +void loop() { + // add you own code here +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/Binary.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/Binary.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/SFU_LoadBinary.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/SFU_LoadBinary.ino new file mode 100644 index 00000000..1b2754cb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_LoadBinary/SFU_LoadBinary.ino @@ -0,0 +1,63 @@ +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + +#include + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static uint8_t const BINARY[] = +{ + #include "Binary.h" +}; + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for(unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { }; + + flash.begin(); + + Serial.print("Mounting ... "); + if(SPIFFS_OK != filesystem.mount()) { + Serial.println("mount() failed with error code "); Serial.println(filesystem.err()); return; + } + Serial.println("OK"); + + + Serial.print("Checking ... "); + if(SPIFFS_OK != filesystem.check()) { + Serial.println("check() failed with error code "); Serial.println(filesystem.err()); return; + } + Serial.println("OK"); + + + Serial.print("Writing \"UPDATE.BIN\" ... "); + File file = filesystem.open("UPDATE.BIN", CREATE | READ_WRITE| TRUNCATE); + + int const bytes_to_write = sizeof(BINARY); + int const bytes_written = file.write((void *)BINARY, bytes_to_write); + + if(bytes_written != bytes_to_write) { + Serial.println("write() failed with error code "); Serial.println(filesystem.err()); return; + } else { + Serial.print("OK ("); + Serial.print(bytes_written); + Serial.println(" bytes written)"); + } + + Serial.print("Unmounting ... "); + filesystem.unmount(); + Serial.println("OK"); +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_Usage/SFU_Usage.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_Usage/SFU_Usage.ino new file mode 100644 index 00000000..db6efd10 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SFU/examples/SFU_Usage/SFU_Usage.ino @@ -0,0 +1,54 @@ +/* + Usage + This example demonstrates how to use the SAMD SFU library to update a + sketch on any Arduino MKR board connected to a MKRMEM Shield. This sketch + prints out the date and time the sketch was compiled. + + Steps to update sketch via MKRMEM shield: + + 1) Upload this sketch or another sketch that includes the SFU library + via #include + + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time so no updates are needed. + + 3) In the IDE select: Sketch -> Export compiled Binary + + 4) Open the location of the sketch and convert the .bin file to a C byte array. + cat SKETCH.bin | xxd --include > Binary.h + + 5) Copy Binary.h file from the sketch's folder to the SFU_LoadBinary sketch + and load it to the MKRMEM via SFU_LoadBinary sketch. +*/ + +/* + Include the SFU library + + This will add some code to the sketch before setup() is called + to check if UPDATE.bin is present on the flash chip of the MKRMEM + shield. If this theck is positive the file is used to update the sketch + running on the board. After this UPDATE.BIN is deleted from the flash. +*/ + +#include + +void setup() { + Serial.begin(9600); + while(!Serial) { } + + // wait a bit + delay(1000); + + String message; + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + + // print out the sketch compile date and time on the serial port + Serial.println(message); +} + +void loop() { + // add you own code here +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/Usage.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/Usage.ino new file mode 100644 index 00000000..5f020eac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/Usage.ino @@ -0,0 +1,106 @@ +/* + Usage + This example demonstrates how to use the SAMD SNU library to update a + sketch on an Arduino MKRWiFi1010 board using the board and nothing else. + It prints out the date and time the sketch was compiled at + to both Serial and Serial1. + + Arduino MKRWiFi1010 board + + Steps to update sketch via NINA WiFi/BT module: + + 1) Upload this sketch or another sketch that includes the SNU library + via #include + + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time so no updates are needed. + + 3) In the IDE select: Sketch -> Export compiled Binary + + 4) Use WiFiStorage.download(url, "UPDATE.BIN") function to download the + new binary from a remote webserver. + + 5) Reboot the board; the update will be applied seamlessly + + created 14 December 2018 + by Martino Facchin +*/ + +/* + Include the SNU library + + This will add some code to the sketch before setup() is called + to check if the WiFi module is present and UPDATE.bin exists. + + If UPDATE.bin is present, the file is used to update the sketch + running on the board. After this UPDATE.bin is deleted from NINA memory. +*/ +#include +#include + +#include "arduino_secrets.h" +///////please enter your sensitive data in the Secret tab/arduino_secrets.h +/////// Wifi Settings /////// +char ssid[] = SECRET_SSID; // your network SSID (name) +char pass[] = SECRET_PASS; // your network password +char url[] = SECRET_OTA_URL; + +int status = WL_IDLE_STATUS; + +String message; + +void setup() { + Serial.begin(9600); + Serial1.begin(9600); + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + // don't continue: + while (true); + } + + // attempt to connect to Wifi network: + while ( status != WL_CONNECTED) { + Serial.print("Attempting to connect to SSID: "); + Serial.println(ssid); + // Connect to WPA/WPA2 network. Change this line if using open or WEP network: + status = WiFi.begin(ssid, pass); + } + + // wait a bit + delay(1000); + + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + + // print out the sketch compile date and time on the serial port + Serial.println(message); + Serial1.println(message); + + Serial.println("Type \"download\" in the Serial Monitor to start downloading the update"); +} + +void loop() { + String command = Serial.readStringUntil('\n'); + + if (command.indexOf("download") >= 0) { + + Serial.println("Downloading update file"); + WiFiStorage.download(url, "UPDATE.BIN"); + + WiFiStorageFile update = WiFiStorage.open("/fs/UPDATE.BIN"); + if (update.available()) { + Serial.println("Download complete, please restart or type \"restart\" to apply the update"); + Serial.println("Filesize: " + String(update.available())); + } else { + Serial.println("Download failed, please retry :("); + } + } + + if (command.indexOf("restart") >= 0) { + NVIC_SystemReset(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/arduino_secrets.h new file mode 100644 index 00000000..6b57ebd7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SNU/examples/Usage/arduino_secrets.h @@ -0,0 +1,3 @@ +#define SECRET_SSID "" +#define SECRET_PASS "" +#define SECRET_OTA_URL "http://downloads.arduino.cc/misc/WiFi1010_blinkRBG.bin" diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino new file mode 100644 index 00000000..8104fcbc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/BarometricPressureSensor/BarometricPressureSensor.ino @@ -0,0 +1,143 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + */ + +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initalize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead ) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return(result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino new file mode 100644 index 00000000..a06f1133 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SPI/examples/DigitalPotControl/DigitalPotControl.ino @@ -0,0 +1,73 @@ +/* + Digital Pot Control + + This example controls an Analog Devices AD5206 digital potentiometer. + The AD5206 has 6 potentiometer channels. Each channel's pins are labeled + A - connect this to voltage + W - this is the pot's wiper, which changes when you set it + B - connect this to ground. + + The AD5206 is SPI-compatible,and to command it, you send two bytes, + one with the channel number (0 - 5) and one with the resistance value for the + channel (0 - 255). + + The circuit: + * All A pins of AD5206 connected to +5V + * All B pins of AD5206 connected to ground + * An LED and a 220-ohm resisor in series connected from each W pin to ground + * CS - to digital pin 10 (SS pin) + * SDI - to digital pin 11 (MOSI pin) + * CLK - to digital pin 13 (SCK pin) + + created 10 Aug 2010 + by Tom Igoe + + Thanks to Heather Dewey-Hagborg for the original tutorial, 2005 + +*/ + + +// inslude the SPI library: +#include + + +// set pin 10 as the slave select for the digital pot: +const int slaveSelectPin = 10; + +void setup() { + // set the slaveSelectPin as an output: + pinMode (slaveSelectPin, OUTPUT); + // initialize SPI: + SPI.begin(); +} + +void loop() { + // go through the six channels of the digital pot: + for (int channel = 0; channel < 6; channel++) { + // change the resistance on this channel from min to max: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, level); + delay(10); + } + // wait a second at the top: + delay(100); + // change the resistance on this channel from max to min: + for (int level = 0; level < 255; level++) { + digitalPotWrite(channel, 255 - level); + delay(10); + } + } + +} + +void digitalPotWrite(int address, int value) { + // take the SS pin low to select the chip: + digitalWrite(slaveSelectPin, LOW); + delay(100); + // send in the address and value via SPI: + SPI.transfer(address); + SPI.transfer(value); + delay(100); + // take the SS pin high to de-select the chip: + digitalWrite(slaveSelectPin, HIGH); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/SSU_HttpOta.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/SSU_HttpOta.ino new file mode 100644 index 00000000..a7eaa671 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/SSU_HttpOta.ino @@ -0,0 +1,227 @@ +/* + Small example sketch demonstrating how to perform OTA via HTTP/S + utilizing a MKRGSM 1400 and the storage on the integrated + SARA U-201 GSM module. + + Please, be careful because no verification is done on the + received OTA file, apart size verification of the transmitted + bytes using the HTTP Content-Length header. + + For production-grade OTA procedure you might want to implement + a content verification procedure using a CRC calculation + or an hash (eg. MD5 or SHA256) comparison. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + Steps to update a sketch: + + 1) Create a new sketch or update an existing one to be updated over-the-air. + The sketch needs to contain also the code below for future OTAs. + The sketch must include the SSU library via + #include + + 2) In the IDE select: Sketch -> Export compiled Binary. + + 3) Open the location of the sketch (Sketch -> Show Sketch Folder) and upload + the .bin file to your HTTP/S server. + + 4) Upload this sketch after configuring the server, port and filename variables. + + The sketch will download the OTA file, store it into the U-201 storage, and + will reset the board to trigger the SSU update procedure. + + + created 25 June 2020 + by Giampaolo Mancini +*/ + +#include + +// This includes triggers the firmware update procedure +// in the bootloader after reset. +#include + +// Do not change! SSU will look for these files! +constexpr char UPDATE_FILE_NAME[] = "UPDATE.BIN"; +static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK"; + +#include "arduino_secrets.h" +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// Change to GSMClient for non-SSL/TLS connection. +// Not recommended. +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; + +GSMFileUtils fileUtils; + +bool isHeaderComplete = false; +String httpHeader; + +bool isDownloadComplete = false; +unsigned int fileSize = 0; +unsigned int totalWritten = 0; + +constexpr char server[] = "example.org"; +constexpr int port = 443; + +// Name of the new firmware file to be updated. +constexpr char filename[] = "update.bin"; + + +void setup() +{ + unsigned long timeout = millis(); + + Serial.begin(9600); + while (!Serial && millis() - timeout < 5000) + ; + + Serial.println("Starting OTA Update via HTTP and Arduino SSU."); + Serial.println(); + + bool connected = false; + + Serial.print("Connecting to cellular network... "); + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected."); + Serial.println(); + + // Modem has already been initialized in the sketch: + // begin FileUtils without MODEM initialization. + fileUtils.begin(false); + + Serial.print("Connecting to "); + Serial.print(server); + Serial.print(":"); + Serial.print(port); + Serial.print("... "); + if (client.connect(server, port)) { + Serial.println("Connected."); + Serial.print("Downloading "); + Serial.println(filename); + Serial.print("... "); + // Make the HTTP request: + client.print("GET /"); + client.print(filename); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + Serial.println("Connection failed"); + } +} + +void loop() +{ + while (client.available()) { + // Skip the HTTP header + if (!isHeaderComplete) { + const char c = client.read(); + httpHeader += c; + if (httpHeader.endsWith("\r\n\r\n")) { + isHeaderComplete = true; + + // Get the size of the OTA file from the + // HTTP Content-Length header. + fileSize = getContentLength(); + + Serial.println(); + Serial.print("HTTP header complete. "); + Serial.print("OTA file size is "); + Serial.print(fileSize); + Serial.println(" bytes."); + if (fileSize == 0) { + Serial.println("Unable to get OTA file size."); + while (true) + ; + } + } + } else { + // Read the OTA file in len-bytes blocks to preserve RAM. + constexpr size_t len { 512 }; + char buf[len] { 0 }; + + // Read len bytes from HTTP client... + uint32_t read = client.readBytes(buf, len); + // and append them to the update file. + uint32_t written = fileUtils.appendFile(UPDATE_FILE_NAME, buf, read); + + if (written != read) { + Serial.println("Error while saving data."); + while (true) + ; + } + + // Update the received byte counter + totalWritten += written; + + // Check for full file received and stored + isDownloadComplete = totalWritten == fileSize; + + Serial.print("Received: "); + Serial.print(totalWritten); + Serial.print("/"); + Serial.println(fileSize); + } + } + if (isDownloadComplete) { + Serial.println(); + Serial.println("Download complete."); + Serial.println("Enabling checkpoint."); + Serial.println(); + + // Create the checkpoint file: will be removed by SSU + // after successful update. + auto status = fileUtils.downloadFile(CHECK_FILE_NAME, { 0 }, 1); + if (status != 1) { + Serial.println("Unable to create checkpoint file."); + while (true) + ; + } + + Serial.println("Resetting MCU in order to trigger SSU..."); + Serial.println(); + delay(500); + NVIC_SystemReset(); + } +} + +int getContentLength() +{ + const String contentLengthHeader = "Content-Length:"; + const auto contentLengthHeaderLen = contentLengthHeader.length(); + + auto indexContentLengthStart = httpHeader.indexOf(contentLengthHeader); + if (indexContentLengthStart < 0) { + Serial.println("Unable to find Content-Length header (Start)"); + return 0; + } + auto indexContentLengthStop = httpHeader.indexOf("\r\n", indexContentLengthStart); + if (indexContentLengthStart < 0) { + Serial.println("Unable to find Content-Length header (Stop)"); + return 0; + } + auto contentLength = httpHeader.substring(indexContentLengthStart + contentLengthHeaderLen + 1, indexContentLengthStop); + + contentLength.trim(); + return contentLength.toInt(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/arduino_secrets.h new file mode 100644 index 00000000..fa36edb9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_HttpOta/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/SSU_LZSS_HttpOta.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/SSU_LZSS_HttpOta.ino new file mode 100644 index 00000000..247bbb48 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/SSU_LZSS_HttpOta.ino @@ -0,0 +1,230 @@ +/* + Small example sketch demonstrating how to perform OTA via HTTP/S + utilizing a MKRGSM 1400 and the storage on the integrated + SARA U-201 GSM module. + + Please, be careful because no verification is done on the + received OTA file, apart size verification of the transmitted + bytes using the HTTP Content-Length header. + + For production-grade OTA procedure you might want to implement + a content verification procedure using a CRC calculation + or an hash (eg. MD5 or SHA256) comparison. + + Circuit: + * MKR GSM 1400 board + * Antenna + * SIM card with a data plan + + Steps to update a sketch: + + 1) Create a new sketch or update an existing one to be updated over-the-air. + The sketch needs to contain also the code below for future OTAs. + The sketch must include the SSU library via + #include + + 2) In the IDE select: Sketch -> Export compiled Binary. + + 3) Open the location of the sketch (Sketch -> Show Sketch Folder) and compress it + with a lzss tool + (eg. https://github.com/arduino-libraries/ArduinoIoTCloud/blob/master/extras/tools/lzss.py). + + 4) Upload the .lzss file to your HTTP/S server. + + 5) Upload this sketch after configuring the server, port and filename variables. + + The sketch will download the OTA file, store it into the U-201 storage, and + will reset the board to trigger the SSU update procedure. + + + created 25 June 2020 + by Giampaolo Mancini +*/ + +#include + +// This includes triggers the firmware update procedure +// in the bootloader after reset. +#include + +// Do not change! SSU will look for these files! +constexpr char UPDATE_FILE_NAME[] = "UPDATE.BIN.LZSS"; +static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK"; + +#include "arduino_secrets.h" +const char PINNUMBER[] = SECRET_PINNUMBER; +// APN data +const char GPRS_APN[] = SECRET_GPRS_APN; +const char GPRS_LOGIN[] = SECRET_GPRS_LOGIN; +const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD; + +// Change to GSMClient for non-SSL/TLS connection. +// Not recommended. +GSMSSLClient client; +GPRS gprs; +GSM gsmAccess; + +GSMFileUtils fileUtils; + +bool isHeaderComplete = false; +String httpHeader; + +bool isDownloadComplete = false; +unsigned int fileSize = 0; +unsigned int totalWritten = 0; + +constexpr char server[] = "example.org"; +constexpr int port = 443; + +// Name of the new firmware file to be updated. +constexpr char filename[] = "update.lzss"; + + +void setup() +{ + unsigned long timeout = millis(); + + Serial.begin(9600); + while (!Serial && millis() - timeout < 5000) + ; + + Serial.println("Starting OTA Update via HTTP and Arduino SSU."); + Serial.println(); + + bool connected = false; + + Serial.print("Connecting to cellular network... "); + while (!connected) { + if ((gsmAccess.begin(PINNUMBER) == GSM_READY) && (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) { + connected = true; + } else { + Serial.println("Not connected"); + delay(1000); + } + } + + Serial.println("Connected."); + Serial.println(); + + // Modem has already been initialized in the sketch: + // begin FileUtils without MODEM initialization. + fileUtils.begin(false); + + Serial.print("Connecting to "); + Serial.print(server); + Serial.print(":"); + Serial.print(port); + Serial.print("... "); + if (client.connect(server, port)) { + Serial.println("Connected."); + Serial.print("Downloading "); + Serial.println(filename); + Serial.print("... "); + // Make the HTTP request: + client.print("GET /"); + client.print(filename); + client.println(" HTTP/1.1"); + client.print("Host: "); + client.println(server); + client.println("Connection: close"); + client.println(); + } else { + Serial.println("Connection failed"); + } +} + +void loop() +{ + while (client.available()) { + // Skip the HTTP header + if (!isHeaderComplete) { + const char c = client.read(); + httpHeader += c; + if (httpHeader.endsWith("\r\n\r\n")) { + isHeaderComplete = true; + + // Get the size of the OTA file from the + // HTTP Content-Length header. + fileSize = getContentLength(); + + Serial.println(); + Serial.print("HTTP header complete. "); + Serial.print("OTA file size is "); + Serial.print(fileSize); + Serial.println(" bytes."); + if (fileSize == 0) { + Serial.println("Unable to get OTA file size."); + while (true) + ; + } + } + } else { + // Read the OTA file in len-bytes blocks to preserve RAM. + constexpr size_t len { 512 }; + char buf[len] { 0 }; + + // Read len bytes from HTTP client... + uint32_t read = client.readBytes(buf, len); + // and append them to the update file. + uint32_t written = fileUtils.appendFile(UPDATE_FILE_NAME, buf, read); + + if (written != read) { + Serial.println("Error while saving data."); + while (true) + ; + } + + // Update the received byte counter + totalWritten += written; + + // Check for full file received and stored + isDownloadComplete = totalWritten == fileSize; + + Serial.print("Received: "); + Serial.print(totalWritten); + Serial.print("/"); + Serial.println(fileSize); + } + } + if (isDownloadComplete) { + Serial.println(); + Serial.println("Download complete."); + Serial.println("Enabling checkpoint."); + Serial.println(); + + // Create the checkpoint file: will be removed by SSU + // after successful update. + auto status = fileUtils.downloadFile(CHECK_FILE_NAME, { 0 }, 1); + if (status != 1) { + Serial.println("Unable to create checkpoint file."); + while (true) + ; + } + + Serial.println("Resetting MCU in order to trigger SSU..."); + Serial.println(); + delay(500); + NVIC_SystemReset(); + } +} + +int getContentLength() +{ + const String contentLengthHeader = "Content-Length:"; + const auto contentLengthHeaderLen = contentLengthHeader.length(); + + auto indexContentLengthStart = httpHeader.indexOf(contentLengthHeader); + if (indexContentLengthStart < 0) { + Serial.println("Unable to find Content-Length header (Start)"); + return 0; + } + auto indexContentLengthStop = httpHeader.indexOf("\r\n", indexContentLengthStart); + if (indexContentLengthStart < 0) { + Serial.println("Unable to find Content-Length header (Stop)"); + return 0; + } + auto contentLength = httpHeader.substring(indexContentLengthStart + contentLengthHeaderLen + 1, indexContentLengthStop); + + contentLength.trim(); + return contentLength.toInt(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/arduino_secrets.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/arduino_secrets.h new file mode 100644 index 00000000..fa36edb9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LZSS_HttpOta/arduino_secrets.h @@ -0,0 +1,4 @@ +#define SECRET_PINNUMBER "" +#define SECRET_GPRS_APN "GPRS_APN" // replace your GPRS APN +#define SECRET_GPRS_LOGIN "login" // replace with your GPRS login +#define SECRET_GPRS_PASSWORD "password" // replace with your GPRS password \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/Binary.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/Binary.h new file mode 100644 index 00000000..e69de29b diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/SSU_LoadBinary.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/SSU_LoadBinary.ino new file mode 100644 index 00000000..8acfff75 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_LoadBinary/SSU_LoadBinary.ino @@ -0,0 +1,57 @@ +/************************************************************************************** + * INCLUDE + **************************************************************************************/ + + +#include + + +/************************************************************************************** + * CONSTANTS + **************************************************************************************/ + +static char const BINARY[] = + +{ + #include "Binary.h" +}; + + +GSMFileUtils fileUtils; + + +/************************************************************************************** + * SETUP/LOOP + **************************************************************************************/ + +void setup() { + Serial.begin(9600); + + unsigned long const start = millis(); + for(unsigned long now = millis(); !Serial && ((now - start) < 5000); now = millis()) { }; + + Serial.print("Accessing SARA U-201 Filesystem... "); + if(!fileUtils.begin()) { + Serial.println("failed."); + return; + + } + Serial.println("OK"); + Serial.print("Writing \"UPDATE.BIN\" ... "); + + uint32_t bytes_to_write = sizeof(BINARY); + auto bytes_written = fileUtils.downloadFile("UPDATE.BIN", BINARY, bytes_to_write); + + if(bytes_written != bytes_to_write) { + Serial.println("downloadFile failed.");return; + + } else { + Serial.print("OK ("); + Serial.print(bytes_written); + Serial.println(" bytes written)"); + } +} + +void loop() { + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_Usage/SSU_Usage.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_Usage/SSU_Usage.ino new file mode 100644 index 00000000..0183553f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/SSU/examples/SSU_Usage/SSU_Usage.ino @@ -0,0 +1,49 @@ +/* + Usage + This example demonstrates how to use the SAMD SSU library to update a + sketch on any Arduino MKR board via the storage on the SARA U-201 GSM module. + This sketch prints out the date and time the sketch was compiled. + Steps to update sketch: + 1) Upload this sketch or another sketch that includes the SSU library + via #include + 2) Update the sketch as desired. For this example the sketch prints out + the compiled date and time so no updates are needed. + 3) In the IDE select: Sketch -> Export compiled Binary + 4) Open the location of the sketch and convert the .bin file to a C byte array. + cat SKETCH.bin | xxd --include > Binary.h + 5) Copy Binary.h file from the sketch's folder to the SSU_LoadBinary sketch + and load it to the U-201 via SSU_LoadBinary sketch. +*/ + +/* + Include the SSU library + + This will add some code to the sketch before setup() is called + to check if UPDATE.BIN and UPDATE.OK are present on the storage of + the U-201 module. If this theck is positive UPDATE.BIN is used to update + the sketch running on the board. + After this UPDATE.BIN and UPDATE.OK are deleted from the flash. +*/ + + +#include + +void setup() +{ + Serial.begin(9600); + while (!Serial) { } + // wait a bit + delay(1000); + String message; + message += "Sketch compile date and time: "; + message += __DATE__; + message += " "; + message += __TIME__; + // print out the sketch compile date and time on the serial port + Serial.println(message); +} + +void loop() +{ + // add you own code here +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino new file mode 100644 index 00000000..ea7509cb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/ADKTerminalTest/ADKTerminalTest.ino @@ -0,0 +1,75 @@ +/* + Copyright (c) 2012 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#define ARDUINO_MAIN +//#include "variant.h" +#include "Arduino.h" +#include +#include + + +USBHost usb; +ADK adk(&usb,"Arduino SA", + "Arduino_Terminal", + "Arduino Terminal for Android", + "1.0", + "http://labs.arduino.cc/uploads/ADK/ArduinoTerminal/ThibaultTerminal_ICS_0001.apk", + "1"); + +void setup(void) +{ + SERIAL_PORT_MONITOR.begin( 115200 ); + while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("\r\nADK demo start"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay(20); +} + +#define RCVSIZE 128 + +void loop(void) +{ + uint8_t buf[RCVSIZE]; + uint32_t nbread = 0; + char helloworld[] = "Hello World!\r\n"; + + usb.Task(); + + if( adk.isReady() == false ) { + return; + } + /* Write hello string to ADK */ + adk.SndData(strlen(helloworld), (uint8_t *)helloworld); + + delay(1000); + + /* Read data from ADK and print to UART */ + adk.RcvData((uint8_t *)&nbread, buf); + if (nbread > 0) + { + SERIAL_PORT_MONITOR.print("RCV: "); + for (uint32_t i = 0; i < nbread; ++i) + { + SERIAL_PORT_MONITOR.print((char)buf[i]); + } + SERIAL_PORT_MONITOR.print("\r\n"); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/KeyboardController/KeyboardController.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/KeyboardController/KeyboardController.ino new file mode 100644 index 00000000..f1b6463a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/KeyboardController/KeyboardController.ino @@ -0,0 +1,89 @@ +/* + Keyboard Controller Example + + Shows the output of a USB Keyboard connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + https://www.arduino.cc/en/Tutorial/KeyboardController + + This sample code is part of the public domain. + */ + +// Require keyboard control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach keyboard controller to USB +KeyboardController keyboard(usb); + +void printKey(); + +// This function intercepts key press +void keyPressed() { + SERIAL_PORT_MONITOR.print("Pressed: "); + printKey(); +} + +// This function intercepts key release +void keyReleased() { + SERIAL_PORT_MONITOR.print("Released: "); + printKey(); +} + +void printKey() { + // getOemKey() returns the OEM-code associated with the key + SERIAL_PORT_MONITOR.print(" key:"); + SERIAL_PORT_MONITOR.print(keyboard.getOemKey()); + + // getModifiers() returns a bits field with the modifiers-keys + int mod = keyboard.getModifiers(); + SERIAL_PORT_MONITOR.print(" mod:"); + SERIAL_PORT_MONITOR.print(mod); + + SERIAL_PORT_MONITOR.print(" => "); + + if (mod & LeftCtrl) + SERIAL_PORT_MONITOR.print("L-Ctrl "); + if (mod & LeftShift) + SERIAL_PORT_MONITOR.print("L-Shift "); + if (mod & Alt) + SERIAL_PORT_MONITOR.print("Alt "); + if (mod & LeftCmd) + SERIAL_PORT_MONITOR.print("L-Cmd "); + if (mod & RightCtrl) + SERIAL_PORT_MONITOR.print("R-Ctrl "); + if (mod & RightShift) + SERIAL_PORT_MONITOR.print("R-Shift "); + if (mod & AltGr) + SERIAL_PORT_MONITOR.print("AltGr "); + if (mod & RightCmd) + SERIAL_PORT_MONITOR.print("R-Cmd "); + + // getKey() returns the ASCII translation of OEM key + // combined with modifiers. + SERIAL_PORT_MONITOR.write(keyboard.getKey()); + SERIAL_PORT_MONITOR.println(); +} + +void setup() +{ + SERIAL_PORT_MONITOR.begin( 115200 ); + while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Keyboard Controller Program started"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay( 20 ); +} + +void loop() +{ + // Process USB tasks + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/MouseController/MouseController.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/MouseController/MouseController.ino new file mode 100644 index 00000000..fd02d3e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/MouseController/MouseController.ino @@ -0,0 +1,97 @@ +/* + Mouse Controller Example + + Shows the output of a USB Mouse connected to + the Native USB port on an Arduino Due Board. + + created 8 Oct 2012 + by Cristian Maglie + + https://www.arduino.cc/en/Tutorial/MouseController + + This sample code is part of the public domain. + */ + +// Require mouse control library +#include + +// Initialize USB Controller +USBHost usb; + +// Attach mouse controller to USB +MouseController mouse(usb); + +// variables for mouse button states +bool leftButton = false; +bool middleButton = false; +bool rightButton = false; + +// This function intercepts mouse movements +void mouseMoved() { + SERIAL_PORT_MONITOR.print("Move: "); + SERIAL_PORT_MONITOR.print(mouse.getXChange()); + SERIAL_PORT_MONITOR.print(", "); + SERIAL_PORT_MONITOR.println(mouse.getYChange()); +} + +// This function intercepts mouse movements while a button is pressed +void mouseDragged() { + SERIAL_PORT_MONITOR.print("DRAG: "); + SERIAL_PORT_MONITOR.print(mouse.getXChange()); + SERIAL_PORT_MONITOR.print(", "); + SERIAL_PORT_MONITOR.println(mouse.getYChange()); +} + +// This function intercepts mouse button press +void mousePressed() { + SERIAL_PORT_MONITOR.print("Pressed: "); + if (mouse.getButton(LEFT_BUTTON)) { + SERIAL_PORT_MONITOR.print("L"); + leftButton = true; + } + if (mouse.getButton(MIDDLE_BUTTON)) { + SERIAL_PORT_MONITOR.print("M"); + middleButton = true; + } + if (mouse.getButton(RIGHT_BUTTON)) { + SERIAL_PORT_MONITOR.print("R"); + rightButton = true; + } + SERIAL_PORT_MONITOR.println(); +} + +// This function intercepts mouse button release +void mouseReleased() { + SERIAL_PORT_MONITOR.print("Released: "); + if (!mouse.getButton(LEFT_BUTTON) && leftButton == true) { + SERIAL_PORT_MONITOR.print("L"); + leftButton = false; + } + if (!mouse.getButton(MIDDLE_BUTTON) && middleButton == true) { + SERIAL_PORT_MONITOR.print("M"); + middleButton = false; + } + if (!mouse.getButton(RIGHT_BUTTON) && rightButton == true) { + SERIAL_PORT_MONITOR.print("R"); + rightButton = false; + } + SERIAL_PORT_MONITOR.println(); +} + +void setup() +{ + SERIAL_PORT_MONITOR.begin( 115200 ); + while (!SERIAL_PORT_MONITOR); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Mouse Controller Program started"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay( 20 ); +} + +void loop() +{ + // Process USB tasks + usb.Task(); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino new file mode 100644 index 00000000..de9ab09f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/USB_desc.ino @@ -0,0 +1,389 @@ + + +#include "Arduino.h" +#include +#include "pgmstrings.h" +// Satisfy IDE, which only needs to see the include statment in the ino. +#ifdef dobogusinclude +#include +#endif + +USBHost usb; +//USBHub Hub1(&Usb); +//USBHub Hub2(&Usb); +//USBHub Hub3(&Usb); +//USBHub Hub4(&Usb); +//USBHub Hub5(&Usb); +//USBHub Hub6(&Usb); +//USBHub Hub7(&Usb); + +uint32_t next_time; + +void print_hex(int v, int num_places); +void printintfdescr( uint8_t* descr_ptr ); +byte getconfdescr( byte addr, byte conf ); +void printconfdescr( uint8_t* descr_ptr ); +void printunkdescr( uint8_t* descr_ptr ); +void printepdescr( uint8_t* descr_ptr ); +void printProgStr(const prog_char str[]); +void printHIDdescr( uint8_t* descr_ptr ); + +void PrintAllAddresses(UsbDeviceDefinition *pdev) +{ + UsbDeviceAddress adr; + adr.devAddress = pdev->address.devAddress; + SERIAL_PORT_MONITOR.print("\r\nAddr:"); + SERIAL_PORT_MONITOR.print(adr.devAddress, HEX); + SERIAL_PORT_MONITOR.print("("); + SERIAL_PORT_MONITOR.print(adr.bmHub, HEX); + SERIAL_PORT_MONITOR.print("."); + SERIAL_PORT_MONITOR.print(adr.bmParent, HEX); + SERIAL_PORT_MONITOR.print("."); + SERIAL_PORT_MONITOR.print(adr.bmAddress, HEX); + SERIAL_PORT_MONITOR.println(")"); +} + +void PrintAddress(uint8_t addr) +{ + UsbDeviceAddress adr; + adr.devAddress = addr; + SERIAL_PORT_MONITOR.print("\r\nADDR:\t"); + SERIAL_PORT_MONITOR.println(adr.devAddress,HEX); + SERIAL_PORT_MONITOR.print("DEV:\t"); + SERIAL_PORT_MONITOR.println(adr.bmAddress,HEX); + SERIAL_PORT_MONITOR.print("PRNT:\t"); + SERIAL_PORT_MONITOR.println(adr.bmParent,HEX); + SERIAL_PORT_MONITOR.print("HUB:\t"); + SERIAL_PORT_MONITOR.println(adr.bmHub,HEX); +} + +void setup() +{ + SERIAL_PORT_MONITOR.begin( 115200 ); + while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection + SERIAL_PORT_MONITOR.println("Start USB Desc"); + + if (usb.Init() == -1) + SERIAL_PORT_MONITOR.println("OSC did not start."); + + delay( 20 ); + + next_time = millis() + 10000; +} + +byte getdevdescr( byte addr, byte &num_conf ); + +void PrintDescriptors(uint8_t addr) +{ + uint8_t rcode = 0; + byte num_conf = 0; + + rcode = getdevdescr( (byte)addr, num_conf ); + if( rcode ) + { + printProgStr(Gen_Error_str); + print_hex( rcode, 8 ); + } + SERIAL_PORT_MONITOR.print("\r\n"); + + for (int i=0; iaddress.devAddress, 8); + SERIAL_PORT_MONITOR.println("\r\n--"); + PrintDescriptors( pdev->address.devAddress ); +} + +void loop() +{ + usb.Task(); + + if( usb.getUsbTaskState() == USB_STATE_RUNNING ) + { + //if (millis() >= next_time) + { + usb.ForEachUsbDevice(&PrintAllDescriptors); + usb.ForEachUsbDevice(&PrintAllAddresses); + + while( 1 ); //stop + } + } +} + +byte getdevdescr( byte addr, byte &num_conf ) +{ + USB_DEVICE_DESCRIPTOR buf; + byte rcode; + rcode = usb.getDevDescr( addr, 0, 0x12, ( uint8_t *)&buf ); + if( rcode ) { + return( rcode ); + } + printProgStr(Dev_Header_str); + printProgStr(Dev_Length_str); + print_hex( buf.bLength, 8 ); + printProgStr(Dev_Type_str); + print_hex( buf.bDescriptorType, 8 ); + printProgStr(Dev_Version_str); + print_hex( buf.bcdUSB, 16 ); + printProgStr(Dev_Class_str); + print_hex( buf.bDeviceClass, 8 ); + printProgStr(Dev_Subclass_str); + print_hex( buf.bDeviceSubClass, 8 ); + printProgStr(Dev_Protocol_str); + print_hex( buf.bDeviceProtocol, 8 ); + printProgStr(Dev_Pktsize_str); + print_hex( buf.bMaxPacketSize0, 8 ); + printProgStr(Dev_Vendor_str); + print_hex( buf.idVendor, 16 ); + printProgStr(Dev_Product_str); + print_hex( buf.idProduct, 16 ); + printProgStr(Dev_Revision_str); + print_hex( buf.bcdDevice, 16 ); + printProgStr(Dev_Mfg_str); + print_hex( buf.iManufacturer, 8 ); + printProgStr(Dev_Prod_str); + print_hex( buf.iProduct, 8 ); + printProgStr(Dev_Serial_str); + print_hex( buf.iSerialNumber, 8 ); + printProgStr(Dev_Nconf_str); + print_hex( buf.bNumConfigurations, 8 ); + num_conf = buf.bNumConfigurations; + return( 0 ); +} + +void printhubdescr(uint8_t *descrptr, uint8_t addr) +{ + HubDescriptor *pHub = (HubDescriptor*) descrptr; + uint8_t len = *((uint8_t*)descrptr); + + printProgStr(PSTR("\r\n\r\nHub Descriptor:\r\n")); + printProgStr(PSTR("bDescLength:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bDescLength, HEX); + + printProgStr(PSTR("bDescriptorType:\t")); + SERIAL_PORT_MONITOR.println(pHub->bDescriptorType, HEX); + + printProgStr(PSTR("bNbrPorts:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bNbrPorts, HEX); + + printProgStr(PSTR("LogPwrSwitchMode:\t")); + SERIAL_PORT_MONITOR.println(pHub->LogPwrSwitchMode, BIN); + + printProgStr(PSTR("CompoundDevice:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->CompoundDevice, BIN); + + printProgStr(PSTR("OverCurrentProtectMode:\t")); + SERIAL_PORT_MONITOR.println(pHub->OverCurrentProtectMode, BIN); + + printProgStr(PSTR("TTThinkTime:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->TTThinkTime, BIN); + + printProgStr(PSTR("PortIndicatorsSupported:")); + SERIAL_PORT_MONITOR.println(pHub->PortIndicatorsSupported, BIN); + + printProgStr(PSTR("Reserved:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->Reserved, HEX); + + printProgStr(PSTR("bPwrOn2PwrGood:\t\t")); + SERIAL_PORT_MONITOR.println(pHub->bPwrOn2PwrGood, HEX); + + printProgStr(PSTR("bHubContrCurrent:\t")); + SERIAL_PORT_MONITOR.println(pHub->bHubContrCurrent, HEX); + + for (uint8_t i=7; ibNbrPorts; i++) + // PrintHubPortStatus(&Usb, addr, i, 1); +} + +byte getconfdescr( byte addr, byte conf ) +{ + uint8_t buf[ BUFSIZE ]; + uint8_t* buf_ptr = buf; + byte rcode; + byte descr_length; + byte descr_type; + uint16_t total_length; + rcode = usb.getConfDescr( addr, 0, 4, conf, buf ); //get total length + LOBYTE( total_length ) = buf[ 2 ]; + HIBYTE( total_length ) = buf[ 3 ]; + if( total_length > sizeof(buf)) { //check if total length is larger than buffer + printProgStr(Conf_Trunc_str); + total_length = sizeof(buf); + } + rcode = usb.getConfDescr( addr, 0, total_length, conf, buf ); //get the whole descriptor + while( buf_ptr < buf + total_length ) { //parsing descriptors + descr_length = *( buf_ptr ); + descr_type = *( buf_ptr + 1 ); + switch( descr_type ) { + case( USB_DESCRIPTOR_CONFIGURATION ): + printconfdescr( buf_ptr ); + break; + case( USB_DESCRIPTOR_INTERFACE ): + printintfdescr( buf_ptr ); + break; + case( USB_DESCRIPTOR_ENDPOINT ): + printepdescr( buf_ptr ); + break; + case 0x21: // HID Descriptor + printHIDdescr( buf_ptr ); + break; + case 0x29: + printhubdescr( buf_ptr, addr ); + break; + default: + printunkdescr( buf_ptr ); + break; + }//switch( descr_type + buf_ptr = ( buf_ptr + descr_length ); //advance buffer pointer + }//while( buf_ptr <=... + return( 0 ); +} +/* prints hex numbers with leading zeroes */ +// copyright, Peter H Anderson, Baltimore, MD, Nov, '07 +// source: http://www.phanderson.com/arduino/arduino_display.html +void print_hex(int v, int num_places) +{ + int mask=0, n, num_nibbles, digit; + + for (n=1; n<=num_places; n++) { + mask = (mask << 1) | 0x0001; + } + v = v & mask; // truncate v to specified number of places + + num_nibbles = num_places / 4; + if ((num_places % 4) != 0) { + ++num_nibbles; + } + do { + digit = ((v >> (num_nibbles-1) * 4)) & 0x0f; + SERIAL_PORT_MONITOR.print(digit, HEX); + } + while(--num_nibbles); +} +/* function to print configuration descriptor */ +void printconfdescr( uint8_t* descr_ptr ) +{ + USB_CONFIGURATION_DESCRIPTOR* conf_ptr = ( USB_CONFIGURATION_DESCRIPTOR* )descr_ptr; + printProgStr(Conf_Header_str); + printProgStr(Conf_Totlen_str); + print_hex( conf_ptr->wTotalLength, 16 ); + printProgStr(Conf_Nint_str); + print_hex( conf_ptr->bNumInterfaces, 8 ); + printProgStr(Conf_Value_str); + print_hex( conf_ptr->bConfigurationValue, 8 ); + printProgStr(Conf_String_str); + print_hex( conf_ptr->iConfiguration, 8 ); + printProgStr(Conf_Attr_str); + print_hex( conf_ptr->bmAttributes, 8 ); + printProgStr(Conf_Pwr_str); + print_hex( conf_ptr->bMaxPower, 8 ); + return; +} +/* function to print interface descriptor */ +void printintfdescr( uint8_t* descr_ptr ) +{ + USB_INTERFACE_DESCRIPTOR* intf_ptr = ( USB_INTERFACE_DESCRIPTOR* )descr_ptr; + printProgStr(Int_Header_str); + printProgStr(Int_Number_str); + print_hex( intf_ptr->bInterfaceNumber, 8 ); + printProgStr(Int_Alt_str); + print_hex( intf_ptr->bAlternateSetting, 8 ); + printProgStr(Int_Endpoints_str); + print_hex( intf_ptr->bNumEndpoints, 8 ); + printProgStr(Int_Class_str); + print_hex( intf_ptr->bInterfaceClass, 8 ); + printProgStr(Int_Subclass_str); + print_hex( intf_ptr->bInterfaceSubClass, 8 ); + printProgStr(Int_Protocol_str); + print_hex( intf_ptr->bInterfaceProtocol, 8 ); + printProgStr(Int_String_str); + print_hex( intf_ptr->iInterface, 8 ); + return; +} + +/* function to print HID descriptor */ +void printHIDdescr( uint8_t* descr_ptr ) +{ + USB_HID_DESCRIPTOR* ep_ptr = ( USB_HID_DESCRIPTOR* )descr_ptr; + + printProgStr(PSTR("\r\n\r\nHID Descriptor:\r\n")); + printProgStr(PSTR("HID Class Release:\t")); + print_hex( ep_ptr->bcdHID, 16 ); + printProgStr(PSTR("\r\nCountry Code:\t\t")); + print_hex( ep_ptr->bCountryCode, 8 ); + printProgStr(PSTR("\r\nNumb Class Descriptor:\t")); + print_hex( ep_ptr->bNumDescriptors, 8 ); + printProgStr(PSTR("\r\nDescriptor Type:\t")); + if( ep_ptr->bDescrType == 0x22 ) + printProgStr(PSTR("REPORT DESCRIPTOR")); + else + print_hex( ep_ptr->bDescrType, 8 ); + printProgStr(PSTR("\r\nCSize Report Descr:\t")); + print_hex( ep_ptr->wDescriptorLength, 16 ); +} + +/* function to print endpoint descriptor */ +void printepdescr( uint8_t* descr_ptr ) +{ + uint8_t transfer_type; + + USB_ENDPOINT_DESCRIPTOR* ep_ptr = ( USB_ENDPOINT_DESCRIPTOR* )descr_ptr; + printProgStr(End_Header_str); + printProgStr(End_Address_str); + if( 0x80 & ep_ptr->bEndpointAddress ) printProgStr(PSTR("IN\t\t")); + else printProgStr(PSTR("OUT\t\t")); + print_hex( (ep_ptr->bEndpointAddress & 0xF), 8 ); + printProgStr(End_Attr_str); + transfer_type = ep_ptr->bmAttributes & bmUSB_TRANSFER_TYPE; + if( transfer_type == USB_TRANSFER_TYPE_INTERRUPT ) printProgStr(PSTR("INTERRUPT\t")); + else if( transfer_type == USB_TRANSFER_TYPE_BULK ) printProgStr(PSTR("BULK\t")); + else if( transfer_type == USB_TRANSFER_TYPE_ISOCHRONOUS ) printProgStr(PSTR("ISO\t")); + print_hex( ep_ptr->bmAttributes, 8 ); + printProgStr(End_Pktsize_str); + print_hex( ep_ptr->wMaxPacketSize, 16 ); + printProgStr(End_Interval_str); + print_hex( ep_ptr->bInterval, 8 ); + + return; +} +/*function to print unknown descriptor */ +void printunkdescr( uint8_t* descr_ptr ) +{ + byte length = *descr_ptr; + byte i; + printProgStr(Unk_Header_str); + printProgStr(Unk_Length_str); + print_hex( *descr_ptr, 8 ); + printProgStr(Unk_Type_str); + print_hex( *(descr_ptr + 1 ), 8 ); + printProgStr(Unk_Contents_str); + descr_ptr += 2; + for( i = 0; i < length; i++ ) { + print_hex( *descr_ptr, 8 ); + descr_ptr++; + } +} + + +/* Print a string from Program Memory directly to save RAM */ +void printProgStr(const prog_char str[]) +{ + char c; + if(!str) return; + while((c = pgm_read_byte(str++))) + SERIAL_PORT_MONITOR.print(c); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/pgmstrings.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/pgmstrings.h new file mode 100644 index 00000000..bdb0077e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/USBHost/examples/USB_desc/pgmstrings.h @@ -0,0 +1,52 @@ +#if !defined(__PGMSTRINGS_H__) +#define __PGMSTRINGS_H__ + +#define LOBYTE(x) ((char*)(&(x)))[0] +#define HIBYTE(x) ((char*)(&(x)))[1] +#define BUFSIZE 256 //buffer size + + +/* Print strings in Program Memory */ +const char Gen_Error_str[] PROGMEM = "\r\nRequest error. Error code:\t"; +const char Dev_Header_str[] PROGMEM ="\r\nDevice descriptor: "; +const char Dev_Length_str[] PROGMEM ="\r\nDescriptor Length:\t"; +const char Dev_Type_str[] PROGMEM ="\r\nDescriptor type:\t"; +const char Dev_Version_str[] PROGMEM ="\r\nUSB version:\t\t"; +const char Dev_Class_str[] PROGMEM ="\r\nDevice class:\t\t"; +const char Dev_Subclass_str[] PROGMEM ="\r\nDevice Subclass:\t"; +const char Dev_Protocol_str[] PROGMEM ="\r\nDevice Protocol:\t"; +const char Dev_Pktsize_str[] PROGMEM ="\r\nMax.packet size:\t"; +const char Dev_Vendor_str[] PROGMEM ="\r\nVendor ID:\t\t"; +const char Dev_Product_str[] PROGMEM ="\r\nProduct ID:\t\t"; +const char Dev_Revision_str[] PROGMEM ="\r\nRevision ID:\t\t"; +const char Dev_Mfg_str[] PROGMEM ="\r\nMfg.string index:\t"; +const char Dev_Prod_str[] PROGMEM ="\r\nProd.string index:\t"; +const char Dev_Serial_str[] PROGMEM ="\r\nSerial number index:\t"; +const char Dev_Nconf_str[] PROGMEM ="\r\nNumber of conf.:\t"; +const char Conf_Trunc_str[] PROGMEM ="Total length truncated to 256 bytes"; +const char Conf_Header_str[] PROGMEM ="\r\nConfiguration descriptor:"; +const char Conf_Totlen_str[] PROGMEM ="\r\nTotal length:\t\t"; +const char Conf_Nint_str[] PROGMEM ="\r\nNum.intf:\t\t"; +const char Conf_Value_str[] PROGMEM ="\r\nConf.value:\t\t"; +const char Conf_String_str[] PROGMEM ="\r\nConf.string:\t\t"; +const char Conf_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; +const char Conf_Pwr_str[] PROGMEM ="\r\nMax.pwr:\t\t"; +const char Int_Header_str[] PROGMEM ="\r\n\r\nInterface descriptor:"; +const char Int_Number_str[] PROGMEM ="\r\nIntf.number:\t\t"; +const char Int_Alt_str[] PROGMEM ="\r\nAlt.:\t\t\t"; +const char Int_Endpoints_str[] PROGMEM ="\r\nEndpoints:\t\t"; +const char Int_Class_str[] PROGMEM ="\r\nIntf. Class:\t\t"; +const char Int_Subclass_str[] PROGMEM ="\r\nIntf. Subclass:\t\t"; +const char Int_Protocol_str[] PROGMEM ="\r\nIntf. Protocol:\t\t"; +const char Int_String_str[] PROGMEM ="\r\nIntf.string:\t\t"; +const char End_Header_str[] PROGMEM ="\r\n\r\nEndpoint descriptor:"; +const char End_Address_str[] PROGMEM ="\r\nEndpoint address:\t"; +const char End_Attr_str[] PROGMEM ="\r\nAttr.:\t\t\t"; +const char End_Pktsize_str[] PROGMEM ="\r\nMax.pkt size:\t\t"; +const char End_Interval_str[] PROGMEM ="\r\nPolling interval:\t"; +const char Unk_Header_str[] PROGMEM = "\r\nUnknown descriptor:"; +const char Unk_Length_str[] PROGMEM ="\r\nLength:\t\t"; +const char Unk_Type_str[] PROGMEM ="\r\nType:\t\t"; +const char Unk_Contents_str[] PROGMEM ="\r\nContents:\t"; + +#endif // __PGMSTRINGS_H__ \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino new file mode 100644 index 00000000..9c41c18f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/SFRRanger_reader/SFRRanger_reader.ino @@ -0,0 +1,87 @@ +// I2C SRF10 or SRF08 Devantech Ultrasonic Ranger Finder +// by Nicholas Zambetti +// and James Tichenor + +// Demonstrates use of the Wire library reading data from the +// Devantech Utrasonic Rangers SFR08 and SFR10 + +// Created 29 April 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial communication at 9600bps +} + +int reading = 0; + +void loop() +{ + // step 1: instruct sensor to read echoes + Wire.beginTransmission(112); // transmit to device #112 (0x70) + // the address specified in the datasheet is 224 (0xE0) + // but i2c adressing uses the high 7 bits so it's 112 + Wire.write(byte(0x00)); // sets register pointer to the command register (0x00) + Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50) + // use 0x51 for centimeters + // use 0x52 for ping microseconds + Wire.endTransmission(); // stop transmitting + + // step 2: wait for readings to happen + delay(70); // datasheet suggests at least 65 milliseconds + + // step 3: instruct sensor to return a particular echo reading + Wire.beginTransmission(112); // transmit to device #112 + Wire.write(byte(0x02)); // sets register pointer to echo #1 register (0x02) + Wire.endTransmission(); // stop transmitting + + // step 4: request reading from sensor + Wire.requestFrom(112, 2); // request 2 bytes from slave device #112 + + // step 5: receive reading from sensor + if(2 <= Wire.available()) // if two bytes were received + { + reading = Wire.read(); // receive high byte (overwrites previous reading) + reading = reading << 8; // shift high byte to be high 8 bits + reading |= Wire.read(); // receive low byte as lower 8 bits + Serial.println(reading); // print the reading + } + + delay(250); // wait a bit since people have to read the output :) +} + + +/* + +// The following code changes the address of a Devantech Ultrasonic Range Finder (SRF10 or SRF08) +// usage: changeAddress(0x70, 0xE6); + +void changeAddress(byte oldAddress, byte newAddress) +{ + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA0)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xAA)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(byte(0xA5)); + Wire.endTransmission(); + + Wire.beginTransmission(oldAddress); + Wire.write(byte(0x00)); + Wire.write(newAddress); + Wire.endTransmission(); +} + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino new file mode 100644 index 00000000..38da1c54 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino @@ -0,0 +1,39 @@ +// I2C Digital Potentiometer +// by Nicholas Zambetti +// and Shawn Bonkowski + +// Demonstrates use of the Wire library +// Controls AD5171 digital potentiometer via I2C/TWI + +// Created 31 March 2006 + +// This example code is in the public domain. + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) +} + +byte val = 0; + +void loop() +{ + Wire.beginTransmission(44); // transmit to device #44 (0x2c) + // device address is specified in datasheet + Wire.write(byte(0x00)); // sends instruction byte + Wire.write(val); // sends potentiometer value byte + Wire.endTransmission(); // stop transmitting + + val++; // increment value + if(val == 64) // if reached 64th position (max) + { + val = 0; // start over from lowest value + } + delay(500); +} + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_reader/master_reader.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_reader/master_reader.ino new file mode 100644 index 00000000..4124d7d6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_reader/master_reader.ino @@ -0,0 +1,32 @@ +// Wire Master Reader +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Reads data from an I2C/TWI slave device +// Refer to the "Wire Slave Sender" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) + Serial.begin(9600); // start serial for output +} + +void loop() +{ + Wire.requestFrom(2, 6); // request 6 bytes from slave device #2 + + while(Wire.available()) // slave may send less than requested + { + char c = Wire.read(); // receive a byte as character + Serial.print(c); // print the character + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_writer/master_writer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_writer/master_writer.ino new file mode 100644 index 00000000..ccaa0361 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/master_writer/master_writer.ino @@ -0,0 +1,31 @@ +// Wire Master Writer +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Writes data to an I2C/TWI slave device +// Refer to the "Wire Slave Receiver" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(); // join i2c bus (address optional for master) +} + +byte x = 0; + +void loop() +{ + Wire.beginTransmission(4); // transmit to device #4 + Wire.write("x is "); // sends five bytes + Wire.write(x); // sends one byte + Wire.endTransmission(); // stop transmitting + + x++; + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_receiver/slave_receiver.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_receiver/slave_receiver.ino new file mode 100644 index 00000000..60dd4bdd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_receiver/slave_receiver.ino @@ -0,0 +1,38 @@ +// Wire Slave Receiver +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Receives data as an I2C/TWI slave device +// Refer to the "Wire Master Writer" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(4); // join i2c bus with address #4 + Wire.onReceive(receiveEvent); // register event + Serial.begin(9600); // start serial for output +} + +void loop() +{ + delay(100); +} + +// function that executes whenever data is received from master +// this function is registered as an event, see setup() +void receiveEvent(int howMany) +{ + while(1 < Wire.available()) // loop through all but the last + { + char c = Wire.read(); // receive byte as a character + Serial.print(c); // print the character + } + int x = Wire.read(); // receive byte as an integer + Serial.println(x); // print the integer +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_sender/slave_sender.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_sender/slave_sender.ino new file mode 100644 index 00000000..d3b238af --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoCore-samd/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -0,0 +1,32 @@ +// Wire Slave Sender +// by Nicholas Zambetti + +// Demonstrates use of the Wire library +// Sends data as an I2C/TWI slave device +// Refer to the "Wire Master Reader" example for use with this + +// Created 29 March 2006 + +// This example code is in the public domain. + + +#include + +void setup() +{ + Wire.begin(2); // join i2c bus with address #2 + Wire.onRequest(requestEvent); // register event +} + +void loop() +{ + delay(100); +} + +// function that executes whenever data is requested by master +// this function is registered as an event, see setup() +void requestEvent() +{ + Wire.write("hello "); // respond with message of 6 bytes + // as expected by master +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/README.md new file mode 100644 index 00000000..32a6a5ef --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/README.md @@ -0,0 +1,4 @@ +# FruitToEmoji + +Classifies fruit using the RGB color and proximity sensors of the Arduino Nano 33 BLE Sense, using a TensorFlow Lite Micro model trained on data captured from the same hardware + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_capture/object_color_capture.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_capture/object_color_capture.ino new file mode 100644 index 00000000..4788a481 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_capture/object_color_capture.ino @@ -0,0 +1,55 @@ +/* + Object color sampler + -------------------- + Samples the color of objects and outputs CSV logfile to serial console + + Hardware: Arduino Nano 33 BLE Sense board. + + Usage: Place object of interest to the color sensor + + This example code is in the public domain. +*/ + +#include + +void setup() { + + Serial.begin(9600); + while (!Serial) {}; + + if (!APDS.begin()) { + Serial.println("Error initializing APDS9960 sensor."); + } + + // print the header + Serial.println("Red,Green,Blue"); +} + +void loop() { + int r, g, b, c, p; + float sum; + + // wait for proximity and color sensor data + while (!APDS.colorAvailable() || !APDS.proximityAvailable()) {} + + // read the color and proximity data + APDS.readColor(r, g, b, c); + sum = r + g + b; + p = APDS.readProximity(); + + // if object is close and well enough illumated + if (p == 0 && c > 10 && sum > 0) { + + float redRatio = r / sum; + float greenRatio = g / sum; + float blueRatio = b / sum; + + // print the data in CSV format + Serial.print(redRatio, 3); + Serial.print(','); + Serial.print(greenRatio, 3); + Serial.print(','); + Serial.print(blueRatio, 3); + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_classify/object_color_classify.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_classify/object_color_classify.ino new file mode 100644 index 00000000..d6a4efbe --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/FruitToEmoji/sketches/object_color_classify/object_color_classify.ino @@ -0,0 +1,134 @@ +/* + Object classifier by color + -------------------------- + + Uses RGB color sensor input to Neural Network to classify objects + Outputs object class to serial using unicode emojis + + Note: The direct use of C/C++ pointers, namespaces, and dynamic memory is generally + discouraged in Arduino examples, and in the future the TensorFlowLite library + might change to make the sketch simpler. + + Hardware: Arduino Nano 33 BLE Sense board. + + Created by Don Coleman, Sandeep Mistry + Adapted by Dominic Pajak + + This example code is in the public domain. +*/ + +// Arduino_TensorFlowLite - Version: 0.alpha.precompiled +#include + +#include +#include +#include +#include +#include +#include +#include "model.h" + +// global variables used for TensorFlow Lite (Micro) +tflite::MicroErrorReporter tflErrorReporter; + +// pull in all the TFLM ops, you can remove this line and +// only pull in the TFLM ops you need, if would like to reduce +// the compiled size of the sketch. +tflite::AllOpsResolver tflOpsResolver; + +const tflite::Model* tflModel = nullptr; +tflite::MicroInterpreter* tflInterpreter = nullptr; +TfLiteTensor* tflInputTensor = nullptr; +TfLiteTensor* tflOutputTensor = nullptr; + +// Create a static memory buffer for TFLM, the size may need to +// be adjusted based on the model you are using +constexpr int tensorArenaSize = 8 * 1024; +byte tensorArena[tensorArenaSize]; + +// array to map gesture index to a name +const char* CLASSES[] = { + "Apple", // u8"\U0001F34E", // Apple + "Banana", // u8"\U0001F34C", // Banana + "Orange" // u8"\U0001F34A" // Orange +}; + +#define NUM_CLASSES (sizeof(CLASSES) / sizeof(CLASSES[0])) + +void setup() { + Serial.begin(9600); + while (!Serial) {}; + + Serial.println("Object classification using RGB color sensor"); + Serial.println("--------------------------------------------"); + Serial.println("Arduino Nano 33 BLE Sense running TensorFlow Lite Micro"); + Serial.println(""); + + if (!APDS.begin()) { + Serial.println("Error initializing APDS9960 sensor."); + } + + // get the TFL representation of the model byte array + tflModel = tflite::GetModel(model); + if (tflModel->version() != TFLITE_SCHEMA_VERSION) { + Serial.println("Model schema mismatch!"); + while (1); + } + + // Create an interpreter to run the model + tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter); + + // Allocate memory for the model's input and output tensors + tflInterpreter->AllocateTensors(); + + // Get pointers for the model's input and output tensors + tflInputTensor = tflInterpreter->input(0); + tflOutputTensor = tflInterpreter->output(0); +} + +void loop() { + int r, g, b, p, c; + float sum; + + // check if both color and proximity data is available to sample + while (!APDS.colorAvailable() || !APDS.proximityAvailable()) {} + + // read the color and proximity sensor + APDS.readColor(r, g, b, c); + p = APDS.readProximity(); + sum = r + g + b; + + // check if there's an object close and well illuminated enough + if (p == 0 && c > 10 && sum > 0) { + + float redRatio = r / sum; + float greenRatio = g / sum; + float blueRatio = b / sum; + + // input sensor data to model + tflInputTensor->data.f[0] = redRatio; + tflInputTensor->data.f[1] = greenRatio; + tflInputTensor->data.f[2] = blueRatio; + + // Run inferencing + TfLiteStatus invokeStatus = tflInterpreter->Invoke(); + if (invokeStatus != kTfLiteOk) { + Serial.println("Invoke failed!"); + while (1); + return; + } + + // Output results + for (int i = 0; i < NUM_CLASSES; i++) { + Serial.print(CLASSES[i]); + Serial.print(" "); + Serial.print(int(tflOutputTensor->data.f[i] * 100)); + Serial.print("%\n"); + } + Serial.println(); + + // Wait for the object to be moved away + while (!APDS.proximityAvailable() || (APDS.readProximity() == 0)) {} + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/Emoji_Button/Emoji_Button.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/Emoji_Button/Emoji_Button.ino new file mode 100644 index 00000000..ff350d28 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/Emoji_Button/Emoji_Button.ino @@ -0,0 +1,92 @@ +/* + Emoji Button + + This example sends an emoji character over USB HID when the button is pressed. + + Note: Only macOS and Linux as supported at this time, and the use of + #define is generally discouraged in Arduino examples + + The circuit: + - Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board. + - Button connected to pin 3 and GND. + + Created by Don Coleman, Sandeep Mistry + + This example code is in the public domain. +*/ + +#include +#include + +// Select an OS: +//#define MACOS // You'll need to enable and select the unicode keyboard: System Preferences -> Input Sources -> + -> Others -> Unicode Hex Input +//#define LINUX + +#if !defined(MACOS) && !defined(LINUX) +#error "Please select an OS!" +#endif + +// use table: https://apps.timwhitlock.info/emoji/tables/unicode +const int bicep = 0x1f4aa; +const int punch = 0x1f44a; + +const int buttonPin = 3; + +USBKeyboard keyboard; + +int previousButtonState = HIGH; + +void setup() { + pinMode(buttonPin, INPUT_PULLUP); +} + +void loop() { + int buttonState = digitalRead(buttonPin); + + if (buttonState != previousButtonState) { + if (buttonState == LOW) { + // pressed + sentUtf8(bicep); + } else { + // released + } + + previousButtonState = buttonState; + } +} + +void sentUtf8(unsigned long c) { + String s; + +#if defined(MACOS) + // https://apple.stackexchange.com/questions/183045/how-can-i-type-unicode-characters-without-using-the-mouse + + s = String(utf8ToUtf16(c), HEX); + + for (int i = 0; i < s.length(); i++) { + keyboard.key_code(s[i], KEY_ALT); + } +#elif defined(LINUX) + s = String(c, HEX); + + keyboard.key_code('u', KEY_CTRL | KEY_SHIFT); + + for (int i = 0; i < s.length(); i++) { + keyboard.key_code(s[i]); + } +#endif + keyboard.key_code(' '); +} + +// based on https://stackoverflow.com/a/6240819/2020087 +unsigned long utf8ToUtf16(unsigned long in) { + unsigned long result; + + in -= 0x10000; + + result |= (in & 0x3ff); + result |= (in << 6) & 0x03ff0000; + result |= 0xd800dc00; + + return result; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/HardwareTest/HardwareTest.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/HardwareTest/HardwareTest.ino new file mode 100644 index 00000000..19bd9b32 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/HardwareTest/HardwareTest.ino @@ -0,0 +1,66 @@ +/* + Hardware Test + + This example performs a basic hardware test of the board which includes + testing the on-board IMU, LED and external button. + + When the button is pressed the on-board LED will turn on. + + The circuit: + - Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board. + - Button connected to pin 3 and GND. + + Created by Don Coleman, Sandeep Mistry + + This example code is in the public domain. +*/ + +#include + +const int buttonPin = 3; +const int ledPin = LED_BUILTIN; + +int buttonState = LOW; +int previousButtonState = HIGH; + +void setup() { + Serial.begin(9600); + //while (!Serial); + Serial.println("Arduino ML Workshop Hardware Test"); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1); + } + + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize the push button pin as an input with (internal) pullup: + pinMode(buttonPin, INPUT_PULLUP); +} + +void loop() { + // read the state of the push button pin: + buttonState = digitalRead(buttonPin); + + // HIGH and LOW are opposite because of we are using an internal pullup resistor. + // LOW is pressed. HIGH is released. + + if (buttonState == LOW) { + // Button is pressed, turn the LED on + digitalWrite(ledPin, HIGH); + if (buttonState != previousButtonState) { + Serial.println("LED is ON"); + } + } else { + // Button is released, turn the LED off + digitalWrite(ledPin, LOW); + if (buttonState != previousButtonState) { + Serial.println("LED is OFF"); + } + } + + // save the previous state of the button since we only print + // the LED status when the state changes + previousButtonState = buttonState; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Capture/IMU_Capture.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Capture/IMU_Capture.ino new file mode 100644 index 00000000..d41c802c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Capture/IMU_Capture.ino @@ -0,0 +1,92 @@ +/* + IMU Capture + + This example uses the on-board IMU to start reading acceleration and gyroscope + data from on-board IMU and prints it to the Serial Monitor for one second + when the significant motion is detected. + + You can also use the Serial Plotter to graph the data. + + The circuit: + - Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board. + + Created by Don Coleman, Sandeep Mistry + Modified by Dominic Pajak, Sandeep Mistry + + This example code is in the public domain. +*/ + +#include + +const float accelerationThreshold = 2.5; // threshold of significant in G's +const int numSamples = 119; + +int samplesRead = numSamples; + +void setup() { + Serial.begin(9600); + while (!Serial); + + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1); + } + + // print the header + Serial.println("aX,aY,aZ,gX,gY,gZ"); +} + +void loop() { + float aX, aY, aZ, gX, gY, gZ; + + // wait for significant motion + while (samplesRead == numSamples) { + if (IMU.accelerationAvailable()) { + // read the acceleration data + IMU.readAcceleration(aX, aY, aZ); + + // sum up the absolutes + float aSum = fabs(aX) + fabs(aY) + fabs(aZ); + + // check if it's above the threshold + if (aSum >= accelerationThreshold) { + // reset the sample read count + samplesRead = 0; + break; + } + } + } + + // check if the all the required samples have been read since + // the last time the significant motion was detected + while (samplesRead < numSamples) { + // check if both new acceleration and gyroscope data is + // available + if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) { + // read the acceleration and gyroscope data + IMU.readAcceleration(aX, aY, aZ); + IMU.readGyroscope(gX, gY, gZ); + + samplesRead++; + + // print the data in CSV format + Serial.print(aX, 3); + Serial.print(','); + Serial.print(aY, 3); + Serial.print(','); + Serial.print(aZ, 3); + Serial.print(','); + Serial.print(gX, 3); + Serial.print(','); + Serial.print(gY, 3); + Serial.print(','); + Serial.print(gZ, 3); + Serial.println(); + + if (samplesRead == numSamples) { + // add an empty line if it's the last sample + Serial.println(); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/IMU_Classifier.ino b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/IMU_Classifier.ino new file mode 100644 index 00000000..83b34e19 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/IMU_Classifier.ino @@ -0,0 +1,161 @@ +/* + IMU Classifier + + This example uses the on-board IMU to start reading acceleration and gyroscope + data from on-board IMU, once enough samples are read, it then uses a + TensorFlow Lite (Micro) model to try to classify the movement as a known gesture. + + Note: The direct use of C/C++ pointers, namespaces, and dynamic memory is generally + discouraged in Arduino examples, and in the future the TensorFlowLite library + might change to make the sketch simpler. + + The circuit: + - Arduino Nano 33 BLE or Arduino Nano 33 BLE Sense board. + + Created by Don Coleman, Sandeep Mistry + Modified by Dominic Pajak, Sandeep Mistry + + This example code is in the public domain. +*/ + +#include + +#include +#include +#include +#include +#include +#include + +#include "model.h" + +const float accelerationThreshold = 2.5; // threshold of significant in G's +const int numSamples = 119; + +int samplesRead = numSamples; + +// global variables used for TensorFlow Lite (Micro) +tflite::MicroErrorReporter tflErrorReporter; + +// pull in all the TFLM ops, you can remove this line and +// only pull in the TFLM ops you need, if would like to reduce +// the compiled size of the sketch. +tflite::AllOpsResolver tflOpsResolver; + +const tflite::Model* tflModel = nullptr; +tflite::MicroInterpreter* tflInterpreter = nullptr; +TfLiteTensor* tflInputTensor = nullptr; +TfLiteTensor* tflOutputTensor = nullptr; + +// Create a static memory buffer for TFLM, the size may need to +// be adjusted based on the model you are using +constexpr int tensorArenaSize = 8 * 1024; +byte tensorArena[tensorArenaSize] __attribute__((aligned(16))); + +// array to map gesture index to a name +const char* GESTURES[] = { + "punch", + "flex" +}; + +#define NUM_GESTURES (sizeof(GESTURES) / sizeof(GESTURES[0])) + +void setup() { + Serial.begin(9600); + while (!Serial); + + // initialize the IMU + if (!IMU.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1); + } + + // print out the samples rates of the IMUs + Serial.print("Accelerometer sample rate = "); + Serial.print(IMU.accelerationSampleRate()); + Serial.println(" Hz"); + Serial.print("Gyroscope sample rate = "); + Serial.print(IMU.gyroscopeSampleRate()); + Serial.println(" Hz"); + + Serial.println(); + + // get the TFL representation of the model byte array + tflModel = tflite::GetModel(model); + if (tflModel->version() != TFLITE_SCHEMA_VERSION) { + Serial.println("Model schema mismatch!"); + while (1); + } + + // Create an interpreter to run the model + tflInterpreter = new tflite::MicroInterpreter(tflModel, tflOpsResolver, tensorArena, tensorArenaSize, &tflErrorReporter); + + // Allocate memory for the model's input and output tensors + tflInterpreter->AllocateTensors(); + + // Get pointers for the model's input and output tensors + tflInputTensor = tflInterpreter->input(0); + tflOutputTensor = tflInterpreter->output(0); +} + +void loop() { + float aX, aY, aZ, gX, gY, gZ; + + // wait for significant motion + while (samplesRead == numSamples) { + if (IMU.accelerationAvailable()) { + // read the acceleration data + IMU.readAcceleration(aX, aY, aZ); + + // sum up the absolutes + float aSum = fabs(aX) + fabs(aY) + fabs(aZ); + + // check if it's above the threshold + if (aSum >= accelerationThreshold) { + // reset the sample read count + samplesRead = 0; + break; + } + } + } + + // check if the all the required samples have been read since + // the last time the significant motion was detected + while (samplesRead < numSamples) { + // check if new acceleration AND gyroscope data is available + if (IMU.accelerationAvailable() && IMU.gyroscopeAvailable()) { + // read the acceleration and gyroscope data + IMU.readAcceleration(aX, aY, aZ); + IMU.readGyroscope(gX, gY, gZ); + + // normalize the IMU data between 0 to 1 and store in the model's + // input tensor + tflInputTensor->data.f[samplesRead * 6 + 0] = (aX + 4.0) / 8.0; + tflInputTensor->data.f[samplesRead * 6 + 1] = (aY + 4.0) / 8.0; + tflInputTensor->data.f[samplesRead * 6 + 2] = (aZ + 4.0) / 8.0; + tflInputTensor->data.f[samplesRead * 6 + 3] = (gX + 2000.0) / 4000.0; + tflInputTensor->data.f[samplesRead * 6 + 4] = (gY + 2000.0) / 4000.0; + tflInputTensor->data.f[samplesRead * 6 + 5] = (gZ + 2000.0) / 4000.0; + + samplesRead++; + + if (samplesRead == numSamples) { + // Run inferencing + TfLiteStatus invokeStatus = tflInterpreter->Invoke(); + if (invokeStatus != kTfLiteOk) { + Serial.println("Invoke failed!"); + while (1); + return; + } + + // Loop through the output tensor values from the model + for (int i = 0; i < NUM_GESTURES; i++) { + Serial.print(GESTURES[i]); + Serial.print(": "); + Serial.println(tflOutputTensor->data.f[i], 6); + } + Serial.println(); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/model.h b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/model.h new file mode 100644 index 00000000..8f3216f6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/ArduinoSketches/IMU_Classifier/model.h @@ -0,0 +1,3 @@ +const unsigned char model[] = { + +}; diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/README.md new file mode 100644 index 00000000..56a060ba --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/GestureToEmoji/README.md @@ -0,0 +1,24 @@ +# Machine Learning on Arduino +## TensorFlow Lite gesture training tutorial + +In this tutorial we will teach a board to recognise gestures! We'll capture motion data from the [Arduino Nano 33 BLE Sense](https://store.arduino.cc/arduino-nano-33-ble-sense) board, import it into TensorFlow to train a model, and deploy a classifier onto the board using [TensorFlow Lite for microcontrollers](https://www.tensorflow.org/lite/microcontrollers/overview). + +### Credits + +This tutorial is adapted from the [workshop](https://github.com/sandeepmistry/aimldevfest-workshop-2019) Sandeep Mistry, Arduino and Don Coleman, Chariot Solutions presented at AI/ML Devfest in September 2019. + + + + +## Exercises + +* [Exercise 1: Development Environment](exercises/exercise1.md) +* [Exercise 2: Connecting the Board](exercises/exercise2.md) +* [Exercise 3: Visualizing the IMU Data](exercises/exercise3.md) +* [Exercise 4: Gather the Training Data](exercises/exercise4.md) +* [Exercise 5: Machine Learning](exercises/exercise5.md) +* [Exercise 6: Classifying IMU Data](exercises/exercise6.md) +* [Exercise 7: Gesture Controlled USB Emoji Keyboard](exercises/exercise7.md) +* [Exercise 8: Next Steps](exercises/exercise8.md) + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/README.md new file mode 100644 index 00000000..faa83359 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/ArduinoTensorFlowLiteTutorials/README.md @@ -0,0 +1,11 @@ +# Machine Learning on Arduino +## Arduino TensorFlow Lite Tutorials + +[![Compile Sketches status](https://github.com/arduino/ArduinoTensorFlowLiteTutorials/actions/workflows/compile-sketches.yml/badge.svg)](https://github.com/arduino/ArduinoTensorFlowLiteTutorials/actions/workflows/compile-sketches.yml) + +This Github repo contains tutorials for using TensorFlow Lite on Arduino hardware. + +* [GestureToEmoji](GestureToEmoji/) + * Use the Arduino Nano 33 BLE Sense to convert motion gestures to emojis +* [FruitToEmoji](FruitToEmoji/) + * Use the Arduino Nano 33 BLE Sense to classify fruit using the RGB color and proximity sensors diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/LICENSE b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/LICENSE new file mode 100644 index 00000000..001b337a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/LICENSE @@ -0,0 +1,674 @@ +GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/README.md b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/README.md new file mode 100644 index 00000000..ac18e10d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/README.md @@ -0,0 +1,301 @@ +# Education Introduction Library - a.k.a. EduIntro + +## Description + +Arduino library for short introduction training workshops run by Arduino Education. This library is originally made for TinkerKit. It simplifies the use of sensors and actuators when connected to an Arduino board. The goal is to plan and conduct a simple one or two hours of training workshop where users will still have the opportunity to model meaningful interactions using discrete electronic components. It consists of already implemented basic functions for electronic components. In order to use its functions, it only requires to import this library and then call its functions. + +## Installation + +### First Method + +1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries +1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation. +1. Then search for EduIntro using the search bar. +1. Click on the text area and then select the specific version and install it. + +### Second Method + +1. Navigate to the Releases page. +1. Download the latest release. +1. Extract the zip file +1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library + +## Features + +- ### Self contained + + EduIntro doesn’t depend on any library. + +- ### Easy to use + + It is simple, basic and very easy to understand. The user only needs to import the library in his code and start using its functions. + +- ### Complete package for small workshops + + Basic functions of discrete electronic components have already been implemented in this library. For a small one or two hours workshop, the user does not have to implement all the basic functions for the electronic component from scratch. + +- ### Function calls + + Basic functions of the electronic components have been implemented in this library. There's no need to re-implement these basic functions from scratch. The user simply has to import the library in the project and can use any of its functions by just calling it. + +- ### Intuitive syntax + + EduIntro has a simple and intuitive syntax to handle variables and functions. + +- ### Give back + + EduIntro is free for everyone. Everyone can download and use it in their projects, assignments or anywhere for free. + +## Components and functions + +- ### Button + + - readSwitch() + - pressed() + - released() + - held() + - *Note: construct a button with Button NAME(PIN) or Button NAME(PIN,PULL_UP | PULL_DOWN), by default buttons are considered to use internal pull-ups* + +- ### DHT11 + + - update() + - readCelsius() + - readFahrenheit() + - readHumidity() + +- ### Generic + + - ### For analog inputs + + - readX() + - readY() + - readZ() + - read() + - increasing() + - decreasing() + + - ### For digital inputs + + - read() + + - ### For outputs (this extends to LEDs) + + - isPWM() + - write() + - on() + - off() + - blink() + - state() + - *Note: construct an output with e.g. Led NAME(PIN) or Led NAME(PIN,NORMAL | INVERTED), this helps with common cathode LEDs* + +- ### IMU + + - begin() + - readAcceleration() + - readGyroscope() + - read() + +- ### LED (besides all of the output functions) + + - brightness() + +- ### LM35 + + - readCelsius() + - readFahrenheit() + +- ### PIR + + - update() + - hadActivity() + - resetActivity() + - readSwitch() + - activated() + - deactivated() + - active() + +- ### Piezo + + - beep() + - noBeep() + - play() + - getMelodySize() + +- ### Potentiometer + + - read() + - readRange() + - readStep() + +- ### ServoMotor + + - write() + +- ### Thermistor + + - readCelsius() + - readFahrenheit() + +- ### WiFiComm + + - init() + - getSSID() + - getIP() + - getStatus() + - getClient() + +## Examples + +There are many examples implemented in this library. Below are shown some of the examples. + + - ### Blink + Turns on an LED on for one second, then off for one second, repeatedly + +``` C++ +#include + +Led led(D10); + +void loop() +{ + led.on(); + delay(1000); + led.off(); + delay(1000); +} +``` + + - ### Button + Changes the behavior between on and off an LED when pressing a button. + +``` C++ +#include + +Button button(D7); +Led led(D10); + +void loop() +{ + if (button.readSwitch() == LOW) { + led.on(); + } + else { + led.off(); + } +} +``` + +## Versions + +### v0.0.16 (Current stable version) + +#### November, 2021 + +* Fixed an issue with the Potentiometer class in mbed (Nano 33 BLE Sense) +* Added readRange() method for the Potentiometer +* Added inverted logic for outputs and the constructor to have e.g. *Led led(PIN, NORMAL | INVERTED)* + +### v0.0.13 + +#### April, 2021 + +* Eliminated delays in button handling +* Added second constructor for Button, choose pull_up or down + +### v0.0.12 + +#### December 16, 2019 + +* Added library dependencies + +### v0.0.11 + +#### December 9, 2019 + +* Added Nano Every by separating the two possible MEGAAVR boards (Nano Every + Uno WiFi rev2). +* Included a noBeep() function +* Added the new README with basic API description + +### v0.0.10 + +#### August 28, 2019 + +The previous release included a non-functional WiFiComm file. It has been revised and made beautification in some of the code. It has been made sure that the Classic boards work fine as it got broken in the previous release. + +### v0.0.9 + +#### August 27, 2019 + +Added support for the WiFi REV2 board and fixed the incompatibilities with servo and piezo. + +### v0.0.8 + +#### May 01, 2019 + +All classes were separated to allow adding new classes by simply copy-pasting and modifying template examples. + +### v0.0.7 + +#### April 17, 2019 + +General bug fixing: servo library not-two-servos fixed, added a new two-melodies example, fixed the button-pressed-by-default bug. Thanks to D. Spikol for bug catching and S. Mistry for reminding me that C++ inheritance is not always doing the things you expect. + +### v0.0.6 + +#### February 10, 2019 + +For a course at Aalborg University, CPH, we added the humidity and temperature sensor DHT11, the LM35 temperature sensor, a PIR sensor, and a couple more examples to the courseware. + +### v0.0.5 + +#### January 27, 2019 + +Sabas came all the way from Mexico to Malmo and made a fresh pull request. Now the library works with MKR boards! + +### v0.0.4 + +#### January 25, 2019 + +See possible results of the workshop [here](https://photos.app.goo.gl/G9B4KmBHX7FQGdYNA) + +## Contributing + +If you want to contribute to this project: + +- Report bugs and errors +- Ask for enhancements +- Create issues and pull requests +- Tell others about this library +- Contribute new protocols + +Please read [CONTRIBUTING.md](https://github.com/arduino/EduIntro/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. + +## Credits + +The Library created and maintained by D. Cuartielles, Malmo, 2018 - 2019 +WiFi REV2 compatibility by C. Rodriguez (IMU + WiFi), and D. Cuartielles (servo), Malmo, 2019 +MKR compatibility by A. Sabas, Malmo, 2019 + +Based on previous work by: + +- D. Mellis, Milano, 2006 +- T. Igoe, New York, 2008 - 2010 +- S. Fitzgerald, New York, 2010 +- D. Gomba, Torino, 2010 +- F. Vanzati, Torino, 2011 +- M. Loglio, London, 2013 +- G. Hadjikyriacou (DHT11 lib originator), ?? +- SimKard (DHT11), 2010 +- R. Tillaart (DHT11), 2011 - 2013 +- A. Dalton (DHT11), 2013 +- [Arduino community](https://www.arduino.cc) + +## Current stable version + +**number:** v0.0.16 + +**codename:** ananas + +## License + +This library is licensed under [GPLv3](https://www.gnu.org/licenses/quick-guide-gplv3.html). diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/IMU/IMU.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/IMU/IMU.ino new file mode 100644 index 00000000..4515fa4c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/IMU/IMU.ino @@ -0,0 +1,56 @@ +/* + Inertia Meassurement Unit (IMU) A.K.A. Motion + + IMPORTANT: This example is using the Arduino_LSM6DS3 library in the backed. You + need to have it installed before testing this code. If you are on + Arduino Create (the online IDE) the library will already be there. + + This example uses the embeded IMU unit in the Arduino UNO Wifi Rev2. + + The IMU captures values from the accelerometer and the gyroscope. + These values can be accesable with: + + acc_x: Returns the X value of the accelerometer. + acc_y: Returns the Y value of the accelerometer. + acc_z: Returns the Z value of the accelerometer. + gyro_x: Returns the X value of the gyroscope. + gyro_y: Returns the Y value of the gyroscope. + gyro_z: Returns the Z value of the gyroscope. + + This example code is in the public domain. + + created in Aug 2019 by C. Rodriguez + based on work by D. Cuartielles (2019), F. Vanzati (2011) and M. Loglio (2013) +*/ + +// include the EduIntro library +#include + +Motion imu; //Create the object to access the IMU unit + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); + + // initialize the IMU, if failed, stay here + if (!imu.begin()) { + Serial.println("Failed to initialize IMU!"); + while (1); + } +} + +void loop() +{ + // read all data from the IMU and store it in local variables + if (imu.read()) { + + // print the collected data in a row on the Serial Monitor + // or use the Serial Plotter to better understand the values + Serial.print(imu.acc_x); + Serial.print('\t'); + Serial.print(imu.acc_y); + Serial.print('\t'); + Serial.println(imu.acc_z); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/WebLed/WebLed.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/WebLed/WebLed.ino new file mode 100644 index 00000000..85529613 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/WiFi_rev2/WebLed/WebLed.ino @@ -0,0 +1,132 @@ +/* + WebLed + + WiFi Web Server LED Blink + + A simple web server that lets you blink an LED via the web. + This sketch will create a new access point (with no password). + It will then launch a new server and print out the IP address + to the Serial monitor. From there, you can open that address in a web browser + to turn on and off the LED on pin 13. + + If the IP address of your board is yourAddress: + http://yourAddress/H turns the LED on + http://yourAddress/L turns it off + + Adapted to EduIntro by C. Rodriguez, and D. Cuartielles (2019) + + Created by Tom Igoe (2012) +*/ + +#include + +// network related info +const char ssid[] = "ArduinoWiFi"; // your network SSID (name). Must have 8 or more characters. +const char pass[] = ""; // your network password (use for WPA, or use as key for WEP). optional, but if set, must have 8 or more characters. +int keyIndex = 0; // your network key Index number (needed only for WEP) + +// misc variables +WiFiComm MyWiFi; +int led = LED_BUILTIN; +int status = WL_IDLE_STATUS; +boolean firstTime = true; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) {}; + + MyWiFi.init(led, ssid, pass); + + // you're connected now, so print out the status + printWiFiStatus(); + Serial.print("\t SSID:"); + Serial.println(MyWiFi.getSSID()); +} + +void loop() { + // compare the previous status to the current status + if (status != MyWiFi.getStatus()) { + // it has changed update the variable + status = MyWiFi.getStatus(); + + if (status == WL_AP_CONNECTED) { + // a device has connected to the AP + Serial.println("Device connected to AP"); + } else { + if (!firstTime) { + // a device has disconnected from the AP, and we are back in listening mode + Serial.println("Device disconnected from AP"); + } + } + } + + WiFiClient client = MyWiFi.getClient(); // listen for incoming clients + + if (client) { // if you get a client, + firstTime = false; + Serial.println("new client"); // print a message out the serial port + String currentLine = ""; // make a String to hold incoming data from the client + while (client.connected()) { // loop while the client's connected + if (client.available()) { // if there's bytes to read from the client, + char c = client.read(); // read a byte, then + Serial.write(c); // print it out the serial monitor + if (c == '\n') { // if the byte is a newline character + + // if the current line is blank, you got two newline characters in a row. + // that's the end of the client HTTP request, so send a response: + if (currentLine.length() == 0) { + // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) + // and a content-type so the client knows what's coming, then a blank line: + client.println("HTTP/1.1 200 OK"); + client.println("Content-type:text/html"); + client.println(); + + // the content of the HTTP response follows the header: + client.print("Click here turn the LED on
    "); + client.print("Click here turn the LED off
    "); + + // The HTTP response ends with another blank line: + client.println(); + // break out of the while loop: + break; + } + else { // if you got a newline, then clear currentLine: + currentLine = ""; + } + } + else if (c != '\r') { // if you got anything else but a carriage return character, + currentLine += c; // add it to the end of the currentLine + } + + // Check to see if the client request was "GET /H" or "GET /L": + if (currentLine.endsWith("GET /H")) { + digitalWrite(led, HIGH); // GET /H turns the LED on + } + if (currentLine.endsWith("GET /L")) { + digitalWrite(led, LOW); // GET /L turns the LED off + } + } + } + // close the connection: + client.stop(); + Serial.println("client disconnected"); + } + +} + + +void printWiFiStatus() { + // print the SSID of the network you're attached to: + Serial.print("SSID: "); + Serial.println(MyWiFi.getSSID()); + + // print your WiFi shield's IP address: + IPAddress ip = MyWiFi.getIP(); + Serial.print("IP Address: "); + Serial.println(ip); + + // print where to go in a browser: + Serial.print("To see this page in action, open a browser to http://"); + Serial.println(ip); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Blink/Blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Blink/Blink.ino new file mode 100644 index 00000000..3547b4e2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Blink/Blink.ino @@ -0,0 +1,28 @@ +/* + Blink + + based on Blink, Arduino's "Hello World!" + Turns on an LED on for one second, then off for one second, repeatedly. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Led led(D10); // creating the object 'led' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + led.on(); // set the LED on + delay(1000); // wait for a second + led.off(); // set the LED off + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Button/Button.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Button/Button.ino new file mode 100644 index 00000000..10529c94 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Button/Button.ino @@ -0,0 +1,37 @@ +/* + Button + + Changes the behavior between on and off an LED when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + // check the switchState of the button + // each time it is pressed, it toggles the LED + // when LOW, light should go on + if (button.readSwitch() == LOW) { + led.on(); + } + else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ButtonStates/ButtonStates.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ButtonStates/ButtonStates.ino new file mode 100644 index 00000000..5b198c62 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ButtonStates/ButtonStates.ino @@ -0,0 +1,37 @@ +/* + ButtonStates + + Test the different Button methods: pressed, released, held + and getSwitch. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +Button btn(D7); + +void setup() +{ + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() +{ + if(btn.pressed()) + Serial.println("pressed"); + if(btn.held()) + Serial.println("held"); + if(btn.released()) { + Serial.println("released"); + Serial.print("switch: "); + Serial.println(btn.readSwitch()); + } + + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/DHT11/DHT11.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/DHT11/DHT11.ino new file mode 100644 index 00000000..fc0cdf1f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/DHT11/DHT11.ino @@ -0,0 +1,45 @@ +/* +DHT11 + +This example reads a DHT11 sensor hooked up on pin D7. Reads both +temperature and humidity and sends it to the Serial port + +created in Feb 2019 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +DHT11 dht11(D7); // creating the object sensor on pin 'D7' + +int C; // temperature C readings are integers +float F; // temperature F readings are returned in float format +int H; // humidity readings are integers + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + dht11.update(); + + C = dht11.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = dht11.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + H = dht11.readHumidity(); // Reading the humidity index + + // Print the collected data in a row on the Serial Monitor + Serial.print("H: "); + Serial.print(H); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Empty/Empty.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Empty/Empty.ino new file mode 100644 index 00000000..9b72a6d4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Empty/Empty.ino @@ -0,0 +1,9 @@ +#include + +void setup() { + //Serial.begin(9600); +} + +void loop() { + +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/LM35/LM35.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/LM35/LM35.ino new file mode 100644 index 00000000..fcbcf0ac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/LM35/LM35.ino @@ -0,0 +1,44 @@ +/* +LM35 + +This example uses an LM35 (or equivalent) sensor hooked up on pin A0. + +Three values are displayed on the Serial Monitor every second: +- the value between 0 and 1023 that represent the Analog Input reading +- the temperature expressed in Celsius degrees +- the temperature expressed in Fahrenheit dedegrees + +created in Feb 2019 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +LM35 lm35(A0); // creating the object 'lm35' on pin A0 + +float C, F; // temperature readings are returned in float format + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + C = lm35.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = lm35.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + + // Print the collected data in a row on the Serial Monitor + Serial.print("Analog reading: "); // Reading the analog value from the thermistor + Serial.print(lm35.read()); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/LightSensor/LightSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/LightSensor/LightSensor.ino new file mode 100644 index 00000000..dfd426ac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/LightSensor/LightSensor.ino @@ -0,0 +1,42 @@ +/* + Read values from an LDR Analog Sensor connected to A0, + then uses the result to set the brightness on an LED + connected on D9. Also prints the values on the + serial monitor. + + created in Aug 2018 by D. Cuartielles + based on work by T. Igoe (2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +#include + +LightSensor ldr(A0); //create the "ldr" object on pin A0 + +Led led(D10); //create the "led" object on pin D10 + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // store the ldr values into a variable called brightnessVal + int brightnessVal = ldr.read(); + + // set the led brightness + led.brightness(brightnessVal); + + //to have it at full brightness + //when it's dark, uncomment this line: + //led.brightness(1023 - brightnessVal); + + // print the results to the serial monitor: + Serial.print("brightness = " ); + Serial.println(brightnessVal); + + + // wait 10 milliseconds before the next loop + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Melody/Melody.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Melody/Melody.ino new file mode 100644 index 00000000..4dacb0e2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Melody/Melody.ino @@ -0,0 +1,36 @@ +/* + Melody + + Plays a song stored in an array, repeatedly. You should connect + a speaker to pin D10 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + piezo.play(melody); // play the song + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MelodyButton/MelodyButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MelodyButton/MelodyButton.ino new file mode 100644 index 00000000..bae0386c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MelodyButton/MelodyButton.ino @@ -0,0 +1,40 @@ +/* + MelodyButton + + Plays a song stored in an array, when pressing a button. You should connect + a speaker to pin D10 and a button to pin D7 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Button button(D7); // creating the object 'button' on pin D7 + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play(melody); // play the song + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino new file mode 100644 index 00000000..a1812f08 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino @@ -0,0 +1,46 @@ +/* + MelodyButtonTwoSounds + + Plays a song stored in an array, when pressing a button, a different one + when releasing the button. You should connect a speaker to pin D10 and a + button to pin D7. Melodies are stored in arrays ending with NULL + + created in Apr 2019 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc. +// add the NULL to signify the end of the array +int melody1[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + SILENCE, 4, NULL}; + +int melody2[] = { NOTE_D4, 4, + NOTE_C3, 8, + NOTE_F3, 8, + SILENCE, 4, NULL}; + +Button button(D7);// creating the object 'button' on pin D7 + +Piezo piezo(D10);// creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() +{ + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play (melody1); + } + if (button.released()) { + piezo.play (melody2); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MosFet/MosFet.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MosFet/MosFet.ino new file mode 100644 index 00000000..a8102856 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/MosFet/MosFet.ino @@ -0,0 +1,28 @@ +/* +Write a signal to a MosFet transistor using a Potentiometer. + +created in Aug 2018 by D. Cuartielles +based on work by M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +MosFet mos(D3); //create the mos object on pin D3 +Potentiometer pot(A0); //create the pot object on pin A0 + +void setup() { + //nothing here +} + +void loop() +{ + int val = pot.read(); //assign to a "val" variable + //the potentiometer values + + mos.write(val); //assign the values to the mosfet + + delay(10); //rest for 10 milliseconds. +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PIR/PIR.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PIR/PIR.ino new file mode 100644 index 00000000..4ad2eda1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PIR/PIR.ino @@ -0,0 +1,36 @@ +/* + PIR + + Changes the behavior between on and off an LED when a PIR sensor is activated. + Assumes the use of a PIR sensor that needs no pull-up + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + */ + +// include the EduIntro library +#include + +PIR pir(D7); // creating the object 'pir' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + // check the state of the PIR sensor + // if you just want to detect the turn from not active to active + // use pir.activated() instead + if (pir.active() == HIGH) { + led.on(); + } + else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PIRStates/PIRStates.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PIRStates/PIRStates.ino new file mode 100644 index 00000000..ee893556 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PIRStates/PIRStates.ino @@ -0,0 +1,42 @@ +/* + PIRStates + + Test the different PIR methods: activated, deactivated, active, + readSwitch, hadActivity, and resetActivity + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +PIR pir(D7); + +void setup() +{ + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() +{ + if(pir.activated()) + Serial.println("activited"); + if(pir.active()) + Serial.println("still active"); + if(pir.deactivated()) { + Serial.println("deactivated"); + Serial.print("switch: "); + Serial.println(pir.readSwitch()); + } + if(!pir.activated() && pir.hadActivity()) { + Serial.print("had activity: "); + Serial.println(pir.hadActivity()); + pir.resetActivity(); + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PhysicalPixel/PhysicalPixel.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PhysicalPixel/PhysicalPixel.ino new file mode 100644 index 00000000..a33f0343 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/PhysicalPixel/PhysicalPixel.ino @@ -0,0 +1,52 @@ +/* +Physical Pixel + +An example of using the Arduino board to receive data from the computer. In +this case, the Arduino boards turns on an LED when it receives the character +'H', and turns off the LED when it receives the character 'L'. + +The data can be sent from the Arduino Serial Monitor, or another program like +Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. + +The circuit: +- LED connected from digital pin 13 to ground + + created in Aug 2018 by D. Cuartielles + based on work by D. Mellis (2006), T. Igoe and S. Fitzgerald (2011) + + This example code is in the public domain. + */ + +#include + +Led led(D13); + +int incomingByte; // a variable to read incoming serial data + +void setup() +{ + Serial.begin(9600); +} + + +void loop() { + // see if there's incoming serial data: + if (Serial.available() > 0) { + + // read the oldest byte in the serial buffer: + incomingByte = Serial.read(); + + // if it's a capital H (ASCII 72), turn on the LED: + if (incomingByte == 'H') { + led.on(); + } + // if it's an L (ASCII 76) turn off the LED: + if (incomingByte == 'L') { + led.off(); + } + + if (incomingByte == 'S') { + Serial.println(led.state(), DEC); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Potentiometer/Potentiometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Potentiometer/Potentiometer.ino new file mode 100644 index 00000000..0b259803 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Potentiometer/Potentiometer.ino @@ -0,0 +1,40 @@ +/* + Read the value of a Potentiometer connected to A0, + then uses the results to write the brightness on + an LED connected on D10. Also prints the values + on the serial monitor. + + created in Aug 2018 by D. Cuartielles + based on work by T. Igoe (2008, 2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +Led led(D10); // creating the object 'led' on pin D10 + +int brightnessVal = 0; // value read from the pot + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // read the potentiometer's value: + brightnessVal = pot.read(); + + // set the led brightness + led.brightness(brightnessVal); + + // print the results to the serial monitor: + Serial.print("brightness = " ); + Serial.println(brightnessVal); + + + // wait 10 milliseconds before the next loop + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Relay/Relay.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Relay/Relay.ino new file mode 100644 index 00000000..5f4e0a3d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Relay/Relay.ino @@ -0,0 +1,35 @@ +/* + Relay + + Turns on and off a Relay connected to D10, when pressing a + Button attached to D7. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Button btn(D7); // creating the object 'button' on pin D7 + +Relay relay(D10); // creating the object 'relay' on pin D10 + +void setup() { + // nothing to add here +} + +void loop() +{ + // check the switch state + if(btn.readSwitch() == HIGH) { + relay.on(); + } + else{ + relay.off(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/RisingDecreasing/RisingDecreasing.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/RisingDecreasing/RisingDecreasing.ino new file mode 100644 index 00000000..af4d5515 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/RisingDecreasing/RisingDecreasing.ino @@ -0,0 +1,32 @@ +/* +Increasing & Decreasing + + this sketch shows how to use increasing() and + decreasing() on analog inputs. + + increasing() returns HIGH when values are rising, + decreasing() is HIGH when values are decreasing + + created in Aug 2018 by D. Cuartielles + based on work by M. Loglio (2013) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Thermistor therm(A0); // creating the object 'therm' on pin A0 + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + if (therm.increasing()) Serial.println("increasing"); + if (therm.decreasing()) Serial.println("decreasing"); + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Servo/Servo.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Servo/Servo.ino new file mode 100644 index 00000000..657bb702 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Servo/Servo.ino @@ -0,0 +1,29 @@ +/* + Servo + + Makes a Servo change angle after some time. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + servo.write(90); + delay (1000); // wait for a second + servo.write(0); + delay (1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoButton/ServoButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoButton/ServoButton.ino new file mode 100644 index 00000000..4b5ff78a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoButton/ServoButton.ino @@ -0,0 +1,34 @@ +/* + Makes a Servo change angle when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + // check the switchState of the button + // each time it is pressed, it toggles the servo's position + // when LOW, light should go on + if (button.readSwitch() == LOW) { + servo.write(90); + } + else { + servo.write(0); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoKnob/ServoKnob.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoKnob/ServoKnob.ino new file mode 100644 index 00000000..9eef4a1e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoKnob/ServoKnob.ino @@ -0,0 +1,45 @@ +/* + Makes a Servo change angle when turning a potentiometer. + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + + based on https://www.arduino.cc/en/tutorial/knob + */ + +// include the EduIntro library +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + +int potVal = 0; // value read from the pot +int angleVal = 0; // value of the angle to set the servo + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + // read the potentiometer's value: + potVal = pot.read(); + + // map the data from the sensor (0..1023) to + // one the servo can take (0..180) + angleVal = map(potVal, 0, 1023, 0, 180); + + // set the led brightness + servo.write(angleVal); + + // print the results to the serial monitor: + Serial.print("angle = " ); + Serial.println(angleVal); + + + // wait 100 milliseconds before the next loop + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoKnobContinuous/ServoKnobContinuous.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoKnobContinuous/ServoKnobContinuous.ino new file mode 100644 index 00000000..ab949b08 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/ServoKnobContinuous/ServoKnobContinuous.ino @@ -0,0 +1,54 @@ +/* + Makes a Continuous Servo change speed when turning a potentiometer. + Prints the different motor states to the serial port. + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + + based on https://www.arduino.cc/en/tutorial/knob + */ + +// include the EduIntro library +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + +int potVal = 0; // value read from the pot +int angleVal = 0; // value of the angle to set the servo + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + // read the potentiometer's value: + potVal = pot.read(); + + // map the data from the sensor (0..1023) to + // one the servo can take (0..180) + angleVal = map(potVal, 0, 1023, 0, 180); + + // set the led brightness + servo.write(angleVal); + + // Signify it different events for the motor + if (angleVal == 90) + Serial.println("Motor Stop"); + if (angleVal <= 1) + Serial.println("Motor Max clockwise"); + if (angleVal >= 179) + Serial.println("Motor Max counter clockwise"); + + // print the results to the serial monitor: + Serial.print("angle = " ); + Serial.println(angleVal); + + + // wait 100 milliseconds before the next loop + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Thermistor/Thermistor.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Thermistor/Thermistor.ino new file mode 100644 index 00000000..46479676 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_board/all/Thermistor/Thermistor.ino @@ -0,0 +1,42 @@ +/* +Thermistor hooked up on pin A0. + +Three values are displayed on the Serial Monitor every second: +- the value between 0 and 1023 that represent the Analog Input reading +- the temperature expressed in Celsius degrees +- the temperature expressed in Fahrenheit dedegrees + +created in Aug 2018 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +Thermistor therm(A0); // creating the object 'therm' on pin A0 + +float C, F; // temperature readings are returned in float format + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + C = therm.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = therm.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + + // Print the collected data in a row on the Serial Monitor + Serial.print("Analog reading: "); // Reading the analog value from the thermistor + Serial.print(therm.read()); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Blink/Blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Blink/Blink.ino new file mode 100644 index 00000000..3547b4e2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Blink/Blink.ino @@ -0,0 +1,28 @@ +/* + Blink + + based on Blink, Arduino's "Hello World!" + Turns on an LED on for one second, then off for one second, repeatedly. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Led led(D10); // creating the object 'led' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + led.on(); // set the LED on + delay(1000); // wait for a second + led.off(); // set the LED off + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Button/Button.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Button/Button.ino new file mode 100644 index 00000000..10529c94 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Button/Button.ino @@ -0,0 +1,37 @@ +/* + Button + + Changes the behavior between on and off an LED when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + // check the switchState of the button + // each time it is pressed, it toggles the LED + // when LOW, light should go on + if (button.readSwitch() == LOW) { + led.on(); + } + else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ButtonStates/ButtonStates.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ButtonStates/ButtonStates.ino new file mode 100644 index 00000000..5b198c62 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ButtonStates/ButtonStates.ino @@ -0,0 +1,37 @@ +/* + ButtonStates + + Test the different Button methods: pressed, released, held + and getSwitch. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +Button btn(D7); + +void setup() +{ + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() +{ + if(btn.pressed()) + Serial.println("pressed"); + if(btn.held()) + Serial.println("held"); + if(btn.released()) { + Serial.println("released"); + Serial.print("switch: "); + Serial.println(btn.readSwitch()); + } + + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/DHT11/DHT11.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/DHT11/DHT11.ino new file mode 100644 index 00000000..fc0cdf1f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/DHT11/DHT11.ino @@ -0,0 +1,45 @@ +/* +DHT11 + +This example reads a DHT11 sensor hooked up on pin D7. Reads both +temperature and humidity and sends it to the Serial port + +created in Feb 2019 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +DHT11 dht11(D7); // creating the object sensor on pin 'D7' + +int C; // temperature C readings are integers +float F; // temperature F readings are returned in float format +int H; // humidity readings are integers + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + dht11.update(); + + C = dht11.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = dht11.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + H = dht11.readHumidity(); // Reading the humidity index + + // Print the collected data in a row on the Serial Monitor + Serial.print("H: "); + Serial.print(H); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Empty/Empty.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Empty/Empty.ino new file mode 100644 index 00000000..9b72a6d4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Empty/Empty.ino @@ -0,0 +1,9 @@ +#include + +void setup() { + //Serial.begin(9600); +} + +void loop() { + +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/LM35/LM35.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/LM35/LM35.ino new file mode 100644 index 00000000..fcbcf0ac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/LM35/LM35.ino @@ -0,0 +1,44 @@ +/* +LM35 + +This example uses an LM35 (or equivalent) sensor hooked up on pin A0. + +Three values are displayed on the Serial Monitor every second: +- the value between 0 and 1023 that represent the Analog Input reading +- the temperature expressed in Celsius degrees +- the temperature expressed in Fahrenheit dedegrees + +created in Feb 2019 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +LM35 lm35(A0); // creating the object 'lm35' on pin A0 + +float C, F; // temperature readings are returned in float format + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + C = lm35.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = lm35.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + + // Print the collected data in a row on the Serial Monitor + Serial.print("Analog reading: "); // Reading the analog value from the thermistor + Serial.print(lm35.read()); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/LightSensor/LightSensor.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/LightSensor/LightSensor.ino new file mode 100644 index 00000000..dfd426ac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/LightSensor/LightSensor.ino @@ -0,0 +1,42 @@ +/* + Read values from an LDR Analog Sensor connected to A0, + then uses the result to set the brightness on an LED + connected on D9. Also prints the values on the + serial monitor. + + created in Aug 2018 by D. Cuartielles + based on work by T. Igoe (2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +#include + +LightSensor ldr(A0); //create the "ldr" object on pin A0 + +Led led(D10); //create the "led" object on pin D10 + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // store the ldr values into a variable called brightnessVal + int brightnessVal = ldr.read(); + + // set the led brightness + led.brightness(brightnessVal); + + //to have it at full brightness + //when it's dark, uncomment this line: + //led.brightness(1023 - brightnessVal); + + // print the results to the serial monitor: + Serial.print("brightness = " ); + Serial.println(brightnessVal); + + + // wait 10 milliseconds before the next loop + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Melody/Melody.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Melody/Melody.ino new file mode 100644 index 00000000..4dacb0e2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Melody/Melody.ino @@ -0,0 +1,36 @@ +/* + Melody + + Plays a song stored in an array, repeatedly. You should connect + a speaker to pin D10 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + piezo.play(melody); // play the song + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MelodyButton/MelodyButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MelodyButton/MelodyButton.ino new file mode 100644 index 00000000..bae0386c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MelodyButton/MelodyButton.ino @@ -0,0 +1,40 @@ +/* + MelodyButton + + Plays a song stored in an array, when pressing a button. You should connect + a speaker to pin D10 and a button to pin D7 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Button button(D7); // creating the object 'button' on pin D7 + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play(melody); // play the song + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino new file mode 100644 index 00000000..a1812f08 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MelodyButtonTwoSounds/MelodyButtonTwoSounds.ino @@ -0,0 +1,46 @@ +/* + MelodyButtonTwoSounds + + Plays a song stored in an array, when pressing a button, a different one + when releasing the button. You should connect a speaker to pin D10 and a + button to pin D7. Melodies are stored in arrays ending with NULL + + created in Apr 2019 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc. +// add the NULL to signify the end of the array +int melody1[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + SILENCE, 4, NULL}; + +int melody2[] = { NOTE_D4, 4, + NOTE_C3, 8, + NOTE_F3, 8, + SILENCE, 4, NULL}; + +Button button(D7);// creating the object 'button' on pin D7 + +Piezo piezo(D10);// creating the object 'piezo' on pin D10 + +void setup() { + //nothing here +} + +void loop() +{ + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play (melody1); + } + if (button.released()) { + piezo.play (melody2); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MosFet/MosFet.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MosFet/MosFet.ino new file mode 100644 index 00000000..a8102856 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/MosFet/MosFet.ino @@ -0,0 +1,28 @@ +/* +Write a signal to a MosFet transistor using a Potentiometer. + +created in Aug 2018 by D. Cuartielles +based on work by M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +MosFet mos(D3); //create the mos object on pin D3 +Potentiometer pot(A0); //create the pot object on pin A0 + +void setup() { + //nothing here +} + +void loop() +{ + int val = pot.read(); //assign to a "val" variable + //the potentiometer values + + mos.write(val); //assign the values to the mosfet + + delay(10); //rest for 10 milliseconds. +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PIR/PIR.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PIR/PIR.ino new file mode 100644 index 00000000..4ad2eda1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PIR/PIR.ino @@ -0,0 +1,36 @@ +/* + PIR + + Changes the behavior between on and off an LED when a PIR sensor is activated. + Assumes the use of a PIR sensor that needs no pull-up + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + */ + +// include the EduIntro library +#include + +PIR pir(D7); // creating the object 'pir' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + // check the state of the PIR sensor + // if you just want to detect the turn from not active to active + // use pir.activated() instead + if (pir.active() == HIGH) { + led.on(); + } + else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PIRStates/PIRStates.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PIRStates/PIRStates.ino new file mode 100644 index 00000000..ee893556 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PIRStates/PIRStates.ino @@ -0,0 +1,42 @@ +/* + PIRStates + + Test the different PIR methods: activated, deactivated, active, + readSwitch, hadActivity, and resetActivity + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +PIR pir(D7); + +void setup() +{ + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() +{ + if(pir.activated()) + Serial.println("activited"); + if(pir.active()) + Serial.println("still active"); + if(pir.deactivated()) { + Serial.println("deactivated"); + Serial.print("switch: "); + Serial.println(pir.readSwitch()); + } + if(!pir.activated() && pir.hadActivity()) { + Serial.print("had activity: "); + Serial.println(pir.hadActivity()); + pir.resetActivity(); + } + + delay(500); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PhysicalPixel/PhysicalPixel.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PhysicalPixel/PhysicalPixel.ino new file mode 100644 index 00000000..a33f0343 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/PhysicalPixel/PhysicalPixel.ino @@ -0,0 +1,52 @@ +/* +Physical Pixel + +An example of using the Arduino board to receive data from the computer. In +this case, the Arduino boards turns on an LED when it receives the character +'H', and turns off the LED when it receives the character 'L'. + +The data can be sent from the Arduino Serial Monitor, or another program like +Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. + +The circuit: +- LED connected from digital pin 13 to ground + + created in Aug 2018 by D. Cuartielles + based on work by D. Mellis (2006), T. Igoe and S. Fitzgerald (2011) + + This example code is in the public domain. + */ + +#include + +Led led(D13); + +int incomingByte; // a variable to read incoming serial data + +void setup() +{ + Serial.begin(9600); +} + + +void loop() { + // see if there's incoming serial data: + if (Serial.available() > 0) { + + // read the oldest byte in the serial buffer: + incomingByte = Serial.read(); + + // if it's a capital H (ASCII 72), turn on the LED: + if (incomingByte == 'H') { + led.on(); + } + // if it's an L (ASCII 76) turn off the LED: + if (incomingByte == 'L') { + led.off(); + } + + if (incomingByte == 'S') { + Serial.println(led.state(), DEC); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Potentiometer/Potentiometer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Potentiometer/Potentiometer.ino new file mode 100644 index 00000000..0b259803 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Potentiometer/Potentiometer.ino @@ -0,0 +1,40 @@ +/* + Read the value of a Potentiometer connected to A0, + then uses the results to write the brightness on + an LED connected on D10. Also prints the values + on the serial monitor. + + created in Aug 2018 by D. Cuartielles + based on work by T. Igoe (2008, 2010), D. Gomba (2010), F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +Led led(D10); // creating the object 'led' on pin D10 + +int brightnessVal = 0; // value read from the pot + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() { + // read the potentiometer's value: + brightnessVal = pot.read(); + + // set the led brightness + led.brightness(brightnessVal); + + // print the results to the serial monitor: + Serial.print("brightness = " ); + Serial.println(brightnessVal); + + + // wait 10 milliseconds before the next loop + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Relay/Relay.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Relay/Relay.ino new file mode 100644 index 00000000..5f4e0a3d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Relay/Relay.ino @@ -0,0 +1,35 @@ +/* + Relay + + Turns on and off a Relay connected to D10, when pressing a + Button attached to D7. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Button btn(D7); // creating the object 'button' on pin D7 + +Relay relay(D10); // creating the object 'relay' on pin D10 + +void setup() { + // nothing to add here +} + +void loop() +{ + // check the switch state + if(btn.readSwitch() == HIGH) { + relay.on(); + } + else{ + relay.off(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/RisingDecreasing/RisingDecreasing.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/RisingDecreasing/RisingDecreasing.ino new file mode 100644 index 00000000..af4d5515 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/RisingDecreasing/RisingDecreasing.ino @@ -0,0 +1,32 @@ +/* +Increasing & Decreasing + + this sketch shows how to use increasing() and + decreasing() on analog inputs. + + increasing() returns HIGH when values are rising, + decreasing() is HIGH when values are decreasing + + created in Aug 2018 by D. Cuartielles + based on work by M. Loglio (2013) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Thermistor therm(A0); // creating the object 'therm' on pin A0 + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + if (therm.increasing()) Serial.println("increasing"); + if (therm.decreasing()) Serial.println("decreasing"); + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Servo/Servo.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Servo/Servo.ino new file mode 100644 index 00000000..657bb702 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Servo/Servo.ino @@ -0,0 +1,29 @@ +/* + Servo + + Makes a Servo change angle after some time. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + servo.write(90); + delay (1000); // wait for a second + servo.write(0); + delay (1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoButton/ServoButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoButton/ServoButton.ino new file mode 100644 index 00000000..4b5ff78a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoButton/ServoButton.ino @@ -0,0 +1,34 @@ +/* + Makes a Servo change angle when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + // check the switchState of the button + // each time it is pressed, it toggles the servo's position + // when LOW, light should go on + if (button.readSwitch() == LOW) { + servo.write(90); + } + else { + servo.write(0); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoKnob/ServoKnob.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoKnob/ServoKnob.ino new file mode 100644 index 00000000..9eef4a1e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoKnob/ServoKnob.ino @@ -0,0 +1,45 @@ +/* + Makes a Servo change angle when turning a potentiometer. + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + + based on https://www.arduino.cc/en/tutorial/knob + */ + +// include the EduIntro library +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + +int potVal = 0; // value read from the pot +int angleVal = 0; // value of the angle to set the servo + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + // read the potentiometer's value: + potVal = pot.read(); + + // map the data from the sensor (0..1023) to + // one the servo can take (0..180) + angleVal = map(potVal, 0, 1023, 0, 180); + + // set the led brightness + servo.write(angleVal); + + // print the results to the serial monitor: + Serial.print("angle = " ); + Serial.println(angleVal); + + + // wait 100 milliseconds before the next loop + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoKnobContinuous/ServoKnobContinuous.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoKnobContinuous/ServoKnobContinuous.ino new file mode 100644 index 00000000..ab949b08 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/ServoKnobContinuous/ServoKnobContinuous.ino @@ -0,0 +1,54 @@ +/* + Makes a Continuous Servo change speed when turning a potentiometer. + Prints the different motor states to the serial port. + + This example code is in the public domain. + + created in Feb 2019 by D. Cuartielles + + based on https://www.arduino.cc/en/tutorial/knob + */ + +// include the EduIntro library +#include + +Potentiometer pot(A0); // creating the object 'pot' on pin A0 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + +int potVal = 0; // value read from the pot +int angleVal = 0; // value of the angle to set the servo + +void setup() { + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + // read the potentiometer's value: + potVal = pot.read(); + + // map the data from the sensor (0..1023) to + // one the servo can take (0..180) + angleVal = map(potVal, 0, 1023, 0, 180); + + // set the led brightness + servo.write(angleVal); + + // Signify it different events for the motor + if (angleVal == 90) + Serial.println("Motor Stop"); + if (angleVal <= 1) + Serial.println("Motor Max clockwise"); + if (angleVal >= 179) + Serial.println("Motor Max counter clockwise"); + + // print the results to the serial monitor: + Serial.print("angle = " ); + Serial.println(angleVal); + + + // wait 100 milliseconds before the next loop + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Thermistor/Thermistor.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Thermistor/Thermistor.ino new file mode 100644 index 00000000..46479676 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/by_topic/Thermistor/Thermistor.ino @@ -0,0 +1,42 @@ +/* +Thermistor hooked up on pin A0. + +Three values are displayed on the Serial Monitor every second: +- the value between 0 and 1023 that represent the Analog Input reading +- the temperature expressed in Celsius degrees +- the temperature expressed in Fahrenheit dedegrees + +created in Aug 2018 by D. Cuartielles +based on work by F. Vanzati (2011) and M. Loglio (2013) + +This example code is in the public domain. +*/ + +// include the EduIntro library +#include + +Thermistor therm(A0); // creating the object 'therm' on pin A0 + +float C, F; // temperature readings are returned in float format + +void setup() +{ + // initialize serial communications at 9600 bps + Serial.begin(9600); +} + +void loop() +{ + C = therm.readCelsius(); // Reading the temperature in Celsius degrees and store in the C variable + F = therm.readFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable + + // Print the collected data in a row on the Serial Monitor + Serial.print("Analog reading: "); // Reading the analog value from the thermistor + Serial.print(therm.read()); + Serial.print("\tC: "); + Serial.print(C); + Serial.print("\tF: "); + Serial.println(F); + + delay(1000); // Wait one second before get another temperature reading +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/cardboardKeyboard/ButtonStatesKeyboard/ButtonStatesKeyboard.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/cardboardKeyboard/ButtonStatesKeyboard/ButtonStatesKeyboard.ino new file mode 100644 index 00000000..c2bbb63a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/cardboardKeyboard/ButtonStatesKeyboard/ButtonStatesKeyboard.ino @@ -0,0 +1,53 @@ +/* + ButtonStates for Cardboard Keyboard + + This example code is in the public domain. + + created in Jan 2019 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include +#include + +// reconfigure these pins to be the ones where you plug your wires +byte btnPins[] = {D9, D10, D11, D12}; + +// which are the keys you will be using ... ? +byte key[] = {'a', 'd', KEY_UP_ARROW, ' '}; + +// array to control the buttons +Button btn[] = { + Button(btnPins[0]), + Button(btnPins[1]), + Button(btnPins[2]), + Button(btnPins[3]), + }; + +void setup() +{ + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); + + // initialize the keyboard controller + Keyboard.begin(); +} + +void loop() +{ + for (int i; i < 4; i ++) { + if (btn[i].pressed()) { + Serial.print("pressed pin: "); Serial.println(btnPins[i]); + Keyboard.press(key[i]); + } + if (btn[i].held()) + Serial.print("held pin: "); Serial.println(btnPins[i]); + if (btn[i].released()) { + Serial.print("released pin: "); Serial.println(btnPins[i]); + Serial.print("switch pin "); Serial.print(btnPins[i]); Serial.print(": "); + Serial.println(btn[i].readSwitch()); + Keyboard.release(key[i]); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Blink/Blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Blink/Blink.ino new file mode 100644 index 00000000..3547b4e2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Blink/Blink.ino @@ -0,0 +1,28 @@ +/* + Blink + + based on Blink, Arduino's "Hello World!" + Turns on an LED on for one second, then off for one second, repeatedly. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +Led led(D10); // creating the object 'led' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + led.on(); // set the LED on + delay(1000); // wait for a second + led.off(); // set the LED off + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Button/Button.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Button/Button.ino new file mode 100644 index 00000000..10529c94 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Button/Button.ino @@ -0,0 +1,37 @@ +/* + Button + + Changes the behavior between on and off an LED when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +Led led(D10); // creating the object 'led' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + // check the switchState of the button + // each time it is pressed, it toggles the LED + // when LOW, light should go on + if (button.readSwitch() == LOW) { + led.on(); + } + else { + led.off(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/ButtonStates/ButtonStates.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/ButtonStates/ButtonStates.ino new file mode 100644 index 00000000..5b198c62 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/ButtonStates/ButtonStates.ino @@ -0,0 +1,37 @@ +/* + ButtonStates + + Test the different Button methods: pressed, released, held + and getSwitch. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + based on work by F. Vanzati (2011) and M. Loglio (2013) +*/ + +#include + +Button btn(D7); + +void setup() +{ + // we are going to use the serial communication as a + // way to see on the PC what is happening on the Arduino + Serial.begin(9600); +} + +void loop() +{ + if(btn.pressed()) + Serial.println("pressed"); + if(btn.held()) + Serial.println("held"); + if(btn.released()) { + Serial.println("released"); + Serial.print("switch: "); + Serial.println(btn.readSwitch()); + } + + delay(50); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Empty/Empty.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Empty/Empty.ino new file mode 100644 index 00000000..9b72a6d4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Empty/Empty.ino @@ -0,0 +1,9 @@ +#include + +void setup() { + //Serial.begin(9600); +} + +void loop() { + +} \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Melody/Melody.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Melody/Melody.ino new file mode 100644 index 00000000..4dacb0e2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Melody/Melody.ino @@ -0,0 +1,36 @@ +/* + Melody + + Plays a song stored in an array, repeatedly. You should connect + a speaker to pin D10 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + piezo.play(melody); // play the song + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/MelodyButton/MelodyButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/MelodyButton/MelodyButton.ino new file mode 100644 index 00000000..bae0386c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/MelodyButton/MelodyButton.ino @@ -0,0 +1,40 @@ +/* + MelodyButton + + Plays a song stored in an array, when pressing a button. You should connect + a speaker to pin D10 and a button to pin D7 + + created in Aug 2018 by D. Cuartielles + + This example code is in the public domain. + */ + +// include the EduIntro library +#include + +// define the song as (note, duration) pairs +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int melody[] = { NOTE_C4, 4, + NOTE_G3, 8, + NOTE_G3, 8, + NOTE_A3, 4, + NOTE_G3, 4, + SILENCE, 4, + NOTE_B3, 4, + NOTE_C4, 4 }; + +Button button(D7); // creating the object 'button' on pin D7 + +Piezo piezo(D10); // creating the object 'piezo' on pin D10 + +void setup() { +//nothing here +} + +void loop() +{ + // if the button was just pressed, play melody + if (button.pressed()) { + piezo.play(melody); // play the song + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Servo/Servo.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Servo/Servo.ino new file mode 100644 index 00000000..657bb702 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/Servo/Servo.ino @@ -0,0 +1,29 @@ +/* + Servo + + Makes a Servo change angle after some time. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + servo.write(90); + delay (1000); // wait for a second + servo.write(0); + delay (1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/ServoButton/ServoButton.ino b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/ServoButton/ServoButton.ino new file mode 100644 index 00000000..4b5ff78a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/EduIntro/examples/courseware/workshop_1h/ServoButton/ServoButton.ino @@ -0,0 +1,34 @@ +/* + Makes a Servo change angle when pressing a Button. + + This example code is in the public domain. + + created in Aug 2018 by D. Cuartielles + + based on http://www.arduino.cc/en/Tutorial/Button + */ + +// include the EduIntro library +#include + +Button button(D7); // creating the object 'button' on pin D7 + +ServoMotor servo(D10); // creating the object 'servo' on pin D10 + + +void setup() { +//nothing here +} + +void loop() +{ + // check the switchState of the button + // each time it is pressed, it toggles the servo's position + // when LOW, light should go on + if (button.readSwitch() == LOW) { + servo.write(90); + } + else { + servo.write(0); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/LICENSE.txt b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/LICENSE.txt new file mode 100644 index 00000000..0e259d42 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/LICENSE.txt @@ -0,0 +1,121 @@ +Creative Commons Legal Code + +CC0 1.0 Universal + + CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE + LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN + ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS + INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES + REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS + PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM + THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED + HEREUNDER. + +Statement of Purpose + +The laws of most jurisdictions throughout the world automatically confer +exclusive Copyright and Related Rights (defined below) upon the creator +and subsequent owner(s) (each and all, an "owner") of an original work of +authorship and/or a database (each, a "Work"). + +Certain owners wish to permanently relinquish those rights to a Work for +the purpose of contributing to a commons of creative, cultural and +scientific works ("Commons") that the public can reliably and without fear +of later claims of infringement build upon, modify, incorporate in other +works, reuse and redistribute as freely as possible in any form whatsoever +and for any purposes, including without limitation commercial purposes. +These owners may contribute to the Commons to promote the ideal of a free +culture and the further production of creative, cultural and scientific +works, or to gain reputation or greater distribution for their Work in +part through the use and efforts of others. + +For these and/or other purposes and motivations, and without any +expectation of additional consideration or compensation, the person +associating CC0 with a Work (the "Affirmer"), to the extent that he or she +is an owner of Copyright and Related Rights in the Work, voluntarily +elects to apply CC0 to the Work and publicly distribute the Work under its +terms, with knowledge of his or her Copyright and Related Rights in the +Work and the meaning and intended legal effect of CC0 on those rights. + +1. Copyright and Related Rights. A Work made available under CC0 may be +protected by copyright and related or neighboring rights ("Copyright and +Related Rights"). Copyright and Related Rights include, but are not +limited to, the following: + + i. the right to reproduce, adapt, distribute, perform, display, + communicate, and translate a Work; + ii. moral rights retained by the original author(s) and/or performer(s); +iii. publicity and privacy rights pertaining to a person's image or + likeness depicted in a Work; + iv. rights protecting against unfair competition in regards to a Work, + subject to the limitations in paragraph 4(a), below; + v. rights protecting the extraction, dissemination, use and reuse of data + in a Work; + vi. database rights (such as those arising under Directive 96/9/EC of the + European Parliament and of the Council of 11 March 1996 on the legal + protection of databases, and under any national implementation + thereof, including any amended or successor version of such + directive); and +vii. other similar, equivalent or corresponding rights throughout the + world based on applicable law or treaty, and any national + implementations thereof. + +2. Waiver. To the greatest extent permitted by, but not in contravention +of, applicable law, Affirmer hereby overtly, fully, permanently, +irrevocably and unconditionally waives, abandons, and surrenders all of +Affirmer's Copyright and Related Rights and associated claims and causes +of action, whether now known or unknown (including existing as well as +future claims and causes of action), in the Work (i) in all territories +worldwide, (ii) for the maximum duration provided by applicable law or +treaty (including future time extensions), (iii) in any current or future +medium and for any number of copies, and (iv) for any purpose whatsoever, +including without limitation commercial, advertising or promotional +purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each +member of the public at large and to the detriment of Affirmer's heirs and +successors, fully intending that such Waiver shall not be subject to +revocation, rescission, cancellation, termination, or any other legal or +equitable action to disrupt the quiet enjoyment of the Work by the public +as contemplated by Affirmer's express Statement of Purpose. + +3. Public License Fallback. Should any part of the Waiver for any reason +be judged legally invalid or ineffective under applicable law, then the +Waiver shall be preserved to the maximum extent permitted taking into +account Affirmer's express Statement of Purpose. In addition, to the +extent the Waiver is so judged Affirmer hereby grants to each affected +person a royalty-free, non transferable, non sublicensable, non exclusive, +irrevocable and unconditional license to exercise Affirmer's Copyright and +Related Rights in the Work (i) in all territories worldwide, (ii) for the +maximum duration provided by applicable law or treaty (including future +time extensions), (iii) in any current or future medium and for any number +of copies, and (iv) for any purpose whatsoever, including without +limitation commercial, advertising or promotional purposes (the +"License"). The License shall be deemed effective as of the date CC0 was +applied by Affirmer to the Work. Should any part of the License for any +reason be judged legally invalid or ineffective under applicable law, such +partial invalidity or ineffectiveness shall not invalidate the remainder +of the License, and in such case Affirmer hereby affirms that he or she +will not (i) exercise any of his or her remaining Copyright and Related +Rights in the Work or (ii) assert any associated claims and causes of +action with respect to the Work, in either case contrary to Affirmer's +express Statement of Purpose. + +4. Limitations and Disclaimers. + + a. No trademark or patent rights held by Affirmer are waived, abandoned, + surrendered, licensed or otherwise affected by this document. + b. Affirmer offers the Work as-is and makes no representations or + warranties of any kind concerning the Work, express, implied, + statutory or otherwise, including without limitation warranties of + title, merchantability, fitness for a particular purpose, non + infringement, or the absence of latent or other defects, accuracy, or + the present or absence of errors, whether or not discoverable, all to + the greatest extent permissible under applicable law. + c. Affirmer disclaims responsibility for clearing rights of other persons + that may apply to the Work or any use thereof, including without + limitation any person's Copyright and Related Rights in the Work. + Further, Affirmer disclaims responsibility for obtaining any necessary + consents, permissions or other rights required for any use of the + Work. + d. Affirmer understands and acknowledges that Creative Commons is not a + party to this document and has no duty or obligation with respect to + this CC0 or use of the Work. diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/README.adoc b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/README.adoc new file mode 100644 index 00000000..9ec43131 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/README.adoc @@ -0,0 +1,13 @@ += Built-in Examples = + +image:https://github.com/arduino/arduino-examples/workflows/Compile%20Examples/badge.svg["Compile Examples Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Compile+Examples"] +image:https://github.com/arduino/arduino-examples/workflows/Code%20Formatting%20Check/badge.svg["Code Formatting Check Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Code+Formatting+Check"] +image:https://github.com/arduino/arduino-examples/workflows/Spell%20Check/badge.svg["Spell Check Status", link="https://github.com/arduino/arduino-examples/actions?workflow=Spell+Check"] + +These are the example Arduino sketches built in to the Arduino IDE. + +They were originally hosted at `https://github.com/arduino/Arduino/tree/master/build/shared` + +For more information about these examples please visit their tutorials at + +https://www.arduino.cc/en/Tutorial/BuiltInExamples + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino new file mode 100644 index 00000000..10e67ec3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino @@ -0,0 +1,26 @@ +/* + AnalogReadSerial + + Reads an analog input on pin 0, prints the result to the Serial Monitor. + Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). + Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogReadSerial +*/ + +// the setup routine runs once when you press reset: +void setup() { + // initialize serial communication at 9600 bits per second: + Serial.begin(9600); +} + +// the loop routine runs over and over again forever: +void loop() { + // read the input on analog pin 0: + int sensorValue = analogRead(A0); + // print out the value you read: + Serial.println(sensorValue); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/BareMinimum/BareMinimum.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/BareMinimum/BareMinimum.ino new file mode 100644 index 00000000..95c2b6eb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/BareMinimum/BareMinimum.ino @@ -0,0 +1,9 @@ +void setup() { + // put your setup code here, to run once: + +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/Blink/Blink.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/Blink/Blink.ino new file mode 100644 index 00000000..9abb8f51 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/Blink/Blink.ino @@ -0,0 +1,37 @@ +/* + Blink + + Turns an LED on for one second, then off for one second, repeatedly. + + Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO + it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to + the correct LED pin independent of which board is used. + If you want to know what pin the on-board LED is connected to on your Arduino + model, check the Technical Specs of your board at: + https://www.arduino.cc/en/Main/Products + + modified 8 May 2014 + by Scott Fitzgerald + modified 2 Sep 2016 + by Arturo Guadalupi + modified 8 Sep 2016 + by Colby Newman + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Blink +*/ + +// the setup function runs once when you press reset or power the board +void setup() { + // initialize digital pin LED_BUILTIN as an output. + pinMode(LED_BUILTIN, OUTPUT); +} + +// the loop function runs over and over again forever +void loop() { + digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) + delay(1000); // wait for a second + digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW + delay(1000); // wait for a second +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino new file mode 100644 index 00000000..49389fe9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino @@ -0,0 +1,29 @@ +/* + DigitalReadSerial + + Reads a digital input on pin 2, prints the result to the Serial Monitor + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/DigitalReadSerial +*/ + +// digital pin 2 has a pushbutton attached to it. Give it a name: +int pushButton = 2; + +// the setup routine runs once when you press reset: +void setup() { + // initialize serial communication at 9600 bits per second: + Serial.begin(9600); + // make the pushbutton's pin an input: + pinMode(pushButton, INPUT); +} + +// the loop routine runs over and over again forever: +void loop() { + // read the input pin: + int buttonState = digitalRead(pushButton); + // print out the state of the button: + Serial.println(buttonState); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/Fade/Fade.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/Fade/Fade.ino new file mode 100644 index 00000000..e598b038 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/Fade/Fade.ino @@ -0,0 +1,40 @@ +/* + Fade + + This example shows how to fade an LED on pin 9 using the analogWrite() + function. + + The analogWrite() function uses PWM, so if you want to change the pin you're + using, be sure to use another PWM capable pin. On most Arduino, the PWM pins + are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11. + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fade +*/ + +int led = 9; // the PWM pin the LED is attached to +int brightness = 0; // how bright the LED is +int fadeAmount = 5; // how many points to fade the LED by + +// the setup routine runs once when you press reset: +void setup() { + // declare pin 9 to be an output: + pinMode(led, OUTPUT); +} + +// the loop routine runs over and over again forever: +void loop() { + // set the brightness of pin 9: + analogWrite(led, brightness); + + // change the brightness for next time through the loop: + brightness = brightness + fadeAmount; + + // reverse the direction of the fading at the ends of the fade: + if (brightness <= 0 || brightness >= 255) { + fadeAmount = -fadeAmount; + } + // wait for 30 milliseconds to see the dimming effect + delay(30); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino new file mode 100644 index 00000000..26e91e52 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/01.Basics/ReadAnalogVoltage/ReadAnalogVoltage.ino @@ -0,0 +1,27 @@ +/* + ReadAnalogVoltage + + Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor. + Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu). + Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground. + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ReadAnalogVoltage +*/ + +// the setup routine runs once when you press reset: +void setup() { + // initialize serial communication at 9600 bits per second: + Serial.begin(9600); +} + +// the loop routine runs over and over again forever: +void loop() { + // read the input on analog pin 0: + int sensorValue = analogRead(A0); + // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): + float voltage = sensorValue * (5.0 / 1023.0); + // print out the value you read: + Serial.println(voltage); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino new file mode 100644 index 00000000..ac47087a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/BlinkWithoutDelay/BlinkWithoutDelay.ino @@ -0,0 +1,71 @@ +/* + Blink without Delay + + Turns on and off a light emitting diode (LED) connected to a digital pin, + without using the delay() function. This means that other code can run at the + same time without being interrupted by the LED code. + + The circuit: + - Use the onboard LED. + - Note: Most Arduinos have an on-board LED you can control. On the UNO, MEGA + and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN + is set to the correct LED pin independent of which board is used. + If you want to know what pin the on-board LED is connected to on your + Arduino model, check the Technical Specs of your board at: + https://www.arduino.cc/en/Main/Products + + created 2005 + by David A. Mellis + modified 8 Feb 2010 + by Paul Stoffregen + modified 11 Nov 2013 + by Scott Fitzgerald + modified 9 Jan 2017 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/BlinkWithoutDelay +*/ + +// constants won't change. Used here to set a pin number: +const int ledPin = LED_BUILTIN;// the number of the LED pin + +// Variables will change: +int ledState = LOW; // ledState used to set the LED + +// Generally, you should use "unsigned long" for variables that hold time +// The value will quickly become too large for an int to store +unsigned long previousMillis = 0; // will store last time LED was updated + +// constants won't change: +const long interval = 1000; // interval at which to blink (milliseconds) + +void setup() { + // set the digital pin as output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // here is where you'd put code that needs to be running all the time. + + // check to see if it's time to blink the LED; that is, if the difference + // between the current time and last time you blinked the LED is bigger than + // the interval at which you want to blink the LED. + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis >= interval) { + // save the last time you blinked the LED + previousMillis = currentMillis; + + // if the LED is off turn it on and vice-versa: + if (ledState == LOW) { + ledState = HIGH; + } else { + ledState = LOW; + } + + // set the LED with the ledState of the variable: + digitalWrite(ledPin, ledState); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/Button/Button.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/Button/Button.ino new file mode 100644 index 00000000..7732bc84 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/Button/Button.ino @@ -0,0 +1,51 @@ +/* + Button + + Turns on and off a light emitting diode(LED) connected to digital pin 13, + when pressing a pushbutton attached to pin 2. + + The circuit: + - LED attached from pin 13 to ground through 220 ohm resistor + - pushbutton attached to pin 2 from +5V + - 10K resistor attached to pin 2 from ground + + - Note: on most Arduinos there is already an LED on the board + attached to pin 13. + + created 2005 + by DojoDave + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button +*/ + +// constants won't change. They're used here to set pin numbers: +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin + +// variables will change: +int buttonState = 0; // variable for reading the pushbutton status + +void setup() { + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize the pushbutton pin as an input: + pinMode(buttonPin, INPUT); +} + +void loop() { + // read the state of the pushbutton value: + buttonState = digitalRead(buttonPin); + + // check if the pushbutton is pressed. If it is, the buttonState is HIGH: + if (buttonState == HIGH) { + // turn LED on: + digitalWrite(ledPin, HIGH); + } else { + // turn LED off: + digitalWrite(ledPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/Debounce/Debounce.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/Debounce/Debounce.ino new file mode 100644 index 00000000..42cd1dc9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/Debounce/Debounce.ino @@ -0,0 +1,86 @@ +/* + Debounce + + Each time the input pin goes from LOW to HIGH (e.g. because of a push-button + press), the output pin is toggled from LOW to HIGH or HIGH to LOW. There's a + minimum delay between toggles to debounce the circuit (i.e. to ignore noise). + + The circuit: + - LED attached from pin 13 to ground through 220 ohm resistor + - pushbutton attached from pin 2 to +5V + - 10 kilohm resistor attached from pin 2 to ground + + - Note: On most Arduino boards, there is already an LED on the board connected + to pin 13, so you don't need any extra components for this example. + + created 21 Nov 2006 + by David A. Mellis + modified 30 Aug 2011 + by Limor Fried + modified 28 Dec 2012 + by Mike Walters + modified 30 Aug 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Debounce +*/ + +// constants won't change. They're used here to set pin numbers: +const int buttonPin = 2; // the number of the pushbutton pin +const int ledPin = 13; // the number of the LED pin + +// Variables will change: +int ledState = HIGH; // the current state of the output pin +int buttonState; // the current reading from the input pin +int lastButtonState = LOW; // the previous reading from the input pin + +// the following variables are unsigned longs because the time, measured in +// milliseconds, will quickly become a bigger number than can be stored in an int. +unsigned long lastDebounceTime = 0; // the last time the output pin was toggled +unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers + +void setup() { + pinMode(buttonPin, INPUT); + pinMode(ledPin, OUTPUT); + + // set initial LED state + digitalWrite(ledPin, ledState); +} + +void loop() { + // read the state of the switch into a local variable: + int reading = digitalRead(buttonPin); + + // check to see if you just pressed the button + // (i.e. the input went from LOW to HIGH), and you've waited long enough + // since the last press to ignore any noise: + + // If the switch changed, due to noise or pressing: + if (reading != lastButtonState) { + // reset the debouncing timer + lastDebounceTime = millis(); + } + + if ((millis() - lastDebounceTime) > debounceDelay) { + // whatever the reading is at, it's been there for longer than the debounce + // delay, so take it as the actual current state: + + // if the button state has changed: + if (reading != buttonState) { + buttonState = reading; + + // only toggle the LED if the new button state is HIGH + if (buttonState == HIGH) { + ledState = !ledState; + } + } + } + + // set the LED: + digitalWrite(ledPin, ledState); + + // save the reading. Next time through the loop, it'll be the lastButtonState: + lastButtonState = reading; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino new file mode 100644 index 00000000..16863a0a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/DigitalInputPullup/DigitalInputPullup.ino @@ -0,0 +1,46 @@ +/* + Input Pull-up Serial + + This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a digital + input on pin 2 and prints the results to the Serial Monitor. + + The circuit: + - momentary switch attached from pin 2 to ground + - built-in LED on pin 13 + + Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal + 20K-ohm resistor is pulled to 5V. This configuration causes the input to read + HIGH when the switch is open, and LOW when it is closed. + + created 14 Mar 2012 + by Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/InputPullupSerial +*/ + +void setup() { + //start serial connection + Serial.begin(9600); + //configure pin 2 as an input and enable the internal pull-up resistor + pinMode(2, INPUT_PULLUP); + pinMode(13, OUTPUT); + +} + +void loop() { + //read the pushbutton value into a variable + int sensorVal = digitalRead(2); + //print out the value of the pushbutton + Serial.println(sensorVal); + + // Keep in mind the pull-up means the pushbutton's logic is inverted. It goes + // HIGH when it's open, and LOW when it's pressed. Turn on pin 13 when the + // button's pressed, and off when it's not: + if (sensorVal == HIGH) { + digitalWrite(13, LOW); + } else { + digitalWrite(13, HIGH); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino new file mode 100644 index 00000000..d3b21222 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/StateChangeDetection/StateChangeDetection.ino @@ -0,0 +1,79 @@ +/* + State change detection (edge detection) + + Often, you don't need to know the state of a digital input all the time, but + you just need to know when the input changes from one state to another. + For example, you want to know when a button goes from OFF to ON. This is called + state change detection, or edge detection. + + This example shows how to detect when a button or button changes from off to on + and on to off. + + The circuit: + - pushbutton attached to pin 2 from +5V + - 10 kilohm resistor attached to pin 2 from ground + - LED attached from pin 13 to ground through 220 ohm resistor (or use the + built-in LED on most Arduino boards) + + created 27 Sep 2005 + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StateChangeDetection +*/ + +// this constant won't change: +const int buttonPin = 2; // the pin that the pushbutton is attached to +const int ledPin = 13; // the pin that the LED is attached to + +// Variables will change: +int buttonPushCounter = 0; // counter for the number of button presses +int buttonState = 0; // current state of the button +int lastButtonState = 0; // previous state of the button + +void setup() { + // initialize the button pin as a input: + pinMode(buttonPin, INPUT); + // initialize the LED as an output: + pinMode(ledPin, OUTPUT); + // initialize serial communication: + Serial.begin(9600); +} + + +void loop() { + // read the pushbutton input pin: + buttonState = digitalRead(buttonPin); + + // compare the buttonState to its previous state + if (buttonState != lastButtonState) { + // if the state has changed, increment the counter + if (buttonState == HIGH) { + // if the current state is HIGH then the button went from off to on: + buttonPushCounter++; + Serial.println("on"); + Serial.print("number of button pushes: "); + Serial.println(buttonPushCounter); + } else { + // if the current state is LOW then the button went from on to off: + Serial.println("off"); + } + // Delay a little bit to avoid bouncing + delay(50); + } + // save the current state as the last state, for next time through the loop + lastButtonState = buttonState; + + + // turns on the LED every four button pushes by checking the modulo of the + // button push counter. the modulo function gives you the remainder of the + // division of two numbers: + if (buttonPushCounter % 4 == 0) { + digitalWrite(ledPin, HIGH); + } else { + digitalWrite(ledPin, LOW); + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/pitches.h new file mode 100644 index 00000000..70b06bc1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/toneKeyboard.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/toneKeyboard.ino new file mode 100644 index 00000000..99e1cc54 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneKeyboard/toneKeyboard.ino @@ -0,0 +1,44 @@ +/* + Keyboard + + Plays a pitch that changes based on a changing analog input + + circuit: + - three force-sensing resistors from +5V to analog in 0 through 5 + - three 10 kilohm resistors from analog in 0 through 5 to ground + - 8 ohm speaker on digital pin 8 + + created 21 Jan 2010 + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneKeyboard +*/ + +#include "pitches.h" + +const int threshold = 10; // minimum reading of the sensors that generates a note + +// notes to play, corresponding to the 3 sensors: +int notes[] = { + NOTE_A4, NOTE_B4, NOTE_C3 +}; + +void setup() { + +} + +void loop() { + for (int thisSensor = 0; thisSensor < 3; thisSensor++) { + // get a sensor reading: + int sensorReading = analogRead(thisSensor); + + // if the sensor is pressed hard enough: + if (sensorReading > threshold) { + // play the note corresponding to this sensor: + tone(8, notes[thisSensor], 20); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/pitches.h b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/pitches.h new file mode 100644 index 00000000..70b06bc1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/pitches.h @@ -0,0 +1,95 @@ +/************************************************* + Public Constants + *************************************************/ + +#define NOTE_B0 31 +#define NOTE_C1 33 +#define NOTE_CS1 35 +#define NOTE_D1 37 +#define NOTE_DS1 39 +#define NOTE_E1 41 +#define NOTE_F1 44 +#define NOTE_FS1 46 +#define NOTE_G1 49 +#define NOTE_GS1 52 +#define NOTE_A1 55 +#define NOTE_AS1 58 +#define NOTE_B1 62 +#define NOTE_C2 65 +#define NOTE_CS2 69 +#define NOTE_D2 73 +#define NOTE_DS2 78 +#define NOTE_E2 82 +#define NOTE_F2 87 +#define NOTE_FS2 93 +#define NOTE_G2 98 +#define NOTE_GS2 104 +#define NOTE_A2 110 +#define NOTE_AS2 117 +#define NOTE_B2 123 +#define NOTE_C3 131 +#define NOTE_CS3 139 +#define NOTE_D3 147 +#define NOTE_DS3 156 +#define NOTE_E3 165 +#define NOTE_F3 175 +#define NOTE_FS3 185 +#define NOTE_G3 196 +#define NOTE_GS3 208 +#define NOTE_A3 220 +#define NOTE_AS3 233 +#define NOTE_B3 247 +#define NOTE_C4 262 +#define NOTE_CS4 277 +#define NOTE_D4 294 +#define NOTE_DS4 311 +#define NOTE_E4 330 +#define NOTE_F4 349 +#define NOTE_FS4 370 +#define NOTE_G4 392 +#define NOTE_GS4 415 +#define NOTE_A4 440 +#define NOTE_AS4 466 +#define NOTE_B4 494 +#define NOTE_C5 523 +#define NOTE_CS5 554 +#define NOTE_D5 587 +#define NOTE_DS5 622 +#define NOTE_E5 659 +#define NOTE_F5 698 +#define NOTE_FS5 740 +#define NOTE_G5 784 +#define NOTE_GS5 831 +#define NOTE_A5 880 +#define NOTE_AS5 932 +#define NOTE_B5 988 +#define NOTE_C6 1047 +#define NOTE_CS6 1109 +#define NOTE_D6 1175 +#define NOTE_DS6 1245 +#define NOTE_E6 1319 +#define NOTE_F6 1397 +#define NOTE_FS6 1480 +#define NOTE_G6 1568 +#define NOTE_GS6 1661 +#define NOTE_A6 1760 +#define NOTE_AS6 1865 +#define NOTE_B6 1976 +#define NOTE_C7 2093 +#define NOTE_CS7 2217 +#define NOTE_D7 2349 +#define NOTE_DS7 2489 +#define NOTE_E7 2637 +#define NOTE_F7 2794 +#define NOTE_FS7 2960 +#define NOTE_G7 3136 +#define NOTE_GS7 3322 +#define NOTE_A7 3520 +#define NOTE_AS7 3729 +#define NOTE_B7 3951 +#define NOTE_C8 4186 +#define NOTE_CS8 4435 +#define NOTE_D8 4699 +#define NOTE_DS8 4978 + + diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/toneMelody.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/toneMelody.ino new file mode 100644 index 00000000..22022dce --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMelody/toneMelody.ino @@ -0,0 +1,50 @@ +/* + Melody + + Plays a melody + + circuit: + - 8 ohm speaker on digital pin 8 + + created 21 Jan 2010 + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMelody +*/ + +#include "pitches.h" + +// notes in the melody: +int melody[] = { + NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 +}; + +// note durations: 4 = quarter note, 8 = eighth note, etc.: +int noteDurations[] = { + 4, 8, 8, 4, 4, 4, 4, 4 +}; + +void setup() { + // iterate over the notes of the melody: + for (int thisNote = 0; thisNote < 8; thisNote++) { + + // to calculate the note duration, take one second divided by the note type. + //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. + int noteDuration = 1000 / noteDurations[thisNote]; + tone(8, melody[thisNote], noteDuration); + + // to distinguish the notes, set a minimum time between them. + // the note's duration + 30% seems to work well: + int pauseBetweenNotes = noteDuration * 1.30; + delay(pauseBetweenNotes); + // stop the tone playing: + noTone(8); + } +} + +void loop() { + // no need to repeat the melody. +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMultiple/toneMultiple.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMultiple/toneMultiple.ino new file mode 100644 index 00000000..63a60203 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/toneMultiple/toneMultiple.ino @@ -0,0 +1,40 @@ +/* + Multiple tone player + + Plays multiple tones on multiple pins in sequence + + circuit: + - three 8 ohm speakers on digital pins 6, 7, and 8 + + created 8 Mar 2010 + by Tom Igoe + based on a snippet from Greg Borenstein + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/toneMultiple +*/ + +void setup() { + +} + +void loop() { + // turn off tone function for pin 8: + noTone(8); + // play a note on pin 6 for 200 ms: + tone(6, 440, 200); + delay(200); + + // turn off tone function for pin 6: + noTone(6); + // play a note on pin 7 for 500 ms: + tone(7, 494, 500); + delay(500); + + // turn off tone function for pin 7: + noTone(7); + // play a note on pin 8 for 300 ms: + tone(8, 523, 300); + delay(300); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino new file mode 100644 index 00000000..3171cfca --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/02.Digital/tonePitchFollower/tonePitchFollower.ino @@ -0,0 +1,39 @@ +/* + Pitch follower + + Plays a pitch that changes based on a changing analog input + + circuit: + - 8 ohm speaker on digital pin 9 + - photoresistor on analog 0 to 5V + - 4.7 kilohm resistor on analog 0 to ground + + created 21 Jan 2010 + modified 31 May 2012 + by Tom Igoe, with suggestion from Michael Flynn + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/tonePitchFollower +*/ + +void setup() { + // initialize serial communications (for debugging only): + Serial.begin(9600); +} + +void loop() { + // read the sensor: + int sensorReading = analogRead(A0); + // print the sensor reading so you know its range + Serial.println(sensorReading); + // map the analog input range (in this case, 400 - 1000 from the photoresistor) + // to the output pitch range (120 - 1500Hz) + // change the minimum and maximum input numbers below depending on the range + // your sensor's giving: + int thisPitch = map(sensorReading, 400, 1000, 120, 1500); + + // play the pitch: + tone(9, thisPitch, 10); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino new file mode 100644 index 00000000..4033ca02 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogInOutSerial/AnalogInOutSerial.ino @@ -0,0 +1,52 @@ +/* + Analog input, analog output, serial output + + Reads an analog input pin, maps the result to a range from 0 to 255 and uses + the result to set the pulse width modulation (PWM) of an output pin. + Also prints the results to the Serial Monitor. + + The circuit: + - potentiometer connected to analog pin 0. + Center pin of the potentiometer goes to the analog pin. + side pins of the potentiometer go to +5V and ground + - LED connected from digital pin 9 to ground through 220 ohm resistor + + created 29 Dec. 2008 + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInOutSerial +*/ + +// These constants won't change. They're used to give names to the pins used: +const int analogInPin = A0; // Analog input pin that the potentiometer is attached to +const int analogOutPin = 9; // Analog output pin that the LED is attached to + +int sensorValue = 0; // value read from the pot +int outputValue = 0; // value output to the PWM (analog out) + +void setup() { + // initialize serial communications at 9600 bps: + Serial.begin(9600); +} + +void loop() { + // read the analog in value: + sensorValue = analogRead(analogInPin); + // map it to the range of the analog out: + outputValue = map(sensorValue, 0, 1023, 0, 255); + // change the analog out value: + analogWrite(analogOutPin, outputValue); + + // print the results to the Serial Monitor: + Serial.print("sensor = "); + Serial.print(sensorValue); + Serial.print("\t output = "); + Serial.println(outputValue); + + // wait 2 milliseconds before the next loop for the analog-to-digital + // converter to settle after the last reading: + delay(2); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogInput/AnalogInput.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogInput/AnalogInput.ino new file mode 100644 index 00000000..9a1bbddb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogInput/AnalogInput.ino @@ -0,0 +1,50 @@ +/* + Analog Input + + Demonstrates analog input by reading an analog sensor on analog pin 0 and + turning on and off a light emitting diode(LED) connected to digital pin 13. + The amount of time the LED will be on and off depends on the value obtained + by analogRead(). + + The circuit: + - potentiometer + center pin of the potentiometer to the analog input 0 + one side pin (either one) to ground + the other side pin to +5V + - LED + anode (long leg) attached to digital output 13 through 220 ohm resistor + cathode (short leg) attached to ground + + - Note: because most Arduinos have a built-in LED attached to pin 13 on the + board, the LED is optional. + + created by David Cuartielles + modified 30 Aug 2011 + By Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogInput +*/ + +int sensorPin = A0; // select the input pin for the potentiometer +int ledPin = 13; // select the pin for the LED +int sensorValue = 0; // variable to store the value coming from the sensor + +void setup() { + // declare the ledPin as an OUTPUT: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // read the value from the sensor: + sensorValue = analogRead(sensorPin); + // turn the ledPin on + digitalWrite(ledPin, HIGH); + // stop the program for milliseconds: + delay(sensorValue); + // turn the ledPin off: + digitalWrite(ledPin, LOW); + // stop the program for for milliseconds: + delay(sensorValue); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino new file mode 100644 index 00000000..9d938d27 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/AnalogWriteMega/AnalogWriteMega.ino @@ -0,0 +1,46 @@ +/* + Mega analogWrite() test + + This sketch fades LEDs up and down one at a time on digital pins 2 through 13. + This sketch was written for the Arduino Mega, and will not work on other boards. + + The circuit: + - LEDs attached from pins 2 through 13 to ground. + + created 8 Feb 2009 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/AnalogWriteMega +*/ + +// These constants won't change. They're used to give names to the pins used: +const int lowestPin = 2; +const int highestPin = 13; + + +void setup() { + // set pins 2 through 13 as outputs: + for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // iterate over the pins: + for (int thisPin = lowestPin; thisPin <= highestPin; thisPin++) { + // fade the LED on thisPin from off to brightest: + for (int brightness = 0; brightness < 255; brightness++) { + analogWrite(thisPin, brightness); + delay(2); + } + // fade the LED on thisPin from brightest to off: + for (int brightness = 255; brightness >= 0; brightness--) { + analogWrite(thisPin, brightness); + delay(2); + } + // pause between LEDs: + delay(100); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Calibration/Calibration.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Calibration/Calibration.ino new file mode 100644 index 00000000..ba5cf703 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Calibration/Calibration.ino @@ -0,0 +1,75 @@ +/* + Calibration + + Demonstrates one technique for calibrating sensor input. The sensor readings + during the first five seconds of the sketch execution define the minimum and + maximum of expected values attached to the sensor pin. + + The sensor minimum and maximum initial values may seem backwards. Initially, + you set the minimum high and listen for anything lower, saving it as the new + minimum. Likewise, you set the maximum low and listen for anything higher as + the new maximum. + + The circuit: + - analog sensor (potentiometer will do) attached to analog input 0 + - LED attached from digital pin 9 to ground through 220 ohm resistor + + created 29 Oct 2008 + by David A Mellis + modified 30 Aug 2011 + by Tom Igoe + modified 07 Apr 2017 + by Zachary J. Fields + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Calibration +*/ + +// These constants won't change: +const int sensorPin = A0; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to + +// variables: +int sensorValue = 0; // the sensor value +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value + + +void setup() { + // turn on LED to signal the start of the calibration period: + pinMode(13, OUTPUT); + digitalWrite(13, HIGH); + + // calibrate during the first five seconds + while (millis() < 5000) { + sensorValue = analogRead(sensorPin); + + // record the maximum sensor value + if (sensorValue > sensorMax) { + sensorMax = sensorValue; + } + + // record the minimum sensor value + if (sensorValue < sensorMin) { + sensorMin = sensorValue; + } + } + + // signal the end of the calibration period + digitalWrite(13, LOW); +} + +void loop() { + // read the sensor: + sensorValue = analogRead(sensorPin); + + // in case the sensor value is outside the range seen during calibration + sensorValue = constrain(sensorValue, sensorMin, sensorMax); + + // apply the calibration to the sensor reading + sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); + + // fade the LED using the calibrated value: + analogWrite(ledPin, sensorValue); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Fading/Fading.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Fading/Fading.ino new file mode 100644 index 00000000..da694e57 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Fading/Fading.ino @@ -0,0 +1,41 @@ +/* + Fading + + This example shows how to fade an LED using the analogWrite() function. + + The circuit: + - LED attached from digital pin 9 to ground through 220 ohm resistor. + + created 1 Nov 2008 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Fading +*/ + +int ledPin = 9; // LED connected to digital pin 9 + +void setup() { + // nothing happens in setup +} + +void loop() { + // fade in from min to max in increments of 5 points: + for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) { + // sets the value (range from 0 to 255): + analogWrite(ledPin, fadeValue); + // wait for 30 milliseconds to see the dimming effect + delay(30); + } + + // fade out from max to min in increments of 5 points: + for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) { + // sets the value (range from 0 to 255): + analogWrite(ledPin, fadeValue); + // wait for 30 milliseconds to see the dimming effect + delay(30); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Smoothing/Smoothing.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Smoothing/Smoothing.ino new file mode 100644 index 00000000..eece3393 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/03.Analog/Smoothing/Smoothing.ino @@ -0,0 +1,64 @@ +/* + Smoothing + + Reads repeatedly from an analog input, calculating a running average and + printing it to the computer. Keeps ten readings in an array and continually + averages them. + + The circuit: + - analog sensor (potentiometer will do) attached to analog input 0 + + created 22 Apr 2007 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Smoothing +*/ + +// Define the number of samples to keep track of. The higher the number, the +// more the readings will be smoothed, but the slower the output will respond to +// the input. Using a constant rather than a normal variable lets us use this +// value to determine the size of the readings array. +const int numReadings = 10; + +int readings[numReadings]; // the readings from the analog input +int readIndex = 0; // the index of the current reading +int total = 0; // the running total +int average = 0; // the average + +int inputPin = A0; + +void setup() { + // initialize serial communication with computer: + Serial.begin(9600); + // initialize all the readings to 0: + for (int thisReading = 0; thisReading < numReadings; thisReading++) { + readings[thisReading] = 0; + } +} + +void loop() { + // subtract the last reading: + total = total - readings[readIndex]; + // read from the sensor: + readings[readIndex] = analogRead(inputPin); + // add the reading to the total: + total = total + readings[readIndex]; + // advance to the next position in the array: + readIndex = readIndex + 1; + + // if we're at the end of the array... + if (readIndex >= numReadings) { + // ...wrap around to the beginning: + readIndex = 0; + } + + // calculate the average: + average = total / numReadings; + // send it to the computer as ASCII digits + Serial.println(average); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/ASCIITable/ASCIITable.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/ASCIITable/ASCIITable.ino new file mode 100644 index 00000000..f3d4bd06 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/ASCIITable/ASCIITable.ino @@ -0,0 +1,77 @@ +/* + ASCII table + + Prints out byte values in all possible formats: + - as raw binary values + - as ASCII-encoded decimal, hex, octal, and binary values + + For more on ASCII, see http://www.asciitable.com and http://en.wikipedia.org/wiki/ASCII + + The circuit: No external hardware needed. + + created 2006 + by Nicholas Zambetti + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ASCIITable +*/ + +void setup() { + //Initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // prints title with ending line break + Serial.println("ASCII Table ~ Character Map"); +} + +// first visible ASCIIcharacter '!' is number 33: +int thisByte = 33; +// you can also write ASCII characters in single quotes. +// for example, '!' is the same as 33, so you could also use this: +// int thisByte = '!'; + +void loop() { + // prints value unaltered, i.e. the raw binary version of the byte. + // The Serial Monitor interprets all bytes as ASCII, so 33, the first number, + // will show up as '!' + Serial.write(thisByte); + + Serial.print(", dec: "); + // prints value as string as an ASCII-encoded decimal (base 10). + // Decimal is the default format for Serial.print() and Serial.println(), + // so no modifier is needed: + Serial.print(thisByte); + // But you can declare the modifier for decimal if you want to. + // this also works if you uncomment it: + + // Serial.print(thisByte, DEC); + + + Serial.print(", hex: "); + // prints value as string in hexadecimal (base 16): + Serial.print(thisByte, HEX); + + Serial.print(", oct: "); + // prints value as string in octal (base 8); + Serial.print(thisByte, OCT); + + Serial.print(", bin: "); + // prints value as string in binary (base 2) also prints ending line break: + Serial.println(thisByte, BIN); + + // if printed last visible character '~' or 126, stop: + if (thisByte == 126) { // you could also use if (thisByte == '~') { + // This loop loops forever and does nothing + while (true) { + continue; + } + } + // go on to the next character + thisByte++; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Dimmer/Dimmer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Dimmer/Dimmer.ino new file mode 100644 index 00000000..fc121a06 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Dimmer/Dimmer.ino @@ -0,0 +1,114 @@ +/* + Dimmer + + Demonstrates sending data from the computer to the Arduino board, in this case + to control the brightness of an LED. The data is sent in individual bytes, + each of which ranges from 0 to 255. Arduino reads these bytes and uses them to + set the brightness of the LED. + + The circuit: + - LED attached from digital pin 9 to ground through 220 ohm resistor. + - Serial connection to Processing, Max/MSP, or another serial application + + created 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe and Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Dimmer +*/ + +const int ledPin = 9; // the pin that the LED is attached to + +void setup() { + // initialize the serial communication: + Serial.begin(9600); + // initialize the ledPin as an output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + byte brightness; + + // check if data has been sent from the computer: + if (Serial.available()) { + // read the most recent byte (which will be from 0 to 255): + brightness = Serial.read(); + // set the brightness of the LED: + analogWrite(ledPin, brightness); + } +} + +/* Processing code for this example + + // Dimmer - sends bytes over a serial port + + // by David A. Mellis + // This example code is in the public domain. + + import processing.serial.*; + Serial port; + + void setup() { + size(256, 150); + + println("Available serial ports:"); + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // Uses the first port in this list (number 0). Change this to select the port + // corresponding to your Arduino board. The last parameter (e.g. 9600) is the + // speed of the communication. It has to correspond to the value passed to + // Serial.begin() in your Arduino sketch. + port = new Serial(this, Serial.list()[0], 9600); + + // If you know the name of the port used by the Arduino board, you can specify + // it directly like this. + //port = new Serial(this, "COM1", 9600); + } + + void draw() { + // draw a gradient from black to white + for (int i = 0; i < 256; i++) { + stroke(i); + line(i, 0, i, 150); + } + + // write the current X-position of the mouse to the serial port as + // a single byte + port.write(mouseX); + } + +*/ + +/* Max/MSP v5 patch for this example + + ----------begin_max5_patcher---------- + 1008.3ocuXszaiaCD9r8uhA5rqAeHIa0aAMaAVf1S6hdoYQAsDiL6JQZHQ2M + YWr+2KeX4vjnjXKKkKhhiGQ9MeyCNz+X9rnMp63sQvuB+MLa1OlOalSjUvrC + ymEUytKuh05TKJWUWyk5nE9eSyuS6jesvHu4F4MxOuUzB6X57sPKWVzBLXiP + xZtGj6q2vafaaT0.BzJfjj.p8ZPukazsQvpfcpFs8mXR3plh8BoBxURIOWyK + rxspZ0YI.eTCEh5Vqp+wGtFXZMKe6CZc3yWZwTdCmYW.BBkdiby8v0r+ST.W + sD9SdUkn8FYspPbqvnBNFtZWiUyLmleJWo0vuKzeuj2vpJLaWA7YiE7wREui + FpDFDp1KcbAFcP5sJoVxp4NB5Jq40ougIDxJt1wo3GDZHiNocKhiIExx+owv + AdOEAksDs.RRrOoww1Arc.9RvN2J9tamwjkcqknvAE0l+8WnjHqreNet8whK + z6mukIK4d+Xknv3jstvJs8EirMMhxsZIusET25jXbX8xczIl5xPVxhPcTGFu + xNDu9rXtUCg37g9Q8Yc+EuofIYmg8QdkPCrOnXsaHwYs3rWx9PGsO+pqueG2 + uNQBqWFh1X7qQG+3.VHcHrfO1nyR2TlqpTM9MDsLKNCQVz6KO.+Sfc5j1Ykj + jzkn2jwNDRP7LVb3d9LtoWBAOnvB92Le6yRmZ4UF7YpQhiFi7A5Ka8zXhKdA + 4r9TRGG7V4COiSbAJKdXrWNhhF0hNUh7uBa4Mba0l7JUK+omjDMwkSn95Izr + TOwkdp7W.oPRmNRQsiKeu4j3CkfVgt.NYPEYqMGvvJ48vIlPiyzrIuZskWIS + xGJPcmPiWOfLodybH3wjPbMYwlbFIMNHPHFOtLBNaLSa9sGk1TxMzCX5KTa6 + WIH2ocxSdngM0QPqFRxyPHFsprrhGc9Gy9xoBjz0NWdR2yW9DUa2F85jG2v9 + FgTO4Q8qiC7fzzQNpmNpsY3BrYPVJBMJQ1uVmoItRhw9NrVGO3NMNzYZ+zS7 + 3WTvTOnUydG5kHMKLqAOjTe7fN2bGSxOZDkMrBrGQ9J1gONBEy0k4gVo8qHc + cxmfxVihWz6a3yqY9NazzUYkua9UnynadOtogW.JfsVGRVNEbWF8I+eHtcwJ + +wLXqZeSdWLo+FQF6731Tva0BISKTx.cLwmgJsUTTvkg1YsnXmxDge.CDR7x + D6YmX6fMznaF7kdczmJXwm.XSOOrdoHhNA7GMiZYLZZR.+4lconMaJP6JOZ8 + ftCs1YWHZI3o.sIXezX5ihMSuXzZtk3ai1mXRSczoCS32hAydeyXNEu5SHyS + xqZqbd3ZLdera1iPqYxOm++v7SUSz + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Graph/Graph.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Graph/Graph.ino new file mode 100644 index 00000000..b50ca372 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Graph/Graph.ino @@ -0,0 +1,152 @@ +/* + Graph + + A simple example of communication from the Arduino board to the computer: The + value of analog input 0 is sent out the serial port. We call this "serial" + communication because the connection appears to both the Arduino and the + computer as a serial port, even though it may actually use a USB cable. Bytes + are sent one after another (serially) from the Arduino to the computer. + + You can use the Arduino Serial Monitor to view the sent data, or it can be + read by Processing, PD, Max/MSP, or any other program capable of reading data + from a serial port. The Processing code below graphs the data received so you + can see the value of the analog input changing over time. + + The circuit: + - any analog input sensor attached to analog in pin 0 + + created 2006 + by David A. Mellis + modified 9 Apr 2012 + by Tom Igoe and Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Graph +*/ + +void setup() { + // initialize the serial communication: + Serial.begin(9600); +} + +void loop() { + // send the value of analog input 0: + Serial.println(analogRead(A0)); + // wait a bit for the analog-to-digital converter to stabilize after the last + // reading: + delay(2); +} + +/* Processing code for this example + + // Graphing sketch + + // This program takes ASCII-encoded strings from the serial port at 9600 baud + // and graphs them. It expects values in the range 0 to 1023, followed by a + // newline, or newline and carriage return + + // created 20 Apr 2005 + // updated 24 Nov 2015 + // by Tom Igoe + // This example code is in the public domain. + + import processing.serial.*; + + Serial myPort; // The serial port + int xPos = 1; // horizontal position of the graph + float inByte = 0; + + void setup () { + // set the window size: + size(400, 300); + + // List all the available serial ports + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // I know that the first port in the serial list on my Mac is always my + // Arduino, so I open Serial.list()[0]. + // Open whatever port is the one you're using. + myPort = new Serial(this, Serial.list()[0], 9600); + + // don't generate a serialEvent() unless you get a newline character: + myPort.bufferUntil('\n'); + + // set initial background: + background(0); + } + + void draw () { + // draw the line: + stroke(127, 34, 255); + line(xPos, height, xPos, height - inByte); + + // at the edge of the screen, go back to the beginning: + if (xPos >= width) { + xPos = 0; + background(0); + } else { + // increment the horizontal position: + xPos++; + } + } + + void serialEvent (Serial myPort) { + // get the ASCII string: + String inString = myPort.readStringUntil('\n'); + + if (inString != null) { + // trim off any whitespace: + inString = trim(inString); + // convert to an int and map to the screen height: + inByte = float(inString); + println(inByte); + inByte = map(inByte, 0, 1023, 0, height); + } + } + +*/ + +/* Max/MSP v5 patch for this example + + ----------begin_max5_patcher---------- + 1591.3oc0YszbaaCD9r7uBL5RalQUAO3CvdyS5zVenWZxs5NcfHgjPCIfJIT + RTxj+6AOHkoTDooroUs0AQPR73a+1cwtK3WtZxzEpOwqlB9YveAlL4KWMYh6 + Q1GLo99ISKXeJMmU451zTUQAWpmNy+NM+SZ2y+sR1l02JuU9t0hJvFlNcMPy + dOuBv.U5Rgb0LPpRpYBooM3529latArTUVvzZdFPtsXAuDrrTU.f.sBffXxL + vGE50lIHkUVJXq3fRtdaoDvjYfbgjujaFJSCzq4.tLaN.bi1tJefWpqbO0uz + 1IjIABoluxrJ1guxh2JfPO2B5zRNyBCLDFcqbwNvuv9fHCb8bvevyyEU2JKT + YhkBSWPAfq2TZ6YhqmuMUo0feUn+rYpY4YtY+cFw3lUJdCMYAapZqzwUHX8S + crjAd+SIOU6UBAwIygy.Q1+HAA1KH6EveWOFQlitUK92ehfal9kFhUxJ3tWc + sgpxadigWExbt1o7Ps5dk3yttivyg20W0VcSmg1G90qtx92rAZbH4ez.ruy1 + nhmaDPidE07J+5n2sg6E6oKXxUSmc20o6E3SPRDbrkXnPGUYE.i5nCNB9TxQ + jG.G0kCTZtH88f07Rt0ZMMWUw8VvbKVAaTk6GyoraPdZff7rQTejBN54lgyv + HE0Ft7AvIvvgvIwO23jBdUkYOuSvIFSiNcjFhiSsUBwsUCh1AgfNSBAeNDBZ + DIDqY.f8.YjfjV1HAn9XDTxyNFYatVTkKx3kcK9GraZpI5jv7GOx+Z37Xh82 + LSKHIDmDXaESoXRngIZQDKVkpxUkMCyXCQhcCK1z.G457gi3TzMz4RFD515F + G3bIQQwcP3SOF0zlkGhiCBQ1kOHHFFlXaEBQIQnCwv9QF1LxPZ.A4jR5cyQs + vbvHMJsLll01We+rE2LazX6zYmCraRrsPFwKg1ANBZFY.IAihr8Ox.aH0oAL + hB8nQVw0FSJiZeunOykbT6t3r.NP8.iL+bnwNiXuVMNJH9H9YCm89CFXPBER + bz422p8.O4dg6kRxdyjDqRwMIHTbT3QFLskxJ8tbmQK4tm0XGeZWF7wKKtYY + aTAF.XPNFaaQBinQMJ4QLF0aNHF0JtYuHSxoUZfZY6.UU2ejJTb8lQw8Fo5k + Rv6e2PI+fOM71o2ecY1VgTYdCSxxUqLokuYq9jYJi6lxPgD2NIPePLB0mwbG + YA9Rgxdiu1k5xiLlSU6JVnx6wzg3sYHwTesB8Z5D7RiGZpXyvDNJY.DQX3.H + hvmcUN4bP1yCkhpTle2P37jtBsKrLWcMScEmltOPv22ZfAqQAdKr9HzATQwZ + q18PrUGt6Tst2XMCRUfGuhXs6ccn23YloomMqcTiC5iMGPsHsHRWhWFlaenV + XcqwgCQiGGJzptyS2ZMODBz6fGza0bzmXBj7+DA94bvpR01MffAlueO7HwcI + pWCwmzJdvi9ILgflLAFmyXB6O7ML0YbD26lenmcGxjVsZUN+A6pUK7AtTrPg + M+eRYG0qD9j4I7eEbco8Xh6WcO.or9XDC6UCiewbXHkh6xm5LiPEkzpJDRTu + mEB44Fgz4NCtJvX.SM1vo2SlTCZGAe7GZu6ahdRyzFOhYZ+mbVVSYptBw.K1 + tboIkatIA7c1cTKD1u.honLYV04VkluHsXe0szv9pQCE9Ro3jaVB1o15pz2X + zYoBvO5KXCAe0LCYJybE8ZODf4fV8t9qW0zYxq.YJfTosj1bv0xc.SaC0+AV + 9V9L.KKyV3SyTcRtmzi6rO.O16USvts4B5xe9EymDvebK0eMfW6+NIsNlE2m + eqRyJ0utRq13+RjmqYKN1e.4d61jjdsauXe3.2p6jgi9hsNIv97CoyJ01xzl + c3ZhUCtSHx3UZgjoEJYqNY+hYs5zZQVFW19L3JDYaTlMLqAAt1G2yXlnFg9a + 53L1FJVcv.cOX0dh7mCVGCLce7GFcQwDdH5Ta3nyAS0pQbHxegr+tGIZORgM + RnMj5vGl1Fs16drnk7Tf1XOLgv1n0d2iEsCxR.eQsNOZ4FGF7whofgfI3kES + 1kCeOX5L2rifbdu0A9ae2X.V33B1Z+.Bj1FrP5iFrCYCG5EUWSG.hhunHJd. + HJ5hhnng3h9HPj4lud02.1bxGw. + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Midi/Midi.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Midi/Midi.ino new file mode 100644 index 00000000..851fa9b6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/Midi/Midi.ino @@ -0,0 +1,46 @@ +/* + MIDI note player + + This sketch shows how to use the serial transmit pin (pin 1) to send MIDI note data. + If this circuit is connected to a MIDI synth, it will play the notes + F#-0 (0x1E) to F#-5 (0x5A) in sequence. + + The circuit: + - digital in 1 connected to MIDI jack pin 5 + - MIDI jack pin 2 connected to ground + - MIDI jack pin 4 connected to +5V through 220 ohm resistor + - Attach a MIDI cable to the jack, then to a MIDI synth, and play music. + + created 13 Jun 2006 + modified 13 Aug 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Midi +*/ + +void setup() { + // Set MIDI baud rate: + Serial.begin(31250); +} + +void loop() { + // play notes from F#-0 (0x1E) to F#-5 (0x5A): + for (int note = 0x1E; note < 0x5A; note ++) { + //Note on channel 1 (0x90), some note value (note), middle velocity (0x45): + noteOn(0x90, note, 0x45); + delay(100); + //Note on channel 1 (0x90), some note value (note), silent velocity (0x00): + noteOn(0x90, note, 0x00); + delay(100); + } +} + +// plays a MIDI note. Doesn't check to see that cmd is greater than 127, or that +// data values are less than 127: +void noteOn(int cmd, int pitch, int velocity) { + Serial.write(cmd); + Serial.write(pitch); + Serial.write(velocity); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/MultiSerial/MultiSerial.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/MultiSerial/MultiSerial.ino new file mode 100644 index 00000000..20fc4417 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/MultiSerial/MultiSerial.ino @@ -0,0 +1,43 @@ +/* + Multiple Serial test + + Receives from the main serial port, sends to the others. + Receives from serial port 1, sends to the main serial (Serial 0). + + This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc. + + The circuit: + - any serial device attached to Serial port 1 + - Serial Monitor open on Serial port 0 + + created 30 Dec 2008 + modified 20 May 2012 + by Tom Igoe & Jed Roach + modified 27 Nov 2015 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/MultiSerialMega +*/ + + +void setup() { + // initialize both serial ports: + Serial.begin(9600); + Serial1.begin(9600); +} + +void loop() { + // read from port 1, send to port 0: + if (Serial1.available()) { + int inByte = Serial1.read(); + Serial.write(inByte); + } + + // read from port 0, send to port 1: + if (Serial.available()) { + int inByte = Serial.read(); + Serial1.write(inByte); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino new file mode 100644 index 00000000..1582118e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/PhysicalPixel/PhysicalPixel.ino @@ -0,0 +1,161 @@ +/* + Physical Pixel + + An example of using the Arduino board to receive data from the computer. In + this case, the Arduino boards turns on an LED when it receives the character + 'H', and turns off the LED when it receives the character 'L'. + + The data can be sent from the Arduino Serial Monitor, or another program like + Processing (see code below), Flash (via a serial-net proxy), PD, or Max/MSP. + + The circuit: + - LED connected from digital pin 13 to ground through 220 ohm resistor + + created 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe and Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/PhysicalPixel +*/ + +const int ledPin = 13; // the pin that the LED is attached to +int incomingByte; // a variable to read incoming serial data into + +void setup() { + // initialize serial communication: + Serial.begin(9600); + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); +} + +void loop() { + // see if there's incoming serial data: + if (Serial.available() > 0) { + // read the oldest byte in the serial buffer: + incomingByte = Serial.read(); + // if it's a capital H (ASCII 72), turn on the LED: + if (incomingByte == 'H') { + digitalWrite(ledPin, HIGH); + } + // if it's an L (ASCII 76) turn off the LED: + if (incomingByte == 'L') { + digitalWrite(ledPin, LOW); + } + } +} + +/* Processing code for this example + + // Mouse over serial + + // Demonstrates how to send data to the Arduino I/O board, in order to turn ON + // a light if the mouse is over a square and turn it off if the mouse is not. + + // created 2003-4 + // based on examples by Casey Reas and Hernando Barragan + // modified 30 Aug 2011 + // by Tom Igoe + // This example code is in the public domain. + + import processing.serial.*; + + float boxX; + float boxY; + int boxSize = 20; + boolean mouseOverBox = false; + + Serial port; + + void setup() { + size(200, 200); + boxX = width / 2.0; + boxY = height / 2.0; + rectMode(RADIUS); + + // List all the available serial ports in the output pane. + // You will need to choose the port that the Arduino board is connected to + // from this list. The first port in the list is port #0 and the third port + // in the list is port #2. + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // Open the port that the Arduino board is connected to (in this case #0) + // Make sure to open the port at the same speed Arduino is using (9600bps) + port = new Serial(this, Serial.list()[0], 9600); + } + + void draw() { + background(0); + + // Test if the cursor is over the box + if (mouseX > boxX - boxSize && mouseX < boxX + boxSize && + mouseY > boxY - boxSize && mouseY < boxY + boxSize) { + mouseOverBox = true; + // draw a line around the box and change its color: + stroke(255); + fill(153); + // send an 'H' to indicate mouse is over square: + port.write('H'); + } + else { + // return the box to its inactive state: + stroke(153); + fill(153); + // send an 'L' to turn the LED off: + port.write('L'); + mouseOverBox = false; + } + + // Draw the box + rect(boxX, boxY, boxSize, boxSize); + } + +*/ + +/* Max/MSP version 5 patch to run with this example: + + ----------begin_max5_patcher---------- + 1672.3oc2ZszaaiCD9ryuBBebQVCQRYao8xhf1cQCPVfBzh8RRQ.sDsM2HSZ + HQmlzh9eu7gjsjsEk7y0oWjiHoHm4aluYHGlueUmtiDuPy5B9Cv8fNc99Uc5 + XZR2Pm726zcF4knDRlYXciDylQ4xtWa6SReQZZ+iSeMiEQR.ej8BM4A9C7OO + kkAlSjQSAYTdbFfvA27o2c6sfO.Doqd6NfXgDHmRUCKkolg4hT06BfbQJGH3 + 5Qd2e8d.QJIQSow5tzebZ7BFW.FIHow8.2JAQpVIIYByxo9KIMkSjL9D0BRT + sbGHZJIkDoZOSMuQT.8YZ5qpgGI3locF4IpQRzq2nDF+odZMIJkRjpEF44M3 + A9nWAum7LKFbSOv+PSRXYOvmIhYiYpg.8A2LOUOxPyH+TjPJA+MS9sIzTRRr + QP9rXF31IBZAHpVHkHrfaPRHLuUCzoj9GSoQRqIB52y6Z.tu8o4EX+fddfuj + +MrXiwPL5+9cXwrOVvkbxLpomazHbQO7EyX7DpzXYgkFdF6algCQpkX4XUlo + hA6oa7GWck9w0Gnmy6RXQOoQeCfWwlzsdnHLTq8n9PCHLv7Cxa6PAN3RCKjh + ISRVZ+sSl704Tqt0kocE9R8J+P+RJOZ4ysp6gN0vppBbOTEN8qp0YCq5bq47 + PUwfA5e766z7NbGMuncw7VgNRSyQhbnPMGrDsGaFSvKM5NcWoIVdZn44.eOi + 9DTRUT.7jDQzSTiF4UzXLc7tLGh4T9pwaFQkGUGIiOOkpBSJUwGsBd40krHQ + 9XEvwq2V6eLIhV6GuzP7uzzXBmzsXPSRYwBtVLp7s5lKVv6UN2VW7xRtYDbx + 7s7wRgHYDI8YVFaTBshkP49R3rYpH3RlUhTQmK5jMadJyF3cYaTNQMGSyhRE + IIUlJaOOukdhoOyhnekEKmZlqU3UkLrk7bpPrpztKBVUR1uorLddk6xIOqNt + lBOroRrNVFJGLrDxudpET4kzkstNp2lzuUHVMgk5TDZx9GWumnoQTbhXsEtF + tzCcM+z0QKXsngCUtTOEIN0SX2iHTTIIz968.Kf.uhfzUCUuAd3UKd.OKt.N + HTynxTQyjpQD9jlwEXeKQxfHCBahUge6RprSa2V4m3aYOMyaP6gah2Yf1zbD + jVwZVGFZHHxINFxpjr5CiTS9JiZn6e6nTlXQZTAFj6QCppQwzL0AxVtoi6WE + QXsANkEGWMEuwNvhmKTnat7A9RqLq6pXuEwY6xM5xRraoTiurj51J1vKLzFs + CvM7HI14Mpje6YRxHOSieTsJpvJORjxT1nERK6s7YTN7sr6rylNwf5zMiHI4 + meZ4rTYt2PpVettZERbjJ6PjfqN2loPSrUcusH01CegsGEE5467rnCdqT1ES + QxtCvFq.cvGz+BaAHXKzRSfP+2Jf.KCvj5ZLJRAhwi+SWHvPyN3vXiaPn6JR + 3eoA.0TkFhTvpsDMIrL20nAkCI4EoYfSHAuiPBdmJRyd.IynYYjIzMvjOTKf + 3DLvnvRLDLpWeEOYXMfAZqfQ0.qsnlUdmA33t8CNJ7MZEb.u7fiZHLYzDkJp + R7CqEVLGN75U+1JXxFUY.xEEBcRCqhOEkz2bENEWnh4pbh0wY25EefbD6EmW + UA6Ip8wFLyuFXx+Wrp8m6iff1B86W7bqJO9+mx8er4E3.abCLrYdA16sBuHx + vKT6BlpIGQIhL55W7oicf3ayv3ixQCm4aQuY1HZUPQWY+cASx2WZ3f1fICuz + vj5R5ZbM1y8gXYN4dIXaYGq4NhQvS5MmcDADy+S.j8CQ78vk7Q7gtPDX3kFh + 3NGaAsYBUAO.8N1U4WKycxbQdrWxJdXd10gNIO+hkUMmm.CZwknu7JbNUYUq + 0sOsTsI1QudDtjw0t+xZ85wWZd80tMCiiMADNX4UzrcSeK23su87IANqmA7j + tiRzoXi2YRh67ldAk79gPmTe3YKuoY0qdEDV3X8xylCJMTN45JIakB7uY8XW + uVr3PO8wWwEoTW8lsfraX7ZqzZDDXCRqNkztHsGCYpIDDAOqxDpMVUMKcOrp + 942acPvx2NPocMC1wQZ8glRn3myTykVaEUNLoEeJjVaAevA4EAZnsNgkeyO+ + 3rEZB7f0DTazDcQTNmdt8aACGi1QOWnMmd+.6YjMHH19OB5gKsMF877x8wsJ + hN97JSnSfLUXGUoj6ujWXd6Pk1SAC+Pkogm.tZ.1lX1qL.pe6PE11DPeMMZ2 + .P0K+3peBt3NskC + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino new file mode 100644 index 00000000..bbd395b0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/ReadASCIIString/ReadASCIIString.ino @@ -0,0 +1,69 @@ +/* + Reading a serial ASCII-encoded string. + + This sketch demonstrates the Serial parseInt() function. + It looks for an ASCII string of comma-separated values. + It parses them into ints, and uses those to fade an RGB LED. + + Circuit: Common-Cathode RGB LED wired like so: + - red anode: digital pin 3 through 220 ohm resistor + - green anode: digital pin 5 through 220 ohm resistor + - blue anode: digital pin 6 through 220 ohm resistor + - cathode: GND + + created 13 Apr 2012 + by Tom Igoe + modified 14 Mar 2016 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ReadASCIIString +*/ + +// pins for the LEDs: +const int redPin = 3; +const int greenPin = 5; +const int bluePin = 6; + +void setup() { + // initialize serial: + Serial.begin(9600); + // make the pins outputs: + pinMode(redPin, OUTPUT); + pinMode(greenPin, OUTPUT); + pinMode(bluePin, OUTPUT); + +} + +void loop() { + // if there's any serial available, read it: + while (Serial.available() > 0) { + + // look for the next valid integer in the incoming serial stream: + int red = Serial.parseInt(); + // do it again: + int green = Serial.parseInt(); + // do it again: + int blue = Serial.parseInt(); + + // look for the newline. That's the end of your sentence: + if (Serial.read() == '\n') { + // constrain the values to 0 - 255 and invert + // if you're using a common-cathode LED, just use "constrain(color, 0, 255);" + red = 255 - constrain(red, 0, 255); + green = 255 - constrain(green, 0, 255); + blue = 255 - constrain(blue, 0, 255); + + // fade the red, green, and blue legs of the LED: + analogWrite(redPin, red); + analogWrite(greenPin, green); + analogWrite(bluePin, blue); + + // print the three numbers in one string as hexadecimal: + Serial.print(red, HEX); + Serial.print(green, HEX); + Serial.println(blue, HEX); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino new file mode 100644 index 00000000..6fb0a606 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponse/SerialCallResponse.ino @@ -0,0 +1,237 @@ +/* + Serial Call and Response + Language: Wiring/Arduino + + This program sends an ASCII A (byte of value 65) on startup and repeats that + until it gets some data in. Then it waits for a byte in the serial port, and + sends three sensor values whenever it gets a byte in. + + The circuit: + - potentiometers attached to analog inputs 0 and 1 + - pushbutton attached to digital I/O 2 + + created 26 Sep 2005 + by Tom Igoe + modified 24 Apr 2012 + by Tom Igoe and Scott Fitzgerald + Thanks to Greg Shakar and Scott Fitzgerald for the improvements + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialCallResponse +*/ + +int firstSensor = 0; // first analog sensor +int secondSensor = 0; // second analog sensor +int thirdSensor = 0; // digital sensor +int inByte = 0; // incoming serial byte + +void setup() { + // start serial port at 9600 bps: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + pinMode(2, INPUT); // digital sensor is on digital pin 2 + establishContact(); // send a byte to establish contact until receiver responds +} + +void loop() { + // if we get a valid byte, read analog ins: + if (Serial.available() > 0) { + // get incoming byte: + inByte = Serial.read(); + // read first analog input, divide by 4 to make the range 0-255: + firstSensor = analogRead(A0) / 4; + // delay 10ms to let the ADC recover: + delay(10); + // read second analog input, divide by 4 to make the range 0-255: + secondSensor = analogRead(1) / 4; + // read switch, map it to 0 or 255L + thirdSensor = map(digitalRead(2), 0, 1, 0, 255); + // send sensor values: + Serial.write(firstSensor); + Serial.write(secondSensor); + Serial.write(thirdSensor); + } +} + +void establishContact() { + while (Serial.available() <= 0) { + Serial.print('A'); // send a capital A + delay(300); + } +} + +/* Processing sketch to run with this example: + + // This example code is in the public domain. + + import processing.serial.*; + + int bgcolor; // Background color + int fgcolor; // Fill color + Serial myPort; // The serial port + int[] serialInArray = new int[3]; // Where we'll put what we receive + int serialCount = 0; // A count of how many bytes we receive + int xpos, ypos; // Starting position of the ball + boolean firstContact = false; // Whether we've heard from the microcontroller + + void setup() { + size(256, 256); // Stage size + noStroke(); // No border on the next thing drawn + + // Set the starting position of the ball (middle of the stage) + xpos = width / 2; + ypos = height / 2; + + // Print a list of the serial ports for debugging purposes + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // I know that the first port in the serial list on my Mac is always my FTDI + // adaptor, so I open Serial.list()[0]. + // On Windows machines, this generally opens COM1. + // Open whatever port is the one you're using. + String portName = Serial.list()[0]; + myPort = new Serial(this, portName, 9600); + } + + void draw() { + background(bgcolor); + fill(fgcolor); + // Draw the shape + ellipse(xpos, ypos, 20, 20); + } + + void serialEvent(Serial myPort) { + // read a byte from the serial port: + int inByte = myPort.read(); + // if this is the first byte received, and it's an A, clear the serial + // buffer and note that you've had first contact from the microcontroller. + // Otherwise, add the incoming byte to the array: + if (firstContact == false) { + if (inByte == 'A') { + myPort.clear(); // clear the serial port buffer + firstContact = true; // you've had first contact from the microcontroller + myPort.write('A'); // ask for more + } + } + else { + // Add the latest byte from the serial port to array: + serialInArray[serialCount] = inByte; + serialCount++; + + // If we have 3 bytes: + if (serialCount > 2 ) { + xpos = serialInArray[0]; + ypos = serialInArray[1]; + fgcolor = serialInArray[2]; + + // print the values (for debugging purposes only): + println(xpos + "\t" + ypos + "\t" + fgcolor); + + // Send a capital A to request new sensor readings: + myPort.write('A'); + // Reset serialCount: + serialCount = 0; + } + } + } + +*/ + +/* Max/MSP version 5 patch to run with this example: + + ----------begin_max5_patcher---------- + 3908.3oc6ckziiaiE9b0+J3XjCIXpp.WzZNMURv.jCInQ5fYNjNngrDssRKK + 4nkp6JA4+973hrkrsjncKu0SRiXasQ83G+dKj7QV+4qtaxzrOxKlf9Zzuft6 + t+7U2cm7ThSbm936lrL3igIAExaaRJ+CYS+sI2qtTI+ikxSuBMKNojm+N3D4 + Aua5KkPwpuoUAkgKhSm+tbdXo5cQXVOhuGwrohuHD4WT7iXzupen3HY4BuqG + rH0kzrrzxzfkb4kdJONHo9JoUKiSS3kRgjt4jYUk0mkznPJh+CYgHewpSqty + xWVwUh3jIqkEYEfmqQEMr.ETbB+YddQbVZix+tIAqV03z203QDX4ukIKHm6W + ep3T0ovqOUN+435m2Rcx+5U0E+FTzVBh9xOsHXIh5YuADg1x4IYgumG0r3mj + shmFmtJmWvSKCJ0um0WNhOKnJo7c6GmZe8YAg7Ne381Rc2j44wQYoBgn0SJN + c8qCHH1RhQqJi7NRCVsmGt.pGUESCxE31zDdCV.PRyxRZeo0MU.WOHMdYPIu + LVIrT75BMd4p73zxVuHdZ.TFKJByyRRZUTpq77dtRDzZFx+PbT4BYY0DJgaO + dUcSvj0XTT7bdQY6yUFLun8YZo71jl0TIt042RYNLa4RfCTWfsznKWDWfJpl + tJHrbgV6t.AZInfzWP.4INpJHA8za91u+6QN1nk7hh.PpQwonxEbTAWzpilV + MimilkmsDtPbo3TPiUdY0pGa9ZShS4gYUJz1pwE1iwCpxbAgJI9DGGwWNzFT + ksLf3z7M0MybG6Hj1WngsD7VEXS8j5q7Wu5U0+39ir8QJJS5GMHdtRimL4m1 + 0e1EVX0YsE2YssINriYRoFRyWVMoRRUGQvnkmms3pnXDYHbBKMPpIOL5i1s8 + 3rMPwFcRCsGRyPH780.8HBnpWz.vlEQBWJ+0CSunehJSmJxiIZRtNGhhDYrU + jt3ZQyA2fHJhZDifXIQHUHH8oGYgOREI5nqHIzhFWUndPyBdB3VzHJGwUhkV + rgvRl2UCVNMHcd234lf1DN16HFEIdHt99A5hrp7v5WWMSBQZgMP.Tkwoqig8 + W1.Sn1f3h3nn1wLpBypPDzlJ7XinEGkLiMPloWOhrgR7dpZWJQV1faDy35Qj + MThMFkWFGsJChQPqrQp8iorV6Q28HBVF4nMVDJj7f1xyYACFScisg.ruLHOW + uMUS4Am4pI4PTnHi.6bi02HNzSYnDBe4cgAgKzRk1jc8PJLoH3Ydz6.Q.7K8 + tfxx73oUkJq1MGuCy5TpAi.POWZ3AenidLOOIaZPhdjZVW3sdk6LXEGzHb7p + Mfr7SEy3SXHyBSxJ3J2ncNNYVJsXG6Me10nj4cfCRFdTFjLo7q3SiCpjjEDM + .nvra.GN39.E2CDTHWXPo8.xzfqrHCHKnf5QUYUVdoZPUjCSC7LU8.XtTUXl + X8vr51GjwFGLC2AlMdLkU4RiaRrnmJuiudnDk0ZW+9p6TuKBe433JUCzp6fU + iOF0SUk2UQYUPNTEkiZubvKa1tsmgL5SCTXGHnnG0CceLpkpR9Rs28IUESWl + EwWNKfHlg.zj6Ee7S+nE8A+m9F7Cu40u9gMm+aRp3kYYkKd3GDOz5y+c7b96 + K9gfvuIK68uNO6g2vUUL80WxihCVFD9vlB30e2SOrmxUb527RZ3nZNrljGrR + 70vs1J9suWuZ3zaHVdG3RIJLgGj2Gfn6TcGcstEfvtH.hpFLlnBndjOLGQAI + z98BXc6yQxghmOn6gZqj0ShPOXhynLOjzCESt+XwE8TxrCvrdXo16rqnLgvb + HaFmbh29QD+K0DyNdjDwvzQL.NXpoMvoOBxkger0HwMRQbpbCh91fjjG9Idw + prTH9SzaSea5a.GQEPnnh43WNefMlsOgx18n.vgUNO.tKl7tDyI3iHzafJHZ + VVNedVEbGgYIY42i93prB0i7B7KT1LnnCiyAiinpBnsPV7OG.tYKfBsrJOkG + UG5aq26iJw6GyJ4eM5mEgEKaNQPMEBUp.t8.krplOVTlZdJAW27bjvGK7p2p + HQPgLOSJDYv4E9gQBYBjMUselRxDy+4WplIzm9JQAWOEmfb.E364B43CAwp5 + uRRDEv8hWXprjADMUOYpOg9.bVQpEfhKgGCnAnk.rghBJCdTVICA3sDvAhE5 + oU4hf67ea5zWPuILqrD8uiK+i477fjHIt9y.V88yy3uMsZUj7wnxGKNAdPx5 + fAZMErDZOcJU4M01WFQokix.pKa+JE1WacmnKFeYd7b.0PeIzB8Kk+5WIZpB + Ejt34KJeHgOCh4HK8Y3QiAkAfs8TRhhOkG7AAGQf0qxyfmQxa+PLb8Ex.2PS + 4BdO5GB9Hvg+cfJCMofAIMu9Qz+UPCjckqVJlEmyA8Bf.rC6.3hAEuG8TdTU + bZljQ0nr1ayIqmTwQYfyRGafZhur5vfuyMSqYNWmtAPwWHalDSuUgT0Bosh. + JpAR89Y6Ez5QEfPTQO4J0DHLInIliz8BZV2JfV3Bd36qsQwAVVXbr1BGXp6s + Sd5sSDruo74wofx.HxUgxQwTnMLqTXvRmiGh2PUZr5pBynKChjl6feNUjSRn + hEUfRPT1GfG9Ik4TQBm.hEZZ.bc38HjAMKGzDRijEm1ifx1dbgzQyKh6FZc3 + wOCkRJH+KUh0daWs6wzltWx1puXxlWW6NZWY2JiTBzzILRIANku02NourySM + VI1VJTvQZff32AJr+dS9e34QAoA6EGXlGFH9yk7yyQAlVd3SR94g+TxOu1sU + Flgd6ICI96LzazyPu1cgqsZ8r74SgF.65+efbMf4pGHT7lgHh30Sha3N5Ia. + oqjMf7nsuMwycf7iYDybiAAVr3eC.oTMjpzEr8GDRc9bFRGHYXDrzg.Tlx+q + NW8TY1IkzCfZ2IftkQstbB08HUezoDS+oFyI.cWIhWBaDiUo7qIrDO7f.L6n + AXqCmyNT9act.z+Iv.GR0uES0ZXfjdz.IczAxQOUR+zvRsUTigRxmyPYeNlj + yXv8Peef2ZFzuLzWPPeAE8ELzWXYlhe8WzAcUg+b1UkIoCLzIH60zwASGXau + a1Dq2nUY.sox4vng+m0nACePngC9lEMLZMBPodOxf+yx5d4uMCTHm3kJvIIG + jcLMedEQldkjpoBkQyjY1Hk.hmSY95Iwos8NDb9VSlIWOIntqgxryUjL6bCJ + y1lli5tWWxrQ7YmqGYlc6shK1iY2dr0wtNjYxgHyzaq0OznY235awCr8zSz6 + EGd1QNUKf.74dADTBbTbeotjpW95IolY0WpKYONY8M83Rx2MChx3fL+iG5Mm + tXpdmvXj8uTvaAL1WjbbarQD4Z6kXBpnm6a69oKV2PY9WY174IbC3CaRQ9iK + Q4sYGQpwdtZ5wFrc7n569.M83OOR5ydSB1ZcAWCxdbKuavz9LILxfD.wWO.W + Nq+Zu4Es+AP6s5p9jDWH8ET+c85+XbW0.N1nDCTD7U4DGc6ohnU019fS7kQ0 + o43luuOGjv5agHp0DT.CysOfgLR3xXlXTUKm16RivRsn3z0O6cl3YScAvtrb + hwekGB7BZuqESUzBJWmCvK7t9HF8Ts6cUAPoFWso3aP8ApWyJ3wqOPo2pJDC + BQ0NI0Pj8QCQ2r1L5vKaU5lDRYX7yRur1UYYZmJQ9iDHwN9dndB5n5ejflmm + UsBwLHnDkKXWRuAkb3NeuzqRstiQGP.fCQFdHNzaE.8u58Nz9svFE9SGIE1X + kv9Iwfl1BdNWjA7xcThsWCS847loyFD8pZq2E2F04lYULzBTDYhrFSDDJdjo + fisN2NUN26e4xRu51zD5ZseJ4HC63WyIX6jRqsp0jangBnK.Qlo58PCpWevt + ahzqK7fbKsdX6R64aao8LmWhBPh9jKVAPMzb5a2cV6opdWHneMmqMEmAGsPh + ieigIjV+4gF1GgbMNXg+NH44YaRYyd..S1ThHzKhFwwGRaWVITqyj9FvPqMT + d0pDuSqDrOGF.Uogf.juCFi9WAUkYR+rFPanDcPG8SbrtjyG03ZQ8m3AqC5H + NcUUoXSwVrqXKVcZu.5ZnkwIfIVdXVZTwAuTTUiYuxwjZDK6ZgnRtYV8tJmP + hEcuXgz2Goxyaiw35UkaWbpqtfzD02oUkkYqi.YQbZqIIWrIljFolsdmMKFR + wCJ2+DTn.9QlkOld+d9Qy9IJdpLfy05Ik2b8GsG9h8rdm1ZFx1FrmmlA2snw + qI9Mcdi2nr6q3Gc87nLawurbw1dda+tMyGJ9HaQmlkGwy6davisMgrkM65oz + eulfYCzG46am8tSDK144xV4cEvVMTRXq9CIX8+ALNWb6sttKNkiZetnbz+lx + cQnb1Nds2C0tvLNe14hwQtxYbxhqc17qHfamUcZZ3NYSWqjJuiDoizZ+ud2j + naRK4k3346IIVdR1kKiQjM39adMamvc6n+Xp36Yf3SIGh3uKbquqs1JksTII + kuJ7RrZSFb2Cn9j5a6DT8cMo0iczU+lsYaU8YNVh5k5uzJLU26ZcfuJE6XLY + 0mcRp9NTCp+L+Ap+in7Xf3b9jFQBLtIY06PbrGhcrU6N00Qlaf9N0+QPo9nS + P6qsI7aYNLSNOHpsAxis0ggnZLjYqyyFkdSqinVsPaqSDZaYBZ6c93uLCjGm + iCroJVLzU45iNE.pIUfs3TWb.0FejHp9uANr0GcJPTroFDNOHpkIweLnI1QT + dHl3P7LhOF3Ahd9rnvLwAMy5JSdNezGlsIsW9mW44r26js+alhxjlkdhN0YE + YqiH5MTeWo6D4Qm.ieLS7OynmuVGSbmbFUlnWWhiQlhOeN+Yl35bq.tGo9JR + cj8AVqdz7nSgVB9zNj.FTOU68o5d9KO5TUOGxVMw+jTO8T6wqD0hEiHsOJO5 + TTOMoS.zlqN0SpZjz6GcH05ylVM0jwuidlkmAif374ih5M5QPfccr8Hqifff + otN8pt3hUcaWu8nosBhwmD0Epw5KmoF.poxy4YHbnjqfPJqcM3Y2vun7nS.i + f3eETiqcRX2LR.4QmhZrkoCSGwzZrqKHrVR8caari+55d2caPqmq5n.ywe8Q + WrZL9fpwVXeaogMByE6y1SMdjk+gbavbN7fYvVtt1C2XwHJSzpk+tidUO25H + UB9onw9mlFQ10fhpZBaDatcMTTEGcJpwzqg92qqiVtM6Cu0IRQ0ndEdfCAqV + l0qYAUmPrctbxO4XCuPMa1asYzKDks1D52ZCne6Mednz9qW8+.vfqkDA + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino new file mode 100644 index 00000000..44b21553 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialCallResponseASCII/SerialCallResponseASCII.ino @@ -0,0 +1,223 @@ +/* + Serial Call and Response in ASCII + Language: Wiring/Arduino + + This program sends an ASCII A (byte of value 65) on startup and repeats that + until it gets some data in. Then it waits for a byte in the serial port, and + sends three ASCII-encoded, comma-separated sensor values, truncated by a + linefeed and carriage return, whenever it gets a byte in. + + The circuit: + - potentiometers attached to analog inputs 0 and 1 + - pushbutton attached to digital I/O 2 + + created 26 Sep 2005 + by Tom Igoe + modified 24 Apr 2012 + by Tom Igoe and Scott Fitzgerald + Thanks to Greg Shakar and Scott Fitzgerald for the improvements + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialCallResponseASCII +*/ + +int firstSensor = 0; // first analog sensor +int secondSensor = 0; // second analog sensor +int thirdSensor = 0; // digital sensor +int inByte = 0; // incoming serial byte + +void setup() { + // start serial port at 9600 bps and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + pinMode(2, INPUT); // digital sensor is on digital pin 2 + establishContact(); // send a byte to establish contact until receiver responds +} + +void loop() { + // if we get a valid byte, read analog ins: + if (Serial.available() > 0) { + // get incoming byte: + inByte = Serial.read(); + // read first analog input: + firstSensor = analogRead(A0); + // read second analog input: + secondSensor = analogRead(A1); + // read switch, map it to 0 or 255 + thirdSensor = map(digitalRead(2), 0, 1, 0, 255); + // send sensor values: + Serial.print(firstSensor); + Serial.print(","); + Serial.print(secondSensor); + Serial.print(","); + Serial.println(thirdSensor); + } +} + +void establishContact() { + while (Serial.available() <= 0) { + Serial.println("0,0,0"); // send an initial string + delay(300); + } +} + +/* Processing code to run with this example: + + // This example code is in the public domain. + + import processing.serial.*; // import the Processing serial library + Serial myPort; // The serial port + + float bgcolor; // Background color + float fgcolor; // Fill color + float xpos, ypos; // Starting position of the ball + + void setup() { + size(640, 480); + + // List all the available serial ports + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // I know that the first port in the serial list on my Mac is always my + // Arduino board, so I open Serial.list()[0]. + // Change the 0 to the appropriate number of the serial port that your + // microcontroller is attached to. + myPort = new Serial(this, Serial.list()[0], 9600); + + // read bytes into a buffer until you get a linefeed (ASCII 10): + myPort.bufferUntil('\n'); + + // draw with smooth edges: + smooth(); + } + + void draw() { + background(bgcolor); + fill(fgcolor); + // Draw the shape + ellipse(xpos, ypos, 20, 20); + } + + // serialEvent method is run automatically by the Processing applet whenever + // the buffer reaches the byte value set in the bufferUntil() + // method in the setup(): + + void serialEvent(Serial myPort) { + // read the serial buffer: + String myString = myPort.readStringUntil('\n'); + // if you got any bytes other than the linefeed: + myString = trim(myString); + + // split the string at the commas and convert the sections into integers: + int sensors[] = int(split(myString, ',')); + + // print out the values you got: + for (int sensorNum = 0; sensorNum < sensors.length; sensorNum++) { + print("Sensor " + sensorNum + ": " + sensors[sensorNum] + "\t"); + } + // add a linefeed after all the sensor values are printed: + println(); + if (sensors.length > 1) { + xpos = map(sensors[0], 0, 1023, 0, width); + ypos = map(sensors[1], 0, 1023, 0, height); + fgcolor = sensors[2]; + } + // send a byte to ask for more data: + myPort.write("A"); + } + +*/ + +/* Max/MSP version 5 patch to run with this example: + + ----------begin_max5_patcher---------- + 3640.3oc6cs0jZajE94Y9UzKkeHoVloTeSHkm1II0VkeHIthSs6C1obIjZ.E + KjHRhY7jT4+9d5KBj.jTCAXfoV6x.sj5VmyWet127ed6MCFm8EQw.z2f9.5l + a9yau4F0kjW3FS4aFLO3KgIAEpGaPX174hzxAC02qT7kR80mkkUHPAnBQdbP + BZQVdIZRd1bT4r3BDTmkU0YQPY3r3zoeJWDVpe2ttr6cFhvXt7KhyH8W26f9 + USkhiTulrw+1czQUszjrzxzf4B0sdP9dqtS5x4woIhREQiWewrkkUW0oViTD + +GpFASt2Qd0+51akeLzRPIU7DPXagIFnH.4653f9WAKKyxVHRQNcfDXlih2w + puvbdWHAlcTPBRKHg4x5mr74EBMINHV1+iFL.8qG.VMWTTDLUrs.TBH+zAvP + nTEhvvxun9pBd6FWH38DWH6DWv6ItbX.RKBOJ7XbP5ztvDesvhBLb6VTwcOg + DmiBjnXfiIrjjED0CpP490PEmtPExwQA5EGUVjK.CKQJqtcYl0nCMRAJi76D + Z7dQflCCVV1i+ENiTy3AwYaghEA4.KVJx+jHMXbhntJPceO3iBpPOPKtZqtU + jUoXtw28fkEimmEIlOI.3Q4iMT9wO+iLxc9O7sN28928t6Ve8uMYo.7EUN6t + ePVoUW+6E4hOW7CAgeaV1meWd1cuWnYLy8mKhhClGDd25F3ce+C2si1Ud42+ + bZ3IQJOXg7q96t80e50YvDjqHw7VvkRTXhHHuKEerRwmqfBFsS.g9h.HZN3X + hJf5Qd+xHZHgzc.mrqeYjbn4E84evfIDUjDtjNwD2iRHV6anmGdbmsfKxTTJ + dd93rjtBJ2U42foCwZDqKfYzKkrh4VgYIY4FxVRmN2646f8ck+xw7KrjzOlZ + ZYAVfdZgKlaWn29FzA8nfdR2quj.3ejflBJnKr.Dwpf13cZBm85P0rPj.rOB + 6fvztPFGkVI0SAPi5NKHmih7E8Ph2e35uOtYN6x6JEQtJVWpV7gRtm2dZy9W + +YMCxLHrEvAknQktDVdY7v82SFosgmSGHO56BRRt6mEEKxRKDnGd+2812h9X + 5GSeODOcAJ.M9YHHAfjPkyD0GIugn.Ht6bQ.7TTS8DoPtCQCQxWobX+jYPUJ + hPn3zgnx7kogphieFZ2j3TwDgH5dzaUscJ77kEnIY4hoYKglVYzcH5KKxJzu + qmgegxl.0MLNGBNDsr.5IUz0iAPZFE.0TtLOEdClQYrAAeORwW+XVo3aP+hb + DHUBCH.mfbEKfGOPyjQhGiCAdNUUBRcQjij4X.u5MZRDzHSyTDQFbcYdHHIM + AzlF1lnoLjKG8UZH5guV1vEkA4kKWbOPGPC9YgjNdJHVy+ZJQ1.Cq.FUWQpA + ke.8DbUwi.YEWBUCDhPyAXCEETFbuhICg9EIRiYnGVjKyt0+io.r+9vrxRz+ + Nt7OlJxCRhT35u.X0amlI9X5xEQppQwneJrLarPVU7JkGYWVHz2njevz1UoX + XkoEWOkxDWO9kXYocoTwuzF611zXJyimB3F5qf9nOT9qesryJTJ1EOcV4cIh + IPVWYoOBUMFTl.4sGRRzRT4AOIkRjn8h7LnNJI2mhg6OSk5JZrPJ4i9gfu.R + w+NHLCcpfAMij88n+qTPPMt4UTwj3bAnY.h.aIe.RiAEeF8Pdzx3zLkLUs1Z + mcmczah0FH4ZmpLcp.rVbX3d0zalKhSiKAxBZ9BU2zTP3uPobgL1Q.U0.kl+ + jcBZj1AMOpzsJYjdz0n53QXsfYrqELKblH7yUFoDfPVXbrwDGXqCjwjviT7a + rXZbpxOvxzXvpOnPH0GlTJMZog8l2UZJcdPjxjG7ywIYgeFULaInFDk8jpxZ + apvMA4cv9X.7.vaRRGFAcPYHMR0dF2BZC7wEJ2TOKeZnCRD+HzJo.OLWSW6r + qk2wfI6pGf.pdjC4rpfL2YeK8JYloVf93.ocJEvocv9wAcEiMQgBtl.lb0y9 + heKnvtGRs+iHOJHM3uaZbN1jDrhED4FfwfLPCEmH8jV.BB0Z+aF.Vkqc4apU + EIb9a5zAcGt5Rf3WdsNJ3R4PXDU0mouHzIca0MWO.KpQjT8oq1SIyqV3mP24 + ToxfHpdyOPNqgwoK.W.fxfRNtwsiDSBVlT9ociSMu+jfPQqUtk9paFLMONJK + URFMpq7xUuvOXF1HBuN6ndhzfE6nxPXQkKKFGjKQNyHtSptYYVVRyaspyBD3 + CRiA0YQYrlbgHdptY77E4wZk5UWSOf9yJByyRRZzT5673NtiNrvmhiJmoZq5 + fI73wKp5DFrBihhmBNxadsxfoEMuRiIbutfVcM4FWuyr.2bvrlNF5.3U+q9C + sKaa5jkMt70iSd8bC2ZbEFUuAa0DWqYF0tJ91p43649br2nZ2usLGuoxrnQq + 6TArNx+1CjRLPpVWf62Kj59ZFRa38Y6D0kRo8AnT8b0g0e4p8+f6.P4sBnaX + TqMmPsOdOcjG+dMtOmdzcgLdIGqjX0J+FAVrmSu.L8fAX19Ky1C.e1.z+IB2 + qpeCIUV+.I4fARxQGH0i.9ECVZrhZMTheMCkc4XRMsoCgbef2ZFjaF5MXzaH + n2PQugYmhe0WjdcU47Z1Ukhb6CwFISy2HNtcvtaNRWdshHNVgHcNMUlopRm4 + tJByyLXfI0UN6GM7eUiFTm8BMbctZQC8atOegDu6oveXrgpeaGnfaETvsBJN + 6AKuNsT4n+zRVXJtQd+ciEEYKyCq.8ptRTSdBRQrLNcUd5eXcjoa7fyhihZl + UrNQxBYZo5g.vpdt8klkJi1QyPvdH7UFMStbvYu8Amu1nY7ECMKGXBqnY2KH + Z18Jjl4aYNnEYiQWVzrUxytWNzL0VZ14xglI6isN5kAMi2GZlbYPyNma6FqC + aJRs9qEogO+ovfvYFxxjGV07cLnH3QQzm.R.BG7SAkk4wiWVpC2p9jwX23ka + 0zSz4M6e1QZY.8mljMNHwLURqZ9FuzslMk8ZJXtcMPeblVut1XYDhdMCpmjZ + 8BAqsU9DezKxJAa8Hmbbfi+wccuVv7c0qELrEHB+UAhHWzCfCbKPEyBki24Z + clythVwfkYSmlHrPdX8tC5v1iPb5ArPuOWc8NVrRZspq24UxhE0wBcAsMyt2 + 2LLuqvkKZRXjEq5CM6S3tq9Zm6HD+8Prm0F+jDWn1paUe+2ZuF259kxkiR5W + Qf6vzKBtMm+gFrMeuWsKW.6B61VyWOFjz0Zsmwza+.ikxQcAL3iDtbLWMTKm + OtyMEFcjWM9iu0rMa81D8kUl3v2ewcHWP5B2HX6kK7t7DL5fs6JVIrO0Z1l3 + bEpOP3zih9.gbspPzKDYbRVAQ7CFhtZsYzhW1ko0WEJcG3oAC0aRIyxKsUEI + +iDPwOLfp0uNA68MmtSUSmRuNb8d1ttWya7sVWf5Iwf.1LQtZUnqNvT1bS6z + E5o2vfqNSH5bufQbuZV09M.E04Mj8XBUiBqNGl5FSt3NGlZaGRpV6wc4kiWi + q0twaaORhul1jjsIi7cMjQlJJUaQuhR495nlfRQWRJXkrgmMGXWjKM4jdGJH + yovkl4HUetutzWuY5tjFHneGn77rtG3iJ92whCVJxKhBwgGtRaFIzabfNrRn + WThd9q24vsZjf9JvHwOKBhprFDmtXYIZ7xISjaO1GE4OK2V9yiS.qFhvrznh + 8cKyMZs7EVepT01FlCe0rIC0lUk6NX4N9syCyAE660+ovE9hyGqjaGurrLak + G0YwoMlFO4YMSZjd9DcWucsjUr1Yqgy8TluCY3N9Q8.+k0JCD3ZTS0CW8Qyb + s19nOxrgjw7VFU+3ooYviK66pCfimt8AAxHOOBkK+EajC2yayWtciMzgdvpM + NKORj29YyGcS4wFVlql0wcZTg1yw5wvMNiTpuUzpu.Y0miRlgO0w7wpZI2Em + SUBGayVM5eqU4C+rV4ZSPkvXqLJbAHlR3mKwT5ISL8+Kv0k.GWEKwpP3ewk3 + 7omKIN7EtDmp4ZtHk0BfatXgLhgasHgZrVYaY8AIO7fq8Pas1fFzjd4ibwpd + XO4GXOeOG+lcyasNh1R+wVx2yBxeTOT+wiZFYA0P48PNyiiVjAhJlNT4Qvpb + uj3aN2qYqJcBfSWhMbf+YCPcsfbNeTC2l9WNc+5eIlkST0RJgupzIn+kysgC + X6GGXnYpdYfP0GP6MKQXM3N1Ih6XVvcLuym7B0B5w8v.ahqBI49qJcJ.TaX. + N+xBP4NGHhhqYfkRNM9q1f3ZweqyYCQYdGCSZGQ5wBx47o.Ssw+CkcgQOmud + KZic4QKzCw+7ROm8nY2LfMsEDtdfeMKSn5Ev95IQhorcqJcBrzPsQUhRNe8M + 1X6lhOezC4Bidv1nKcFs8YimJ9n8RWZXiO7aSCxDRLdjd91qU5TnmXCeRvmR + 9jnm7b15RmJ9rO4Kr+IgO04BfczyOpqx9npzofOsIlaR8Mo0IUMR48i0mYly + lVMwlw6gbloGRezy4yKEw6BHBBWik.eRi3DNM5KDahS.SOE1EjmXl7Uyqo9T + AtQAO8fG3oLX3cZFxKh0FLNSRfDaoG74gdvW.ZDU9FMGSdFMBt+IQh.6eIvw + FujTkJREGKKcJ3X2WtXf7Ub1HywEqxh2tJnE.FcZhMByrcXQw1x+bOWJYjpy + lv8oq55aEHLcwD8hJjxbVU5EigcNtL7Ql76KVVp69Huhcb87vpoCkRYT+96v + Hd5Ay1rofMqm+FkLYvv0+GL3FkL6bLp21kL6QFNV8BNM48foWBV4zt1wXm5V + 4jkNEbL45dtNw13Iltmi9sAyY0S0l8BR+3yWjVXax7eOmKrp4m0QKIal6VYo + SAf5XQxSrCa5l0qk45k5kAzqEgMNgzkz9FmL5abpnu4IhNzZ+0s+OKCSg0. + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialEvent/SerialEvent.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialEvent/SerialEvent.ino new file mode 100644 index 00000000..831b98db --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialEvent/SerialEvent.ino @@ -0,0 +1,58 @@ +/* + Serial Event example + + When new serial data arrives, this sketch adds it to a String. + When a newline is received, the loop prints the string and clears it. + + A good test for this is to try it with a GPS receiver that sends out + NMEA 0183 sentences. + + NOTE: The serialEvent() feature is not available on the Leonardo, Micro, or + other ATmega32U4 based boards. + + created 9 May 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialEvent +*/ + +String inputString = ""; // a String to hold incoming data +bool stringComplete = false; // whether the string is complete + +void setup() { + // initialize serial: + Serial.begin(9600); + // reserve 200 bytes for the inputString: + inputString.reserve(200); +} + +void loop() { + // print the string when a newline arrives: + if (stringComplete) { + Serial.println(inputString); + // clear the string: + inputString = ""; + stringComplete = false; + } +} + +/* + SerialEvent occurs whenever a new data comes in the hardware serial RX. This + routine is run between each time loop() runs, so using delay inside loop can + delay response. Multiple bytes of data may be available. +*/ +void serialEvent() { + while (Serial.available()) { + // get the new byte: + char inChar = (char)Serial.read(); + // add it to the inputString: + inputString += inChar; + // if the incoming character is a newline, set a flag so the main loop can + // do something about it: + if (inChar == '\n') { + stringComplete = true; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino new file mode 100644 index 00000000..84824cf8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/SerialPassthrough/SerialPassthrough.ino @@ -0,0 +1,40 @@ +/* + SerialPassthrough sketch + + Some boards, like the Arduino 101, the MKR1000, Zero, or the Micro, have one + hardware serial port attached to Digital pins 0-1, and a separate USB serial + port attached to the IDE Serial Monitor. This means that the "serial + passthrough" which is possible with the Arduino UNO (commonly used to interact + with devices/shields that require configuration via serial AT commands) will + not work by default. + + This sketch allows you to emulate the serial passthrough behaviour. Any text + you type in the IDE Serial monitor will be written out to the serial port on + Digital pins 0 and 1, and vice-versa. + + On the 101, MKR1000, Zero, and Micro, "Serial" refers to the USB Serial port + attached to the Serial Monitor, and "Serial1" refers to the hardware serial + port attached to pins 0 and 1. This sketch will emulate Serial passthrough + using those two Serial ports on the boards mentioned above, but you can change + these names to connect any two serial ports on a board that has multiple ports. + + created 23 May 2016 + by Erik Nyquist + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SerialPassthrough +*/ + +void setup() { + Serial.begin(9600); + Serial1.begin(9600); +} + +void loop() { + if (Serial.available()) { // If anything comes in Serial (USB), + Serial1.write(Serial.read()); // read it and send it out Serial1 (pins 0 & 1) + } + + if (Serial1.available()) { // If anything comes in Serial1 (pins 0 & 1) + Serial.write(Serial1.read()); // read it and send it out Serial (USB) + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino new file mode 100644 index 00000000..cf66348b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/04.Communication/VirtualColorMixer/VirtualColorMixer.ino @@ -0,0 +1,129 @@ +/* + This example reads three analog sensors (potentiometers are easiest) and sends + their values serially. The Processing and Max/MSP programs at the bottom take + those three values and use them to change the background color of the screen. + + The circuit: + - potentiometers attached to analog inputs 0, 1, and 2 + + created 2 Dec 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe and Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/VirtualColorMixer +*/ + +const int redPin = A0; // sensor to control red color +const int greenPin = A1; // sensor to control green color +const int bluePin = A2; // sensor to control blue color + +void setup() { + Serial.begin(9600); +} + +void loop() { + Serial.print(analogRead(redPin)); + Serial.print(","); + Serial.print(analogRead(greenPin)); + Serial.print(","); + Serial.println(analogRead(bluePin)); +} + +/* Processing code for this example + + // This example code is in the public domain. + + import processing.serial.*; + + float redValue = 0; // red value + float greenValue = 0; // green value + float blueValue = 0; // blue value + + Serial myPort; + + void setup() { + size(200, 200); + + // List all the available serial ports + // if using Processing 2.1 or later, use Serial.printArray() + println(Serial.list()); + + // I know that the first port in the serial list on my Mac is always my + // Arduino, so I open Serial.list()[0]. + // Open whatever port is the one you're using. + myPort = new Serial(this, Serial.list()[0], 9600); + // don't generate a serialEvent() unless you get a newline character: + myPort.bufferUntil('\n'); + } + + void draw() { + // set the background color with the color values: + background(redValue, greenValue, blueValue); + } + + void serialEvent(Serial myPort) { + // get the ASCII string: + String inString = myPort.readStringUntil('\n'); + + if (inString != null) { + // trim off any whitespace: + inString = trim(inString); + // split the string on the commas and convert the resulting substrings + // into an integer array: + float[] colors = float(split(inString, ",")); + // if the array has at least three elements, you know you got the whole + // thing. Put the numbers in the color variables: + if (colors.length >= 3) { + // map them to the range 0-255: + redValue = map(colors[0], 0, 1023, 0, 255); + greenValue = map(colors[1], 0, 1023, 0, 255); + blueValue = map(colors[2], 0, 1023, 0, 255); + } + } + } + +*/ + +/* Max/MSP patch for this example + + ----------begin_max5_patcher---------- + 1512.3oc4Z00aaaCE8YmeED9ktB35xOjrj1aAsXX4g8xZQeYoXfVh1gqRjdT + TsIsn+2K+PJUovVVJ1VMdCAvxThV7bO7b48dIyWtXxzkxaYkSA+J3u.Sl7kK + lLwcK6MlT2dxzB5so4zRW2lJXeRt7elNy+HM6Vs61uDDzbOYkNmo02sg4euS + 4BSede8S2P0o2vEq+aEKU66PPP7b3LPHDauPvyCmAvv4v6+M7L2XXF2WfCaF + lURgVPKbCxzKUbZdySDUEbgABN.ia08R9mccGYGn66qGutNir27qWbg8iY+7 + HDRx.Hjf+OPHCQgPdpQHoxhBlwB+QF4cbkthlCRk4REnfeKScs3ZwaugWBbj + .PS+.qDPAkZkgPlY5oPS4By2A5aTLFv9pounjsgpnZVF3x27pqtBrRpJnZaa + C3WxTkfUJYA.BzR.BhIy.ehquw7dSoJCsrlATLckR.nhLPNWvVwL+Vp1LHL. + SjMG.tRaG7OxT5R2c8Hx9B8.wLCxVaGI6qnpj45Ug84kL+6YIM8CqUxJyycF + 7bqsBRULGvwfWyRMyovElat7NvqoejaLm4f+fkmyKuVTHy3q3ldhB.WtQY6Z + x0BSOeSpTqA+FW+Yy3SyybH3sFy8p0RVCmaMpTyX6HdDZ2JsPbfSogbBMueH + JLd6RMBdfRMzPjZvimuWIK2XgFA.ZmtfKoh0Sm88qc6OF4bDQ3P6kEtF6xej + .OkjD4H5OllyS+.3FlhY0so4xRlWqyrXErQpt+2rsnXgQNZHZgmMVzEofW7T + S4zORQtgIdDbRHrObRzSMNofUVZVcbKbhQZrSOo934TqRHIN2ncr7BF8TKR1 + tHDqL.PejLRRPKMR.pKFAkbtDa+UOvsYsIFH0DYsTCjqZ66T1CmGeDILLpSm + myk0SdkOKh5LUr4GbWwRYdW7fm.BvDmzHnSdH3biGpSbxxDNJoGDAD1ChH7L + I0DaloOTBLvkO7zPs5HJnKNoGAXbol5eytUhfyiSfnjE1uAq+Fp0a+wygGwR + q3ZI8.psJpkpJnyPzwmXBj7Sh.+bNvVZxlcKAm0OYHIxcIjzEKdRChgO5UMf + LkMPNN0MfiS7Ev6TYQct.F5IWcCZ4504rGsiVswGWWSYyma01QcZgmL+f+sf + oU18Hn6o6dXkMkFF14TL9rIAWE+6wvGV.p.TPqz3HK5L+VxYxl4UmBKEjr.B + 6zinuKI3C+D2Y7azIM6N7QL6t+jQyZxymK1ToAKqVsxjlGyjz2c1kTK3180h + kJEYkacWpv6lyp2VJTjWK47wHA6fyBOWxH9pUf6jUtZkLpNKW.9EeUBH3ymY + XSQlaqGrkQMGzp20adYSmIOGjIABo1xZyAWJtCX9tg6+HMuhMCPyx76ao+Us + UxmzUE79H8d2ZB1m1ztbnOa1mGeAq0awyK8a9UqBUc6pZolpzurTK232e5gp + aInVw8QIIcpaiNSJfY4Z+92Cs+Mc+mgg2cEsvGlLY6V+1kMuioxnB5VM+fsY + 9vSu4WI1PMBGXye6KXvNuzmZTh7U9h5j6vvASdngPdgOFxycNL6ia1axUMmT + JIzebXcQCn3SKMf+4QCMmOZung+6xBCPLfwO8ngcEI52YJ1y7mx3CN9xKUYU + bg7Y1yXjlKW6SrZnguQdsSfOSSDItqv2jwJFjavc1vO7OigyBr2+gDYorRk1 + HXZpVFfu2FxXkZtfp4RQqNkX5y2sya3YYL2iavWAOaizH+pw.Ibg8f1I9h3Z + 2B79sNeOHvBOtfEalWsvyu0KMf015.AaROvZ7vv5AhnndfHLbTgjcCK1KlHv + gOk5B26OqrXjcJ005.QqCHn8fVTxnxfj93SfQiJlv8YV0VT9fVUwOOhSV3uD + eeqCUClbBPa.j3vWDoMZssNTzRNEnE6gYPXazZaMF921syaLWyAeBXvCESA8 + ASi6Zyw8.RQi65J8ZsNx3ho93OhGWENtWpowepae4YhCFeLErOLENtXJrOSc + iadi39rf4hwc8xdhHz3gn3dBI7iDRlFe8huAfIZhq + -----------end_max5_patcher----------- + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/Arrays/Arrays.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/Arrays/Arrays.ino new file mode 100644 index 00000000..dbbb4b42 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/Arrays/Arrays.ino @@ -0,0 +1,56 @@ +/* + Arrays + + Demonstrates the use of an array to hold pin numbers in order to iterate over + the pins in a sequence. Lights multiple LEDs in sequence, then in reverse. + + Unlike the For Loop tutorial, where the pins have to be contiguous, here the + pins can be in any random order. + + The circuit: + - LEDs from pins 2 through 7 to ground + + created 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Arrays +*/ + +int timer = 100; // The higher the number, the slower the timing. +int ledPins[] = { + 2, 7, 4, 6, 5, 3 +}; // an array of pin numbers to which LEDs are attached +int pinCount = 6; // the number of pins (i.e. the length of the array) + +void setup() { + // the array elements are numbered from 0 to (pinCount - 1). + // use a for loop to initialize each pin as an output: + for (int thisPin = 0; thisPin < pinCount; thisPin++) { + pinMode(ledPins[thisPin], OUTPUT); + } +} + +void loop() { + // loop from the lowest pin to the highest: + for (int thisPin = 0; thisPin < pinCount; thisPin++) { + // turn the pin on: + digitalWrite(ledPins[thisPin], HIGH); + delay(timer); + // turn the pin off: + digitalWrite(ledPins[thisPin], LOW); + + } + + // loop from the highest pin to the lowest: + for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) { + // turn the pin on: + digitalWrite(ledPins[thisPin], HIGH); + delay(timer); + // turn the pin off: + digitalWrite(ledPins[thisPin], LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/ForLoopIteration/ForLoopIteration.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/ForLoopIteration/ForLoopIteration.ino new file mode 100644 index 00000000..af9cd7d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/ForLoopIteration/ForLoopIteration.ino @@ -0,0 +1,47 @@ +/* + For Loop Iteration + + Demonstrates the use of a for() loop. + Lights multiple LEDs in sequence, then in reverse. + + The circuit: + - LEDs from pins 2 through 7 to ground + + created 2006 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ForLoopIteration +*/ + +int timer = 100; // The higher the number, the slower the timing. + +void setup() { + // use a for loop to initialize each pin as an output: + for (int thisPin = 2; thisPin < 8; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // loop from the lowest pin to the highest: + for (int thisPin = 2; thisPin < 8; thisPin++) { + // turn the pin on: + digitalWrite(thisPin, HIGH); + delay(timer); + // turn the pin off: + digitalWrite(thisPin, LOW); + } + + // loop from the highest pin to the lowest: + for (int thisPin = 7; thisPin >= 2; thisPin--) { + // turn the pin on: + digitalWrite(thisPin, HIGH); + delay(timer); + // turn the pin off: + digitalWrite(thisPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/IfStatementConditional/IfStatementConditional.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/IfStatementConditional/IfStatementConditional.ino new file mode 100644 index 00000000..efd233f5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/IfStatementConditional/IfStatementConditional.ino @@ -0,0 +1,53 @@ +/* + Conditionals - If statement + + This example demonstrates the use of if() statements. + It reads the state of a potentiometer (an analog input) and turns on an LED + only if the potentiometer goes above a certain threshold level. It prints the + analog value regardless of the level. + + The circuit: + - potentiometer + Center pin of the potentiometer goes to analog pin 0. + Side pins of the potentiometer go to +5V and ground. + - LED connected from digital pin 13 to ground through 220 ohm resistor + + - Note: On most Arduino boards, there is already an LED on the board connected + to pin 13, so you don't need any extra components for this example. + + created 17 Jan 2009 + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ifStatementConditional +*/ + +// These constants won't change: +const int analogPin = A0; // pin that the sensor is attached to +const int ledPin = 13; // pin that the LED is attached to +const int threshold = 400; // an arbitrary threshold level that's in the range of the analog input + +void setup() { + // initialize the LED pin as an output: + pinMode(ledPin, OUTPUT); + // initialize serial communications: + Serial.begin(9600); +} + +void loop() { + // read the value of the potentiometer: + int analogValue = analogRead(analogPin); + + // if the analog value is high enough, turn on the LED: + if (analogValue > threshold) { + digitalWrite(ledPin, HIGH); + } else { + digitalWrite(ledPin, LOW); + } + + // print the analog value: + Serial.println(analogValue); + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino new file mode 100644 index 00000000..a0b42e1f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/WhileStatementConditional/WhileStatementConditional.ino @@ -0,0 +1,87 @@ +/* + Conditionals - while statement + + This example demonstrates the use of while() statements. + + While the pushbutton is pressed, the sketch runs the calibration routine. + The sensor readings during the while loop define the minimum and maximum of + expected values from the photoresistor. + + This is a variation on the calibrate example. + + The circuit: + - photoresistor connected from +5V to analog in pin 0 + - 10 kilohm resistor connected from ground to analog in pin 0 + - LED connected from digital pin 9 to ground through 220 ohm resistor + - pushbutton attached from pin 2 to +5V + - 10 kilohm resistor attached from pin 2 to ground + + created 17 Jan 2009 + modified 30 Aug 2011 + by Tom Igoe + modified 20 Jan 2017 + by Arturo Guadalupi + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/WhileStatementConditional +*/ + + +// These constants won't change: +const int sensorPin = A0; // pin that the sensor is attached to +const int ledPin = 9; // pin that the LED is attached to +const int indicatorLedPin = 13; // pin that the built-in LED is attached to +const int buttonPin = 2; // pin that the button is attached to + + +// These variables will change: +int sensorMin = 1023; // minimum sensor value +int sensorMax = 0; // maximum sensor value +int sensorValue = 0; // the sensor value + + +void setup() { + // set the LED pins as outputs and the switch pin as input: + pinMode(indicatorLedPin, OUTPUT); + pinMode(ledPin, OUTPUT); + pinMode(buttonPin, INPUT); +} + +void loop() { + // while the button is pressed, take calibration readings: + while (digitalRead(buttonPin) == HIGH) { + calibrate(); + } + // signal the end of the calibration period + digitalWrite(indicatorLedPin, LOW); + + // read the sensor: + sensorValue = analogRead(sensorPin); + + // apply the calibration to the sensor reading + sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255); + + // in case the sensor value is outside the range seen during calibration + sensorValue = constrain(sensorValue, 0, 255); + + // fade the LED using the calibrated value: + analogWrite(ledPin, sensorValue); +} + +void calibrate() { + // turn on the indicator LED to indicate that calibration is happening: + digitalWrite(indicatorLedPin, HIGH); + // read the sensor: + sensorValue = analogRead(sensorPin); + + // record the maximum sensor value + if (sensorValue > sensorMax) { + sensorMax = sensorValue; + } + + // record the minimum sensor value + if (sensorValue < sensorMin) { + sensorMin = sensorValue; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/switchCase/switchCase.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/switchCase/switchCase.ino new file mode 100644 index 00000000..3ffc9f0a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/switchCase/switchCase.ino @@ -0,0 +1,56 @@ +/* + Switch statement + + Demonstrates the use of a switch statement. The switch statement allows you + to choose from among a set of discrete values of a variable. It's like a + series of if statements. + + To see this sketch in action, put the board and sensor in a well-lit room, + open the Serial Monitor, and move your hand gradually down over the sensor. + + The circuit: + - photoresistor from analog in 0 to +5V + - 10K resistor from analog in 0 to ground + + created 1 Jul 2009 + modified 9 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase +*/ + +// these constants won't change. They are the lowest and highest readings you +// get from your sensor: +const int sensorMin = 0; // sensor minimum, discovered through experiment +const int sensorMax = 600; // sensor maximum, discovered through experiment + +void setup() { + // initialize serial communication: + Serial.begin(9600); +} + +void loop() { + // read the sensor: + int sensorReading = analogRead(A0); + // map the sensor range to a range of four options: + int range = map(sensorReading, sensorMin, sensorMax, 0, 3); + + // do something different depending on the range value: + switch (range) { + case 0: // your hand is on the sensor + Serial.println("dark"); + break; + case 1: // your hand is close to the sensor + Serial.println("dim"); + break; + case 2: // your hand is a few inches from the sensor + Serial.println("medium"); + break; + case 3: // your hand is nowhere near the sensor + Serial.println("bright"); + break; + } + delay(1); // delay in between reads for stability +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/switchCase2/switchCase2.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/switchCase2/switchCase2.ino new file mode 100644 index 00000000..48cbaa48 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/05.Control/switchCase2/switchCase2.ino @@ -0,0 +1,65 @@ +/* + Switch statement with serial input + + Demonstrates the use of a switch statement. The switch statement allows you + to choose from among a set of discrete values of a variable. It's like a + series of if statements. + + To see this sketch in action, open the Serial monitor and send any character. + The characters a, b, c, d, and e, will turn on LEDs. Any other character will + turn the LEDs off. + + The circuit: + - five LEDs attached to digital pins 2 through 6 through 220 ohm resistors + + created 1 Jul 2009 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/SwitchCase2 +*/ + +void setup() { + // initialize serial communication: + Serial.begin(9600); + // initialize the LED pins: + for (int thisPin = 2; thisPin < 7; thisPin++) { + pinMode(thisPin, OUTPUT); + } +} + +void loop() { + // read the sensor: + if (Serial.available() > 0) { + int inByte = Serial.read(); + // do something different depending on the character received. + // The switch statement expects single number values for each case; in this + // example, though, you're using single quotes to tell the controller to get + // the ASCII value for the character. For example 'a' = 97, 'b' = 98, + // and so forth: + + switch (inByte) { + case 'a': + digitalWrite(2, HIGH); + break; + case 'b': + digitalWrite(3, HIGH); + break; + case 'c': + digitalWrite(4, HIGH); + break; + case 'd': + digitalWrite(5, HIGH); + break; + case 'e': + digitalWrite(6, HIGH); + break; + default: + // turn all the LEDs off: + for (int thisPin = 2; thisPin < 7; thisPin++) { + digitalWrite(thisPin, LOW); + } + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/ADXL3xx/ADXL3xx.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/ADXL3xx/ADXL3xx.ino new file mode 100644 index 00000000..65b579bb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/ADXL3xx/ADXL3xx.ino @@ -0,0 +1,60 @@ +/* + ADXL3xx + + Reads an Analog Devices ADXL3xx accelerometer and communicates the + acceleration to the computer. The pins used are designed to be easily + compatible with the breakout boards from SparkFun, available from: + https://www.sparkfun.com/categories/80 + + The circuit: + - analog 0: accelerometer self test + - analog 1: z-axis + - analog 2: y-axis + - analog 3: x-axis + - analog 4: ground + - analog 5: vcc + + created 2 Jul 2008 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ADXL3xx +*/ + +// these constants describe the pins. They won't change: +const int groundpin = 18; // analog input pin 4 -- ground +const int powerpin = 19; // analog input pin 5 -- voltage +const int xpin = A3; // x-axis of the accelerometer +const int ypin = A2; // y-axis +const int zpin = A1; // z-axis (only on 3-axis models) + +void setup() { + // initialize the serial communications: + Serial.begin(9600); + + // Provide ground and power by using the analog inputs as normal digital pins. + // This makes it possible to directly connect the breakout board to the + // Arduino. If you use the normal 5V and GND pins on the Arduino, + // you can remove these lines. + pinMode(groundpin, OUTPUT); + pinMode(powerpin, OUTPUT); + digitalWrite(groundpin, LOW); + digitalWrite(powerpin, HIGH); +} + +void loop() { + // print the sensor values: + Serial.print(analogRead(xpin)); + // print a tab between values: + Serial.print("\t"); + Serial.print(analogRead(ypin)); + // print a tab between values: + Serial.print("\t"); + Serial.print(analogRead(zpin)); + Serial.println(); + // delay before next reading: + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Knock/Knock.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Knock/Knock.ino new file mode 100644 index 00000000..815d7214 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Knock/Knock.ino @@ -0,0 +1,54 @@ +/* + Knock Sensor + + This sketch reads a piezo element to detect a knocking sound. + It reads an analog pin and compares the result to a set threshold. + If the result is greater than the threshold, it writes "knock" to the serial + port, and toggles the LED on pin 13. + + The circuit: + - positive connection of the piezo attached to analog in 0 + - negative connection of the piezo attached to ground + - 1 megohm resistor attached from analog in 0 to ground + + created 25 Mar 2007 + by David Cuartielles + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Knock +*/ + + +// these constants won't change: +const int ledPin = 13; // LED connected to digital pin 13 +const int knockSensor = A0; // the piezo is connected to analog pin 0 +const int threshold = 100; // threshold value to decide when the detected sound is a knock or not + + +// these variables will change: +int sensorReading = 0; // variable to store the value read from the sensor pin +int ledState = LOW; // variable used to store the last LED status, to toggle the light + +void setup() { + pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT + Serial.begin(9600); // use the serial port +} + +void loop() { + // read the sensor and store it in the variable sensorReading: + sensorReading = analogRead(knockSensor); + + // if the sensor reading is greater than the threshold: + if (sensorReading >= threshold) { + // toggle the status of the ledPin: + ledState = !ledState; + // update the LED pin itself: + digitalWrite(ledPin, ledState); + // send the string "Knock!" back to the computer, followed by newline + Serial.println("Knock!"); + } + delay(100); // delay to avoid overloading the serial port buffer +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Memsic2125/Memsic2125.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Memsic2125/Memsic2125.ino new file mode 100644 index 00000000..b95472b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Memsic2125/Memsic2125.ino @@ -0,0 +1,60 @@ +/* + Memsic2125 + + Read the Memsic 2125 two-axis accelerometer. Converts the pulses output by the + 2125 into milli-g's (1/1000 of Earth's gravity) and prints them over the + serial connection to the computer. + + The circuit: + - X output of accelerometer to digital pin 2 + - Y output of accelerometer to digital pin 3 + - +V of accelerometer to +5V + - GND of accelerometer to ground + + created 6 Nov 2008 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Memsic2125 +*/ + +// these constants won't change: +const int xPin = 2; // X output of the accelerometer +const int yPin = 3; // Y output of the accelerometer + +void setup() { + // initialize serial communications: + Serial.begin(9600); + // initialize the pins connected to the accelerometer as inputs: + pinMode(xPin, INPUT); + pinMode(yPin, INPUT); +} + +void loop() { + // variables to read the pulse widths: + int pulseX, pulseY; + // variables to contain the resulting accelerations + int accelerationX, accelerationY; + + // read pulse from x- and y-axes: + pulseX = pulseIn(xPin, HIGH); + pulseY = pulseIn(yPin, HIGH); + + // convert the pulse width into acceleration + // accelerationX and accelerationY are in milli-g's: + // Earth's gravity is 1000 milli-g's, or 1 g. + accelerationX = ((pulseX / 10) - 500) * 8; + accelerationY = ((pulseY / 10) - 500) * 8; + + // print the acceleration + Serial.print(accelerationX); + // print a tab character: + Serial.print("\t"); + Serial.print(accelerationY); + Serial.println(); + + delay(100); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Ping/Ping.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Ping/Ping.ino new file mode 100644 index 00000000..2d9a0da3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/06.Sensors/Ping/Ping.ino @@ -0,0 +1,79 @@ +/* + Ping))) Sensor + + This sketch reads a PING))) ultrasonic rangefinder and returns the distance + to the closest object in range. To do this, it sends a pulse to the sensor to + initiate a reading, then listens for a pulse to return. The length of the + returning pulse is proportional to the distance of the object from the sensor. + + The circuit: + - +V connection of the PING))) attached to +5V + - GND connection of the PING))) attached to ground + - SIG connection of the PING))) attached to digital pin 7 + + created 3 Nov 2008 + by David A. Mellis + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/Ping +*/ + +// this constant won't change. It's the pin number of the sensor's output: +const int pingPin = 7; + +void setup() { + // initialize serial communication: + Serial.begin(9600); +} + +void loop() { + // establish variables for duration of the ping, and the distance result + // in inches and centimeters: + long duration, inches, cm; + + // The PING))) is triggered by a HIGH pulse of 2 or more microseconds. + // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: + pinMode(pingPin, OUTPUT); + digitalWrite(pingPin, LOW); + delayMicroseconds(2); + digitalWrite(pingPin, HIGH); + delayMicroseconds(5); + digitalWrite(pingPin, LOW); + + // The same pin is used to read the signal from the PING))): a HIGH pulse + // whose duration is the time (in microseconds) from the sending of the ping + // to the reception of its echo off of an object. + pinMode(pingPin, INPUT); + duration = pulseIn(pingPin, HIGH); + + // convert the time into a distance + inches = microsecondsToInches(duration); + cm = microsecondsToCentimeters(duration); + + Serial.print(inches); + Serial.print("in, "); + Serial.print(cm); + Serial.print("cm"); + Serial.println(); + + delay(100); +} + +long microsecondsToInches(long microseconds) { + // According to Parallax's datasheet for the PING))), there are 73.746 + // microseconds per inch (i.e. sound travels at 1130 feet per second). + // This gives the distance travelled by the ping, outbound and return, + // so we divide by 2 to get the distance of the obstacle. + // See: https://www.parallax.com/package/ping-ultrasonic-distance-sensor-downloads/ + return microseconds / 74 / 2; +} + +long microsecondsToCentimeters(long microseconds) { + // The speed of sound is 340 m/s or 29 microseconds per centimeter. + // The ping travels out and back, so to find the distance of the object we + // take half of the distance travelled. + return microseconds / 29 / 2; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/07.Display/RowColumnScanning/RowColumnScanning.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/07.Display/RowColumnScanning/RowColumnScanning.ino new file mode 100644 index 00000000..023a5c25 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/07.Display/RowColumnScanning/RowColumnScanning.ino @@ -0,0 +1,109 @@ +/* + Row-Column Scanning an 8x8 LED matrix with X-Y input + + This example controls an 8x8 LED matrix using two analog inputs. + + This example works for the Lumex LDM-24488NI Matrix. See + https://sigma.octopart.com/140413/datasheet/Lumex-LDM-24488NI.pdf + for the pin connections. + + For other LED cathode column matrixes, you should only need to change the pin + numbers in the row[] and column[] arrays. + + rows are the anodes + cols are the cathodes + --------- + + Pin numbers: + Matrix: + - digital pins 2 through 13, + - analog pins 2 through 5 used as digital 16 through 19 + Potentiometers: + - center pins are attached to analog pins 0 and 1, respectively + - side pins attached to +5V and ground, respectively + + created 27 May 2009 + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/RowColumnScanning +*/ + +// 2-dimensional array of row pin numbers: +const int row[8] = { + 2, 7, 19, 5, 13, 18, 12, 16 +}; + +// 2-dimensional array of column pin numbers: +const int col[8] = { + 6, 11, 10, 3, 17, 4, 8, 9 +}; + +// 2-dimensional array of pixels: +int pixels[8][8]; + +// cursor position: +int x = 5; +int y = 5; + +void setup() { + // initialize the I/O pins as outputs iterate over the pins: + for (int thisPin = 0; thisPin < 8; thisPin++) { + // initialize the output pins: + pinMode(col[thisPin], OUTPUT); + pinMode(row[thisPin], OUTPUT); + // take the col pins (i.e. the cathodes) high to ensure that the LEDS are off: + digitalWrite(col[thisPin], HIGH); + } + + // initialize the pixel matrix: + for (int x = 0; x < 8; x++) { + for (int y = 0; y < 8; y++) { + pixels[x][y] = HIGH; + } + } +} + +void loop() { + // read input: + readSensors(); + + // draw the screen: + refreshScreen(); +} + +void readSensors() { + // turn off the last position: + pixels[x][y] = HIGH; + // read the sensors for X and Y values: + x = 7 - map(analogRead(A0), 0, 1023, 0, 7); + y = map(analogRead(A1), 0, 1023, 0, 7); + // set the new pixel position low so that the LED will turn on in the next + // screen refresh: + pixels[x][y] = LOW; + +} + +void refreshScreen() { + // iterate over the rows (anodes): + for (int thisRow = 0; thisRow < 8; thisRow++) { + // take the row pin (anode) high: + digitalWrite(row[thisRow], HIGH); + // iterate over the cols (cathodes): + for (int thisCol = 0; thisCol < 8; thisCol++) { + // get the state of the current pixel; + int thisPixel = pixels[thisRow][thisCol]; + // when the row is HIGH and the col is LOW, + // the LED where they meet turns on: + digitalWrite(col[thisCol], thisPixel); + // turn the pixel off: + if (thisPixel == LOW) { + digitalWrite(col[thisCol], HIGH); + } + } + // take the row pin low to turn off the whole row: + digitalWrite(row[thisRow], LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/07.Display/barGraph/barGraph.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/07.Display/barGraph/barGraph.ino new file mode 100644 index 00000000..ab97f13d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/07.Display/barGraph/barGraph.ino @@ -0,0 +1,57 @@ +/* + LED bar graph + + Turns on a series of LEDs based on the value of an analog sensor. + This is a simple way to make a bar graph display. Though this graph uses 10 + LEDs, you can use any number by changing the LED count and the pins in the + array. + + This method can be used to control any series of digital outputs that depends + on an analog input. + + The circuit: + - LEDs from pins 2 through 11 to ground + + created 4 Sep 2010 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/BarGraph +*/ + +// these constants won't change: +const int analogPin = A0; // the pin that the potentiometer is attached to +const int ledCount = 10; // the number of LEDs in the bar graph + +int ledPins[] = { + 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 +}; // an array of pin numbers to which LEDs are attached + + +void setup() { + // loop over the pin array and set them all to output: + for (int thisLed = 0; thisLed < ledCount; thisLed++) { + pinMode(ledPins[thisLed], OUTPUT); + } +} + +void loop() { + // read the potentiometer: + int sensorReading = analogRead(analogPin); + // map the result to a range from 0 to the number of LEDs: + int ledLevel = map(sensorReading, 0, 1023, 0, ledCount); + + // loop over the LED array: + for (int thisLed = 0; thisLed < ledCount; thisLed++) { + // if the array element's index is less than ledLevel, + // turn the pin for this element on: + if (thisLed < ledLevel) { + digitalWrite(ledPins[thisLed], HIGH); + } + // turn off all pins higher than the ledLevel: + else { + digitalWrite(ledPins[thisLed], LOW); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino new file mode 100644 index 00000000..e7a3c23c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/CharacterAnalysis/CharacterAnalysis.ino @@ -0,0 +1,85 @@ +/* + Character analysis operators + + Examples using the character analysis operators. + Send any byte and the sketch will tell you about it. + + created 29 Nov 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/CharacterAnalysis +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("send any byte and I'll tell you everything I can about it"); + Serial.println(); +} + +void loop() { + // get any incoming bytes: + if (Serial.available() > 0) { + int thisChar = Serial.read(); + + // say what was sent: + Serial.print("You sent me: \'"); + Serial.write(thisChar); + Serial.print("\' ASCII Value: "); + Serial.println(thisChar); + + // analyze what was sent: + if (isAlphaNumeric(thisChar)) { + Serial.println("it's alphanumeric"); + } + if (isAlpha(thisChar)) { + Serial.println("it's alphabetic"); + } + if (isAscii(thisChar)) { + Serial.println("it's ASCII"); + } + if (isWhitespace(thisChar)) { + Serial.println("it's whitespace"); + } + if (isControl(thisChar)) { + Serial.println("it's a control character"); + } + if (isDigit(thisChar)) { + Serial.println("it's a numeric digit"); + } + if (isGraph(thisChar)) { + Serial.println("it's a printable character that's not whitespace"); + } + if (isLowerCase(thisChar)) { + Serial.println("it's lower case"); + } + if (isPrintable(thisChar)) { + Serial.println("it's printable"); + } + if (isPunct(thisChar)) { + Serial.println("it's punctuation"); + } + if (isSpace(thisChar)) { + Serial.println("it's a space character"); + } + if (isUpperCase(thisChar)) { + Serial.println("it's upper case"); + } + if (isHexadecimalDigit(thisChar)) { + Serial.println("it's a valid hexadecimaldigit (i.e. 0 - 9, a - F, or A - F)"); + } + + // add some space and ask for another byte: + Serial.println(); + Serial.println("Give me another byte:"); + Serial.println(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino new file mode 100644 index 00000000..531742be --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringAdditionOperator/StringAdditionOperator.ino @@ -0,0 +1,67 @@ +/* + Adding Strings together + + Examples of how to add Strings together + You can also add several different data types to String, as shown here: + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringAdditionOperator +*/ + +// declare three Strings: +String stringOne, stringTwo, stringThree; + +void setup() { + // initialize serial and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + stringOne = String("You added "); + stringTwo = String("this string"); + stringThree = String(); + // send an intro: + Serial.println("\n\nAdding Strings together (concatenation):"); + Serial.println(); +} + +void loop() { + // adding a constant integer to a String: + stringThree = stringOne + 123; + Serial.println(stringThree); // prints "You added 123" + + // adding a constant long integer to a String: + stringThree = stringOne + 123456789; + Serial.println(stringThree); // prints "You added 123456789" + + // adding a constant character to a String: + stringThree = stringOne + 'A'; + Serial.println(stringThree); // prints "You added A" + + // adding a constant string to a String: + stringThree = stringOne + "abc"; + Serial.println(stringThree); // prints "You added abc" + + stringThree = stringOne + stringTwo; + Serial.println(stringThree); // prints "You added this string" + + // adding a variable integer to a String: + int sensorValue = analogRead(A0); + stringOne = "Sensor value: "; + stringThree = stringOne + sensorValue; + Serial.println(stringThree); // prints "Sensor Value: 401" or whatever value analogRead(A0) has + + // adding a variable long integer to a String: + stringOne = "millis() value: "; + stringThree = stringOne + millis(); + Serial.println(stringThree); // prints "The millis: 345345" or whatever value millis() has + + // do nothing while true: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino new file mode 100644 index 00000000..b6348928 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringAppendOperator/StringAppendOperator.ino @@ -0,0 +1,72 @@ +/* + Appending to Strings using the += operator and concat() + + Examples of how to append different data types to Strings + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringAppendOperator +*/ + +String stringOne, stringTwo; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + stringOne = String("Sensor "); + stringTwo = String("value"); + // send an intro: + Serial.println("\n\nAppending to a String:"); + Serial.println(); +} + +void loop() { + Serial.println(stringOne); // prints "Sensor " + + // adding a string to a String: + stringOne += stringTwo; + Serial.println(stringOne); // prints "Sensor value" + + // adding a constant string to a String: + stringOne += " for input "; + Serial.println(stringOne); // prints "Sensor value for input" + + // adding a constant character to a String: + stringOne += 'A'; + Serial.println(stringOne); // prints "Sensor value for input A" + + // adding a constant integer to a String: + stringOne += 0; + Serial.println(stringOne); // prints "Sensor value for input A0" + + // adding a constant string to a String: + stringOne += ": "; + Serial.println(stringOne); // prints "Sensor value for input" + + // adding a variable integer to a String: + stringOne += analogRead(A0); + Serial.println(stringOne); // prints "Sensor value for input A0: 456" or whatever analogRead(A0) is + + Serial.println("\n\nchanging the Strings' values"); + stringOne = "A long integer: "; + stringTwo = "The millis(): "; + + // adding a constant long integer to a String: + stringOne += 123456789; + Serial.println(stringOne); // prints "A long integer: 123456789" + + // using concat() to add a long variable to a String: + stringTwo.concat(millis()); + Serial.println(stringTwo); // prints "The millis(): 43534" or whatever the value of the millis() is + + // do nothing while true: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino new file mode 100644 index 00000000..fc6ab619 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringCaseChanges/StringCaseChanges.ino @@ -0,0 +1,43 @@ +/* + String Case changes + + Examples of how to change the case of a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringCaseChanges +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString case changes:"); + Serial.println(); +} + +void loop() { + // toUpperCase() changes all letters to upper case: + String stringOne = ""; + Serial.println(stringOne); + stringOne.toUpperCase(); + Serial.println(stringOne); + + // toLowerCase() changes all letters to lower case: + String stringTwo = ""; + Serial.println(stringTwo); + stringTwo.toLowerCase(); + Serial.println(stringTwo); + + + // do nothing while true: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringCharacters/StringCharacters.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringCharacters/StringCharacters.ino new file mode 100644 index 00000000..a179cfa9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringCharacters/StringCharacters.ino @@ -0,0 +1,45 @@ +/* + String charAt() and setCharAt() + + Examples of how to get and set characters of a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringCharacters +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.println("\n\nString charAt() and setCharAt():"); +} + +void loop() { + // make a String to report a sensor reading: + String reportString = "SensorReading: 456"; + Serial.println(reportString); + + // the reading's most significant digit is at position 15 in the reportString: + char mostSignificantDigit = reportString.charAt(15); + + String message = "Most significant digit of the sensor reading is: "; + Serial.println(message + mostSignificantDigit); + + // add blank space: + Serial.println(); + + // you can also set the character of a String. Change the : to a = character + reportString.setCharAt(13, '='); + Serial.println(reportString); + + // do nothing while true: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino new file mode 100644 index 00000000..aff91394 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringComparisonOperators/StringComparisonOperators.ino @@ -0,0 +1,128 @@ +/* + Comparing Strings + + Examples of how to compare Strings using the comparison operators + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringComparisonOperators +*/ + +String stringOne, stringTwo; + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + + stringOne = String("this"); + stringTwo = String("that"); + // send an intro: + Serial.println("\n\nComparing Strings:"); + Serial.println(); + +} + +void loop() { + // two Strings equal: + if (stringOne == "this") { + Serial.println("StringOne == \"this\""); + } + // two Strings not equal: + if (stringOne != stringTwo) { + Serial.println(stringOne + " =! " + stringTwo); + } + + // two Strings not equal (case sensitivity matters): + stringOne = "This"; + stringTwo = "this"; + if (stringOne != stringTwo) { + Serial.println(stringOne + " =! " + stringTwo); + } + // you can also use equals() to see if two Strings are the same: + if (stringOne.equals(stringTwo)) { + Serial.println(stringOne + " equals " + stringTwo); + } else { + Serial.println(stringOne + " does not equal " + stringTwo); + } + + // or perhaps you want to ignore case: + if (stringOne.equalsIgnoreCase(stringTwo)) { + Serial.println(stringOne + " equals (ignoring case) " + stringTwo); + } else { + Serial.println(stringOne + " does not equal (ignoring case) " + stringTwo); + } + + // a numeric String compared to the number it represents: + stringOne = "1"; + int numberOne = 1; + if (stringOne.toInt() == numberOne) { + Serial.println(stringOne + " = " + numberOne); + } + + + + // two numeric Strings compared: + stringOne = "2"; + stringTwo = "1"; + if (stringOne >= stringTwo) { + Serial.println(stringOne + " >= " + stringTwo); + } + + // comparison operators can be used to compare Strings for alphabetic sorting too: + stringOne = String("Brown"); + if (stringOne < "Charles") { + Serial.println(stringOne + " < Charles"); + } + + if (stringOne > "Adams") { + Serial.println(stringOne + " > Adams"); + } + + if (stringOne <= "Browne") { + Serial.println(stringOne + " <= Browne"); + } + + + if (stringOne >= "Brow") { + Serial.println(stringOne + " >= Brow"); + } + + // the compareTo() operator also allows you to compare Strings + // it evaluates on the first character that's different. + // if the first character of the String you're comparing to comes first in + // alphanumeric order, then compareTo() is greater than 0: + stringOne = "Cucumber"; + stringTwo = "Cucuracha"; + if (stringOne.compareTo(stringTwo) < 0) { + Serial.println(stringOne + " comes before " + stringTwo); + } else { + Serial.println(stringOne + " comes after " + stringTwo); + } + + delay(10000); // because the next part is a loop: + + // compareTo() is handy when you've got Strings with numbers in them too: + + while (true) { + stringOne = "Sensor: "; + stringTwo = "Sensor: "; + + stringOne += analogRead(A0); + stringTwo += analogRead(A5); + + if (stringOne.compareTo(stringTwo) < 0) { + Serial.println(stringOne + " comes before " + stringTwo); + } else { + Serial.println(stringOne + " comes after " + stringTwo); + + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringConstructors/StringConstructors.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringConstructors/StringConstructors.ino new file mode 100644 index 00000000..85d00242 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringConstructors/StringConstructors.ino @@ -0,0 +1,80 @@ +/* + String constructors + + Examples of how to create Strings from other data types + + created 27 Jul 2010 + modified 30 Aug 2011 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringConstructors +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString Constructors:"); + Serial.println(); +} + +void loop() { + // using a constant String: + String stringOne = "Hello String"; + Serial.println(stringOne); // prints "Hello String" + + // converting a constant char into a String: + stringOne = String('a'); + Serial.println(stringOne); // prints "a" + + // converting a constant string into a String object: + String stringTwo = String("This is a string"); + Serial.println(stringTwo); // prints "This is a string" + + // concatenating two strings: + stringOne = String(stringTwo + " with more"); + // prints "This is a string with more": + Serial.println(stringOne); + + // using a constant integer: + stringOne = String(13); + Serial.println(stringOne); // prints "13" + + // using an int and a base: + stringOne = String(analogRead(A0), DEC); + // prints "453" or whatever the value of analogRead(A0) is + Serial.println(stringOne); + + // using an int and a base (hexadecimal): + stringOne = String(45, HEX); + // prints "2d", which is the hexadecimal version of decimal 45: + Serial.println(stringOne); + + // using an int and a base (binary) + stringOne = String(255, BIN); + // prints "11111111" which is the binary value of 255 + Serial.println(stringOne); + + // using a long and a base: + stringOne = String(millis(), DEC); + // prints "123456" or whatever the value of millis() is: + Serial.println(stringOne); + + // using a float and the right decimal places: + stringOne = String(5.698, 3); + Serial.println(stringOne); + + // using a float and less decimal places to use rounding: + stringOne = String(5.698, 2); + Serial.println(stringOne); + + // do nothing while true: + while (true); + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringIndexOf/StringIndexOf.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringIndexOf/StringIndexOf.ino new file mode 100644 index 00000000..219f5087 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringIndexOf/StringIndexOf.ino @@ -0,0 +1,65 @@ +/* + String indexOf() and lastIndexOf() functions + + Examples of how to evaluate, look for, and replace characters in a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringIndexOf +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString indexOf() and lastIndexOf() functions:"); + Serial.println(); +} + +void loop() { + // indexOf() returns the position (i.e. index) of a particular character in a + // String. For example, if you were parsing HTML tags, you could use it: + String stringOne = ""; + int firstClosingBracket = stringOne.indexOf('>'); + Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket); + + stringOne = ""; + int secondOpeningBracket = firstClosingBracket + 1; + int secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket); + Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket); + + // you can also use indexOf() to search for Strings: + stringOne = ""; + int bodyTag = stringOne.indexOf(""); + Serial.println("The index of the body tag in the string " + stringOne + " is " + bodyTag); + + stringOne = "
    • item
    • item
    • item
    "; + int firstListItem = stringOne.indexOf("
  • "); + int secondListItem = stringOne.indexOf("
  • ", firstListItem + 1); + Serial.println("The index of the second list tag in the string " + stringOne + " is " + secondListItem); + + // lastIndexOf() gives you the last occurrence of a character or string: + int lastOpeningBracket = stringOne.lastIndexOf('<'); + Serial.println("The index of the last < in the string " + stringOne + " is " + lastOpeningBracket); + + int lastListItem = stringOne.lastIndexOf("
  • "); + Serial.println("The index of the last list tag in the string " + stringOne + " is " + lastListItem); + + + // lastIndexOf() can also search for a string: + stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; + int lastParagraph = stringOne.lastIndexOf(" 0) { + char inChar = Serial.read(); + txtMsg += inChar; + } + + // print the message and a notice if it's changed: + if (txtMsg.length() != lastStringLength) { + Serial.println(txtMsg); + Serial.println(txtMsg.length()); + // if the String's longer than 140 characters, complain: + if (txtMsg.length() < 140) { + Serial.println("That's a perfectly acceptable text message"); + } else { + Serial.println("That's too long for a text message."); + } + // note the length for next time through the loop: + lastStringLength = txtMsg.length(); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino new file mode 100644 index 00000000..b2530877 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringLengthTrim/StringLengthTrim.ino @@ -0,0 +1,42 @@ +/* + String length() and trim() + + Examples of how to use length() and trim() in a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringLengthTrim +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString length() and trim():"); + Serial.println(); +} + +void loop() { + // here's a String with empty spaces at the end (called white space): + String stringOne = "Hello! "; + Serial.print(stringOne); + Serial.print("<--- end of string. Length: "); + Serial.println(stringOne.length()); + + // trim the white space off the string: + stringOne.trim(); + Serial.print(stringOne); + Serial.print("<--- end of trimmed string. Length: "); + Serial.println(stringOne.length()); + + // do nothing while true: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringReplace/StringReplace.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringReplace/StringReplace.ino new file mode 100644 index 00000000..907f5d01 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/08.Strings/StringReplace/StringReplace.ino @@ -0,0 +1,50 @@ +/* + String replace() + + Examples of how to replace characters or substrings of a String + + created 27 Jul 2010 + modified 2 Apr 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/StringReplace +*/ + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + // send an intro: + Serial.println("\n\nString replace:\n"); + Serial.println(); +} + +void loop() { + String stringOne = ""; + Serial.println(stringOne); + // replace() changes all instances of one substring with another: + // first, make a copy of the original string: + String stringTwo = stringOne; + // then perform the replacements: + stringTwo.replace("<", " 0) { + int inChar = Serial.read(); + if (isDigit(inChar)) { + // convert the incoming byte to a char and add it to the string: + inString += (char)inChar; + } + // if you get a newline, print the string, then the string's value: + if (inChar == '\n') { + Serial.print("Value:"); + Serial.println(inString.toInt()); + Serial.print("String: "); + Serial.println(inString); + // clear the string for new input: + inString = ""; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino new file mode 100644 index 00000000..28c59f97 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardLogout/KeyboardLogout.ino @@ -0,0 +1,89 @@ +/* + Keyboard logout + + This sketch demonstrates the Keyboard library. + + When you connect pin 2 to ground, it performs a logout. + It uses keyboard combinations to do this, as follows: + + On Windows, CTRL-ALT-DEL followed by ALT-l + On Ubuntu, CTRL-ALT-DEL, and ENTER + On OSX, CMD-SHIFT-q + + To wake: Spacebar. + + Circuit: + - Arduino Leonardo or Micro + - wire to connect D2 to ground + + created 6 Mar 2012 + modified 27 Mar 2012 + by Tom Igoe + + This example is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardLogout +*/ + +#define OSX 0 +#define WINDOWS 1 +#define UBUNTU 2 + +#include "Keyboard.h" + +// change this to match your platform: +int platform = OSX; + +void setup() { + // make pin 2 an input and turn on the pull-up resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + Keyboard.begin(); +} + +void loop() { + while (digitalRead(2) == HIGH) { + // do nothing until pin 2 goes low + delay(500); + } + delay(1000); + + switch (platform) { + case OSX: + Keyboard.press(KEY_LEFT_GUI); + // Shift-Q logs out: + Keyboard.press(KEY_LEFT_SHIFT); + Keyboard.press('Q'); + delay(100); + Keyboard.releaseAll(); + // enter: + Keyboard.write(KEY_RETURN); + break; + case WINDOWS: + // CTRL-ALT-DEL: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_DELETE); + delay(100); + Keyboard.releaseAll(); + // ALT-l: + delay(2000); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press('l'); + Keyboard.releaseAll(); + break; + case UBUNTU: + // CTRL-ALT-DEL: + Keyboard.press(KEY_LEFT_CTRL); + Keyboard.press(KEY_LEFT_ALT); + Keyboard.press(KEY_DELETE); + delay(1000); + Keyboard.releaseAll(); + // Enter to confirm logout: + Keyboard.write(KEY_RETURN); + break; + } + + // do nothing: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino new file mode 100644 index 00000000..f0bd32b1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardMessage/KeyboardMessage.ino @@ -0,0 +1,52 @@ +/* + Keyboard Message test + + For the Arduino Leonardo and Micro. + + Sends a text string when a button is pressed. + + The circuit: + - pushbutton attached from pin 4 to +5V + - 10 kilohm resistor attached from pin 4 to ground + + created 24 Oct 2011 + modified 27 Mar 2012 + by Tom Igoe + modified 11 Nov 2013 + by Scott Fitzgerald + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardMessage +*/ + +#include "Keyboard.h" + +const int buttonPin = 4; // input pin for pushbutton +int previousButtonState = HIGH; // for checking the state of a pushButton +int counter = 0; // button push counter + +void setup() { + // make the pushButton pin an input: + pinMode(buttonPin, INPUT); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + // read the pushbutton: + int buttonState = digitalRead(buttonPin); + // if the button state has changed, + if ((buttonState != previousButtonState) + // and it's currently pressed: + && (buttonState == HIGH)) { + // increment the button counter + counter++; + // type out a message + Keyboard.print("You pressed the button "); + Keyboard.print(counter); + Keyboard.println(" times."); + } + // save the current button state for comparison next time: + previousButtonState = buttonState; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino new file mode 100644 index 00000000..d86f944a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardReprogram/KeyboardReprogram.ino @@ -0,0 +1,103 @@ +/* + Arduino Programs Blink + + This sketch demonstrates the Keyboard library. + + For Leonardo and Due boards only. + + When you connect pin 2 to ground, it creates a new window with a key + combination (CTRL-N), then types in the Blink sketch, then auto-formats the + text using another key combination (CTRL-T), then uploads the sketch to the + currently selected Arduino using a final key combination (CTRL-U). + + Circuit: + - Arduino Leonardo, Micro, Due, LilyPad USB, or Yún + - wire to connect D2 to ground + + created 5 Mar 2012 + modified 29 Mar 2012 + by Tom Igoe + modified 3 May 2014 + by Scott Fitzgerald + + This example is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardReprogram +*/ + +#include "Keyboard.h" + +// use this option for OSX. +// Comment it out if using Windows or Linux: +char ctrlKey = KEY_LEFT_GUI; +// use this option for Windows and Linux. +// leave commented out if using OSX: +// char ctrlKey = KEY_LEFT_CTRL; + + +void setup() { + // make pin 2 an input and turn on the pull-up resistor so it goes high unless + // connected to ground: + pinMode(2, INPUT_PULLUP); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + while (digitalRead(2) == HIGH) { + // do nothing until pin 2 goes low + delay(500); + } + delay(1000); + // new document: + Keyboard.press(ctrlKey); + Keyboard.press('n'); + delay(100); + Keyboard.releaseAll(); + // wait for new window to open: + delay(1000); + + // versions of the Arduino IDE after 1.5 pre-populate new sketches with + // setup() and loop() functions let's clear the window before typing anything new + // select all + Keyboard.press(ctrlKey); + Keyboard.press('a'); + delay(500); + Keyboard.releaseAll(); + // delete the selected text + Keyboard.write(KEY_BACKSPACE); + delay(500); + + // Type out "blink": + Keyboard.println("void setup() {"); + Keyboard.println("pinMode(13, OUTPUT);"); + Keyboard.println("}"); + Keyboard.println(); + Keyboard.println("void loop() {"); + Keyboard.println("digitalWrite(13, HIGH);"); + Keyboard.print("delay(3000);"); + // 3000 ms is too long. Delete it: + for (int keystrokes = 0; keystrokes < 6; keystrokes++) { + delay(500); + Keyboard.write(KEY_BACKSPACE); + } + // make it 1000 instead: + Keyboard.println("1000);"); + Keyboard.println("digitalWrite(13, LOW);"); + Keyboard.println("delay(1000);"); + Keyboard.println("}"); + // tidy up: + Keyboard.press(ctrlKey); + Keyboard.press('t'); + delay(100); + Keyboard.releaseAll(); + delay(3000); + // upload code: + Keyboard.press(ctrlKey); + Keyboard.press('u'); + delay(100); + Keyboard.releaseAll(); + + // wait for the sweet oblivion of reprogramming: + while (true); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino new file mode 100644 index 00000000..050bb18c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Keyboard/KeyboardSerial/KeyboardSerial.ino @@ -0,0 +1,39 @@ +/* + Keyboard test + + For the Arduino Leonardo, Micro or Due + + Reads a byte from the serial port, sends a keystroke back. + The sent keystroke is one higher than what's received, e.g. if you send a, + you get b, send A you get B, and so forth. + + The circuit: + - none + + created 21 Oct 2011 + modified 27 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardSerial +*/ + +#include "Keyboard.h" + +void setup() { + // open the serial port: + Serial.begin(9600); + // initialize control over the keyboard: + Keyboard.begin(); +} + +void loop() { + // check for incoming serial data: + if (Serial.available() > 0) { + // read incoming serial data: + char inChar = Serial.read(); + // Type the next ASCII value from what you received: + Keyboard.write(inChar + 1); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino new file mode 100644 index 00000000..88500671 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/KeyboardAndMouseControl/KeyboardAndMouseControl.ino @@ -0,0 +1,93 @@ +/* + KeyboardAndMouseControl + + Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due. + + Hardware: + - five pushbuttons attached to D2, D3, D4, D5, D6 + + The mouse movement is always relative. This sketch reads four pushbuttons, and + uses them to set the movement of the mouse. + + WARNING: When you use the Mouse.move() command, the Arduino takes over your + mouse! Make sure you have control before you use the mouse commands. + + created 15 Mar 2012 + modified 27 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/KeyboardAndMouseControl +*/ + +#include "Keyboard.h" +#include "Mouse.h" + +// set pin numbers for the five buttons: +const int upButton = 2; +const int downButton = 3; +const int leftButton = 4; +const int rightButton = 5; +const int mouseButton = 6; + +void setup() { // initialize the buttons' inputs: + pinMode(upButton, INPUT); + pinMode(downButton, INPUT); + pinMode(leftButton, INPUT); + pinMode(rightButton, INPUT); + pinMode(mouseButton, INPUT); + + Serial.begin(9600); + // initialize mouse control: + Mouse.begin(); + Keyboard.begin(); +} + +void loop() { + // use serial input to control the mouse: + if (Serial.available() > 0) { + char inChar = Serial.read(); + + switch (inChar) { + case 'u': + // move mouse up + Mouse.move(0, -40); + break; + case 'd': + // move mouse down + Mouse.move(0, 40); + break; + case 'l': + // move mouse left + Mouse.move(-40, 0); + break; + case 'r': + // move mouse right + Mouse.move(40, 0); + break; + case 'm': + // perform mouse left click + Mouse.click(MOUSE_LEFT); + break; + } + } + + // use the pushbuttons to control the keyboard: + if (digitalRead(upButton) == HIGH) { + Keyboard.write('u'); + } + if (digitalRead(downButton) == HIGH) { + Keyboard.write('d'); + } + if (digitalRead(leftButton) == HIGH) { + Keyboard.write('l'); + } + if (digitalRead(rightButton) == HIGH) { + Keyboard.write('r'); + } + if (digitalRead(mouseButton) == HIGH) { + Keyboard.write('m'); + } + +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino new file mode 100644 index 00000000..2e0da7a4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/ButtonMouseControl/ButtonMouseControl.ino @@ -0,0 +1,84 @@ +/* + ButtonMouseControl + + For Leonardo and Due boards only. + + Controls the mouse from five pushbuttons on an Arduino Leonardo, Micro or Due. + + Hardware: + - five pushbuttons attached to D2, D3, D4, D5, D6 + + The mouse movement is always relative. This sketch reads four pushbuttons, + and uses them to set the movement of the mouse. + + WARNING: When you use the Mouse.move() command, the Arduino takes over your + mouse! Make sure you have control before you use the mouse commands. + + created 15 Mar 2012 + modified 27 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/ButtonMouseControl +*/ + +#include "Mouse.h" + +// set pin numbers for the five buttons: +const int upButton = 2; +const int downButton = 3; +const int leftButton = 4; +const int rightButton = 5; +const int mouseButton = 6; + +int range = 5; // output range of X or Y movement; affects movement speed +int responseDelay = 10; // response delay of the mouse, in ms + + +void setup() { + // initialize the buttons' inputs: + pinMode(upButton, INPUT); + pinMode(downButton, INPUT); + pinMode(leftButton, INPUT); + pinMode(rightButton, INPUT); + pinMode(mouseButton, INPUT); + // initialize mouse control: + Mouse.begin(); +} + +void loop() { + // read the buttons: + int upState = digitalRead(upButton); + int downState = digitalRead(downButton); + int rightState = digitalRead(rightButton); + int leftState = digitalRead(leftButton); + int clickState = digitalRead(mouseButton); + + // calculate the movement distance based on the button states: + int xDistance = (leftState - rightState) * range; + int yDistance = (upState - downState) * range; + + // if X or Y is non-zero, move: + if ((xDistance != 0) || (yDistance != 0)) { + Mouse.move(xDistance, yDistance, 0); + } + + // if the mouse button is pressed: + if (clickState == HIGH) { + // if the mouse is not pressed, press it: + if (!Mouse.isPressed(MOUSE_LEFT)) { + Mouse.press(MOUSE_LEFT); + } + } + // else the mouse button is not pressed: + else { + // if the mouse is pressed, release it: + if (Mouse.isPressed(MOUSE_LEFT)) { + Mouse.release(MOUSE_LEFT); + } + } + + // a delay so the mouse doesn't move too fast: + delay(responseDelay); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino new file mode 100644 index 00000000..92d00f6d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.ino @@ -0,0 +1,120 @@ +/* + JoystickMouseControl + + Controls the mouse from a joystick on an Arduino Leonardo, Micro or Due. + Uses a pushbutton to turn on and off mouse control, and a second pushbutton + to click the left mouse button. + + Hardware: + - 2-axis joystick connected to pins A0 and A1 + - pushbuttons connected to pin D2 and D3 + + The mouse movement is always relative. This sketch reads two analog inputs + that range from 0 to 1023 (or less on either end) and translates them into + ranges of -6 to 6. + The sketch assumes that the joystick resting values are around the middle of + the range, but that they vary within a threshold. + + WARNING: When you use the Mouse.move() command, the Arduino takes over your + mouse! Make sure you have control before you use the command. This sketch + includes a pushbutton to toggle the mouse control state, so you can turn on + and off mouse control. + + created 15 Sep 2011 + updated 28 Mar 2012 + by Tom Igoe + + This example code is in the public domain. + + https://www.arduino.cc/en/Tutorial/BuiltInExamples/JoystickMouseControl +*/ + +#include "Mouse.h" + +// set pin numbers for switch, joystick axes, and LED: +const int switchPin = 2; // switch to turn on and off mouse control +const int mouseButton = 3; // input pin for the mouse pushButton +const int xAxis = A0; // joystick X axis +const int yAxis = A1; // joystick Y axis +const int ledPin = 5; // Mouse control LED + +// parameters for reading the joystick: +int range = 12; // output range of X or Y movement +int responseDelay = 5; // response delay of the mouse, in ms +int threshold = range / 4; // resting threshold +int center = range / 2; // resting position value + +bool mouseIsActive = false; // whether or not to control the mouse +int lastSwitchState = LOW; // previous switch state + +void setup() { + pinMode(switchPin, INPUT); // the switch pin + pinMode(ledPin, OUTPUT); // the LED pin + // take control of the mouse: + Mouse.begin(); +} + +void loop() { + // read the switch: + int switchState = digitalRead(switchPin); + // if it's changed and it's high, toggle the mouse state: + if (switchState != lastSwitchState) { + if (switchState == HIGH) { + mouseIsActive = !mouseIsActive; + // turn on LED to indicate mouse state: + digitalWrite(ledPin, mouseIsActive); + } + } + // save switch state for next comparison: + lastSwitchState = switchState; + + // read and scale the two axes: + int xReading = readAxis(A0); + int yReading = readAxis(A1); + + // if the mouse control state is active, move the mouse: + if (mouseIsActive) { + Mouse.move(xReading, yReading, 0); + } + + // read the mouse button and click or not click: + // if the mouse button is pressed: + if (digitalRead(mouseButton) == HIGH) { + // if the mouse is not pressed, press it: + if (!Mouse.isPressed(MOUSE_LEFT)) { + Mouse.press(MOUSE_LEFT); + } + } + // else the mouse button is not pressed: + else { + // if the mouse is pressed, release it: + if (Mouse.isPressed(MOUSE_LEFT)) { + Mouse.release(MOUSE_LEFT); + } + } + + delay(responseDelay); +} + +/* + reads an axis (0 or 1 for x or y) and scales the analog input range to a range + from 0 to +*/ + +int readAxis(int thisAxis) { + // read the analog input: + int reading = analogRead(thisAxis); + + // map the reading from the analog input range to the output range: + reading = map(reading, 0, 1023, 0, range); + + // if the output reading is outside from the rest position threshold, use it: + int distance = reading - center; + + if (abs(distance) < threshold) { + distance = 0; + } + + // return the distance for this axis: + return distance; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.txt b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.txt new file mode 100644 index 00000000..55fa2bc4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/09.USB/Mouse/JoystickMouseControl/JoystickMouseControl.txt @@ -0,0 +1 @@ +Controls a computer's cursor movement with a Joystick when a button is pressed. \ No newline at end of file diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino new file mode 100644 index 00000000..5acf9dec --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p02_SpaceshipInterface/p02_SpaceshipInterface.ino @@ -0,0 +1,63 @@ +/* + Arduino Starter Kit example + Project 2 - Spaceship Interface + + This sketch is written to accompany Project 2 in the Arduino Starter Kit + + Parts required: + - one green LED + - two red LEDs + - pushbutton + - 10 kilohm resistor + - three 220 ohm resistors + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// Create a global variable to hold the state of the switch. This variable is +// persistent throughout the program. Whenever you refer to switchState, you’re +// talking about the number it holds +int switchstate = 0; + +void setup() { + // declare the LED pins as outputs + pinMode(3, OUTPUT); + pinMode(4, OUTPUT); + pinMode(5, OUTPUT); + + // declare the switch pin as an input + pinMode(2, INPUT); +} + +void loop() { + + // read the value of the switch + // digitalRead() checks to see if there is voltage on the pin or not + switchstate = digitalRead(2); + + // if the button is not pressed turn on the green LED and off the red LEDs + if (switchstate == LOW) { + digitalWrite(3, HIGH); // turn the green LED on pin 3 on + digitalWrite(4, LOW); // turn the red LED on pin 4 off + digitalWrite(5, LOW); // turn the red LED on pin 5 off + } + // this else is part of the above if() statement. + // if the switch is not LOW (the button is pressed) turn off the green LED and + // blink alternatively the red LEDs + else { + digitalWrite(3, LOW); // turn the green LED on pin 3 off + digitalWrite(4, LOW); // turn the red LED on pin 4 off + digitalWrite(5, HIGH); // turn the red LED on pin 5 on + // wait for a quarter second before changing the light + delay(250); + digitalWrite(4, HIGH); // turn the red LED on pin 4 on + digitalWrite(5, LOW); // turn the red LED on pin 5 off + // wait for a quarter second before changing the light + delay(250); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino new file mode 100644 index 00000000..57959ed5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p03_LoveOMeter/p03_LoveOMeter.ino @@ -0,0 +1,81 @@ +/* + Arduino Starter Kit example + Project 3 - Love-O-Meter + + This sketch is written to accompany Project 3 in the Arduino Starter Kit + + Parts required: + - one TMP36 temperature sensor + - three red LEDs + - three 220 ohm resistors + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// named constant for the pin the sensor is connected to +const int sensorPin = A0; +// room temperature in Celsius +const float baselineTemp = 20.0; + +void setup() { + // open a serial connection to display values + Serial.begin(9600); + // set the LED pins as outputs + // the for() loop saves some extra coding + for (int pinNumber = 2; pinNumber < 5; pinNumber++) { + pinMode(pinNumber, OUTPUT); + digitalWrite(pinNumber, LOW); + } +} + +void loop() { + // read the value on AnalogIn pin 0 and store it in a variable + int sensorVal = analogRead(sensorPin); + + // send the 10-bit sensor value out the serial port + Serial.print("sensor Value: "); + Serial.print(sensorVal); + + // convert the ADC reading to voltage + float voltage = (sensorVal / 1024.0) * 5.0; + + // Send the voltage level out the Serial port + Serial.print(", Volts: "); + Serial.print(voltage); + + // convert the voltage to temperature in degrees C + // the sensor changes 10 mV per degree + // the datasheet says there's a 500 mV offset + // ((voltage - 500 mV) times 100) + Serial.print(", degrees C: "); + float temperature = (voltage - .5) * 100; + Serial.println(temperature); + + // if the current temperature is lower than the baseline turn off all LEDs + if (temperature < baselineTemp + 2) { + digitalWrite(2, LOW); + digitalWrite(3, LOW); + digitalWrite(4, LOW); + } // if the temperature rises 2-4 degrees, turn an LED on + else if (temperature >= baselineTemp + 2 && temperature < baselineTemp + 4) { + digitalWrite(2, HIGH); + digitalWrite(3, LOW); + digitalWrite(4, LOW); + } // if the temperature rises 4-6 degrees, turn a second LED on + else if (temperature >= baselineTemp + 4 && temperature < baselineTemp + 6) { + digitalWrite(2, HIGH); + digitalWrite(3, HIGH); + digitalWrite(4, LOW); + } // if the temperature rises more than 6 degrees, turn all LEDs on + else if (temperature >= baselineTemp + 6) { + digitalWrite(2, HIGH); + digitalWrite(3, HIGH); + digitalWrite(4, HIGH); + } + delay(1); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino new file mode 100644 index 00000000..09f3121d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p04_ColorMixingLamp/p04_ColorMixingLamp.ino @@ -0,0 +1,96 @@ +/* + Arduino Starter Kit example + Project 4 - Color Mixing Lamp + + This sketch is written to accompany Project 3 in the Arduino Starter Kit + + Parts required: + - one RGB LED + - three 10 kilohm resistors + - three 220 ohm resistors + - three photoresistors + - red green and blue colored gels + + created 13 Sep 2012 + modified 14 Nov 2012 + by Scott Fitzgerald + Thanks to Federico Vanzati for improvements + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +const int greenLEDPin = 9; // LED connected to digital pin 9 +const int redLEDPin = 10; // LED connected to digital pin 10 +const int blueLEDPin = 11; // LED connected to digital pin 11 + +const int redSensorPin = A0; // pin with the photoresistor with the red gel +const int greenSensorPin = A1; // pin with the photoresistor with the green gel +const int blueSensorPin = A2; // pin with the photoresistor with the blue gel + +int redValue = 0; // value to write to the red LED +int greenValue = 0; // value to write to the green LED +int blueValue = 0; // value to write to the blue LED + +int redSensorValue = 0; // variable to hold the value from the red sensor +int greenSensorValue = 0; // variable to hold the value from the green sensor +int blueSensorValue = 0; // variable to hold the value from the blue sensor + +void setup() { + // initialize serial communications at 9600 bps: + Serial.begin(9600); + + // set the digital pins as outputs + pinMode(greenLEDPin, OUTPUT); + pinMode(redLEDPin, OUTPUT); + pinMode(blueLEDPin, OUTPUT); +} + +void loop() { + // Read the sensors first: + + // read the value from the red-filtered photoresistor: + redSensorValue = analogRead(redSensorPin); + // give the ADC a moment to settle + delay(5); + // read the value from the green-filtered photoresistor: + greenSensorValue = analogRead(greenSensorPin); + // give the ADC a moment to settle + delay(5); + // read the value from the blue-filtered photoresistor: + blueSensorValue = analogRead(blueSensorPin); + + // print out the values to the Serial Monitor + Serial.print("raw sensor Values \t red: "); + Serial.print(redSensorValue); + Serial.print("\t green: "); + Serial.print(greenSensorValue); + Serial.print("\t Blue: "); + Serial.println(blueSensorValue); + + /* + In order to use the values from the sensor for the LED, you need to do some + math. The ADC provides a 10-bit number, but analogWrite() uses 8 bits. + You'll want to divide your sensor readings by 4 to keep them in range + of the output. + */ + redValue = redSensorValue / 4; + greenValue = greenSensorValue / 4; + blueValue = blueSensorValue / 4; + + // print out the mapped values + Serial.print("Mapped sensor Values \t red: "); + Serial.print(redValue); + Serial.print("\t green: "); + Serial.print(greenValue); + Serial.print("\t Blue: "); + Serial.println(blueValue); + + /* + Now that you have a usable value, it's time to PWM the LED. + */ + analogWrite(redLEDPin, redValue); + analogWrite(greenLEDPin, greenValue); + analogWrite(blueLEDPin, blueValue); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino new file mode 100644 index 00000000..9e042ed9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p05_ServoMoodIndicator/p05_ServoMoodIndicator.ino @@ -0,0 +1,52 @@ +/* + Arduino Starter Kit example + Project 5 - Servo Mood Indicator + + This sketch is written to accompany Project 5 in the Arduino Starter Kit + + Parts required: + - servo motor + - 10 kilohm potentiometer + - two 100 uF electrolytic capacitors + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// include the Servo library +#include + +Servo myServo; // create a servo object + +int const potPin = A0; // analog pin used to connect the potentiometer +int potVal; // variable to read the value from the analog pin +int angle; // variable to hold the angle for the servo motor + +void setup() { + myServo.attach(9); // attaches the servo on pin 9 to the servo object + Serial.begin(9600); // open a serial connection to your computer +} + +void loop() { + potVal = analogRead(potPin); // read the value of the potentiometer + // print out the value to the Serial Monitor + Serial.print("potVal: "); + Serial.print(potVal); + + // scale the numbers from the pot + angle = map(potVal, 0, 1023, 0, 179); + + // print out the angle for the servo motor + Serial.print(", angle: "); + Serial.println(angle); + + // set the servo position + myServo.write(angle); + + // wait for the servo to get there + delay(15); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino new file mode 100644 index 00000000..1b794058 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p06_LightTheremin/p06_LightTheremin.ino @@ -0,0 +1,62 @@ +/* + Arduino Starter Kit example + Project 6 - Light Theremin + + This sketch is written to accompany Project 6 in the Arduino Starter Kit + + Parts required: + - photoresistor + - 10 kilohm resistor + - piezo + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// variable to hold sensor value +int sensorValue; +// variable to calibrate low value +int sensorLow = 1023; +// variable to calibrate high value +int sensorHigh = 0; +// LED pin +const int ledPin = 13; + +void setup() { + // Make the LED pin an output and turn it on + pinMode(ledPin, OUTPUT); + digitalWrite(ledPin, HIGH); + + // calibrate for the first five seconds after program runs + while (millis() < 5000) { + // record the maximum sensor value + sensorValue = analogRead(A0); + if (sensorValue > sensorHigh) { + sensorHigh = sensorValue; + } + // record the minimum sensor value + if (sensorValue < sensorLow) { + sensorLow = sensorValue; + } + } + // turn the LED off, signaling the end of the calibration period + digitalWrite(ledPin, LOW); +} + +void loop() { + //read the input from A0 and store it in a variable + sensorValue = analogRead(A0); + + // map the sensor values to a wide range of pitches + int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000); + + // play the tone for 20 ms on pin 8 + tone(8, pitch, 20); + + // wait for a moment + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino new file mode 100644 index 00000000..bf53da7c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p07_Keyboard/p07_Keyboard.ino @@ -0,0 +1,54 @@ +/* + Arduino Starter Kit example + Project 7 - Keyboard + + This sketch is written to accompany Project 7 in the Arduino Starter Kit + + Parts required: + - two 10 kilohm resistors + - 1 megohm resistor + - 220 ohm resistor + - four pushbuttons + - piezo + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// create an array of notes +// the numbers below correspond to the frequencies of middle C, D, E, and F +int notes[] = {262, 294, 330, 349}; + +void setup() { + //start serial communication + Serial.begin(9600); +} + +void loop() { + // create a local variable to hold the input on pin A0 + int keyVal = analogRead(A0); + // send the value from A0 to the Serial Monitor + Serial.println(keyVal); + + // play the note corresponding to each value on A0 + if (keyVal == 1023) { + // play the first frequency in the array on pin 8 + tone(8, notes[0]); + } else if (keyVal >= 990 && keyVal <= 1010) { + // play the second frequency in the array on pin 8 + tone(8, notes[1]); + } else if (keyVal >= 505 && keyVal <= 515) { + // play the third frequency in the array on pin 8 + tone(8, notes[2]); + } else if (keyVal >= 5 && keyVal <= 10) { + // play the fourth frequency in the array on pin 8 + tone(8, notes[3]); + } else { + // if the value is out of range, play no tone + noTone(8); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino new file mode 100644 index 00000000..0d7004b9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p08_DigitalHourglass/p08_DigitalHourglass.ino @@ -0,0 +1,79 @@ +/* + Arduino Starter Kit example + Project 8 - Digital Hourglass + + This sketch is written to accompany Project 8 in the Arduino Starter Kit + + Parts required: + - 10 kilohm resistor + - six 220 ohm resistors + - six LEDs + - tilt switch + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// named constant for the switch pin +const int switchPin = 8; + +unsigned long previousTime = 0; // store the last time an LED was updated +int switchState = 0; // the current switch state +int prevSwitchState = 0; // the previous switch state +int led = 2; // a variable to refer to the LEDs + +// 600000 = 10 minutes in milliseconds +long interval = 600000; // interval at which to light the next LED + +void setup() { + // set the LED pins as outputs + for (int x = 2; x < 8; x++) { + pinMode(x, OUTPUT); + } + // set the tilt switch pin as input + pinMode(switchPin, INPUT); +} + +void loop() { + // store the time since the Arduino started running in a variable + unsigned long currentTime = millis(); + + // compare the current time to the previous time an LED turned on + // if it is greater than your interval, run the if statement + if (currentTime - previousTime > interval) { + // save the current time as the last time you changed an LED + previousTime = currentTime; + // Turn the LED on + digitalWrite(led, HIGH); + // increment the led variable + // in 10 minutes the next LED will light up + led++; + + if (led == 7) { + // the hour is up + } + } + + // read the switch value + switchState = digitalRead(switchPin); + + // if the switch has changed + if (switchState != prevSwitchState) { + // turn all the LEDs low + for (int x = 2; x < 8; x++) { + digitalWrite(x, LOW); + } + + // reset the LED variable to the first one + led = 2; + + //reset the timer + previousTime = currentTime; + } + // set the previous switch state to the current state + prevSwitchState = switchState; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino new file mode 100644 index 00000000..56c465de --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p09_MotorizedPinwheel/p09_MotorizedPinwheel.ino @@ -0,0 +1,48 @@ +/* + Arduino Starter Kit example + Project 9 - Motorized Pinwheel + + This sketch is written to accompany Project 9 in the Arduino Starter Kit + + Parts required: + - 10 kilohm resistor + - pushbutton + - motor + - 9V battery + - IRF520 MOSFET + - 1N4007 diode + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// named constants for the switch and motor pins +const int switchPin = 2; // the number of the switch pin +const int motorPin = 9; // the number of the motor pin + +int switchState = 0; // variable for reading the switch's status + +void setup() { + // initialize the motor pin as an output: + pinMode(motorPin, OUTPUT); + // initialize the switch pin as an input: + pinMode(switchPin, INPUT); +} + +void loop() { + // read the state of the switch value: + switchState = digitalRead(switchPin); + + // check if the switch is pressed. + if (switchState == HIGH) { + // turn motor on: + digitalWrite(motorPin, HIGH); + } else { + // turn motor off: + digitalWrite(motorPin, LOW); + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino new file mode 100644 index 00000000..69ac37e9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p10_Zoetrope/p10_Zoetrope.ino @@ -0,0 +1,103 @@ +/* + Arduino Starter Kit example + Project 10 - Zoetrope + + This sketch is written to accompany Project 10 in the Arduino Starter Kit + + Parts required: + - two 10 kilohm resistors + - two momentary pushbuttons + - one 10 kilohm potentiometer + - motor + - 9V battery + - H-Bridge + + created 13 Sep 2012 + by Scott Fitzgerald + Thanks to Federico Vanzati for improvements + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +const int controlPin1 = 2; // connected to pin 7 on the H-bridge +const int controlPin2 = 3; // connected to pin 2 on the H-bridge +const int enablePin = 9; // connected to pin 1 on the H-bridge +const int directionSwitchPin = 4; // connected to the switch for direction +const int onOffSwitchStateSwitchPin = 5; // connected to the switch for turning the motor on and off +const int potPin = A0; // connected to the potentiometer's output + +// create some variables to hold values from your inputs +int onOffSwitchState = 0; // current state of the on/off switch +int previousOnOffSwitchState = 0; // previous position of the on/off switch +int directionSwitchState = 0; // current state of the direction switch +int previousDirectionSwitchState = 0; // previous state of the direction switch + +int motorEnabled = 0; // Turns the motor on/off +int motorSpeed = 0; // speed of the motor +int motorDirection = 1; // current direction of the motor + +void setup() { + // initialize the inputs and outputs + pinMode(directionSwitchPin, INPUT); + pinMode(onOffSwitchStateSwitchPin, INPUT); + pinMode(controlPin1, OUTPUT); + pinMode(controlPin2, OUTPUT); + pinMode(enablePin, OUTPUT); + + // pull the enable pin LOW to start + digitalWrite(enablePin, LOW); +} + +void loop() { + // read the value of the on/off switch + onOffSwitchState = digitalRead(onOffSwitchStateSwitchPin); + delay(1); + + // read the value of the direction switch + directionSwitchState = digitalRead(directionSwitchPin); + + // read the value of the pot and divide by 4 to get a value that can be + // used for PWM + motorSpeed = analogRead(potPin) / 4; + + // if the on/off button changed state since the last loop() + if (onOffSwitchState != previousOnOffSwitchState) { + // change the value of motorEnabled if pressed + if (onOffSwitchState == HIGH) { + motorEnabled = !motorEnabled; + } + } + + // if the direction button changed state since the last loop() + if (directionSwitchState != previousDirectionSwitchState) { + // change the value of motorDirection if pressed + if (directionSwitchState == HIGH) { + motorDirection = !motorDirection; + } + } + + // change the direction the motor spins by talking to the control pins + // on the H-Bridge + if (motorDirection == 1) { + digitalWrite(controlPin1, HIGH); + digitalWrite(controlPin2, LOW); + } else { + digitalWrite(controlPin1, LOW); + digitalWrite(controlPin2, HIGH); + } + + // if the motor is supposed to be on + if (motorEnabled == 1) { + // PWM the enable pin to vary the speed + analogWrite(enablePin, motorSpeed); + } else { // if the motor is not supposed to be on + //turn the motor off + analogWrite(enablePin, 0); + } + // save the current on/off switch state as the previous + previousDirectionSwitchState = directionSwitchState; + // save the current switch state as the previous + previousOnOffSwitchState = onOffSwitchState; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino new file mode 100644 index 00000000..a5a6acb4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p11_CrystalBall/p11_CrystalBall.ino @@ -0,0 +1,114 @@ +/* + Arduino Starter Kit example + Project 11 - Crystal Ball + + This sketch is written to accompany Project 11 in the Arduino Starter Kit + + Parts required: + - 220 ohm resistor + - 10 kilohm resistor + - 10 kilohm potentiometer + - 16x2 LCD screen + - tilt switch + + created 13 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// include the library code: +#include + +// initialize the library with the numbers of the interface pins +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); + +// set up a constant for the tilt switch pin +const int switchPin = 6; + +// variable to hold the value of the switch pin +int switchState = 0; + +// variable to hold previous value of the switch pin +int prevSwitchState = 0; + +// a variable to choose which reply from the crystal ball +int reply; + +void setup() { + // set up the number of columns and rows on the LCD + lcd.begin(16, 2); + + // set up the switch pin as an input + pinMode(switchPin, INPUT); + + // Print a message to the LCD. + lcd.print("Ask the"); + // set the cursor to column 0, line 1 + // line 1 is the second row, since counting begins with 0 + lcd.setCursor(0, 1); + // print to the second line + lcd.print("Crystal Ball!"); +} + +void loop() { + // check the status of the switch + switchState = digitalRead(switchPin); + + // compare the switchState to its previous state + if (switchState != prevSwitchState) { + // if the state has changed from HIGH to LOW you know that the ball has been + // tilted from one direction to the other + if (switchState == LOW) { + // randomly chose a reply + reply = random(8); + // clean up the screen before printing a new reply + lcd.clear(); + // set the cursor to column 0, line 0 + lcd.setCursor(0, 0); + // print some text + lcd.print("the ball says:"); + // move the cursor to the second line + lcd.setCursor(0, 1); + + // choose a saying to print based on the value in reply + switch (reply) { + case 0: + lcd.print("Yes"); + break; + + case 1: + lcd.print("Most likely"); + break; + + case 2: + lcd.print("Certainly"); + break; + + case 3: + lcd.print("Outlook good"); + break; + + case 4: + lcd.print("Unsure"); + break; + + case 5: + lcd.print("Ask again"); + break; + + case 6: + lcd.print("Doubtful"); + break; + + case 7: + lcd.print("No"); + break; + } + } + } + // save the current switch state as the last state + prevSwitchState = switchState; +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino new file mode 100644 index 00000000..a9523071 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p12_KnockLock/p12_KnockLock.ino @@ -0,0 +1,171 @@ +/* + Arduino Starter Kit example + Project 12 - Knock Lock + + This sketch is written to accompany Project 12 in the Arduino Starter Kit + + Parts required: + - 1 megohm resistor + - 10 kilohm resistor + - three 220 ohm resistors + - piezo + - servo motor + - push button + - one red LED + - one yellow LED + - one green LED + - 100 uF capacitor + + created 18 Sep 2012 + by Scott Fitzgerald + Thanks to Federico Vanzati for improvements + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// import the library +#include +// create an instance of the Servo library +Servo myServo; + +const int piezo = A0; // pin the piezo is attached to +const int switchPin = 2; // pin the switch is attached to +const int yellowLed = 3; // pin the yellow LED is attached to +const int greenLed = 4; // pin the green LED is attached to +const int redLed = 5; // pin the red LED is attached to + +// variable for the piezo value +int knockVal; +// variable for the switch value +int switchVal; + +// variables for the high and low limits of the knock value +const int quietKnock = 10; +const int loudKnock = 100; + +// variable to indicate if locked or not +bool locked = false; +// how many valid knocks you've received +int numberOfKnocks = 0; + +void setup() { + // attach the servo to pin 9 + myServo.attach(9); + + // make the LED pins outputs + pinMode(yellowLed, OUTPUT); + pinMode(redLed, OUTPUT); + pinMode(greenLed, OUTPUT); + + // set the switch pin as an input + pinMode(switchPin, INPUT); + + // start serial communication for debugging + Serial.begin(9600); + + // turn the green LED on + digitalWrite(greenLed, HIGH); + + // move the servo to the unlocked position + myServo.write(0); + + // print status to the Serial Monitor + Serial.println("the box is unlocked!"); +} + +void loop() { + + // if the box is unlocked + if (locked == false) { + + // read the value of the switch pin + switchVal = digitalRead(switchPin); + + // if the button is pressed, lock the box + if (switchVal == HIGH) { + // set the locked variable to "true" + locked = true; + + // change the status LEDs + digitalWrite(greenLed, LOW); + digitalWrite(redLed, HIGH); + + // move the servo to the locked position + myServo.write(90); + + // print out status + Serial.println("the box is locked!"); + + // wait for the servo to move into position + delay(1000); + } + } + + // if the box is locked + if (locked == true) { + + // check the value of the piezo + knockVal = analogRead(piezo); + + // if there are not enough valid knocks + if (numberOfKnocks < 3 && knockVal > 0) { + + // check to see if the knock is in range + if (checkForKnock(knockVal) == true) { + + // increment the number of valid knocks + numberOfKnocks++; + } + + // print status of knocks + Serial.print(3 - numberOfKnocks); + Serial.println(" more knocks to go"); + } + + // if there are three knocks + if (numberOfKnocks >= 3) { + // unlock the box + locked = false; + + // move the servo to the unlocked position + myServo.write(0); + + // wait for it to move + delay(20); + + // change status LEDs + digitalWrite(greenLed, HIGH); + digitalWrite(redLed, LOW); + Serial.println("the box is unlocked!"); + + numberOfKnocks = 0; + } + } +} + +// this function checks to see if a detected knock is within max and min range +bool checkForKnock(int value) { + // if the value of the knock is greater than the minimum, and larger + // than the maximum + if (value > quietKnock && value < loudKnock) { + // turn the status LED on + digitalWrite(yellowLed, HIGH); + delay(50); + digitalWrite(yellowLed, LOW); + // print out the status + Serial.print("Valid knock of value "); + Serial.println(value); + // return true + return true; + } + // if the knock is not within range + else { + // print status + Serial.print("Bad knock value "); + Serial.println(value); + // return false + return false; + } +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino new file mode 100644 index 00000000..4f25cbe3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p13_TouchSensorLamp/p13_TouchSensorLamp.ino @@ -0,0 +1,66 @@ +/* + Arduino Starter Kit example + Project 13 - Touch Sensor Lamp + + This sketch is written to accompany Project 13 in the Arduino Starter Kit + + Parts required: + - 1 megohm resistor + - metal foil or copper mesh + - 220 ohm resistor + - LED + + Software required : + - CapacitiveSensor library by Paul Badger + https://www.arduino.cc/reference/en/libraries/capacitivesensor/ + + created 18 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +// import the library (must be located in the Arduino/libraries directory) +#include + +// create an instance of the library +// pin 4 sends electrical energy +// pin 2 senses senses a change +CapacitiveSensor capSensor = CapacitiveSensor(4, 2); + +// threshold for turning the lamp on +int threshold = 1000; + +// pin the LED is connected to +const int ledPin = 12; + + +void setup() { + // open a serial connection + Serial.begin(9600); + // set the LED pin as an output + pinMode(ledPin, OUTPUT); +} + +void loop() { + // store the value reported by the sensor in a variable + long sensorValue = capSensor.capacitiveSensor(30); + + // print out the sensor value + Serial.println(sensorValue); + + // if the value is greater than the threshold + if (sensorValue > threshold) { + // turn the LED on + digitalWrite(ledPin, HIGH); + } + // if it's lower than the threshold + else { + // turn the LED off + digitalWrite(ledPin, LOW); + } + + delay(10); +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino new file mode 100644 index 00000000..043b6003 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p14_TweakTheArduinoLogo/p14_TweakTheArduinoLogo.ino @@ -0,0 +1,101 @@ +/* + Arduino Starter Kit example + Project 14 - Tweak the Arduino Logo + + This sketch is written to accompany Project 14 in the Arduino Starter Kit + + Parts required: + - 10 kilohm potentiometer + + Software required: + - Processing (3.0 or newer) https://processing.org/ + - Active Internet connection + + created 18 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + + +void setup() { + // initialize serial communication + Serial.begin(9600); +} + +void loop() { + // read the value of A0, divide by 4 and send it as a byte over the + // serial connection + Serial.write(analogRead(A0) / 4); + delay(1); +} + +/* Processing code for this example + + // Tweak the Arduino Logo + + // by Scott Fitzgerald + // This example code is in the public domain. + + // import the serial library + import processing.serial.*; + + // create an instance of the serial library + Serial myPort; + + // create an instance of PImage + PImage logo; + + // a variable to hold the background color + int bgcolor = 0; + + void setup() { + size(1, 1); + surface.setResizable(true); + // set the color mode to Hue/Saturation/Brightness + colorMode(HSB, 255); + + // load the Arduino logo into the PImage instance + logo = loadImage("http://www.arduino.cc/arduino_logo.png"); + + // make the window the same size as the image + surface.setSize(logo.width, logo.height); + + // print a list of available serial ports to the Processing status window + println("Available serial ports:"); + println(Serial.list()); + + // Tell the serial object the information it needs to communicate with the + // Arduino. Change Serial.list()[0] to the correct port corresponding to + // your Arduino board. The last parameter (e.g. 9600) is the speed of the + // communication. It has to correspond to the value passed to + // Serial.begin() in your Arduino sketch. + myPort = new Serial(this, Serial.list()[0], 9600); + + // If you know the name of the port used by the Arduino board, you can + // specify it directly like this. + // port = new Serial(this, "COM1", 9600); + } + + void draw() { + + // if there is information in the serial port + if ( myPort.available() > 0) { + // read the value and store it in a variable + bgcolor = myPort.read(); + + // print the value to the status window + println(bgcolor); + } + + // Draw the background. the variable bgcolor contains the Hue, determined by + // the value from the serial port + background(bgcolor, 255, 255); + + // draw the Arduino logo + image(logo, 0, 0); + } + +*/ diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino new file mode 100644 index 00000000..28daed08 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/10.StarterKit_BasicKit/p15_HackingButtons/p15_HackingButtons.ino @@ -0,0 +1,34 @@ +/* + Arduino Starter Kit example + Project 15 - Hacking Buttons + + This sketch is written to accompany Project 15 in the Arduino Starter Kit + + Parts required: + - battery powered component + - 220 ohm resistor + - 4N35 optocoupler + + created 18 Sep 2012 + by Scott Fitzgerald + + https://store.arduino.cc/genuino-starter-kit + + This example code is part of the public domain. +*/ + +const int optoPin = 2; // the pin the optocoupler is connected to + +void setup() { + // make the pin with the optocoupler an output + pinMode(optoPin, OUTPUT); +} + +void loop() { + digitalWrite(optoPin, HIGH); // pull pin 2 HIGH, activating the optocoupler + + delay(15); // give the optocoupler a moment to activate + + digitalWrite(optoPin, LOW); // pull pin 2 low until you're ready to activate again + delay(21000); // wait for 21 seconds +} diff --git a/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino new file mode 100644 index 00000000..3f84d6b1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/samples/arduino/arduino-examples/examples/11.ArduinoISP/ArduinoISP/ArduinoISP.ino @@ -0,0 +1,734 @@ +// ArduinoISP +// Copyright (c) 2008-2011 Randall Bohn +// If you require a license, see +// https://opensource.org/licenses/bsd-license.php +// +// This sketch turns the Arduino into a AVRISP using the following Arduino pins: +// +// Pin 10 is used to reset the target microcontroller. +// +// By default, the hardware SPI pins MISO, MOSI and SCK are used to communicate +// with the target. On all Arduinos, these pins can be found +// on the ICSP/SPI header: +// +// MISO °. . 5V (!) Avoid this pin on Due, Zero... +// SCK . . MOSI +// . . GND +// +// On some Arduinos (Uno,...), pins MOSI, MISO and SCK are the same pins as +// digital pin 11, 12 and 13, respectively. That is why many tutorials instruct +// you to hook up the target to these pins. If you find this wiring more +// practical, have a define USE_OLD_STYLE_WIRING. This will work even when not +// using an Uno. (On an Uno this is not needed). +// +// Alternatively you can use any other digital pin by configuring +// software ('BitBanged') SPI and having appropriate defines for PIN_MOSI, +// PIN_MISO and PIN_SCK. +// +// IMPORTANT: When using an Arduino that is not 5V tolerant (Due, Zero, ...) as +// the programmer, make sure to not expose any of the programmer's pins to 5V. +// A simple way to accomplish this is to power the complete system (programmer +// and target) at 3V3. +// +// Put an LED (with resistor) on the following pins: +// 9: Heartbeat - shows the programmer is running +// 8: Error - Lights up if something goes wrong (use red if that makes sense) +// 7: Programming - In communication with the target +// + +#include "Arduino.h" +#undef SERIAL + + +#define PROG_FLICKER true + +// Configure SPI clock (in Hz). +// E.g. for an ATtiny @ 128 kHz: the datasheet states that both the high and low +// SPI clock pulse must be > 2 CPU cycles, so take 3 cycles i.e. divide target +// f_cpu by 6: +// #define SPI_CLOCK (128000/6) +// +// A clock slow enough for an ATtiny85 @ 1 MHz, is a reasonable default: + +#define SPI_CLOCK (1000000/6) + + +// Select hardware or software SPI, depending on SPI clock. +// Currently only for AVR, for other architectures (Due, Zero,...), hardware SPI +// is probably too fast anyway. + +#if defined(ARDUINO_ARCH_AVR) + + #if SPI_CLOCK > (F_CPU / 128) + #define USE_HARDWARE_SPI + #endif + +#endif + +// Configure which pins to use: + +// The standard pin configuration. +#ifndef ARDUINO_HOODLOADER2 + + #define RESET 10 // Use pin 10 to reset the target rather than SS + #define LED_HB 9 + #define LED_ERR 8 + #define LED_PMODE 7 + + // Uncomment following line to use the old Uno style wiring + // (using pin 11, 12 and 13 instead of the SPI header) on Leonardo, Due... + + // #define USE_OLD_STYLE_WIRING + + #ifdef USE_OLD_STYLE_WIRING + + #define PIN_MOSI 11 + #define PIN_MISO 12 + #define PIN_SCK 13 + + #endif + + // HOODLOADER2 means running sketches on the ATmega16U2 serial converter chips + // on Uno or Mega boards. We must use pins that are broken out: +#else + + #define RESET 4 + #define LED_HB 7 + #define LED_ERR 6 + #define LED_PMODE 5 + +#endif + +// By default, use hardware SPI pins: +#ifndef PIN_MOSI + #define PIN_MOSI MOSI +#endif + +#ifndef PIN_MISO + #define PIN_MISO MISO +#endif + +#ifndef PIN_SCK + #define PIN_SCK SCK +#endif + +// Force bitbanged SPI if not using the hardware SPI pins: +#if (PIN_MISO != MISO) || (PIN_MOSI != MOSI) || (PIN_SCK != SCK) + #undef USE_HARDWARE_SPI +#endif + + +// Configure the serial port to use. +// +// Prefer the USB virtual serial port (aka. native USB port), if the Arduino has one: +// - it does not autoreset (except for the magic baud rate of 1200). +// - it is more reliable because of USB handshaking. +// +// Leonardo and similar have an USB virtual serial port: 'Serial'. +// Due and Zero have an USB virtual serial port: 'SerialUSB'. +// +// On the Due and Zero, 'Serial' can be used too, provided you disable autoreset. +// To use 'Serial': #define SERIAL Serial + +#ifdef SERIAL_PORT_USBVIRTUAL + #define SERIAL SERIAL_PORT_USBVIRTUAL +#else + #define SERIAL Serial +#endif + + +// Configure the baud rate: + +#define BAUDRATE 19200 +// #define BAUDRATE 115200 +// #define BAUDRATE 1000000 + + +#define HWVER 2 +#define SWMAJ 1 +#define SWMIN 18 + +// STK Definitions +#define STK_OK 0x10 +#define STK_FAILED 0x11 +#define STK_UNKNOWN 0x12 +#define STK_INSYNC 0x14 +#define STK_NOSYNC 0x15 +#define CRC_EOP 0x20 //ok it is a space... + +void pulse(int pin, int times); + +#ifdef USE_HARDWARE_SPI +#include "SPI.h" +#else + +#define SPI_MODE0 0x00 + +#if !defined(ARDUINO_API_VERSION) || ARDUINO_API_VERSION != 10001 // A SPISettings class is declared by ArduinoCore-API 1.0.1 +class SPISettings { + public: + // clock is in Hz + SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) : clockFreq(clock) { + (void) bitOrder; + (void) dataMode; + }; + + uint32_t getClockFreq() const { + return clockFreq; + } + + private: + uint32_t clockFreq; +}; +#endif // !defined(ARDUINO_API_VERSION) + +class BitBangedSPI { + public: + void begin() { + digitalWrite(PIN_SCK, LOW); + digitalWrite(PIN_MOSI, LOW); + pinMode(PIN_SCK, OUTPUT); + pinMode(PIN_MOSI, OUTPUT); + pinMode(PIN_MISO, INPUT); + } + + void beginTransaction(SPISettings settings) { + pulseWidth = (500000 + settings.getClockFreq() - 1) / settings.getClockFreq(); + if (pulseWidth == 0) { + pulseWidth = 1; + } + } + + void end() {} + + uint8_t transfer(uint8_t b) { + for (unsigned int i = 0; i < 8; ++i) { + digitalWrite(PIN_MOSI, (b & 0x80) ? HIGH : LOW); + digitalWrite(PIN_SCK, HIGH); + delayMicroseconds(pulseWidth); + b = (b << 1) | digitalRead(PIN_MISO); + digitalWrite(PIN_SCK, LOW); // slow pulse + delayMicroseconds(pulseWidth); + } + return b; + } + + private: + unsigned long pulseWidth; // in microseconds +}; + +static BitBangedSPI SPI; + +#endif + +void setup() { + SERIAL.begin(BAUDRATE); + + pinMode(LED_PMODE, OUTPUT); + pulse(LED_PMODE, 2); + pinMode(LED_ERR, OUTPUT); + pulse(LED_ERR, 2); + pinMode(LED_HB, OUTPUT); + pulse(LED_HB, 2); + +} + +int ISPError = 0; +int pmode = 0; +// address for reading and writing, set by 'U' command +unsigned int here; +uint8_t buff[256]; // global block storage + +#define beget16(addr) (*addr * 256 + *(addr+1) ) +typedef struct param { + uint8_t devicecode; + uint8_t revision; + uint8_t progtype; + uint8_t parmode; + uint8_t polling; + uint8_t selftimed; + uint8_t lockbytes; + uint8_t fusebytes; + uint8_t flashpoll; + uint16_t eeprompoll; + uint16_t pagesize; + uint16_t eepromsize; + uint32_t flashsize; +} +parameter; + +parameter param; + +// this provides a heartbeat on pin 9, so you can tell the software is running. +uint8_t hbval = 128; +int8_t hbdelta = 8; +void heartbeat() { + static unsigned long last_time = 0; + unsigned long now = millis(); + if ((now - last_time) < 40) { + return; + } + last_time = now; + if (hbval > 192) { + hbdelta = -hbdelta; + } + if (hbval < 32) { + hbdelta = -hbdelta; + } + hbval += hbdelta; + analogWrite(LED_HB, hbval); +} + +static bool rst_active_high; + +void reset_target(bool reset) { + digitalWrite(RESET, ((reset && rst_active_high) || (!reset && !rst_active_high)) ? HIGH : LOW); +} + +void loop(void) { + // is pmode active? + if (pmode) { + digitalWrite(LED_PMODE, HIGH); + } else { + digitalWrite(LED_PMODE, LOW); + } + // is there an error? + if (ISPError) { + digitalWrite(LED_ERR, HIGH); + } else { + digitalWrite(LED_ERR, LOW); + } + + // light the heartbeat LED + heartbeat(); + if (SERIAL.available()) { + avrisp(); + } +} + +uint8_t getch() { + while (!SERIAL.available()); + return SERIAL.read(); +} +void fill(int n) { + for (int x = 0; x < n; x++) { + buff[x] = getch(); + } +} + +#define PTIME 30 +void pulse(int pin, int times) { + do { + digitalWrite(pin, HIGH); + delay(PTIME); + digitalWrite(pin, LOW); + delay(PTIME); + } while (times--); +} + +void prog_lamp(int state) { + if (PROG_FLICKER) { + digitalWrite(LED_PMODE, state); + } +} + +uint8_t spi_transaction(uint8_t a, uint8_t b, uint8_t c, uint8_t d) { + SPI.transfer(a); + SPI.transfer(b); + SPI.transfer(c); + return SPI.transfer(d); +} + +void empty_reply() { + if (CRC_EOP == getch()) { + SERIAL.print((char)STK_INSYNC); + SERIAL.print((char)STK_OK); + } else { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + } +} + +void breply(uint8_t b) { + if (CRC_EOP == getch()) { + SERIAL.print((char)STK_INSYNC); + SERIAL.print((char)b); + SERIAL.print((char)STK_OK); + } else { + ISPError++; + SERIAL.print((char)STK_NOSYNC); + } +} + +void get_version(uint8_t c) { + switch (c) { + case 0x80: + breply(HWVER); + break; + case 0x81: + breply(SWMAJ); + break; + case 0x82: + breply(SWMIN); + break; + case 0x93: + breply('S'); // serial programmer + break; + default: + breply(0); + } +} + +void set_parameters() { + // call this after reading parameter packet into buff[] + param.devicecode = buff[0]; + param.revision = buff[1]; + param.progtype = buff[2]; + param.parmode = buff[3]; + param.polling = buff[4]; + param.selftimed = buff[5]; + param.lockbytes = buff[6]; + param.fusebytes = buff[7]; + param.flashpoll = buff[8]; + // ignore buff[9] (= buff[8]) + // following are 16 bits (big endian) + param.eeprompoll = beget16(&buff[10]); + param.pagesize = beget16(&buff[12]); + param.eepromsize = beget16(&buff[14]); + + // 32 bits flashsize (big endian) + param.flashsize = buff[16] * 0x01000000 + + buff[17] * 0x00010000 + + buff[18] * 0x00000100 + + buff[19]; + + // AVR devices have active low reset, AT89Sx are active high + rst_active_high = (param.devicecode >= 0xe0); +} + +void start_pmode() { + + // Reset target before driving PIN_SCK or PIN_MOSI + + // SPI.begin() will configure SS as output, so SPI master mode is selected. + // We have defined RESET as pin 10, which for many Arduinos is not the SS pin. + // So we have to configure RESET as output here, + // (reset_target() first sets the correct level) + reset_target(true); + pinMode(RESET, OUTPUT); + SPI.begin(); + SPI.beginTransaction(SPISettings(SPI_CLOCK, MSBFIRST, SPI_MODE0)); + + // See AVR datasheets, chapter "SERIAL_PRG Programming Algorithm": + + // Pulse RESET after PIN_SCK is low: + digitalWrite(PIN_SCK, LOW); + delay(20); // discharge PIN_SCK, value arbitrarily chosen + reset_target(false); + // Pulse must be minimum 2 target CPU clock cycles so 100 usec is ok for CPU + // speeds above 20 KHz + delayMicroseconds(100); + reset_target(true); + + // Send the enable programming command: + delay(50); // datasheet: must be > 20 msec + spi_transaction(0xAC, 0x53, 0x00, 0x00); + pmode = 1; +} + +void end_pmode() { + SPI.end(); + // We're about to take the target out of reset so configure SPI pins as input + pinMode(PIN_MOSI, INPUT); + pinMode(PIN_SCK, INPUT); + reset_target(false); + pinMode(RESET, INPUT); + pmode = 0; +} + +void universal() { + uint8_t ch; + + fill(4); + ch = spi_transaction(buff[0], buff[1], buff[2], buff[3]); + breply(ch); +} + +void flash(uint8_t hilo, unsigned int addr, uint8_t data) { + spi_transaction(0x40 + 8 * hilo, + addr >> 8 & 0xFF, + addr & 0xFF, + data); +} +void commit(unsigned int addr) { + if (PROG_FLICKER) { + prog_lamp(LOW); + } + spi_transaction(0x4C, (addr >> 8) & 0xFF, addr & 0xFF, 0); + if (PROG_FLICKER) { + delay(PTIME); + prog_lamp(HIGH); + } +} + +unsigned int current_page() { + if (param.pagesize == 32) { + return here & 0xFFFFFFF0; + } + if (param.pagesize == 64) { + return here & 0xFFFFFFE0; + } + if (param.pagesize == 128) { + return here & 0xFFFFFFC0; + } + if (param.pagesize == 256) { + return here & 0xFFFFFF80; + } + return here; +} + + +void write_flash(int length) { + fill(length); + if (CRC_EOP == getch()) { + SERIAL.print((char) STK_INSYNC); + SERIAL.print((char) write_flash_pages(length)); + } else { + ISPError++; + SERIAL.print((char) STK_NOSYNC); + } +} + +uint8_t write_flash_pages(int length) { + int x = 0; + unsigned int page = current_page(); + while (x < length) { + if (page != current_page()) { + commit(page); + page = current_page(); + } + flash(LOW, here, buff[x++]); + flash(HIGH, here, buff[x++]); + here++; + } + + commit(page); + + return STK_OK; +} + +#define EECHUNK (32) +uint8_t write_eeprom(unsigned int length) { + // here is a word address, get the byte address + unsigned int start = here * 2; + unsigned int remaining = length; + if (length > param.eepromsize) { + ISPError++; + return STK_FAILED; + } + while (remaining > EECHUNK) { + write_eeprom_chunk(start, EECHUNK); + start += EECHUNK; + remaining -= EECHUNK; + } + write_eeprom_chunk(start, remaining); + return STK_OK; +} +// write (length) bytes, (start) is a byte address +uint8_t write_eeprom_chunk(unsigned int start, unsigned int length) { + // this writes byte-by-byte, page writing may be faster (4 bytes at a time) + fill(length); + prog_lamp(LOW); + for (unsigned int x = 0; x < length; x++) { + unsigned int addr = start + x; + spi_transaction(0xC0, (addr >> 8) & 0xFF, addr & 0xFF, buff[x]); + delay(45); + } + prog_lamp(HIGH); + return STK_OK; +} + +void program_page() { + char result = (char) STK_FAILED; + unsigned int length = 256 * getch(); + length += getch(); + char memtype = getch(); + // flash memory @here, (length) bytes + if (memtype == 'F') { + write_flash(length); + return; + } + if (memtype == 'E') { + result = (char)write_eeprom(length); + if (CRC_EOP == getch()) { + SERIAL.print((char) STK_INSYNC); + SERIAL.print(result); + } else { + ISPError++; + SERIAL.print((char) STK_NOSYNC); + } + return; + } + SERIAL.print((char)STK_FAILED); + return; +} + +uint8_t flash_read(uint8_t hilo, unsigned int addr) { + return spi_transaction(0x20 + hilo * 8, + (addr >> 8) & 0xFF, + addr & 0xFF, + 0); +} + +char flash_read_page(int length) { + for (int x = 0; x < length; x += 2) { + uint8_t low = flash_read(LOW, here); + SERIAL.print((char) low); + uint8_t high = flash_read(HIGH, here); + SERIAL.print((char) high); + here++; + } + return STK_OK; +} + +char eeprom_read_page(int length) { + // here again we have a word address + int start = here * 2; + for (int x = 0; x < length; x++) { + int addr = start + x; + uint8_t ee = spi_transaction(0xA0, (addr >> 8) & 0xFF, addr & 0xFF, 0xFF); + SERIAL.print((char) ee); + } + return STK_OK; +} + +void read_page() { + char result = (char)STK_FAILED; + int length = 256 * getch(); + length += getch(); + char memtype = getch(); + if (CRC_EOP != getch()) { + ISPError++; + SERIAL.print((char) STK_NOSYNC); + return; + } + SERIAL.print((char) STK_INSYNC); + if (memtype == 'F') { + result = flash_read_page(length); + } + if (memtype == 'E') { + result = eeprom_read_page(length); + } + SERIAL.print(result); +} + +void read_signature() { + if (CRC_EOP != getch()) { + ISPError++; + SERIAL.print((char) STK_NOSYNC); + return; + } + SERIAL.print((char) STK_INSYNC); + uint8_t high = spi_transaction(0x30, 0x00, 0x00, 0x00); + SERIAL.print((char) high); + uint8_t middle = spi_transaction(0x30, 0x00, 0x01, 0x00); + SERIAL.print((char) middle); + uint8_t low = spi_transaction(0x30, 0x00, 0x02, 0x00); + SERIAL.print((char) low); + SERIAL.print((char) STK_OK); +} +////////////////////////////////////////// +////////////////////////////////////////// + + +//////////////////////////////////// +//////////////////////////////////// +void avrisp() { + uint8_t ch = getch(); + switch (ch) { + case '0': // signon + ISPError = 0; + empty_reply(); + break; + case '1': + if (getch() == CRC_EOP) { + SERIAL.print((char) STK_INSYNC); + SERIAL.print("AVR ISP"); + SERIAL.print((char) STK_OK); + } else { + ISPError++; + SERIAL.print((char) STK_NOSYNC); + } + break; + case 'A': + get_version(getch()); + break; + case 'B': + fill(20); + set_parameters(); + empty_reply(); + break; + case 'E': // extended parameters - ignore for now + fill(5); + empty_reply(); + break; + case 'P': + if (!pmode) { + start_pmode(); + } + empty_reply(); + break; + case 'U': // set address (word) + here = getch(); + here += 256 * getch(); + empty_reply(); + break; + + case 0x60: //STK_PROG_FLASH + getch(); // low addr + getch(); // high addr + empty_reply(); + break; + case 0x61: //STK_PROG_DATA + getch(); // data + empty_reply(); + break; + + case 0x64: //STK_PROG_PAGE + program_page(); + break; + + case 0x74: //STK_READ_PAGE 't' + read_page(); + break; + + case 'V': //0x56 + universal(); + break; + case 'Q': //0x51 + ISPError = 0; + end_pmode(); + empty_reply(); + break; + + case 0x75: //STK_READ_SIGN 'u' + read_signature(); + break; + + // expecting a command, not CRC_EOP + // this is how we can get back in sync + case CRC_EOP: + ISPError++; + SERIAL.print((char) STK_NOSYNC); + break; + + // anything else we will return STK_UNKNOWN + default: + ISPError++; + if (CRC_EOP == getch()) { + SERIAL.print((char)STK_UNKNOWN); + } else { + SERIAL.print((char)STK_NOSYNC); + } + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AccessModifierOffset.cpp b/other/clang-format-configuration/testdata/input/targeted/AccessModifierOffset.cpp new file mode 100644 index 00000000..c1e7b082 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AccessModifierOffset.cpp @@ -0,0 +1,5 @@ +class Foo { +public: + protected: + private: +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignAfterOpenBracket.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignAfterOpenBracket.cpp new file mode 100644 index 00000000..6cd51d4e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignAfterOpenBracket.cpp @@ -0,0 +1,11 @@ +void foo(int arg1, int arg2) { + (void)arg1; + (void)arg2; +} + +void bar() { + foo(42, + 1234); + foo(42, + 1234); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignArrayOfStructures.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignArrayOfStructures.cpp new file mode 100644 index 00000000..2b6180ff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignArrayOfStructures.cpp @@ -0,0 +1,19 @@ +struct Foo_t { + int bar; + int baz; +}; + +Foo_t pippo[] = { + {1, 11}, + { 11, 1 }, +}; + +Foo_t pluto[] = { + { 1, 11}, + {11, 1}, +}; + +Foo_t paperino[] = { + { 1, 11 }, + { 11, 1 }, +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveAssignments.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveAssignments.cpp new file mode 100644 index 00000000..aeb5d06b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveAssignments.cpp @@ -0,0 +1,5 @@ +int a = 42; +int bb = 42; + +int ccc = 42; +int dddd = 42; diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveBitFields.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveBitFields.cpp new file mode 100644 index 00000000..72d556df --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveBitFields.cpp @@ -0,0 +1,7 @@ +struct Foo_t { + int a : 1; + int bb : 16; + + int ccc : 1; + int dddd : 16; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveDeclarations.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveDeclarations.cpp new file mode 100644 index 00000000..f1f23be2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveDeclarations.cpp @@ -0,0 +1,5 @@ +int a = 42; +long b = 42; + +int c = 42; +long d = 42; diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveMacros.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveMacros.cpp new file mode 100644 index 00000000..7d65080f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignConsecutiveMacros.cpp @@ -0,0 +1,5 @@ +#define FOO_A 42 +#define FOO_BB 42 + +#define FOO_CCC 42 +#define FOO_DDDD 42 diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignEscapedNewlines.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignEscapedNewlines.cpp new file mode 100644 index 00000000..9feef26b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignEscapedNewlines.cpp @@ -0,0 +1,20 @@ +#define FOO \ + int a; \ + int bb; \ + int ccc; \ + int dddd; \ + int e; + +#define BAR \ + int a; \ + int bb; \ + int ccc; \ + int dddd; \ + int e; + +#define BAZ \ + int a; \ + int bb; \ + int ccc; \ + int dddd; \ + int e; diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignOperands.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignOperands.cpp new file mode 100644 index 00000000..968be194 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignOperands.cpp @@ -0,0 +1,12 @@ +int foo = 42 + + 1234; + +int bar = 42 + + 1234; + +int baz = 42 + + 1234; + +int qux = 42 + + 1234; + diff --git a/other/clang-format-configuration/testdata/input/targeted/AlignTrailingComments.cpp b/other/clang-format-configuration/testdata/input/targeted/AlignTrailingComments.cpp new file mode 100644 index 00000000..4ff5b433 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlignTrailingComments.cpp @@ -0,0 +1,5 @@ +int a; // foo +int b = 42; // foo + +int c; // foo +int d = 42; // foo diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowAllArgumentsOnNextLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowAllArgumentsOnNextLine.cpp new file mode 100644 index 00000000..75aefbd2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowAllArgumentsOnNextLine.cpp @@ -0,0 +1,12 @@ +void foo(int arg1, int arg2) { + (void)arg1; + (void)arg2; +} + +void bar() { + foo( + 42, 1234); + + foo(42, + 1234); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowAllConstructorInitializersOnNextLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowAllConstructorInitializersOnNextLine.cpp new file mode 100644 index 00000000..2f0f7008 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowAllConstructorInitializersOnNextLine.cpp @@ -0,0 +1,13 @@ +class Foo { + Foo(); + Foo(int); + int bar; + int baz; +}; + +Foo::Foo() : + bar(42), baz(1234) {} + +Foo::Foo(int qux) : + bar(qux), + baz(1234) {} diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowAllParametersOfDeclarationOnNextLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowAllParametersOfDeclarationOnNextLine.cpp new file mode 100644 index 00000000..971ed280 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowAllParametersOfDeclarationOnNextLine.cpp @@ -0,0 +1,21 @@ +void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( + int foo, int bar, int baz); +void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa( + int foo, int bar, int baz) { + + (void)foo; + (void)bar; + (void)baz; +} + +void bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(int foo, + int bar, + int baz); +void bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(int foo, + int bar, + int baz) { + + (void)foo; + (void)bar; + (void)baz; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowShortBlocksOnASingleLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowShortBlocksOnASingleLine.cpp new file mode 100644 index 00000000..1a7f90cb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowShortBlocksOnASingleLine.cpp @@ -0,0 +1,10 @@ +void foo() { + while (true) { + } + + while (true) {} + + while (true) { + continue; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowShortCaseLabelsOnASingleLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowShortCaseLabelsOnASingleLine.cpp new file mode 100644 index 00000000..08fc617a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowShortCaseLabelsOnASingleLine.cpp @@ -0,0 +1,7 @@ +void foo() { + switch (1) { + case 2: break; + case 3: + break; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowShortEnumsOnASingleLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowShortEnumsOnASingleLine.cpp new file mode 100644 index 00000000..4b7bb4c8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowShortEnumsOnASingleLine.cpp @@ -0,0 +1,6 @@ +enum Foo_t { A, B }; + +enum Bar_t { + C, + D +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowShortFunctionsOnASingleLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowShortFunctionsOnASingleLine.cpp new file mode 100644 index 00000000..abd5c6da --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowShortFunctionsOnASingleLine.cpp @@ -0,0 +1,23 @@ +void foo() {} + +void bar() { +} + +int baz() { return 42; } + +int qux() { + return 42; +} + +class Pippo { + void foo() {} + + void bar() { + } + + int baz() { return 42; } + + int qux() { + return 42; + } +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowShortIfStatementsOnASingleLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowShortIfStatementsOnASingleLine.cpp new file mode 100644 index 00000000..a4e3f7a5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowShortIfStatementsOnASingleLine.cpp @@ -0,0 +1,18 @@ +void foo() { + bool a = true; + + if (a) + return; + else { + return; + } + + if (a) return; + else + return; + + if (a) return; + else { + return; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowShortLambdasOnASingleLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowShortLambdasOnASingleLine.cpp new file mode 100644 index 00000000..c25185d0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowShortLambdasOnASingleLine.cpp @@ -0,0 +1,13 @@ +auto foo = []() {}; + +auto bar = []() { +}; + +auto baz = []() { + return 42; +}; + +void qux(void (*)()) {} +void pippo() { + qux([]() {}); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AllowShortLoopsOnASingleLine.cpp b/other/clang-format-configuration/testdata/input/targeted/AllowShortLoopsOnASingleLine.cpp new file mode 100644 index 00000000..13bbf9ae --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AllowShortLoopsOnASingleLine.cpp @@ -0,0 +1,10 @@ +void foo() { + while (true) continue; + + while (true) + continue; + + while (true) { + continue; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakAfterReturnType.cpp b/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakAfterReturnType.cpp new file mode 100644 index 00000000..f2a018ff --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakAfterReturnType.cpp @@ -0,0 +1,22 @@ +int foo(); + +int foo() { return 42; } + +class Bar { + int foo() { return 42; } +}; + +int +baz(); + +int +baz() { + return 42; +} + +class Qux { + int + baz() { + return 42; + } +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakBeforeMultilineStrings.cpp b/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakBeforeMultilineStrings.cpp new file mode 100644 index 00000000..f1fe78da --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakBeforeMultilineStrings.cpp @@ -0,0 +1,11 @@ +void foo() { + char bar[] = + "asdf" + "zxcv"; + + char baz[] = "asdf" + "zxcv"; + + (void)bar; + (void)baz; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakTemplateDeclarations.cpp b/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakTemplateDeclarations.cpp new file mode 100644 index 00000000..c31eb810 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/AlwaysBreakTemplateDeclarations.cpp @@ -0,0 +1,15 @@ +template T foo() {} +template +T bar() {} + +template T baz(int a, + int b) { + (void)a; + (void)b; +} +template +T qux(int a, + int b) { + (void)a; + (void)b; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BinPackArguments.cpp b/other/clang-format-configuration/testdata/input/targeted/BinPackArguments.cpp new file mode 100644 index 00000000..999fdbd2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BinPackArguments.cpp @@ -0,0 +1,16 @@ +void foo(int arg1, int arg2, int arg3) { + (void)arg1; + (void)arg2; + (void)arg3; +} + +void bar() { + int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 42; + + foo(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); + + foo(aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BinPackParameters.cpp b/other/clang-format-configuration/testdata/input/targeted/BinPackParameters.cpp new file mode 100644 index 00000000..77d16aa9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BinPackParameters.cpp @@ -0,0 +1,16 @@ +void foo(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + int cccccccccccccccccccccccccccccccccccccccccccccccccc) { + + (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + (void)bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + (void)cccccccccccccccccccccccccccccccccccccccccccccccccc; +} + +void bar(int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, + int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + int cccccccccccccccccccccccccccccccccccccccccccccccccc) { + + (void)aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + (void)bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + (void)cccccccccccccccccccccccccccccccccccccccccccccccccc; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BitFieldColonSpacing.cpp b/other/clang-format-configuration/testdata/input/targeted/BitFieldColonSpacing.cpp new file mode 100644 index 00000000..75f3d8f3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BitFieldColonSpacing.cpp @@ -0,0 +1,6 @@ +struct Foo_t { + int foo : 2; + int bar:2; + int baz :2; + int qux: 2; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterCaseLabel.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterCaseLabel.cpp new file mode 100644 index 00000000..4834b025 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterCaseLabel.cpp @@ -0,0 +1,11 @@ +void foo() { + switch (1) { + case 2: + { + break; + } + case 3: { + break; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterClass.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterClass.cpp new file mode 100644 index 00000000..5a30b9e0 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterClass.cpp @@ -0,0 +1,8 @@ +class Foo +{ +public: +}; + +class Bar { +public: +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterControlStatement.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterControlStatement.cpp new file mode 100644 index 00000000..cda95828 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterControlStatement.cpp @@ -0,0 +1,21 @@ +void foo() { + if (true) + { + return; + } + + if (true) { + return; + } + + if (true && + true) + { + return; + } + + if (true && + true) { + return; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterEnum.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterEnum.cpp new file mode 100644 index 00000000..61e2cb9c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterEnum.cpp @@ -0,0 +1,10 @@ +enum Foo_t +{ + A, + B +}; + +enum Bar_t { + C, + D +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterExternBlock.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterExternBlock.cpp new file mode 100644 index 00000000..ca982520 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterExternBlock.cpp @@ -0,0 +1,8 @@ +extern "C" +{ + int foo(); +} + +extern "C" { + int bar(); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterFunction.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterFunction.cpp new file mode 100644 index 00000000..eb205f15 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterFunction.cpp @@ -0,0 +1,8 @@ +void foo() +{ + return; +} + +void bar() { + return; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterNamespace.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterNamespace.cpp new file mode 100644 index 00000000..bcadff8c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterNamespace.cpp @@ -0,0 +1,8 @@ +namespace +{ + __attribute__ ((unused))int foo; +} + +namespace { + __attribute__ ((unused))int bar; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterStruct.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterStruct.cpp new file mode 100644 index 00000000..6797d3b1 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterStruct.cpp @@ -0,0 +1,8 @@ +struct Foo_t +{ + int bar; +}; + +struct Baz_t { + int qux; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterUnion.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterUnion.cpp new file mode 100644 index 00000000..a2db5884 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_AfterUnion.cpp @@ -0,0 +1,8 @@ +union Foo_t +{ + int bar; +}; + +union Baz_t { + int qux; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeCatch.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeCatch.cpp new file mode 100644 index 00000000..ad40e3bb --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeCatch.cpp @@ -0,0 +1,16 @@ +void foo() {} + +void bar() { + try { + foo(); + } + catch (int e) { + (void)e; + } + + try { + foo(); + } catch (int e) { + (void)e; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeElse.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeElse.cpp new file mode 100644 index 00000000..1b4c6b17 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeElse.cpp @@ -0,0 +1,14 @@ +void foo() { + if (true) { + return; + } + else { + return; + } + + if (true) { + return; + } else { + return; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeLambdaBody.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeLambdaBody.cpp new file mode 100644 index 00000000..e767ab59 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeLambdaBody.cpp @@ -0,0 +1,12 @@ +void foo(void (*)()) {} + +void bar() { + foo([]() + { + return; + }); + + foo([]() { + return; + }); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeWhile.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeWhile.cpp new file mode 100644 index 00000000..ad99702a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_BeforeWhile.cpp @@ -0,0 +1,10 @@ +void foo() { + do { + continue; + } + while (true); + + do { + continue; + } while (true); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_IndentBraces.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_IndentBraces.cpp new file mode 100644 index 00000000..09c08c84 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_IndentBraces.cpp @@ -0,0 +1,5 @@ +void foo() + {} + +void bar() +{} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyFunction.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyFunction.cpp new file mode 100644 index 00000000..17dffbf6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyFunction.cpp @@ -0,0 +1,10 @@ +void foo() { +} + +void bar() {} + +void baz() +{ +} + +void qux() {} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyNamespace.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyNamespace.cpp new file mode 100644 index 00000000..a1438fe4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyNamespace.cpp @@ -0,0 +1,11 @@ +namespace { +} + +namespace +{ +} + +namespace {} + +namespace +{} diff --git a/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyRecord.cpp b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyRecord.cpp new file mode 100644 index 00000000..3b5ac241 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BraceWrapping_SplitEmptyRecord.cpp @@ -0,0 +1,11 @@ +class Foo { +}; + +class Bar +{ +}; + +class Baz {}; + +class Qux +{}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBinaryOperators.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBinaryOperators.cpp new file mode 100644 index 00000000..715489a8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBinaryOperators.cpp @@ -0,0 +1,18 @@ +int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = 42; + +int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + +int ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc = + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + +int ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd = + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +int eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee = + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + +int fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff + = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Allman.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Allman.cpp new file mode 100644 index 00000000..6cb32765 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Allman.cpp @@ -0,0 +1,70 @@ +extern "C" +{ + void foo(); +} + +void foo() +{ + switch (1) + { + case 2: + { + break; + } + } + + if (true) + { + return; + } + + do { + continue; + } while (true); +} + +void bar() +{ + try + { + foo(); + } + catch (int e) + { + (void)e; + } + try + { + foo(); + } + catch (int e) + { + (void)e; + } +} + +class Foo +{ +public: +}; + +enum Foo_t +{ + A, + B +}; + +namespace +{ +const int foo = 42; +} + +struct Bar_t +{ + int foo; +}; + +union Baz_t +{ + int foo; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Attach.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Attach.cpp new file mode 100644 index 00000000..ca0cecce --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Attach.cpp @@ -0,0 +1,53 @@ +extern "C" { + void foo(); +} + +void foo() { + switch (1) { + case 2: { + break; + } + } + + if (true) { + return; + } + + do { + continue; + } while (true); +} + +void bar() { + try { + foo(); + } catch (int e) { + (void)e; + } + try { + foo(); + } catch (int e) { + (void)e; + } +} + +class Foo { +public: +}; + +enum Foo_t { + A, + B +}; + +namespace { +const int foo = 42; +} + +struct Bar_t { + int foo; +}; + +union Baz_t { + int foo; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Whitesmiths.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Whitesmiths.cpp new file mode 100644 index 00000000..e5dc3bcf --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeBraces_Whitesmiths.cpp @@ -0,0 +1,69 @@ +extern "C" + { + void foo(); + } + +void foo() + { + switch (1) + { + case 2: + { + break; + } + } + + if (true) + { + return; + } + + do { + continue; + } while (true); + } + +void bar() + { + try + { + foo(); + } + catch (int e) + { + (void)e; + } + try + { + foo(); + } + catch (int e) + { + (void)e; + } + } + +class Foo + { +public: + }; + +enum Foo_t + { + A, + B + }; + +namespace + { +const int foo = 42; + } + +struct Bar_t + { + int foo; + }; + +union Baz_t { + int foo; + }; diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakBeforeConceptDeclarations.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeConceptDeclarations.cpp new file mode 100644 index 00000000..ce35423a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeConceptDeclarations.cpp @@ -0,0 +1,8 @@ +template +concept foo = requires(T bar) { + (void)bar; +}; + +template concept baz = requires(T bar) { + (void)bar; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakBeforeTernaryOperators.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeTernaryOperators.cpp new file mode 100644 index 00000000..a0d4b88b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakBeforeTernaryOperators.cpp @@ -0,0 +1,13 @@ +void foo() { + bool aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = true; + + bool bar = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + ? aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + + bar = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa ? + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa : + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + + (void)bar; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakConstructorInitializers.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakConstructorInitializers.cpp new file mode 100644 index 00000000..b9a51061 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakConstructorInitializers.cpp @@ -0,0 +1,19 @@ +class Foo { + Foo(); + Foo(int); + Foo(int, int); + int bar; + int baz; +}; + +Foo::Foo() + : bar(42), + baz(42) {} + +Foo::Foo(int qux) + : bar(qux) + , baz(42) {} + +Foo::Foo(int qux, int pippo) : + bar(qux), + baz(pippo) {} diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakInheritanceList.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakInheritanceList.cpp new file mode 100644 index 00000000..d7f180f4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakInheritanceList.cpp @@ -0,0 +1,14 @@ +class Foo {}; +class Bar {}; + +class Baz + : Foo, + Bar {}; + +class Qux + : Foo + , Bar {}; + +class Pippo : + Foo, + Bar {}; diff --git a/other/clang-format-configuration/testdata/input/targeted/BreakStringLiterals.cpp b/other/clang-format-configuration/testdata/input/targeted/BreakStringLiterals.cpp new file mode 100644 index 00000000..c24a3ef7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/BreakStringLiterals.cpp @@ -0,0 +1,8 @@ +char foo[] = "veryVeryVeryVery" + "VeryVeryVeryVeryVeryVery" + "VeryVeryVeryVeryVeryVeryVery" + "VeryVeryVeryVeryVeryVeryVeryVery" + "VeryVeryVeryVeryVeryVeryVery" + "VeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; + +char bar[] = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; diff --git a/other/clang-format-configuration/testdata/input/targeted/ColumnLimit.cpp b/other/clang-format-configuration/testdata/input/targeted/ColumnLimit.cpp new file mode 100644 index 00000000..e6740fd9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/ColumnLimit.cpp @@ -0,0 +1 @@ +// VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong diff --git a/other/clang-format-configuration/testdata/input/targeted/CompactNamespaces.cpp b/other/clang-format-configuration/testdata/input/targeted/CompactNamespaces.cpp new file mode 100644 index 00000000..f1862591 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/CompactNamespaces.cpp @@ -0,0 +1,7 @@ +namespace foo { namespace bar { +}} + +namespace baz { +namespace qux { +} +} diff --git a/other/clang-format-configuration/testdata/input/targeted/ConstructorInitializerAllOnOneLineOrOnePerLine.cpp b/other/clang-format-configuration/testdata/input/targeted/ConstructorInitializerAllOnOneLineOrOnePerLine.cpp new file mode 100644 index 00000000..05c8001b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/ConstructorInitializerAllOnOneLineOrOnePerLine.cpp @@ -0,0 +1,15 @@ +class Foo { + Foo(); + Foo(int); + int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + int ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc; +}; + +Foo::Foo() + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(42), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(42), ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc(42) {} + +Foo::Foo(int bar) + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bar), + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(42), + ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc(42) {} diff --git a/other/clang-format-configuration/testdata/input/targeted/ConstructorInitializerIndentWidth.cpp b/other/clang-format-configuration/testdata/input/targeted/ConstructorInitializerIndentWidth.cpp new file mode 100644 index 00000000..c1388d83 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/ConstructorInitializerIndentWidth.cpp @@ -0,0 +1,20 @@ +class Foo { + Foo(); + Foo(int); + Foo(int, int); + int pippo; + int pluto; + int paperino; +}; +class Bar {}; +class Baz {}; + +class Qux +: Foo, + Bar, + Baz {}; + +Foo::Foo() +: pippo(42), + pluto(42), + paperino(42) {} diff --git a/other/clang-format-configuration/testdata/input/targeted/ContinuationIndentWidth.cpp b/other/clang-format-configuration/testdata/input/targeted/ContinuationIndentWidth.cpp new file mode 100644 index 00000000..12dadb5d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/ContinuationIndentWidth.cpp @@ -0,0 +1,2 @@ +int foo = +42; diff --git a/other/clang-format-configuration/testdata/input/targeted/Cpp11BracedListStyle.cpp b/other/clang-format-configuration/testdata/input/targeted/Cpp11BracedListStyle.cpp new file mode 100644 index 00000000..0a60969a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/Cpp11BracedListStyle.cpp @@ -0,0 +1,3 @@ +int foo[] = {42, 1234}; + +int bar[] = { 42, 1234 }; diff --git a/other/clang-format-configuration/testdata/input/targeted/DeriveLineEnding.cpp b/other/clang-format-configuration/testdata/input/targeted/DeriveLineEnding.cpp new file mode 100644 index 00000000..5fe51a85 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/DeriveLineEnding.cpp @@ -0,0 +1 @@ +// this file intentionally has CRLF line endings diff --git a/other/clang-format-configuration/testdata/input/targeted/DerivePointerAlignment.cpp b/other/clang-format-configuration/testdata/input/targeted/DerivePointerAlignment.cpp new file mode 100644 index 00000000..a20454b8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/DerivePointerAlignment.cpp @@ -0,0 +1,14 @@ +int* foo; +int* bar; +int * baz; +int *qux; + +void pippo(int& foo) { + (void)foo; +} +void pluto(int & foo) { + (void)foo; +} +void paperino(int &foo) { + (void)foo; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/EmptyLineAfterAccessModifier.cpp b/other/clang-format-configuration/testdata/input/targeted/EmptyLineAfterAccessModifier.cpp new file mode 100644 index 00000000..a2262eac --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/EmptyLineAfterAccessModifier.cpp @@ -0,0 +1,19 @@ +class Foo { +public: + int foo; +}; + +class Bar { +public: + int foo; + +private: + + int bar; +}; + +class Baz { +public: + + int foo; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/EmptyLineBeforeAccessModifier.cpp b/other/clang-format-configuration/testdata/input/targeted/EmptyLineBeforeAccessModifier.cpp new file mode 100644 index 00000000..48f8a664 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/EmptyLineBeforeAccessModifier.cpp @@ -0,0 +1,31 @@ +class Foo { +public: +private: + int foo; +protected: +}; + +class Bar { +public: + +private: + int foo; +protected: +}; + +class Baz { +public: +private: + int foo; + +protected: +}; + +class Qux { +public: + +private: + int foo; + +protected: +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/FixNamespaceComments.cpp b/other/clang-format-configuration/testdata/input/targeted/FixNamespaceComments.cpp new file mode 100644 index 00000000..27970bbc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/FixNamespaceComments.cpp @@ -0,0 +1,5 @@ +namespace foo { +} + +namespace bar { +} // namespace baz diff --git a/other/clang-format-configuration/testdata/input/targeted/IncludeBlocks.cpp b/other/clang-format-configuration/testdata/input/targeted/IncludeBlocks.cpp new file mode 100644 index 00000000..1cb051ad --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IncludeBlocks.cpp @@ -0,0 +1,9 @@ +#include "include/b.h" +#include +#include "include/a.h" +#include + +#include "include/d.h" +#include +#include "include/c.h" +#include diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentAccessModifiers.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentAccessModifiers.cpp new file mode 100644 index 00000000..a22c5f4c --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentAccessModifiers.cpp @@ -0,0 +1,13 @@ +class Foo { + int bar; + + public: + int baz; +}; + +class Pippo { + int pluto; + +public: + int paperino; +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentCaseBlocks.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentCaseBlocks.cpp new file mode 100644 index 00000000..0153107b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentCaseBlocks.cpp @@ -0,0 +1,12 @@ +void foo() { + switch (1) { + case 2: + { + break; + } + case 3: { + break; + } + } +} + diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentCaseLabels.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentCaseLabels.cpp new file mode 100644 index 00000000..6c5a7c85 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentCaseLabels.cpp @@ -0,0 +1,8 @@ +void foo() { + switch (1) { + case 2: + break; + case 3: + break; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentExternBlock.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentExternBlock.cpp new file mode 100644 index 00000000..0c03b89e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentExternBlock.cpp @@ -0,0 +1,4 @@ +extern "C" { + void foo(); +void bar(); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentGotoLabels.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentGotoLabels.cpp new file mode 100644 index 00000000..a29efa7b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentGotoLabels.cpp @@ -0,0 +1,7 @@ +void foo() { + bar: +baz: + + goto bar; + goto baz; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentPPDirectives.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentPPDirectives.cpp new file mode 100644 index 00000000..ba1a3f83 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentPPDirectives.cpp @@ -0,0 +1,7 @@ +#if defined(FOO) +#define BAR +#elif defined(BAZ) +# define QUX +#else + #define PIPPO +#endif diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentRequires.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentRequires.cpp new file mode 100644 index 00000000..a7159d8d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentRequires.cpp @@ -0,0 +1,5 @@ +template + requires true T foo() {} + +template +requires true T bar() {} diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentWidth.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentWidth.cpp new file mode 100644 index 00000000..e1c31529 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentWidth.cpp @@ -0,0 +1,6 @@ +void foo() { +int bar; + (void)bar; + int baz; + (void)baz; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/IndentWrappedFunctionNames.cpp b/other/clang-format-configuration/testdata/input/targeted/IndentWrappedFunctionNames.cpp new file mode 100644 index 00000000..4b1315cc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/IndentWrappedFunctionNames.cpp @@ -0,0 +1,5 @@ +void + foo() {} + +void +bar() {} diff --git a/other/clang-format-configuration/testdata/input/targeted/InsertTrailingCommas.cpp b/other/clang-format-configuration/testdata/input/targeted/InsertTrailingCommas.cpp new file mode 100644 index 00000000..00118d1d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/InsertTrailingCommas.cpp @@ -0,0 +1,9 @@ +int foo[] = { + 42, + 1234 +}; + +int bar[] = { + 42, + 1234, +}; diff --git a/other/clang-format-configuration/testdata/input/targeted/KeepEmptyLinesAtTheStartOfBlocks.cpp b/other/clang-format-configuration/testdata/input/targeted/KeepEmptyLinesAtTheStartOfBlocks.cpp new file mode 100644 index 00000000..43af71a2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/KeepEmptyLinesAtTheStartOfBlocks.cpp @@ -0,0 +1,10 @@ +void foo() { + if (true) { + + return; + } + + if (true) { + return; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/LambdaBodyIndentation.cpp b/other/clang-format-configuration/testdata/input/targeted/LambdaBodyIndentation.cpp new file mode 100644 index 00000000..86c9135b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/LambdaBodyIndentation.cpp @@ -0,0 +1,13 @@ +void foo(void (*)()) {} + +void bar() { + foo( + []() { + // baz + }); + + foo( + []() { + // baz + }); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/MaxEmptyLinesToKeep.cpp b/other/clang-format-configuration/testdata/input/targeted/MaxEmptyLinesToKeep.cpp new file mode 100644 index 00000000..86dc4ce8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/MaxEmptyLinesToKeep.cpp @@ -0,0 +1,24 @@ +int foo; + + + + + + + + + + + + + + + + + + + + + + +int bar; diff --git a/other/clang-format-configuration/testdata/input/targeted/NamespaceIndentation.cpp b/other/clang-format-configuration/testdata/input/targeted/NamespaceIndentation.cpp new file mode 100644 index 00000000..8d4f455f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/NamespaceIndentation.cpp @@ -0,0 +1,10 @@ +namespace { +const int foo = 42; + const int bar = 42; +namespace baz { +const int qux = 42; +} + namespace pippo { + const int pluto = 42; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/PPIndentWidth.cpp b/other/clang-format-configuration/testdata/input/targeted/PPIndentWidth.cpp new file mode 100644 index 00000000..72598ca5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/PPIndentWidth.cpp @@ -0,0 +1,7 @@ +#if defined(FOO) +#define BAR +#elif defined(BAZ) + #define QUX +#else + #define PIPPO +#endif diff --git a/other/clang-format-configuration/testdata/input/targeted/PackConstructorInitializers.cpp b/other/clang-format-configuration/testdata/input/targeted/PackConstructorInitializers.cpp new file mode 100644 index 00000000..5a098682 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/PackConstructorInitializers.cpp @@ -0,0 +1,28 @@ +class Foo { + Foo(); + Foo(int); + Foo(int, int); + Foo(int, int, int); + int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa; + int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; + int cccccccccccccccccccccccccccccccccccccccccccccccccc; + int d; + int e; + int f; + int ddddddddddddddddddddddddd; + int ggggggggggggggggggggggggg; + int hhhhhhhhhhhhhhhhhhhhhhhhh; + int iiiiiiiiiiiiiiiiiiiiiiiii; +}; + +Foo::Foo() + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(42), + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(1234), + cccccccccccccccccccccccccccccccccccccccccccccccccc(11) {} + +Foo::Foo(int bar) + : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(bar), bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(1234), + cccccccccccccccccccccccccccccccccccccccccccccccccc(11) {} + +Foo::Foo(int bar, int baz, int qux) + : ggggggggggggggggggggggggg(bar), hhhhhhhhhhhhhhhhhhhhhhhhh(baz), iiiiiiiiiiiiiiiiiiiiiiiii(qux) {} diff --git a/other/clang-format-configuration/testdata/input/targeted/PointerAlignment.cpp b/other/clang-format-configuration/testdata/input/targeted/PointerAlignment.cpp new file mode 100644 index 00000000..1e73f8ab --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/PointerAlignment.cpp @@ -0,0 +1,13 @@ +int* foo; +int *bar; +int * baz; + +void pippo(int& foo) { + (void)foo; +} +void pluto(int &foo) { + (void)foo; +} +void paperino(int & foo) { + (void)foo; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/QualifierAlignment.cpp b/other/clang-format-configuration/testdata/input/targeted/QualifierAlignment.cpp new file mode 100644 index 00000000..2871ab3d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/QualifierAlignment.cpp @@ -0,0 +1,2 @@ +const int foo = 42; +int const bar = 42; diff --git a/other/clang-format-configuration/testdata/input/targeted/ReferenceAlignment.cpp b/other/clang-format-configuration/testdata/input/targeted/ReferenceAlignment.cpp new file mode 100644 index 00000000..be03a968 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/ReferenceAlignment.cpp @@ -0,0 +1,9 @@ +void pippo(int& foo) { + (void)foo; +} +void pluto(int &foo) { + (void)foo; +} +void paperino(int & foo) { + (void)foo; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/ReflowComments.cpp b/other/clang-format-configuration/testdata/input/targeted/ReflowComments.cpp new file mode 100644 index 00000000..407ae299 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/ReflowComments.cpp @@ -0,0 +1,11 @@ +// foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo +// foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo +// foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo + +/* bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar + * bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar + * bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar */ + +// foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo foo + +/* bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar bar */ diff --git a/other/clang-format-configuration/testdata/input/targeted/RemoveBracesLLVM.cpp b/other/clang-format-configuration/testdata/input/targeted/RemoveBracesLLVM.cpp new file mode 100644 index 00000000..5b1e2fa9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/RemoveBracesLLVM.cpp @@ -0,0 +1,8 @@ +void foo() { + if (true) + return; + + if (true) { + return; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SeparateDefinitionBlocks.cpp b/other/clang-format-configuration/testdata/input/targeted/SeparateDefinitionBlocks.cpp new file mode 100644 index 00000000..82f9df04 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SeparateDefinitionBlocks.cpp @@ -0,0 +1,11 @@ +int foo; + +void bar() {} +void baz() {} + +void qux() {} + +void pippo() {} + +void pluto() {} +void paperino() {} diff --git a/other/clang-format-configuration/testdata/input/targeted/ShortNamespaceLines.cpp b/other/clang-format-configuration/testdata/input/targeted/ShortNamespaceLines.cpp new file mode 100644 index 00000000..4ca42355 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/ShortNamespaceLines.cpp @@ -0,0 +1,17 @@ +namespace { +} + +namespace { +__attribute__((unused)) int foo; +} + +namespace { +__attribute__((unused)) int bar; +__attribute__((unused)) int baz; +} + +namespace { +__attribute__((unused)) int pippo; +__attribute__((unused)) int pluto; +__attribute__((unused)) int paperino; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SortIncludes.cpp b/other/clang-format-configuration/testdata/input/targeted/SortIncludes.cpp new file mode 100644 index 00000000..19c4cfab --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SortIncludes.cpp @@ -0,0 +1,4 @@ +#include "include/b.h" +#include "include/a.h" +#include +#include diff --git a/other/clang-format-configuration/testdata/input/targeted/SortUsingDeclarations.cpp b/other/clang-format-configuration/testdata/input/targeted/SortUsingDeclarations.cpp new file mode 100644 index 00000000..f6c084f8 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SortUsingDeclarations.cpp @@ -0,0 +1,13 @@ +namespace a { +int aa; +int ab; +} +namespace b { +int ba; +int bb; +} + +using b::bb; +using b::ba; +using a::ab; +using a::aa; diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceAfterCStyleCast.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceAfterCStyleCast.cpp new file mode 100644 index 00000000..37a8ccfe --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceAfterCStyleCast.cpp @@ -0,0 +1,3 @@ +int foo = (int) 42; + +int bar = (int)42; diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceAfterLogicalNot.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceAfterLogicalNot.cpp new file mode 100644 index 00000000..aa0ff8dd --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceAfterLogicalNot.cpp @@ -0,0 +1,4 @@ +bool foo() { + return ! true; + return !true; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceAfterTemplateKeyword.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceAfterTemplateKeyword.cpp new file mode 100644 index 00000000..7e085f1a --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceAfterTemplateKeyword.cpp @@ -0,0 +1,3 @@ +template T foo() {} + +template T bar() {} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceAroundPointerQualifiers.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceAroundPointerQualifiers.cpp new file mode 100644 index 00000000..97a885b2 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceAroundPointerQualifiers.cpp @@ -0,0 +1,2 @@ +void* const* foo = nullptr; +void* const * bar = nullptr; diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeAssignmentOperators.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeAssignmentOperators.cpp new file mode 100644 index 00000000..d6e19281 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeAssignmentOperators.cpp @@ -0,0 +1,7 @@ +void foo() { + int bar = 42; + bar += 1; + + int baz= 42; + baz+= 1; +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCaseColon.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCaseColon.cpp new file mode 100644 index 00000000..13106290 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCaseColon.cpp @@ -0,0 +1,6 @@ +void foo() { + switch (1) { + case 2 : break; + case 3: break; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCpp11BracedList .cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCpp11BracedList .cpp new file mode 100644 index 00000000..8c914c5d --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCpp11BracedList .cpp @@ -0,0 +1,3 @@ +int foo {}; + +int bar{}; diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCtorInitializerColon.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCtorInitializerColon.cpp new file mode 100644 index 00000000..7408cac4 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeCtorInitializerColon.cpp @@ -0,0 +1,9 @@ +class Foo { + Foo(); + Foo(int); + int bar; +}; + +Foo::Foo() : bar(42) {} + +Foo::Foo(int baz): bar(baz) {} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeInheritanceColon.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeInheritanceColon.cpp new file mode 100644 index 00000000..72a591e3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeInheritanceColon.cpp @@ -0,0 +1,5 @@ +class Foo {}; + +class Bar : Foo {}; + +class Baz: Foo {}; diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeParens.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeParens.cpp new file mode 100644 index 00000000..7f714640 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeParens.cpp @@ -0,0 +1,11 @@ +void foo() { + if(true) { + foo(); + } +} + +void bar () { + if (true) { + foo (); + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeParensOptions.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeParensOptions.cpp new file mode 100644 index 00000000..eb71ecc6 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeParensOptions.cpp @@ -0,0 +1,40 @@ +void foo() { + if (true) {} + if(true) {} +} + +void bar (int); +void baz(int); + +void bar (int qux) { + (void)qux; +} +void baz(int qux) { + (void)qux; +} + +#if (true) +#endif +#if(true) +#endif + +class Foo { +public: + Foo(){}; + Foo(int baz) + : bar(baz) {} + int bar; + + Foo operator++ (int qux) { + (void)qux; + return Foo(42); + } + + Foo operator--(int qux) { + (void)qux; + return Foo(42); + } +}; + +void pippo() {} +void pluto () {} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeRangeBasedForLoopColon.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeRangeBasedForLoopColon.cpp new file mode 100644 index 00000000..2eb570c7 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeRangeBasedForLoopColon.cpp @@ -0,0 +1,9 @@ +void foo() { + for (char bar : "baz") { + (void) bar; + } + + for (char bar: "baz") { + (void) bar; + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeSquareBrackets.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeSquareBrackets.cpp new file mode 100644 index 00000000..18675fc5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceBeforeSquareBrackets.cpp @@ -0,0 +1,2 @@ +int foo [42]; +int bar[42]; diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceInEmptyBlock.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceInEmptyBlock.cpp new file mode 100644 index 00000000..4f0c1dd9 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceInEmptyBlock.cpp @@ -0,0 +1,3 @@ +void foo() { } + +void bar() {} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpaceInEmptyParentheses.cpp b/other/clang-format-configuration/testdata/input/targeted/SpaceInEmptyParentheses.cpp new file mode 100644 index 00000000..e27abe68 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpaceInEmptyParentheses.cpp @@ -0,0 +1,7 @@ +void foo( ) { + foo( ); +} + +void bar() { + bar(); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpacesBeforeTrailingComments.cpp b/other/clang-format-configuration/testdata/input/targeted/SpacesBeforeTrailingComments.cpp new file mode 100644 index 00000000..a70b9f95 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpacesBeforeTrailingComments.cpp @@ -0,0 +1,3 @@ +//foo +// bar +// baz diff --git a/other/clang-format-configuration/testdata/input/targeted/SpacesInAngles.cpp b/other/clang-format-configuration/testdata/input/targeted/SpacesInAngles.cpp new file mode 100644 index 00000000..c5c51e7e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpacesInAngles.cpp @@ -0,0 +1,6 @@ +template void bar() {} + +void baz() { + bar< 42 >(); + bar<42>(); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpacesInCStyleCastParentheses.cpp b/other/clang-format-configuration/testdata/input/targeted/SpacesInCStyleCastParentheses.cpp new file mode 100644 index 00000000..211005db --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpacesInCStyleCastParentheses.cpp @@ -0,0 +1,3 @@ +int foo = ( int )42; + +int bar = (int)42; diff --git a/other/clang-format-configuration/testdata/input/targeted/SpacesInConditionalStatement.cpp b/other/clang-format-configuration/testdata/input/targeted/SpacesInConditionalStatement.cpp new file mode 100644 index 00000000..f1fdf1fa --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpacesInConditionalStatement.cpp @@ -0,0 +1,4 @@ +void foo() { + if ( true ) {} + if (true) {} +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpacesInLineCommentPrefix.cpp b/other/clang-format-configuration/testdata/input/targeted/SpacesInLineCommentPrefix.cpp new file mode 100644 index 00000000..a70b9f95 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpacesInLineCommentPrefix.cpp @@ -0,0 +1,3 @@ +//foo +// bar +// baz diff --git a/other/clang-format-configuration/testdata/input/targeted/SpacesInParentheses.cpp b/other/clang-format-configuration/testdata/input/targeted/SpacesInParentheses.cpp new file mode 100644 index 00000000..1cc2112f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpacesInParentheses.cpp @@ -0,0 +1,9 @@ +void foo( int bar ) { + (void)bar; +} + +void baz(int qux) { + foo( qux ); + + foo(qux); +} diff --git a/other/clang-format-configuration/testdata/input/targeted/SpacesInSquareBrackets.cpp b/other/clang-format-configuration/testdata/input/targeted/SpacesInSquareBrackets.cpp new file mode 100644 index 00000000..868592bc --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/SpacesInSquareBrackets.cpp @@ -0,0 +1,3 @@ +int foo[ 42 ]; + +int bar[42]; diff --git a/other/clang-format-configuration/testdata/input/targeted/Standard.cpp b/other/clang-format-configuration/testdata/input/targeted/Standard.cpp new file mode 100644 index 00000000..9a81f34f --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/Standard.cpp @@ -0,0 +1,6 @@ +#include +#include + +std::vector > foo; + +std::vector> bar; diff --git a/other/clang-format-configuration/testdata/input/targeted/TabWidth.cpp b/other/clang-format-configuration/testdata/input/targeted/TabWidth.cpp new file mode 100644 index 00000000..b08c89d3 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/TabWidth.cpp @@ -0,0 +1,18 @@ +// This test data must have multiple indentation levels in order to provide sufficient coverage of the unintuitive +// interaction between IndentWidth and TabWidth. See the TabWidth option notes for details. + +void foo() { + int bar = + 42; + (void)bar; + { + int baz = + 42; + (void)baz; + { + int qux = + 42; + (void)qux; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/UseCRLF.cpp b/other/clang-format-configuration/testdata/input/targeted/UseCRLF.cpp new file mode 100644 index 00000000..6a32543e --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/UseCRLF.cpp @@ -0,0 +1 @@ +// this file intentionally has CRLF line endings diff --git a/other/clang-format-configuration/testdata/input/targeted/UseTab.cpp b/other/clang-format-configuration/testdata/input/targeted/UseTab.cpp new file mode 100644 index 00000000..328fc97b --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/UseTab.cpp @@ -0,0 +1,20 @@ +// This test data must have multiple indentation levels in order to provide sufficient coverage of how UseTab is +// affected by the unintuitive interaction between IndentWidth and TabWidth. See the TabWidth option notes for details. + +int a; // foo +int bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb; // foo +void bar() { + int baz = + 42; + (void)baz; + { + int qux = + 42; + (void)qux; + { + int pippo = + 42; + (void)pippo; + } + } +} diff --git a/other/clang-format-configuration/testdata/input/targeted/include/a.h b/other/clang-format-configuration/testdata/input/targeted/include/a.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/include/a.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/input/targeted/include/aa.h b/other/clang-format-configuration/testdata/input/targeted/include/aa.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/include/aa.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/input/targeted/include/b.h b/other/clang-format-configuration/testdata/input/targeted/include/b.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/include/b.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/input/targeted/include/bb.h b/other/clang-format-configuration/testdata/input/targeted/include/bb.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/include/bb.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/input/targeted/include/c.h b/other/clang-format-configuration/testdata/input/targeted/include/c.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/include/c.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/input/targeted/include/cc.h b/other/clang-format-configuration/testdata/input/targeted/include/cc.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/include/cc.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/input/targeted/include/d.h b/other/clang-format-configuration/testdata/input/targeted/include/d.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/include/d.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/other/clang-format-configuration/testdata/input/targeted/include/dd.h b/other/clang-format-configuration/testdata/input/targeted/include/dd.h new file mode 100644 index 00000000..e26b0ab5 --- /dev/null +++ b/other/clang-format-configuration/testdata/input/targeted/include/dd.h @@ -0,0 +1 @@ +// This file intentionally left empty. diff --git a/package-lock.json b/package-lock.json index 836ad772..64d4c653 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4,21 +4,136 @@ "requires": true, "packages": { "": { + "dependencies": { + "js-yaml": "^4.1.0" + }, "devDependencies": { "ajv-cli": "^5.0.0", "ajv-formats": "^2.1.1", + "eslint": "^8.2.0", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-import": "^2.25.2", "github-label-sync": "2.2.0", "markdown-link-check": "^3.10.2", "markdownlint-cli": "^0.31.1", "prettier": "^2.7.1" } }, + "node_modules/@eslint/eslintrc": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", + "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", + "dev": true, + "dependencies": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^9.3.2", + "globals": "^13.15.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/@eslint/eslintrc/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/@eslint/eslintrc/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@eslint/eslintrc/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/@eslint/eslintrc/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, "node_modules/@financial-times/origami-service-makefile": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@financial-times/origami-service-makefile/-/origami-service-makefile-7.0.3.tgz", "integrity": "sha512-aKe65sZ3XgZ/0Sm0MDLbGrcO3G4DRv/bVW4Gpmw68cRZV9IBE7h/pwfR3Rs7njNSZMFkjS4rPG/YySv9brQByA==", "dev": true }, + "node_modules/@humanwhocodes/config-array": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.6.0.tgz", + "integrity": "sha512-JQlEKbcgEUjBFhLIF4iqM7u/9lwgHRBcpHrmUNCALK0Q3amXN6lxdoXLnF0sm11E9VqTmBALR87IlUg1bZ8A9A==", + "dev": true, + "dependencies": { + "@humanwhocodes/object-schema": "^1.2.0", + "debug": "^4.1.1", + "minimatch": "^3.0.4" + }, + "engines": { + "node": ">=10.10.0" + } + }, + "node_modules/@humanwhocodes/config-array/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/@humanwhocodes/config-array/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "node_modules/@humanwhocodes/object-schema": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", + "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "dev": true + }, "node_modules/@sindresorhus/is": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", @@ -67,6 +182,12 @@ "integrity": "sha512-3YP80IxxFJB4b5tYC2SUPwkg0XQLiu0nWvhRgEatgjf+29IcWO9X1k8xRv5DGssJ/lCrjYTjQPcobJr2yWIVuQ==", "dev": true }, + "node_modules/@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", + "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", + "dev": true + }, "node_modules/@types/keyv": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz", @@ -91,6 +212,27 @@ "@types/node": "*" } }, + "node_modules/acorn": { + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", + "dev": true, + "bin": { + "acorn": "bin/acorn" + }, + "engines": { + "node": ">=0.4.0" + } + }, + "node_modules/acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "peerDependencies": { + "acorn": "^6.0.0 || ^7.0.0 || ^8.0.0" + } + }, "node_modules/ajv": { "version": "8.11.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz", @@ -133,6 +275,28 @@ } } }, + "node_modules/ajv-cli/node_modules/argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "dependencies": { + "sprintf-js": "~1.0.2" + } + }, + "node_modules/ajv-cli/node_modules/js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "dev": true, + "dependencies": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/ajv-formats": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", @@ -150,6 +314,24 @@ } } }, + "node_modules/ansi-colors": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", + "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", + "dev": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true, + "engines": { + "node": ">=8" + } + }, "node_modules/ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -166,12 +348,27 @@ } }, "node_modules/argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, + "node_modules/array-includes": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.5.tgz", + "integrity": "sha512-iSDYZMMyTPkiFasVqfuAQnWAYcvO/SeBSCGKePoEthjp4LEMTe4uLc7b025o4jAZpHhihh8xPo99TNWUWWkGDQ==", "dev": true, "dependencies": { - "sprintf-js": "~1.0.2" + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.19.5", + "get-intrinsic": "^1.1.1", + "is-string": "^1.0.7" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/array-uniq": { @@ -183,6 +380,24 @@ "node": ">=0.10.0" } }, + "node_modules/array.prototype.flat": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.0.tgz", + "integrity": "sha512-12IUEkHsAhA4DY5s0FPgNXIdc8VRSqD9Zp78a5au9abH/SOBrsp082JOWFNTjkMozh8mqcdiKuaLGhPeYztxSw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.2", + "es-shim-unscopables": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/asn1": { "version": "0.2.6", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", @@ -292,6 +507,28 @@ "node": ">=8" } }, + "node_modules/call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true, + "engines": { + "node": ">=6" + } + }, "node_modules/caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -420,12 +657,32 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, + "node_modules/confusing-browser-globals": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz", + "integrity": "sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==", + "dev": true + }, "node_modules/core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", "dev": true }, + "node_modules/cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, "node_modules/css-select": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", @@ -511,6 +768,12 @@ "node": ">=4.0.0" } }, + "node_modules/deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true + }, "node_modules/defer-to-connect": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", @@ -520,6 +783,22 @@ "node": ">=10" } }, + "node_modules/define-properties": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz", + "integrity": "sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==", + "dev": true, + "dependencies": { + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/delayed-stream": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", @@ -529,6 +808,18 @@ "node": ">=0.4.0" } }, + "node_modules/doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/dom-serializer": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", @@ -603,6 +894,18 @@ "once": "^1.4.0" } }, + "node_modules/enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "dev": true, + "dependencies": { + "ansi-colors": "^4.1.1" + }, + "engines": { + "node": ">=8.6" + } + }, "node_modules/entities": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/entities/-/entities-4.3.0.tgz", @@ -615,89 +918,544 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, - "node_modules/esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "node_modules/es-abstract": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz", + "integrity": "sha512-WEm2oBhfoI2sImeM4OF2zE2V3BYdSF+KnSi9Sidz51fQHd7+JuF8Xgcj9/0o+OWeIeIS/MiuNnlruQrJf16GQA==", "dev": true, - "bin": { - "esparse": "bin/esparse.js", - "esvalidate": "bin/esvalidate.js" + "dependencies": { + "call-bind": "^1.0.2", + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "function.prototype.name": "^1.1.5", + "get-intrinsic": "^1.1.1", + "get-symbol-description": "^1.0.0", + "has": "^1.0.3", + "has-property-descriptors": "^1.0.0", + "has-symbols": "^1.0.3", + "internal-slot": "^1.0.3", + "is-callable": "^1.2.4", + "is-negative-zero": "^2.0.2", + "is-regex": "^1.1.4", + "is-shared-array-buffer": "^1.0.2", + "is-string": "^1.0.7", + "is-weakref": "^1.0.2", + "object-inspect": "^1.12.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.2", + "regexp.prototype.flags": "^1.4.3", + "string.prototype.trimend": "^1.0.5", + "string.prototype.trimstart": "^1.0.5", + "unbox-primitive": "^1.0.2" }, "engines": { - "node": ">=4" + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/extend": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", - "dev": true - }, - "node_modules/extsprintf": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", - "integrity": "sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==", + "node_modules/es-shim-unscopables": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-shim-unscopables/-/es-shim-unscopables-1.0.0.tgz", + "integrity": "sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==", "dev": true, - "engines": [ - "node >=0.6.0" - ] - }, - "node_modules/fast-deep-equal": { - "version": "3.1.3", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true + "dependencies": { + "has": "^1.0.3" + } }, - "node_modules/fast-json-patch": { - "version": "2.2.1", - "resolved": "https://registry.npmjs.org/fast-json-patch/-/fast-json-patch-2.2.1.tgz", - "integrity": "sha512-4j5uBaTnsYAV5ebkidvxiLUYOwjQ+JSFljeqfTxCrH9bDmlCQaOJFS84oDJ2rAXZq2yskmk3ORfoP9DCwqFNig==", + "node_modules/es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", "dev": true, "dependencies": { - "fast-deep-equal": "^2.0.1" + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" }, "engines": { - "node": ">= 0.4.0" + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/fast-json-patch/node_modules/fast-deep-equal": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", - "integrity": "sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w==", - "dev": true - }, - "node_modules/fast-json-stable-stringify": { - "version": "2.1.0", - "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", - "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", - "dev": true - }, - "node_modules/forever-agent": { - "version": "0.6.1", - "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", - "integrity": "sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==", + "node_modules/escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", "dev": true, "engines": { - "node": "*" + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/form-data": { - "version": "2.3.3", - "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", - "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "node_modules/eslint": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.2.0.tgz", + "integrity": "sha512-erw7XmM+CLxTOickrimJ1SiF55jiNlVSp2qqm0NuBWPtHYQCegD5ZMaW0c3i5ytPqL+SSLaCxdvQXFPLJn+ABw==", "dev": true, "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.6", - "mime-types": "^2.1.12" + "@eslint/eslintrc": "^1.0.4", + "@humanwhocodes/config-array": "^0.6.0", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "doctrine": "^3.0.0", + "enquirer": "^2.3.5", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^6.0.0", + "eslint-utils": "^3.0.0", + "eslint-visitor-keys": "^3.0.0", + "espree": "^9.0.0", + "esquery": "^1.4.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^6.0.1", + "globals": "^13.6.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "js-yaml": "^4.1.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.0.4", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "progress": "^2.0.0", + "regexpp": "^3.2.0", + "semver": "^7.2.1", + "strip-ansi": "^6.0.1", + "strip-json-comments": "^3.1.0", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "bin": { + "eslint": "bin/eslint.js" }, "engines": { - "node": ">= 0.12" + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint" } }, - "node_modules/fs.realpath": { - "version": "1.0.0", + "node_modules/eslint-config-airbnb-base": { + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-15.0.0.tgz", + "integrity": "sha512-xaX3z4ZZIcFLvh2oUNvcX5oEofXda7giYmuplVxoOg5A7EXJMrUyqRgR+mhDhPK8LZ4PttFOBvCYDbX3sUoUig==", + "dev": true, + "dependencies": { + "confusing-browser-globals": "^1.0.10", + "object.assign": "^4.1.2", + "object.entries": "^1.1.5", + "semver": "^6.3.0" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + }, + "peerDependencies": { + "eslint": "^7.32.0 || ^8.2.0", + "eslint-plugin-import": "^2.25.2" + } + }, + "node_modules/eslint-config-airbnb-base/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true, + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/eslint-config-prettier": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz", + "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==", + "dev": true, + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-import-resolver-node": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz", + "integrity": "sha512-0En0w03NRVMn9Uiyn8YRPDKvWjxCWkslUEhGNTdGx15RvPJYQ+lbOlqrlNI2vEAs4pDYK4f/HN2TbDmk5TP0iw==", + "dev": true, + "dependencies": { + "debug": "^3.2.7", + "resolve": "^1.20.0" + } + }, + "node_modules/eslint-module-utils": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.7.3.tgz", + "integrity": "sha512-088JEC7O3lDZM9xGe0RerkOMd0EjFl+Yvd1jPWIkMT5u3H9+HC34mWWPnqPrN13gieT9pBOO+Qt07Nb/6TresQ==", + "dev": true, + "dependencies": { + "debug": "^3.2.7", + "find-up": "^2.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/eslint-plugin-import": { + "version": "2.25.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.25.2.tgz", + "integrity": "sha512-qCwQr9TYfoBHOFcVGKY9C9unq05uOxxdklmBXLVvcwo68y5Hta6/GzCZEMx2zQiu0woKNEER0LE7ZgaOfBU14g==", + "dev": true, + "dependencies": { + "array-includes": "^3.1.4", + "array.prototype.flat": "^1.2.5", + "debug": "^2.6.9", + "doctrine": "^2.1.0", + "eslint-import-resolver-node": "^0.3.6", + "eslint-module-utils": "^2.7.0", + "has": "^1.0.3", + "is-core-module": "^2.7.0", + "is-glob": "^4.0.3", + "minimatch": "^3.0.4", + "object.values": "^1.1.5", + "resolve": "^1.20.0", + "tsconfig-paths": "^3.11.0" + }, + "engines": { + "node": ">=4" + }, + "peerDependencies": { + "eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8" + } + }, + "node_modules/eslint-plugin-import/node_modules/debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/eslint-plugin-import/node_modules/doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "dependencies": { + "esutils": "^2.0.2" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/eslint-plugin-import/node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", + "dev": true + }, + "node_modules/eslint-scope": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-6.0.0.tgz", + "integrity": "sha512-uRDL9MWmQCkaFus8RF5K9/L/2fn+80yoW3jkD53l4shjCh26fCtvJGasxjUqP5OT87SYTxCVA3BwTUzuELx9kA==", + "dev": true, + "dependencies": { + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/eslint-utils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", + "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", + "dev": true, + "dependencies": { + "eslint-visitor-keys": "^2.0.0" + }, + "engines": { + "node": "^10.0.0 || ^12.0.0 || >= 14.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + }, + "peerDependencies": { + "eslint": ">=5" + } + }, + "node_modules/eslint-utils/node_modules/eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/eslint/node_modules/ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/eslint/node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/eslint/node_modules/ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true, + "engines": { + "node": ">= 4" + } + }, + "node_modules/eslint/node_modules/json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "node_modules/eslint/node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + }, + "node_modules/espree": { + "version": "9.3.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", + "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", + "dev": true, + "dependencies": { + "acorn": "^8.7.1", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.3.0" + }, + "engines": { + "node": "^12.22.0 || ^14.17.0 || >=16.0.0" + } + }, + "node_modules/esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true, + "bin": { + "esparse": "bin/esparse.js", + "esvalidate": "bin/esvalidate.js" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/esquery": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", + "integrity": "sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==", + "dev": true, + "dependencies": { + "estraverse": "^5.1.0" + }, + "engines": { + "node": ">=0.10" + } + }, + "node_modules/esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", + "dev": true, + "dependencies": { + "estraverse": "^5.2.0" + }, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", + "dev": true, + "engines": { + "node": ">=4.0" + } + }, + "node_modules/esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/extend": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "dev": true + }, + "node_modules/extsprintf": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/extsprintf/-/extsprintf-1.3.0.tgz", + "integrity": "sha512-11Ndz7Nv+mvAC1j0ktTa7fAb0vLyGGX+rMHNBYQviQDGU0Hw7lhctJANqbPhu9nV9/izT/IntTgZ7Im/9LJs9g==", + "dev": true, + "engines": [ + "node >=0.6.0" + ] + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "dev": true + }, + "node_modules/fast-json-patch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/fast-json-patch/-/fast-json-patch-2.2.1.tgz", + "integrity": "sha512-4j5uBaTnsYAV5ebkidvxiLUYOwjQ+JSFljeqfTxCrH9bDmlCQaOJFS84oDJ2rAXZq2yskmk3ORfoP9DCwqFNig==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^2.0.1" + }, + "engines": { + "node": ">= 0.4.0" + } + }, + "node_modules/fast-json-patch/node_modules/fast-deep-equal": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz", + "integrity": "sha512-bCK/2Z4zLidyB4ReuIsvALH6w31YfAQDmXMqMx6FyfHqvBxtjC0eRumeSu4Bs3XtXwpyIywtSTrVT99BxY1f9w==", + "dev": true + }, + "node_modules/fast-json-stable-stringify": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", + "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", + "dev": true + }, + "node_modules/fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true + }, + "node_modules/file-entry-cache": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", + "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "dev": true, + "dependencies": { + "flat-cache": "^3.0.4" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha512-NWzkk0jSJtTt08+FBFMvXoeZnOJD+jTtsRmBYbAIzJdX6l7dLgR7CTubCM5/eDdPUBvLCeVasP1brfVR/9/EZQ==", + "dev": true, + "dependencies": { + "locate-path": "^2.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/flat-cache": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", + "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", + "dev": true, + "dependencies": { + "flatted": "^3.1.0", + "rimraf": "^3.0.2" + }, + "engines": { + "node": "^10.12.0 || >=12.0.0" + } + }, + "node_modules/flatted": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.6.tgz", + "integrity": "sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==", + "dev": true + }, + "node_modules/forever-agent": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", + "integrity": "sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==", + "dev": true, + "engines": { + "node": "*" + } + }, + "node_modules/form-data": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-2.3.3.tgz", + "integrity": "sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.6", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 0.12" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==", "dev": true @@ -708,6 +1466,53 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "node_modules/function.prototype.name": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.5.tgz", + "integrity": "sha512-uN7m/BzVKQnCUF/iW8jYea67v++2u7m5UgENbHRtdDVclOUP+FMPlCNdmk0h/ysGyo2tavMJEDqJAkJdRa1vMA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.0", + "functions-have-names": "^1.2.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==", + "dev": true + }, + "node_modules/functions-have-names": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", + "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.2.tgz", + "integrity": "sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA==", + "dev": true, + "dependencies": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/get-stdin": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-9.0.0.tgz", @@ -735,6 +1540,22 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/get-symbol-description": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.0.0.tgz", + "integrity": "sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "get-intrinsic": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -766,24 +1587,73 @@ "node": ">=12" } }, + "node_modules/github-label-sync/node_modules/argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "dependencies": { + "sprintf-js": "~1.0.2" + } + }, + "node_modules/github-label-sync/node_modules/js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "dev": true, + "dependencies": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + }, + "bin": { + "js-yaml": "bin/js-yaml.js" + } + }, "node_modules/glob": { "version": "7.2.3", "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", "dev": true, "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.1.1", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "dependencies": { + "is-glob": "^4.0.3" + }, + "engines": { + "node": ">=10.13.0" + } + }, + "node_modules/globals": { + "version": "13.15.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.15.0.tgz", + "integrity": "sha512-bpzcOlgDhMG070Av0Vy5Owklpv1I6+j96GhUI7Rh7IzDCKLzboflLrrfqMu8NquDbiR4EOQk7XzJwqVJxicxog==", + "dev": true, + "dependencies": { + "type-fest": "^0.20.2" }, "engines": { - "node": "*" + "node": ">=8" }, "funding": { - "url": "https://github.com/sponsors/isaacs" + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/got": { @@ -868,6 +1738,15 @@ "node": ">= 0.4.0" } }, + "node_modules/has-bigints": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", + "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -877,6 +1756,45 @@ "node": ">=8" } }, + "node_modules/has-property-descriptors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", + "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.1.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", + "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", + "dev": true, + "dependencies": { + "has-symbols": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/html-link-extractor": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/html-link-extractor/-/html-link-extractor-1.0.5.tgz", @@ -960,6 +1878,31 @@ "node": ">= 4" } }, + "node_modules/import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, + "dependencies": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + }, + "engines": { + "node": ">=6" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true, + "engines": { + "node": ">=0.8.19" + } + }, "node_modules/inflight": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", @@ -985,6 +1928,20 @@ "node": ">=10" } }, + "node_modules/internal-slot": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.3.tgz", + "integrity": "sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA==", + "dev": true, + "dependencies": { + "get-intrinsic": "^1.1.0", + "has": "^1.0.3", + "side-channel": "^1.0.4" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/is": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz", @@ -1003,6 +1960,137 @@ "node": ">=8" } }, + "node_modules/is-bigint": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", + "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", + "dev": true, + "dependencies": { + "has-bigints": "^1.0.1" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-boolean-object": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", + "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-callable": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.4.tgz", + "integrity": "sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-core-module": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.9.0.tgz", + "integrity": "sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==", + "dev": true, + "dependencies": { + "has": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-date-object": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", + "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", + "dev": true, + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dev": true, + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-negative-zero": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", + "integrity": "sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-number-object": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", + "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", + "dev": true, + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-regex": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", + "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-relative-url": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/is-relative-url/-/is-relative-url-3.0.0.tgz", @@ -1015,12 +2103,66 @@ "node": ">=8" } }, + "node_modules/is-shared-array-buffer": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz", + "integrity": "sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-string": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", + "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", + "dev": true, + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/is-symbol": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", + "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", + "dev": true, + "dependencies": { + "has-symbols": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==", "dev": true }, + "node_modules/is-weakref": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-weakref/-/is-weakref-1.0.2.tgz", + "integrity": "sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/isemail": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/isemail/-/isemail-3.2.0.tgz", @@ -1033,6 +2175,12 @@ "node": ">=4.0.0" } }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, "node_modules/isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -1040,13 +2188,11 @@ "dev": true }, "node_modules/js-yaml": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", - "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", - "dev": true, + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "dependencies": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" + "argparse": "^2.0.1" }, "bin": { "js-yaml": "bin/js-yaml.js" @@ -1085,6 +2231,12 @@ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true }, + "node_modules/json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true + }, "node_modules/json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -1134,6 +2286,19 @@ "json-buffer": "3.0.1" } }, + "node_modules/levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/link-check": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/link-check/-/link-check-5.1.0.tgz", @@ -1155,12 +2320,31 @@ "uc.micro": "^1.0.1" } }, + "node_modules/locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==", + "dev": true, + "dependencies": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "node_modules/lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true + }, "node_modules/lowercase-keys": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", @@ -1170,6 +2354,18 @@ "node": ">=8" } }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/markdown-it": { "version": "12.3.2", "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", @@ -1186,12 +2382,6 @@ "markdown-it": "bin/markdown-it.js" } }, - "node_modules/markdown-it/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, "node_modules/markdown-it/node_modules/entities": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz", @@ -1266,12 +2456,6 @@ "node": ">=12" } }, - "node_modules/markdownlint-cli/node_modules/argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, "node_modules/markdownlint-cli/node_modules/commander": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.0.0.tgz", @@ -1281,18 +2465,6 @@ "node": "^12.20.0 || >=14" } }, - "node_modules/markdownlint-cli/node_modules/js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, - "dependencies": { - "argparse": "^2.0.1" - }, - "bin": { - "js-yaml": "bin/js-yaml.js" - } - }, "node_modules/markdownlint-cli/node_modules/minimatch": { "version": "3.0.8", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.8.tgz", @@ -1383,6 +2555,12 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, + "node_modules/natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true + }, "node_modules/needle": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/needle/-/needle-3.1.0.tgz", @@ -1443,7 +2621,74 @@ "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", "dev": true, "engines": { - "node": "*" + "node": "*" + } + }, + "node_modules/object-inspect": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", + "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==", + "dev": true, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/object.entries": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.5.tgz", + "integrity": "sha512-TyxmjUoZggd4OrrU1W66FMDG6CuqJxsFvymeyXI51+vQLN67zYfZseptRge703kKQdo4uccgAKebXFcRCzk4+g==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.1" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/object.values": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.5.tgz", + "integrity": "sha512-QUZRW0ilQ3PnPpbNtgdNV1PDbEqLIiSFB3l+EnGtBQ/8SUTLj1PZwtQHABZtLgwpJZTSZhuGLOGk57Drx2IvYg==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" } }, "node_modules/octonode": { @@ -1470,6 +2715,23 @@ "wrappy": "1" } }, + "node_modules/optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "dependencies": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + }, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/p-cancelable": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", @@ -1479,6 +2741,51 @@ "node": ">=8" } }, + "node_modules/p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "dependencies": { + "p-try": "^1.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==", + "dev": true, + "dependencies": { + "p-limit": "^1.1.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha512-U1etNYuMJoIz3ZXSrrySFjsXQTWOx2/jdi86L+2pRvph/qMKL6sbcCYdH23fqsbm8TH2Gn0OybpT4eSFlCVHww==", + "dev": true, + "engines": { + "node": ">=4" + } + }, + "node_modules/parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "dependencies": { + "callsites": "^3.0.0" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/parse5": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.0.0.tgz", @@ -1504,6 +2811,15 @@ "url": "https://github.com/inikulin/parse5?sponsor=1" } }, + "node_modules/path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", @@ -1513,12 +2829,36 @@ "node": ">=0.10.0" } }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true + }, "node_modules/performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", "dev": true }, + "node_modules/prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true, + "engines": { + "node": ">= 0.8.0" + } + }, "node_modules/prettier": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", @@ -1611,6 +2951,35 @@ "node": "*" } }, + "node_modules/regexp.prototype.flags": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.3.tgz", + "integrity": "sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "functions-have-names": "^1.2.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/regexpp": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", + "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/mysticatea" + } + }, "node_modules/request": { "version": "2.88.2", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", @@ -1652,12 +3021,38 @@ "node": ">=0.10.0" } }, + "node_modules/resolve": { + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", + "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "dev": true, + "dependencies": { + "is-core-module": "^2.9.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/resolve-alpn": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz", "integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==", "dev": true }, + "node_modules/resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/responselike": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz", @@ -1667,6 +3062,21 @@ "lowercase-keys": "^2.0.0" } }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/run-con": { "version": "1.2.10", "resolved": "https://registry.npmjs.org/run-con/-/run-con-1.2.10.tgz", @@ -1714,6 +3124,56 @@ "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", "dev": true }, + "node_modules/semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -1745,6 +3205,55 @@ "node": ">=0.10.0" } }, + "node_modules/string.prototype.trimend": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.5.tgz", + "integrity": "sha512-I7RGvmjV4pJ7O3kdf+LXFpVfdNOxtCW/2C8f6jNiW4+PQchwxkCDzlk1/7p+Wl4bqFIZeF47qAHXLuHHWKAxog==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.19.5" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/string.prototype.trimstart": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.5.tgz", + "integrity": "sha512-THx16TJCGlsN0o6dl2o6ncWUsdgnLRSA23rRE5pyGBw/mLr3Ej/R2LaqCtgP8VNMGZsvMWnf9ooZPyY2bHvUFg==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.19.5" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true, + "engines": { + "node": ">=4" + } + }, "node_modules/strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -1769,6 +3278,24 @@ "node": ">=8" } }, + "node_modules/supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true + }, "node_modules/tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", @@ -1782,6 +3309,30 @@ "node": ">=0.8" } }, + "node_modules/tsconfig-paths": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz", + "integrity": "sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==", + "dev": true, + "dependencies": { + "@types/json5": "^0.0.29", + "json5": "^1.0.1", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + } + }, + "node_modules/tsconfig-paths/node_modules/json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "dev": true, + "dependencies": { + "minimist": "^1.2.0" + }, + "bin": { + "json5": "lib/cli.js" + } + }, "node_modules/tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", @@ -1806,12 +3357,51 @@ "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==", "dev": true }, + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "dependencies": { + "prelude-ls": "^1.2.1" + }, + "engines": { + "node": ">= 0.8.0" + } + }, + "node_modules/type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", "dev": true }, + "node_modules/unbox-primitive": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", + "integrity": "sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==", + "dev": true, + "dependencies": { + "call-bind": "^1.0.2", + "has-bigints": "^1.0.2", + "has-symbols": "^1.0.3", + "which-boxed-primitive": "^1.0.2" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -1831,6 +3421,12 @@ "uuid": "bin/uuid" } }, + "node_modules/v8-compile-cache": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", + "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", + "dev": true + }, "node_modules/verror": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", @@ -1845,20 +3441,152 @@ "extsprintf": "^1.2.0" } }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/which-boxed-primitive": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", + "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", + "dev": true, + "dependencies": { + "is-bigint": "^1.0.1", + "is-boolean-object": "^1.1.0", + "is-number-object": "^1.0.4", + "is-string": "^1.0.5", + "is-symbol": "^1.0.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true } }, "dependencies": { + "@eslint/eslintrc": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.3.0.tgz", + "integrity": "sha512-UWW0TMTmk2d7hLcWD1/e2g5HDM/HQ3csaLSqXCfqwh4uNDuNqlaKWXmEsL4Cs41Z0KnILNvwbHAah3C2yt06kw==", + "dev": true, + "requires": { + "ajv": "^6.12.4", + "debug": "^4.3.2", + "espree": "^9.3.2", + "globals": "^13.15.0", + "ignore": "^5.2.0", + "import-fresh": "^3.2.1", + "js-yaml": "^4.1.0", + "minimatch": "^3.1.2", + "strip-json-comments": "^3.1.1" + }, + "dependencies": { + "ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, "@financial-times/origami-service-makefile": { "version": "7.0.3", "resolved": "https://registry.npmjs.org/@financial-times/origami-service-makefile/-/origami-service-makefile-7.0.3.tgz", "integrity": "sha512-aKe65sZ3XgZ/0Sm0MDLbGrcO3G4DRv/bVW4Gpmw68cRZV9IBE7h/pwfR3Rs7njNSZMFkjS4rPG/YySv9brQByA==", "dev": true }, + "@humanwhocodes/config-array": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.6.0.tgz", + "integrity": "sha512-JQlEKbcgEUjBFhLIF4iqM7u/9lwgHRBcpHrmUNCALK0Q3amXN6lxdoXLnF0sm11E9VqTmBALR87IlUg1bZ8A9A==", + "dev": true, + "requires": { + "@humanwhocodes/object-schema": "^1.2.0", + "debug": "^4.1.1", + "minimatch": "^3.0.4" + }, + "dependencies": { + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, + "@humanwhocodes/object-schema": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@humanwhocodes/object-schema/-/object-schema-1.2.1.tgz", + "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", + "dev": true + }, "@sindresorhus/is": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz", @@ -1898,6 +3626,12 @@ "integrity": "sha512-3YP80IxxFJB4b5tYC2SUPwkg0XQLiu0nWvhRgEatgjf+29IcWO9X1k8xRv5DGssJ/lCrjYTjQPcobJr2yWIVuQ==", "dev": true }, + "@types/json5": { + "version": "0.0.29", + "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", + "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", + "dev": true + }, "@types/keyv": { "version": "3.1.4", "resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz", @@ -1922,6 +3656,19 @@ "@types/node": "*" } }, + "acorn": { + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.7.1.tgz", + "integrity": "sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A==", + "dev": true + }, + "acorn-jsx": { + "version": "5.3.2", + "resolved": "https://registry.npmjs.org/acorn-jsx/-/acorn-jsx-5.3.2.tgz", + "integrity": "sha512-rq9s+JNhf0IChjtDXxllJ7g41oZk5SlXtp0LHwyA5cejwn7vKmKp4pPri6YEePv2PU65sAsegbXtIinmDFDXgQ==", + "dev": true, + "requires": {} + }, "ajv": { "version": "8.11.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz", @@ -1947,6 +3694,27 @@ "json-schema-migrate": "^2.0.0", "json5": "^2.1.3", "minimist": "^1.2.0" + }, + "dependencies": { + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "~1.0.2" + } + }, + "js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + } } }, "ajv-formats": { @@ -1958,6 +3726,18 @@ "ajv": "^8.0.0" } }, + "ansi-colors": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-4.1.3.tgz", + "integrity": "sha512-/6w/C21Pm1A7aZitlI5Ni/2J6FFQN8i1Cvz3kHABAAbw93v/NlvKdVOqz7CCWz/3iv/JplRSEEZ83XION15ovw==", + "dev": true + }, + "ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "dev": true + }, "ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -1968,12 +3748,21 @@ } }, "argparse": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", - "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, + "array-includes": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/array-includes/-/array-includes-3.1.5.tgz", + "integrity": "sha512-iSDYZMMyTPkiFasVqfuAQnWAYcvO/SeBSCGKePoEthjp4LEMTe4uLc7b025o4jAZpHhihh8xPo99TNWUWWkGDQ==", "dev": true, "requires": { - "sprintf-js": "~1.0.2" + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.19.5", + "get-intrinsic": "^1.1.1", + "is-string": "^1.0.7" } }, "array-uniq": { @@ -1982,6 +3771,18 @@ "integrity": "sha512-GVYjmpL05al4dNlKJm53mKE4w9OOLiuVHWorsIA3YVz+Hu0hcn6PtE3Ydl0EqU7v+7ABC4mjjWsnLUxbpno+CA==", "dev": true }, + "array.prototype.flat": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.3.0.tgz", + "integrity": "sha512-12IUEkHsAhA4DY5s0FPgNXIdc8VRSqD9Zp78a5au9abH/SOBrsp082JOWFNTjkMozh8mqcdiKuaLGhPeYztxSw==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.2", + "es-shim-unscopables": "^1.0.0" + } + }, "asn1": { "version": "0.2.6", "resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.6.tgz", @@ -2079,6 +3880,22 @@ "responselike": "^2.0.0" } }, + "call-bind": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", + "integrity": "sha512-7O+FbCihrB5WGbFYesctwmTKae6rOiIzmz1icreWJ+0aA7LJfuqhEso2T9ncpcFtzMQtzXf2QGGueWJGTYsqrA==", + "dev": true, + "requires": { + "function-bind": "^1.1.1", + "get-intrinsic": "^1.0.2" + } + }, + "callsites": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", + "integrity": "sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==", + "dev": true + }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -2180,12 +3997,29 @@ "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==", "dev": true }, + "confusing-browser-globals": { + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/confusing-browser-globals/-/confusing-browser-globals-1.0.11.tgz", + "integrity": "sha512-JsPKdmh8ZkmnHxDk55FZ1TqVLvEQTvoByJZRN9jzI0UjxK/QgAmsphz7PGtqgPieQZ/CQcHWXCR7ATDNhGe+YA==", + "dev": true + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "integrity": "sha512-3lqz5YjWTYnW6dlDa5TLaTCcShfar1e40rmcJVwCBJC6mWlFuj0eCHIElmG1g5kyuJ/GD+8Wn4FFCcz4gJPfaQ==", "dev": true }, + "cross-spawn": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz", + "integrity": "sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==", + "dev": true, + "requires": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + } + }, "css-select": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/css-select/-/css-select-5.1.0.tgz", @@ -2211,119 +4045,465 @@ "integrity": "sha512-jRFi8UDGo6j+odZiEpjazZaWqEal3w/basFjQHQEwVtZJGDpxbH1MeYluwCS8Xq5wmLJooDlMgvVarmWfGM44g==", "dev": true, "requires": { - "assert-plus": "^1.0.0" + "assert-plus": "^1.0.0" + } + }, + "debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dev": true, + "requires": { + "ms": "^2.1.1" + } + }, + "decompress-response": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", + "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "dev": true, + "requires": { + "mimic-response": "^3.1.0" + }, + "dependencies": { + "mimic-response": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", + "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "dev": true + } + } + }, + "deep-extend": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", + "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", + "dev": true + }, + "deep-is": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", + "integrity": "sha512-oIPzksmTg4/MriiaYGO+okXDT7ztn/w3Eptv/+gSIdMdKsJo0u4CfYNFJPy+4SKMuCqGw2wxnA+URMg3t8a/bQ==", + "dev": true + }, + "defer-to-connect": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", + "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==", + "dev": true + }, + "define-properties": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.4.tgz", + "integrity": "sha512-uckOqKcfaVvtBdsVkdPv3XjveQJsNQqmhXgRi8uhvWWuPYZCNlzT8qAyblUgNoXdHdjMTzAqeGjAoli8f+bzPA==", + "dev": true, + "requires": { + "has-property-descriptors": "^1.0.0", + "object-keys": "^1.1.1" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true + }, + "doctrine": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz", + "integrity": "sha512-yS+Q5i3hBf7GBkd4KG8a7eBNNWNGLTaEwwYWUijIYM7zrlYDM0BFXHjjPWlWZ1Rg7UaddZeIDmi9jF3HmqiQ2w==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, + "dom-serializer": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", + "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "dev": true, + "requires": { + "domelementtype": "^2.3.0", + "domhandler": "^5.0.2", + "entities": "^4.2.0" + } + }, + "domelementtype": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", + "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", + "dev": true + }, + "domhandler": { + "version": "5.0.3", + "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", + "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "dev": true, + "requires": { + "domelementtype": "^2.3.0" + } + }, + "domutils": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.0.1.tgz", + "integrity": "sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==", + "dev": true, + "requires": { + "dom-serializer": "^2.0.0", + "domelementtype": "^2.3.0", + "domhandler": "^5.0.1" + } + }, + "ecc-jsbn": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", + "integrity": "sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==", + "dev": true, + "requires": { + "jsbn": "~0.1.0", + "safer-buffer": "^2.1.0" + } + }, + "end-of-stream": { + "version": "1.4.4", + "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", + "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "dev": true, + "requires": { + "once": "^1.4.0" + } + }, + "enquirer": { + "version": "2.3.6", + "resolved": "https://registry.npmjs.org/enquirer/-/enquirer-2.3.6.tgz", + "integrity": "sha512-yjNnPr315/FjS4zIsUxYguYUPP2e1NK4d7E7ZOLiyYCcbFBiTMyID+2wvm2w6+pZ/odMA7cRkjhsPbltwBOrLg==", + "dev": true, + "requires": { + "ansi-colors": "^4.1.1" + } + }, + "entities": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-4.3.0.tgz", + "integrity": "sha512-/iP1rZrSEJ0DTlPiX+jbzlA3eVkY/e8L8SozroF395fIqE3TYF/Nz7YOMAawta+vLmyJ/hkGNNPcSbMADCCXbg==", + "dev": true + }, + "es-abstract": { + "version": "1.20.1", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.20.1.tgz", + "integrity": "sha512-WEm2oBhfoI2sImeM4OF2zE2V3BYdSF+KnSi9Sidz51fQHd7+JuF8Xgcj9/0o+OWeIeIS/MiuNnlruQrJf16GQA==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "function.prototype.name": "^1.1.5", + "get-intrinsic": "^1.1.1", + "get-symbol-description": "^1.0.0", + "has": "^1.0.3", + "has-property-descriptors": "^1.0.0", + "has-symbols": "^1.0.3", + "internal-slot": "^1.0.3", + "is-callable": "^1.2.4", + "is-negative-zero": "^2.0.2", + "is-regex": "^1.1.4", + "is-shared-array-buffer": "^1.0.2", + "is-string": "^1.0.7", + "is-weakref": "^1.0.2", + "object-inspect": "^1.12.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.2", + "regexp.prototype.flags": "^1.4.3", + "string.prototype.trimend": "^1.0.5", + "string.prototype.trimstart": "^1.0.5", + "unbox-primitive": "^1.0.2" + } + }, + "es-shim-unscopables": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-shim-unscopables/-/es-shim-unscopables-1.0.0.tgz", + "integrity": "sha512-Jm6GPcCdC30eMLbZ2x8z2WuRwAws3zTBBKuusffYVUrNj/GVSUAZ+xKMaUpfNDR5IbyNA5LJbaecoUVbmUcB1w==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "dev": true, + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "escape-string-regexp": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz", + "integrity": "sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==", + "dev": true + }, + "eslint": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-8.2.0.tgz", + "integrity": "sha512-erw7XmM+CLxTOickrimJ1SiF55jiNlVSp2qqm0NuBWPtHYQCegD5ZMaW0c3i5ytPqL+SSLaCxdvQXFPLJn+ABw==", + "dev": true, + "requires": { + "@eslint/eslintrc": "^1.0.4", + "@humanwhocodes/config-array": "^0.6.0", + "ajv": "^6.10.0", + "chalk": "^4.0.0", + "cross-spawn": "^7.0.2", + "debug": "^4.3.2", + "doctrine": "^3.0.0", + "enquirer": "^2.3.5", + "escape-string-regexp": "^4.0.0", + "eslint-scope": "^6.0.0", + "eslint-utils": "^3.0.0", + "eslint-visitor-keys": "^3.0.0", + "espree": "^9.0.0", + "esquery": "^1.4.0", + "esutils": "^2.0.2", + "fast-deep-equal": "^3.1.3", + "file-entry-cache": "^6.0.1", + "functional-red-black-tree": "^1.0.1", + "glob-parent": "^6.0.1", + "globals": "^13.6.0", + "ignore": "^4.0.6", + "import-fresh": "^3.0.0", + "imurmurhash": "^0.1.4", + "is-glob": "^4.0.0", + "js-yaml": "^4.1.0", + "json-stable-stringify-without-jsonify": "^1.0.1", + "levn": "^0.4.1", + "lodash.merge": "^4.6.2", + "minimatch": "^3.0.4", + "natural-compare": "^1.4.0", + "optionator": "^0.9.1", + "progress": "^2.0.0", + "regexpp": "^3.2.0", + "semver": "^7.2.1", + "strip-ansi": "^6.0.1", + "strip-json-comments": "^3.1.0", + "text-table": "^0.2.0", + "v8-compile-cache": "^2.0.3" + }, + "dependencies": { + "ajv": { + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.1", + "fast-json-stable-stringify": "^2.0.0", + "json-schema-traverse": "^0.4.1", + "uri-js": "^4.2.2" + } + }, + "debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dev": true, + "requires": { + "ms": "2.1.2" + } + }, + "ignore": { + "version": "4.0.6", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz", + "integrity": "sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==", + "dev": true + }, + "json-schema-traverse": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", + "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==", + "dev": true + }, + "ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", + "dev": true + } + } + }, + "eslint-config-airbnb-base": { + "version": "15.0.0", + "resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-15.0.0.tgz", + "integrity": "sha512-xaX3z4ZZIcFLvh2oUNvcX5oEofXda7giYmuplVxoOg5A7EXJMrUyqRgR+mhDhPK8LZ4PttFOBvCYDbX3sUoUig==", + "dev": true, + "requires": { + "confusing-browser-globals": "^1.0.10", + "object.assign": "^4.1.2", + "object.entries": "^1.1.5", + "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } + } + }, + "eslint-config-prettier": { + "version": "8.5.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-8.5.0.tgz", + "integrity": "sha512-obmWKLUNCnhtQRKc+tmnYuQl0pFU1ibYJQ5BGhTVB08bHe9wC8qUeG7c08dj9XX+AuPj1YSGSQIHl1pnDHZR0Q==", + "dev": true, + "requires": {} + }, + "eslint-import-resolver-node": { + "version": "0.3.6", + "resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.6.tgz", + "integrity": "sha512-0En0w03NRVMn9Uiyn8YRPDKvWjxCWkslUEhGNTdGx15RvPJYQ+lbOlqrlNI2vEAs4pDYK4f/HN2TbDmk5TP0iw==", + "dev": true, + "requires": { + "debug": "^3.2.7", + "resolve": "^1.20.0" } }, - "debug": { - "version": "3.2.7", - "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", - "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "eslint-module-utils": { + "version": "2.7.3", + "resolved": "https://registry.npmjs.org/eslint-module-utils/-/eslint-module-utils-2.7.3.tgz", + "integrity": "sha512-088JEC7O3lDZM9xGe0RerkOMd0EjFl+Yvd1jPWIkMT5u3H9+HC34mWWPnqPrN13gieT9pBOO+Qt07Nb/6TresQ==", "dev": true, "requires": { - "ms": "^2.1.1" + "debug": "^3.2.7", + "find-up": "^2.1.0" } }, - "decompress-response": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/decompress-response/-/decompress-response-6.0.0.tgz", - "integrity": "sha512-aW35yZM6Bb/4oJlZncMH2LCoZtJXTRxES17vE3hoRiowU2kWHaJKFkSBDnDR+cm9J+9QhXmREyIfv0pji9ejCQ==", + "eslint-plugin-import": { + "version": "2.25.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-import/-/eslint-plugin-import-2.25.2.tgz", + "integrity": "sha512-qCwQr9TYfoBHOFcVGKY9C9unq05uOxxdklmBXLVvcwo68y5Hta6/GzCZEMx2zQiu0woKNEER0LE7ZgaOfBU14g==", "dev": true, "requires": { - "mimic-response": "^3.1.0" + "array-includes": "^3.1.4", + "array.prototype.flat": "^1.2.5", + "debug": "^2.6.9", + "doctrine": "^2.1.0", + "eslint-import-resolver-node": "^0.3.6", + "eslint-module-utils": "^2.7.0", + "has": "^1.0.3", + "is-core-module": "^2.7.0", + "is-glob": "^4.0.3", + "minimatch": "^3.0.4", + "object.values": "^1.1.5", + "resolve": "^1.20.0", + "tsconfig-paths": "^3.11.0" }, "dependencies": { - "mimic-response": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", - "integrity": "sha512-z0yWI+4FDrrweS8Zmt4Ej5HdJmky15+L2e6Wgn3+iK5fWzb6T3fhNFq2+MeTRb064c6Wr4N/wv0DzQTjNzHNGQ==", + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "doctrine": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/doctrine/-/doctrine-2.1.0.tgz", + "integrity": "sha512-35mSku4ZXK0vfCuHEDAwt55dg2jNajHZ1odvF+8SSr82EsZY4QmXfuWso8oEd8zRhVObSN18aM0CjSdoBX7zIw==", + "dev": true, + "requires": { + "esutils": "^2.0.2" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==", "dev": true } } }, - "deep-extend": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", - "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==", - "dev": true - }, - "defer-to-connect": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/defer-to-connect/-/defer-to-connect-2.0.1.tgz", - "integrity": "sha512-4tvttepXG1VaYGrRibk5EwJd1t4udunSOVMdLSAL6mId1ix438oPwPZMALY41FCijukO1L0twNcGsdzS7dHgDg==", - "dev": true - }, - "delayed-stream": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "dev": true - }, - "dom-serializer": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-2.0.0.tgz", - "integrity": "sha512-wIkAryiqt/nV5EQKqQpo3SToSOV9J0DnbJqwK7Wv/Trc92zIAYZ4FlMu+JPFW1DfGFt81ZTCGgDEabffXeLyJg==", + "eslint-scope": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-6.0.0.tgz", + "integrity": "sha512-uRDL9MWmQCkaFus8RF5K9/L/2fn+80yoW3jkD53l4shjCh26fCtvJGasxjUqP5OT87SYTxCVA3BwTUzuELx9kA==", "dev": true, "requires": { - "domelementtype": "^2.3.0", - "domhandler": "^5.0.2", - "entities": "^4.2.0" + "esrecurse": "^4.3.0", + "estraverse": "^5.2.0" } }, - "domelementtype": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.3.0.tgz", - "integrity": "sha512-OLETBj6w0OsagBwdXnPdN0cnMfF9opN69co+7ZrbfPGrdpPVNBUj02spi6B1N7wChLQiPn4CSH/zJvXw56gmHw==", - "dev": true - }, - "domhandler": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/domhandler/-/domhandler-5.0.3.tgz", - "integrity": "sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==", + "eslint-utils": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/eslint-utils/-/eslint-utils-3.0.0.tgz", + "integrity": "sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==", "dev": true, "requires": { - "domelementtype": "^2.3.0" + "eslint-visitor-keys": "^2.0.0" + }, + "dependencies": { + "eslint-visitor-keys": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-2.1.0.tgz", + "integrity": "sha512-0rSmRBzXgDzIsD6mGdJgevzgezI534Cer5L/vyMX0kHzT/jiB43jRhd9YUlMGYLQy2zprNmoT8qasCGtY+QaKw==", + "dev": true + } } }, - "domutils": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/domutils/-/domutils-3.0.1.tgz", - "integrity": "sha512-z08c1l761iKhDFtfXO04C7kTdPBLi41zwOZl00WS8b5eiaebNpY00HKbztwBq+e3vyqWNwWF3mP9YLUeqIrF+Q==", + "eslint-visitor-keys": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/eslint-visitor-keys/-/eslint-visitor-keys-3.3.0.tgz", + "integrity": "sha512-mQ+suqKJVyeuwGYHAdjMFqjCyfl8+Ldnxuyp3ldiMBFKkvytrXUZWaiPCEav8qDHKty44bD+qV1IP4T+w+xXRA==", + "dev": true + }, + "espree": { + "version": "9.3.2", + "resolved": "https://registry.npmjs.org/espree/-/espree-9.3.2.tgz", + "integrity": "sha512-D211tC7ZwouTIuY5x9XnS0E9sWNChB7IYKX/Xp5eQj3nFXhqmiUDB9q27y76oFl8jTg3pXcQx/bpxMfs3CIZbA==", "dev": true, "requires": { - "dom-serializer": "^2.0.0", - "domelementtype": "^2.3.0", - "domhandler": "^5.0.1" + "acorn": "^8.7.1", + "acorn-jsx": "^5.3.2", + "eslint-visitor-keys": "^3.3.0" } }, - "ecc-jsbn": { - "version": "0.1.2", - "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", - "integrity": "sha512-eh9O+hwRHNbG4BLTjEl3nw044CkGm5X6LoaCf7LPp7UU8Qrt47JYNi6nPX8xjW97TKGKm1ouctg0QSpZe9qrnw==", + "esprima": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", + "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "dev": true + }, + "esquery": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/esquery/-/esquery-1.4.0.tgz", + "integrity": "sha512-cCDispWt5vHHtwMY2YrAQ4ibFkAL8RbH5YGBnZBc90MolvvfkkQcJro/aZiAQUlQ3qgrYS6D6v8Gc5G5CQsc9w==", "dev": true, "requires": { - "jsbn": "~0.1.0", - "safer-buffer": "^2.1.0" + "estraverse": "^5.1.0" } }, - "end-of-stream": { - "version": "1.4.4", - "resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz", - "integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==", + "esrecurse": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/esrecurse/-/esrecurse-4.3.0.tgz", + "integrity": "sha512-KmfKL3b6G+RXvP8N1vr3Tq1kL/oCFgn2NYXEtqP8/L3pKapUA4G8cFVaoF3SU323CD4XypR/ffioHmkti6/Tag==", "dev": true, "requires": { - "once": "^1.4.0" + "estraverse": "^5.2.0" } }, - "entities": { - "version": "4.3.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-4.3.0.tgz", - "integrity": "sha512-/iP1rZrSEJ0DTlPiX+jbzlA3eVkY/e8L8SozroF395fIqE3TYF/Nz7YOMAawta+vLmyJ/hkGNNPcSbMADCCXbg==", + "estraverse": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-5.3.0.tgz", + "integrity": "sha512-MMdARuVEQziNTeJD8DgMqmhwR11BRQ/cBP+pLtYdSTnf3MIO8fFeiINEbX36ZdNlfU/7A9f3gUw49B3oQsvwBA==", "dev": true }, - "esprima": { - "version": "4.0.1", - "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", - "integrity": "sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A==", + "esutils": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", + "integrity": "sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==", "dev": true }, "extend": { @@ -2367,6 +4547,46 @@ "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==", "dev": true }, + "fast-levenshtein": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz", + "integrity": "sha512-DCXu6Ifhqcks7TZKY3Hxp3y6qphY5SJZmrWMDrKcERSOXWQdMhU9Ig/PYrzyw/ul9jOIyh0N4M0tbC5hodg8dw==", + "dev": true + }, + "file-entry-cache": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-6.0.1.tgz", + "integrity": "sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==", + "dev": true, + "requires": { + "flat-cache": "^3.0.4" + } + }, + "find-up": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-2.1.0.tgz", + "integrity": "sha512-NWzkk0jSJtTt08+FBFMvXoeZnOJD+jTtsRmBYbAIzJdX6l7dLgR7CTubCM5/eDdPUBvLCeVasP1brfVR/9/EZQ==", + "dev": true, + "requires": { + "locate-path": "^2.0.0" + } + }, + "flat-cache": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/flat-cache/-/flat-cache-3.0.4.tgz", + "integrity": "sha512-dm9s5Pw7Jc0GvMYbshN6zchCA9RgQlzzEZX3vylR9IqFfS8XciblUXOKfW6SiuJ0e13eDYZoZV5wdrev7P3Nwg==", + "dev": true, + "requires": { + "flatted": "^3.1.0", + "rimraf": "^3.0.2" + } + }, + "flatted": { + "version": "3.2.6", + "resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.6.tgz", + "integrity": "sha512-0sQoMh9s0BYsm+12Huy/rkKxVu4R1+r96YX5cG44rHV0pQ6iC3Q+mkoMFaGWObMFYQxCVT+ssG1ksneA2MI9KQ==", + "dev": true + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -2396,6 +4616,41 @@ "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "dev": true }, + "function.prototype.name": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/function.prototype.name/-/function.prototype.name-1.1.5.tgz", + "integrity": "sha512-uN7m/BzVKQnCUF/iW8jYea67v++2u7m5UgENbHRtdDVclOUP+FMPlCNdmk0h/ysGyo2tavMJEDqJAkJdRa1vMA==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.0", + "functions-have-names": "^1.2.2" + } + }, + "functional-red-black-tree": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/functional-red-black-tree/-/functional-red-black-tree-1.0.1.tgz", + "integrity": "sha512-dsKNQNdj6xA3T+QlADDA7mOSlX0qiMINjn0cgr+eGHGsbSHzTabcIogz2+p/iqP1Xs6EP/sS2SbqH+brGTbq0g==", + "dev": true + }, + "functions-have-names": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", + "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", + "dev": true + }, + "get-intrinsic": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.2.tgz", + "integrity": "sha512-Jfm3OyCxHh9DJyc28qGk+JmfkpO41A4XkneDSujN9MDXrm4oDKdHvndhZ2dN94+ERNfkYJWDclW6k2L/ZGHjXA==", + "dev": true, + "requires": { + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.3" + } + }, "get-stdin": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-9.0.0.tgz", @@ -2411,6 +4666,16 @@ "pump": "^3.0.0" } }, + "get-symbol-description": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/get-symbol-description/-/get-symbol-description-1.0.0.tgz", + "integrity": "sha512-2EmdH1YvIQiZpltCNgkuiUnyukzxM/R6NDJX31Ke3BG1Nq5b0S2PhX59UKi9vZpPDQVdqn+1IcaAwnzTT5vCjw==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "get-intrinsic": "^1.1.1" + } + }, "getpass": { "version": "0.1.7", "resolved": "https://registry.npmjs.org/getpass/-/getpass-0.1.7.tgz", @@ -2434,6 +4699,27 @@ "js-yaml": "^3.14.1", "node.extend": "^2.0.2", "octonode": "^0.10.2" + }, + "dependencies": { + "argparse": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", + "integrity": "sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg==", + "dev": true, + "requires": { + "sprintf-js": "~1.0.2" + } + }, + "js-yaml": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", + "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", + "dev": true, + "requires": { + "argparse": "^1.0.7", + "esprima": "^4.0.0" + } + } } }, "glob": { @@ -2450,6 +4736,24 @@ "path-is-absolute": "^1.0.0" } }, + "glob-parent": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz", + "integrity": "sha512-XxwI8EOhVQgWp6iDL+3b0r86f4d6AX6zSU55HfB4ydCEuXLXc5FcYeOu+nnGftS4TEju/11rt4KJPTMgbfmv4A==", + "dev": true, + "requires": { + "is-glob": "^4.0.3" + } + }, + "globals": { + "version": "13.15.0", + "resolved": "https://registry.npmjs.org/globals/-/globals-13.15.0.tgz", + "integrity": "sha512-bpzcOlgDhMG070Av0Vy5Owklpv1I6+j96GhUI7Rh7IzDCKLzboflLrrfqMu8NquDbiR4EOQk7XzJwqVJxicxog==", + "dev": true, + "requires": { + "type-fest": "^0.20.2" + } + }, "got": { "version": "11.8.5", "resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz", @@ -2514,12 +4818,42 @@ "function-bind": "^1.1.1" } }, + "has-bigints": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", + "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", + "dev": true + }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, + "has-property-descriptors": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.0.tgz", + "integrity": "sha512-62DVLZGoiEBDHQyqG4w9xCuZ7eJEwNmJRWw2VY84Oedb7WFcA27fiEVe8oUQx9hAUJ4ekurquucTGwsyO1XGdQ==", + "dev": true, + "requires": { + "get-intrinsic": "^1.1.1" + } + }, + "has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "dev": true + }, + "has-tostringtag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.0.tgz", + "integrity": "sha512-kFjcSNhnlGV1kyoGk7OXKSawH5JOb/LzUc5w9B02hOTO0dfFRjbHQKvg1d6cf3HbeUmtU9VbbV3qzZ2Teh97WQ==", + "dev": true, + "requires": { + "has-symbols": "^1.0.2" + } + }, "html-link-extractor": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/html-link-extractor/-/html-link-extractor-1.0.5.tgz", @@ -2574,48 +4908,158 @@ "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", "dev": true, "requires": { - "safer-buffer": ">= 2.1.2 < 3.0.0" + "safer-buffer": ">= 2.1.2 < 3.0.0" + } + }, + "ignore": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", + "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "dev": true + }, + "import-fresh": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/import-fresh/-/import-fresh-3.3.0.tgz", + "integrity": "sha512-veYYhQa+D1QBKznvhUHxb8faxlrwUnxseDAbAp457E0wLNio2bOSKnjYDhMj+YiAq61xrMGhQk9iXVk5FzgQMw==", + "dev": true, + "requires": { + "parent-module": "^1.0.0", + "resolve-from": "^4.0.0" + } + }, + "imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "dev": true + }, + "inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dev": true, + "requires": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "dev": true + }, + "ini": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz", + "integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==", + "dev": true + }, + "internal-slot": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.3.tgz", + "integrity": "sha512-O0DB1JC/sPyZl7cIo78n5dR7eUSwwpYPiXRhTzNxZVAMUuB8vlnRFyLxdrVToks6XPLVnFfbzaVd5WLjhgg+vA==", + "dev": true, + "requires": { + "get-intrinsic": "^1.1.0", + "has": "^1.0.3", + "side-channel": "^1.0.4" + } + }, + "is": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz", + "integrity": "sha512-nW24QBoPcFGGHJGUwnfpI7Yc5CdqWNdsyHQszVE/z2pKHXzh7FZ5GWhJqSyaQ9wMkQnsTx+kAI8bHlCX4tKdbg==", + "dev": true + }, + "is-absolute-url": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/is-absolute-url/-/is-absolute-url-3.0.3.tgz", + "integrity": "sha512-opmNIX7uFnS96NtPmhWQgQx6/NYFgsUXYMllcfzwWKUMwfo8kku1TvE6hkNcH+Q1ts5cMVrsY7j0bxXQDciu9Q==", + "dev": true + }, + "is-bigint": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", + "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", + "dev": true, + "requires": { + "has-bigints": "^1.0.1" + } + }, + "is-boolean-object": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", + "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + } + }, + "is-callable": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.4.tgz", + "integrity": "sha512-nsuwtxZfMX67Oryl9LCQ+upnC0Z0BgpwntpS89m1H/TLF0zNfzfLMV/9Wa/6MZsj0acpEjAO0KF1xT6ZdLl95w==", + "dev": true + }, + "is-core-module": { + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.9.0.tgz", + "integrity": "sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A==", + "dev": true, + "requires": { + "has": "^1.0.3" + } + }, + "is-date-object": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", + "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", + "dev": true, + "requires": { + "has-tostringtag": "^1.0.0" } }, - "ignore": { - "version": "5.2.0", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz", - "integrity": "sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ==", + "is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", "dev": true }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", "dev": true, "requires": { - "once": "^1.3.0", - "wrappy": "1" + "is-extglob": "^2.1.1" } }, - "inherits": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true - }, - "ini": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/ini/-/ini-2.0.0.tgz", - "integrity": "sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA==", + "is-negative-zero": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", + "integrity": "sha512-dqJvarLawXsFbNDeJW7zAz8ItJ9cd28YufuuFzh0G8pNHjJMnY08Dv7sYX2uF5UpQOwieAeOExEYAWWfu7ZZUA==", "dev": true }, - "is": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/is/-/is-3.3.0.tgz", - "integrity": "sha512-nW24QBoPcFGGHJGUwnfpI7Yc5CdqWNdsyHQszVE/z2pKHXzh7FZ5GWhJqSyaQ9wMkQnsTx+kAI8bHlCX4tKdbg==", - "dev": true + "is-number-object": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", + "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", + "dev": true, + "requires": { + "has-tostringtag": "^1.0.0" + } }, - "is-absolute-url": { - "version": "3.0.3", - "resolved": "https://registry.npmjs.org/is-absolute-url/-/is-absolute-url-3.0.3.tgz", - "integrity": "sha512-opmNIX7uFnS96NtPmhWQgQx6/NYFgsUXYMllcfzwWKUMwfo8kku1TvE6hkNcH+Q1ts5cMVrsY7j0bxXQDciu9Q==", - "dev": true + "is-regex": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", + "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + } }, "is-relative-url": { "version": "3.0.0", @@ -2626,12 +5070,48 @@ "is-absolute-url": "^3.0.0" } }, + "is-shared-array-buffer": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.2.tgz", + "integrity": "sha512-sqN2UDu1/0y6uvXyStCOzyhAjCSlHceFoMKJW8W9EU9cvic/QdsZ0kEU93HEy3IUEFZIiH/3w+AH/UQbPHNdhA==", + "dev": true, + "requires": { + "call-bind": "^1.0.2" + } + }, + "is-string": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", + "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", + "dev": true, + "requires": { + "has-tostringtag": "^1.0.0" + } + }, + "is-symbol": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", + "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", + "dev": true, + "requires": { + "has-symbols": "^1.0.2" + } + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "integrity": "sha512-cyA56iCMHAh5CdzjJIa4aohJyeO1YbwLi3Jc35MmRU6poroFjIGZzUzupGiRPOjgHg9TLu43xbpwXk523fMxKA==", "dev": true }, + "is-weakref": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-weakref/-/is-weakref-1.0.2.tgz", + "integrity": "sha512-qctsuLZmIQ0+vSSMfoVvyFe2+GSEvnmZ2ezTup1SBse9+twCCeial6EEi3Nc2KFcf6+qz2FBPnjXsk8xhKSaPQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.2" + } + }, "isemail": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/isemail/-/isemail-3.2.0.tgz", @@ -2641,6 +5121,12 @@ "punycode": "2.x.x" } }, + "isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "dev": true + }, "isstream": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz", @@ -2648,13 +5134,11 @@ "dev": true }, "js-yaml": { - "version": "3.14.1", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz", - "integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==", - "dev": true, + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", + "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", "requires": { - "argparse": "^1.0.7", - "esprima": "^4.0.0" + "argparse": "^2.0.1" } }, "jsbn": { @@ -2690,6 +5174,12 @@ "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", "dev": true }, + "json-stable-stringify-without-jsonify": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-stable-stringify-without-jsonify/-/json-stable-stringify-without-jsonify-1.0.1.tgz", + "integrity": "sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==", + "dev": true + }, "json-stringify-safe": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz", @@ -2730,6 +5220,16 @@ "json-buffer": "3.0.1" } }, + "levn": { + "version": "0.4.1", + "resolved": "https://registry.npmjs.org/levn/-/levn-0.4.1.tgz", + "integrity": "sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1", + "type-check": "~0.4.0" + } + }, "link-check": { "version": "5.1.0", "resolved": "https://registry.npmjs.org/link-check/-/link-check-5.1.0.tgz", @@ -2751,18 +5251,43 @@ "uc.micro": "^1.0.1" } }, + "locate-path": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-2.0.0.tgz", + "integrity": "sha512-NCI2kiDkyR7VeEKm27Kda/iQHyKJe1Bu0FlTbYp3CqJu+9IFe9bLyAjMxf5ZDDbEg+iMPzB5zYyUTSm8wVTKmA==", + "dev": true, + "requires": { + "p-locate": "^2.0.0", + "path-exists": "^3.0.0" + } + }, "lodash": { "version": "4.17.21", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, + "lodash.merge": { + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", + "integrity": "sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ==", + "dev": true + }, "lowercase-keys": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz", "integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==", "dev": true }, + "lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dev": true, + "requires": { + "yallist": "^4.0.0" + } + }, "markdown-it": { "version": "12.3.2", "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz", @@ -2776,12 +5301,6 @@ "uc.micro": "^1.0.5" }, "dependencies": { - "argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, "entities": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz", @@ -2843,27 +5362,12 @@ "run-con": "~1.2.10" }, "dependencies": { - "argparse": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", - "dev": true - }, "commander": { "version": "9.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-9.0.0.tgz", "integrity": "sha512-JJfP2saEKbQqvW+FI93OYUB4ByV5cizMpFMiiJI8xDbBvQvSkIk0VvQdn1CZ8mqAO8Loq2h0gYTYtDFUZUeERw==", "dev": true }, - "js-yaml": { - "version": "4.1.0", - "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", - "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", - "dev": true, - "requires": { - "argparse": "^2.0.1" - } - }, "minimatch": { "version": "3.0.8", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.8.tgz", @@ -2935,6 +5439,12 @@ "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", "dev": true }, + "natural-compare": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", + "integrity": "sha512-OWND8ei3VtNC9h7V60qff3SVobHr996CTwgxubgyQYEpg290h9J0buyECNNJexkFm5sOajh5G116RYA1c8ZMSw==", + "dev": true + }, "needle": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/needle/-/needle-3.1.0.tgz", @@ -2977,6 +5487,52 @@ "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==", "dev": true }, + "object-inspect": { + "version": "1.12.2", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.12.2.tgz", + "integrity": "sha512-z+cPxW0QGUp0mcqcsgQyLVRDoXFQbXOwBaqyF7VIgI4TWNQsDHrBpUQslRmIfAoYWdYzs6UlKJtB2XJpTaNSpQ==", + "dev": true + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", + "dev": true + }, + "object.assign": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.2.tgz", + "integrity": "sha512-ixT2L5THXsApyiUPYKmW+2EHpXXe5Ii3M+f4e+aJFAHao5amFRW6J0OO6c/LU8Be47utCx2GL89hxGB6XSmKuQ==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "define-properties": "^1.1.3", + "has-symbols": "^1.0.1", + "object-keys": "^1.1.1" + } + }, + "object.entries": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.5.tgz", + "integrity": "sha512-TyxmjUoZggd4OrrU1W66FMDG6CuqJxsFvymeyXI51+vQLN67zYfZseptRge703kKQdo4uccgAKebXFcRCzk4+g==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.1" + } + }, + "object.values": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/object.values/-/object.values-1.1.5.tgz", + "integrity": "sha512-QUZRW0ilQ3PnPpbNtgdNV1PDbEqLIiSFB3l+EnGtBQ/8SUTLj1PZwtQHABZtLgwpJZTSZhuGLOGk57Drx2IvYg==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "es-abstract": "^1.19.1" + } + }, "octonode": { "version": "0.10.2", "resolved": "https://registry.npmjs.org/octonode/-/octonode-0.10.2.tgz", @@ -2998,12 +5554,59 @@ "wrappy": "1" } }, + "optionator": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/optionator/-/optionator-0.9.1.tgz", + "integrity": "sha512-74RlY5FCnhq4jRxVUPKDaRwrVNXMqsGsiW6AJw4XK8hmtm10wC0ypZBLw5IIp85NZMr91+qd1RvvENwg7jjRFw==", + "dev": true, + "requires": { + "deep-is": "^0.1.3", + "fast-levenshtein": "^2.0.6", + "levn": "^0.4.1", + "prelude-ls": "^1.2.1", + "type-check": "^0.4.0", + "word-wrap": "^1.2.3" + } + }, "p-cancelable": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz", "integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==", "dev": true }, + "p-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-1.3.0.tgz", + "integrity": "sha512-vvcXsLAJ9Dr5rQOPk7toZQZJApBl2K4J6dANSsEuh6QI41JYcsS/qhTGa9ErIUUgK3WNQoJYvylxvjqmiqEA9Q==", + "dev": true, + "requires": { + "p-try": "^1.0.0" + } + }, + "p-locate": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-2.0.0.tgz", + "integrity": "sha512-nQja7m7gSKuewoVRen45CtVfODR3crN3goVQ0DDZ9N3yHxgpkuBhZqsaiotSQRrADUrne346peY7kT3TSACykg==", + "dev": true, + "requires": { + "p-limit": "^1.1.0" + } + }, + "p-try": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz", + "integrity": "sha512-U1etNYuMJoIz3ZXSrrySFjsXQTWOx2/jdi86L+2pRvph/qMKL6sbcCYdH23fqsbm8TH2Gn0OybpT4eSFlCVHww==", + "dev": true + }, + "parent-module": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", + "integrity": "sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g==", + "dev": true, + "requires": { + "callsites": "^3.0.0" + } + }, "parse5": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/parse5/-/parse5-7.0.0.tgz", @@ -3023,18 +5626,42 @@ "parse5": "^7.0.0" } }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha512-bpC7GYwiDYQ4wYLe+FA8lhRjhQCMcQGuSgGGqDkg/QerRWw9CmGRT0iSOVRSZJ29NMLZgIzqaljJ63oaL4NIJQ==", + "dev": true + }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", "dev": true }, + "path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "dev": true + }, + "path-parse": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.7.tgz", + "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", + "dev": true + }, "performance-now": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "integrity": "sha512-7EAHlyLHI56VEIdK57uwHdHKIaAGbnXPiw0yWbarQZOKaKpvUIgW0jWRVLiatnM+XXlSwsanIBH/hzGMJulMow==", "dev": true }, + "prelude-ls": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz", + "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", + "dev": true + }, "prettier": { "version": "2.7.1", "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz", @@ -3097,6 +5724,23 @@ "randombytes": "2.0.3" } }, + "regexp.prototype.flags": { + "version": "1.4.3", + "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.4.3.tgz", + "integrity": "sha512-fjggEOO3slI6Wvgjwflkc4NFRCTZAu5CnNfBd5qOMYhWdn67nJBBu34/TkD++eeFmd8C9r9jfXJ27+nSiRkSUA==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.3", + "functions-have-names": "^1.2.2" + } + }, + "regexpp": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", + "integrity": "sha512-pq2bWo9mVD43nbts2wGv17XLiNLya+GklZ8kaDLV2Z08gDCsGpnKn9BFMepvWuHCbyVvY7J5o5+BVvoQbmlJLg==", + "dev": true + }, "request": { "version": "2.88.2", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", @@ -3131,12 +5775,29 @@ "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", "dev": true }, + "resolve": { + "version": "1.22.1", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.1.tgz", + "integrity": "sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==", + "dev": true, + "requires": { + "is-core-module": "^2.9.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + } + }, "resolve-alpn": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/resolve-alpn/-/resolve-alpn-1.2.1.tgz", "integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g==", "dev": true }, + "resolve-from": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/resolve-from/-/resolve-from-4.0.0.tgz", + "integrity": "sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==", + "dev": true + }, "responselike": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.0.tgz", @@ -3146,6 +5807,15 @@ "lowercase-keys": "^2.0.0" } }, + "rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dev": true, + "requires": { + "glob": "^7.1.3" + } + }, "run-con": { "version": "1.2.10", "resolved": "https://registry.npmjs.org/run-con/-/run-con-1.2.10.tgz", @@ -3176,6 +5846,41 @@ "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", "dev": true }, + "semver": { + "version": "7.3.7", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.7.tgz", + "integrity": "sha512-QlYTucUYOews+WeEujDoEGziz4K6c47V/Bd+LjSSYcA94p+DmINdf7ncaUinThfvZyu13lN9OY1XDxt8C0Tw0g==", + "dev": true, + "requires": { + "lru-cache": "^6.0.0" + } + }, + "shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "dev": true, + "requires": { + "shebang-regex": "^3.0.0" + } + }, + "shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "dev": true + }, + "side-channel": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.4.tgz", + "integrity": "sha512-q5XPytqFEIKHkGdiMIrY10mvLRvnQh42/+GoBlFW3b2LXLE2xxJpZFdm94we0BaoV3RwJyGqg5wS7epxTv0Zvw==", + "dev": true, + "requires": { + "call-bind": "^1.0.0", + "get-intrinsic": "^1.0.2", + "object-inspect": "^1.9.0" + } + }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -3199,6 +5904,43 @@ "tweetnacl": "~0.14.0" } }, + "string.prototype.trimend": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/string.prototype.trimend/-/string.prototype.trimend-1.0.5.tgz", + "integrity": "sha512-I7RGvmjV4pJ7O3kdf+LXFpVfdNOxtCW/2C8f6jNiW4+PQchwxkCDzlk1/7p+Wl4bqFIZeF47qAHXLuHHWKAxog==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.19.5" + } + }, + "string.prototype.trimstart": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/string.prototype.trimstart/-/string.prototype.trimstart-1.0.5.tgz", + "integrity": "sha512-THx16TJCGlsN0o6dl2o6ncWUsdgnLRSA23rRE5pyGBw/mLr3Ej/R2LaqCtgP8VNMGZsvMWnf9ooZPyY2bHvUFg==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "define-properties": "^1.1.4", + "es-abstract": "^1.19.5" + } + }, + "strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dev": true, + "requires": { + "ansi-regex": "^5.0.1" + } + }, + "strip-bom": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", + "integrity": "sha512-vavAMRXOgBVNF6nyEEmL3DBK19iRpDcoIwW+swQ+CbGiu7lju6t+JklA1MHweoWtadgt4ISVUsXLyDq34ddcwA==", + "dev": true + }, "strip-json-comments": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", @@ -3214,6 +5956,18 @@ "has-flag": "^4.0.0" } }, + "supports-preserve-symlinks-flag": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/supports-preserve-symlinks-flag/-/supports-preserve-symlinks-flag-1.0.0.tgz", + "integrity": "sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==", + "dev": true + }, + "text-table": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", + "dev": true + }, "tough-cookie": { "version": "2.5.0", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", @@ -3224,6 +5978,29 @@ "punycode": "^2.1.1" } }, + "tsconfig-paths": { + "version": "3.14.1", + "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz", + "integrity": "sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ==", + "dev": true, + "requires": { + "@types/json5": "^0.0.29", + "json5": "^1.0.1", + "minimist": "^1.2.6", + "strip-bom": "^3.0.0" + }, + "dependencies": { + "json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + } + } + }, "tslib": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.4.0.tgz", @@ -3245,12 +6022,39 @@ "integrity": "sha512-KXXFFdAbFXY4geFIwoyNK+f5Z1b7swfXABfL7HXCmoIWMKU3dmS26672A4EeQtDzLKy7SXmfBu51JolvEKwtGA==", "dev": true }, + "type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", + "dev": true, + "requires": { + "prelude-ls": "^1.2.1" + } + }, + "type-fest": { + "version": "0.20.2", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.20.2.tgz", + "integrity": "sha512-Ne+eE4r0/iWnpAxD852z3A+N0Bt5RN//NjJwRd2VFHEmrywxf5vsZlh4R6lixl6B+wz/8d+maTSAkN1FIkI3LQ==", + "dev": true + }, "uc.micro": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz", "integrity": "sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==", "dev": true }, + "unbox-primitive": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", + "integrity": "sha512-61pPlCD9h51VoreyJ0BReideM3MDKMKnh6+V9L08331ipq6Q8OFXZYiqP6n/tbHx4s5I9uRhcye6BrbkizkBDw==", + "dev": true, + "requires": { + "call-bind": "^1.0.2", + "has-bigints": "^1.0.2", + "has-symbols": "^1.0.3", + "which-boxed-primitive": "^1.0.2" + } + }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -3266,6 +6070,12 @@ "integrity": "sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==", "dev": true }, + "v8-compile-cache": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz", + "integrity": "sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==", + "dev": true + }, "verror": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", @@ -3277,11 +6087,45 @@ "extsprintf": "^1.2.0" } }, + "which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "dev": true, + "requires": { + "isexe": "^2.0.0" + } + }, + "which-boxed-primitive": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", + "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", + "dev": true, + "requires": { + "is-bigint": "^1.0.1", + "is-boolean-object": "^1.1.0", + "is-number-object": "^1.0.4", + "is-string": "^1.0.5", + "is-symbol": "^1.0.3" + } + }, + "word-wrap": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.3.tgz", + "integrity": "sha512-Hz/mrNwitNRh/HUAtM/VT/5VH+ygD6DV7mYKZAtHOrbs8U7lvPS6xf7EJKMF0uW1KJCl0H701g3ZGus+muE5vQ==", + "dev": true + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", "dev": true + }, + "yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", + "dev": true } } } diff --git a/package.json b/package.json index 41895eb9..d67b744c 100644 --- a/package.json +++ b/package.json @@ -2,9 +2,16 @@ "devDependencies": { "ajv-cli": "^5.0.0", "ajv-formats": "^2.1.1", + "eslint": "^8.2.0", + "eslint-config-airbnb-base": "^15.0.0", + "eslint-config-prettier": "^8.5.0", + "eslint-plugin-import": "^2.25.2", "github-label-sync": "2.2.0", "markdown-link-check": "^3.10.2", "markdownlint-cli": "^0.31.1", "prettier": "^2.7.1" + }, + "dependencies": { + "js-yaml": "^4.1.0" } } diff --git a/workflow-templates/assets/check-javascript-task/Taskfile.yml b/workflow-templates/assets/check-javascript-task/Taskfile.yml new file mode 100644 index 00000000..791bdae1 --- /dev/null +++ b/workflow-templates/assets/check-javascript-task/Taskfile.yml @@ -0,0 +1,19 @@ +# See: https://taskfile.dev/#/usage +version: "3" + +tasks: + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-javascript-task/Taskfile.yml + js:fix: + desc: Fix JavaScript code linting violations + deps: + - task: npm:install-deps + cmds: + - npx eslint --ext .js,.jsx --fix . + + # Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-javascript-task/Taskfile.yml + js:lint: + desc: Lint JavaScript code + deps: + - task: npm:install-deps + cmds: + - npx eslint --ext .js,.jsx . diff --git a/workflow-templates/assets/check-javascript/.eslintrc.yml b/workflow-templates/assets/check-javascript/.eslintrc.yml new file mode 100644 index 00000000..3e0be6c9 --- /dev/null +++ b/workflow-templates/assets/check-javascript/.eslintrc.yml @@ -0,0 +1,14 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/check-javascript/.eslintrc.yml +# See: https://eslint.org/docs/user-guide/configuring/ +# The code style defined in this file is the official standardized style to be used in all Arduino projects and should +# not be modified. + +extends: + - airbnb-base + - prettier +rules: + max-len: + - error + - code: 180 + no-console: "off" + no-underscore-dangle: "off" diff --git a/workflow-templates/check-javascript-task.md b/workflow-templates/check-javascript-task.md new file mode 100644 index 00000000..af4cc7da --- /dev/null +++ b/workflow-templates/check-javascript-task.md @@ -0,0 +1,93 @@ +# "Check JavaScript" workflow (Task) + +Workflow file: [check-javascript-task.yml](check-javascript-task.yml) + +Use [**ESLint**](https://eslint.org/) to lint the repository's JavaScript files. + +**Note:** This workflow is focused on linting. Formatting checks for JavaScript are provided by the ["Check Prettier Formatting" workflow (Task)](https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-prettier-formatting-task.md), so both should be used. + +This is the version of the workflow for projects using the [Task](https://taskfile.dev/#/) task runner tool. + +## Installation + +### Workflow + +Install the [`check-javascript-task.yml`](check-javascript-task.yml) GitHub Actions workflow to `.github/workflows/` + +### Assets + +- [`.eslintrc.yml`](assets/check-javascript/.eslintrc.yml) - **ESLint** configuration file. + ❗ The code style defined in this file is the official standardized style to be used in all Arduino projects and should not be modified. + - Install to: repository root +- [`Taskfile.yml`](assets/check-javascript-task/Taskfile.yml) - JavaScript linting tasks. + - Install to: repository root (or merge into the existing `Taskfile.yml`). +- [`Taskfile.yml`](assets/npm-task/Taskfile.yml) - npm tasks. + - Install to: repository root (or merge into the existing `Taskfile.yml`). + +### Dependencies + +The tool dependencies of this workflow are managed by [npm](https://www.npmjs.com/). + +Add the dependencies by running this command: + +```text +npm install --save-dev eslint@^8.19.0 eslint-config-prettier@^8.5.0 +npx install-peerdeps --dev eslint-config-airbnb-base +``` + +Commit the resulting changes to the `package.json` and `package-lock.json` files. + +### Configuration + +#### Workflow + +Configure the version of [**Node.js**](https://nodejs.org) used for development of the project in the `env.NODE_VERSION` field of `check-javascript-task.yml`. + +#### `.gitignore` + +Add the following to [`/.gitignore`](https://git-scm.com/docs/gitignore): + +```gitignore +/node_modules/ +``` + +### Readme badge + +Markdown badge: + +```markdown +[![Check JavaScript status](https://github.com/TODO_REPO_OWNER/TODO_REPO_NAME/actions/workflows/check-javascript-task.yml/badge.svg)](https://github.com/TODO_REPO_OWNER/TODO_REPO_NAME/actions/workflows/check-javascript-task.yml) +``` + +Replace the `TODO_REPO_OWNER` and `TODO_REPO_NAME` placeholders in the URLs with the final repository owner and name ([example](https://raw.githubusercontent.com/arduino-libraries/ArduinoIoTCloud/master/README.md)). + +--- + +Asciidoc badge: + +```adoc +image:https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-javascript-task.yml/badge.svg["Check JavaScript status", link="https://github.com/{repository-owner}/{repository-name}/actions/workflows/check-javascript-task.yml"] +``` + +Define the `{repository-owner}` and `{repository-name}` attributes and use them throughout the readme ([example](https://raw.githubusercontent.com/arduino-libraries/WiFiNINA/master/README.adoc)). + +## Commit message + +``` +Add CI workflow to lint JavaScript code + +On every push and pull request that affects relevant files, and periodically, run ESLint on the repository's JavaScript +files. + +ESLint is configured via the .eslintrc.yml file: +https://eslint.org/docs/user-guide/configuring/configuration-files +``` + +## PR message + +```markdown +On every push and pull request that affects relevant files, and periodically, run [**ESLint**](https://eslint.org/) on the repository's JavaScript files. + +**ESLint** is configured via the `.eslintrc.yml` file: +https://eslint.org/docs/latest/user-guide/configuring/configuration-files +``` diff --git a/workflow-templates/check-javascript-task.yml b/workflow-templates/check-javascript-task.yml new file mode 100644 index 00000000..851259a5 --- /dev/null +++ b/workflow-templates/check-javascript-task.yml @@ -0,0 +1,54 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-javascript-task.md +name: Check JavaScript + +env: + # See: https://github.com/actions/setup-node/#readme + NODE_VERSION: 16.x + +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/check-javascript-task.ya?ml" + - ".eslintignore" + - "**/.eslintrc*" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + - "**.jsx?" + pull_request: + paths: + - ".github/workflows/check-javascript-task.ya?ml" + - ".eslintignore" + - "**/.eslintrc*" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + - "**.jsx?" + workflow_dispatch: + repository_dispatch: + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Lint + run: task js:lint diff --git a/workflow-templates/dependabot/workflow-template-copies/.github/workflows/check-javascript-task.yml b/workflow-templates/dependabot/workflow-template-copies/.github/workflows/check-javascript-task.yml new file mode 100644 index 00000000..851259a5 --- /dev/null +++ b/workflow-templates/dependabot/workflow-template-copies/.github/workflows/check-javascript-task.yml @@ -0,0 +1,54 @@ +# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/check-javascript-task.md +name: Check JavaScript + +env: + # See: https://github.com/actions/setup-node/#readme + NODE_VERSION: 16.x + +# See: https://docs.github.com/actions/using-workflows/events-that-trigger-workflows +on: + push: + paths: + - ".github/workflows/check-javascript-task.ya?ml" + - ".eslintignore" + - "**/.eslintrc*" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + - "**.jsx?" + pull_request: + paths: + - ".github/workflows/check-javascript-task.ya?ml" + - ".eslintignore" + - "**/.eslintrc*" + - "package.json" + - "package-lock.json" + - "Taskfile.ya?ml" + - "**.jsx?" + workflow_dispatch: + repository_dispatch: + +permissions: + contents: read + +jobs: + check: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ env.NODE_VERSION }} + + - name: Install Task + uses: arduino/setup-task@v1 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + version: 3.x + + - name: Lint + run: task js:lint