-
Notifications
You must be signed in to change notification settings - Fork 18
Add getDirection()
support to ModulinoKnob
and example β‘
#34
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
Changes from 5 commits
53c079c
59aef64
e53f803
9a2a9cf
3d48585
c70097d
66200f1
cff95ab
812cd95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Compiled object files | ||
*.o | ||
*.a | ||
*.so | ||
*.out | ||
|
||
# Arduino build folder | ||
build/ | ||
*.elf | ||
*.bin | ||
*.hex | ||
*.eep | ||
|
||
# Arduino CLI and IDE cache | ||
*.d | ||
*.dep | ||
*.map | ||
*.lst | ||
|
||
# MacOS specific | ||
.DS_Store | ||
|
||
# Backup files | ||
*~ | ||
*.swp | ||
|
||
# VS Code | ||
.vscode/ |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert this file :) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -243,8 +243,9 @@ class ModulinoKnob : public Module { | |
bool begin() { | ||
auto ret = Module::begin(); | ||
if (ret) { | ||
// check for set() bug | ||
auto _val = get(); | ||
_lastPosition = _val; | ||
_lastDebounceTime = millis(); | ||
set(100); | ||
if (get() != 100) { | ||
_bug_on_set = true; | ||
|
@@ -255,12 +256,27 @@ class ModulinoKnob : public Module { | |
} | ||
return ret; | ||
} | ||
int16_t get() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove it. |
||
bool update() { | ||
uint8_t buf[3]; | ||
auto res = read(buf, 3); | ||
if (res == false) { | ||
return 0; | ||
} | ||
get(buf); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
return 1; | ||
} | ||
int16_t get(uint8_t * buf = nullptr) { | ||
if (buf == nullptr) { | ||
buf = (uint8_t*)malloc(3); | ||
if (buf == nullptr) { | ||
return 0; | ||
} | ||
auto res = read(buf, 3); | ||
if (res == false) { | ||
_pressed = false; | ||
return 0; | ||
} | ||
} | ||
_pressed = (buf[2] != 0); | ||
int16_t ret = buf[0] | (buf[1] << 8); | ||
return ret; | ||
|
@@ -277,6 +293,24 @@ class ModulinoKnob : public Module { | |
get(); | ||
return _pressed; | ||
} | ||
int8_t getDirection() { | ||
unsigned long now = millis(); | ||
if (now - _lastDebounceTime < DEBOUNCE_DELAY) { | ||
return 0; | ||
} | ||
int16_t current = get(); | ||
int8_t direction = 0; | ||
if (current > _lastPosition) { | ||
direction = 1; | ||
} else if (current < _lastPosition) { | ||
direction = -1; | ||
} | ||
if (direction != 0) { | ||
_lastDebounceTime = now; | ||
_lastPosition = current; | ||
} | ||
return direction; | ||
} | ||
virtual uint8_t discover() { | ||
for (unsigned int i = 0; i < sizeof(match)/sizeof(match[0]); i++) { | ||
if (scan(match[i])) { | ||
|
@@ -288,6 +322,9 @@ class ModulinoKnob : public Module { | |
private: | ||
bool _pressed = false; | ||
bool _bug_on_set = false; | ||
int16_t _lastPosition = 0; | ||
unsigned long _lastDebounceTime = 0; | ||
static constexpr unsigned long DEBOUNCE_DELAY = 30; | ||
protected: | ||
uint8_t match[2] = { 0x74, 0x76 }; | ||
}; | ||
|
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.
Remove this file.
It is already included in the PR #33