Class: Device::VirtualKeyboard

Inherits:
Object
  • Object
show all
Defined in:
lib/device/virtual_keyboard.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.attributesObject

Returns the value of attribute attributes.



6
7
8
# File 'lib/device/virtual_keyboard.rb', line 6

def attributes
  @attributes
end

.textObject

Returns the value of attribute text.



6
7
8
# File 'lib/device/virtual_keyboard.rb', line 6

def text
  @text
end

.typeObject

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_keyboardObject



225
226
227
228
229
230
231
232
# File 'lib/device/virtual_keyboard.rb', line 225

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



195
196
197
198
199
200
201
202
203
204
205
# File 'lib/device/virtual_keyboard.rb', line 195

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



207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/device/virtual_keyboard.rb', line 207

def self.show_text(key, params)
  case key[:char]
  when :keyboard_uppercase, :keyboard_symbol_number, :keyboard_symbol_number_2, :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
    if self.text && self.text.size < 20
      self.text << key[:char] unless key[:char] == :enter
    end
  end
  Device::Display.print_line("#{self.text}", params[:line], params[:column])
end

.text_not_ready?(key) ⇒ Boolean

Returns:

  • (Boolean)


191
192
193
# File 'lib/device/virtual_keyboard.rb', line 191

def self.text_not_ready?(key)
  key != :enter && key != Device::IO::ENTER && key != Device::IO::CANCEL
end

.type_text(params = {}) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/device/virtual_keyboard.rb', line 158

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])
  if params[:timeout_enabled]
    time = Time.now + (params[:timeout] || Device::IO.timeout) / 1000
  end

  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
      if params[:timeout_enabled]
        break(Device::IO::KEY_TIMEOUT) if Time.now > time
      end
      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

.wifi_passwordObject



234
235
236
237
238
239
240
# File 'lib/device/virtual_keyboard.rb', line 234

def self.wifi_password
  self.text = if Device::Setting.wifi_password == 'false'
                ''
              else
                Device::Setting.wifi_password
              end
end