Added dependencies to get_sdk.sh. Cleaned up code in enter_download_mode.py and made compatible with py2 and py3.

master
Jessy Diamond Exum 2017-06-09 16:48:15 -07:00
parent 2fd475d365
commit f39aaec298
2 changed files with 29 additions and 22 deletions

View File

@ -1,2 +1,3 @@
#!/bin/bash
sudo apt-get install gcc-arm-none-eabi
sudo apt-get install gcc-arm-none-eabi python-pip
sudo pip2 install libusb1

View File

@ -1,27 +1,33 @@
#!/usr/bin/env python
import usb1
from __future__ import print_function
import sys
import time
import traceback
import usb1
if __name__ == "__main__":
context = usb1.USBContext()
handle = None
for device in context.getDeviceList(skip_on_error=True):
if device.getVendorID() == 0xbbaa and device.getProductID()&0xFF00 == 0xdd00:
print "found device"
handle = device.open()
handle.claimInterface(0)
break
if handle == None:
print "no device found"
exit(0)
def enter_download_mode(device):
handle = device.open()
handle.claimInterface(0)
try:
handle.controlWrite(usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE, 0xd1, 0, 0, '')
except Exception:
traceback.print_exc()
print "expected error, exiting cleanly"
time.sleep(1)
handle.controlWrite(usb1.TYPE_VENDOR | usb1.RECIPIENT_DEVICE, 0xd1, 0, 0, b'')
except usb1.USBErrorIO as e:
print("Device download mode enabled.")
time.sleep(1)
else:
print("Device failed to enter download mode.")
sys.exit(1)
def find_first_panda(context=None):
context = context or usb1.USBContext()
for device in context.getDeviceList(skip_on_error=True):
if device.getVendorID() == 0xbbaa and device.getProductID()&0xFF00 == 0xdd00:
return device
if __name__ == "__main__":
panda_dev = find_first_panda()
if panda_dev == None:
print("no device found")
sys.exit(0)
print("found device")
enter_download_mode(panda_dev)