37 lines
987 B
Python
37 lines
987 B
Python
import tkinter as tk
|
|
|
|
encoders = []
|
|
class SMBus:
|
|
def __init__(self, bus):
|
|
print(f"fake SMBus initialized on bus {bus}")
|
|
self.bus = bus
|
|
|
|
|
|
def read_i2c_block_data(self, addr, cmd, length):
|
|
data = []
|
|
for encoder in encoders:
|
|
pos_as_byte_array = encoder.get_position().to_bytes(2, 'little', signed=True)
|
|
data.append(pos_as_byte_array[0])
|
|
data.append(pos_as_byte_array[1])
|
|
|
|
#print(f"SMBus data set to: {data}")
|
|
return data
|
|
|
|
def createTestEncoder():
|
|
encoder = TestEncoder()
|
|
encoders.append(encoder)
|
|
return encoder
|
|
|
|
class TestEncoder:
|
|
""" represent a test encoder controlled by keyboard input """
|
|
def __init__(self):
|
|
self._position = 0
|
|
|
|
def _rotate_cw(self, event=None):
|
|
self._position += 1
|
|
|
|
def _rotate_ccw(self, event=None):
|
|
self._position -= 1
|
|
|
|
def get_position(self) -> int:
|
|
return self._position |