mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
Cosmetics
This commit is contained in:
parent
c955820521
commit
907a2dd561
@ -32,4 +32,3 @@ while color != COLOR_NONE:
|
||||
action_by_color(color)
|
||||
|
||||
print(number)
|
||||
|
||||
|
@ -22,7 +22,8 @@ class _SpheroImproved(spheropy.Sphero):
|
||||
async def connect(self, search_name=None, address=None, port=None, bluetooth_interface=None, use_ble=False,
|
||||
num_retry_attempts=1):
|
||||
gattool = BLEInterfaceGattool(search_name)
|
||||
return await super().connect(search_name, address, port, gattool, use_ble, num_retry_attempts)
|
||||
return await
|
||||
super().connect(search_name, address, port, gattool, use_ble, num_retry_attempts)
|
||||
|
||||
async def sleep(self, sleeptime, reset_inactivity_timeout=True, response_timeout_in_seconds=None):
|
||||
# port from https://github.com/jchadwhite/SpheroBB8-python/blob/master/BB8_driver.py#L394
|
||||
@ -33,7 +34,8 @@ class _SpheroImproved(spheropy.Sphero):
|
||||
wait_for_response=False,
|
||||
reset_inactivity_timeout=reset_inactivity_timeout)
|
||||
|
||||
return await self._send_command(command, response_timeout_in_seconds)
|
||||
return await
|
||||
self._send_command(command, response_timeout_in_seconds)
|
||||
|
||||
async def set_rotation_rate(self, rate, reset_inactivity_timeout=True, response_timeout_in_seconds=None):
|
||||
# port from https://github.com/jchadwhite/SpheroBB8-python/blob/master/BB8_driver.py
|
||||
@ -44,7 +46,8 @@ class _SpheroImproved(spheropy.Sphero):
|
||||
wait_for_response=False,
|
||||
reset_inactivity_timeout=reset_inactivity_timeout)
|
||||
|
||||
return await self._send_command(command, response_timeout_in_seconds)
|
||||
return await
|
||||
self._send_command(command, response_timeout_in_seconds)
|
||||
|
||||
|
||||
class BB8(object):
|
||||
|
@ -3,8 +3,7 @@ import time
|
||||
from time import sleep
|
||||
|
||||
from pylgbst import *
|
||||
from pylgbst.comms import DebugServerConnection
|
||||
from pylgbst.hub import MoveHub, math
|
||||
from pylgbst.hub import MoveHub
|
||||
from pylgbst.peripherals import EncodedMotor, TiltSensor, Current, Voltage, COLORS, COLOR_BLACK
|
||||
|
||||
log = logging.getLogger("demo")
|
||||
@ -13,9 +12,11 @@ log = logging.getLogger("demo")
|
||||
def demo_led_colors(movehub):
|
||||
# LED colors demo
|
||||
log.info("LED colors demo")
|
||||
|
||||
# We get a response with payload and port, not x and y here...
|
||||
def colour_callback(**named):
|
||||
log.info("LED Color callback: %s", named)
|
||||
|
||||
movehub.led.subscribe(colour_callback)
|
||||
for color in list(COLORS.keys())[1:] + [COLOR_BLACK]:
|
||||
log.info("Setting LED color to: %s", COLORS[color])
|
||||
@ -183,6 +184,7 @@ def demo_all(movehub):
|
||||
demo_color_sensor(movehub)
|
||||
demo_motor_sensors(movehub)
|
||||
|
||||
|
||||
DEMO_CHOICES = {
|
||||
'all': demo_all,
|
||||
'voltage': demo_voltage,
|
||||
@ -196,24 +198,26 @@ DEMO_CHOICES = {
|
||||
'motor_sensors': demo_motor_sensors,
|
||||
}
|
||||
|
||||
|
||||
def get_options():
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser(
|
||||
arg_parser = argparse.ArgumentParser(
|
||||
description='Demonstrate move-hub communications',
|
||||
)
|
||||
parser.add_argument(
|
||||
arg_parser.add_argument(
|
||||
'-c', '--connection',
|
||||
default='auto://',
|
||||
help='''Specify connection URL to use, `protocol://mac?param=X` with protocol in:
|
||||
"gatt","pygatt","gattlib","gattool", "bluepy","bluegiga"'''
|
||||
)
|
||||
parser.add_argument(
|
||||
arg_parser.add_argument(
|
||||
'-d', '--demo',
|
||||
default='all',
|
||||
choices=sorted(DEMO_CHOICES.keys()),
|
||||
help="Run a particular demo, default all"
|
||||
)
|
||||
return parser
|
||||
return arg_parser
|
||||
|
||||
|
||||
def connection_from_url(url):
|
||||
import pylgbst
|
||||
@ -224,10 +228,11 @@ def connection_from_url(url):
|
||||
except ImportError:
|
||||
from urlparse import urlparse, parse_qs
|
||||
parsed = urlparse(url)
|
||||
name = 'get_connection_%s'%(parsed.scheme)
|
||||
name = 'get_connection_%s' % parsed.scheme
|
||||
factory = getattr(pylgbst, name, None)
|
||||
if not factory:
|
||||
raise ValueError("Unrecognised URL scheme/protocol, expect a get_connection_<protocol> in pylgbst: %s"%(parsed.protocol))
|
||||
msg = "Unrecognised URL scheme/protocol, expect a get_connection_<protocol> in pylgbst: %s"
|
||||
raise ValueError(msg % parsed.protocol)
|
||||
params = {}
|
||||
if parsed.netloc.strip():
|
||||
params['hub_mac'] = parsed.netloc
|
||||
@ -240,6 +245,7 @@ def connection_from_url(url):
|
||||
**params
|
||||
)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
parser = get_options()
|
||||
@ -249,8 +255,7 @@ if __name__ == '__main__':
|
||||
connection = connection_from_url(options.connection)
|
||||
parameters['connection'] = connection
|
||||
except ValueError as err:
|
||||
parser.error(error.args[0])
|
||||
connection
|
||||
parser.error(err.args[0])
|
||||
|
||||
hub = MoveHub(**parameters)
|
||||
try:
|
||||
|
@ -1,4 +1,12 @@
|
||||
[
|
||||
[125, 64, 64],
|
||||
[145, 255, 250]
|
||||
[
|
||||
125,
|
||||
64,
|
||||
64
|
||||
],
|
||||
[
|
||||
145,
|
||||
255,
|
||||
250
|
||||
]
|
||||
]
|
@ -56,7 +56,6 @@ class GattoolConnection(Connection):
|
||||
return True
|
||||
|
||||
|
||||
|
||||
class BlueGigaConnection(GattoolConnection):
|
||||
def __init__(self):
|
||||
super(BlueGigaConnection, self).__init__()
|
||||
|
@ -622,7 +622,6 @@
|
||||
]
|
||||
]
|
||||
},
|
||||
|
||||
"LEDRGB on port 0x32": {
|
||||
"mode_count": 2,
|
||||
"input_modes": [],
|
||||
@ -694,7 +693,6 @@
|
||||
"can_input": false
|
||||
}
|
||||
},
|
||||
|
||||
"ColorDistanceSensor on port 0x1": {
|
||||
"mode_count": 11,
|
||||
"input_modes": [
|
||||
@ -1010,7 +1008,6 @@
|
||||
]
|
||||
]
|
||||
},
|
||||
|
||||
"TiltSensor on port 0x3a": {
|
||||
"mode_count": 8,
|
||||
"input_modes": [
|
||||
@ -1266,7 +1263,6 @@
|
||||
]
|
||||
]
|
||||
},
|
||||
|
||||
"Current on port 0x3b": {
|
||||
"mode_count": 2,
|
||||
"input_modes": [
|
||||
|
Loading…
x
Reference in New Issue
Block a user