-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollover.py
114 lines (75 loc) · 3.02 KB
/
rollover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# -*- coding: utf-8 -*-
"""
Created on Mon Jan 13 15:42:56 2020
@author: Russ_2
This is a test of the rollover logic used in the arduino progrogram
there is also a spreadsheet for this
>>> f"{new_comedian}"
'Eric Idle is 74.'
>>> f"{new_comedian!r}"
'Eric Idle is 74. Surprise!'
You can use space around = as in f"{name =}" that will expand to f"name ={name}
"""
class RollOver(object):
def __init__(self):
"""
the wrong way to instance variables, java like but works
"""
self.current_clock = 0
self.next_event = 10
self.CLOCK_ROLLOVER = 4294967295
self.MAX_DELTA_T = 500000
self.MAX_TIME_AHEAD = 1000
self.ROLLOVER_AT = self.CLOCK_ROLLOVER - self.MAX_DELTA_T
self.just_to_be_sure = 100
self.ADJ_TIME = ( self.CLOCK_ROLLOVER - self.ROLLOVER_AT +
self.MAX_TIME_AHEAD + self.just_to_be_sure ) # 501100
def str_consts(self):
"""
"""
a_str = f"#define CLOCK_ROLLOVER = {self.CLOCK_ROLLOVER}"
a_str += f"\n#define MAX_DELTA_T = {self.MAX_DELTA_T}"
a_str += f"\n#define MAX_TIME_AHEAD = {self.MAX_TIME_AHEAD}"
a_str += f"\n#define ROLLOVER_AT = {self.ROLLOVER_AT}"
a_str += f"\n#define ADJ_TIME = {self.ADJ_TIME}"
return a_str
def print_consts(self):
"""
"""
print( self.str_consts() )
def str_vars(self):
"""
"""
a_str = f"self.current_clock = {self.current_clock}"
a_str += f"\nself.next_event = {self.next_event}"
a_str += f"\ndelta = {self.next_event - self.current_clock }"
# a_str += f"\nself.MAX_TIME_AHEAD = {self.MAX_TIME_AHEAD}"
# a_str += f"\nself.ROLLOVER_AT = {self.ROLLOVER_AT}"
# a_str += f"\nself.ADJ_TIME = {self.ADJ_TIME}"
return a_str
def adv_clock( self, delta_t ):
"""
"""
print( f"\n---------advance clock by {delta_t}")
self.current_clock += delta_t
if self.current_clock > self.ROLLOVER_AT :
print( ">>>rollover" )
self.current_clock = ( self.current_clock + self.ADJ_TIME ) % self.CLOCK_ROLLOVER
self.next_event = ( self.next_event + self.ADJ_TIME ) % self.CLOCK_ROLLOVER
msg = self.str_vars()
print( msg )
def steps( self, no_steps, delta_t, ):
"""
"""
for i in range(0, no_steps):
self.adv_clock( delta_t )
# seem to show logic and these constants work fine
a_rollover = RollOver()
a_rollover.print_consts()
print( a_rollover.str_vars() )
#a_rollover.next_event = a_rollover.current_clock + 500
a_rollover.current_clock = a_rollover.ROLLOVER_AT - 1000
a_rollover.next_event = a_rollover.current_clock + 500
print( a_rollover.str_vars() )
a_rollover.adv_clock( 200 )
a_rollover.steps( 11, 200 )