summaryrefslogtreecommitdiffstatshomepage
path: root/tools/pyboard.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/pyboard.py')
-rw-r--r--tools/pyboard.py38
1 files changed, 29 insertions, 9 deletions
diff --git a/tools/pyboard.py b/tools/pyboard.py
index a44710914e..dce60350d0 100644
--- a/tools/pyboard.py
+++ b/tools/pyboard.py
@@ -9,7 +9,7 @@ Example usage:
import pyboard
pyb = pyboard.Pyboard('/dev/ttyACM0')
pyb.enter_raw_repl()
- pyb.exec('pyb.Led(1).on()')
+ pyb.exec('pyb.LED(1).on()')
pyb.exit_raw_repl()
To run a script from the local machine on the board and print out the results:
@@ -17,6 +17,10 @@ To run a script from the local machine on the board and print out the results:
import pyboard
pyboard.execfile('test.py', device='/dev/ttyACM0')
+This script can also be run directly. To execute a local script, use:
+
+ python pyboard.py test.py
+
"""
import time
@@ -50,6 +54,7 @@ class Pyboard:
return data
def enter_raw_repl(self):
+ self.serial.write(b'\r\x03') # ctrl-C: interrupt any running program
self.serial.write(b'\r\x01') # ctrl-A: enter raw REPL
self.serial.write(b'\x04') # ctrl-D: soft reset
data = self.read_until(1, b'to exit\r\n>')
@@ -110,18 +115,19 @@ def run_test():
pyb.exec('def apply(l, f):\r\n for item in l:\r\n f(item)\r\n')
- pyb.exec('leds=[pyb.Led(l) for l in range(1, 5)]')
+ pyb.exec('leds=[pyb.LED(l) for l in range(1, 5)]')
pyb.exec('apply(leds, lambda l:l.off())')
## USR switch test
- if True:
- for i in range(2):
- print("press USR button")
- pyb.exec('while pyb.switch(): pyb.delay(10)')
- pyb.exec('while not pyb.switch(): pyb.delay(10)')
+ pyb.exec('switch = pyb.Switch()')
+
+ for i in range(2):
+ print("press USR button")
+ pyb.exec('while switch(): pyb.delay(10)')
+ pyb.exec('while not switch(): pyb.delay(10)')
- print('USR switch passed')
+ print('USR switch passed')
## accel test
@@ -155,5 +161,19 @@ def run_test():
pyb.exit_raw_repl()
pyb.close()
+def main():
+ import argparse
+ cmd_parser = argparse.ArgumentParser(description='Run scripts on the pyboard.')
+ cmd_parser.add_argument('--device', default='/dev/ttyACM0', help='the serial device of the pyboard')
+ cmd_parser.add_argument('--test', action='store_true', help='run a small test suite on the pyboard')
+ cmd_parser.add_argument('files', nargs='*', help='input files')
+ args = cmd_parser.parse_args()
+
+ if args.test:
+ run_test()
+
+ for file in args.files:
+ execfile(file, device=args.device)
+
if __name__ == "__main__":
- run_test()
+ main()