qt1070 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/qt1070/qt1070.rb +113 -6
- data/lib/qt1070/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33cd55716699c6d5130b03225d9471da3661ed55
|
4
|
+
data.tar.gz: 52b0cb5f04ee121278a0bd486a35831630674f99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de0a34d49f28274b7631c77fe3577979ec6557596f8cc83b575c6e06179f2083eaf0370133ef25ea6e160eadcde0edc2d393a9dd5d76026bb52ac187688841fd
|
7
|
+
data.tar.gz: 494629066335cb701d3e86d4aef236a2cb4a6afae6530a1063c6b400d57798208a289b115fe7b5fd9a4a5c1244002eb4327581b134584c38ce07964f67399bd3
|
data/lib/qt1070/qt1070.rb
CHANGED
@@ -2,16 +2,123 @@ require "i2c"
|
|
2
2
|
|
3
3
|
module Qt1070
|
4
4
|
class Qt1070
|
5
|
-
|
5
|
+
|
6
6
|
I2C_ADDRESS = 0x1B
|
7
|
-
|
7
|
+
|
8
8
|
def initialize port
|
9
|
-
@i2c = I2C.create port
|
9
|
+
@i2c = I2C.create port
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def chip_id
|
13
|
+
id = read_byte 0x00
|
14
|
+
minor = id & 0x0F
|
15
|
+
major = (id >> 4) & 0x0F
|
16
|
+
{major: major, minor: minor}
|
17
|
+
end
|
18
|
+
|
19
|
+
def firmware_version
|
20
|
+
version = read_byte 0x01
|
21
|
+
minor = version & 0x0F
|
22
|
+
major = (version >> 4) & 0x0F
|
23
|
+
"#{major}.#{minor}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def detection_status
|
27
|
+
status = read_byte 0x02
|
28
|
+
return "Calibrate" if status & (1 << 7) != 0
|
29
|
+
return "Touch" if status & (1 << 0) != 0
|
30
|
+
return "Overflow" if status & (1 << 6) != 0
|
31
|
+
"Undefined"
|
32
|
+
end
|
33
|
+
|
34
|
+
def key_status key = nil
|
35
|
+
unless key.nil?
|
36
|
+
raise "Key index must be between 0 and 6" unless key.between? 0, 6
|
37
|
+
end
|
38
|
+
status_value = read_byte 0x03
|
39
|
+
status = []
|
40
|
+
8.times do |i|
|
41
|
+
status[i] = status_value & (1 << i) != 0 ? "pressed" : "released"
|
42
|
+
end
|
43
|
+
key.nil? ? status : status[i]
|
44
|
+
end
|
45
|
+
|
46
|
+
def key_signal key
|
47
|
+
raise "Key index must be between 0 and 6" unless key.between? 0, 6
|
48
|
+
register = 0x04 + (key * 2)
|
49
|
+
read_short register
|
50
|
+
end
|
51
|
+
|
52
|
+
def reference_data key
|
53
|
+
raise "Key index must b between 0 and 6" unless key.between? 0, 6
|
54
|
+
register = 18 + (key * 2)
|
55
|
+
read_short register
|
56
|
+
end
|
57
|
+
|
58
|
+
#TODO write to this register
|
59
|
+
def negative_threshold_level key
|
60
|
+
raise "Key index must be between 0 and 6" unless key.between? 0, 6
|
61
|
+
read_byte 32 + key
|
62
|
+
end
|
63
|
+
|
64
|
+
#TODO write to this register
|
65
|
+
def adjacent_key_suppression_level key
|
66
|
+
#TODO parse/check result
|
67
|
+
raise "Key index must be between 0 and 6" unless key.between? 0, 6
|
68
|
+
read_byte 39 + key
|
69
|
+
end
|
70
|
+
|
71
|
+
#TODO write to this register
|
72
|
+
def detection_integrator_counter key
|
73
|
+
#TODO parse/check result
|
74
|
+
raise "Key index must be between 0 and 6" unless key.between? 0, 6
|
75
|
+
read_byte 46 + key
|
76
|
+
end
|
77
|
+
|
78
|
+
#TODO write to this register
|
79
|
+
def fo_mo_guard_no
|
80
|
+
#TODO parse/check result
|
81
|
+
read_byte 53
|
82
|
+
end
|
83
|
+
|
84
|
+
#TODO write to this register
|
85
|
+
def low_power_mode
|
86
|
+
#TODO parse/check result
|
87
|
+
read_byte 54
|
88
|
+
end
|
89
|
+
|
90
|
+
#TODO write to this register
|
91
|
+
def maximum_on_duration
|
92
|
+
#TODO parse/check result
|
93
|
+
read_byte 55
|
94
|
+
end
|
95
|
+
|
96
|
+
#TODO write to this register
|
97
|
+
def calibrate
|
98
|
+
#TODO parse/check result
|
99
|
+
read_byte 56
|
100
|
+
end
|
101
|
+
|
102
|
+
#TODO write to this register
|
103
|
+
def reset
|
104
|
+
#TODO parse/check result
|
105
|
+
read_byte 57
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
def read register, read_bytes = 1
|
110
|
+
@i2c.read I2C_ADDRESS, read_bytes , register
|
111
|
+
end
|
112
|
+
|
113
|
+
def read_byte register
|
114
|
+
data = read register
|
115
|
+
data.unpack("C").first
|
116
|
+
end
|
117
|
+
|
118
|
+
def read_short register
|
119
|
+
data = read register, 2
|
120
|
+
data.unpack("S_").first
|
121
|
+
end
|
15
122
|
end
|
16
123
|
|
17
124
|
end
|
data/lib/qt1070/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qt1070
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sille Van Landschoot
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|