Skip to content

Commit

Permalink
fix sphero toys incorrect listener commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
superfashi committed May 26, 2022
1 parent 7399f57 commit 2f11b4e
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 133 deletions.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@

setup(
name='spherov2',
version='0.10.2',
version='0.11',
author='Hanbang Wang', # and 'Elionardo Feliciano',
author_email='[email protected]', # and '[email protected]',
license='MIT',
description='An unofficial Bluetooth low energy library for Sphero toys in Python.',
long_description=long_desc,
long_description_content_type='text/markdown',
url='https://github.com/artificial-intelligence-class/spherov2.py',
packages=find_namespace_packages(include=['spherov2', 'spherov2.*']),
packages=find_namespace_packages(include=['spherov2', 'spherov2.*'],
exclude=["*.test", "*.test.*"]),
classifiers=[
'Development Status :: 4 - Beta',
'Framework :: Robot Framework :: Library',
Expand Down
84 changes: 3 additions & 81 deletions spherov2/toy/bb8.py
Original file line number Diff line number Diff line change
@@ -1,88 +1,10 @@
from enum import IntEnum
from enum import IntEnum
from functools import lru_cache

from spherov2.commands.core import Core
from spherov2.commands.sphero import Sphero
from spherov2.controls.v1 import FirmwareUpdateControl
from spherov2.toy.sphero import Sphero as SPHERO
from spherov2.toy.ollie import Ollie
from spherov2.types import ToyType


class BB8(SPHERO):
class BB8(Ollie):
toy_type = ToyType('BB-8', 'BB-', 'BB', .06)

# _send_uuid = '22bb746f-2ba1-7554-2d6f-726568705327'
# _response_uuid = '22bb746f-2ba6-7554-2d6f-726568705327'
# _handshake = [('22bb746f-2bbd-7554-2d6f-726568705327', bytearray(b'011i3')),
# ('22bb746f-2bb2-7554-2d6f-726568705327', bytearray([7]))]

class LEDs(IntEnum):
BODY_RED = 0
BODY_GREEN = 1
BODY_BLUE = 2
AIMING = 3
HEAD = 4

class Animations(IntEnum):
EMOTE_ALARM = 0
EMOTE_NO = 1
EMOTE_SCAN_SWEEP = 2
EMOTE_SCARED = 3
EMOTE_YES = 4
EMOTE_AFFIRMATIVE = 5
EMOTE_AGITATED = 6
EMOTE_ANGRY = 7
EMOTE_CONTENT = 8
EMOTE_EXCITED = 9
EMOTE_FIERY = 10
EMOTE_GREETINGS = 11
EMOTE_NERVOUS = 12
EMOTE_SLEEP = 14
EMOTE_SURPRISED = 15
EMOTE_UNDERSTOOD = 16
HIT = 17
WWM_ANGRY = 18
WWM_ANXIOUS = 19
WWM_BOW = 20
WWM_CURIOUS = 22
WWM_DOUBLE_TAKE = 23
WWM_EXCITED = 24
WWM_FIERY = 25
WWM_HAPPY = 26
WWM_JITTERY = 27
WWM_LAUGH = 28
WWM_LONG_SHAKE = 29
WWM_NO = 30
WWM_OMINOUS = 31
WWM_RELIEVED = 32
WWM_SAD = 33
WWM_SCARED = 34
WWM_SHAKE = 35
WWM_SURPRISED = 36
WWM_TAUNTING = 37
WWM_WHISPER = 38
WWM_YELLING = 39
WWM_YOOHOO = 40
WWM_FRUSTRATED = 41
IDLE_1 = 42
IDLE_2 = 43
IDLE_3 = 44
EYE_1 = 45
EYE_2 = 46
EYE_3 = 47
EYE_4 = 48

# Async - Sphero
# Bootloader - Sphero
# Core
get_factory_config_block_crc = Core.get_factory_config_block_crc # GetFactorConfigBlockCrcCommand

# Sphero
get_sku = Sphero.get_sku # GetSkuCommand

# Controls - Sphero
@property
@lru_cache(None)
def firmware_update_control(self):
return FirmwareUpdateControl(self)
get_factory_config_block_crc = Core.get_factory_config_block_crc
102 changes: 54 additions & 48 deletions spherov2/toy/sphero.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from collections import OrderedDict
from functools import partialmethod, lru_cache

from spherov2.commands.async_ import Async
from spherov2.commands.bootloader import Bootloader
from spherov2.commands.core import Core
from spherov2.commands.power import Power
from spherov2.commands.sensor import Sensor
from spherov2.commands.sphero import Sphero as SpheroCmd
from spherov2.controls.v1 import DriveControl, SensorControl
from spherov2.controls.v1 import DriveControl, SensorControl, StatsControl, FirmwareUpdateControl
from spherov2.toy import ToySensor, Toy
from spherov2.types import ToyType

Expand Down Expand Up @@ -60,72 +59,74 @@ def wake(self):

# Async
add_battery_state_changed_notify_listener = partialmethod(Toy._add_listener,
Power.battery_state_changed_notify) # BatteryStateChangedNotifyCommand
Async.battery_state_changed_notify)
remove_battery_state_changed_notify_listener = partialmethod(Toy._remove_listener,
Power.battery_state_changed_notify) # BatteryStateChangedNotifyCommand
Async.battery_state_changed_notify)
add_collision_detected_notify_listener = partialmethod(Toy._add_listener,
Sensor.collision_detected_notify) # CollisionDetectedNotifyCommand
Async.collision_detected_notify)
remove_collision_detected_notify_listener = partialmethod(Toy._remove_listener,
Sensor.collision_detected_notify) # CollisionDetectedNotifyCommand
add_did_sleep_notify_listener = partialmethod(Toy._add_listener, Power.did_sleep_notify) # DidSleepNotifyCommand
Async.collision_detected_notify)
add_did_sleep_notify_listener = partialmethod(Toy._add_listener,
Async.did_sleep_notify)
remove_did_sleep_notify_listener = partialmethod(Toy._remove_listener,
Power.did_sleep_notify) # DidSleepNotifyCommand
add_gyro_max_notify_listener = partialmethod(Toy._add_listener, Sensor.gyro_max_notify) # GyroMaxNotifyCommand
Async.did_sleep_notify)
add_gyro_max_notify_listener = partialmethod(Toy._add_listener,
Async.gyro_max_notify)
remove_gyro_max_notify_listener = partialmethod(Toy._remove_listener,
Sensor.gyro_max_notify) # GyroMaxNotifyCommand
Async.gyro_max_notify)
add_sensor_streaming_data_notify_listener = partialmethod(Toy._add_listener,
Sensor.sensor_streaming_data_notify) # SensorStreamingDataNotifyCommand
Async.sensor_streaming_data_notify)
remove_sensor_streaming_data_notify_listener = partialmethod(Toy._remove_listener,
Sensor.sensor_streaming_data_notify) # SensorStreamingDataNotifyCommand
add_will_sleep_notify_listener = partialmethod(Toy._add_listener, Power.will_sleep_notify) # WillSleepNotifyCommand
Async.sensor_streaming_data_notify)
add_will_sleep_notify_listener = partialmethod(Toy._add_listener,
Async.will_sleep_notify)
remove_will_sleep_notify_listener = partialmethod(Toy._remove_listener,
Power.will_sleep_notify) # WillSleepNotifyCommand
Async.will_sleep_notify)

