Skip to content

OLED Display Interface

Overview

The SMARTA L v2 device utilizes a monochrome OLED display (likely an SSD1306 driven via I2C) to provide users with real-time status information, menu navigation for the Button Interface, and feedback on operations.

Initialization

  • The display is initialized during the initialize_device() sequence in main.ino.
  • It uses the Adafruit GFX and Adafruit SSD1306 libraries.
  • The I2C address is typically 0x3C.
  • If the display fails to initialize, an error message is printed to the Serial console.

Main Display (updateDisplay() in OLED.ino)

This is the primary screen shown during normal operation. It dynamically updates to show:

  • Tank Level: Numerically displayed (e.g., "LEVEL 35"). Shows ".." if the level is unknown (999).
  • Tank Graphic: A visual representation of the tank, with the fill level corresponding to tank_level relative to minVal and maxVal.
    • If tank_level is below minVal, an "X" is drawn through the tank.
  • Last Sensor Update: Shows how many seconds ago the sensor data was last received (e.g., "10s"). If this exceeds sensorCommsLossThreshold, it's highlighted with "!".
  • Triggers Active: An "A" is displayed if triggers_active is true.
  • Pump Timer: Shows minutes:seconds the pump has been running.
  • Min/Max Levels: Displays the configured minVal and maxVal next to the tank graphic.
  • Status Icons (Top Right & Right Edge):
    • Wi-Fi Icon: Shown if wifi_connected is true.
    • LTE Icon: Shown if lte_connected is true.
    • Bluetooth Icon: Shown if ble_connected is true.
    • Restart Counter: If countup_to_restart is greater than 0 (indicating pending reboot due to connectivity loss), this number is shown.
  • Filling Animation: The drawFillingBitmap() function can display an animated sequence (using bitmaps from bitmaps.h) when the pump is active (filling variable).

Settings Menu Display (Handled in settingsTask() in SMARTA_L_v2.ino and showSetting())

When the settings mode is active via the Button Interface:

  • The OLED displays the current menu item (e.g., "REBOOT", "ROLLBACK FW", "FACTORY RESET", "Set Min Level").
  • When adjusting a value (e.g., Min/Max Level), the screen shows the setting name and its current/temporary value (showSetting() function).
  • Confirmation messages like "SAVED!" or "SAVED (Auto)!" are displayed upon changing a setting.

Status and Notification Screens

The OLED.ino file contains various functions to display specific messages or states:

  • printStatusToOLED(const std::string &message): A generic function to clear the display and show a short message (used for OTA updates, errors, etc.).
  • setupDisplay(const char *title, int textSize = 1): A helper to clear and prepare the display with a title.
  • Welcome Sequence (welcomeScreenDisplay()):
    • Shows "SMARTA L".
    • Shows the current firmware version (e.g., currentVersion).
  • Wi-Fi Related Messages:
    • waitingForWiFiDisplay(): "WAITING FOR WIFI", "The device starts in 60 seconds".
    • wifiFailedDisplay(): "Failed to connect...", "We will keep trying".
    • connectToWiFiDisplay(): "Connecting to WiFi", device hostname, "Please wait...".
  • Sensor Related Messages:
    • sensorPairedDisplay(): "SENSOR PAIRED", displays the sensor's MAC address (adv_id).
    • noSensorDetectedDisplay(): "NO SENSOR DETECTED".
  • Pump Related Messages:
    • noPumpDetectedDisplay(): "CANNOT OPERATE PUMP", "NO PUMP DETECTED".
  • System Action Feedback (often called from main.ino or settingsTask()):
    • OTA Updates: "Checking version...", "Updating...", progress messages.
    • Rollback: "Performing rollback...", "Rollback successful. Rebooting...", "Rollback failed.".
    • Factory Reset: "Performing factory reset...".
    • Reboot: "REBOOTING".
  • Captive Portal (guideToSaveDisplay()): "CAPTIVE PORTAL ACTIVE", "CLICK SAVE WHEN DONE".
  • Mode Display (updateDisplayMode()): Shows "LOCAL MODE" or "WIFI MODE".

General Display Operations

  • display.clearDisplay(): Clears the screen content.
  • display.setTextSize(): Sets the font size.
  • display.setTextColor(): Sets the text color (usually WHITE on black background).
  • display.setCursor(): Sets the position for subsequent drawing.
  • display.println() / display.print(): Prints text.
  • display.drawBitmap(): Draws predefined icons/graphics from bitmaps.h.
  • display.drawRect(), display.fillRect(), display.drawLine(): Used for drawing shapes (like the tank).
  • display.display(): Must be called to transfer the buffer content to the actual screen.

Key Files

  • OLED.ino: Contains most of the display logic, including updateDisplay() and various status screen functions.
  • main.ino: Initializes the display and calls display functions for OTA, factory reset, etc.
  • SMARTA_L_v2.ino: The settingsTask() interacts heavily with the display for menu navigation. The loop() calls updateDisplay() if not in settings mode.
  • bitmaps.h & bitmaps.cpp: Define the icons and animation frames used on the display.