Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def init_pfio(self, widget, data=None):
pfio.init()
def __init__(self, spi_liststore_lock):
gtk.gdk.threads_init() # init the gdk threads
threading.Thread.__init__(self)
self.spi_liststore_lock = spi_liststore_lock
# a bit of spaghetti set up
emulator_parts.pfio = pfio
emulator_parts.rpi_emulator = self
self.spi_visualiser_section = emulator_parts.SpiVisualiserFrame(self)
global pfio_connect
try:
pfio.init()
pfio_connect = True
except pfio.InitError:
print "Could not connect to the SPI module (check privileges). Starting emulator assuming that the PiFace is not connected."
pfio_connect = False
emulator_parts.pfio = None
self.emu_window = gtk.Window()
self.emu_window.connect("delete-event", gtk.main_quit)
self.emu_window.set_title(WINDOW_TITLE)
# emu screen
self.emu_screen = emulator_parts.EmulatorScreen(EMU_WIDTH, EMU_HEIGHT, EMU_SPEED)
self.emu_screen.show()
# board connected msg
if pfio_connect:
def start_pfio_server(callback=None, verbose=False, port=DEFAULT_PORT):
"""Starts listening for pfio packets over the network"""
pfio.init()
try:
# this returns the loopback ip on the RPi :-(
#hostname = socket.gethostname()
###################################################
# this is pretty hacky, if anyone can find a better
# solution, then please change this!
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80)) # try to connect to google's dns
hostname = s.getsockname()[0] # get this device's hostname
s.close()
# blergh, nasty stuff
###################################################
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((hostname, port))
import pfio
from time import sleep
pfio.init()
TEST_MODE = True
def delay():
global TEST_MODE
if TEST_MODE:
sleep(1)
def shift_out(data_pin, latch_pin, clock_pin, edian, data):
delay()
print "Latch pin low"
pfio.digital_write(latch_pin,0)
delay()
print "clock pin low"
pfio.digital_write(clock_pin, 0)
delay()
def init():
window = gtk.Window()
window.connect("delete-event", gtk.main_quit)
window.set_title("SPI Visualiser")
window.set_size_request(500, 200)
visualiser = SpiVisualiserSection()
sender = SpiSenderSection()
pfio.spi_handler = pfio.get_spi_handler()
pfio.spi_visualiser_section = visualiser
visualiser.show()
sender.show()
container = gtk.VBox()
container.pack_start(child=visualiser, expand=True, fill=True)
container.pack_start(child=sender, expand=False)
container.show()
window.add(container)
window.show()
gtk.main()
def __init__(self, spi_liststore_lock):
gtk.gdk.threads_init() # init the gdk threads
threading.Thread.__init__(self)
self.spi_liststore_lock = spi_liststore_lock
# a bit of spaghetti set up
emulator_parts.pfio = pfio
emulator_parts.rpi_emulator = self
self.spi_visualiser_section = emulator_parts.SpiVisualiserFrame(self)
global pfio_connect
try:
pfio.init()
pfio_connect = True
except pfio.InitError:
print "Could not connect to the SPI module (check privileges). Starting emulator assuming that the PiFace is not connected."
pfio_connect = False
emulator_parts.pfio = None
self.emu_window = gtk.Window()
self.emu_window.connect("delete-event", gtk.main_quit)
self.emu_window.set_title(WINDOW_TITLE)
# emu screen
self.emu_screen = emulator_parts.EmulatorScreen(EMU_WIDTH, EMU_HEIGHT, EMU_SPEED)
self.emu_screen.show()
# board connected msg
if pfio_connect:
msg = "Pi Face detected!"
else:
sock.sendto(p.for_network(), sender)
elif packet.command == READ_OUT_CMD:
output_bitp = pfio.read_output()
p = PfionPacket(READ_OUT_ACK)
p.bit_pattern = output_bitp
sock.sendto(p.for_network(), sender)
elif packet.command == READ_IN_CMD:
input_bitp = pfio.read_input()
p = PfionPacket(READ_IN_ACK)
p.bit_pattern = input_bitp
sock.sendto(p.for_network(), sender)
elif packet.command == DIGITAL_WRITE_CMD:
pfio.digital_write(packet.pin_number, packet.pin_value)
p = PfionPacket(DIGITAL_WRITE_ACK)
sock.sendto(p.for_network(), sender)
elif packet.command == DIGITAL_READ_CMD:
pin_value = pfio.digital_read(packet.pin_number)
p = PfionPacket(DIGITAL_READ_ACK)
p.pin_number = packet.pin_number
p.pin_value = pin_value
sock.sendto(p.for_network(), sender)
elif callback != None:
callback(packet, sender)
elif verbose:
print "Unkown packet command (%d). Ignoring." % packet.command
def shift_out(data_pin, latch_pin, clock_pin, edian, data):
delay()
print "Latch pin low"
pfio.digital_write(latch_pin,0)
delay()
print "clock pin low"
pfio.digital_write(clock_pin, 0)
delay()
data_bits = str(bin(data)[2:].zfill(8))
if edian:
for bit in data_bits:
bit = int(bit)
print bit
pfio.digital_write(data_pin, bit)
delay()
pulse_clock(clock_pin)
else:
for bit in reversed(data_bits):
def pulse_clock(clock_pin):
print "clock high"
pfio.digital_write(clock_pin, 1)
delay()
print "clock low"
pfio.digital_write(clock_pin, 0)
delay()
def pulse_clock(clock_pin):
print "clock high"
pfio.digital_write(clock_pin, 1)
delay()
print "clock low"
pfio.digital_write(clock_pin, 0)
delay()