2022-10-25 07:49:19 +00:00
|
|
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
2022-11-09 16:06:52 +00:00
|
|
|
from kuukar.kuukar_config import COLLISION_DETECTOR_PIN, COLLISION_ENABLE
|
2022-11-04 04:58:20 +00:00
|
|
|
from kuukar.kuukar_lcd import lcd
|
|
|
|
from kuukar.kuukar_leds import leds
|
2022-11-11 14:39:14 +00:00
|
|
|
from time import perf_counter as pc
|
|
|
|
|
2022-10-22 12:39:10 +00:00
|
|
|
class collision:
|
2022-11-11 14:39:14 +00:00
|
|
|
lastCollision_ts = 0
|
2022-11-04 04:58:20 +00:00
|
|
|
def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, lcd: lcd, leds: leds) -> None:
|
|
|
|
self.mcu = mcu
|
2022-10-25 07:49:19 +00:00
|
|
|
self.lcd = lcd
|
|
|
|
self.leds = leds
|
2022-11-09 16:06:52 +00:00
|
|
|
if COLLISION_ENABLE:
|
|
|
|
self.mcu.set_pin_mode_digital_input(COLLISION_DETECTOR_PIN, self.collision_handle)
|
2022-10-25 07:49:19 +00:00
|
|
|
|
|
|
|
def collision_handle(self, data):
|
|
|
|
val = data[2]
|
2022-11-11 14:39:14 +00:00
|
|
|
if val == 1 and pc() - self.lastCollision_ts > 1.5:
|
|
|
|
self.lcd.play_video("keke_hurt")
|
|
|
|
self.lastCollision_ts = pc()
|