Class: Device::VirtualKeyboard
- Inherits:
-
Object
- Object
- Device::VirtualKeyboard
- Defined in:
- lib/device/virtual_keyboard.rb
Class Attribute Summary collapse
-
.attributes ⇒ Object
Returns the value of attribute attributes.
-
.text ⇒ Object
Returns the value of attribute text.
-
.type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
- .change_keyboard ⇒ Object
- .parse(line_x, line_y, params) ⇒ Object
- .show_text(key, params) ⇒ Object
- .text_not_ready?(key) ⇒ Boolean
- .type_text(params = {}) ⇒ Object
- .wifi_password ⇒ Object
Class Attribute Details
.attributes ⇒ Object
Returns the value of attribute attributes.
6 7 8 |
# File 'lib/device/virtual_keyboard.rb', line 6 def attributes @attributes end |
.text ⇒ Object
Returns the value of attribute text.
6 7 8 |
# File 'lib/device/virtual_keyboard.rb', line 6 def text @text end |
.type ⇒ Object
Returns the value of attribute type.
6 7 8 |
# File 'lib/device/virtual_keyboard.rb', line 6 def type @type end |
Class Method Details
.change_keyboard ⇒ Object
178 179 180 181 182 183 184 185 |
# File 'lib/device/virtual_keyboard.rb', line 178 def self.change_keyboard if type.nil? self.type = :keyboard_capital Device::Display.print_bitmap('./shared/keyboard_capital.bmp') else Device::Display.print_bitmap("./shared/#{type}.bmp") end end |
.parse(line_x, line_y, params) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/device/virtual_keyboard.rb', line 150 def self.parse(line_x, line_y, params) key = attributes[type].find do |value| value[:x].include?(line_x) && value[:y].include?(line_y) end return if key.nil? Device::Audio.beep(7, 60) show_text(key, params) key[:char] end |
.show_text(key, params) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/device/virtual_keyboard.rb', line 162 def self.show_text(key, params) case key[:char] when :keyboard_uppercase, :keyboard_symbol_number, :keyboard_capital self.type = key[:char] change_keyboard when :erase self.text += '' if text.nil? self.text = text[0..-2] when :space self.text += ' ' else self.text << key[:char] unless key[:char] == :enter end Device::Display.print_line("#{self.text}", params[:line], params[:column]) end |
.text_not_ready?(key) ⇒ Boolean
146 147 148 |
# File 'lib/device/virtual_keyboard.rb', line 146 def self.text_not_ready?(key) key != :enter && key != Device::IO::ENTER && key != Device::IO::CANCEL end |
.type_text(params = {}) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/device/virtual_keyboard.rb', line 116 def self.type_text(params = {}) phisical_keys = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', "\017"] change_keyboard Device::Display.print_line("#{self.text}", params[:line], params[:column]) time = Time.now + (params[:timeout] || Device::IO.timeout) / 1000 key = nil while text_not_ready?(key) line_x, line_y = getxy_stream(100) if line_x && line_y touch_clear key = parse(line_x, line_y, params) else break(Device::IO::KEY_TIMEOUT) if Time.now > time key = getc(100) if phisical_keys.include?(key) if key == Device::IO::BACK show_text({char: :erase}, params) else show_text({char: key}, params) end end end end [key, self.text] end |