summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVasil Zlatanov <v@skozl.com>2017-05-04 02:22:44 +0100
committerVasil Zlatanov <v@skozl.com>2017-05-04 02:22:44 +0100
commit539e0e1e974825f1d60975d6c5352d1b1927c22b (patch)
tree9ec7f5966d91a2703b206bc9feba34413f745ce2
parent7d23bf04971c1a509ccb124768740ae86b8eda7a (diff)
downloade2-switch-539e0e1e974825f1d60975d6c5352d1b1927c22b.tar.gz
e2-switch-539e0e1e974825f1d60975d6c5352d1b1927c22b.tar.bz2
e2-switch-539e0e1e974825f1d60975d6c5352d1b1927c22b.zip
Add automatic threshold
-rw-r--r--src/main.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index cf2214f..aa1b3b7 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -17,7 +17,9 @@ Counter *switch_position[4];
Ticker timer;
volatile uint16_t switch_count[4] = { 0, 0, 0, 0 };
+volatile uint16_t switch_pressed[4] = { 0, 0, 0, 0 };
volatile uint16_t update = 0;
+uint16_t max_count[4];
// Initialise display
SPInit gSpi(D_MOSI_PIN, NC, D_CLK_PIN);
@@ -64,6 +66,14 @@ void tout(void)
for (int i = 0; i < 3; ++i) {
switch_count[i] = switch_position[i]->read();
switch_position[i]->write(0);
+
+ if (max_count[i] < switch_count[i])
+ max_count[i] = switch_count[i];
+
+ if (switch_count[i] < (3/5)*max_count[i])
+ switch_pressed[i] = 1;
+ else if (switch_count[i] > (4/5)*max_count[i])
+ switch_pressed[i] = 0;
}
// Update display
update = 1;