From 7e9da402a670b413d35925eacd58cbf5ea212b3b Mon Sep 17 00:00:00 2001 From: Siwat Sirichai Date: Thu, 8 Dec 2022 20:07:29 +0700 Subject: [PATCH] edit structure --- app.py | 46 ++++++++++++++++++++++------------------ kuukar/kuukar.py | 18 ++++++++++------ kuukar/kuukar_sensors.py | 5 +++-- 3 files changed, 40 insertions(+), 29 deletions(-) diff --git a/app.py b/app.py index 3395906..8f463ca 100644 --- a/app.py +++ b/app.py @@ -1,28 +1,32 @@ import time -from telemetrix_rpi_pico import telemetrix_rpi_pico -import kuukar.kuukar_leds as kuukar_leds -import kuukar.kuukar_collision as kuukar_collision -import kuukar.kuukar_motion as kuukar_motion -import kuukar.kuukar_lcd as kuukar_lcd -import kuukar.kuukar_sensors as kuukar_sensors -import kuukar.kuukar_environment as kuukar_environment +# from telemetrix_rpi_pico import telemetrix_rpi_pico +# import kuukar.kuukar_leds as kuukar_leds +# import kuukar.kuukar_collision as kuukar_collision +# import kuukar.kuukar_motion as kuukar_motion +# import kuukar.kuukar_lcd as kuukar_lcd +# import kuukar.kuukar_sensors as kuukar_sensors +# import kuukar.kuukar_environment as kuukar_environment -from kuukar.kuukar_config import SERIAL_MCU, SERIAL_DRV +# from kuukar.kuukar_config import SERIAL_MCU, SERIAL_DRV -mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_MCU, sleep_tune=0.001) -drv = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_DRV, sleep_tune=0.001) -sensors = kuukar_sensors.sensors(mcu) -leds = kuukar_leds.leds(mcu) -motion = kuukar_motion.motion(mcu, drv, leds, sensors) -lcd = kuukar_lcd.lcd(motion, sensors) -environment = kuukar_environment.environment(lcd, leds, sensors) -collision = kuukar_collision.collision(mcu, lcd, leds) +from kuukar.kuukar import kuukar + +# mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_MCU, sleep_tune=0.001) +# drv = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_DRV, sleep_tune=0.001) +# sensors = kuukar_sensors.sensors(mcu) +# leds = kuukar_leds.leds(mcu) +# motion = kuukar_motion.motion(mcu, drv, leds, sensors) +# lcd = kuukar_lcd.lcd(motion, sensors) +# environment = kuukar_environment.environment(lcd, leds, sensors) +# collision = kuukar_collision.collision(mcu, lcd, leds) + +car = kuukar() while True: - temp = sensors.get_temperature() - humid = sensors.get_humidity_pct() - dist1 = sensors.sonar_get_distance(0) - dist2 = sensors.sonar_get_distance(1) - dist3 = sensors.sonar_get_distance(2) + temp = car.sensors.get_temperature() + humid = car.sensors.get_humidity_pct() + dist1 = car.sensors.sonar_get_distance(0) + dist2 = car.sensors.sonar_get_distance(1) + dist3 = car.sensors.sonar_get_distance(2) print(f'temp: {temp}, humidity: {humid}, dist1: {dist1}, dist2: {dist2}, dist3: {dist3}') time.sleep(1) diff --git a/kuukar/kuukar.py b/kuukar/kuukar.py index 38212c5..cf294c7 100644 --- a/kuukar/kuukar.py +++ b/kuukar/kuukar.py @@ -7,13 +7,19 @@ import kuukar.kuukar_sensors as kuukar_sensors import kuukar.kuukar_environment as kuukar_environment from kuukar.kuukar_config import SERIAL_MCU, SERIAL_DRV + class kuukar: def __init__(self) -> None: - self.mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_MCU, sleep_tune=0.001) - self.drv = telemetrix_rpi_pico.TelemetrixRpiPico(com_port=SERIAL_DRV, sleep_tune=0.001) - self.sensors = kuukar_sensors.sensors(self.mcu) + self.mcu = telemetrix_rpi_pico.TelemetrixRpiPico( + com_port=SERIAL_MCU, sleep_tune=0.001) + self.drv = telemetrix_rpi_pico.TelemetrixRpiPico( + com_port=SERIAL_DRV, sleep_tune=0.001) + self.sensors = kuukar_sensors.sensors(self.mcu, self.drv) self.leds = kuukar_leds.leds(self.mcu) - self.motion = kuukar_motion.motion(self.mcu, self.drv, self.leds, self.sensors) + self.motion = kuukar_motion.motion( + self.mcu, self.drv, self.leds, self.sensors) self.lcd = kuukar_lcd.lcd(self.motion, self.sensors) - self.environment = kuukar_environment.environment(self.lcd, self.leds, self.sensors) - self.collision = kuukar_collision.collision(self.mcu, self.lcd, self.leds) \ No newline at end of file + self.environment = kuukar_environment.environment( + self.lcd, self.leds, self.sensors) + self.collision = kuukar_collision.collision( + self.mcu, self.lcd, self.leds) diff --git a/kuukar/kuukar_sensors.py b/kuukar/kuukar_sensors.py index b2bd5f3..3963392 100644 --- a/kuukar/kuukar_sensors.py +++ b/kuukar/kuukar_sensors.py @@ -12,13 +12,14 @@ class sensors: __humidity = 0 __brightness = 0 - def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico) -> None: + def __init__(self, mcu: telemetrix_rpi_pico.TelemetrixRpiPico, drv: telemetrix_rpi_pico.TelemetrixRpiPico) -> None: self.mcu = mcu + self.drv = drv self.mcu.set_pin_mode_analog_input(SONAR_1_ADC_PIN, 100, self.__sonar_callback) self.mcu.set_pin_mode_analog_input(SONAR_2_ADC_PIN, 100, self.__sonar_callback) self.mcu.set_pin_mode_analog_input(SONAR_3_ADC_PIN, 100, self.__sonar_callback) self.mcu.set_pin_mode_dht(DHT22_PIN, self.__dht22_callback) - self.mcu.set_pin_mode_analog_input(LIGHT_ANALOG_PIN, 0, self.__light_sensor_callback) + self.drv.set_pin_mode_analog_input(LIGHT_ANALOG_PIN, 0, self.__light_sensor_callback) def sonar_get_distance(self, id: int) -> float: return self.__sonar_distances[id]