From e86f9513fcf944a41519b615aafd8dc99d937b1e Mon Sep 17 00:00:00 2001 From: SuperFashi Date: Fri, 3 Sep 2021 10:58:31 -0400 Subject: [PATCH] reformat code, bump version to 0.10, close #3 --- README.md | 6 +- docs/conf.py | 4 +- setup.py | 2 +- spherov2/adapter/tcp_adapter.py | 1 + spherov2/commands/async_.py | 1 - spherov2/commands/connection.py | 6 +- spherov2/commands/io.py | 7 +- spherov2/commands/system_info.py | 2 +- spherov2/scanner.py | 3 +- spherov2/sphero_edu.py | 25 +-- spherov2/test/BB8Test.py | 17 +- spherov2/test/BoltTest.py | 45 ++--- spherov2/test/MiniTest.py | 17 +- spherov2/toy/__init__.py | 22 +-- spherov2/toy/bb8.py | 46 ++--- spherov2/toy/bb9e.py | 70 ++++---- spherov2/toy/bolt.py | 291 ++++++++++++++++--------------- spherov2/toy/mini.py | 191 ++++++++++---------- spherov2/toy/sphero.py | 135 +++++++------- spherov2/toy/sprk2.py | 3 - spherov2/utils.py | 59 ++++--- 21 files changed, 480 insertions(+), 473 deletions(-) diff --git a/README.md b/README.md index cac49fd..dff0c61 100644 --- a/README.md +++ b/README.md @@ -9,9 +9,9 @@ An unofficial Python library for [Sphero](https://sphero.com/) toys that support - [x] Sphero BB-8 - [x] Sphero BB-9E - [x] Sphero R2-D2 / R2-Q5 -- [o] Sphero BOLT (In Progress) -- [ ] Sphero SPRK+ / SPRK 2.0 -- [ ] Sphero Mini +- [x] Sphero BOLT (In Progress) +- [x] Sphero SPRK+ / SPRK 2.0 +- [x] Sphero Mini - [x] Sphero RVR The logic is written based on reverse-engineering the official [Sphero Edu for Android](https://play.google.com/store/apps/details?id=com.sphero.sprk), with the help from available documentation and other unofficial community-based Sphero libraries like [igbopie/spherov2.js](https://github.com/igbopie/spherov2.js) and [EnotYoyo/pysphero](https://github.com/EnotYoyo/pysphero). diff --git a/docs/conf.py b/docs/conf.py index dce164a..f5a730b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,9 +24,9 @@ author = 'Hanbang Wang' # The short X.Y version -version = '0.9' +version = '0.10' # The full version, including alpha/beta/rc tags -release = '0.9' +release = '0.10' # -- General configuration --------------------------------------------------- diff --git a/setup.py b/setup.py index 0d608fa..ffbc691 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name='spherov2', - version='0.9', + version='0.10', author='Hanbang Wang', # and 'Elionardo Feliciano', author_email='hanbangw@cis.upenn.edu', # and 'elionardo.feliciano.dev@gmail.com', license='MIT', diff --git a/spherov2/adapter/tcp_adapter.py b/spherov2/adapter/tcp_adapter.py index 766c73a..1bda0a2 100644 --- a/spherov2/adapter/tcp_adapter.py +++ b/spherov2/adapter/tcp_adapter.py @@ -25,6 +25,7 @@ def recvall(s, size): def get_tcp_adapter(host: str, port: int = 50004): """Gets an anonymous ``TCPAdapter`` with the given address and port.""" + class TCPAdapter: @staticmethod def scan_toys(timeout=5.0): diff --git a/spherov2/commands/async_.py b/spherov2/commands/async_.py index b99b162..a1c6412 100644 --- a/spherov2/commands/async_.py +++ b/spherov2/commands/async_.py @@ -1,4 +1,3 @@ -from enum import IntEnum, IntFlag import struct from enum import IntEnum, IntFlag diff --git a/spherov2/commands/connection.py b/spherov2/commands/connection.py index f7b10f0..564eb46 100644 --- a/spherov2/commands/connection.py +++ b/spherov2/commands/connection.py @@ -1,6 +1,8 @@ -from enum import IntEnum, IntFlag +from enum import IntEnum + from spherov2.commands import Commands + class BleCentralStates(IntEnum): NOT_YET_INITIALIZED = 0 DISCONNECTED = 1 @@ -10,7 +12,7 @@ class BleCentralStates(IntEnum): CONNECTED = 5 DISCONNECTING = 6 CONFIGURING = 7 - + class BleCentralStates(IntEnum): NOT_YET_INITIALIZED = 0 diff --git a/spherov2/commands/io.py b/spherov2/commands/io.py index 46f3416..d596baf 100644 --- a/spherov2/commands/io.py +++ b/spherov2/commands/io.py @@ -155,9 +155,10 @@ def set_compressed_frame_player_frame_rotation(toy, b_arr, j, b, proc=None): # @staticmethod def set_compressed_frame_player_text_scrolling(toy, b_arr, j, b, proc=None): # Untested / Unknown Param Names toy._execute(IO._encode(toy, 59, proc, [*b_arr, j, b])) - - set_compressed_frame_player_text_scrolling_notify = (26, 60, 0xff), lambda listener, p: listener(p.data[0]) # Untested / Unknown Param Names - + + set_compressed_frame_player_text_scrolling_notify = (26, 60, 0xff), lambda listener, p: listener( + p.data[0]) # Untested / Unknown Param Names + @staticmethod def draw_compressed_frame_player_line(toy, x1, y1, x2, y2, r, g, b, proc=None): toy._execute(IO._encode(toy, 61, proc, [x1, y1, x2, y2, r, g, b])) diff --git a/spherov2/commands/system_info.py b/spherov2/commands/system_info.py index 44089a3..cedb6f1 100644 --- a/spherov2/commands/system_info.py +++ b/spherov2/commands/system_info.py @@ -56,7 +56,7 @@ def get_board_revision(toy, proc=None): @staticmethod def get_mac_address(toy, proc=None): return toy._execute(SystemInfo._encode(toy, 6, proc)).data - + @staticmethod def get_model_number(toy, proc=None): return toy._execute(SystemInfo._encode(toy, 18, proc)).data diff --git a/spherov2/scanner.py b/spherov2/scanner.py index d8f8c2a..66192fe 100644 --- a/spherov2/scanner.py +++ b/spherov2/scanner.py @@ -6,12 +6,13 @@ from spherov2.toy import Toy from spherov2.toy.bb8 import BB8 from spherov2.toy.bb9e import BB9E +from spherov2.toy.bolt import BOLT from spherov2.toy.mini import Mini from spherov2.toy.ollie import Ollie from spherov2.toy.r2d2 import R2D2 from spherov2.toy.r2q5 import R2Q5 from spherov2.toy.rvr import RVR -from spherov2.toy.bolt import BOLT + class ToyNotFoundError(Exception): ... diff --git a/spherov2/sphero_edu.py b/spherov2/sphero_edu.py index 587fe89..c1d468b 100644 --- a/spherov2/sphero_edu.py +++ b/spherov2/sphero_edu.py @@ -385,30 +385,33 @@ def strobe(self, color: Color, period: float, count: int): time.sleep(period) # TODO Sphero BOLT Lights - def set_matrix_pixel(self, x:int, y:int, color: Color): + def set_matrix_pixel(self, x: int, y: int, color: Color): """For Sphero BOLT: Changes the color of BOLT's matrix at X and Y value. 8x8 """ - strMapLoc:str = str(x) + ':' + str(y) - self.__leds[strMapLoc] = bound_color(color, self.__leds[strMapLoc]) #TODO: Do this in a way that works with line and fill + strMapLoc: str = str(x) + ':' + str(y) + self.__leds[strMapLoc] = bound_color(color, self.__leds[ + strMapLoc]) # TODO: Do this in a way that works with line and fill ToyUtil.set_matrix_pixel(self.__toy, x, y, **self.__leds[strMapLoc]._asdict(), is_user_color=False) def set_matrix_line(self, x1: int, y1: int, x2: int, y2: int, color: Color): """For Sphero BOLT: Changes the color of BOLT's matrix from x1,y1 to x2,y2 in a line. 8x8 """ - strMapLoc:str = str(x1) + 'x' + str(y1) + '|' + str(x2) + 'x' + str(y2) - self.__leds[strMapLoc] = bound_color(color, self.__leds[strMapLoc]) #TODO: Do this in a way that works with pixel and fill (needs to be accurate to diagonal lines) + strMapLoc: str = str(x1) + 'x' + str(y1) + '|' + str(x2) + 'x' + str(y2) + self.__leds[strMapLoc] = bound_color(color, self.__leds[ + strMapLoc]) # TODO: Do this in a way that works with pixel and fill (needs to be accurate to diagonal lines) ToyUtil.set_matrix_line(self.__toy, x1, y1, x2, y2, **self.__leds[strMapLoc]._asdict(), is_user_color=False) - + def set_matrix_fill(self, x1: int, y1: int, x2: int, y2: int, color: Color): """For Sphero BOLT: Changes the color of BOLT's matrix from x1,y1 to x2,y2 in a box. 8x8 """ - strMapLoc:str = str(x1) + 'x' + str(y1) + '[]' + str(x2) + 'x' + str(y2) - self.__leds[strMapLoc] = bound_color(color, self.__leds[strMapLoc]) #TODO: Do this in a way that works with pixel and line + strMapLoc: str = str(x1) + 'x' + str(y1) + '[]' + str(x2) + 'x' + str(y2) + self.__leds[strMapLoc] = bound_color(color, self.__leds[ + strMapLoc]) # TODO: Do this in a way that works with pixel and line ToyUtil.set_matrix_fill(self.__toy, x1, y1, x2, y2, **self.__leds[strMapLoc]._asdict(), is_user_color=False) - - def register_matrix_animation(self, s, s2, z, s3, s_arr, i, i_arr): #TODO: fix this function + + def register_matrix_animation(self, s, s2, z, s3, s_arr, i, i_arr): # TODO: fix this function ToyUtil.register_matrix_animation(self.__toy, s, s2, z, s3, s_arr, i, i_arr); - + def play_matrix_animation(self, s): ToyUtil.play_matrix_animation(self.__toy, s); diff --git a/spherov2/test/BB8Test.py b/spherov2/test/BB8Test.py index 489ce4a..429e014 100644 --- a/spherov2/test/BB8Test.py +++ b/spherov2/test/BB8Test.py @@ -1,5 +1,6 @@ -#python3 +# python3 import time + from spherov2 import scanner from spherov2.sphero_edu import SpheroEduAPI from spherov2.types import Color @@ -11,15 +12,15 @@ print("Connected.") with SpheroEduAPI(toy) as droid: print("Testing Main LED") - droid.set_main_led(Color(r=255, g=0, b=0)) #Sets Main LED + droid.set_main_led(Color(r=255, g=0, b=0)) # Sets Main LED time.sleep(1) - + print("Testing Aiming LED") - droid.set_back_led(255) #Sets Aiming light on + droid.set_back_led(255) # Sets Aiming light on time.sleep(1) - + print("Testing Roll") - droid.roll(0,100,5) + droid.roll(0, 100, 5) time.sleep(1) - - print("Testing End!") \ No newline at end of file + + print("Testing End!") diff --git a/spherov2/test/BoltTest.py b/spherov2/test/BoltTest.py index b86a8cf..ef58083 100644 --- a/spherov2/test/BoltTest.py +++ b/spherov2/test/BoltTest.py @@ -1,5 +1,6 @@ -#python3 +# python3 import time + from spherov2 import scanner from spherov2.sphero_edu import SpheroEduAPI from spherov2.types import Color @@ -11,36 +12,36 @@ print("Connected.") with SpheroEduAPI(toy) as droid: print("Testing Main LED") - droid.set_main_led(Color(r=0, g=0, b=255)) #Sets whole Matrix + droid.set_main_led(Color(r=0, g=0, b=255)) # Sets whole Matrix time.sleep(1) print("Testing Front LED") - droid.set_front_led(Color(r=0, g=255, b=0)) #Sets front LED + droid.set_front_led(Color(r=0, g=255, b=0)) # Sets front LED time.sleep(1) print("Testing Back LED") - droid.set_back_led(Color(r=255, g=0, b=0)) #Sets back LED + droid.set_back_led(Color(r=255, g=0, b=0)) # Sets back LED time.sleep(1) print("Set Matrix Pixel") - droid.set_matrix_pixel(0, 0, Color(r=255, g=255, b=0)) #Set Matrix Pixel + droid.set_matrix_pixel(0, 0, Color(r=255, g=255, b=0)) # Set Matrix Pixel time.sleep(1) print("Set Matrix Line") - droid.set_matrix_line(1, 0, 1, 7, Color(r=255, g=0, b=255)) #Set Matrix Line + droid.set_matrix_line(1, 0, 1, 7, Color(r=255, g=0, b=255)) # Set Matrix Line time.sleep(1) print("Set Matrix Fill") - droid.set_matrix_fill(2, 0, 6, 6, Color(r=0, g=255, b=255)) #Set Matrix Box + droid.set_matrix_fill(2, 0, 6, 6, Color(r=0, g=255, b=255)) # Set Matrix Box time.sleep(2) print("Testing End!") - - #Smile (manual) - #droid.set_main_led(Color(r=0, g=0, b=0)) #Sets whole Matrix - #droid.set_matrix_line(2, 7, 5, 7, Color(r=255, g=0, b=255)) #Set Matrix Line - #droid.set_matrix_line(1, 6, 6, 6, Color(r=255, g=0, b=255)) #Set Matrix Line - #droid.set_matrix_line(0, 5, 1, 5, Color(r=255, g=0, b=255)) #Set Matrix Line - #droid.set_matrix_line(3, 5, 4, 5, Color(r=255, g=0, b=255)) #Set Matrix Line - #droid.set_matrix_line(6, 5, 7, 5, Color(r=255, g=0, b=255)) #Set Matrix Line - #droid.set_matrix_line(0, 4, 7, 4, Color(r=255, g=0, b=255)) #Set Matrix Line - #droid.set_matrix_line(0, 3, 7, 3, Color(r=255, g=0, b=255)) #Set Matrix Line - #droid.set_matrix_pixel(0, 2, Color(r=255, g=0, b=255)) #Set Matrix Pixel - #droid.set_matrix_pixel(7, 2, Color(r=255, g=0, b=255)) #Set Matrix Pixel - #droid.set_matrix_pixel(1, 1, Color(r=255, g=0, b=255)) #Set Matrix Pixel - #droid.set_matrix_pixel(6, 1, Color(r=255, g=0, b=255)) #Set Matrix Pixel - #droid.set_matrix_line(2, 0, 5, 0, Color(r=255, g=0, b=255)) #Set Matrix Line + + # Smile (manual) + # droid.set_main_led(Color(r=0, g=0, b=0)) #Sets whole Matrix + # droid.set_matrix_line(2, 7, 5, 7, Color(r=255, g=0, b=255)) #Set Matrix Line + # droid.set_matrix_line(1, 6, 6, 6, Color(r=255, g=0, b=255)) #Set Matrix Line + # droid.set_matrix_line(0, 5, 1, 5, Color(r=255, g=0, b=255)) #Set Matrix Line + # droid.set_matrix_line(3, 5, 4, 5, Color(r=255, g=0, b=255)) #Set Matrix Line + # droid.set_matrix_line(6, 5, 7, 5, Color(r=255, g=0, b=255)) #Set Matrix Line + # droid.set_matrix_line(0, 4, 7, 4, Color(r=255, g=0, b=255)) #Set Matrix Line + # droid.set_matrix_line(0, 3, 7, 3, Color(r=255, g=0, b=255)) #Set Matrix Line + # droid.set_matrix_pixel(0, 2, Color(r=255, g=0, b=255)) #Set Matrix Pixel + # droid.set_matrix_pixel(7, 2, Color(r=255, g=0, b=255)) #Set Matrix Pixel + # droid.set_matrix_pixel(1, 1, Color(r=255, g=0, b=255)) #Set Matrix Pixel + # droid.set_matrix_pixel(6, 1, Color(r=255, g=0, b=255)) #Set Matrix Pixel + # droid.set_matrix_line(2, 0, 5, 0, Color(r=255, g=0, b=255)) #Set Matrix Line diff --git a/spherov2/test/MiniTest.py b/spherov2/test/MiniTest.py index 489ce4a..429e014 100644 --- a/spherov2/test/MiniTest.py +++ b/spherov2/test/MiniTest.py @@ -1,5 +1,6 @@ -#python3 +# python3 import time + from spherov2 import scanner from spherov2.sphero_edu import SpheroEduAPI from spherov2.types import Color @@ -11,15 +12,15 @@ print("Connected.") with SpheroEduAPI(toy) as droid: print("Testing Main LED") - droid.set_main_led(Color(r=255, g=0, b=0)) #Sets Main LED + droid.set_main_led(Color(r=255, g=0, b=0)) # Sets Main LED time.sleep(1) - + print("Testing Aiming LED") - droid.set_back_led(255) #Sets Aiming light on + droid.set_back_led(255) # Sets Aiming light on time.sleep(1) - + print("Testing Roll") - droid.roll(0,100,5) + droid.roll(0, 100, 5) time.sleep(1) - - print("Testing End!") \ No newline at end of file + + print("Testing End!") diff --git a/spherov2/toy/__init__.py b/spherov2/toy/__init__.py index 883469b..186949f 100644 --- a/spherov2/toy/__init__.py +++ b/spherov2/toy/__init__.py @@ -126,14 +126,14 @@ class ToyV2(Toy): _packet = PacketV2 _handshake = [] _response_uuid = _send_uuid = '00010002-574f-4f20-5370-6865726f2121' - #_response_uuid = _send_uuid = '00010002-574f-4f20-5370-6865726f2121' #Available responses - #_response_uuid = _send_uuid = '00010003-574f-4f20-5370-6865726f2121' - #_response_uuid = _send_uuid = '00020004-574f-4f20-5370-6865726f2121' - #_response_uuid = _send_uuid = '00020005-574f-4f20-5370-6865726f2121' - #_response_uuid = _send_uuid = '00020002-574f-4f20-5370-6865726f2121' - #_response_uuid = _send_uuid = '22bb746f-2bbd-7554-2d6f-726568705327' - #_response_uuid = _send_uuid = '22bb746f-2bb2-7554-2d6f-726568705327' - #_response_uuid = _send_uuid = '22bb746f-2bbf-7554-2d6f-726568705327' - #_response_uuid = _send_uuid = '22bb746f-2ba1-7554-2d6f-726568705327' - #_response_uuid = _send_uuid = '22bb746f-2ba6-7554-2d6f-726568705327' - #_response_uuid = _send_uuid = '22bb746f-2bb0-7554-2d6f-726568705327' + # _response_uuid = _send_uuid = '00010002-574f-4f20-5370-6865726f2121' #Available responses + # _response_uuid = _send_uuid = '00010003-574f-4f20-5370-6865726f2121' + # _response_uuid = _send_uuid = '00020004-574f-4f20-5370-6865726f2121' + # _response_uuid = _send_uuid = '00020005-574f-4f20-5370-6865726f2121' + # _response_uuid = _send_uuid = '00020002-574f-4f20-5370-6865726f2121' + # _response_uuid = _send_uuid = '22bb746f-2bbd-7554-2d6f-726568705327' + # _response_uuid = _send_uuid = '22bb746f-2bb2-7554-2d6f-726568705327' + # _response_uuid = _send_uuid = '22bb746f-2bbf-7554-2d6f-726568705327' + # _response_uuid = _send_uuid = '22bb746f-2ba1-7554-2d6f-726568705327' + # _response_uuid = _send_uuid = '22bb746f-2ba6-7554-2d6f-726568705327' + # _response_uuid = _send_uuid = '22bb746f-2bb0-7554-2d6f-726568705327' diff --git a/spherov2/toy/bb8.py b/spherov2/toy/bb8.py index 3ecd7aa..72880b4 100644 --- a/spherov2/toy/bb8.py +++ b/spherov2/toy/bb8.py @@ -1,33 +1,29 @@ -from collections import OrderedDict from enum import IntEnum -from functools import partialmethod, lru_cache +from enum import IntEnum +from functools import 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 -from spherov2.controls.v1 import DriveControl, FirmwareUpdateControl, LedControl, SensorControl, StatsControl -from spherov2.toy import ToyV2, ToySensor, Toy +from spherov2.controls.v1 import FirmwareUpdateControl from spherov2.toy.sphero import Sphero as SPHERO from spherov2.types import ToyType class BB8(SPHERO): 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')), + + # _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 @@ -76,21 +72,17 @@ class Animations(IntEnum): 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 + + # 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) - diff --git a/spherov2/toy/bb9e.py b/spherov2/toy/bb9e.py index f36291a..5c43d1d 100644 --- a/spherov2/toy/bb9e.py +++ b/spherov2/toy/bb9e.py @@ -114,53 +114,46 @@ class Animations(IntEnum): z=ToySensor(0x800000, -20000., 20000.) ) ) - - #Animatronic + + # Animatronic play_animation = Animatronic.play_animation stop_animation = Animatronic.stop_animation enable_idle_animations = Animatronic.enable_idle_animations enable_trophy_mode = Animatronic.enable_trophy_mode get_trophy_mode_enabled = Animatronic.get_trophy_mode_enabled - - - #APIAndShell + + # APIAndShell ping = ApiAndShell.ping get_api_protocol_version = ApiAndShell.get_api_protocol_version send_command_to_shell = ApiAndShell.send_command_to_shell add_send_string_to_console_listener = partialmethod(Toy._add_listener, ApiAndShell.send_string_to_console) remove_send_string_to_console_listener = partialmethod(Toy._remove_listener, ApiAndShell.send_string_to_console) - - - #Connection + + # Connection set_bluetooth_name = Connection.set_bluetooth_name get_bluetooth_name = Connection.get_bluetooth_name - - - #Drive + + # Drive set_raw_motors = Drive.set_raw_motors reset_yaw = Drive.reset_yaw drive_with_heading = Drive.drive_with_heading set_stabilization = Drive.set_stabilization - - - #FactoryTest + + # FactoryTest get_factory_mode_challenge = FactoryTest.get_factory_mode_challenge enter_factory_mode = FactoryTest.enter_factory_mode exit_factory_mode = FactoryTest.exit_factory_mode get_chassis_id = FactoryTest.get_chassis_id - - - #Firmware + + # Firmware get_pending_update_flags = Firmware.get_pending_update_flags - - - #IO + + # IO play_audio_file = IO.play_audio_file set_all_leds_with_16_bit_mask = IO.set_all_leds_with_16_bit_mask start_idle_led_animation = IO.start_idle_led_animation - - - #Sensor + + # Sensor set_sensor_streaming_mask = Sensor.set_sensor_streaming_mask get_sensor_streaming_mask = Sensor.get_sensor_streaming_mask add_sensor_streaming_data_notify_listener = partialmethod(Toy._add_listener, Sensor.sensor_streaming_data_notify) @@ -185,9 +178,8 @@ class Animations(IntEnum): enable_gyro_activity_notify = Sensor.enable_gyro_activity_notify add_gyro_activity_notify_listener = partialmethod(Toy._add_listener, Sensor.gyro_activity_notify) remove_gyro_activity_notify_listener = partialmethod(Toy._remove_listener, Sensor.gyro_activity_notify) - - - #Power + + # Power enter_deep_sleep = Power.enter_deep_sleep sleep = Power.sleep get_battery_voltage = Power.get_battery_voltage @@ -206,30 +198,32 @@ class Animations(IntEnum): Power.battery_voltage_state_change_notify) remove_battery_voltage_state_change_notify_listener = partialmethod(Toy._remove_listener, Power.battery_voltage_state_change_notify) - - - #SystemInfo + + # SystemInfo get_main_app_version = SystemInfo.get_main_app_version get_bootloader_version = SystemInfo.get_bootloader_version get_board_revision = SystemInfo.get_board_revision get_mac_address = SystemInfo.get_mac_address get_stats_id = SystemInfo.get_stats_id get_secondary_main_app_version = SystemInfo.get_secondary_main_app_version - add_secondary_main_app_version_notify_listener = partialmethod(Toy._add_listener, SystemInfo.secondary_main_app_version_notify) - remove_secondary_main_app_version_notify_listener = partialmethod(Toy._remove_listener, SystemInfo.secondary_main_app_version_notify) + add_secondary_main_app_version_notify_listener = partialmethod(Toy._add_listener, + SystemInfo.secondary_main_app_version_notify) + remove_secondary_main_app_version_notify_listener = partialmethod(Toy._remove_listener, + SystemInfo.secondary_main_app_version_notify) get_processor_name = SystemInfo.get_processor_name get_secondary_mcu_bootloader_version = SystemInfo.get_secondary_mcu_bootloader_version - add_get_secondary_mcu_bootloader_version_notify_listener = partialmethod(Toy._add_listener, SystemInfo.secondary_mcu_bootloader_version_notify) - remove_get_secondary_mcu_bootloader_version_notify_listener = partialmethod(Toy._remove_listener, SystemInfo.secondary_mcu_bootloader_version_notify) + add_get_secondary_mcu_bootloader_version_notify_listener = partialmethod(Toy._add_listener, + SystemInfo.secondary_mcu_bootloader_version_notify) + remove_get_secondary_mcu_bootloader_version_notify_listener = partialmethod(Toy._remove_listener, + SystemInfo.secondary_mcu_bootloader_version_notify) get_three_character_sku = SystemInfo.get_three_character_sku - - - #Controls + + # Controls @property @lru_cache(None) def drive_control(self): return DriveControl(self) - + @property @lru_cache(None) def firmware_update_control(self): @@ -244,7 +238,7 @@ def multi_led_control(self): @lru_cache(None) def sensor_control(self): return SensorControl(self) - + @property @lru_cache(None) def stats_control(self): diff --git a/spherov2/toy/bolt.py b/spherov2/toy/bolt.py index 90c0145..cf28ff6 100644 --- a/spherov2/toy/bolt.py +++ b/spherov2/toy/bolt.py @@ -2,17 +2,16 @@ from enum import IntEnum from functools import partialmethod, lru_cache -from spherov2.commands.animatronic import Animatronic from spherov2.commands.api_and_shell import ApiAndShell from spherov2.commands.connection import Connection from spherov2.commands.drive import Drive -from spherov2.commands.factory_test import FactoryTest from spherov2.commands.firmware import Firmware from spherov2.commands.io import IO from spherov2.commands.power import Power from spherov2.commands.sensor import Sensor from spherov2.commands.system_info import SystemInfo -from spherov2.controls.v2 import AnimationControl, DriveControl, LedControl, SensorControl, StatsControl, StreamingControl, Processors +from spherov2.controls.v2 import AnimationControl, DriveControl, LedControl, SensorControl, StatsControl, \ + Processors from spherov2.toy import ToyV2, Toy, ToySensor from spherov2.types import ToyType @@ -29,7 +28,7 @@ class LEDs(IntEnum): BACK_GREEN = 4 BACK_BLUE = 5 - #Sensors Available: + # Sensors Available: sensors = OrderedDict( quaternion=OrderedDict( x=ToySensor(0x2000000, -1., 1.), @@ -67,181 +66,193 @@ class LEDs(IntEnum): z=ToySensor(0x800000, -20000., 20000.) ) ) - - -#Bolt Supported calls - #API and Shell: - get_api_protocol_version = ApiAndShell.get_api_protocol_version #GetApiProtocolVersionCommand - get_supported_cids = ApiAndShell.get_supported_cids #GetSupportedCidsCommand - get_supported_dids = ApiAndShell.get_supported_dids #GetSupportedDidsCommand - ping = ApiAndShell.ping #PingCommand - send_command_to_shell = ApiAndShell.send_command_to_shell #SendCommandToShellCommand - add_send_string_to_console_listener = partialmethod(Toy._add_listener, ApiAndShell.send_string_to_console) #SendStringToConsoleCommand - remove_send_string_to_console_listener = partialmethod(Toy._remove_listener, ApiAndShell.send_string_to_console) #SendStringToConsoleCommand - - - #Connection - get_bluetooth_advertising_name = Connection.get_bluetooth_advertising_name #GetBluetoothAdvertisingNameCommand - get_bluetooth_name = Connection.get_bluetooth_name #GetBluetoothNameCommand - set_bluetooth_name = Connection.set_bluetooth_name #SetBluetoothNameCommand - - - #Drive - drive_with_heading = Drive.drive_with_heading #DriveWithHeadingCommand - reset_yaw = Drive.reset_yaw #ResetYawCommand - set_pitch_torque_modification_value = Drive.set_pitch_torque_modification_value #SetPitchTorqueModificationValueCommand - set_raw_motors = Drive.set_raw_motors #SetRawMotorsCommand - set_stabilization = Drive.set_stabilization #SetStabilizationCommand - - - #Firmware - get_pending_update_flags = Firmware.get_pending_update_flags #GetPendingUpdateFlagsCommand - - - #IO - most LED/Matrix stuff is done on Secondary Processor, if issues check that - assign_compressed_frame_player_frames_to_animation = partialmethod(IO.assign_compressed_frame_player_frames_to_animation, - proc=Processors.SECONDARY) #AssignCompressedFramePlayerFramesToAnimationCommand + + # Bolt Supported calls + # API and Shell: + get_api_protocol_version = ApiAndShell.get_api_protocol_version # GetApiProtocolVersionCommand + get_supported_cids = ApiAndShell.get_supported_cids # GetSupportedCidsCommand + get_supported_dids = ApiAndShell.get_supported_dids # GetSupportedDidsCommand + ping = ApiAndShell.ping # PingCommand + send_command_to_shell = ApiAndShell.send_command_to_shell # SendCommandToShellCommand + add_send_string_to_console_listener = partialmethod(Toy._add_listener, + ApiAndShell.send_string_to_console) # SendStringToConsoleCommand + remove_send_string_to_console_listener = partialmethod(Toy._remove_listener, + ApiAndShell.send_string_to_console) # SendStringToConsoleCommand + + # Connection + get_bluetooth_advertising_name = Connection.get_bluetooth_advertising_name # GetBluetoothAdvertisingNameCommand + get_bluetooth_name = Connection.get_bluetooth_name # GetBluetoothNameCommand + set_bluetooth_name = Connection.set_bluetooth_name # SetBluetoothNameCommand + + # Drive + drive_with_heading = Drive.drive_with_heading # DriveWithHeadingCommand + reset_yaw = Drive.reset_yaw # ResetYawCommand + set_pitch_torque_modification_value = Drive.set_pitch_torque_modification_value # SetPitchTorqueModificationValueCommand + set_raw_motors = Drive.set_raw_motors # SetRawMotorsCommand + set_stabilization = Drive.set_stabilization # SetStabilizationCommand + + # Firmware + get_pending_update_flags = Firmware.get_pending_update_flags # GetPendingUpdateFlagsCommand + + # IO - most LED/Matrix stuff is done on Secondary Processor, if issues check that + assign_compressed_frame_player_frames_to_animation = partialmethod( + IO.assign_compressed_frame_player_frames_to_animation, + proc=Processors.SECONDARY) # AssignCompressedFramePlayerFramesToAnimationCommand add_compressed_frame_player_animation_complete_notify_listener = partialmethod( - Toy._add_listener, IO.compressed_frame_player_animation_complete_notify) #CompressedFramePlayerAnimationCompleteNotifyCommand + Toy._add_listener, + IO.compressed_frame_player_animation_complete_notify) # CompressedFramePlayerAnimationCompleteNotifyCommand remove_compressed_frame_player_animation_complete_notify_listener = partialmethod( - Toy._remove_listener, IO.compressed_frame_player_animation_complete_notify) #CompressedFramePlayerAnimationCompleteNotifyCommand - delete_all_compressed_frame_player_animations_and_frames = partialmethod(IO.delete_all_compressed_frame_player_animations_and_frames, - proc=Processors.SECONDARY) #DeleteAllCompressedFramePlayerAnimationsAndFramesCommand + Toy._remove_listener, + IO.compressed_frame_player_animation_complete_notify) # CompressedFramePlayerAnimationCompleteNotifyCommand + delete_all_compressed_frame_player_animations_and_frames = partialmethod( + IO.delete_all_compressed_frame_player_animations_and_frames, + proc=Processors.SECONDARY) # DeleteAllCompressedFramePlayerAnimationsAndFramesCommand draw_compressed_frame_player_fill = partialmethod(IO.draw_compressed_frame_player_fill, - proc=Processors.SECONDARY) #DrawCompressedFramePlayerFillCommand + proc=Processors.SECONDARY) # DrawCompressedFramePlayerFillCommand draw_compressed_frame_player_line = partialmethod(IO.draw_compressed_frame_player_line, - proc=Processors.SECONDARY) #DrawCompressedFramePlayerLineCommand + proc=Processors.SECONDARY) # DrawCompressedFramePlayerLineCommand get_compressed_frame_player_list_of_frames = partialmethod(IO.get_compressed_frame_player_list_of_frames, - proc=Processors.SECONDARY) #GetCompressedFramePlayerListOfFramesCommand - override_compressed_frame_player_animation_global_settings = partialmethod(IO.override_compressed_frame_player_animation_global_settings, - proc=Processors.SECONDARY) #OverrideCompressedFramePlayerAnimationGlobalSettingsCommand + proc=Processors.SECONDARY) # GetCompressedFramePlayerListOfFramesCommand + override_compressed_frame_player_animation_global_settings = partialmethod( + IO.override_compressed_frame_player_animation_global_settings, + proc=Processors.SECONDARY) # OverrideCompressedFramePlayerAnimationGlobalSettingsCommand pause_compressed_frame_player_animation = partialmethod(IO.pause_compressed_frame_player_animation, - proc=Processors.SECONDARY) #PauseCompressedFramePlayerAnimationCommand + proc=Processors.SECONDARY) # PauseCompressedFramePlayerAnimationCommand play_compressed_frame_player_animation = partialmethod(IO.play_compressed_frame_player_animation, - proc=Processors.SECONDARY) #PlayCompressedFramePlayerAnimationCommand - play_compressed_frame_player_animation_with_loop_option = partialmethod(IO.play_compressed_frame_player_animation_with_loop_option, - proc=Processors.SECONDARY) #PlayCompressedFramePlayerAnimationWithLoopOptionCommand + proc=Processors.SECONDARY) # PlayCompressedFramePlayerAnimationCommand + play_compressed_frame_player_animation_with_loop_option = partialmethod( + IO.play_compressed_frame_player_animation_with_loop_option, + proc=Processors.SECONDARY) # PlayCompressedFramePlayerAnimationWithLoopOptionCommand play_compressed_frame_player_frame = partialmethod(IO.play_compressed_frame_player_frame, - proc=Processors.SECONDARY) #PlayCompressedFramePlayerFrameCommand + proc=Processors.SECONDARY) # PlayCompressedFramePlayerFrameCommand reset_compressed_frame_player_animation = partialmethod(IO.reset_compressed_frame_player_animation, - proc=Processors.SECONDARY) #ResetCompressedFramePlayerAnimationCommand + proc=Processors.SECONDARY) # ResetCompressedFramePlayerAnimationCommand resume_compressed_frame_player_animation = partialmethod(IO.resume_compressed_frame_player_animation, - proc=Processors.SECONDARY) #ResumeCompressedFramePlayerAnimationCommand + proc=Processors.SECONDARY) # ResumeCompressedFramePlayerAnimationCommand save_compressed_frame_player64_bit_frame = partialmethod(IO.save_compressed_frame_player64_bit_frame, - proc=Processors.SECONDARY) #SaveCompressedFramePlayer64BitFrameCommand + proc=Processors.SECONDARY) # SaveCompressedFramePlayer64BitFrameCommand save_compressed_frame_player_animation = partialmethod(IO.save_compressed_frame_player_animation, - proc=Processors.SECONDARY) #SaveCompressedFramePlayerAnimationCommand - save_compressed_frame_player_animation_without_frames = partialmethod(IO.save_compressed_frame_player_animation_without_frames, - proc=Processors.SECONDARY) #SaveCompressedFramePlayerAnimationWithoutFramesCommand + proc=Processors.SECONDARY) # SaveCompressedFramePlayerAnimationCommand + save_compressed_frame_player_animation_without_frames = partialmethod( + IO.save_compressed_frame_player_animation_without_frames, + proc=Processors.SECONDARY) # SaveCompressedFramePlayerAnimationWithoutFramesCommand set_all_leds_with_8_bit_mask = partialmethod(IO.set_all_leds_with_8_bit_mask, - proc=Processors.PRIMARY) #SetAllLedsWith8BitMaskCommand + proc=Processors.PRIMARY) # SetAllLedsWith8BitMaskCommand set_compressed_frame_player = partialmethod(IO.set_compressed_frame_player, - proc=Processors.SECONDARY) #SetCompressedFramePlayerCommand + proc=Processors.SECONDARY) # SetCompressedFramePlayerCommand set_compressed_frame_player_frame_rotation = partialmethod(IO.set_compressed_frame_player_frame_rotation, - proc=Processors.SECONDARY) #SetCompressedFramePlayerFrameRotationCommand + proc=Processors.SECONDARY) # SetCompressedFramePlayerFrameRotationCommand set_compressed_frame_player_one_color = partialmethod(IO.set_compressed_frame_player_one_color, - proc=Processors.SECONDARY) #SetCompressedFramePlayerOneColorCommand + proc=Processors.SECONDARY) # SetCompressedFramePlayerOneColorCommand set_compressed_frame_player_pixel = partialmethod(IO.set_compressed_frame_player_pixel, - proc=Processors.SECONDARY) #SetCompressedFramePlayerPixelCommand + proc=Processors.SECONDARY) # SetCompressedFramePlayerPixelCommand set_compressed_frame_player_single_character = partialmethod(IO.set_compressed_frame_player_single_character, - proc=Processors.SECONDARY) #SetCompressedFramePlayerSingleCharacterCommand + proc=Processors.SECONDARY) # SetCompressedFramePlayerSingleCharacterCommand set_compressed_frame_player_text_scrolling = partialmethod(IO.set_compressed_frame_player_text_scrolling, - proc=Processors.SECONDARY) #SetCompressedFramePlayerTextScrollingCommand + proc=Processors.SECONDARY) # SetCompressedFramePlayerTextScrollingCommand add_compressed_frame_player_animation_complete_notify = partialmethod( - Toy._add_listener, IO.set_compressed_frame_player_text_scrolling_notify) #SetCompressedFramePlayerTextScrollingNotifyCommand + Toy._add_listener, + IO.set_compressed_frame_player_text_scrolling_notify) # SetCompressedFramePlayerTextScrollingNotifyCommand remove_compressed_frame_player_animation_complete_notify_listener = partialmethod( - Toy._remove_listener, IO.set_compressed_frame_player_text_scrolling_notify) #SetCompressedFramePlayerTextScrollingNotifyCommand - set_led = partialmethod(IO.set_led, proc = Processors.SECONDARY) #SetLedCommand - - #Testing + Toy._remove_listener, + IO.set_compressed_frame_player_text_scrolling_notify) # SetCompressedFramePlayerTextScrollingNotifyCommand + set_led = partialmethod(IO.set_led, proc=Processors.SECONDARY) # SetLedCommand + + # Testing release_led_requests = partialmethod(IO.release_led_requests, proc=Processors.PRIMARY) - - #Power + # Power add_will_sleep_notify_listener = partialmethod(Toy._add_listener, - Power.charger_state_changed_notify) #ChargerStateChangedNotifyCommand + Power.charger_state_changed_notify) # ChargerStateChangedNotifyCommand remove_will_sleep_notify_listener = partialmethod(Toy._remove_listener, - Power.charger_state_changed_notify) #ChargerStateChangedNotifyCommand + Power.charger_state_changed_notify) # ChargerStateChangedNotifyCommand add_will_sleep_notify_listener = partialmethod(Toy._add_listener, - Power.did_sleep_notify) #DidSleepNotifyCommand + Power.did_sleep_notify) # DidSleepNotifyCommand remove_will_sleep_notify_listener = partialmethod(Toy._remove_listener, - Power.did_sleep_notify) #DidSleepNotifyCommand - enable_battery_voltage_state_change_notify = Power.enable_battery_voltage_state_change_notify #EnableBatteryVoltageStateChangeNotifyCommand - enable_charger_state_changed_notify = Power.enable_charger_state_changed_notify #EnableChargerStateChangedNotifyCommand - enter_deep_sleep = Power.enter_deep_sleep #EnterDeepSleepCommand - get_battery_voltage = Power.get_battery_voltage #GetBatteryVoltageCommand - get_battery_voltage_state = Power.get_battery_voltage_state #GetBatteryVoltageStateCommand - get_charger_state = Power.get_charger_state #GetChargerStateCommand - sleep = Power.sleep #SleepCommand - wake = Power.wake #WakeCommand + Power.did_sleep_notify) # DidSleepNotifyCommand + enable_battery_voltage_state_change_notify = Power.enable_battery_voltage_state_change_notify # EnableBatteryVoltageStateChangeNotifyCommand + enable_charger_state_changed_notify = Power.enable_charger_state_changed_notify # EnableChargerStateChangedNotifyCommand + enter_deep_sleep = Power.enter_deep_sleep # EnterDeepSleepCommand + get_battery_voltage = Power.get_battery_voltage # GetBatteryVoltageCommand + get_battery_voltage_state = Power.get_battery_voltage_state # GetBatteryVoltageStateCommand + get_charger_state = Power.get_charger_state # GetChargerStateCommand + sleep = Power.sleep # SleepCommand + wake = Power.wake # WakeCommand add_will_sleep_notify_listener = partialmethod(Toy._add_listener, - Power.will_sleep_notify) #WillSleepNotifyCommand + Power.will_sleep_notify) # WillSleepNotifyCommand remove_will_sleep_notify_listener = partialmethod(Toy._remove_listener, - Power.will_sleep_notify) #WillSleepNotifyCommand - - - #Sensor - add_collision_detected_notify_listener = partialmethod(Toy._add_listener, Sensor.collision_detected_notify) #CollisionDetectedNotifyCommand - remove_collision_detected_notify_listener = partialmethod(Toy._remove_listener, Sensor.collision_detected_notify) #CollisionDetectedNotifyCommand - configure_collision_detection = Sensor.configure_collision_detection #ConfigureCollisionDetectionCommand - enable_gyro_max_notify = Sensor.enable_gyro_max_notify #EnableGyroMaxNotifyCommand - get_ambient_light_sensor_value = Sensor.get_ambient_light_sensor_value #GetAmbientLightSensorValueCommand - get_bot_to_bot_infrared_readings = Sensor.get_bot_to_bot_infrared_readings #GetBotToBotInfraredReadingsCommand - get_extended_sensor_streaming_mask = Sensor.get_extended_sensor_streaming_mask #GetExtendedSensorStreamingMaskCommand - set_sensor_streaming_mask = Sensor.set_sensor_streaming_mask #GetSensorStreamingMaskCommand - add_gyro_max_notify_listener = partialmethod(Toy._add_listener, Sensor.gyro_max_notify) #GyroMaxNotifyCommand - remove_gyro_max_notify_listener = partialmethod(Toy._remove_listener, Sensor.gyro_max_notify) #GyroMaxNotifyCommand - listen_for_robot_to_robot_infrared_message = Sensor.listen_for_robot_to_robot_infrared_message #ListenForRobotToRobotInfraredMessageCommand - magnetometer_calibrate_to_north = Sensor.magnetometer_calibrate_to_north #MagnetometerCalibrateToNorthCommand - add_magnetometer_north_yaw_notify_listener = partialmethod(Toy._add_listener, Sensor.magnetometer_north_yaw_notify) #MagnetometerNorthYawNotifyCommand - remove_magnetometer_north_yaw_notify_listener = partialmethod(Toy._remove_listener, Sensor.magnetometer_north_yaw_notify) #MagnetometerNorthYawNotifyCommand - reset_locator_x_and_y = Sensor.reset_locator_x_and_y #ResetLocationXAndYCommand - add_robot_to_robot_infrared_message_received_notify_listener = partialmethod(Toy._add_listener, Sensor.robot_to_robot_infrared_message_received_notify) ##RobotToRobotInfraredMessageReceivedNotifyCommand - remove_robot_to_robot_infrared_message_received_notify_listener = partialmethod(Toy._remove_listener, Sensor.robot_to_robot_infrared_message_received_notify) #RobotToRobotInfraredMessageReceivedNotifyCommand - send_robot_to_robot_infrared_message = Sensor.send_robot_to_robot_infrared_message #SendRobotToRobotInfraredMessageCommand - add_sensor_streaming_data_notify_listener = partialmethod(Toy._add_listener, Sensor.sensor_streaming_data_notify) #SensorStreamingDataNotifyCommand - remove_sensor_streaming_data_notify_listener = partialmethod(Toy._remove_listener, Sensor.sensor_streaming_data_notify) #SensorStreamingDataNotifyCommand - set_extended_sensor_streaming_mask = Sensor.set_extended_sensor_streaming_mask #SetExtendedSensorStreamingMaskCommand - set_locator_flags = Sensor.set_locator_flags #SetLocatorFlagsCommand - get_sensor_streaming_mask = Sensor.get_sensor_streaming_mask #SetSensorStreamingMaskCommand - start_robot_to_robot_infrared_broadcasting = Sensor.start_robot_to_robot_infrared_broadcasting #StartRobotToRobotInfraredBroadcastingCommand - start_robot_to_robot_infrared_evading = Sensor.start_robot_to_robot_infrared_evading #StartRobotToRobotInfraredEvadingCommand - start_robot_to_robot_infrared_following = Sensor.start_robot_to_robot_infrared_following #StartRobotToRobotInfraredFollowingCommand - stop_robot_to_robot_infrared_broadcasting = Sensor.stop_robot_to_robot_infrared_broadcasting #StopRobotToRobotInfraredBroadcastingCommand - stop_robot_to_robot_infrared_evading = Sensor.stop_robot_to_robot_infrared_evading #StopRobotToRobotInfraredEvadingCommand - stop_robot_to_robot_infrared_following = Sensor.stop_robot_to_robot_infrared_following #StopRobotToRobotInfraredFollowingCommand - + Power.will_sleep_notify) # WillSleepNotifyCommand - #System Info - erase_config_block = SystemInfo.erase_config_block #EraseConfigBlockCommand - get_board_revision = SystemInfo.get_board_revision #GetBoardRevisionCommand - get_boot_reason = SystemInfo.get_boot_reason #GetBootReasonCommand - get_bootloader_version = SystemInfo.get_bootloader_version #GetBootloaderVersionCommand + # Sensor + add_collision_detected_notify_listener = partialmethod(Toy._add_listener, + Sensor.collision_detected_notify) # CollisionDetectedNotifyCommand + remove_collision_detected_notify_listener = partialmethod(Toy._remove_listener, + Sensor.collision_detected_notify) # CollisionDetectedNotifyCommand + configure_collision_detection = Sensor.configure_collision_detection # ConfigureCollisionDetectionCommand + enable_gyro_max_notify = Sensor.enable_gyro_max_notify # EnableGyroMaxNotifyCommand + get_ambient_light_sensor_value = Sensor.get_ambient_light_sensor_value # GetAmbientLightSensorValueCommand + get_bot_to_bot_infrared_readings = Sensor.get_bot_to_bot_infrared_readings # GetBotToBotInfraredReadingsCommand + get_extended_sensor_streaming_mask = Sensor.get_extended_sensor_streaming_mask # GetExtendedSensorStreamingMaskCommand + set_sensor_streaming_mask = Sensor.set_sensor_streaming_mask # GetSensorStreamingMaskCommand + add_gyro_max_notify_listener = partialmethod(Toy._add_listener, Sensor.gyro_max_notify) # GyroMaxNotifyCommand + remove_gyro_max_notify_listener = partialmethod(Toy._remove_listener, + Sensor.gyro_max_notify) # GyroMaxNotifyCommand + listen_for_robot_to_robot_infrared_message = Sensor.listen_for_robot_to_robot_infrared_message # ListenForRobotToRobotInfraredMessageCommand + magnetometer_calibrate_to_north = Sensor.magnetometer_calibrate_to_north # MagnetometerCalibrateToNorthCommand + add_magnetometer_north_yaw_notify_listener = partialmethod(Toy._add_listener, + Sensor.magnetometer_north_yaw_notify) # MagnetometerNorthYawNotifyCommand + remove_magnetometer_north_yaw_notify_listener = partialmethod(Toy._remove_listener, + Sensor.magnetometer_north_yaw_notify) # MagnetometerNorthYawNotifyCommand + reset_locator_x_and_y = Sensor.reset_locator_x_and_y # ResetLocationXAndYCommand + add_robot_to_robot_infrared_message_received_notify_listener = partialmethod(Toy._add_listener, + Sensor.robot_to_robot_infrared_message_received_notify) ##RobotToRobotInfraredMessageReceivedNotifyCommand + remove_robot_to_robot_infrared_message_received_notify_listener = partialmethod(Toy._remove_listener, + Sensor.robot_to_robot_infrared_message_received_notify) # RobotToRobotInfraredMessageReceivedNotifyCommand + send_robot_to_robot_infrared_message = Sensor.send_robot_to_robot_infrared_message # SendRobotToRobotInfraredMessageCommand + add_sensor_streaming_data_notify_listener = partialmethod(Toy._add_listener, + Sensor.sensor_streaming_data_notify) # SensorStreamingDataNotifyCommand + remove_sensor_streaming_data_notify_listener = partialmethod(Toy._remove_listener, + Sensor.sensor_streaming_data_notify) # SensorStreamingDataNotifyCommand + set_extended_sensor_streaming_mask = Sensor.set_extended_sensor_streaming_mask # SetExtendedSensorStreamingMaskCommand + set_locator_flags = Sensor.set_locator_flags # SetLocatorFlagsCommand + get_sensor_streaming_mask = Sensor.get_sensor_streaming_mask # SetSensorStreamingMaskCommand + start_robot_to_robot_infrared_broadcasting = Sensor.start_robot_to_robot_infrared_broadcasting # StartRobotToRobotInfraredBroadcastingCommand + start_robot_to_robot_infrared_evading = Sensor.start_robot_to_robot_infrared_evading # StartRobotToRobotInfraredEvadingCommand + start_robot_to_robot_infrared_following = Sensor.start_robot_to_robot_infrared_following # StartRobotToRobotInfraredFollowingCommand + stop_robot_to_robot_infrared_broadcasting = Sensor.stop_robot_to_robot_infrared_broadcasting # StopRobotToRobotInfraredBroadcastingCommand + stop_robot_to_robot_infrared_evading = Sensor.stop_robot_to_robot_infrared_evading # StopRobotToRobotInfraredEvadingCommand + stop_robot_to_robot_infrared_following = Sensor.stop_robot_to_robot_infrared_following # StopRobotToRobotInfraredFollowingCommand + + # System Info + erase_config_block = SystemInfo.erase_config_block # EraseConfigBlockCommand + get_board_revision = SystemInfo.get_board_revision # GetBoardRevisionCommand + get_boot_reason = SystemInfo.get_boot_reason # GetBootReasonCommand + get_bootloader_version = SystemInfo.get_bootloader_version # GetBootloaderVersionCommand get_secondary_mcu_bootloader_version = SystemInfo.get_secondary_mcu_bootloader_version - get_config_block = SystemInfo.get_config_block #GetConfigBlockCommand - get_last_error_info = SystemInfo.get_last_error_info #GetLastErrorInfoCommand - get_mac_address = SystemInfo.get_mac_address #GetMacAddressCommand - get_main_app_version = SystemInfo.get_main_app_version #GetMainAppVersionCommand + get_config_block = SystemInfo.get_config_block # GetConfigBlockCommand + get_last_error_info = SystemInfo.get_last_error_info # GetLastErrorInfoCommand + get_mac_address = SystemInfo.get_mac_address # GetMacAddressCommand + get_main_app_version = SystemInfo.get_main_app_version # GetMainAppVersionCommand get_secondary_main_app_version = SystemInfo.get_secondary_main_app_version - get_manufacturing_date = SystemInfo.get_manufacturing_date #GetManufacturingDateCommand - get_processor_name = SystemInfo.get_processor_name #GetProcessorNameCommand - get_sku = SystemInfo.get_sku #GetSkuCommand - get_stats_id = SystemInfo.get_stats_id #GetStatsIdCommand - get_swd_locking_status = SystemInfo.get_swd_locking_status #GetSwdLockingStatusCommand - set_config_block = SystemInfo.set_config_block #SetConfigBlockCommand - write_config_block = SystemInfo.write_config_block #WriteConfigBlockCommand - - #Controls - V2 + get_manufacturing_date = SystemInfo.get_manufacturing_date # GetManufacturingDateCommand + get_processor_name = SystemInfo.get_processor_name # GetProcessorNameCommand + get_sku = SystemInfo.get_sku # GetSkuCommand + get_stats_id = SystemInfo.get_stats_id # GetStatsIdCommand + get_swd_locking_status = SystemInfo.get_swd_locking_status # GetSwdLockingStatusCommand + set_config_block = SystemInfo.set_config_block # SetConfigBlockCommand + write_config_block = SystemInfo.write_config_block # WriteConfigBlockCommand + + # Controls - V2 @property @lru_cache(None) def animation_control(self): return AnimationControl(self) - + @property @lru_cache(None) def drive_control(self): return DriveControl(self) - + @property @lru_cache(None) def multi_led_control(self): @@ -251,7 +262,7 @@ def multi_led_control(self): @lru_cache(None) def sensor_control(self): return SensorControl(self) - + @property @lru_cache(None) def stats_control(self): diff --git a/spherov2/toy/mini.py b/spherov2/toy/mini.py index 740077d..fb007b8 100644 --- a/spherov2/toy/mini.py +++ b/spherov2/toy/mini.py @@ -2,7 +2,6 @@ from enum import IntEnum from functools import partialmethod, lru_cache -from spherov2.commands.animatronic import Animatronic from spherov2.commands.api_and_shell import ApiAndShell from spherov2.commands.connection import Connection from spherov2.commands.drive import Drive @@ -13,15 +12,16 @@ from spherov2.commands.sensor import Sensor from spherov2.commands.system_info import SystemInfo from spherov2.commands.system_mode import SystemMode -from spherov2.controls.v2 import AnimationControl, DriveControl, FirmwareUpdateControl, LedControl, SensorControl, StatsControl, StreamingControl, Processors +from spherov2.controls.v2 import DriveControl, FirmwareUpdateControl, LedControl, SensorControl, \ + StatsControl from spherov2.toy import ToyV2, Toy, ToySensor from spherov2.types import ToyType class Mini(ToyV2): toy_type = ToyType('Sphero Mini', 'SM-', 'SM', .12) - _handshake = [('00020005-574f-4f20-5370-6865726f2121', bytearray(b'usetheforce...band'))] #Remove ForceBand - + _handshake = [('00020005-574f-4f20-5370-6865726f2121', bytearray(b'usetheforce...band'))] # Remove ForceBand + class LEDs(IntEnum): AIMING = 0 BODY_RED = 1 @@ -30,8 +30,8 @@ class LEDs(IntEnum): USER_BODY_RED = 4 USER_BODY_GREEN = 5 USER_BODY_BLUE = 6 - -#Sensors Available: + + # Sensors Available: sensors = OrderedDict( quaternion=OrderedDict( x=ToySensor(0x2000000, -1., 1.), @@ -61,7 +61,7 @@ class LEDs(IntEnum): speed=OrderedDict(speed=ToySensor(0x4, 0., 32767.)), core_time=OrderedDict(core_time=ToySensor(0x2, 0., 0.)) ) - + extended_sensors = OrderedDict( gyroscope=OrderedDict( x=ToySensor(0x2000000, -20000., 20000.), @@ -70,118 +70,115 @@ class LEDs(IntEnum): ) ) -#Mini Supported calls - #API and Shell: - ping = ApiAndShell.ping #PingCommand - get_api_protocol_version = ApiAndShell.get_api_protocol_version #GetApiProtocolVersionCommand - send_command_to_shell = ApiAndShell.send_command_to_shell #SendCommandToShellCommand - add_send_string_to_console_listener = partialmethod(Toy._add_listener, ApiAndShell.send_string_to_console) #SendStringToConsoleCommand - remove_send_string_to_console_listener = partialmethod(Toy._remove_listener, ApiAndShell.send_string_to_console) #SendStringToConsoleCommand - - - #Connection - get_bluetooth_name = Connection.get_bluetooth_name #GetBluetoothNameCommand - set_bluetooth_name = Connection.set_bluetooth_name #SetBluetoothNameCommand - - - #Drive - set_raw_motors = Drive.set_raw_motors #SetRawMotorsCommand - reset_yaw = Drive.reset_yaw #ResetYawCommand - drive_with_heading = Drive.drive_with_heading #DriveWithHeadingCommand - set_stabilization = Drive.set_stabilization #SetStabilizationCommand - - - #FactoryTest - exit_factory_mode = FactoryTest.exit_factory_mode #ExitFactoryModeCommand - get_chassis_id = FactoryTest.get_chassis_id #GetChassisIdCommand - - - #Firmware - get_pending_update_flags = Firmware.get_pending_update_flags #GetPendingUpdateFlagsCommand - - - #IO - set_all_leds_with_16_bit_mask = IO.set_all_leds_with_16_bit_mask #SetAllLedsWith16BitMaskCommand - start_idle_led_animation = IO.start_idle_led_animation #StartIdleLedAnimationCommand - - - #Power + # Mini Supported calls + # API and Shell: + ping = ApiAndShell.ping # PingCommand + get_api_protocol_version = ApiAndShell.get_api_protocol_version # GetApiProtocolVersionCommand + send_command_to_shell = ApiAndShell.send_command_to_shell # SendCommandToShellCommand + add_send_string_to_console_listener = partialmethod(Toy._add_listener, + ApiAndShell.send_string_to_console) # SendStringToConsoleCommand + remove_send_string_to_console_listener = partialmethod(Toy._remove_listener, + ApiAndShell.send_string_to_console) # SendStringToConsoleCommand + + # Connection + get_bluetooth_name = Connection.get_bluetooth_name # GetBluetoothNameCommand + set_bluetooth_name = Connection.set_bluetooth_name # SetBluetoothNameCommand + + # Drive + set_raw_motors = Drive.set_raw_motors # SetRawMotorsCommand + reset_yaw = Drive.reset_yaw # ResetYawCommand + drive_with_heading = Drive.drive_with_heading # DriveWithHeadingCommand + set_stabilization = Drive.set_stabilization # SetStabilizationCommand + + # FactoryTest + exit_factory_mode = FactoryTest.exit_factory_mode # ExitFactoryModeCommand + get_chassis_id = FactoryTest.get_chassis_id # GetChassisIdCommand + + # Firmware + get_pending_update_flags = Firmware.get_pending_update_flags # GetPendingUpdateFlagsCommand + + # IO + set_all_leds_with_16_bit_mask = IO.set_all_leds_with_16_bit_mask # SetAllLedsWith16BitMaskCommand + start_idle_led_animation = IO.start_idle_led_animation # StartIdleLedAnimationCommand + + # Power add_battery_state_changed_notify_listener = partialmethod(Toy._add_listener, - Power.battery_state_changed_notify) #BatteryStateChangedNotifyCommand + Power.battery_state_changed_notify) # BatteryStateChangedNotifyCommand remove_battery_state_changed_notify_listener = partialmethod(Toy._remove_listener, - Power.battery_state_changed_notify) #BatteryStateChangedNotifyCommand + Power.battery_state_changed_notify) # BatteryStateChangedNotifyCommand add_did_sleep_notify_listener = partialmethod(Toy._add_listener, - Power.did_sleep_notify) #DidSleepNotifyCommand + Power.did_sleep_notify) # DidSleepNotifyCommand remove_did_sleep_notify_listener = partialmethod(Toy._remove_listener, - Power.did_sleep_notify) #DidSleepNotifyCommand + Power.did_sleep_notify) # DidSleepNotifyCommand add_will_sleep_notify_listener = partialmethod(Toy._add_listener, - Power.will_sleep_notify) #WillSleepNotifyCommand + Power.will_sleep_notify) # WillSleepNotifyCommand remove_will_sleep_notify_listener = partialmethod(Toy._remove_listener, - Power.will_sleep_notify) #WillSleepNotifyCommand - enable_battery_state_changed_notify = Power.enable_battery_state_changed_notify #EnableBatteryStateChangedNotifyCommand - enter_deep_sleep = Power.enter_deep_sleep #EnterDeepSleepCommand - get_battery_percentage = Power.get_battery_percentage #GetBatteryPercentageCommand - get_battery_state = Power.get_battery_state #GetBatteryStateCommand - get_battery_voltage = Power.get_battery_voltage #GetBatteryVoltageCommand - get_battery_voltage_state = Power.get_battery_voltage_state #GetBatterVoltageCommand - sleep = Power.sleep #SleepCommand - wake = Power.wake #WakeCommand - - - #Sensor - add_collision_detected_notify_listener = partialmethod(Toy._add_listener, Sensor.collision_detected_notify) #CollisionDetectedNotifyCommand - remove_collision_detected_notify_listener = partialmethod(Toy._remove_listener, Sensor.collision_detected_notify) #CollisionDetectedNotifyCommand - configure_collision_detection = Sensor.configure_collision_detection #ConfigureCollisionDetectionCommand - enable_collision_detected_notify = Sensor.enable_collision_detected_notify #EnableCollisionDetectedNotifyCommand - enable_gyro_max_notify = Sensor.enable_gyro_max_notify #EnableGyroMaxNotifyCommand - get_extended_sensor_streaming_mask = Sensor.get_extended_sensor_streaming_mask #GetExtendedSensorStreamingMaskCommand - set_extended_sensor_streaming_mask = Sensor.set_extended_sensor_streaming_mask #SetExtendedSensorStreamingMaskCommand - get_sensor_streaming_mask = Sensor.get_sensor_streaming_mask #SetSensorStreamingMaskCommand - set_sensor_streaming_mask = Sensor.set_sensor_streaming_mask #GetSensorStreamingMaskCommand - add_gyro_max_notify_listener = partialmethod(Toy._add_listener, Sensor.gyro_max_notify) #GyroMaxNotifyCommand - remove_gyro_max_notify_listener = partialmethod(Toy._remove_listener, Sensor.gyro_max_notify) #GyroMaxNotifyCommand - reset_locator_x_and_y = Sensor.reset_locator_x_and_y #ResetLocationXAndYCommand - add_sensor_streaming_data_notify_listener = partialmethod(Toy._add_listener, Sensor.sensor_streaming_data_notify) #SensorStreamingDataNotifyCommand - remove_sensor_streaming_data_notify_listener = partialmethod(Toy._remove_listener, Sensor.sensor_streaming_data_notify) #SensorStreamingDataNotifyCommand - set_locator_flags = Sensor.set_locator_flags #SetLocatorFlagsCommand - - - #System Info - get_board_revision = SystemInfo.get_board_revision #GetBoardRevisionCommand - get_bootloader_version = SystemInfo.get_bootloader_version #GetBootloaderVersionCommand - get_mac_address = SystemInfo.get_mac_address #GetMacAddressCommand - get_main_app_version = SystemInfo.get_main_app_version #GetMainAppVersionCommand - get_model_number = SystemInfo.get_model_number #GetModelNumberCommand - get_processor_name = SystemInfo.get_processor_name #GetProcessorNameCommand - get_stats_id = SystemInfo.get_stats_id #GetStatsIdCommand - get_three_character_sku = SystemInfo.get_three_character_sku #GetThreeCharacterSkuCommand - - - #System Mode - enable_desktoy_mode = SystemMode.enable_desktoy_mode #EnableDesktoyModeCommand - - - #Controls - V2 + Power.will_sleep_notify) # WillSleepNotifyCommand + enable_battery_state_changed_notify = Power.enable_battery_state_changed_notify # EnableBatteryStateChangedNotifyCommand + enter_deep_sleep = Power.enter_deep_sleep # EnterDeepSleepCommand + get_battery_percentage = Power.get_battery_percentage # GetBatteryPercentageCommand + get_battery_state = Power.get_battery_state # GetBatteryStateCommand + get_battery_voltage = Power.get_battery_voltage # GetBatteryVoltageCommand + get_battery_voltage_state = Power.get_battery_voltage_state # GetBatterVoltageCommand + sleep = Power.sleep # SleepCommand + wake = Power.wake # WakeCommand + + # Sensor + add_collision_detected_notify_listener = partialmethod(Toy._add_listener, + Sensor.collision_detected_notify) # CollisionDetectedNotifyCommand + remove_collision_detected_notify_listener = partialmethod(Toy._remove_listener, + Sensor.collision_detected_notify) # CollisionDetectedNotifyCommand + configure_collision_detection = Sensor.configure_collision_detection # ConfigureCollisionDetectionCommand + enable_collision_detected_notify = Sensor.enable_collision_detected_notify # EnableCollisionDetectedNotifyCommand + enable_gyro_max_notify = Sensor.enable_gyro_max_notify # EnableGyroMaxNotifyCommand + get_extended_sensor_streaming_mask = Sensor.get_extended_sensor_streaming_mask # GetExtendedSensorStreamingMaskCommand + set_extended_sensor_streaming_mask = Sensor.set_extended_sensor_streaming_mask # SetExtendedSensorStreamingMaskCommand + get_sensor_streaming_mask = Sensor.get_sensor_streaming_mask # SetSensorStreamingMaskCommand + set_sensor_streaming_mask = Sensor.set_sensor_streaming_mask # GetSensorStreamingMaskCommand + add_gyro_max_notify_listener = partialmethod(Toy._add_listener, Sensor.gyro_max_notify) # GyroMaxNotifyCommand + remove_gyro_max_notify_listener = partialmethod(Toy._remove_listener, + Sensor.gyro_max_notify) # GyroMaxNotifyCommand + reset_locator_x_and_y = Sensor.reset_locator_x_and_y # ResetLocationXAndYCommand + add_sensor_streaming_data_notify_listener = partialmethod(Toy._add_listener, + Sensor.sensor_streaming_data_notify) # SensorStreamingDataNotifyCommand + remove_sensor_streaming_data_notify_listener = partialmethod(Toy._remove_listener, + Sensor.sensor_streaming_data_notify) # SensorStreamingDataNotifyCommand + set_locator_flags = Sensor.set_locator_flags # SetLocatorFlagsCommand + + # System Info + get_board_revision = SystemInfo.get_board_revision # GetBoardRevisionCommand + get_bootloader_version = SystemInfo.get_bootloader_version # GetBootloaderVersionCommand + get_mac_address = SystemInfo.get_mac_address # GetMacAddressCommand + get_main_app_version = SystemInfo.get_main_app_version # GetMainAppVersionCommand + get_model_number = SystemInfo.get_model_number # GetModelNumberCommand + get_processor_name = SystemInfo.get_processor_name # GetProcessorNameCommand + get_stats_id = SystemInfo.get_stats_id # GetStatsIdCommand + get_three_character_sku = SystemInfo.get_three_character_sku # GetThreeCharacterSkuCommand + + # System Mode + enable_desktoy_mode = SystemMode.enable_desktoy_mode # EnableDesktoyModeCommand + + # Controls - V2 @property @lru_cache(None) def drive_control(self): return DriveControl(self) - + @property @lru_cache(None) def multi_led_control(self): return LedControl(self) - + @property @lru_cache(None) def sensor_control(self): return SensorControl(self) - + @property @lru_cache(None) def stats_control(self): return StatsControl(self) - + @property @lru_cache(None) def firmware_update_control(self): diff --git a/spherov2/toy/sphero.py b/spherov2/toy/sphero.py index e986ec0..f09bbc4 100644 --- a/spherov2/toy/sphero.py +++ b/spherov2/toy/sphero.py @@ -1,7 +1,6 @@ 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 @@ -55,86 +54,88 @@ class Sphero(Toy): ), speed=OrderedDict(speed=ToySensor(0x400000, 0., 32767.)), ) - + def wake(self): self._Toy__adapter.write('22bb746f-2bbf-7554-2d6f-726568705327', bytearray([1])) - - - #Async + + # Async add_battery_state_changed_notify_listener = partialmethod(Toy._add_listener, - Power.battery_state_changed_notify) #BatteryStateChangedNotifyCommand + Power.battery_state_changed_notify) # BatteryStateChangedNotifyCommand remove_battery_state_changed_notify_listener = partialmethod(Toy._remove_listener, - Power.battery_state_changed_notify) #BatteryStateChangedNotifyCommand - add_collision_detected_notify_listener = partialmethod(Toy._add_listener, Sensor.collision_detected_notify) #CollisionDetectedNotifyCommand - 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 - 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 - remove_gyro_max_notify_listener = partialmethod(Toy._remove_listener, Sensor.gyro_max_notify) #GyroMaxNotifyCommand - add_sensor_streaming_data_notify_listener = partialmethod(Toy._add_listener, Sensor.sensor_streaming_data_notify) #SensorStreamingDataNotifyCommand - 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 - remove_will_sleep_notify_listener = partialmethod(Toy._remove_listener, Power.will_sleep_notify) #WillSleepNotifyCommand - - - #Bootloader - begin_reflash = Bootloader.begin_reflash #BeginReflashCommand - here_is_page = Bootloader.here_is_page #HereIsPageCommand - jump_to_main = Bootloader.jump_to_main #JumpToMainCommand - - - #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 - - - #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 - - - #Controls - V1 + Power.battery_state_changed_notify) # BatteryStateChangedNotifyCommand + add_collision_detected_notify_listener = partialmethod(Toy._add_listener, + Sensor.collision_detected_notify) # CollisionDetectedNotifyCommand + 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 + 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 + remove_gyro_max_notify_listener = partialmethod(Toy._remove_listener, + Sensor.gyro_max_notify) # GyroMaxNotifyCommand + add_sensor_streaming_data_notify_listener = partialmethod(Toy._add_listener, + Sensor.sensor_streaming_data_notify) # SensorStreamingDataNotifyCommand + 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 + remove_will_sleep_notify_listener = partialmethod(Toy._remove_listener, + Power.will_sleep_notify) # WillSleepNotifyCommand + + # Bootloader + begin_reflash = Bootloader.begin_reflash # BeginReflashCommand + here_is_page = Bootloader.here_is_page # HereIsPageCommand + jump_to_main = Bootloader.jump_to_main # JumpToMainCommand + + # 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 + + # 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 + + # 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 - #@property - #@lru_cache(None) - #def multi_led_control(self): + + # The way utils.py is implemented this doesnt need to be present + # @property + # @lru_cache(None) + # def multi_led_control(self): # return LedControl(self) @property @lru_cache(None) def sensor_control(self): return SensorControl(self) - + @property @lru_cache(None) def stats_control(self): diff --git a/spherov2/toy/sprk2.py b/spherov2/toy/sprk2.py index 1522ae1..0bd31cd 100644 --- a/spherov2/toy/sprk2.py +++ b/spherov2/toy/sprk2.py @@ -1,9 +1,6 @@ -from spherov2.toy import Toy from spherov2.toy.sphero import Sphero as SPHERO from spherov2.types import ToyType class Sprk2(SPHERO): toy_type = ToyType('Sphero SPRK+', 'SK-', 'SK', .06) - - diff --git a/spherov2/utils.py b/spherov2/utils.py index 5b10829..1253c5a 100644 --- a/spherov2/utils.py +++ b/spherov2/utils.py @@ -161,7 +161,7 @@ def _fallback(): toy.LEDs.RIGHT_BRAKELIGHT_RED: r, toy.LEDs.RIGHT_BRAKELIGHT_GREEN: g, toy.LEDs.RIGHT_BRAKELIGHT_BLUE: b - } + } else: mapping = None @@ -341,47 +341,50 @@ def set_led_matrix_one_colour(toy: Toy, r: int, g: int, b: int, not_supported_ha toy.set_compressed_frame_player_one_color(r, g, b) elif not_supported_handler: not_supported_handler() - + @staticmethod def set_matrix_pixel(toy: Toy, x: int, y: int, r: int, g: int, b: int, is_user_color: bool, - not_supported_handler: Callable[[], None] = None): + not_supported_handler: Callable[[], None] = None): def _fallback(): not_supported_handler() - + ToyUtil.set_led_matrix_pixel(toy, x, y, r, g, b, _fallback) - + @staticmethod - def set_led_matrix_pixel(toy: Toy, x: int, y: int, r: int, g: int, b: int, not_supported_handler: Callable[[], None] = None): + def set_led_matrix_pixel(toy: Toy, x: int, y: int, r: int, g: int, b: int, + not_supported_handler: Callable[[], None] = None): if toy.implements(IO.set_compressed_frame_player_pixel): toy.set_compressed_frame_player_pixel(x, y, r, g, b) elif not_supported_handler: not_supported_handler() - + @staticmethod def set_matrix_line(toy: Toy, x1: int, y1: int, x2: int, y2: int, r: int, g: int, b: int, is_user_color: bool, - not_supported_handler: Callable[[], None] = None): + not_supported_handler: Callable[[], None] = None): def _fallback(): not_supported_handler() - + ToyUtil.set_led_matrix_line(toy, x1, y1, x2, y2, r, g, b, _fallback) - + @staticmethod - def set_led_matrix_line(toy: Toy, x1: int, y1: int, x2: int, y2: int, r: int, g: int, b: int, not_supported_handler: Callable[[], None] = None): + def set_led_matrix_line(toy: Toy, x1: int, y1: int, x2: int, y2: int, r: int, g: int, b: int, + not_supported_handler: Callable[[], None] = None): if toy.implements(IO.draw_compressed_frame_player_line): toy.draw_compressed_frame_player_line(x1, y1, x2, y2, r, g, b) elif not_supported_handler: not_supported_handler() - + @staticmethod def set_matrix_fill(toy: Toy, x1: int, y1: int, x2: int, y2: int, r: int, g: int, b: int, is_user_color: bool, - not_supported_handler: Callable[[], None] = None): + not_supported_handler: Callable[[], None] = None): def _fallback(): not_supported_handler() - + ToyUtil.set_led_matrix_fill(toy, x1, y1, x2, y2, r, g, b, _fallback) - + @staticmethod - def set_led_matrix_fill(toy: Toy, x1: int, y1: int, x2: int, y2: int, r: int, g: int, b: int, not_supported_handler: Callable[[], None] = None): + def set_led_matrix_fill(toy: Toy, x1: int, y1: int, x2: int, y2: int, r: int, g: int, b: int, + not_supported_handler: Callable[[], None] = None): if toy.implements(IO.draw_compressed_frame_player_fill): toy.draw_compressed_frame_player_fill(x1, y1, x2, y2, r, g, b) elif not_supported_handler: @@ -451,32 +454,34 @@ def __fallback(): ToyUtil.set_multiple_leds(toy, mapping, __fallback) ToyUtil.set_led_matrix_one_colour(toy, 0, 0, 0) - - #Bolt Animation - def register_matrix_animation(toy: Toy, s, s2, z, s3, s_arr, i, i_arr, not_supported_handler: Callable[[], None] = None): + + # Bolt Animation + def register_matrix_animation(toy: Toy, s, s2, z, s3, s_arr, i, i_arr, + not_supported_handler: Callable[[], None] = None): def _fallback(): not_supported_handler() - + ToyUtil.save_compressed_frame_player_animation(toy, s, s2, z, s3, s_arr, i, i_arr, _fallback) - - def save_compressed_frame_player_animation(toy: Toy, s, s2, z, s3, s_arr, i, i_arr, not_supported_handler: Callable[[], None] = None): + + def save_compressed_frame_player_animation(toy: Toy, s, s2, z, s3, s_arr, i, i_arr, + not_supported_handler: Callable[[], None] = None): if toy.implements(IO.save_compressed_frame_player_animation): toy.save_compressed_frame_player_animation(s, s2, z, s3, s_arr, i, i_arr) elif not_supported_handler: not_supported_handler() - + def play_matrix_animation(toy: Toy, s, not_supported_handler: Callable[[], None] = None): def _fallback(): not_supported_handler() - - ToyUtil.save_compressed_frame_player_animation(toy, s, s2, z, s3, s_arr, i, i_arr, _fallback) - + + ToyUtil.save_compressed_frame_player_animation(toy, s, s2, z, s3, s_arr, i, i_arr, _fallback) + def play_compressed_frame_player_animation(toy: Toy, s, not_supported_handler: Callable[[], None] = None): if toy.implements(IO.play_compressed_frame_player_animation): toy.play_compressed_frame_player_animation(s) elif not_supported_handler: not_supported_handler() - + # Sound @staticmethod def play_sound(toy: Toy, sound: IntEnum, force_play: bool, not_supported_handler: Callable[[], None] = None):