From 0c09eb8674f0620aa535288aef6cff058c96f907 Mon Sep 17 00:00:00 2001 From: Sergio Lecuona Date: Sat, 11 Nov 2023 11:54:35 +0100 Subject: [PATCH 1/5] Rename to avoid confusion This has to be reverted before pullRequest --- library.json | 4 ++-- library.properties | 4 ++-- src/{EncoderTool.h => EncoderTool_74165_switch.h} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename src/{EncoderTool.h => EncoderTool_74165_switch.h} (100%) diff --git a/library.json b/library.json index e57054b..84ceb0b 100644 --- a/library.json +++ b/library.json @@ -1,5 +1,5 @@ { - "name": "EncoderTool", + "name": "EncoderTool_74165_switch", "keywords": "encoder, multiplexed, polling, 74165, 4067, 4051", "description": "The EncoderTool is a library to manage and read out rotary encoders with or without buttons, connected either directly or via multiplexers. It supports the common types of encoders (full / quad / half) and some variants. It provides periodic and limit modes and can invoke callbacks on value changes.", "repository": @@ -24,5 +24,5 @@ "version": ">2.5.0" } ], - "headers": "EncoderTool.h" + "headers": "EncoderTool_74165_switch.h" } diff --git a/library.properties b/library.properties index a7d39f3..9f63d36 100644 --- a/library.properties +++ b/library.properties @@ -1,4 +1,4 @@ -name=EncoderTool +name=EncoderTool_74165_switch version=3.2.0 author=luni64 maintainer=luni64 @@ -8,4 +8,4 @@ category=Sensors url=https://github.com/luni64/EncoderTool architectures=* depends=Bounce2 -includes=EncoderTool.h +includes=EncoderTool_74165_switch.h diff --git a/src/EncoderTool.h b/src/EncoderTool_74165_switch.h similarity index 100% rename from src/EncoderTool.h rename to src/EncoderTool_74165_switch.h From fedc3f865a2d84b199b46198def4995aa240606a Mon Sep 17 00:00:00 2001 From: Sergio Lecuona Date: Sun, 12 Nov 2023 19:50:46 +0100 Subject: [PATCH 2/5] isolate update function for btn --- src/EncoderBase.h | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/EncoderBase.h b/src/EncoderBase.h index 1aaf50c..e627369 100644 --- a/src/EncoderBase.h +++ b/src/EncoderBase.h @@ -43,6 +43,7 @@ namespace EncoderTool bool buttonChanged(); counter_t update(uint_fast8_t phaseA, uint_fast8_t phaseB, uint_fast8_t btn = 0); + counter_t updateBtn(uint_fast8_t btn); protected: EncoderBase() = default; @@ -210,12 +211,6 @@ namespace EncoderTool template counter_t EncoderBase::update(uint_fast8_t phaseA, uint_fast8_t phaseB, uint_fast8_t btn) { - if (button.update(btn)) - { - btnChanged = true; - if (btnCallback != nullptr) { btnCallback(button.read()); } - } - unsigned input = (phaseA << 1 | phaseB) ^ invert; // invert signals if necessary if (stateMachine == nullptr) return 0; // tick might get called from yield before class is initialized @@ -278,6 +273,31 @@ namespace EncoderTool return false; } + template + counter_t EncoderBase::updateBtn(uint_fast8_t btn) + { + if (button.update(btn)) //button changed + { + btnChanged = true; + if (btnCallback != nullptr) + { + btnCallback(button.read()); + return -1; + } + else{ + return button.read(); + } + } + else + { + return -1; + } + + //#if defined(USE_ERROR_CALLBACKS) + // TODO: implement error callback for button + // #endif + } + template const uint8_t EncoderBase::stateMachineQtr[7][4]{ // 00 01 10 11 From 9b89e5d127c5d598b8f8541f5c385edf707d1549 Mon Sep 17 00:00:00 2001 From: Sergio Lecuona Date: Sun, 12 Nov 2023 19:53:20 +0100 Subject: [PATCH 3/5] finish allBtnCallback func template --- src/Multiplexed/EncPlexBase.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Multiplexed/EncPlexBase.h b/src/Multiplexed/EncPlexBase.h index 184bab0..6cb2683 100644 --- a/src/Multiplexed/EncPlexBase.h +++ b/src/Multiplexed/EncPlexBase.h @@ -18,6 +18,7 @@ namespace EncoderTool #endif void attachCallback(allCallback_t callback); + void attachBtnCallback(allBtnCallback_t btnCallback); EncoderBase& operator[](size_t idx); protected: @@ -26,11 +27,13 @@ namespace EncoderTool void begin(CountMode mode = CountMode::quarter); void begin(allCallback_t, CountMode mode = CountMode::quarter); + void begin(allCallback_t, allBtnCallback_t, CountMode mode = CountMode::quarter); const size_t encoderCount; EncoderBase* encoders; allCallback_t callback = nullptr; + allBtnCallback_t btnCallback = nullptr; counter_t c; }; @@ -67,4 +70,9 @@ namespace EncoderTool { callback = _callback; } + template + void EncPlexBase::attachBtnCallback(allBtnCallback_t _btnCallback) + { + btnCallback = _btnCallback; + } } From bb891232d0092b9b9a56c21fcb58af84f37eff61 Mon Sep 17 00:00:00 2001 From: Sergio Lecuona Date: Sun, 12 Nov 2023 19:57:17 +0100 Subject: [PATCH 4/5] replicate encoderCallback for button --- src/Multiplexed/EncPlex74165.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/Multiplexed/EncPlex74165.h b/src/Multiplexed/EncPlex74165.h index 1bba46c..017920f 100644 --- a/src/Multiplexed/EncPlex74165.h +++ b/src/Multiplexed/EncPlex74165.h @@ -94,11 +94,16 @@ namespace EncoderTool int btn = Btn.pin < NUM_DIGITAL_PINS ? directRead(Btn) : LOW; int delta = EncPlexBase::encoders[0].update(a, b, btn); + int btnState = EncPlexBase::encoders[0].updateBtn(btn); if (delta != 0 && EncPlexBase::callback != nullptr) { EncPlexBase::callback(0, EncPlexBase::encoders[0].getValue(), delta); } + if (btnState != -1 && EncPlexBase::btnCallback != nullptr) + { + EncPlexBase::btnCallback(0, btnState); + } for (unsigned i = 1; i < EncPlexBase::encoderCount; i++) // shift in the the rest of the encoders { directWrite(CLK, HIGH); @@ -108,6 +113,11 @@ namespace EncoderTool { EncPlexBase::callback(i, EncPlexBase::encoders[i].getValue(), delta); } + int btnState = EncPlexBase::encoders[i].updateBtn(Btn.pin < NUM_DIGITAL_PINS ? directRead(Btn) : -1); + if (btnState != -1 && EncPlexBase::btnCallback != nullptr) + { + EncPlexBase::btnCallback(i, btnState); + } directWrite(CLK, LOW); delay50ns(); } From 33710e493894fe9fb42a3577543ced6aafe77f67 Mon Sep 17 00:00:00 2001 From: Sergio Lecuona Date: Sun, 12 Nov 2023 20:24:48 +0100 Subject: [PATCH 5/5] Reverted alt dev naming --- library.json | 4 ++-- library.properties | 4 ++-- src/{EncoderTool_74165_switch.h => EncoderTool.h} | 0 3 files changed, 4 insertions(+), 4 deletions(-) rename src/{EncoderTool_74165_switch.h => EncoderTool.h} (100%) diff --git a/library.json b/library.json index 84ceb0b..e57054b 100644 --- a/library.json +++ b/library.json @@ -1,5 +1,5 @@ { - "name": "EncoderTool_74165_switch", + "name": "EncoderTool", "keywords": "encoder, multiplexed, polling, 74165, 4067, 4051", "description": "The EncoderTool is a library to manage and read out rotary encoders with or without buttons, connected either directly or via multiplexers. It supports the common types of encoders (full / quad / half) and some variants. It provides periodic and limit modes and can invoke callbacks on value changes.", "repository": @@ -24,5 +24,5 @@ "version": ">2.5.0" } ], - "headers": "EncoderTool_74165_switch.h" + "headers": "EncoderTool.h" } diff --git a/library.properties b/library.properties index 9f63d36..a7d39f3 100644 --- a/library.properties +++ b/library.properties @@ -1,4 +1,4 @@ -name=EncoderTool_74165_switch +name=EncoderTool version=3.2.0 author=luni64 maintainer=luni64 @@ -8,4 +8,4 @@ category=Sensors url=https://github.com/luni64/EncoderTool architectures=* depends=Bounce2 -includes=EncoderTool_74165_switch.h +includes=EncoderTool.h diff --git a/src/EncoderTool_74165_switch.h b/src/EncoderTool.h similarity index 100% rename from src/EncoderTool_74165_switch.h rename to src/EncoderTool.h