From 0062b279bd09a0b7fac68b70bf95b6d79bae0cfd Mon Sep 17 00:00:00 2001 From: jiander-snap Date: Tue, 22 Jul 2025 06:56:45 -0600 Subject: [PATCH 1/8] Add method to change encoder encoding type. (#29) * Add method to change encoder encoding type. * Restore encoding default. --- src/EncoderClass.cpp | 9 +++++++++ src/EncoderClass.h | 10 ++++++++++ src/utility/QEI/QEI.cpp | 32 +++++++++++++++++++------------- src/utility/QEI/QEI.h | 7 +++++++ 4 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/EncoderClass.cpp b/src/EncoderClass.cpp index 3fe546f..7308f07 100644 --- a/src/EncoderClass.cpp +++ b/src/EncoderClass.cpp @@ -63,5 +63,14 @@ int EncoderClass::getRevolutions(int channel) { } } +void EncoderClass::setEncoding(int channel, QEI::Encoding encoding) { + switch (channel) { + case 0: + return _enc0.setEncoding(encoding); + case 1: + return _enc1.setEncoding(encoding); + } +} + EncoderClass MachineControl_Encoders; /**** END OF FILE ****/ \ No newline at end of file diff --git a/src/EncoderClass.h b/src/EncoderClass.h index ecb18d1..3f76085 100644 --- a/src/EncoderClass.h +++ b/src/EncoderClass.h @@ -94,6 +94,16 @@ class EncoderClass { */ int getRevolutions(int channel); + /** + * @brief Set the encoding type for the specified encoder channel. + * + * This method changes the encoding type from the default X2_ENCODING. + * + * @param channel The encoder channel (0 or 1) to be changed. + * @param encoding The encoding type. + */ + void setEncoding(int channel, QEI::Encoding encoding); + private: QEI _enc0; // QEI object for encoder 0 QEI _enc1; // QEI object for encoder 1 diff --git a/src/utility/QEI/QEI.cpp b/src/utility/QEI/QEI.cpp index db767db..7ef3f57 100644 --- a/src/utility/QEI/QEI.cpp +++ b/src/utility/QEI/QEI.cpp @@ -148,19 +148,7 @@ QEI::QEI(PinName channelA, currState_ = (chanA << 1) | (chanB); prevState_ = currState_; - //X2 encoding uses interrupts on only channel A. - //X4 encoding uses interrupts on channel A, - //and on channel B. - channelA_.rise(mbed::callback(this, &QEI::encode)); - if(encoding != X1_ENCODING){ - channelA_.fall(mbed::callback(this, &QEI::encode)); - } - - //If we're using X4 encoding, then attach interrupts to channel B too. - if (encoding == X4_ENCODING) { - channelB_.rise(mbed::callback(this, &QEI::encode)); - channelB_.fall(mbed::callback(this, &QEI::encode)); - } + setEncoding(encoding); //Index is optional. if (index != NC) { index_.rise(mbed::callback(this, &QEI::index)); @@ -193,6 +181,24 @@ int QEI::getRevolutions(void) { } +void QEI::setEncoding(Encoding encoding) { + //X2 encoding uses interrupts on only channel A. + //X4 encoding uses interrupts on channel A, + //and on channel B. + channelA_.rise(mbed::callback(this, &QEI::encode)); + if(encoding != X1_ENCODING){ + channelA_.fall(mbed::callback(this, &QEI::encode)); + } else { + channelA_.fall(0); + } + + //If we're using X4 encoding, then attach interrupts to channel B too. + if (encoding == X4_ENCODING) { + channelB_.rise(mbed::callback(this, &QEI::encode)); + channelB_.fall(mbed::callback(this, &QEI::encode)); + } +} + // +-------------+ // | X1 Encoding | // +-------------+ diff --git a/src/utility/QEI/QEI.h b/src/utility/QEI/QEI.h index 8e6fba0..caa449d 100644 --- a/src/utility/QEI/QEI.h +++ b/src/utility/QEI/QEI.h @@ -208,6 +208,13 @@ class QEI { */ int getRevolutions(void); + /** + * Set the ecoding type of the encoder. + * + * Changes the type of encoding used by the encoder from the default X2_ENCODING. + */ + void setEncoding(Encoding encoding); + private: /** From 4ae895c814cfc783d89c317fb8386973679ed79b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 6 Aug 2025 17:20:46 +0000 Subject: [PATCH 2/8] Bump actions/download-artifact from 4 to 5 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 4 to 5. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 53a9f54..72ec06b 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v4 - name: Download configuration files artifact - uses: actions/download-artifact@v4 + uses: actions/download-artifact@v5 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From d53d823584210b91a498324921960d5c9004502e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Aug 2025 01:09:22 +0000 Subject: [PATCH 3/8] Bump actions/checkout from 4 to 5 Bumps [actions/checkout](https://github.com/actions/checkout) from 4 to 5. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples.yml | 2 +- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index e818685..e13b990 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Arduino Lint uses: arduino/arduino-lint-action@v2 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index b03232d..bcbd662 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Compile example sketches uses: arduino/compile-sketches@v1 diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index ef7d894..19f5d38 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 72ec06b..62c898a 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v5 - name: Download configuration files artifact uses: actions/download-artifact@v5 From 52edbcff5a56f6164081bbaeb9961f630306b561 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:23:04 +0000 Subject: [PATCH 4/8] Bump actions/upload-artifact from 4 to 5 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 4 to 5. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/compile-examples.yml | 2 +- .github/workflows/sync-labels.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index bcbd662..deceb19 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -54,7 +54,7 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} - name: Save memory usage change report as artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: if-no-files-found: error path: ${{ env.SKETCHES_REPORTS_PATH }} diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 62c898a..23a751a 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -70,7 +70,7 @@ jobs: file-url: https://raw.githubusercontent.com/arduino/tooling-project-assets/main/workflow-templates/assets/sync-labels/${{ matrix.filename }} - name: Pass configuration files to next job via workflow artifact - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v5 with: path: | *.yaml From e3996b88789855b62e376c6b2e3833ec05e9f61a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:37:05 +0000 Subject: [PATCH 5/8] Bump actions/download-artifact from 5 to 6 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 5 to 6. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/sync-labels.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index 62c898a..96b9914 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -108,7 +108,7 @@ jobs: uses: actions/checkout@v5 - name: Download configuration files artifact - uses: actions/download-artifact@v5 + uses: actions/download-artifact@v6 with: name: ${{ env.CONFIGURATIONS_ARTIFACT }} path: ${{ env.CONFIGURATIONS_FOLDER }} From e962b4c007a1847d38cb6b5afb4eed63e9b973ff Mon Sep 17 00:00:00 2001 From: svollenweider <34137138+svollenweider@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:23:18 +0100 Subject: [PATCH 6/8] Add `config` parameter to RS485 initialization (#27) * Update RS485CommClass.cpp Added RS485Config * Update RS485CommClass.h * Update RS485_fullduplex.ino * Update RS485_halfduplex.ino * Removed = in cpp --- examples/RS485_fullduplex/RS485_fullduplex.ino | 4 ++-- examples/RS485_halfduplex/RS485_halfduplex.ino | 4 ++-- src/RS485CommClass.cpp | 6 +++--- src/RS485CommClass.h | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/RS485_fullduplex/RS485_fullduplex.ino b/examples/RS485_fullduplex/RS485_fullduplex.ino index 71a9dd4..ff4dbe6 100644 --- a/examples/RS485_fullduplex/RS485_fullduplex.ino +++ b/examples/RS485_fullduplex/RS485_fullduplex.ino @@ -38,7 +38,7 @@ void setup() { // - Half Duplex // - No A/B and Y/Z 120 Ohm termination enabled // Enable the RS485/RS232 system - MachineControl_RS485Comm.begin(115200, 0, 500); // Specify baudrate, and preamble and postamble times for RS485 communication + MachineControl_RS485Comm.begin(115200, SERIAL_8N1, 0, 500); // Specify baudrate, serial_config and preamble and postamble times for RS485 communication // Enable Full Duplex mode // This will also enable A/B and Y/Z 120 Ohm termination resistors @@ -70,4 +70,4 @@ void loop() { sendNow = millis() + sendInterval; } -} \ No newline at end of file +} diff --git a/examples/RS485_halfduplex/RS485_halfduplex.ino b/examples/RS485_halfduplex/RS485_halfduplex.ino index 6bb6a36..9da354a 100644 --- a/examples/RS485_halfduplex/RS485_halfduplex.ino +++ b/examples/RS485_halfduplex/RS485_halfduplex.ino @@ -37,7 +37,7 @@ void setup() { // - Half Duplex // - No A/B and Y/Z 120 Ohm termination enabled // Enable the RS485/RS232 system - MachineControl_RS485Comm.begin(115200, 0, 500); // Specify baudrate, and preamble and postamble times for RS485 communication + MachineControl_RS485Comm.begin(115200, SERIAL_8N1, 0, 500); // Specify baudrate, serial config and preamble and postamble times for RS485 communication // Start in receive mode MachineControl_RS485Comm.receive(); @@ -65,4 +65,4 @@ void loop() { sendNow = millis() + sendInterval; } -} \ No newline at end of file +} diff --git a/src/RS485CommClass.cpp b/src/RS485CommClass.cpp index 4cd4b75..c7afa6d 100644 --- a/src/RS485CommClass.cpp +++ b/src/RS485CommClass.cpp @@ -17,7 +17,7 @@ RS485CommClass::RS485CommClass(arduino::UART& uart_itf, PinName rs_tx_pin, PinNa RS485CommClass::~RS485CommClass() { } -void RS485CommClass::begin(unsigned long baudrate, int predelay, int postdelay) { +void RS485CommClass::begin(unsigned long baudrate, uint16_t config, int predelay, int postdelay) { /* Pinout configuration */ pinMode(PinNameToIndex(MC_RS485_TX_PIN), OUTPUT); pinMode(PinNameToIndex(MC_RS485_RX_PIN), OUTPUT); @@ -45,7 +45,7 @@ void RS485CommClass::begin(unsigned long baudrate, int predelay, int postdelay) _enable(); /* Call begin() base class to initialize RS485 communication */ - RS485Class::begin(baudrate, predelay, postdelay); + RS485Class::begin(baudrate, config, predelay, postdelay); return; } @@ -92,4 +92,4 @@ void RS485CommClass::_disable() { arduino::UART _UART4_ {MC_RS485_TX_PIN, MC_RS485_RX_PIN, NC, NC}; RS485CommClass MachineControl_RS485Comm(_UART4_); -/**** END OF FILE ****/ \ No newline at end of file +/**** END OF FILE ****/ diff --git a/src/RS485CommClass.h b/src/RS485CommClass.h index b518533..a87d91e 100644 --- a/src/RS485CommClass.h +++ b/src/RS485CommClass.h @@ -54,10 +54,11 @@ class RS485CommClass : public RS485Class { * This method initializes the RS485 communication protocol with the specified baud rate and pre/post delays. * * @param baudrate The desired baud rate for the RS485 communication. + * @param config The desired Serial config (bits, parity and stopbits), see HardwareSerial.h * @param predelay The delay before sending data in the RS485 communication (default: RS485_DEFAULT_PRE_DELAY). * @param postdelay The delay after sending data in the RS485 communication (default: RS485_DEFAULT_POST_DELAY). */ - void begin(unsigned long baudrate = 115200, int predelay = RS485_DEFAULT_PRE_DELAY, int postdelay = RS485_DEFAULT_POST_DELAY); + void begin(unsigned long baudrate = 115200, uint16_t config = SERIAL_8N1, int predelay = RS485_DEFAULT_PRE_DELAY, int postdelay = RS485_DEFAULT_POST_DELAY); /** * @brief Close the RS485 communication protocol. From 54daa464fe1d6c2a82e2f9b48c99ff6b0d819dd1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:24:26 +0100 Subject: [PATCH 7/8] Bump actions/checkout from 5 to 6 (#34) Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/check-arduino.yml | 2 +- .github/workflows/compile-examples.yml | 2 +- .github/workflows/spell-check.yml | 2 +- .github/workflows/sync-labels.yml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/check-arduino.yml b/.github/workflows/check-arduino.yml index e13b990..97b2bf2 100644 --- a/.github/workflows/check-arduino.yml +++ b/.github/workflows/check-arduino.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Arduino Lint uses: arduino/arduino-lint-action@v2 diff --git a/.github/workflows/compile-examples.yml b/.github/workflows/compile-examples.yml index deceb19..755d8cd 100644 --- a/.github/workflows/compile-examples.yml +++ b/.github/workflows/compile-examples.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Compile example sketches uses: arduino/compile-sketches@v1 diff --git a/.github/workflows/spell-check.yml b/.github/workflows/spell-check.yml index 19f5d38..8fc4b8c 100644 --- a/.github/workflows/spell-check.yml +++ b/.github/workflows/spell-check.yml @@ -16,7 +16,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Spell check uses: codespell-project/actions-codespell@master diff --git a/.github/workflows/sync-labels.yml b/.github/workflows/sync-labels.yml index cb55211..d49c1cb 100644 --- a/.github/workflows/sync-labels.yml +++ b/.github/workflows/sync-labels.yml @@ -27,7 +27,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Download JSON schema for labels configuration file id: download-schema @@ -105,7 +105,7 @@ jobs: echo "::set-output name=flag::--dry-run" - name: Checkout repository - uses: actions/checkout@v5 + uses: actions/checkout@v6 - name: Download configuration files artifact uses: actions/download-artifact@v6 From 55173d6cbdf55d8ba576126837f8cb2819b63725 Mon Sep 17 00:00:00 2001 From: Leonardo Cavagnis <45899760+leonardocavagnis@users.noreply.github.com> Date: Thu, 20 Nov 2025 18:25:00 +0100 Subject: [PATCH 8/8] Bump version to 1.0.4 --- library.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.properties b/library.properties index b523049..850305f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Arduino_PortentaMachineControl -version=1.0.3 +version=1.0.4 author=Arduino maintainer=Arduino sentence=Arduino Library for Portenta Machine Control (PMC)