TTY.dcl 2.23 KB
Newer Older
Mart Lubbers's avatar
Mart Lubbers committed
1 2 3 4
definition module TTY

from StdClass import class zero

Mart Lubbers's avatar
Mart Lubbers committed
5
:: *TTY (:== Int)
Mart Lubbers's avatar
Mart Lubbers committed
6 7

:: ByteSize = BytesizeFive | BytesizeSix | BytesizeSeven | BytesizeEight
8
:: Parity = ParityNone | ParityOdd | ParityEven | ParitySpace | ParityMark
Mart Lubbers's avatar
Mart Lubbers committed
9 10 11 12 13
:: BaudRate = B0 | B50 | B75 | B110 | B134 | B150 | B200 | B300 | B600 |
	B1200 | B1800 | B2400 | B4800 | B9600 | B19200 | B38400 | B57600 |
	B115200 | B230400

:: TTYSettings = {
Mart Lubbers's avatar
Mart Lubbers committed
14
		devicePath :: String,
Mart Lubbers's avatar
Mart Lubbers committed
15 16 17
		baudrate :: BaudRate,
		bytesize :: ByteSize,
		parity :: Parity,
Mart Lubbers's avatar
Mart Lubbers committed
18
		stop2bits :: Bool,
19 20 21
		xonxoff :: Bool,
		//Set this to 2 if you want to connect to a borked arduino
		sleepTime :: Int
Mart Lubbers's avatar
Mart Lubbers committed
22 23 24 25
	}

instance zero TTYSettings

26 27 28 29 30 31 32
/**
 * Returns a list of tty devices. This list is not conclusive but just checks familiar names.
 *
 * @param The world
 * @result The list of detected devices
 * @result The updated world
 */
33
getTTYDevices :: !*World -> *(![String], !*World)
34

35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
/**
 * Smart constructor for {{`TTYSettings`}}
 *
 * @param devicePath
 * @param baudrate
 * @param parity
 * @param stop2bits
 * @param xonxoff
 * @param sleepTime
 */
makeTTYSettings :: String BaudRate ByteSize Parity Bool Bool Int -> TTYSettings

/**
 * Closes a TTY
 *
 * @param tty handle
 * @param world
 * @result Ok flag
 * @result new world
 */
Mart Lubbers's avatar
Mart Lubbers committed
55
TTYclose :: !*TTY !*env -> (!Bool, !*env)
56 57 58 59 60 61 62 63

/**
 * Reads the error from the tty library
 *
 * @param world
 * @result Error
 * @result new world
 */
Mart Lubbers's avatar
Mart Lubbers committed
64
TTYerror :: !*env -> (!String, !*env)
65 66 67 68 69 70 71 72 73 74

/**
 * Open a tty
 *
 * @param tty settings
 * @param world
 * @result Ok flag
 * @result TTY handle
 * @result new world
 */
Mart Lubbers's avatar
Mart Lubbers committed
75
TTYopen :: !TTYSettings !*env -> (!Bool,!*TTY,!*env)
76 77 78 79 80 81 82 83 84

/**
 * Read a byte from a tty
 *
 * @param tty handle
 * @param world
 * @result byte
 * @result new tty handle
 */
Mart Lubbers's avatar
Mart Lubbers committed
85
TTYread :: !*TTY -> (!Int, !*TTY)
86 87 88 89 90 91 92 93 94

/**
 * Read a line from the tty (up until '\n' or EOF)
 *
 * @param tty handle
 * @param world
 * @result line
 * @result new tty handle
 */
Mart Lubbers's avatar
Mart Lubbers committed
95
TTYreadline :: !*TTY -> (!String, !*TTY)
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113

/**
* Checks if the TTY device is available for reading
*
* @param tty handle
* @result Data available
* @result Ok flag
* @result new tty handle
*/
TTYavailable :: !*TTY -> (!Bool, !Bool, !*TTY)

/**
* Write bytes to a TTY
*
* @param The bytes to write
* @param The tty handle
* @result new tty handle
*/
Mart Lubbers's avatar
Mart Lubbers committed
114
TTYwrite :: !String !*TTY -> *TTY