From fd5a6dec261e4d5c4ea5cd001f5b01681bc5d0a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mac=C3=ADas?= Date: Thu, 9 Aug 2018 18:51:20 +0200 Subject: [PATCH] Update create2.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Enabled history in the REPL python console. --- irobot/console_interfaces/create2.py | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/irobot/console_interfaces/create2.py b/irobot/console_interfaces/create2.py index 7d6a216..b8fb5a1 100644 --- a/irobot/console_interfaces/create2.py +++ b/irobot/console_interfaces/create2.py @@ -16,8 +16,8 @@ def check_for_quirks(robot): print('Checking firmware for quirks') print('Restarting Robot...') - boot_message = robot.firmware_version.split(u'\r\n') + for line in boot_message: if match(FIRMWARE_PREFIX, line): print('Found firmware:', line) @@ -64,16 +64,33 @@ def format(self, record): def main(): import code - + import atexit + import os + import readline + import rlcompleter + + historyPath = os.path.expanduser("~/.pyhistory") + + def save_history(historyPath=historyPath): + import readline + readline.write_history_file(historyPath) + + if os.path.exists(historyPath): + readline.read_history_file(historyPath) + + atexit.register(save_history) + del os, atexit, readline, rlcompleter, save_history, historyPath + print('Launching REPL') port = input('Serial Port> ') + brc_pin = int(input('BRC Pin> ')) print() - + # give the user a way out before we launch into interactive mode if port.lower() == 'quit()': return try: - robot = Create2(port) + robot = Create2(port,brc_pin) except RobotConnectionError as e: print(e, '\nInner Exception:', e.__cause__) return