From 84ec943d6df66f8ca404d7cc0babf0ddbd3dbcbe Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard <dr@jones.dk> Date: Wed, 2 Apr 2025 16:03:49 +0200 Subject: add function qualifyVote() --- Mussel/Mussel.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'Mussel/Mussel.cpp') 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 -- cgit v1.2.3