File tree 8 files changed +38
-45
lines changed 8 files changed +38
-45
lines changed Original file line number Diff line number Diff line change
1
+ const Board = require ( '../micropython.js' )
2
+
3
+ let board = new Board ( )
4
+
5
+ board . listPorts ( )
6
+ . then ( ( ports ) => {
7
+ console . log ( 'available ports' , ports )
8
+ } )
Original file line number Diff line number Diff line change 1
1
const Board = require ( '../micropython.js' )
2
2
3
- let board = new Board ( {
4
- device : process . env . PORT || '/dev/tty.usbmodem141101'
5
- } )
3
+ let board = new Board ( )
6
4
7
- board . open ( )
5
+ board . open ( process . env . PORT || '/dev/tty.usbmodem141101' )
8
6
. then ( ( ) => {
9
7
console . log ( 'connected' )
10
8
console . log ( 'entering raw repl' )
Original file line number Diff line number Diff line change 1
1
const Board = require ( '../micropython.js' )
2
2
3
- let board = new Board ( {
4
- device : process . env . PORT || '/dev/tty.usbmodem141101'
5
- } )
6
-
7
3
console . log ( 'connect' )
8
- board . open ( )
4
+
5
+ let board = new Board ( )
6
+
7
+ board . open ( process . env . PORT || '/dev/tty.usbm
8000
odem141101' )
9
8
. then ( async ( ) => {
10
9
try {
11
10
await board . execfile ( './test.py' )
Original file line number Diff line number Diff line change 1
1
const Board = require ( '../micropython.js' )
2
2
3
- let board = new Board ( {
4
- device : process . env . PORT || '/dev/tty.usbmodem141101'
5
- } )
6
-
7
3
console . log ( 'connect' )
8
- board . open ( )
4
+ let board = new Board ( )
5
+ board . open ( process . env . PORT || '/dev/tty.usbmodem141101' )
9
6
. then ( async ( ) => {
10
7
try {
11
8
await board . fs_put ( './test.py' , 'test.py' )
Original file line number Diff line number Diff line change 1
1
const Board = require ( '../micropython.js' )
2
2
3
- let board = new Board ( {
4
- device : process . env . PORT || '/dev/tty.usbmodem141101'
5
- } )
6
-
7
3
console . log ( 'connect' )
8
- board . open ( )
4
+ let board = new Board ( )
5
+ board . open ( process . env . PORT || '/dev/tty.usbmodem141101' )
9
6
. then ( async ( ) => {
10
7
try {
11
8
await board . fs_rm ( 'test.py' )
Original file line number Diff line number Diff line change 1
1
const Board = require ( '../micropython.js' )
2
2
3
- let board = new Board ( {
4
- device : process . env . PORT || '/dev/tty.usbmodem141101'
5
- } )
6
-
7
3
console . log ( 'connect' )
8
- board . open ( )
4
+ let board = new Board ( )
5
+ board . open ( process . env . PORT || '/dev/tty.usbmodem141101' )
9
6
. then ( async ( ) => {
10
7
try {
11
8
await board . fs_ls ( )
Original file line number Diff line number Diff line change 1
1
const Board = require ( '../micropython.js' )
2
2
3
- let board = new Board ( {
4
- device : process . env . PORT || '/dev/tty.usbmodem141101'
5
- } )
6
-
7
3
console . log ( 'connect' )
8
- board . open ( )
4
+ let board = new Board ( )
5
+ board . open ( process . env . PORT || '/dev/tty.usbmodem141101' )
9
6
. then ( async ( ) => {
10
7
try {
11
8
await board . fs_cat ( 'test.py' )
Original file line number Diff line number Diff line change @@ -12,26 +12,30 @@ function sleep(millis) {
12
12
}
13
13
14
14
class MicroPythonBoard {
15
- constructor ( options ) {
16
- const { device, autoOpen = false } = options
17
- this . device = device || { }
15
+ constructor ( ) {
16
+ this . device = null
18
17
this . in_raw_repl = false
19
- this . use_raw_paste = true
18
+ }
19
+
20
+ listPorts ( ) {
21
+ return SerialPort . list ( )
22
+ }
23
+
24
+ open ( device ) {
25
+ if ( device ) {
26
+ this . device = device
27
+ }
28
+ if ( ! this . device ) {
29
+ throw new Error ( `No device specified` )
30
+ }
20
31
21
32
this . serial = new SerialPort ( {
22
- path : device ,
33
+ path : this . device ,
23
34
baudRate : 115200 ,
24
35
lock : false ,
25
36
autoOpen : false
26
37
} )
27
38
28
- if ( autoOpen ) {
29
- this . open ( )
30
- }
31
-
32
- }
33
-
34
- open ( ) {
35
39
return new Promise ( ( resolve , reject ) => {
36
40
this . serial . open ( ( err ) => {
37
41
if ( err ) {
@@ -128,10 +132,6 @@ class MicroPythonBoard {
128
132
} )
129
133
}
130
134
131
- // SKIPPING THIS FOR NOW
132
- // raw_paste_write() {
133
- // // Only used if `use_raw_paste` is true
134
- // }
135
135
136
136
exec_raw_no_follow ( options ) {
137
137
const { timeout = null , command = '' } = options || { }
You can’t perform that action at this time.
0 commit comments