even more typehints
This commit is contained in:
		@@ -6,26 +6,26 @@ _TICKS_MAX = const(_TICKS_PERIOD - 1)
 | 
			
		||||
_TICKS_HALFPERIOD = const(_TICKS_PERIOD // 2)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def ticks_diff(new, start):
 | 
			
		||||
def ticks_diff(new: int, start: int) -> int:
 | 
			
		||||
    diff = (new - start) & _TICKS_MAX
 | 
			
		||||
    diff = ((diff + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD
 | 
			
		||||
    return diff
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def ticks_add(ticks, delta):
 | 
			
		||||
def ticks_add(ticks: int, delta: int) -> int:
 | 
			
		||||
    return (ticks + delta) % _TICKS_PERIOD
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def check_deadline(new, start, ms):
 | 
			
		||||
def check_deadline(new: int, start: int, ms: int) -> int:
 | 
			
		||||
    return ticks_diff(new, start) < ms
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class PeriodicTimer:
 | 
			
		||||
    def __init__(self, period):
 | 
			
		||||
    def __init__(self, period: int):
 | 
			
		||||
        self.period = period
 | 
			
		||||
        self.last_tick = ticks_ms()
 | 
			
		||||
 | 
			
		||||
    def tick(self):
 | 
			
		||||
    def tick(self) -> bool:
 | 
			
		||||
        now = ticks_ms()
 | 
			
		||||
        if ticks_diff(now, self.last_tick) >= self.period:
 | 
			
		||||
            self.last_tick = now
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								kmk/utils.py
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								kmk/utils.py
									
									
									
									
									
								
							@@ -1,7 +1,7 @@
 | 
			
		||||
from supervisor import ticks_ms
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def clamp(x, bottom=0, top=100):
 | 
			
		||||
def clamp(x: int, bottom: int = 0, top: int = 100) -> int:
 | 
			
		||||
    return min(max(bottom, x), top)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -13,18 +13,18 @@ class Debug:
 | 
			
		||||
    debug = Debug(__name__)
 | 
			
		||||
    '''
 | 
			
		||||
 | 
			
		||||
    def __init__(self, name=__name__):
 | 
			
		||||
    def __init__(self, name: str = __name__):
 | 
			
		||||
        self.name = name
 | 
			
		||||
 | 
			
		||||
    def __call__(self, message):
 | 
			
		||||
    def __call__(self, message: str) -> None:
 | 
			
		||||
        print(f'{ticks_ms()} {self.name}: {message}')
 | 
			
		||||
 | 
			
		||||
    @property
 | 
			
		||||
    def enabled(self):
 | 
			
		||||
    def enabled(self) -> bool:
 | 
			
		||||
        global _debug_enabled
 | 
			
		||||
        return _debug_enabled
 | 
			
		||||
 | 
			
		||||
    @enabled.setter
 | 
			
		||||
    def enabled(self, enabled):
 | 
			
		||||
    def enabled(self, enabled: bool):
 | 
			
		||||
        global _debug_enabled
 | 
			
		||||
        _debug_enabled = enabled
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user