Skip to content

Commit

Permalink
Prevent calibrating when 'actual' fields have a value of 0 (#103)
Browse files Browse the repository at this point in the history
Implement missing gen5 calibration logic
  • Loading branch information
DasAmpharos authored Apr 20, 2024
1 parent e376f5b commit dc44f71
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 43 deletions.
10 changes: 5 additions & 5 deletions eon_timer/timers/gen3/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from eon_timer.util.enum import EnhancedEnum
from eon_timer.util.injector import component
from eon_timer.util.properties.property import Property
from eon_timer.util.properties.property import Property, IntProperty
from eon_timer.util.properties.settings import Settings


Expand All @@ -15,10 +15,10 @@ class Gen3Mode(EnhancedEnum, StrEnum):
@component()
class Gen3Model(Settings):
mode = Property(Gen3Mode.STANDARD, value_type=str)
pre_timer = Property(5000)
target_frame = Property(1000)
calibration = Property(0)
frame_hit = Property(0, transient=True)
pre_timer = IntProperty(5000)
target_frame = IntProperty(1000)
calibration = IntProperty(0)
frame_hit = IntProperty(0, transient=True)

@property
@override
Expand Down
15 changes: 7 additions & 8 deletions eon_timer/timers/gen3/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import QGroupBox, QPushButton, QSizePolicy, QSpinBox

from eon_timer.app_state import AppState
from eon_timer.timers import FrameTimer
from eon_timer.util import const, pyside
from eon_timer.util.injector import component
Expand Down Expand Up @@ -109,13 +108,13 @@ def create_phases(self) -> list[int]:
)

def calibrate(self):
calibration = self.model.calibration.get()
offset = self.frame_timer.calibrate(
self.model.target_frame.get(),
self.model.frame_hit.get()
)
self.model.calibration.set(calibration + offset)
self.model.frame_hit.set(0)
if self.model.frame_hit.get() > 0:
offset = self.frame_timer.calibrate(
self.model.target_frame.get(),
self.model.frame_hit.get()
)
self.model.calibration.add(offset)
self.model.frame_hit.set(0)

def __on_mode_changed(self, event: PropertyChangeEvent[Gen3Mode]) -> None:
self.set_visible(self.Field.SET_TARGET_FRAME,
Expand Down
12 changes: 6 additions & 6 deletions eon_timer/timers/gen4/model.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from typing import override

from eon_timer.util.injector import component
from eon_timer.util.properties.property import Property
from eon_timer.util.properties.property import IntProperty
from eon_timer.util.properties.settings import Settings


@component()
class Gen4Model(Settings):
target_delay = Property(600)
target_second = Property(50)
calibrated_delay = Property(500)
calibrated_second = Property(14)
delay_hit = Property(0, transient=True)
target_delay = IntProperty(600)
target_second = IntProperty(50)
calibrated_delay = IntProperty(500)
calibrated_second = IntProperty(14)
delay_hit = IntProperty(0, transient=True)

@property
@override
Expand Down
17 changes: 8 additions & 9 deletions eon_timer/timers/gen4/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import QGroupBox, QSizePolicy, QSpinBox

from eon_timer.app_state import AppState
from eon_timer.timers import Calibrator, DelayTimer
from eon_timer.util import const, pyside
from eon_timer.util.injector import component
Expand Down Expand Up @@ -102,15 +101,15 @@ def create_phases(self) -> list[int]:
)

