aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Mussel/Mussel.cpp23
-rw-r--r--Mussel/Mussel.h9
2 files changed, 32 insertions, 0 deletions
diff --git a/Mussel/Mussel.cpp b/Mussel/Mussel.cpp
index 568030a..1d5c2b0 100644
--- a/Mussel/Mussel.cpp
+++ b/Mussel/Mussel.cpp
@@ -258,6 +258,29 @@ void Mussel::printStack() {
}
}
+bool qualifyVote(Vote vote, unsigned long currentTime) {
+
+ // If the measure is 42 (YES), check timestamp validity
+ if (vote.measure == 42) {
+ // If the vote's timestamp is within 1 minute, count it as YES
+ if (currentTime - vote.timestamp <= MUSSEL_VOTE_TIME_AHEAD) {
+ return true;
+ }
+ // If the vote's timestamp is older than 2 minutes, count it as NO
+ else if (currentTime - vote.timestamp > MUSSEL_VOTE_TIME_BEHIND) {
+ return false;
+ }
+ }
+
+ // If the measure is 2, always count the vote as NO
+ if (vote.measure == 2) {
+ return false;
+ }
+
+ // Default case: vote is invalid if no conditions are met
+ return false;
+}
+
/// Dump internal variables, formatted for use with Serial Plotter
///
/// @return internal variables as String
diff --git a/Mussel/Mussel.h b/Mussel/Mussel.h
index a50ccaa..a098e52 100644
--- a/Mussel/Mussel.h
+++ b/Mussel/Mussel.h
@@ -18,6 +18,8 @@
// seconds
#define MUSSEL_NORMAL_PACE 50U
#define MUSSEL_STRESS_PACE 10U
+#define MUSSEL_VOTE_TIME_AHEAD 60000U // 1 minute
+#define MUSSEL_VOTE_TIME_BEHIND 120000U // 2 minutes
// milliseconds
#define MUSSEL_DEBOUNCE_DELAY 50U
@@ -40,12 +42,19 @@ class Mussel {
const uint8_t pin,
const uint8_t type);
+ struct Vote {
+ String id;
+ unsigned long timestamp;
+ int measure;
+ };
+
void begin();
String desc();
byte read();
String debug();
bool push(String id, unsigned long timestamp, int measure);
void printStack();
+ bool qualifyVote(Vote vote, unsigned long currentTime);
private:
int _attitude;