diff --git a/src/SmartCube/cubeButtons.h b/src/SmartCube/cubeButtons.h index 5eecf0f..c648e9c 100644 --- a/src/SmartCube/cubeButtons.h +++ b/src/SmartCube/cubeButtons.h @@ -1,5 +1,8 @@ extern Adafruit_SSD1306 display; // Reference to the OLED display object +extern unsigned long lastRefresh; +extern const unsigned long refreshInterval; bool is_display_off = false; // State variable to track display on/off status +bool is_sound_off = false; // State variable to track display on/off status int buttonDebounceDelay = 50; // Debounce delay in milliseconds int buttonLongPressDelay = 2000; // Long press threshold in milliseconds @@ -29,7 +32,10 @@ void cubeButtonHandler() { if (!leftBeeped) { beep(1000); // Play beep for a short press leftBeeped = true; // Mark as beeped to avoid repeat beeps - // Handle left short press action here + if (is_sound_off) { + is_sound_off = false; // Update display state + beep(1600); // Additional beep to confirm display is on + } } } } else { @@ -43,7 +49,7 @@ void cubeButtonHandler() { if (!middleBeeped) { beep(1000); // Play beep for a short press middleBeeped = true; // Mark as beeped to avoid repeat beeps - // Handle middle short press action here + lastRefresh = millis() + refreshInterval + 1; } } } else { @@ -71,10 +77,10 @@ void cubeButtonHandler() { // Long press detection for left button if (leftPressed && (currentMillis - leftPressStart > buttonLongPressDelay)) { - if (!leftBeeped) { - beep(1000); // Play beep for a long press - leftBeeped = true; // Mark as beeped to avoid repeat beeps - // Handle left long press action here + if (!is_sound_off) { // Turn off the display if it's on + beep(1400); // Beep to indicate display turn-off + is_sound_off = true; // Update display state + beep(1000); // Additional beep to confirm display is off } } diff --git a/src/main.cpp b/src/main.cpp index ed4777c..6daaea7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -22,7 +22,7 @@ bool newProblemsDetected = false; int totalProblems = 0; // Variable to store the total number of active problems // History buffer for the graph -const int maxHistorySize = 30; +const int maxHistorySize = 60; int problemHistory[maxHistorySize] = {0}; // Array to store history int historyIndex = 0; // Current index for the latest value @@ -163,12 +163,16 @@ void displayProblems() { display.clearDisplay(); display.setTextSize(1); display.setCursor(0, 0); - display.printf(" I:%d W:%d A:%d H:%d D:%d", + display.printf("I:%d W:%d A:%d H:%d D:%d", severityCounts[1], severityCounts[2], severityCounts[3], severityCounts[4], severityCounts[5]); + if (is_sound_off) { + display.setCursor(122, 0); + display.print("X"); + } display.drawLine(0, 45, 127, 45, 1); // Line under the graph display.drawLine(0, 10, 127, 10, 1); // Line under the graph @@ -208,8 +212,9 @@ void displayProblems() { display.setCursor(scrollPos, 48); display.print(problemDescriptions); display.setTextSize(1); - display.fillRect(112,35,10,10,0); - display.setCursor(113,36); + display.fillRect(112,35,16,11,0); + display.drawRect(112,35,16,11,1); + display.setCursor(113,37); display.print(totalProblems); display.display(); } @@ -231,7 +236,7 @@ void loop() { displayProblems(); - if (newProblemsDetected) { + if (newProblemsDetected && !is_sound_off) { playAlertMelody(); newProblemsDetected = false; }