Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
firmware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
card10
firmware
Commits
72424267
Verified
Commit
72424267
authored
5 years ago
by
fpletz
Browse files
Options
Downloads
Patches
Plain Diff
feat(tools): add run.py to execute python files via serial
parent
c3e34289
No related branches found
No related tags found
1 merge request
!165
feat(tools): add run.py to execute python files via serial
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
default.nix
+1
-0
1 addition, 0 deletions
default.nix
tools/run.py
+38
-0
38 additions, 0 deletions
tools/run.py
with
39 additions
and
0 deletions
default.nix
+
1
−
0
View file @
72424267
...
...
@@ -22,6 +22,7 @@ in stdenv.mkDerivation rec {
ninja
py
py
.
pkgs
.
pillow
py
.
pkgs
.
pyserial
];
src
=
./.
;
buildCommand
=
''
...
...
This diff is collapsed.
Click to expand it.
tools/run.py
0 → 100755
+
38
−
0
View file @
72424267
#!/usr/bin/env python3
# or using nix-shell
#!/usr/bin/env nix-shell
#! nix-shell -i python3 -p "python3.withPackages (ps: [ ps.pyserial ])"
import
sys
import
base64
import
argparse
import
serial
parser
=
argparse
.
ArgumentParser
(
description
=
"
Executes python scripts on card10
"
)
parser
.
add_argument
(
"
script
"
,
type
=
argparse
.
FileType
(
"
r
"
),
help
=
"
micropython file to execute
"
)
parser
.
add_argument
(
"
-d
"
,
"
--device
"
,
default
=
"
/dev/ttyACM0
"
,
help
=
"
Serial device of the pycardium console
"
,
)
args
=
parser
.
parse_args
()
code
=
base64
.
b64encode
(
bytes
(
args
.
script
.
read
(),
"
utf-8
"
))
with
serial
.
Serial
(
port
=
args
.
device
,
baudrate
=
115200
)
as
s
:
s
.
write
(
b
"
\x03
import ubinascii; exec(ubinascii.a2b_base64(
'"
+
code
+
b
"'
))
\r\n
"
)
s
.
readline
()
s
.
readline
()
line
=
""
while
not
line
.
startswith
(
"
>>>
"
):
char
=
s
.
read
().
decode
(
"
utf-8
"
)
if
char
==
"
\n
"
:
print
(
line
)
line
=
""
else
:
line
+=
char
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment