Class: Itiscold::TTY
Class Method Summary collapse
- .data_bits(t, val) ⇒ Object
- .open(filename, speed, mode) ⇒ Object
- .parity(t, val) ⇒ Object
- .read_timeout(t, val) ⇒ Object
- .reading(t) ⇒ Object
- .speed(t, speed) ⇒ Object
- .stop_bits(t, val) ⇒ Object
Class Method Details
.data_bits(t, val) ⇒ Object
24 25 26 27 28 |
# File 'lib/itiscold.rb', line 24 def self.data_bits t, val t.cflag &= ~CSIZE # clear previous values t.cflag |= const_get("CS#{val}") # Set the data bits t end |
.open(filename, speed, mode) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/itiscold.rb', line 12 def self.open filename, speed, mode if mode =~ /^(\d)(\w)(\d)$/ t.data_bits = $1.to_i t.stop_bits = $3.to_i t.parity = { 'N' => :none, 'E' => :even, 'O' => :odd }[$2] t.speed = speed t.read_timeout = 5 t.reading = true t.update! end end |
.parity(t, val) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/itiscold.rb', line 40 def self.parity t, val case val when :none t.cflag &= ~PARENB when :even t.cflag |= PARENB # Enable parity t.cflag &= ~PARODD # Make it not odd when :odd t.cflag |= PARENB # Enable parity t.cflag |= PARODD # Make it odd else raise end t end |
.read_timeout(t, val) ⇒ Object
62 63 64 65 66 |
# File 'lib/itiscold.rb', line 62 def self.read_timeout t, val t.cc[VTIME] = val t.cc[VMIN] = 0 t end |
.reading(t) ⇒ Object
68 69 70 71 |
# File 'lib/itiscold.rb', line 68 def self.reading t t.cflag |= CLOCAL | CREAD t end |
.speed(t, speed) ⇒ Object
56 57 58 59 60 |
# File 'lib/itiscold.rb', line 56 def self.speed t, speed t.ispeed = const_get("B#{speed}") t.ospeed = const_get("B#{speed}") t end |
.stop_bits(t, val) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/itiscold.rb', line 30 def self.stop_bits t, val case val when 1 then t.cflag &= ~CSTOPB when 2 then t.cflag |= CSTOPB else raise end t end |