class Qt1070::Qt1070

Constants

I2C_ADDRESS

Public Class Methods

new(i2c) click to toggle source
# File lib/qt1070/qt1070.rb, line 8
def initialize i2c
        @i2c = i2c
end

Public Instance Methods

adjacent_key_suppression_level(key) click to toggle source

TODO write to this register

# File lib/qt1070/qt1070.rb, line 65
def adjacent_key_suppression_level key
  #TODO parse/check result
  raise "Key index must be between 0 and 6" unless key.between? 0, 6
  read_byte 39 + key
end
calibrate() click to toggle source

TODO write to this register

# File lib/qt1070/qt1070.rb, line 97
def calibrate
  #TODO parse/check result
  read_byte 56
end
chip_id() click to toggle source
# File lib/qt1070/qt1070.rb, line 12
def chip_id
  id = read_byte 0x00
  minor = id & 0x0F
  major = (id >> 4) & 0x0F
  {major: major, minor: minor}
end
detection_integrator_counter(key) click to toggle source

TODO write to this register

# File lib/qt1070/qt1070.rb, line 72
def detection_integrator_counter key
  #TODO parse/check result
  raise "Key index must be between 0 and 6" unless key.between? 0, 6
  read_byte 46 + key
end
detection_status() click to toggle source
# File lib/qt1070/qt1070.rb, line 26
def detection_status
  status = read_byte 0x02
  return "Calibrate" if status & (1 << 7) != 0
  return "Touch" if status & (1 << 0) != 0
  return "Overflow" if status & (1 << 6) != 0
  "Undefined"
end
firmware_version() click to toggle source
# File lib/qt1070/qt1070.rb, line 19
def firmware_version
  version = read_byte 0x01
  minor = version & 0x0F
  major = (version >> 4) & 0x0F
  "#{major}.#{minor}"
end
fo_mo_guard_no() click to toggle source

TODO write to this register

# File lib/qt1070/qt1070.rb, line 79
def fo_mo_guard_no
  #TODO parse/check result
  read_byte 53
end
key_signal(key) click to toggle source
# File lib/qt1070/qt1070.rb, line 46
def key_signal key
  raise "Key index must be between 0 and 6" unless key.between? 0, 6
  register = 0x04 + (key * 2)
  read_short register
end
key_status(key = nil) click to toggle source
# File lib/qt1070/qt1070.rb, line 34
def key_status key = nil
  unless key.nil?
      raise "Key index must be between 0 and 6" unless key.between? 0, 6
  end
  status_value = read_byte 0x03
  status = [] 
  8.times do |i|
    status[i] = status_value & (1 << i) != 0 ? "pressed" : "released"
  end
  key.nil? ? status : status[i]
end
low_power_mode() click to toggle source

TODO write to this register

# File lib/qt1070/qt1070.rb, line 85
def low_power_mode
  #TODO parse/check result
  read_byte 54
end
maximum_on_duration() click to toggle source

TODO write to this register

# File lib/qt1070/qt1070.rb, line 91
def maximum_on_duration
  #TODO parse/check result
  read_byte 55
end
negative_threshold_level(key) click to toggle source

TODO write to this register

# File lib/qt1070/qt1070.rb, line 59
def negative_threshold_level key
  raise "Key index must be between 0 and 6" unless key.between? 0, 6
  read_byte 32 + key
end
reference_data(key) click to toggle source
# File lib/qt1070/qt1070.rb, line 52
def reference_data key
  raise "Key index must b between 0 and 6" unless key.between? 0, 6
  register = 18 + (key * 2)
  read_short register
end
reset() click to toggle source

TODO write to this register

# File lib/qt1070/qt1070.rb, line 103
def reset
  #TODO parse/check result
  read_byte 57
end

Private Instance Methods

read(register, read_bytes = 1) click to toggle source
# File lib/qt1070/qt1070.rb, line 109
def read register, read_bytes = 1
  @i2c.read I2C_ADDRESS, read_bytes , register
end
read_byte(register) click to toggle source
# File lib/qt1070/qt1070.rb, line 113
def read_byte register
  data = read register
  data.unpack("C").first
end
read_short(register) click to toggle source
# File lib/qt1070/qt1070.rb, line 118
def read_short register
  data = read register, 2
  data.unpack("S_").first
end