Skip to content

Commit

Permalink
Moved imports out of inline to top level
Browse files Browse the repository at this point in the history
  • Loading branch information
fall-byrd committed Sep 21, 2024
1 parent c1ca6ee commit 25f989a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
17 changes: 13 additions & 4 deletions backend/hardware/gpiochip/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,25 @@
and the individual files for configuration information.
"""

from hardware.gpiochip.gpiod_simulation import GPIODChipSimulation
from hardware.gpiochip.gpiod_chipset import GPIODChipset

IMPORT_ERROR = False

# We check for an import error here as this ikmport requires the gpiod python library
# to be installed, which is not a requirement
try:
from hardware.gpiochip.gpiod import GPIODChip
except ModuleNotFoundError:
IMPORT_ERROR = True


def createGPIOChip(gpioConfig: dict, devices: dict):
gpioType = gpioConfig['implementation']
if gpioType == "gpiod":
from hardware.gpiochip.gpiod import GPIODChip
if gpioType == "gpiod" and not IMPORT_ERROR:
return GPIODChip(gpioConfig)
if gpioType == "simulation":
from hardware.gpiochip.gpiod_simulation import GPIODChipSimulation
return GPIODChipSimulation(gpioConfig)
if gpioType == "gpiod_chipset":
from hardware.gpiochip.gpiod_chipset import GPIODChipset
return GPIODChipset(gpioConfig, devices)
raise Exception("Unsupported gpiochiptype")
7 changes: 4 additions & 3 deletions backend/hardware/thermometer/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
and either the individual files or backend/config.py for configuration information.
"""

from hardware.thermometer.w1_therm import W1TempSensor
from hardware.thermometer.serial import SerialTempSensor
from hardware.thermometer.serial_simulation import SerialTempSensorSimulation


def createThermometer(thermometerConfig: dict, devices: dict):
thermometerType = thermometerConfig['implementation']
if thermometerType == "w1_therm":
from hardware.thermometer.w1_therm import W1TempSensor
return W1TempSensor()
elif thermometerType == "serial":
from hardware.thermometer.serial import SerialTempSensor
return SerialTempSensor(thermometerConfig)
elif thermometerType == "simulation":
from hardware.thermometer.serial_simulation import SerialTempSensorSimulation
return SerialTempSensorSimulation(thermometerConfig)
raise Exception("Unsupported thermometer type")
19 changes: 9 additions & 10 deletions backend/microlab/core.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
"""
Contains function for starting up the microlab process
"""
import logging
import sys
import time
import threading
import signal

import hardware.devicelist
import recipes.core
import recipes.state

from config import microlabConfig as config
from hardware.core import MicroLabHardware

HALT = threading.Event()
Expand Down Expand Up @@ -64,16 +73,6 @@ def startMicrolabProcess(in_queue, out_queue):
(False, message) on failure.
reference "selectOption" in /recipes/__init__.py for more info
"""
import logging
import sys
import time

import hardware.devicelist
import recipes.core
import recipes.state
import signal
from config import microlabConfig as config

microlabHardware = MicroLabHardware.get_microlab_hardware_controller()

def runMicrolab():
Expand Down

0 comments on commit 25f989a

Please sign in to comment.