mirror of
https://github.com/infinition/Bjorn.git
synced 2025-12-06 06:11:46 +00:00
Clone
1
display.py
infinition edited this page 2024-07-06 01:05:09 +02:00
Table of Contents
- display.py
- Initialization and Start of Display
- Display Class
- __init__ Method
- schedule_update_shared_data Method
- schedule_update_vuln_count Method
- update_main_image Method
- update_vuln_count Method
- update_shared_data Method
- display_comment Method
- is_bluetooth_active Method
- is_wifi_connected Method
- is_interface_connected Method
- is_usb_connected Method
- run Method
- handle_exit_display Function
- Execution Flow when display.py is Run
- Step 1: Initialize Display
- Step 2: Start Main Loop
- Step 3: Update Threads
- Step 4: Handle Exit Signal
- Summary
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
Displayclass 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
Displayclass 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:
- Initialize Display:
- Initializes the e-ink display and handles any errors during initialization.
- Start Threads:
- Starts the
update_main_image,schedule_update_shared_data, andschedule_update_vuln_countthreads to manage updates.
- Starts the
- Initialize Display:
schedule_update_shared_data Method
- Purpose: Periodically updates the shared data with the latest system information.
- Key Steps:
- Loop:
- Continuously updates shared data at regular intervals until the application is set to exit.
- Loop:
schedule_update_vuln_count Method
- Purpose: Periodically updates the vulnerability count on the display.
- Key Steps:
- Loop:
- Continuously updates the vulnerability count at regular intervals until the application is set to exit.
- Loop:
update_main_image Method
- Purpose: Updates the main image on the display with the latest image data.
- Key Steps:
- Loop:
- Continuously updates the main image at random intervals until the application is set to exit.
- Randomize Image:
- Selects a new image based on the current status and updates the display.
- Loop:
update_vuln_count Method
- Purpose: Updates the vulnerability count on the display.
- Key Steps:
- Load and Check Files:
- Loads the vulnerability summary file and network knowledge base file, and checks for alive hosts.
- Update Vulnerability Count:
- Updates the vulnerability count based on the data and writes it to the live status file.
- Load and Check Files:
update_shared_data Method
- Purpose: Updates the shared data with the latest system information.
- Key Steps:
- Load and Check Files:
- Loads the live status file and cracked password files to update various counts.
- Update Shared Data:
- Updates shared data attributes such as port count, target count, and various connection statuses.
- Load and Check Files:
display_comment Method
- Purpose: Displays a comment based on the status of the orchestrator.
- Key Steps:
- Fetch Comment:
- Retrieves a comment from the
Commentaireiainstance based on the current status.
- Retrieves a comment from the
- Update Display:
- Updates the display with the fetched comment and current status text.
- Fetch Comment:
is_bluetooth_active Method
- Purpose: Checks if Bluetooth is active.
- Key Steps:
- Run Command:
- Executes the
hciconfigcommand to check the status of the Bluetooth adapter.
- Executes the
- Check Status:
- Returns
Trueif the adapter is up and running, otherwiseFalse.
- Returns
- Run Command:
is_wifi_connected Method
- Purpose: Checks if Wi-Fi is connected.
- Key Steps:
- Run Command:
- Executes the
iwgetidcommand to get the current SSID.
- Executes the
- Check Connection:
- Returns
Trueif connected to a Wi-Fi network, otherwiseFalse.
- Returns
- Run Command:
is_interface_connected Method
- Purpose: Checks if any device is connected to the specified interface (e.g.,
pan0orusb0). - Key Steps:
- Run Command:
- Executes the
ip neigh show devcommand to check for connected devices.
- Executes the
- Check Output:
- Returns
Trueif there are any connected devices, otherwiseFalse.
- Returns
- Run Command:
is_usb_connected Method
- Purpose: Checks if any device is connected to the USB interface (
usb0). - Key Steps:
- Run Command:
- Executes the
ip neigh show dev usb0command to check for connected devices.
- Executes the
- Check Output:
- Returns
Trueif there are any connected devices, otherwiseFalse.
- Returns
- Run Command:
run Method
- Purpose: Main loop for updating the e-ink display with shared data.
- Key Steps:
- Loop:
- Continuously updates the display until the application is set to exit.
- Initialize Display:
- Initializes the e-ink display for partial updates.
- Display Comment:
- Displays the current comment based on the orchestrator status.
- Update Display Elements:
- Updates various elements on the display, including status icons, statistics, and images.
- Render Display:
- Renders the updated content on the e-ink display and saves the current screen image.
- Loop:
handle_exit_display Function
- Purpose: Handles the exit signal and closes the display.
- Key Steps:
- Set Exit Flag:
- Sets the
should_exitflag toTrueto signal all threads to stop.
- Sets the
- Cleanup:
- Cleans up the display and exits the application.
- Set Exit Flag:
Execution Flow when display.py is Run
Step 1: Initialize Display
- An instance of the
Displayclass 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, andschedule_update_vuln_countthreads continuously update the display and shared data.
Step 4: Handle Exit Signal
- When an exit signal is received, the
handle_exit_displayfunction 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.