Skip to content

Commit

Permalink
Improved look and feel
Browse files Browse the repository at this point in the history
Improved type hints
Added copyright notices
  • Loading branch information
Lawstorant committed Oct 7, 2024
1 parent 77e9f37 commit 8794308
Show file tree
Hide file tree
Showing 13 changed files with 93 additions and 154 deletions.
2 changes: 1 addition & 1 deletion boxflat/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, data_path: str, config_path: str, dry_run: bool, custom: bool
with open(os.path.join(data_path, "version"), "r") as version:
self._version = version.readline().strip()

self._panels = {}
self._panels: dict[str, SettingsPanel] = {}
self._dry_run = dry_run

self.set_default_size(0, 850)
Expand Down
4 changes: 2 additions & 2 deletions boxflat/hid_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def add_device(self, pattern: MozaHidDevice):

for hid in devices:
if re.search(pattern, hid.name.lower()):
print(f"HID device found: " + hid.name)
print(f"HID device found: {hid.name}")
device = hid

if device is not None:
Expand Down Expand Up @@ -228,7 +228,7 @@ def _notify_button(self, number: int, state: int):
number -= KEY_NEXT_FAVORITE - (BTN_DEAD - BTN_JOYSTICK) - 2

#print(f"button {number}, state: {state}")
self._dispatch("button-" + str(number), state)
self._dispatch(f"button-{number}", state)


def _hid_read_loop(self, device: evdev.InputDevice):
Expand Down
25 changes: 14 additions & 11 deletions boxflat/panels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,6 @@ def prepare_ui(self):

# Basic settings
self.add_preferences_group("Basic settings")
self._sensitivity_row = BoxflatSliderRow("Road Sensitivity", range_end=10)
self._add_row(self._sensitivity_row)
self._current_row.add_marks(2, 4, 6, 8)
self._current_row.set_expression("*4 + 10")
self._current_row.set_reverse_expression("/4 - 2.5")
self._current_row.subscribe(self._cm.set_setting, "base-road-sensitivity")
self._current_row.subscribe(self._set_eq_preset, True)
self._cm.subscribe("base-road-sensitivity", self._current_row.set_value)

self._add_row(BoxflatSliderRow("Maximum Wheel Speed", suffix="%", range_end=200))
self._current_row.add_marks(50, 100, 150)
self._current_row.set_expression("*10")
Expand Down Expand Up @@ -236,7 +227,7 @@ def prepare_ui(self):
def __prepare_eq(self):
self.add_preferences_page("Equalizer", "network-cellular-signal-excellent-symbolic")

self.add_preferences_group("Equalizer")
self.add_preferences_group()
self._eq_row = BoxflatEqRow("FFB Equalizer", 6,
subtitle="Perfectly balanced, as all things should be", range_end=400, suffix="%", button_row=False)
self._add_row(self._eq_row)
Expand All @@ -247,15 +238,27 @@ def __prepare_eq(self):
self._eq_row.subscribe_slider(i, self._cm.set_setting, f"base-equalizer{i+1}")
self._cm.subscribe(f"base-equalizer{i+1}", self._eq_row.set_slider_value, i)

self.add_preferences_group()
self._sensitivity_row = BoxflatSliderRow("Road Sensitivity", range_end=10)
self._add_row(self._sensitivity_row)
self._sensitivity_row.add_marks(2, 4, 6, 8)
self._sensitivity_row.set_expression("*4 + 10")
self._sensitivity_row.set_reverse_expression("/4 - 2.5")
self._sensitivity_row.set_slider_width(350)
self._sensitivity_row.subscribe(self._cm.set_setting, "base-road-sensitivity")
self._sensitivity_row.subscribe(self._set_eq_preset, True)
self._cm.subscribe("base-road-sensitivity", self._sensitivity_row.set_value)


def __prepare_curve(self):
self.add_preferences_page("Curve", "network-cellular-signal-excellent-symbolic")

self.add_preferences_group("Base FFB Curve")
self.add_preferences_group()
self._curve_row = BoxflatEqRow("FFB Curve", 5, subtitle="Game FFB to Output FFB ratio", suffix="%")
self._add_row(self._curve_row)
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.add_labels("20%", "40%", "60%", "80%", "100%")
self._current_row.set_height(320)

