Files
IQ.Pilot/iqpilot/__init__.py
T
2026-07-11 09:58:33 -05:00

30 lines
1.0 KiB
Python

"""
Copyright © IQ.Lvbs, apart of Project Teal Lvbs, All Rights Reserved, licensed under https://konn3kt.com/tos
"""
import hashlib
from enum import IntEnum
# How often background loops refresh cached params, in seconds.
PARAMS_UPDATE_PERIOD = 3
def get_file_hash(path: str) -> str:
"""Hex SHA-256 of a file's contents."""
with open(path, "rb") as handle:
return hashlib.file_digest(handle, "sha256").hexdigest()
def get_sanitize_int_param(key: str, min_val: int, max_val: int, params) -> int:
"""Read an int param, clamp it into [min_val, max_val], and write the clamp back
if it moved so the stored value never drifts out of range."""
stored = params.get(key, return_default=True)
bounded = min(max(stored, min_val), max_val)
if bounded != stored:
params.put(key, bounded)
return bounded
# Speed-limit feature level (SpeedLimitMode param contract), ordered by authority.
_SLC_TIERS = ("off", "information", "warning", "control")
Mode = IntEnum("Mode", [(tier, rank) for rank, tier in enumerate(_SLC_TIERS)])