RASCSI/python/ctrlboard/src/menu/timer.py
Benjamin Zeiss cd0da558c3
Initial version of the Control Board UI (#687)
Initial version of the Control Board UI (#687)
2022-02-25 21:03:36 +01:00

25 lines
823 B
Python

"""Module providing a timer class"""
import time
class Timer:
"""Class implementing a timer class. Takes an activation delay and
sets a flag if the activation delay exprires."""
def __init__(self, activation_delay):
self.start_timestamp = int(time.time())
self.activation_delay = activation_delay
self.enabled = False
def check_timer(self):
"""Checks the timer whether it has reached the activation delay."""
current_timestamp = int(time.time())
timestamp_diff = current_timestamp - self.start_timestamp
if timestamp_diff >= self.activation_delay:
self.enabled = True
def reset_timer(self):
"""Resets the timer and starts from the beginning."""
self.start_timestamp = int(time.time())
self.enabled = False