implement leds
This commit is contained in:
parent
c572956e27
commit
e5864eeec5
|
@ -13,5 +13,5 @@ class collision:
|
||||||
def collision_handle(self, data):
|
def collision_handle(self, data):
|
||||||
val = data[2]
|
val = data[2]
|
||||||
if val == 1:
|
if val == 1:
|
||||||
self.leds.flash(r=255,g=0,b=0,duration_ms=250)
|
self.leds.__flasher__(r=255,g=0,b=0,duration=250)
|
||||||
self.lcd.keke_hurt()
|
self.lcd.play_video("keke_hurt")
|
|
@ -18,14 +18,14 @@ class environment:
|
||||||
while True:
|
while True:
|
||||||
if self.sensors.get_temperature() > 38.0:
|
if self.sensors.get_temperature() > 38.0:
|
||||||
if not self.t_alerted:
|
if not self.t_alerted:
|
||||||
lcd.keke_died()
|
lcd.play_video("keke_died")
|
||||||
self.t_alerted = True
|
self.t_alerted = True
|
||||||
else:
|
else:
|
||||||
self.t_alerted = False
|
self.t_alerted = False
|
||||||
|
|
||||||
if self.sensors.get_humidity_pct() > 60.0:
|
if self.sensors.get_humidity_pct() > 60.0:
|
||||||
if not self.h_alerted:
|
if not self.h_alerted:
|
||||||
lcd.keke_cute_noise()
|
lcd.play_video("keke_cute_noise")
|
||||||
self.h_alerted = True
|
self.h_alerted = True
|
||||||
else:
|
else:
|
||||||
self.h_alerted = False
|
self.h_alerted = False
|
||||||
|
|
|
@ -4,21 +4,6 @@ class lcd:
|
||||||
self.nextion = kuukar_nextion.nextion()
|
self.nextion = kuukar_nextion.nextion()
|
||||||
self.nextion.send_command("page home")
|
self.nextion.send_command("page home")
|
||||||
|
|
||||||
def keke_uwu(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def keke_cute_noise(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def keke_hurt(self):
|
|
||||||
self.play_video("keke_hurt")
|
|
||||||
|
|
||||||
def keke_died(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def takina_noise(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def play_video(self,filename: str) -> None:
|
def play_video(self,filename: str) -> None:
|
||||||
self.nextion.send_command("page video_player")
|
self.nextion.send_command("page video_player")
|
||||||
self.nextion.send_command("video.path=\"sd0/"+filename+".video\"")
|
self.nextion.send_command("video.path=\"sd0/"+filename+".video\"")
|
||||||
|
|
|
@ -1,12 +1,37 @@
|
||||||
|
import threading
|
||||||
|
from time import perf_counter
|
||||||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||||
|
import time
|
||||||
from kuukar_config import LEDS_DATA_PIN, LEDS_NUM
|
from kuukar_config import LEDS_DATA_PIN, LEDS_NUM
|
||||||
|
|
||||||
|
|
||||||
class leds:
|
class leds:
|
||||||
|
flashing = False
|
||||||
|
start_time = perf_counter()
|
||||||
def __init__(self, aux_board: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
|
def __init__(self, aux_board: telemetrix_rpi_pico.TelemetrixRpiPico) -> None:
|
||||||
self.aux_board = aux_board
|
self.aux_board = aux_board
|
||||||
self.aux_board.set_pin_mode_neopixel(LEDS_DATA_PIN, LEDS_NUM)
|
self.aux_board.set_pin_mode_neopixel(LEDS_DATA_PIN, LEDS_NUM)
|
||||||
|
|
||||||
def flash(self, r: int, g: int, b: int, duration_ms: int):
|
def flash(self,r: int, g: int, b: int, duration: int):
|
||||||
pass
|
if not self.flashing:
|
||||||
|
self.flashing = True
|
||||||
|
self.start_time = perf_counter()
|
||||||
|
threading.Thread(target=self.__flasher__,args=(r,g,b,duration))
|
||||||
|
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __blink_func__(t: float,dur: float):
|
||||||
|
if t>dur:
|
||||||
|
return 0
|
||||||
|
return (-1/(dur/2.0)**2)*(t-dur/2.0)**2+1
|
||||||
|
|
||||||
|
def __get_time__(self) -> float:
|
||||||
|
return perf_counter()-self.start_time
|
||||||
|
|
||||||
|
def __flasher__(self, r: int, g: int, b: int, duration: int):
|
||||||
|
while True:
|
||||||
|
print(leds.__blink_func__(self.__get_time__(),duration))
|
||||||
|
time.sleep(0.05)
|
||||||
|
if self.__get_time__ > duration:
|
||||||
|
flashing = False
|
||||||
|
break
|
|
@ -28,7 +28,7 @@ class sensors:
|
||||||
def __sonar_callback__(self, data):
|
def __sonar_callback__(self, data):
|
||||||
pin = data[1]
|
pin = data[1]
|
||||||
distance = data[2]
|
distance = data[2]
|
||||||
sonar_id = self.sonar_pins.index(pin)
|
sonar_id = self.__sonar_trig_pins__.index(pin)
|
||||||
self.__sonar_distances__[sonar_id] = distance
|
self.__sonar_distances__[sonar_id] = distance
|
||||||
|
|
||||||
def get_temperature(self) -> float:
|
def get_temperature(self) -> float:
|
||||||
|
|
Loading…
Reference in New Issue