# Bootloader
begin_reflash = Bootloader.begin_reflash # BeginReflashCommand
here_is_page = Bootloader.here_is_page # HereIsPageCommand
jump_to_main = Bootloader.jump_to_main # JumpToMainCommand
begin_reflash = Bootloader.begin_reflash
here_is_page = Bootloader.here_is_page
jump_to_main = Bootloader.jump_to_main

# Core
enable_battery_state_changed_notify = Core.enable_battery_state_changed_notify # EnableBatteryStateChangedNotifyCommand
get_bluetooth_info = Core.get_bluetooth_info # GetBluetoothInfoCommand
get_charger_state = Core.get_charger_state # GetChargerStateCommand
get_power_state = Core.get_power_state # GetPowerStateCommand
get_versions = Core.get_versions # GetVersionsCommand
jump_to_bootloader = Core.jump_to_bootloader # JumpToBootloaderCommand
ping = Core.ping # PingCommand
set_bluetooth_name = Core.set_bluetooth_name # SetBluetoothNameCommand
set_inactivity_timeout = Core.set_inactivity_timeout # SetInactivityTimeoutCommand
sleep = Core.sleep # SleepCommand
enable_battery_state_changed_notify = Core.enable_battery_state_changed_notify
get_bluetooth_info = Core.get_bluetooth_info
get_charger_state = Core.get_charger_state
get_power_state = Core.get_power_state
get_versions = Core.get_versions
jump_to_bootloader = Core.jump_to_bootloader
ping = Core.ping
set_bluetooth_name = Core.set_bluetooth_name
set_inactivity_timeout = Core.set_inactivity_timeout
sleep = Core.sleep

