Skip to content

Commit

Permalink
feat (firmware): add simulation flags for WiFi and battery status
Browse files Browse the repository at this point in the history
  • Loading branch information
sayanee committed Dec 6, 2024
1 parent 6fcb26f commit 0d69382
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions _code/demo/demo.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
// Change the debug level accordingly:
// DBG_NONE, DBG_ERROR, DBG_WARNING,
// DBG_INFO (default), DBG_DEBUG, and DBG_VERBOSE
#ifdef PRODUCTION
#define DEBUG DBG_NONE
#else
#define DEBUG DBG_INFO
#endif
// Change the debug level accordingly:
// DBG_NONE, DBG_ERROR, DBG_WARNING,
// DBG_INFO (default), DBG_DEBUG, and DBG_VERBOSE

// Simulatation flags
bool simulateWifiNotConnected = false;
bool simulateBattery = false;
bool simulateCurrentTimeNotInRange = false;

#include "Arduino_DebugUtils.h"
#include "src/bell/bell.h"
Expand Down Expand Up @@ -62,7 +67,10 @@ void setup() {
if (isWifiConnected()) {
// If the current time is within the specified range, ring the bell
if (isCurrentTimeInRange()) {
DEBUG_INFO("Ringing the bell! The time is right.");
ringBell();
} else {
DEBUG_INFO("Not ringing the bell. The time is not right.");
}

// Display WiFi information on the debug interface
Expand Down Expand Up @@ -121,6 +129,10 @@ void initializeDebug() {
}

bool isWifiConnected() {
if (simulateWifiNotConnected) {
return false;
}

wifiConnector.connect();
return wifiConnector.isConnected();
}
Expand All @@ -131,18 +143,22 @@ void displayWiFiInfo() {
}

bool isCurrentTimeInRange() {
if (simulateCurrentTimeNotInRange) {
DEBUG_INFO("Current time: ");
DEBUG_INFO("22:09:08");
return false;
}

timeManager.init();

DEBUG_INFO("Current time: ");
DEBUG_INFO(timeManager.getFormattedTime().c_str());

if (timeManager.isCurrentTimeInRange()) {
DEBUG_INFO("Ringing the bell! The time is right.");
return true;
} else {
DEBUG_INFO("Not ringing the bell! The time is not right.");
return false;
}

return false;
}

void ringBell() {
Expand All @@ -152,11 +168,14 @@ void ringBell() {
}

int checkBatteryLevel() {
if (simulateBattery) {
return 13;
}

batteryLevel.init();
float batt = batteryLevel.calculate();
String debugMessage = "Battery Level: "
+ String(batt)
+ "%";
+ String(batt);
DEBUG_INFO(debugMessage.c_str());

return (int)batt;
Expand Down

0 comments on commit 0d69382

Please sign in to comment.