Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

patch from walter to cleanup behavior

  • Loading branch information...
commit 67e4233bc4944253ca75de204c158bd36cafd997 1 parent 4498f1f
@itdaniher authored
Showing with 25 additions and 23 deletions.
  1. +15 −19 WeDoMore.py
  2. +10 −4 wedo_plugin/wedo_plugin.py
View
34 WeDoMore.py
@@ -47,12 +47,7 @@ def __init__(self, device=None):
it."""
self.dev = None
self.number = 0
- if self.dev is None:
- device_list = scan_for_devices()
- if len(device_list) > 0:
- self.dev = device_list[0] # Default to first device
- else:
- self.dev = device
+ self.dev = device
if self.dev is None:
logging.debug("No Lego WeDo found")
else:
@@ -71,16 +66,16 @@ def init_device(self):
logger.error(
"Could not detatch kernel driver: %s" % (str(e)))
except usb.core.USBError as e:
- logger.error("Could not talk to device: %s" % (str(e)))
+ logger.error("Could not talk to WeDo device: %s" % (str(e)))
+ self.endpoint = self.dev[0][(0,0)][0]
def getRawData(self):
"""Read 64 bytes from the WeDo's endpoint, but only
return the last eight."""
try:
- self.endpoint = self.dev[0][(0,0)][0]
data = list(self.endpoint.read(64)[-8:])
except usb.core.USBError as e:
- logger.error("Could not read from driver: %s" % (str(e)))
+ logger.error("Could not read from WeDo device: %s" % (str(e)))
return None
return data
@@ -113,28 +108,29 @@ def setMotors(self, valMotorA, valMotorB):
logger.error("Could not write to driver: %s" % (str(e)))
def getData(self):
- """Sensor data is contained in the 2nd and 4th byte,
- with sensor IDs being contained in the 3rd and 5th
- byte respectively."""
+ """Sensor data is contained in the 2nd and 4th byte, with
+ sensor IDs being contained in the 3rd and 5th byte
+ respectively."""
rawData = self.getRawData()
if rawData is not None:
sensorData = {rawData[3]: rawData[2], rawData[5]: rawData[4]}
else:
sensorData = {}
- print sensorData
return sensorData
def processTilt(self, v):
- """Use a series of elif/value-checks to process the
- tilt sensor data."""
- if v in [24, 25, 26, 27]:
+ """Use a series of elif/value-checks to process the tilt
+ sensor data."""
+ if v in range(10, 40):
return TILT_BACK
- elif v in [73, 74, 75, 76]:
+ elif v in range(60, 90):
return TILT_RIGHT
- elif v in [175, 176, 177, 178, 179, 180]:
+ elif v in range(170, 190):
return TILT_FORWARD
- elif v in [229, 230]:
+ elif v in range(220, 240):
return TILT_LEFT
+ elif v in range(120, 140):
+ return NO_TILT
else:
return NO_TILT
View
14 wedo_plugin/wedo_plugin.py
@@ -140,18 +140,23 @@ def setup(self):
def wedo_select(self, i):
''' Select current device '''
+ if self.wedo_count() == 0:
+ self.active_wedo = None
+ self._parent.showlabel(
+ 'status', _('WeDo is available'))
+ return
if type(i) == unicode:
i = str(i.encode('ascii', 'replace'))
if type(i) == float or type(i) == str:
i = int(i)
if type(i) != int:
i = 1
- i -= 1 # Userspace counts from 1; internally, we count from 0
- if i < 0 or i > self.wedo_count() - 1:
- self._parent.showlabel(
- 'status', _('WeDo %d is not available; defaulting to 1') % (i))
if i < 0:
i = -i
+ if i < 0 or i > self.wedo_count() - 1:
+ self._parent.showlabel(
+ 'status', _('WeDo %d is unavailable; defaulting to 1') % (i))
+ i -= 1 # Userspace counts from 1; internally, we count from 0
if i > self.wedo_count() - 1:
i = 0
self.active_wedo = i
@@ -261,6 +266,7 @@ def start(self):
''' Each time program starts, scan for devices and reset status '''
for wedo in self.WeDos:
wedo.dev = None
+ self.active_wedo = None
device_list = scan_for_devices()
if len(device_list) > 0:
self.status = True
Please sign in to comment.
Something went wrong with that request. Please try again.