Skip to content

Commit

Permalink
Adds new start options for Profiler and option to rotate the display
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangranados committed Sep 30, 2024
1 parent bf3e8c2 commit 9aa9287
Show file tree
Hide file tree
Showing 5 changed files with 154 additions and 45 deletions.
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
wlanpi-fpms (1.4.3) unstable; urgency=medium

* Adds option System > Settings > Rotate Display
* Adds option Apps > Profiler > Start Other

-- Adrian Granados <adrian@intuitibits.com> Mon, 30 Sep 2024 00:00:00 -0500

wlanpi-fpms (1.4.2) UNRELEASED; urgency=medium

* Adrian's 6b6b7cd Adds logic for reboot detection using D-Bus PrepareForShutdown
Expand Down
142 changes: 103 additions & 39 deletions fpms/fpms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import dbus.mainloop.glib
from gi.repository import GLib
import syslog
import configparser

import getopt
import gpiod
Expand Down Expand Up @@ -44,18 +45,7 @@
from .modules.apps.scanner import *
from .modules.bluetooth import *
from .modules.cloud_tests import CloudUtils
from .modules.constants import (
BUTTONS_PINS,
DISPLAY_MODE,
IMAGE_DIR,
MODE_FILE,
NAV_BAR_TOP,
PAGE_HEIGHT,
PAGE_SLEEP,
PAGE_WIDTH,
SCRIPT_PATH,
WLANPI_IMAGE_FILE,
)
from .modules.constants import *
from .modules.env_utils import EnvUtils
from .modules.modes import *
from .modules.nav.buttons import Button
Expand All @@ -71,6 +61,8 @@
from .modules.reg_domain import *
from .modules.time_zone import *

FPMS_CONF_FILE = "/etc/wlanpi-fpms.conf"

#######################################
# Initialize various global variables
#######################################
Expand All @@ -84,8 +76,8 @@
# drawing action in already if progress (e.g. by another activity). An activity
# happens during each cycle of the main while loop or when a button is pressed
# (This does not appear to be threading or process spawning)
'display_orientation': DISPLAY_ORIENTATION_NORMAL, # Display module orientation
'drawing_in_progress': False, # True when page being painted on screen

