Skip to content

display.py

infinition edited this page Jul 5, 2024 · 1 revision

display.py

This document describes the detailed step-by-step process of how the Display class works, including the specific methods, classes, and functions used at each step.

Initialization and Start of Display

Importing Modules

  • The Display class imports several modules, including standard libraries (threading, time, os, pandas, lgpio, signal, glob, logging, random, sys, subprocess, netifaces) and custom modules (Image, ImageDraw, shared_data, epd2in13_V2, Commentaireia, Logger).

Creating Display Instance

  • An instance of the Display class is created to initialize and manage the e-ink display.

Display Class

__init__ Method

  • Purpose: Initializes the display and starts the main image and shared data update threads.
  • Key Steps:
    1. Initialize Display:
      • Initializes the e-ink display and handles any errors during initialization.
    2. Start Threads:
      • Starts the update_main_image, schedule_update_shared_data, and schedule_update_vuln_count threads to manage updates.

schedule_update_shared_data Method

  • Purpose: Periodically updates the shared data with the latest system information.
  • Key Steps:
    1. Loop:
      • Continuously updates shared data at regular intervals until the application is set to exit.

schedule_update_vuln_count Method

  • Purpose: Periodically updates the vulnerability count on the display.
  • Key Steps:
    1. Loop:
      • Continuously updates the vulnerability count at regular intervals until the application is set to exit.

update_main_image Method

  • Purpose: Updates the main image on the display with the latest image data.
  • Key Steps:
    1. Loop:
      • Continuously updates the main image at random intervals until the application is set to exit.
    2. Randomize Image:
      • Selects a new image based on the current status and updates the display.

update_vuln_count Method

  • Purpose: Updates the vulnerability count on the display.
  • Key Steps:
    1. Load and Check Files:
      • Loads the vulnerability summary file and network knowledge base file, and checks for alive hosts.
    2. Update Vulnerability Count:
      • Updates the vulnerability count based on the data and writes it to the live status file.

update_shared_data Method

  • Purpose: Updates the shared data with the latest system information.
  • Key Steps:
    1. Load and Check Files:
      • Loads the live status file and cracked password files to update various counts.
    2. Update Shared Data:
      • Updates shared data attributes such as port count, target count, and various connection statuses.

display_comment Method

  • Purpose: Displays a comment based on the status of the orchestrator.
  • Key Steps:
    1. Fetch Comment:
      • Retrieves a comment from the Commentaireia instance based on the current status.
    2. Update Display:
      • Updates the display with the fetched comment and current status text.

is_bluetooth_active Method

  • Purpose: Checks if Bluetooth is active.
  • Key Steps:
    1. Run Command:
      • Executes the hciconfig command to check the status of the Bluetooth adapter.
    2. Check Status:
      • Returns True if the adapter is up and running, otherwise False.

is_wifi_connected Method

  • Purpose: Checks if Wi-Fi is connected.
  • Key Steps:
    1. Run Command:
      • Executes the iwgetid command to get the current SSID.
    2. Check Connection:
      • Returns True if connected to a Wi-Fi network, otherwise False.

is_interface_connected Method

  • Purpose: Checks if any device is connected to the specified interface (e.g., pan0 or usb0).
  • Key Steps:
    1. Run Command:
      • Executes the ip neigh show dev command to check for connected devices.
    2. Check Output:
      • Returns True if there are any connected devices, otherwise False.

is_usb_connected Method

  • Purpose: Checks if any device is connected to the USB interface (usb0).
  • Key Steps:
    1. Run Command:
      • Executes the ip neigh show dev usb0 command to check for connected devices.
    2. Check Output:
      • Returns True if there are any connected devices, otherwise False.

run Method

  • Purpose: Main loop for updating the e-ink display with shared data.
  • Key Steps:
    1. Loop:
      • Continuously updates the display until the application is set to exit.
    2. Initialize Display:
      • Initializes the e-ink display for partial updates.
    3. Display Comment:
      • Displays the current comment based on the orchestrator status.
    4. Update Display Elements:
      • Updates various elements on the display, including status icons, statistics, and images.
    5. Render Display:
      • Renders the updated content on the e-ink display and saves the current screen image.

handle_exit_display Function

  • Purpose: Handles the exit signal and closes the display.
  • Key Steps:
    1. Set Exit Flag:
      • Sets the should_exit flag to True to signal all threads to stop.
    2. Cleanup:
      • Cleans up the display and exits the application.

Execution Flow when display.py is Run

Step 1: Initialize Display

  • An instance of the Display class is created, initializing the e-ink display and starting update threads.

Step 2: Start Main Loop

  • The main loop is started in a separate thread to continuously update the display.

Step 3: Update Threads

  • The update_main_image, schedule_update_shared_data, and schedule_update_vuln_count threads continuously update the display and shared data.

Step 4: Handle Exit Signal

  • When an exit signal is received, the handle_exit_display function sets the exit flag and cleans up the display before exiting.

Summary

The Display class is responsible for managing the e-ink display of the Bjorn project, updating it with relevant data and statuses. It initializes the display, manages multiple threads for updating shared data and vulnerability counts, and handles the rendering of information and images on the display. The class ensures that the display is continuously updated with the latest information and handles system commands to check the status of various connections.