RASCSI/python/ctrlboard/src/menu/timer.py
nucleogenic 315ef9f248
Auto-format Python sources with black, fix all issues reported by flake8 (#1010)
* Update config for black and flake8
* Auto-format Python sources with black
* Fix issues reported by flake8
* Exclude protobuf files from black
* Address formatting feedback
2022-11-30 05:19:17 +00:00

26 lines
824 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