Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions 4BorgWeb.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import time
import sys
import threading
import SocketServer
import socketserver
import picamera
import picamera.array
import cv2
Expand Down Expand Up @@ -39,13 +39,13 @@
if not PBR.foundChip:
boards = PicoBorgRev.ScanForPicoBorgReverse()
if len(boards) == 0:
print 'No PicoBorg Reverse found, check you are attached :)'
print('No PicoBorg Reverse found, check you are attached :)')
else:
print 'No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress)
print(('No PicoBorg Reverse at address %02X, but we did find boards:' % (PBR.i2cAddress)))
for board in boards:
print ' %02X (%d)' % (board, board)
print 'If you need to change the I²C address change the setup line so it is correct, e.g.'
print 'PBR.i2cAddress = 0x%02X' % (boards[0])
print((' %02X (%d)' % (board, board)))
print('If you need to change the I²C address change the setup line so it is correct, e.g.')
print(('PBR.i2cAddress = 0x%02X' % (boards[0])))
sys.exit()
#PBR.SetEpoIgnore(True) # Uncomment to disable EPO latch, needed if you do not have a switch / jumper
PBR.SetCommsFailsafe(False) # Disable the communications failsafe
Expand Down Expand Up @@ -78,15 +78,15 @@ def run(self):
if timedOut:
if self.event.wait(1):
# Connection
print 'Reconnected...'
print('Reconnected...')
timedOut = False
self.event.clear()
else:
if self.event.wait(1):
self.event.clear()
else:
# Timed out
print 'Timed out...'
print('Timed out...')
timedOut = True
PBR.MotorsOff()

Expand Down Expand Up @@ -131,12 +131,12 @@ def __init__(self):
def run(self):
global camera
global processor
print 'Start the stream using the video port'
print('Start the stream using the video port')
camera.capture_sequence(self.TriggerStream(), format='bgr', use_video_port=True)
print 'Terminating camera processing...'
print('Terminating camera processing...')
processor.terminated = True
processor.join()
print 'Processing terminated.'
print('Processing terminated.')

# Stream delegation loop
def TriggerStream(self):
Expand All @@ -149,7 +149,7 @@ def TriggerStream(self):
processor.event.set()

# Class used to implement the web server
class WebServer(SocketServer.BaseRequestHandler):
class WebServer(socketserver.BaseRequestHandler):
def handle(self):
global PBR
global lastFrame
Expand Down Expand Up @@ -465,34 +465,34 @@ def send(self, content):
lockFrame = threading.Lock()

# Startup sequence
print 'Setup camera'
print('Setup camera')
camera = picamera.PiCamera()
camera.resolution = (imageWidth, imageHeight)
camera.framerate = frameRate

print 'Setup the stream processing thread'
print('Setup the stream processing thread')
processor = StreamProcessor()

print 'Wait ...'
print('Wait ...')
time.sleep(2)
captureThread = ImageCapture()

print 'Setup the watchdog'
print('Setup the watchdog')
watchdog = Watchdog()