'shutdown_in_progress': False, # True when shutdown or reboot started
'screen_cleared': False, # True when display cleared (e.g. screen save)
'display_state': 'page', # current display state: 'page' or 'menu'
Expand Down Expand Up @@ -131,7 +123,7 @@ def detect_reboot_target(args):
If detected, it triggers the shutdown handler.
"""
# log_to_syslog(f"Checking arguments for reboot.target: {args}")

for arg in args:
# Check for reboot.target or its systemd path
if isinstance(arg, str) and ("reboot" in arg):
Expand All @@ -148,7 +140,7 @@ def handle_shutdown():
log_to_syslog("Drawing reboot image")
oled.drawImage(Image.open(IMAGE_DIR + '/reboot.png').convert(DISPLAY_MODE))
log_to_syslog("Reboot image drawn")


# Handler for PrepareForShutdown signal
def handle_prepare_for_shutdown(reboot_arg):
Expand Down Expand Up @@ -210,7 +202,7 @@ def run_dbus_loop():
# handle_systemd_unit_signal,
# dbus_interface="org.freedesktop.systemd1.Unit", # Unit interface
# signal_name=None, # Capture any signal related to the unit
# bus_name="org.freedesktop.systemd1",
# bus_name="org.freedesktop.systemd1",
# path="/org/freedesktop/systemd1/unit/reboot_2etarget" # Path to reboot.target unit
# )

Expand All @@ -219,7 +211,7 @@ def run_dbus_loop():
# handle_systemd_unit_signal,
# dbus_interface="org.freedesktop.systemd1.Unit", # Unit interface
# signal_name=None, # Capture any signal related to the unit
# bus_name="org.freedesktop.systemd1",
# bus_name="org.freedesktop.systemd1",
# path="/org/freedesktop/systemd1/unit/systemd_2dreboot_2eservice" # Path to systemd-reboot.service
# )

Expand All @@ -233,18 +225,45 @@ def run_dbus_loop():
)
log_to_syslog(f"event handlers added")

# Run indefinitely to handle D-Bus signals
# Run indefinitely to handle D-Bus signals
loop = GLib.MainLoop()
loop.run()

# Function to read a value from a section in the .conf file
def read_value(section, key, default_value):
config = configparser.ConfigParser()
config.read(FPMS_CONF_FILE)

# Read the value from the specified section and key
if config.has_section(section) and config.has_option(section, key):
value = config.get(section, key)
return value
else:
return default_value

# Function to modify and save a value in the specified section and key
def save_value(section, key, new_value):
config = configparser.ConfigParser()
config.read(FPMS_CONF_FILE)

# Check if the section exists, if not, create it
if not config.has_section(section):
config.add_section(section)

# Modify or add the value
config.set(section, key, new_value)

# Write the updated config back to the file
with open(FPMS_CONF_FILE, 'w') as f:
config.write(f)

def main():
# Run D-Bus main loop in a separate thread
dbus_thread = threading.Thread(target=run_dbus_loop)
dbus_thread.daemon = True
dbus_thread.start()
log_to_syslog(f"fpms starting after dbus thread setup")

global g_vars
global running

Expand Down Expand Up @@ -305,6 +324,9 @@ def usage():
####################################
oled.init()

g_vars['display_orientation'] = read_value("display", "orientation", DISPLAY_ORIENTATION_NORMAL)
oled.orientation = g_vars['display_orientation']

############################
# shared objects
############################
Expand Down Expand Up @@ -497,6 +519,14 @@ def profiler_start_2dot4ghz():
app_obj = Profiler(g_vars)
app_obj.profiler_start_2dot4ghz(g_vars)

def profiler_start_5ghz_unii1():
app_obj = Profiler(g_vars)
app_obj.profiler_start_5ghz_unii1(g_vars)

def profiler_start_5ghz_unii3():
app_obj = Profiler(g_vars)
app_obj.profiler_start_5ghz_unii3(g_vars)

def profiler_start_no11r():
app_obj = Profiler(g_vars)
app_obj.profiler_start_no11r(g_vars)
Expand Down Expand Up @@ -589,6 +619,17 @@ def set_reg_domain_de():
system_obj = RegDomain(g_vars)
system_obj.set_reg_domain_de(g_vars)

def rotate_display():
if g_vars['display_orientation'] == DISPLAY_ORIENTATION_NORMAL:
g_vars['display_orientation'] = DISPLAY_ORIENTATION_FLIPPED
else:
g_vars['display_orientation'] = DISPLAY_ORIENTATION_NORMAL
oled.orientation = g_vars['display_orientation']
save_value("display", "orientation", g_vars['display_orientation'])
g_vars['sig_fired'] = True
menu_left()
g_vars['sig_fired'] = False

def show_date():
system_obj = System(g_vars)
system_obj.show_date(g_vars)
Expand Down Expand Up @@ -801,9 +842,14 @@ def create_shortcut(menu, path, location=[]):
{"name": "Status", "action": profiler_status},
{"name": "Stop", "action": profiler_stop},
{"name": "Start", "action": profiler_start},
{"name": "Start 2.4 GHz", "action": profiler_start_2dot4ghz},
{"name": "Start (no 11r)", "action": profiler_start_no11r},
{"name": "Start (no 11ax)", "action": profiler_start_no11ax},
{"name": "Start Other", "action": [
{"name": "Start 2.4 GHz", "action": profiler_start_2dot4ghz},
{"name": "Start 5 GHz 36", "action": profiler_start_5ghz_unii1},
{"name": "Start 5 GHz 149", "action": profiler_start_5ghz_unii3},
{"name": "Start (no 11r)", "action": profiler_start_no11r},
{"name": "Start (no 11ax)", "action": profiler_start_no11ax}
]
},
{"name": "Purge Reports", "action": [
{"name": "Confirm", "action": profiler_purge_reports},
]
Expand Down Expand Up @@ -858,6 +904,7 @@ def create_shortcut(menu, path, location=[]):
{"name": "Set Domain DE", "action": [
{"name": "Confirm & Reboot", "action": set_reg_domain_de},]},
]},
{"name": "Rotate Display", "action": rotate_display}
]},
{"name": "Reboot", "action": [
{"name": "Confirm", "action": reboot},
Expand Down Expand Up @@ -1115,23 +1162,40 @@ def monitor_buttons():
events = request.read_edge_events()

for event in events:
if event.line_offset == BUTTONS_PINS['up']:
up_key()
elif event.line_offset == BUTTONS_PINS['down']:
down_key()
elif event.line_offset == BUTTONS_PINS['left']:
left_key()
elif event.line_offset == BUTTONS_PINS['right']:
right_key()
elif event.line_offset == BUTTONS_PINS['center']:
center_key()
elif event.line_offset == BUTTONS_PINS['key1']:
key_1()
elif event.line_offset == BUTTONS_PINS['key2']:
key_2()
elif event.line_offset == BUTTONS_PINS['key3']:
key_3()

if g_vars['display_orientation'] == DISPLAY_ORIENTATION_FLIPPED:
if event.line_offset == BUTTONS_PINS['up']:
down_key()
elif event.line_offset == BUTTONS_PINS['down']:
up_key()
elif event.line_offset == BUTTONS_PINS['left']:
right_key()
elif event.line_offset == BUTTONS_PINS['right']:
left_key()
elif event.line_offset == BUTTONS_PINS['center']:
center_key()
elif event.line_offset == BUTTONS_PINS['key1']:
key_3()
elif event.line_offset == BUTTONS_PINS['key2']:
key_2()
elif event.line_offset == BUTTONS_PINS['key3']:
key_1()
else:
if event.line_offset == BUTTONS_PINS['up']:
up_key()
elif event.line_offset == BUTTONS_PINS['down']:
down_key()
elif event.line_offset == BUTTONS_PINS['left']:
left_key()
elif event.line_offset == BUTTONS_PINS['right']:
right_key()
elif event.line_offset == BUTTONS_PINS['center']:
center_key()
elif event.line_offset == BUTTONS_PINS['key1']:
key_1()
elif event.line_offset == BUTTONS_PINS['key2']:
key_2()
elif event.line_offset == BUTTONS_PINS['key3']:
key_3()

m = threading.Thread(name="button-monitor", target=monitor_buttons)
m.daemon = True
Expand Down
31 changes: 27 additions & 4 deletions fpms/modules/apps/profiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,16 @@ def profiler_ctl(self, g_vars, action="status"):
cfg_dict = {"channel": "11", "ft_disabled": "False", "he_disabled": "False"}
self.profiler_ctl_file_update(cfg_dict, config_file)

elif action == "start_5ghz_unii1":
# set the config file to use params
cfg_dict = {"channel": "36", "ft_disabled": "False", "he_disabled": "False"}
self.profiler_ctl_file_update(cfg_dict, config_file)

elif action == "start_5ghz_unii3":
# set the config file to use params
cfg_dict = {"channel": "149", "ft_disabled": "False", "he_disabled": "False"}
self.profiler_ctl_file_update(cfg_dict, config_file)

elif action == "start_no11r":
# set the config file to use params
cfg_dict = {"channel": "36", "ft_disabled": "True", "he_disabled": "False"}
Expand Down Expand Up @@ -261,9 +271,13 @@ def profiler_ctl(self, g_vars, action="status"):
time.sleep(0.5)
elapsed_time = elapsed_time + 0.5

self.alert_obj.display_alert_info(
g_vars, "Profiler started.", title="Success"
)
if self.profiler_beaconing():
self.alert_obj.display_alert_info(
g_vars, "Profiler started.", title="Success"
)
else:
self.alert_obj.display_alert_error(g_vars, "Start failed.")

except subprocess.CalledProcessError as proc_exc:
self.alert_obj.display_alert_error(g_vars, "Start failed.")
except subprocess.TimeoutExpired as timeout_exc:
Expand Down Expand Up @@ -300,7 +314,8 @@ def profiler_ctl(self, g_vars, action="status"):
else:
self.alert_obj.display_alert_info(
g_vars, "Profiler stopped.", title="Success"
)
)

except subprocess.CalledProcessError as exc:
self.alert_obj.display_alert_error(g_vars, "Stop failed.")

Expand Down Expand Up @@ -358,6 +373,14 @@ def profiler_start_2dot4ghz(self, g_vars):
self.profiler_ctl(g_vars, action="start_2dot4ghz")
return

def profiler_start_5ghz_unii1(self, g_vars):
self.profiler_ctl(g_vars, action="start_5ghz_unii1")
return

def profiler_start_5ghz_unii3(self, g_vars):
self.profiler_ctl(g_vars, action="start_5ghz_unii3")
return

def profiler_start_no11r(self, g_vars):
self.profiler_ctl(g_vars, action="start_no11r")
return
Expand Down
4 changes: 4 additions & 0 deletions fpms/modules/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
# Uncomment the line below to force a display type
#DISPLAY_TYPE = DISPLAY_TYPE_ST7789

DISPLAY_ORIENTATION_NORMAL = "normal"
DISPLAY_ORIENTATION_FLIPPED = "flipped"

IMAGE_DIR = "images/128x128"
MAX_TABLE_LINES = 9
MAX_PAGE_LINES = 8
Expand Down Expand Up @@ -120,6 +123,7 @@
"key2": 20,
"key3": 16
}

# temp setup to test code using Sapphire HAT
# (center - middle front panel button, up/down = side wheel up/down)
BUTTONS_SAPPHIRE = {
Expand Down
15 changes: 13 additions & 2 deletions fpms/modules/wlanpi_oled.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,31 @@
# -*- coding: utf-8 -*-

import os
from fpms.modules.constants import DISPLAY_TYPE, DISPLAY_TYPE_ST7735
from PIL import Image

from fpms.modules.constants import (
DISPLAY_TYPE,
DISPLAY_TYPE_ST7735,
DISPLAY_ORIENTATION_FLIPPED,
DISPLAY_ORIENTATION_NORMAL
)
from fpms.modules.screen.st7735 import ST7735
from fpms.modules.screen.luma import Luma

# Initialize device based on the display type
device = ST7735() if DISPLAY_TYPE == DISPLAY_TYPE_ST7735 else Luma()
orientation = DISPLAY_ORIENTATION_NORMAL

# Initialize the device
def init():
device.init()

# Draw an image on the display
def drawImage(image):
device.drawImage(image)
if orientation == DISPLAY_ORIENTATION_FLIPPED:
device.drawImage(image.transpose(Image.Transpose.ROTATE_180))
else:
device.drawImage(image)

# Clear the display
def clear():
Expand Down

0 comments on commit 9aa9287

Please sign in to comment.