Class implementing a timer class. Takes an activation delay and sets a flag if the activation delay exprires.
| 4 | |
| 5 | |
| 6 | class Timer: |
| 7 | """Class implementing a timer class. Takes an activation delay and |
| 8 | sets a flag if the activation delay exprires.""" |
| 9 | |
| 10 | def __init__(self, activation_delay): |
| 11 | self.start_timestamp = int(time.time()) |
| 12 | self.activation_delay = activation_delay |
| 13 | self.enabled = False |
| 14 | |
| 15 | def check_timer(self): |
| 16 | """Checks the timer whether it has reached the activation delay.""" |
| 17 | current_timestamp = int(time.time()) |
| 18 | timestamp_diff = current_timestamp - self.start_timestamp |
| 19 | |
| 20 | if timestamp_diff >= self.activation_delay: |
| 21 | self.enabled = True |
| 22 | |
| 23 | def reset_timer(self): |
| 24 | """Resets the timer and starts from the beginning.""" |
| 25 | self.start_timestamp = int(time.time()) |
| 26 | self.enabled = False |