# Run the web server until we are told to close
httpServer = SocketServer.TCPServer(("0.0.0.0", webPort), WebServer)
httpServer = socketserver.TCPServer(("0.0.0.0", webPort), WebServer)
try:
print 'Press CTRL+C to terminate the web-server'
print('Press CTRL+C to terminate the web-server')
while running:
httpServer.handle_request()
except KeyboardInterrupt:
# CTRL+C exit
print '\nUser shutdown'
print('\nUser shutdown')
finally:
# Turn the motors off under all scenarios
PBR.MotorsOff()
print 'Motors off'
print('Motors off')
# Tell each thread to stop, and wait for them to end
running = False
captureThread.join()
Expand All @@ -502,4 +502,4 @@ def send(self, content):
watchdog.join()
del camera
PBR.SetLed(True)
print 'Web-server terminated.'
print('Web-server terminated.')
50 changes: 25 additions & 25 deletions Diablo.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ def ScanForDiablo(busNumber = 1):
The busNumber if supplied is which I�C bus to scan, 0 for Rev 1 boards, 1 for Rev 2 boards, if not supplied the default is 1
"""
found = []
print 'Scanning I�C bus #%d' % (busNumber)
print(('Scanning I�C bus #%d' % (busNumber)))
bus = Diablo()
for address in range(0x03, 0x78, 1):
try:
bus.InitBusOnly(busNumber, address)
i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN)
if len(i2cRecv) == I2C_MAX_LEN:
if i2cRecv[1] == I2C_ID_DIABLO:
print 'Found Diablo at %02X' % (address)
print(('Found Diablo at %02X' % (address)))
found.append(address)
else:
pass
Expand All @@ -104,11 +104,11 @@ def ScanForDiablo(busNumber = 1):
except:
pass
if len(found) == 0:
print 'No Diablo boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber)
print(('No Diablo boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber)))
elif len(found) == 1:
print '1 Diablo board found'
print('1 Diablo board found')
else:
print '%d Diablo boards found' % (len(found))
print(('%d Diablo boards found' % (len(found))))
return found


Expand All @@ -122,64 +122,64 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1):
Warning, this new I�C address will still be used after resetting the power on the device
"""
if newAddress < 0x03:
print 'Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)'
print('Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)')
return
elif newAddress > 0x77:
print 'Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)'
print('Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)')
return
if oldAddress < 0x0:
found = ScanForDiablo(busNumber)
if len(found) < 1:
print 'No Diablo boards found, cannot set a new I�C address!'
print('No Diablo boards found, cannot set a new I�C address!')
return
else:
oldAddress = found[0]
print 'Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber)
print(('Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber)))
bus = Diablo()
bus.InitBusOnly(busNumber, oldAddress)
try:
i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN)
if len(i2cRecv) == I2C_MAX_LEN:
if i2cRecv[1] == I2C_ID_DIABLO:
foundChip = True
print 'Found Diablo at %02X' % (oldAddress)
print(('Found Diablo at %02X' % (oldAddress)))
else:
foundChip = False
print 'Found a device at %02X, but it is not a Diablo (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_DIABLO)
print(('Found a device at %02X, but it is not a Diablo (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_DIABLO)))
else:
foundChip = False
print 'Missing Diablo at %02X' % (oldAddress)
print(('Missing Diablo at %02X' % (oldAddress)))
except KeyboardInterrupt:
raise
except:
foundChip = False
print 'Missing Diablo at %02X' % (oldAddress)
print(('Missing Diablo at %02X' % (oldAddress)))
if foundChip:
bus.RawWrite(COMMAND_SET_I2C_ADD, [newAddress])
time.sleep(0.1)
print 'Address changed to %02X, attempting to talk with the new address' % (newAddress)
print(('Address changed to %02X, attempting to talk with the new address' % (newAddress)))
try:
bus.InitBusOnly(busNumber, newAddress)
i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN)
if len(i2cRecv) == I2C_MAX_LEN:
if i2cRecv[1] == I2C_ID_DIABLO:
foundChip = True
print 'Found Diablo at %02X' % (newAddress)
print(('Found Diablo at %02X' % (newAddress)))
else:
foundChip = False
print 'Found a device at %02X, but it is not a Diablo (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_DIABLO)
print(('Found a device at %02X, but it is not a Diablo (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_DIABLO)))
else:
foundChip = False
print 'Missing Diablo at %02X' % (newAddress)
print(('Missing Diablo at %02X' % (newAddress)))
except KeyboardInterrupt:
raise
except:
foundChip = False
print 'Missing Diablo at %02X' % (newAddress)
print(('Missing Diablo at %02X' % (newAddress)))
if foundChip:
print 'New I�C address of %02X set successfully' % (newAddress)
print(('New I�C address of %02X set successfully' % (newAddress)))
else:
print 'Failed to set new I�C address...'
print('Failed to set new I�C address...')


# Class used to control Diablo
Expand Down Expand Up @@ -268,7 +268,7 @@ def Print(self, message):
Wrapper used by the Diablo instance to print messages, will call printFunction if set, print otherwise
"""
if self.printFunction == None:
print message
print(message)
else:
self.printFunction(message)

Expand Down Expand Up @@ -904,10 +904,10 @@ def Help(self):
Displays the names and descriptions of the various functions and settings provided
"""
funcList = [Diablo.__dict__.get(a) for a in dir(Diablo) if isinstance(Diablo.__dict__.get(a), types.FunctionType)]
funcListSorted = sorted(funcList, key = lambda x: x.func_code.co_firstlineno)
funcListSorted = sorted(funcList, key = lambda x: x.__code__.co_firstlineno)

print self.__doc__
print
print((self.__doc__))
print()
for func in funcListSorted:
print '=== %s === %s' % (func.func_name, func.func_doc)
print(('=== %s === %s' % (func.__name__, func.__doc__)))

50 changes: 25 additions & 25 deletions PicoBorgRev.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ def ScanForPicoBorgReverse(busNumber = 1):
The busNumber if supplied is which I�C bus to scan, 0 for Rev 1 boards, 1 for Rev 2 boards, if not supplied the default is 1
"""
found = []
print 'Scanning I�C bus #%d' % (busNumber)
print(('Scanning I�C bus #%d' % (busNumber)))
bus = PicoBorgRev()
for address in range(0x03, 0x78, 1):
try:
bus.InitBusOnly(busNumber, address)
i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN)
if len(i2cRecv) == I2C_MAX_LEN:
if i2cRecv[1] == I2C_ID_PICOBORG_REV:
print 'Found PicoBorg Reverse at %02X' % (address)
print(('Found PicoBorg Reverse at %02X' % (address)))
found.append(address)
else:
pass
Expand All @@ -105,11 +105,11 @@ def ScanForPicoBorgReverse(busNumber = 1):
except:
pass
if len(found) == 0:
print 'No PicoBorg Reverse boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber)
print(('No PicoBorg Reverse boards found, is bus #%d correct (should be 0 for Rev 1, 1 for Rev 2)' % (busNumber)))
elif len(found) == 1:
print '1 PicoBorg Reverse board found'
print('1 PicoBorg Reverse board found')
else:
print '%d PicoBorg Reverse boards found' % (len(found))
print(('%d PicoBorg Reverse boards found' % (len(found))))
return found


Expand All @@ -123,64 +123,64 @@ def SetNewAddress(newAddress, oldAddress = -1, busNumber = 1):
Warning, this new I�C address will still be used after resetting the power on the device
"""
if newAddress < 0x03:
print 'Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)'
print('Error, I�C addresses below 3 (0x03) are reserved, use an address between 3 (0x03) and 119 (0x77)')
return
elif newAddress > 0x77:
print 'Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)'
print('Error, I�C addresses above 119 (0x77) are reserved, use an address between 3 (0x03) and 119 (0x77)')
return
if oldAddress < 0x0:
found = ScanForPicoBorgReverse(busNumber)
if len(found) < 1:
print 'No PicoBorg Reverse boards found, cannot set a new I�C address!'
print('No PicoBorg Reverse boards found, cannot set a new I�C address!')
return
else:
oldAddress = found[0]
print 'Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber)
print(('Changing I�C address from %02X to %02X (bus #%d)' % (oldAddress, newAddress, busNumber)))
bus = PicoBorgRev()
bus.InitBusOnly(busNumber, oldAddress)
try:
i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN)
if len(i2cRecv) == I2C_MAX_LEN:
if i2cRecv[1] == I2C_ID_PICOBORG_REV:
foundChip = True
print 'Found PicoBorg Reverse at %02X' % (oldAddress)
print(('Found PicoBorg Reverse at %02X' % (oldAddress)))
else:
foundChip = False
print 'Found a device at %02X, but it is not a PicoBorg Reverse (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_PICOBORG_REV)
print(('Found a device at %02X, but it is not a PicoBorg Reverse (ID %02X instead of %02X)' % (oldAddress, i2cRecv[1], I2C_ID_PICOBORG_REV)))
else:
foundChip = False
print 'Missing PicoBorg Reverse at %02X' % (oldAddress)
print(('Missing PicoBorg Reverse at %02X' % (oldAddress)))
except KeyboardInterrupt:
raise
except:
foundChip = False
print 'Missing PicoBorg Reverse at %02X' % (oldAddress)
print(('Missing PicoBorg Reverse at %02X' % (oldAddress)))
if foundChip:
bus.RawWrite(COMMAND_SET_I2C_ADD, [newAddress])
time.sleep(0.1)
print 'Address changed to %02X, attempting to talk with the new address' % (newAddress)
print(('Address changed to %02X, attempting to talk with the new address' % (newAddress)))
try:
bus.InitBusOnly(busNumber, newAddress)
i2cRecv = bus.RawRead(COMMAND_GET_ID, I2C_MAX_LEN)
if len(i2cRecv) == I2C_MAX_LEN:
if i2cRecv[1] == I2C_ID_PICOBORG_REV:
foundChip = True
print 'Found PicoBorg Reverse at %02X' % (newAddress)
print(('Found PicoBorg Reverse at %02X' % (newAddress)))
else:
foundChip = False
print 'Found a device at %02X, but it is not a PicoBorg Reverse (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_PICOBORG_REV)
print(('Found a device at %02X, but it is not a PicoBorg Reverse (ID %02X instead of %02X)' % (newAddress, i2cRecv[1], I2C_ID_PICOBORG_REV)))
else:
foundChip = False
print 'Missing PicoBorg Reverse at %02X' % (newAddress)
print(('Missing PicoBorg Reverse at %02X' % (newAddress)))
except KeyboardInterrupt:
raise
except:
foundChip = False
print 'Missing PicoBorg Reverse at %02X' % (newAddress)
print(('Missing PicoBorg Reverse at %02X' % (newAddress)))
if foundChip:
print 'New I�C address of %02X set successfully' % (newAddress)
print(('New I�C address of %02X set successfully' % (newAddress)))
else:
print 'Failed to set new I�C address...'
print('Failed to set new I�C address...')


# Class used to control PicoBorg Reverse
Expand Down Expand Up @@ -269,7 +269,7 @@ def Print(self, message):
Wrapper used by the PicoBorgRev instance to print messages, will call printFunction if set, print otherwise
"""
if self.printFunction == None:
print message
print(message)
else:
self.printFunction(message)

Expand Down Expand Up @@ -935,10 +935,10 @@ def Help(self):
Displays the names and descriptions of the various functions and settings provided
"""
funcList = [PicoBorgRev.__dict__.get(a) for a in dir(PicoBorgRev) if isinstance(PicoBorgRev.__dict__.get(a), types.FunctionType)]
funcListSorted = sorted(funcList, key = lambda x: x.func_code.co_firstlineno)
funcListSorted = sorted(funcList, key = lambda x: x.__code__.co_firstlineno)

print self.__doc__
print
print((self.__doc__))
print()
for func in funcListSorted:
print '=== %s === %s' % (func.func_name, func.func_doc)
print(('=== %s === %s' % (func.__name__, func.__doc__)))

Loading