Skip to content

Commit 17891ce

Browse files
committed
- Made imports in device driver classes more pythonic (mostly now named imports).
1 parent 20748be commit 17891ce

10 files changed

Lines changed: 39 additions & 39 deletions

File tree

devices/LED_driver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import pyControl.hardware as _h
1+
from pyControl.hardware import Digital_output
22

3-
class LED_driver(_h.Digital_output):
3+
class LED_driver(Digital_output):
44
def __init__(self, port):
55
super().__init__(port.DIO_A)

devices/MCP.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import pyb
22
import math
33
from array import array
4-
import pyControl.hardware as _h
4+
import pyControl.hardware as hw
55

6-
class _MCP(_h.IO_object):
6+
class _MCP(hw.IO_object):
77
# Parent class for MCP23017 and MCP23008 port expanders.
88

99
def __init__(self, I2C_bus, interrupt_pin, addr):
@@ -13,7 +13,7 @@ def __init__(self, I2C_bus, interrupt_pin, addr):
1313
self.interrupts_enabled = False
1414
self.interrupt_pin = interrupt_pin
1515
self.reg_values = {} # Register values set by user.
16-
_h.assign_ID(self)
16+
hw.assign_ID(self)
1717

1818
def reset(self):
1919
self.write_register('IODIR' , 0) # Set pins as ouptuts.
@@ -54,7 +54,7 @@ def enable_interrupts(self):
5454
self.interrupts_enabled = True
5555

5656
def ISR(self, i):
57-
_h.interrupt_queue.put(self.ID)
57+
hw.interrupt_queue.put(self.ID)
5858

5959
def _process_interrupt(self):
6060
INTF = self.read_register('INTF')
@@ -110,7 +110,7 @@ def __init__(self, I2C_bus=1, interrupt_pin='X5', addr=0x20):
110110
self.reset()
111111

112112

113-
class _Pin(_h.IO_expander_pin):
113+
class _Pin(hw.IO_expander_pin):
114114
# GPIO pin on MCP IO expander.
115115

116116
def __init__(self, IOx, id, mode=None):

devices/audio_board.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pyb
2-
import pyControl.audio as _a
2+
from pyControl.audio import Audio_output
33

4-
class Audio_board(_a.Audio_output):
4+
class Audio_board(Audio_output):
55

66
def __init__(self, port):
77
assert port.DAC is not None, '! Audio board needs port with DAC.'

devices/breakout_1_0.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import pyControl.hardware as _h
1+
from pyControl.hardware import Port
22

33
class Breakout_1_0():
44
def __init__(self):
55
# Inputs and outputs.
6-
self.port_1 = _h.Port(DIO_A='X1' , DIO_B='X2', DIO_C='X5', POW_A='Y8', POW_B='Y4',
6+
self.port_1 = Port(DIO_A='X1' , DIO_B='X2', DIO_C='X5', POW_A='Y8', POW_B='Y4',
77
POW_C='Y2', DAC=1, UART=4) # Jumper required to use either DAC/DIO_C or POW_C.
8-
self.port_2 = _h.Port(DIO_A='X3' , DIO_B='X4', DIO_C='X6' , POW_A='Y7', POW_B='Y3',
8+
self.port_2 = Port(DIO_A='X3' , DIO_B='X4', DIO_C='X6' , POW_A='Y7', POW_B='Y3',
99
POW_C='Y1', DAC=2) # Jumper required to use either DAC or POW_C.
10-
self.port_3 = _h.Port(DIO_A='X7' , DIO_B='X8' , POW_A='Y6', POW_B='Y2')
11-
self.port_4 = _h.Port(DIO_A='X12', DIO_B='X11', POW_A='Y5', POW_B='Y1')
10+
self.port_3 = Port(DIO_A='X7' , DIO_B='X8' , POW_A='Y6', POW_B='Y2')
11+
self.port_4 = Port(DIO_A='X12', DIO_B='X11', POW_A='Y5', POW_B='Y1')
1212
self.BNC_1 = 'Y11'
1313
self.BNC_2 = 'Y12'
1414
self.DAC_1 = 'X5'

devices/breakout_1_2.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import pyControl.hardware as _h
1+
from pyControl.hardware import Port
22

33
class Breakout_1_2():
44
def __init__(self):
55
# Inputs and outputs.
6-
self.port_1 = _h.Port(DIO_A='X1', DIO_B='X2' , POW_A='Y7' , POW_B='Y8' , POW_C='Y11', UART=4)
7-
self.port_2 = _h.Port(DIO_A='Y3', DIO_B='Y4' , POW_A='X4' , POW_B='X18', POW_C='Y12')
8-
self.port_3 = _h.Port(DIO_A='X9', DIO_B='X10', POW_A='X7' , POW_B='X19',
6+
self.port_1 = Port(DIO_A='X1', DIO_B='X2' , POW_A='Y7' , POW_B='Y8' , POW_C='Y11', UART=4)
7+
self.port_2 = Port(DIO_A='Y3', DIO_B='Y4' , POW_A='X4' , POW_B='X18', POW_C='Y12')
8+
self.port_3 = Port(DIO_A='X9', DIO_B='X10', POW_A='X7' , POW_B='X19',
99
DIO_C='X5', DAC=1 , I2C=1, UART=1)
10-
self.port_4 = _h.Port(DIO_A='Y9', DIO_B='Y10', POW_A='X8' , POW_B='X20',
10+
self.port_4 = Port(DIO_A='Y9', DIO_B='Y10', POW_A='X8' , POW_B='X20',
1111
DIO_C='X6', DAC=2 , I2C=2, UART=3)
12-
self.port_5 = _h.Port(DIO_A='Y5', DIO_B='Y6' , POW_A='X21', POW_B='X22')
13-
self.port_6 = _h.Port(DIO_A='X3', DIO_B='X11' , POW_A='Y1' , POW_B='Y2')
12+
self.port_5 = Port(DIO_A='Y5', DIO_B='Y6' , POW_A='X21', POW_B='X22')
13+
self.port_6 = Port(DIO_A='X3', DIO_B='X11' , POW_A='Y1' , POW_B='Y2')
1414
self.BNC_1 = 'X12'
1515
self.BNC_2 = 'X11'
1616
self.DAC_1 = 'X5'

devices/lickometer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import pyControl.hardware as _h
1+
from pyControl.hardware import Digital_input, Digital_output
22

33
class Lickometer():
44
# Two lick detectors and two solenoids.
55
def __init__(self, port, rising_event_A='lick_1', falling_event_A='lick_1_off',
66
rising_event_B='lick_2', falling_event_B='lick_2_off', debounce=5):
7-
self.lick_1 = _h.Digital_input(port.DIO_A, rising_event_A, falling_event_A, debounce)
8-
self.lick_2 = _h.Digital_input(port.DIO_B, rising_event_B, falling_event_B, debounce)
9-
self.SOL_1 = _h.Digital_output(port.POW_A)
10-
self.SOL_2 = _h.Digital_output(port.POW_B)
7+
self.lick_1 = Digital_input(port.DIO_A, rising_event_A, falling_event_A, debounce)
8+
self.lick_2 = Digital_input(port.DIO_B, rising_event_B, falling_event_B, debounce)
9+
self.SOL_1 = Digital_output(port.POW_A)
10+
self.SOL_2 = Digital_output(port.POW_B)

devices/nine_poke.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from devices._poke import _Poke
2-
from devices._MCP import MCP23017, MCP23008
1+
from devices.poke import _Poke
2+
from devices.MCP import MCP23017, MCP23008
33
from pyControl.hardware import Digital_output
44

55
class Nine_poke():

devices/poke.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import pyControl.hardware as _h
1+
from pyControl.hardware import Digital_output, Digital_input
22

33
class Poke():
44
# Single IR beam, LED and Solenoid.
55
def __init__(self, port, rising_event = None, falling_event = None, debounce = 5):
6-
self.input = _h.Digital_input(port.DIO_A, rising_event, falling_event, debounce)
7-
self.LED = _h.Digital_output(port.POW_A)
8-
self.SOL = _h.Digital_output(port.POW_B)
6+
self.input = Digital_input(port.DIO_A, rising_event, falling_event, debounce)
7+
self.LED = Digital_output(port.POW_A)
8+
self.SOL = Digital_output(port.POW_B)
99
if port.POW_C is not None:
10-
self.POW_C = _h.Digital_output(port.POW_C)
10+
self.POW_C = Digital_output(port.POW_C)
1111

1212
def value(self):
1313
return self.input.value()
@@ -16,8 +16,8 @@ def value(self):
1616
class _Poke():
1717
# Poke class used in multi-poke devices.
1818
def __init__(self, input_pin, LED_pin, rising_event, falling_event, debounce):
19-
self.input = _h.Digital_input(input_pin, rising_event, falling_event, debounce)
20-
if LED_pin: self.LED = _h.Digital_output(LED_pin)
19+
self.input = Digital_input(input_pin, rising_event, falling_event, debounce)
20+
if LED_pin: self.LED = Digital_output(LED_pin)
2121

2222
def value(self):
2323
return self.input.value()

devices/port_expander.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from pyControl.hardware import Port
2-
from devices._MCP import MCP23017
2+
from devices.MCP import MCP23017
33

44
class Port_expander():
55
# IO expander board which runs 8 behaviour ports from an MCP23017 i2c port expander.

devices/stepper_motor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import pyControl.hardware as _h
1+
from pyControl.hardware import Digital_output
22

33
class Stepper_motor():
44
def __init__(self, port=None, direction_pin=None, step_pin=None):
55
if port:
66
direction_pin = port.DIO_A
77
step_pin = port.DIO_B
8-
self._direction = _h.Digital_output(direction_pin)
9-
self._step = _h.Digital_output(step_pin)
8+
self._direction = Digital_output(direction_pin)
9+
self._step = Digital_output(step_pin)
1010

1111
def forward(self, step_rate, n_steps=False):
1212
self._direction.off() #set direction forward

0 commit comments

Comments
 (0)