# Sphero
boost = SpheroCmd.boost # BoostCommand
configure_collision_detection = SpheroCmd.configure_collision_detection # ConfigureCollisionDetectionCommand
configure_locator = SpheroCmd.configure_locator # ConfigureLocatorCommand
get_chassis_id = SpheroCmd.get_chassis_id # GetChassisId
get_persistent_options = SpheroCmd.get_persistent_options # GetPersistentOptionsCommand
get_temperature = SpheroCmd.get_temperature # GetTemperatureCommand
set_temporary_options = SpheroCmd.set_temporary_options # GetTemporaryOptionsCommand
roll = SpheroCmd.roll # RollCommand
self_level = SpheroCmd.self_level # SelfLevelCommand
set_back_led_brightness = SpheroCmd.set_back_led_brightness # SetBackLedBrightnessCommand
set_data_streaming = SpheroCmd.set_data_streaming # SetDataSteamingCommand
set_heading = SpheroCmd.set_heading # SetHeadingCommand
set_main_led = SpheroCmd.set_main_led # SetMainLedCommand
set_motion_timeout = SpheroCmd.set_motion_timeout # SetMotionTimeoutCommand
set_persistent_options = SpheroCmd.set_persistent_options # SetPersistentOptionsCommand
set_raw_motors = SpheroCmd.set_raw_motors # SetRawMotorsCommand
set_rotation_rate = SpheroCmd.set_rotation_rate # SetRotationRateCommand
set_stabilization = SpheroCmd.set_stabilization # SetStabilizationCommand
set_temporary_options = SpheroCmd.set_temporary_options # SetTemporaryOptionsCommand
boost = SpheroCmd.boost
configure_collision_detection = SpheroCmd.configure_collision_detection
configure_locator = SpheroCmd.configure_locator
get_chassis_id = SpheroCmd.get_chassis_id
get_persistent_options = SpheroCmd.get_persistent_options
get_temperature = SpheroCmd.get_temperature
set_temporary_options = SpheroCmd.set_temporary_options
roll = SpheroCmd.roll
self_level = SpheroCmd.self_level
set_back_led_brightness = SpheroCmd.set_back_led_brightness
set_data_streaming = SpheroCmd.set_data_streaming
set_heading = SpheroCmd.set_heading
set_main_led = SpheroCmd.set_main_led
set_motion_timeout = SpheroCmd.set_motion_timeout
set_persistent_options = SpheroCmd.set_persistent_options
set_raw_motors = SpheroCmd.set_raw_motors
set_rotation_rate = SpheroCmd.set_rotation_rate
set_stabilization = SpheroCmd.set_stabilization

# Controls - V1
@property
@lru_cache(None)
def drive_control(self):
return DriveControl(self)

# The way utils.py is implemented this doesnt need to be present
# The way utils.py is implemented this doesn't need to be present
# @property
# @lru_cache(None)
# def multi_led_control(self):
Expand All @@ -140,3 +141,8 @@ def sensor_control(self):
@lru_cache(None)
def stats_control(self):
return StatsControl(self)

@property
@lru_cache(None)
def firmware_update_control(self):
return FirmwareUpdateControl(self)
4 changes: 2 additions & 2 deletions spherov2/toy/sprk2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from spherov2.toy.sphero import Sphero as SPHERO
from spherov2.toy.bb8 import BB8
from spherov2.types import ToyType


class Sprk2(SPHERO):
class Sprk2(BB8):
toy_type = ToyType('Sphero SPRK+', 'SK-', 'SK', .06)

0 comments on commit 2f11b4e

Please sign in to comment.