From e4b66029dc69543c9b6bd6f173f260c823d37b7b Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Wed, 16 Apr 2025 20:25:45 +0200 Subject: use log_i() --- vote/vote.ino | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'vote') diff --git a/vote/vote.ino b/vote/vote.ino index 13b425a..a805ea6 100644 --- a/vote/vote.ino +++ b/vote/vote.ino @@ -80,7 +80,8 @@ void storeVoteForMussel(const String& id, unsigned long timestamp, int gape_meas // If mussel not found, add new if (index == -1) { if (voterCount >= VOTER_MAX) { - Serial.printf("Ignored: Max mussel limit reached (%s)\n", id.c_str()); + log_i("Ignored: Max mussel limit reached (%s)", + id.c_str()); return; } voters[voterCount].id = id; @@ -100,18 +101,19 @@ void storeVoteForMussel(const String& id, unsigned long timestamp, int gape_meas // Store the new vote at the end voter.votes[voter.voteCount++] = {timestamp, gape_measure}; - Serial.printf("Vote stored: Time: %lu, Mussel: %s, Gape: %d\n", timestamp, id.c_str(), gape_measure); + log_i("Vote stored: Time: %lu, Mussel: %s, Gape: %d", + timestamp, id.c_str(), gape_measure); } /// Classify mussel state based on topmost vote void alignVotes() { - Serial.println("---- Mussel Alignment Status ----"); for (int i = 0; i < voterCount; i++) { Voter &voter = voters[i]; // Skip mussels with no data if (voter.voteCount == 0) { - Serial.printf("Mussel ID: %s - No data\n", voter.id.c_str()); + log_i("Mussel ID: %s - No data", + voter.id.c_str()); continue; } @@ -121,10 +123,9 @@ void alignVotes() { (latest.measure >= 40 && latest.measure <= 90) ? "Open" : "Invalid reading"; - Serial.printf("Mussel ID: %s | Latest Gape: %d | State: %s\n", - voter.id.c_str(), latest.measure, state.c_str()); + log_i("Mussel ID: %s | Latest Gape: %d | State: %s", + voter.id.c_str(), latest.measure, state.c_str()); } - Serial.println("---------------------------------"); } /// Decide whether a vote is valid based on gape and age @@ -136,35 +137,37 @@ const char* qualifyMusselVote(int gape, unsigned long voteTimestamp, unsigned lo unsigned long age = now - voteTimestamp; // Log the state - Serial.printf("Qualifying vote | Time since vote: %lu ms | Gape: %d (%s)\n", age, gape, gapStateStr); + log_i("Qualifying vote | Time since vote: %lu ms | Gape: %d (%s)", + age, gape, gapStateStr); // Invalid if mussel is closed if (gapState == Closed) { - Serial.println("→ INVALID: Mussel is Closed."); + log_i("→ INVALID: Mussel is Closed"); return "invalid"; } // Invalid if vote is too old if (age > VOTE_TIME_BEHIND) { - Serial.println("→ INVALID: Vote is too old (>2 minutes)."); + log_i("→ INVALID: Vote is too old (>2 minutes)"); return "invalid"; } // Valid if within 1 minute and mussel is open if (age <= VOTE_TIME_AHEAD) { - Serial.println("→ VALID: Mussel is Open and vote is recent."); + log_i("→ VALID: Mussel is Open and vote is recent"); return "valid"; } // Catch-all for anything in between - Serial.println("→ INVALID: Vote is in uncertain window time"); + log_i("→ INVALID: Vote is in uncertain window time"); return "invalid"; } /// Output the final vote decision for a mussel void concludeMusselVote(const String& musselId, const char* validity) { const char* result = strcmp(validity, "valid") == 0 ? "YES" : "NO"; - Serial.printf("Final Vote from Mussel %s → %s (Vote was %s)\n", musselId.c_str(), result, validity); + log_i("Final Vote from Mussel %s → %s (Vote was %s)", + musselId.c_str(), result, validity); } // Bluetooth beacon discovery callbacks -- cgit v1.2.3