adding files
This commit is contained in:
0
RPi/.gitkeep
Normal file
0
RPi/.gitkeep
Normal file
37
RPi/fake_smbus.py
Normal file
37
RPi/fake_smbus.py
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
Reference in New Issue
Block a user