def calibrate(self):
calibration = self.calibrator.to_delays(
self.delay_timer.calibrate(
self.model.target_delay.get(),
self.model.delay_hit.get()
if self.model.delay_hit.get() > 0:
calibration = self.calibrator.to_delays(
self.delay_timer.calibrate(
self.model.target_delay.get(),
self.model.delay_hit.get()
)
)
)
calibrated_delay = self.model.calibrated_delay.get() + calibration
self.model.calibrated_delay.set(calibrated_delay)
self.model.delay_hit.set(0)
self.model.calibrated_delay.add(calibration)
self.model.delay_hit.set(0)

def get_calibration(self) -> int:
return self.calibrator.create_calibration(
Expand Down
20 changes: 10 additions & 10 deletions eon_timer/timers/gen5/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from eon_timer.util.enum import EnhancedEnum
from eon_timer.util.injector import component
from eon_timer.util.properties.property import Property
from eon_timer.util.properties.property import Property, IntProperty
from eon_timer.util.properties.settings import Settings


Expand All @@ -17,15 +17,15 @@ class Gen5Mode(EnhancedEnum, StrEnum):
@component()
class Gen5Model(Settings):
mode = Property(Gen5Mode.STANDARD, value_type=str)
calibration = Property(-95)
frame_calibration = Property(0)
entralink_calibration = Property(256)
target_delay = Property(1200)
target_second = Property(50)
target_advances = Property(100)
delay_hit = Property(0, transient=True)
second_hit = Property(0, transient=True)
advances_hit = Property(0, transient=True)
calibration = IntProperty(-95)
frame_calibration = IntProperty(0)
entralink_calibration = IntProperty(256)
target_delay = IntProperty(1200)
target_second = IntProperty(50)
target_advances = IntProperty(100)
delay_hit = IntProperty(0, transient=True)
second_hit = IntProperty(0, transient=True)
advances_hit = IntProperty(0, transient=True)

@property
@override
Expand Down
62 changes: 57 additions & 5 deletions eon_timer/timers/gen5/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from PySide6.QtCore import Qt, Signal
from PySide6.QtWidgets import QSizePolicy, QSpinBox, QGroupBox

from eon_timer.app_state import AppState
from eon_timer.timers import Calibrator, DelayTimer, SecondTimer, EntralinkTimer, EnhancedEntralinkTimer
from eon_timer.util import const, pyside
from eon_timer.util.injector import component
from eon_timer.util.properties import bindings
from eon_timer.util.properties.property_change import PropertyChangeEvent
from eon_timer.util.pyside import EnumComboBox, ScrollWidget
from eon_timer.util.pyside import EnumComboBox
from eon_timer.util.pyside.form import FormWidget, FormLayout
from .model import Gen5Model, Gen5Mode
from eon_timer.timers import Calibrator, DelayTimer, SecondTimer, EntralinkTimer, EnhancedEntralinkTimer


@component()
Expand All @@ -36,15 +35,13 @@ class Field(FormWidget.Field):
timer_changed: Final[Signal] = Signal()

def __init__(self,
state: AppState,
model: Gen5Model,
calibrator: Calibrator,
delay_timer: DelayTimer,
second_timer: SecondTimer,
entralink_timer: EntralinkTimer,
enhanced_entralink_timer: EnhancedEntralinkTimer) -> None:
super().__init__(None)
self.state: Final[AppState] = state
self.model: Final[Gen5Model] = model
self.calibrator: Final[Calibrator] = calibrator
self.delay_timer: Final[DelayTimer] = delay_timer
Expand Down Expand Up @@ -174,3 +171,58 @@ def create_phases(self) -> list[int]:
self.model.entralink_calibration.get(),
self.model.frame_calibration.get()
)

def calibrate(self):
if self.model.delay_hit.get() > 0:
mode = self.model.mode.get()
match mode:
case Gen5Mode.STANDARD:
self.model.calibration.add(self.calibrator.calibrate_to_delays(self.second_calibration))
case Gen5Mode.C_GEAR:
self.model.calibration.add(self.calibrator.calibrate_to_delays(self.delay_calibration))
case (Gen5Mode.ENTRALINK,
Gen5Mode.ENTRALINK_PLUS):
self.model.calibration.add(self.calibrator.calibrate_to_delays(self.second_calibration))
self.model.entralink_calibration.add(
self.calibrator.calibrate_to_delays(self.entralink_calibration)
)
if mode == Gen5Mode.ENTRALINK_PLUS:
self.model.frame_calibration.add(self.advances_calibration)

self.model.delay_hit.set(0)
self.model.second_hit.set(0)
self.model.advances_hit.set(0)

def __can_calibrate(self) -> bool:
match self.model.mode.get():
case Gen5Mode.STANDARD:
return self.model.second_hit.get() > 0
case Gen5Mode.C_GEAR:
return self.model.delay_hit.get() > 0
case Gen5Mode.ENTRALINK:
return (self.model.delay_hit.get() > 0 and
self.model.second_hit.get() > 0)
case Gen5Mode.ENTRALINK_PLUS:
return (self.model.delay_hit.get() > 0 and
self.model.second_hit.get() > 0 and
self.model.advances_hit.get() > 0)

@property
def delay_calibration(self) -> int:
return self.delay_timer.calibrate(self.model.target_delay.get(),
self.model.delay_hit.get())

@property
def second_calibration(self) -> int:
return self.second_timer.calibrate(self.model.target_second.get(),
self.model.second_hit.get())

@property
def entralink_calibration(self) -> int:
return self.entralink_timer.calibrate(self.model.target_delay.get(),
self.model.delay_hit.get() - self.second_calibration)

@property
def advances_calibration(self) -> int:
return self.enhanced_entralink_timer.calibrate(self.model.target_advances.get(),
self.model.advances_hit.get())
17 changes: 17 additions & 0 deletions eon_timer/util/properties/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,20 @@ def set(self, new_value: T) -> None:
@property
def transient(self) -> bool:
return self.__transient


class IntProperty(Property[int]):
def __init__(self, initial_value: int | None = None, transient: bool = False):
super().__init__(initial_value, int, transient)

def add(self, value: int):
self.set(self.get() + value)

def sub(self, value: int):
self.set(self.get() - value)

def mul(self, value: int):
self.set(self.get() * value)

def div(self, value: int):
self.set(int(self.get() / value))

0 comments on commit dc44f71

Please sign in to comment.