-
-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Rework encoders to enable asymmetric split keyboards #12090
Merged
Merged
Changes from 8 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9b7be8b
rework encoder pin handling for split keyboards
c31e643
simplify encoder code
20f003f
fixes and align resolutions
BalzGuenat 6290092
update docs
BalzGuenat 91ae274
fix formating of encoder.c with clang-format
BalzGuenat 8f2f14f
replace include of quantum.h in encoder.h
BalzGuenat f283d0f
fix transport buffer size for encoders
BalzGuenat b8f157b
add unit tests for encoders
BalzGuenat b8aba1b
Merge branch 'develop' into rework-encoders
BalzGuenat bcd52bd
Merge remote-tracking branch 'upstream/develop' into rework-encoders
BalzGuenat 32599a4
format encoder tests
BalzGuenat 8213db2
reapply transport buffer size fix after transport was refactored
BalzGuenat 8069c47
Merge branch 'develop' into rework-encoders
BalzGuenat 15b1c51
add license header to encoder test files
BalzGuenat ff6b611
Merge remote-tracking branch 'upstream/develop' into rework-encoders
BalzGuenat e41e946
Merge branch 'develop' into rework-encoders
tzarc d545e98
Fix overall test execution, tests are failing.
tzarc 07d246d
Merge remote-tracking branch 'upstream/develop' into rework-encoders
tzarc 1d9e349
fix encoder tests
BalzGuenat 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 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 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 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 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 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,130 @@ | ||
|
||
#include "gtest/gtest.h" | ||
#include "gmock/gmock.h" | ||
#include <vector> | ||
#include <algorithm> | ||
#include <stdio.h> | ||
|
||
extern "C" { | ||
#include "encoder.h" | ||
#include "encoder/tests/mock.h" | ||
} | ||
|
||
struct update { | ||
int8_t index; | ||
bool clockwise; | ||
}; | ||
|
||
uint8_t uidx = 0; | ||
update updates[32]; | ||
|
||
void encoder_update_kb(int8_t index, bool clockwise) { | ||
updates[uidx % 32] = {index, clockwise}; | ||
uidx++; | ||
} | ||
|
||
bool setAndRead(pin_t pin, bool val) { | ||
setPin(pin, val); | ||
return encoder_read(); | ||
} | ||
|
||
class EncoderTest : public ::testing::Test { | ||
|
||
}; | ||
|
||
TEST_F(EncoderTest, TestInit) { | ||
uidx = 0; | ||
encoder_init(); | ||
EXPECT_EQ(pinIsInputHigh[0], true); | ||
EXPECT_EQ(pinIsInputHigh[1], true); | ||
EXPECT_EQ(uidx, 0); | ||
} | ||
|
||
TEST_F(EncoderTest, TestOneClockwise) { | ||
uidx = 0; | ||
encoder_init(); | ||
// send 4 pulses. with resolution 4, that's one step and we should get 1 update. | ||
setAndRead(0, false); | ||
setAndRead(1, false); | ||
setAndRead(0, true); | ||
setAndRead(1, true); | ||
|
||
EXPECT_EQ(uidx, 1); | ||
EXPECT_EQ(updates[0].index, 0); | ||
EXPECT_EQ(updates[0].clockwise, true); | ||
} | ||
|
||
TEST_F(EncoderTest, TestOneCounterClockwise) { | ||
uidx = 0; | ||
encoder_init(); | ||
setAndRead(1, false); | ||
setAndRead(0, false); | ||
setAndRead(1, true); | ||
setAndRead(0, true); | ||
|
||
EXPECT_EQ(uidx, 1); | ||
EXPECT_EQ(updates[0].index, 0); | ||
EXPECT_EQ(updates[0].clockwise, false); | ||
} | ||
|
||
TEST_F(EncoderTest, TestTwoClockwiseOneCC) { | ||
uidx = 0; | ||
encoder_init(); | ||
setAndRead(0, false); | ||
setAndRead(1, false); | ||
setAndRead(0, true); | ||
setAndRead(1, true); | ||
setAndRead(0, false); | ||
setAndRead(1, false); | ||
setAndRead(0, true); | ||
setAndRead(1, true); | ||
setAndRead(1, false); | ||
setAndRead(0, false); | ||
setAndRead(1, true); | ||
setAndRead(0, true); | ||
|
||
EXPECT_EQ(uidx, 3); | ||
EXPECT_EQ(updates[0].index, 0); | ||
EXPECT_EQ(updates[0].clockwise, true); | ||
EXPECT_EQ(updates[1].index, 0); | ||
EXPECT_EQ(updates[1].clockwise, true); | ||
EXPECT_EQ(updates[2].index, 0); | ||
EXPECT_EQ(updates[2].clockwise, false); | ||
} | ||
|
||
TEST_F(EncoderTest, TestNoEarly) { | ||
uidx = 0; | ||
encoder_init(); | ||
// send 3 pulses. with resolution 4, that's not enough for a step. | ||
setAndRead(0, false); | ||
setAndRead(1, false); | ||
setAndRead(0, true); | ||
EXPECT_EQ(uidx, 0); | ||
// now send last pulse | ||
setAndRead(1, true); | ||
EXPECT_EQ(uidx, 1); | ||
EXPECT_EQ(updates[0].index, 0); | ||
EXPECT_EQ(updates[0].clockwise, true); | ||
} | ||
|
||
TEST_F(EncoderTest, TestHalfway) { | ||
uidx = 0; | ||
encoder_init(); | ||
// go halfway | ||
setAndRead(0, false); | ||
setAndRead(1, false); | ||
EXPECT_EQ(uidx, 0); | ||
// back off | ||
setAndRead(1, true); | ||
setAndRead(0, true); | ||
EXPECT_EQ(uidx, 0); | ||
// go all the way | ||
setAndRead(0, false); | ||
setAndRead(1, false); | ||
setAndRead(0, true); | ||
setAndRead(1, true); | ||
// should result in 1 update | ||
EXPECT_EQ(uidx, 1); | ||
EXPECT_EQ(updates[0].index, 0); | ||
EXPECT_EQ(updates[0].clockwise, true); | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may be worth removing this.
In the encoder.c file, you could add:
Or the like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was a bit worried about making things confusing. Leaving out the left side would have very different effect from leaving out the right side. Leave out the
_RIGHT
pads, the pads get mirrored and you get encoders on both sides. But leave out the "normal" (aka. left) pads and you only get encoders on right.It would also mean that a board with encoders on only left would look different from a board with encoders only on right:
Waddaya think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I'd prefer to explicitly require both sides in definitions, if an asymmetrical encoder setup is defined.
So you could do the
#ifdef
, but I'm not sure it's the most readable/understandable/maintainable.So yeah, my vote would be both: