Skip to content

Commit

Permalink
Refactor hw initialization so that we can shut down the digipot as so…
Browse files Browse the repository at this point in the history
…on as the app is launched, fixes #4
  • Loading branch information
fijam committed Nov 4, 2021
1 parent dd8c1e1 commit 3b28884
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 29 deletions.
26 changes: 26 additions & 0 deletions digipot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

os.environ["BLINKA_MCP2221"] = "1"

try:
import board
import busio
except RuntimeError:
print("Titler not conneted to USB!")


def hardware_setup():
# from adafruit_blinka.microcontroller.mcp2221 import mcp2221
# mcp2221.mcp2221.gp_set_mode(3, 0b001) # turn LED_I2C on
from adafruit_bus_device.i2c_device import I2CDevice
i2c = busio.I2C(board.SCL, board.SDA)
pot = I2CDevice(i2c, 0x2C)
return pot


def write_to_pot(value, pot):
pot.write(bytes([0x00 & 0xff, value & 0xff]))


def shutdown_pot(pot):
pot.write(bytes([0x20 & 0xff, 0 & 0xff]))
29 changes: 1 addition & 28 deletions hardware.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Finding out how many times to push a button and how.
import os
import sys
import time

from digipot import *
from settings import PRESS, HOLD, wipers, recorder

if recorder == 'R70/90/91':
Expand All @@ -15,16 +15,6 @@
from definitions.r900 import change_set_moves, set_initial, set_uppercase, \
set_lowercase, set_numbers, set_complete, entrypoints

# help Blinka find our microcontroller
os.environ["BLINKA_MCP2221"] = "1"

try:
import board
import busio
except RuntimeError:
print("Titler not conneted to USB")
sys.exit()


def return_current_set(letter, current_set):
# find out where we ended up, this carries over to the next letter
Expand Down Expand Up @@ -86,23 +76,6 @@ def input_string(string_ascii):
push_button('Stop', HOLD, 1) # finish entry


def hardware_setup():
# from adafruit_blinka.microcontroller.mcp2221 import mcp2221
# mcp2221.mcp2221.gp_set_mode(3, 0b001) # turn LED_I2C on
from adafruit_bus_device.i2c_device import I2CDevice
i2c = busio.I2C(board.SCL, board.SDA)
pot = I2CDevice(i2c, 0x2C)
return pot


def write_to_pot(value, pot):
pot.write(bytes([0x00 & 0xff, value & 0xff]))


def shutdown_pot(pot):
pot.write(bytes([0x20 & 0xff, 0 & 0xff]))


def push_button(button, timing, times):
for _ in range(times):
write_to_pot(wipers[button], ad5245)
Expand Down
10 changes: 9 additions & 1 deletion mdrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@

from webapi import *
from settings import PRESS, OFFSET
from digipot import *

try:
ad5245 = hardware_setup()
except NameError:
print("Initialization skipped")
else:
shutdown_pot(ad5245)

try:
from gooey import Gooey
Expand All @@ -31,7 +39,7 @@ def parse_arguments():
parser.add_argument('--only_label', default='OFF', dest='label_mode', choices=['OFF', 'ON', 'ERASE'],
help='Label a recorded disc')
parser.add_argument('--no-tmarks', dest='no_tmarks', action='store_true',
help='Add 2s of silence instead of TMarks between tracks')
help='Add 2s of silence instead of TMarks between tracks')
return parser.parse_args()


Expand Down

0 comments on commit 3b28884

Please sign in to comment.