-
Notifications
You must be signed in to change notification settings - Fork 0
added rotary enc manual charging state & integrated #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nocturne-1
wants to merge
13
commits into
main
Choose a base branch
from
feature/rotary_enc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d0dc8e0
added rotary enc manual charging state & integrated
nocturne-1 6530fb6
changes
nocturne-1 b80266f
added rotaryencoderinterface.h to mock library
nocturne-1 c58758b
fixed pio tests
nocturne-1 54f7e12
fixed bool
nocturne-1 effa201
added display visibility for manual charging, deleted serial code, in…
nocturne-1 ef691f9
Created rotary encoder unit tests, implemented mock rotary encoder in…
ebajit 996a318
minor style fixes
nocturne-1 ae1a905
Merge branch 'feature/rotary_enc' of https://github.com/hytech-racing…
nocturne-1 ba27945
deleted rotary_enc tests
nocturne-1 928ac9f
added tasks for rotary encoder interface usage
nocturne-1 906f29e
deleted mock interrupt routine (testing on hardware)
nocturne-1 d44bce0
final changes after hardware testing: added debouncing for ISR & chan…
nocturne-1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #ifndef ROTARYENCODERINTERFACE_H | ||
| #define ROTARYENCODERINTERFACE_H | ||
|
|
||
| #include <Arduino.h> | ||
| #include <Encoder.h> | ||
| #include "CCUData.h" | ||
|
|
||
| #include "etl/singleton.h" | ||
| #include <etl/delegate.h> | ||
|
|
||
| #define CLK 21 | ||
| #define DT 20 | ||
| #define SW 19 | ||
|
|
||
| struct rotary_encoder_s { | ||
| volatile bool state = false; | ||
| volatile float encoder_value = 0; | ||
| unsigned long last_button_press = 0; | ||
| const float max_value = 120; | ||
| const float min_value = 0; | ||
| }; | ||
|
|
||
| class RotaryEncoderInterface | ||
| { | ||
| public: | ||
| RotaryEncoderInterface(CCUData &ccu_data) : | ||
| _ccu_data(ccu_data) {Serial.begin(9600);}; | ||
|
|
||
| void setupEncoder(); | ||
| void updateEncoder(); | ||
| static void isr1(); | ||
| void set_enc_value(int dt_value); | ||
|
|
||
| bool isButtonPressed() const { return _encoder_data.state; }; | ||
|
|
||
| private: | ||
| rotary_encoder_s _encoder_data; | ||
| CCUData &_ccu_data; | ||
| }; | ||
|
|
||
| using RotaryEncoderInterfaceInstance = etl::singleton<RotaryEncoderInterface>; | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #include "RotaryEncoderInterface.h" | ||
| #include "CCUData.h" | ||
|
|
||
|
|
||
| const int bounce_delay = 200; //Worked best during testing to minimize switch bouncing | ||
| volatile unsigned long last_interrupt_time = 0; | ||
|
|
||
| void RotaryEncoderInterface::isr1() { | ||
| unsigned long current_time = millis(); | ||
| if (current_time - last_interrupt_time > bounce_delay) { | ||
| int enc_b_value = digitalRead(DT); | ||
| RotaryEncoderInterfaceInstance::instance().set_enc_value(enc_b_value); | ||
| last_interrupt_time = current_time; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| void RotaryEncoderInterface::set_enc_value(int enc_b_value) { | ||
| if (enc_b_value == HIGH) { | ||
| if (_encoder_data.encoder_value < _encoder_data.max_value) { | ||
nocturne-1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _encoder_data.encoder_value += 1.0; | ||
| } | ||
| } else { | ||
| if (_encoder_data.encoder_value > _encoder_data.min_value) { | ||
| _encoder_data.encoder_value -= 1.0; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void RotaryEncoderInterface::setupEncoder() { | ||
| _encoder_data.encoder_value = 0; | ||
| _encoder_data.state = false; | ||
| pinMode(CLK, INPUT_PULLUP); | ||
| pinMode(DT, INPUT_PULLUP); | ||
| pinMode(SW, INPUT_PULLUP); | ||
| attachInterrupt(digitalPinToInterrupt(CLK), RotaryEncoderInterface::isr1, FALLING); | ||
| } | ||
|
|
||
| void RotaryEncoderInterface::updateEncoder() { | ||
| static float prev_value = -1; | ||
| int btn_state = digitalRead(SW); | ||
|
|
||
| _ccu_data.encoder_value = _encoder_data.encoder_value; | ||
|
|
||
| if (_encoder_data.encoder_value != prev_value) { | ||
| Serial.print("Current value: "); | ||
| Serial.println(_encoder_data.encoder_value); | ||
| } | ||
| prev_value = _encoder_data.encoder_value; | ||
|
|
||
| if (btn_state == LOW) { | ||
| if (millis() - _encoder_data.last_button_press > bounce_delay) { | ||
| _encoder_data.state = !_encoder_data.state; | ||
| Serial.println("Button pressed!"); | ||
| } | ||
| _encoder_data.last_button_press = millis(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #ifndef ROTARYENCODERINTERFACE_H | ||
| #define ROTARYENCODERINTERFACE_H | ||
|
|
||
| #include "CCUData.h" | ||
| #include "mockArduino.h" | ||
|
|
||
| #include "etl/singleton.h" | ||
| #include <etl/delegate.h> | ||
|
|
||
| #define CLK 2 //change based on actual pin used | ||
| #define DT 3 //change based on actual pin used | ||
| #define SW 4 //change based on actual pin used | ||
|
|
||
| struct rotary_encoder_s { | ||
| volatile bool state = false; | ||
| volatile float encoder_value = 0; | ||
| unsigned long last_button_press = 0; | ||
| const float max_value = 120; | ||
nocturne-1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const float min_value = 0; | ||
| }; | ||
|
|
||
| class RotaryEncoderInterface | ||
| { | ||
| public: | ||
| RotaryEncoderInterface(CCUData &ccu_data) : | ||
| _ccu_data(ccu_data) {}; | ||
|
|
||
| inline void setupEncoder() { | ||
| _encoder_data.encoder_value = 0; | ||
| _encoder_data.state = false; | ||
| } | ||
|
|
||
| inline void updateEncoder() { | ||
| // Sync internal encoder value to CCUData (matching real implementation) | ||
| _ccu_data.encoder_value = _encoder_data.encoder_value; | ||
| } | ||
|
|
||
| inline void set_enc_value(int dt_value) { | ||
| if (dt_value == HIGH) { | ||
| if (_encoder_data.encoder_value < _encoder_data.max_value) { | ||
| _encoder_data.encoder_value += 1.0f; | ||
| } | ||
| } else { | ||
| if (_encoder_data.encoder_value > _encoder_data.min_value) { | ||
| _encoder_data.encoder_value -= 1.0f; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| bool isButtonPressed() const { return _encoder_data.state; }; | ||
|
|
||
| private: | ||
| rotary_encoder_s _encoder_data; | ||
| CCUData &_ccu_data; | ||
| }; | ||
|
|
||
| using RotaryEncoderInterfaceInstance = etl::singleton<RotaryEncoderInterface>; | ||
|
|
||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.