2022-07-20 15:35:56 +02:00
|
|
|
from supervisor import ticks_ms
|
|
|
|
|
|
|
|
|
2022-10-02 20:49:23 +02:00
|
|
|
def clamp(x: int, bottom: int = 0, top: int = 100) -> int:
|
2021-12-05 18:25:19 +01:00
|
|
|
return min(max(bottom, x), top)
|
2022-07-20 15:35:56 +02:00
|
|
|
|
|
|
|
|
|
|
|
_debug_enabled = False
|
|
|
|
|
|
|
|
|
|
|
|
class Debug:
|
|
|
|
'''default usage:
|
|
|
|
debug = Debug(__name__)
|
|
|
|
'''
|
|
|
|
|
2022-10-02 20:49:23 +02:00
|
|
|
def __init__(self, name: str = __name__):
|
2022-07-20 15:35:56 +02:00
|
|
|
self.name = name
|
|
|
|
|
2022-10-02 20:49:23 +02:00
|
|
|
def __call__(self, message: str) -> None:
|
2022-07-20 15:35:56 +02:00
|
|
|
print(f'{ticks_ms()} {self.name}: {message}')
|
|
|
|
|
|
|
|
@property
|
2022-10-02 20:49:23 +02:00
|
|
|
def enabled(self) -> bool:
|
2022-07-20 15:35:56 +02:00
|
|
|
global _debug_enabled
|
|
|
|
return _debug_enabled
|
|
|
|
|
|
|
|
@enabled.setter
|
2022-10-02 20:49:23 +02:00
|
|
|
def enabled(self, enabled: bool):
|
2022-07-20 15:35:56 +02:00
|
|
|
global _debug_enabled
|
|
|
|
_debug_enabled = enabled
|