summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2014-03-09 16:21:20 +0100
committerVegard Storheil Eriksen <zyp@jvnv.net>2014-11-09 22:49:30 +0100
commitafb3e6cdd24191d6cc2aa813dda646f2c1f19ee2 (patch)
tree61d38ba4285acaad2f9a5753dcf5343ece045bc7 /main.cpp
parentf6f94ac4fe9d9774dce374eec32a633abc5ce9e1 (diff)
Added up/down buttons for QE inputs.
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp47
1 files changed, 45 insertions, 2 deletions
diff --git a/main.cpp b/main.cpp
index a6acd7e..4f3f897 100644
--- a/main.cpp
+++ b/main.cpp
@@ -120,8 +120,8 @@ auto report_desc = gamepad(
// Inputs.
report_id(1),
- buttons(11),
- padding_in(5),
+ buttons(15),
+ padding_in(1),
usage_page(UsagePage::Desktop),
usage(DesktopUsage::X),
@@ -588,6 +588,12 @@ int main() {
qe2a.set_mode(Pin::AF);
qe2b.set_mode(Pin::AF);
+ uint8_t last_x = 0;
+ uint8_t last_y = 0;
+
+ int8_t state_x = 0;
+ int8_t state_y = 0;
+
while(1) {
usb.process();
@@ -611,6 +617,43 @@ int main() {
uint32_t qe1_count = TIM2.CNT;
uint32_t qe2_count = TIM3.CNT;
+ int8_t rx = qe1_count - last_x;
+ int8_t ry = qe2_count - last_y;
+ last_x = qe1_count;
+ last_y = qe2_count;
+
+ if(rx > 0) {
+ state_x = 100;
+ } else if(rx < 0) {
+ state_x = -100;
+ } else if(state_x > 0) {
+ state_x--;
+ } else if(state_x < 0) {
+ state_x++;
+ }
+
+ if(ry > 0) {
+ state_y = 100;
+ } else if(ry < 0) {
+ state_y = -100;
+ } else if(state_y > 0) {
+ state_y--;
+ } else if(state_y < 0) {
+ state_y++;
+ }
+
+ if(state_x > 0) {
+ buttons |= 1 << 11;
+ } else if(state_x < 0) {
+ buttons |= 1 << 12;
+ }
+
+ if(state_y > 0) {
+ buttons |= 1 << 13;
+ } else if(state_y < 0) {
+ buttons |= 1 << 14;
+ }
+
if(config.qe1_sens < 0) {
qe1_count /= -config.qe1_sens;
} else if(config.qe1_sens > 0) {