self._current_row.add_buttons("Linear", "S Curve", "Inverted S", "Exponential", "Parabolic")
self._current_row.set_button_value(-1)
Expand Down
2 changes: 1 addition & 1 deletion boxflat/panels/h_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def prepare_ui(self):
self._current_row.add_marks(250, 500, 750)
self._current_row.set_active(False)

self.add_preferences_group("Calibration")
self.add_preferences_group()
self._add_row(BoxflatCalibrationRow("Device Calibration", "Shift into R > 7th > R > Neutral"))
self._current_row.subscribe("calibration-start", self._cm.set_setting, "hpattern-calibration-start")
self._current_row.subscribe("calibration-stop", self._cm.set_setting, "hpattern-calibration-stop")
9 changes: 5 additions & 4 deletions boxflat/panels/handbrake.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,24 @@ def prepare_ui(self):
self._cm.subscribe("handbrake-button-threshold", self._current_row.set_value)
self._current_row.set_active(False)

self.add_preferences_group("Range settings", level_bar=1)
self.add_preferences_group("Handbrake Curve", level_bar=1)
self._current_group.set_bar_max(65535)
self._hid_handler.subscribe(MozaAxis.HANDBRAKE.name, self._current_group.set_bar_level)

self._curve_row = BoxflatEqRow("Output Curve", 5, suffix="%")
self._curve_row = BoxflatEqRow("", 5, suffix="%")
self._add_row(self._curve_row)
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.add_labels("20%", "40%", "60%", "80%", "100%")
self._current_row.set_height(260)
self._current_row.add_buttons("Linear", "S Curve", "Exponential", "Parabolic")
self._current_row.set_button_value(-1)
self._current_row.set_height(280)
self._current_row.subscribe(self._set_curve_preset)
for i in range(5):
self._curve_row.subscribe_slider(i, self._set_curve_point, i)
self._cm.subscribe(f"handbrake-y{i+1}", self._get_curve, i)


self.add_preferences_group("Handbrake Range")
self._add_row(BoxflatSliderRow("Range Start", suffix="%"))
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.set_slider_width(380)
Expand All @@ -71,7 +72,7 @@ def prepare_ui(self):
self._current_row.subscribe(self._cm.set_setting, "handbrake-max")
self._cm.subscribe("handbrake-max", self._current_row.set_value)

self.add_preferences_group("Calibration")
self.add_preferences_group()
self._add_row(BoxflatCalibrationRow("Handbrake Calibration", "Pull handbrake fully once"))
self._current_row.subscribe("calibration-start", self._cm.set_setting, "handbrake-calibration-start")
self._current_row.subscribe("calibration-stop", self._cm.set_setting, "handbrake-calibration-stop")
Expand Down
8 changes: 4 additions & 4 deletions boxflat/panels/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ def prepare_ui(self):
self.add_preferences_group("Pedals")
self._cm.subscribe_connected("pedals-throttle-dir", self._current_group.set_active, 1)

self._add_row(BoxflatMinMaxLevelRow("Throttle input", self._set_limit, "pedals-throttle", max_value=65534))
self._add_row(BoxflatMinMaxLevelRow("Throttle input", self._set_limit, "pedals-throttle", max_value=65_534))
self._hid_handler.subscribe(MozaAxis.THROTTLE.name, self._current_row.set_value)
self._cm.subscribe_connected("pedals-throttle-dir", self._current_row.set_active, 1)

self._add_row(BoxflatMinMaxLevelRow("Brake input", self._set_limit, "pedals-brake", max_value=65534))
self._add_row(BoxflatMinMaxLevelRow("Brake input", self._set_limit, "pedals-brake", max_value=65_534))
self._hid_handler.subscribe(MozaAxis.BRAKE.name, self._current_row.set_value)
self._cm.subscribe_connected("pedals-throttle-dir", self._current_row.set_active, 1)

