Commit ad5a279b authored by Mart Lubbers's avatar Mart Lubbers
Browse files

add devicepath to TTYSettings

parent 2d370b44
...@@ -11,6 +11,7 @@ from StdClass import class zero ...@@ -11,6 +11,7 @@ from StdClass import class zero
B115200 | B230400 B115200 | B230400
:: TTYSettings = { :: TTYSettings = {
devicePath :: String,
baudrate :: BaudRate, baudrate :: BaudRate,
bytesize :: ByteSize, bytesize :: ByteSize,
parity :: Parity, parity :: Parity,
...@@ -22,7 +23,7 @@ instance zero TTYSettings ...@@ -22,7 +23,7 @@ instance zero TTYSettings
TTYclose :: !*TTY !*env -> (!Bool, !*env) TTYclose :: !*TTY !*env -> (!Bool, !*env)
TTYerror :: !*env -> (!String, !*env) TTYerror :: !*env -> (!String, !*env)
TTYopen :: !String !TTYSettings !*env -> (!Bool,!*TTY,!*env) TTYopen :: !TTYSettings !*env -> (!Bool,!*TTY,!*env)
TTYread :: !*TTY -> (!Int, !*TTY) TTYread :: !*TTY -> (!Int, !*TTY)
TTYreadline :: !*TTY -> (!String, !*TTY) TTYreadline :: !*TTY -> (!String, !*TTY)
TTYavailable :: !*TTY -> (!Bool, !*TTY) TTYavailable :: !*TTY -> (!Bool, !*TTY)
......
...@@ -11,6 +11,7 @@ import code from "ctty." ...@@ -11,6 +11,7 @@ import code from "ctty."
instance zero TTYSettings where instance zero TTYSettings where
zero = {TTYSettings | zero = {TTYSettings |
devicePath = "/dev/ttyACM0",
baudrate = B9600, baudrate = B9600,
bytesize = BytesizeEight, bytesize = BytesizeEight,
parity = ParityNone, parity = ParityNone,
...@@ -33,9 +34,9 @@ instance toInt Parity where ...@@ -33,9 +34,9 @@ instance toInt Parity where
ParityNone = 0; ParityOdd = 1; ParityEven = 2; ParitySpace = 3; ParityNone = 0; ParityOdd = 1; ParityEven = 2; ParitySpace = 3;
ParityMark = 4 ParityMark = 4
TTYopen :: !String !TTYSettings !*env -> (!Bool, !*TTY, !*env) TTYopen :: !TTYSettings !*env -> (!Bool, !*TTY, !*env)
TTYopen fn ts w = TTYopen2 TTYopen ts w = TTYopen2
fn ts.devicePath
(toInt ts.baudrate) (toInt ts.baudrate)
(toInt ts.bytesize) (toInt ts.bytesize)
(toInt ts.parity) (toInt ts.parity)
......
...@@ -7,4 +7,4 @@ derive class iTask TTYSettings ...@@ -7,4 +7,4 @@ derive class iTask TTYSettings
getTTYDevices :: !*env -> *(![String], !*env) getTTYDevices :: !*env -> *(![String], !*env)
syncSerialChannel :: String TTYSettings (b -> String) (String -> a) (Shared ([a],[b],Bool)) -> Task () | iTask a & iTask b syncSerialChannel :: TTYSettings (b -> String) (String -> a) (Shared ([a],[b],Bool)) -> Task () | iTask a & iTask b
...@@ -31,11 +31,11 @@ getTTYDevices w = case readDirectory "/dev" w of ...@@ -31,11 +31,11 @@ getTTYDevices w = case readDirectory "/dev" w of
isTTY s = not (isEmpty (filter (flip startsWith s) prefixes)) isTTY s = not (isEmpty (filter (flip startsWith s) prefixes))
prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"] prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"]
syncSerialChannel :: String TTYSettings (b -> String) (String -> a) (Shared ([a],[b],Bool)) -> Task () | iTask a & iTask b syncSerialChannel :: TTYSettings (b -> String) (String -> a) (Shared ([a],[b],Bool)) -> Task () | iTask a & iTask b
syncSerialChannel dev opts enc dec rw = Task eval syncSerialChannel opts enc dec rw = Task eval
where where
eval event evalOpts tree=:(TCInit taskId ts) iworld=:{IWorld|world} eval event evalOpts tree=:(TCInit taskId ts) iworld=:{IWorld|world}
= case TTYopen dev opts world of = case TTYopen opts world of
(False, _, world) (False, _, world)
# (err, world) = TTYerror world # (err, world) = TTYerror world
= (ExceptionResult (exception err), {iworld & world=world}) = (ExceptionResult (exception err), {iworld & world=world})
......
...@@ -14,7 +14,7 @@ TTYerrorclose f w ...@@ -14,7 +14,7 @@ TTYerrorclose f w
Start :: *World -> *World Start :: *World -> *World
Start w Start w
# (io, w) = stdio w # (io, w) = stdio w
# (ok, tty, w) = TTYopen "/dev/ttyUSB0" zero w # (ok, tty, w) = TTYopen {zero & devicePath="/dev/ttyUSB0"} w
| not ok = TTYerrorclose io w | not ok = TTYerrorclose io w
#! tty = TTYwrite "echo123\n" tty #! tty = TTYwrite "echo123\n" tty
#! (av, tty) = TTYavailable tty #! (av, tty) = TTYavailable tty
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment