Commit ad5a279b authored by Mart Lubbers's avatar Mart Lubbers

add devicepath to TTYSettings

parent 2d370b44
......@@ -11,6 +11,7 @@ from StdClass import class zero
B115200 | B230400
:: TTYSettings = {
devicePath :: String,
baudrate :: BaudRate,
bytesize :: ByteSize,
parity :: Parity,
......@@ -22,7 +23,7 @@ instance zero TTYSettings
TTYclose :: !*TTY !*env -> (!Bool, !*env)
TTYerror :: !*env -> (!String, !*env)
TTYopen :: !String !TTYSettings !*env -> (!Bool,!*TTY,!*env)
TTYopen :: !TTYSettings !*env -> (!Bool,!*TTY,!*env)
TTYread :: !*TTY -> (!Int, !*TTY)
TTYreadline :: !*TTY -> (!String, !*TTY)
TTYavailable :: !*TTY -> (!Bool, !*TTY)
......
......@@ -11,6 +11,7 @@ import code from "ctty."
instance zero TTYSettings where
zero = {TTYSettings |
devicePath = "/dev/ttyACM0",
baudrate = B9600,
bytesize = BytesizeEight,
parity = ParityNone,
......@@ -33,9 +34,9 @@ instance toInt Parity where
ParityNone = 0; ParityOdd = 1; ParityEven = 2; ParitySpace = 3;
ParityMark = 4
TTYopen :: !String !TTYSettings !*env -> (!Bool, !*TTY, !*env)
TTYopen fn ts w = TTYopen2
fn
TTYopen :: !TTYSettings !*env -> (!Bool, !*TTY, !*env)
TTYopen ts w = TTYopen2
ts.devicePath
(toInt ts.baudrate)
(toInt ts.bytesize)
(toInt ts.parity)
......
......@@ -7,4 +7,4 @@ derive class iTask TTYSettings
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
isTTY s = not (isEmpty (filter (flip startsWith s) prefixes))
prefixes = ["ttyS", "ttyACM", "ttyUSB", "tty.usbserial"]
syncSerialChannel :: String TTYSettings (b -> String) (String -> a) (Shared ([a],[b],Bool)) -> Task () | iTask a & iTask b
syncSerialChannel dev opts enc dec rw = Task eval
syncSerialChannel :: TTYSettings (b -> String) (String -> a) (Shared ([a],[b],Bool)) -> Task () | iTask a & iTask b
syncSerialChannel opts enc dec rw = Task eval
where
eval event evalOpts tree=:(TCInit taskId ts) iworld=:{IWorld|world}
= case TTYopen dev opts world of
= case TTYopen opts world of
(False, _, world)
# (err, world) = TTYerror world
= (ExceptionResult (exception err), {iworld & world=world})
......
......@@ -14,7 +14,7 @@ TTYerrorclose f w
Start :: *World -> *World
Start 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
#! tty = TTYwrite "echo123\n" 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