self._add_row(BoxflatMinMaxLevelRow("Clutch input", self._set_limit, "pedals-clutch", max_value=65534))
self._add_row(BoxflatMinMaxLevelRow("Clutch input", self._set_limit, "pedals-clutch", max_value=65_534))
self._hid_handler.subscribe(MozaAxis.CLUTCH.name, self._current_row.set_value)
self._cm.subscribe_connected("pedals-throttle-dir", self._current_row.set_active, 1)

self.add_preferences_group("Handbrake")
self._add_row(BoxflatMinMaxLevelRow("Input", self._set_limit, "handbrake", max_value=65534))
self._add_row(BoxflatMinMaxLevelRow("Input", self._set_limit, "handbrake", max_value=65_534))
self._hid_handler.subscribe(MozaAxis.HANDBRAKE.name, self._current_row.set_value)
self._cm.subscribe_connected("handbrake-direction", self._current_group.set_present, 1)
self._current_group.set_present(False)
Expand Down
158 changes: 41 additions & 117 deletions boxflat/panels/pedals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
from boxflat.panels.settings_panel import SettingsPanel
from boxflat.connection_manager import MozaConnectionManager
from boxflat.widgets import *
from boxflat.hid_handler import MozaAxis
from boxflat.hid_handler import MozaAxis, AxisData

class PedalsSettings(SettingsPanel):
def __init__(self, button_callback, connection_manager: MozaConnectionManager, hid_handler):
self._brake_calibration_row = None
self._curve_rows = []
self._curve_rows: dict[str, BoxflatEqRow] = {}

self._presets = [
[20, 40, 60, 80, 100], # Linear
Expand All @@ -17,146 +17,69 @@ def __init__(self, button_callback, connection_manager: MozaConnectionManager, h
[46, 72, 86, 94, 100] # Parabolic
]

self._pedals = [
"throttle",
"brake",
"clutch"
]

super().__init__("Pedals", button_callback, connection_manager, hid_handler)
self._cm.subscribe_connected("pedals-throttle-dir", self.active)


def set_brake_calibration_active(self, active: bool):
def set_brake_calibration_active(self, active: int):
self._brake_calibration_row.set_active(active)


def prepare_ui(self):
self.add_view_stack()
for pedal in [MozaAxis.THROTTLE, MozaAxis.BRAKE, MozaAxis.CLUTCH]:
self._prepare_pedal(pedal)

# Throttle
self.add_preferences_page("Throttle")
self.add_preferences_group("Throttle settings", level_bar=1)
self._current_group.set_bar_max(65534)
self._hid_handler.subscribe(MozaAxis.THROTTLE.name, self._current_group.set_bar_level)

self._curve_rows.append(BoxflatEqRow("Throttle Curve", 5, suffix="%"))
self._add_row(self._curve_rows[0])
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.add_labels("20%", "40%", "60%", "80%", "100%")
self._current_row.set_height(260)
self._current_row.add_buttons("Linear", "S Curve", "Exponential", "Parabolic")
# self._current_row.set_button_value(-1)
self._current_row.subscribe(self._set_curve_preset, "throttle")
for i in range(5):
self._curve_rows[0].subscribe_slider(i, self._set_curve_point, i, "throttle")
self._cm.subscribe(f"pedals-throttle-y{i+1}", self._get_curve, i, "throttle")
def _prepare_pedal(self, pedal: AxisData):
self.add_preferences_page(pedal.name.title())
self.add_preferences_group(f"{pedal.name.title()} Curve", level_bar=1)
self._current_group.set_bar_max(65_534)
self._hid_handler.subscribe(pedal.name, self._current_group.set_bar_level)

self._add_row(BoxflatSliderRow("Range Start", suffix="%"))
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.set_slider_width(380)
self._current_row.subscribe(self._cm.set_setting, "pedals-throttle-min")
self._cm.subscribe("pedals-throttle-min", self._current_row.set_value)

self._add_row(BoxflatSliderRow("Range End", suffix="%"))
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.set_slider_width(380)
self._current_row.subscribe(self._cm.set_setting, "pedals-throttle-max")
self._cm.subscribe("pedals-throttle-max", self._current_row.set_value)

self.add_preferences_group("Misc")
self._add_row(BoxflatSwitchRow("Reverse Direction"))
self._current_row.subscribe(self._cm.set_setting, "pedals-throttle-dir")
self._cm.subscribe("pedals-throttle-dir", self._current_row.set_value)

self._add_row(BoxflatCalibrationRow("Calibration", "Fully depress throttle once"))
self._current_row.subscribe("calibration-start", self._cm.set_setting, "pedals-throttle-calibration-start", True)
self._current_row.subscribe("calibration-stop", self._cm.set_setting, "pedals-throttle-calibration-stop", True)

# Brake
self.add_preferences_page("Brake")
self.add_preferences_group("Brake settings", level_bar=1)
self._current_group.set_bar_max(65534)
self._hid_handler.subscribe(MozaAxis.BRAKE.name, self._current_group.set_bar_level)

self._curve_rows.append(BoxflatEqRow("Brake Curve", 5, suffix="%"))
self._add_row(self._curve_rows[1])
self._curve_rows[pedal.name] = BoxflatEqRow("", 5, suffix="%")
self._add_row(self._curve_rows[pedal.name])
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.add_labels("20%", "40%", "60%", "80%", "100%")
self._current_row.set_height(260)
self._current_row.set_height(280)
self._current_row.add_buttons("Linear", "S Curve", "Exponential", "Parabolic")
# self._current_row.set_button_value(-1)
self._current_row.subscribe(self._set_curve_preset, "brake")
self._curve_rows[pedal.name].set_height(290)
self._current_row.subscribe(self._set_curve_preset, pedal.name)
for i in range(5):
self._curve_rows[1].subscribe_slider(i, self._set_curve_point, i, "brake")
self._cm.subscribe(f"pedals-brake-y{i+1}", self._get_curve, i, "brake")
self._curve_rows[pedal.name].subscribe_slider(i, self._set_curve_point, i, pedal.name)
self._cm.subscribe(f"pedals-{pedal.name}-y{i+1}", self._get_curve, i, pedal.name)

self.add_preferences_group(f"{pedal.name.title()} Range")
self._add_row(BoxflatSliderRow("Range Start", suffix="%"))
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.set_slider_width(380)
self._current_row.subscribe(self._cm.set_setting, "pedals-brake-min")
self._cm.subscribe("pedals-brake-min", self._current_row.set_value)
self._current_row.subscribe(self._cm.set_setting, f"pedals-{pedal.name}-min")
self._cm.subscribe(f"pedals-{pedal.name}-min", self._current_row.set_value)

self._add_row(BoxflatSliderRow("Range End", suffix="%"))
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.set_slider_width(380)
self._current_row.subscribe(self._cm.set_setting, "pedals-brake-max")
self._cm.subscribe("pedals-brake-max", self._current_row.set_value)

self._add_row(BoxflatSliderRow("Sensor ratio", suffix="%", subtitle="0% = Only Angle Sensor\n100% = Only Load Cell"))
self._current_row.add_marks(25, 50, 75)
self._current_row.subscribe(self._cm.set_setting, "pedals-brake-angle-ratio")
self._cm.subscribe("pedals-brake-angle-ratio", self._current_row.set_value)

self.add_preferences_group("Misc")
self._add_row(BoxflatSwitchRow("Reverse Direction"))
self._current_row.subscribe(self._cm.set_setting, "pedals-brake-dir")
self._cm.subscribe("pedals-brake-dir", self._current_row.set_value)

self._brake_calibration_row = BoxflatCalibrationRow("Calibration", "Fully depress brake once")
self._add_row(self._brake_calibration_row)
self._current_row.subscribe("calibration-start", self._cm.set_setting, "pedals-throttle-brake-start", True)
self._current_row.subscribe("calibration-stop", self._cm.set_setting, "pedals-throttle-brake-stop", True)
self._current_row.set_active(False)

# Clutch
self.add_preferences_page("Clutch")
self.add_preferences_group("Clutch settings", level_bar=1)
self._current_group.set_bar_max(65534)
self._hid_handler.subscribe(MozaAxis.CLUTCH.name, self._current_group.set_bar_level)

self._curve_rows.append(BoxflatEqRow("Clutch Curve", 5, suffix="%"))
self._add_row(self._curve_rows[2])
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.add_labels("20%", "40%", "60%", "80%", "100%")
self._current_row.set_height(260)
self._current_row.add_buttons("Linear", "S Curve", "Exponential", "Parabolic")
# self._current_row.set_button_value(-1)
self._current_row.subscribe(self._set_curve_preset, "clutch")
for i in range(5):
self._curve_rows[2].subscribe_slider(i, self._set_curve_point, i, "clutch")
self._cm.subscribe(f"pedals-clutch-y{i+1}", self._get_curve, i, "clutch")

self._add_row(BoxflatSliderRow("Range Start", suffix="%"))
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.set_slider_width(380)
self._current_row.subscribe(self._cm.set_setting, "pedals-clutch-min")
self._cm.subscribe("pedals-clutch-min", self._current_row.set_value)
self._current_row.subscribe(self._cm.set_setting, f"pedals-{pedal.name}-max")
self._cm.subscribe(f"pedals-{pedal.name}-max", self._current_row.set_value)

self._add_row(BoxflatSliderRow("Range End", suffix="%"))
self._current_row.add_marks(20, 40, 60, 80)
self._current_row.set_slider_width(380)
self._current_row.subscribe(self._cm.set_setting, "pedals-clutch-max")
self._cm.subscribe("pedals-clutch-max", self._current_row.set_value)
if pedal == MozaAxis.BRAKE:
self._add_row(BoxflatSliderRow("Sensor ratio", suffix="%", subtitle="0% = Only Angle Sensor\n100% = Only Load Cell"))
self._current_row.add_marks(25, 50, 75)
self._current_row.subscribe(self._cm.set_setting, "pedals-brake-angle-ratio")
self._cm.subscribe("pedals-brake-angle-ratio", self._current_row.set_value)

self.add_preferences_group("Misc")
self._add_row(BoxflatSwitchRow("Reverse Direction"))
self._current_row.subscribe(self._cm.set_setting, "pedals-clutch-dir")
self._cm.subscribe("pedals-clutch-dir", self._current_row.set_value)
self._current_row.subscribe(self._cm.set_setting, f"pedals-{pedal.name}-dir")
self._cm.subscribe(f"pedals-{pedal.name}-dir", self._current_row.set_value)

self._add_row(BoxflatCalibrationRow("Calibration", "Fully depress clutch once"))
self._current_row.subscribe("calibration-start", self._cm.set_setting, "pedals-clutch-calibration-start", True)
self._current_row.subscribe("calibration-stop", self._cm.set_setting, "pedals-clutch-calibration-stop", True)
self._add_row(BoxflatCalibrationRow("Calibration", f"Fully depress {pedal.name} once"))
self._current_row.subscribe("calibration-start", self._cm.set_setting, f"pedals-{pedal.name}-calibration-start", True)
self._current_row.subscribe("calibration-stop", self._cm.set_setting, f"pedals-{pedal.name}-calibration-stop", True)
if pedal == MozaAxis.BRAKE:
self._brake_calibration_row = self._current_row
self._current_row.set_active(False)


def _set_curve_preset(self, value: int, pedal: str):
Expand All @@ -168,17 +91,18 @@ def _set_curve_point(self, value: int, index: int, pedal: str):


def _set_curve(self, values: list, pedal: str):
self._curve_rows[self._pedals.index(pedal)].set_sliders_value(values, mute=False)
self._curve_rows[pedal].set_sliders_value(values, mute=False)


def _get_curve(self, value: int, sindex: int, pedal: str):
index = -1
pi = self._pedals.index(pedal)
values = self._curve_rows[pi].get_sliders_value()
row = self._curve_rows[pedal]

values = row.get_sliders_value()
values[sindex] = value

if values in self._presets:
index = self._presets.index(values)

self._curve_rows[pi].set_button_value(index)
self._curve_rows[pi].set_slider_value(value, sindex)
row.set_button_value(index)
row.set_slider_value(value, sindex)
Loading

0 comments on commit 8794308

Please sign in to comment.