Timer refactor: stopwatch-like semantics, mcrfpy.timers collection closes #173
Major Timer API improvements: - Add `stopped` flag to Timer C++ class for proper state management - Add `start()` method to restart stopped timers (preserves callback) - Add `stop()` method that removes from engine but preserves callback - Make `active` property read-write (True=start/resume, False=pause) - Add `start=True` init parameter to create timers in stopped state - Add `mcrfpy.timers` module-level collection (tuple of active timers) - One-shot timers now set stopped=true instead of clearing callback - Remove deprecated `setTimer()` and `delTimer()` module functions Timer callbacks now receive (timer, runtime) instead of just (runtime). Updated all tests to use new Timer API and callback signature. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
fc95fc2844
commit
5d41292bf6
16 changed files with 440 additions and 262 deletions
|
|
@ -57,9 +57,7 @@ def test_on_move_fires():
|
|||
automation.moveTo(200, 200)
|
||||
automation.moveTo(250, 250)
|
||||
|
||||
def check_results(runtime):
|
||||
mcrfpy.delTimer("check_move")
|
||||
|
||||
def check_results(timer, runtime):
|
||||
if move_count[0] >= 2:
|
||||
print(f" - on_move fired {move_count[0]} times: PASS")
|
||||
print(f" Positions: {positions[:5]}...")
|
||||
|
|
@ -71,7 +69,7 @@ def test_on_move_fires():
|
|||
print("\n=== on_move basic tests passed! ===")
|
||||
sys.exit(0)
|
||||
|
||||
mcrfpy.setTimer("check_move", check_results, 200)
|
||||
mcrfpy.Timer("check_move", check_results, 200, once=True)
|
||||
|
||||
|
||||
def test_on_move_not_outside():
|
||||
|
|
@ -99,9 +97,7 @@ def test_on_move_not_outside():
|
|||
automation.moveTo(60, 60)
|
||||
automation.moveTo(70, 70)
|
||||
|
||||
def check_results(runtime):
|
||||
mcrfpy.delTimer("check_outside")
|
||||
|
||||
def check_results(timer, runtime):
|
||||
if move_count[0] == 0:
|
||||
print(" - No on_move outside bounds: PASS")
|
||||
# Chain to the firing test
|
||||
|
|
@ -110,7 +106,7 @@ def test_on_move_not_outside():
|
|||
print(f" - Unexpected {move_count[0]} move(s) outside bounds: FAIL")
|
||||
sys.exit(1)
|
||||
|
||||
mcrfpy.setTimer("check_outside", check_results, 200)
|
||||
mcrfpy.Timer("check_outside", check_results, 200, once=True)
|
||||
|
||||
|
||||
def test_all_types_have_on_move():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue