sensors 0.0.1 → 0.0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sensors.rb +2 -2
- data/lib/sensors/c/types.rb +101 -101
- data/lib/sensors/chip.rb +38 -38
- data/lib/sensors/feature.rb +22 -22
- data/lib/sensors/subfeature.rb +20 -20
- metadata +13 -2
data/lib/sensors.rb
CHANGED
@@ -38,13 +38,13 @@ module Sensors
|
|
38
38
|
|
39
39
|
def self.chips (match=nil)
|
40
40
|
Enumerator.new do |e|
|
41
|
-
|
41
|
+
number = FFI::MemoryPointer.new :int
|
42
42
|
match = Chip.new(match.to_s) if match
|
43
43
|
|
44
44
|
until (chip = C::sensors_get_detected_chips(match.to_ffi, number)).null?
|
45
45
|
e << Chip.new(chip)
|
46
46
|
end
|
47
|
-
|
47
|
+
end
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
data/lib/sensors/c/types.rb
CHANGED
@@ -31,19 +31,19 @@ module Sensors; module C
|
|
31
31
|
# :string, :libsensors_version # TODO: look how to get an extern var
|
32
32
|
|
33
33
|
BusType = FFI::Enum.new([
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
34
|
+
:any, -1,
|
35
|
+
:i2c,
|
36
|
+
:isa,
|
37
|
+
:pci,
|
38
|
+
:spi,
|
39
|
+
:virtual,
|
40
|
+
:acpi,
|
41
|
+
:hid
|
42
42
|
])
|
43
43
|
|
44
44
|
module BusNumber
|
45
|
-
|
46
|
-
|
45
|
+
Any = -1
|
46
|
+
Ignore = -2
|
47
47
|
end
|
48
48
|
|
49
49
|
class BusId < FFI::Struct
|
@@ -62,7 +62,7 @@ end
|
|
62
62
|
|
63
63
|
FeatureType = FFI::Enum.new([
|
64
64
|
:in, 0x00,
|
65
|
-
|
65
|
+
:fan, 0x01,
|
66
66
|
:temp, 0x02,
|
67
67
|
:power, 0x03,
|
68
68
|
:energy, 0x04,
|
@@ -77,102 +77,102 @@ FeatureType = FFI::Enum.new([
|
|
77
77
|
])
|
78
78
|
|
79
79
|
SubfeatureType = FFI::Enum.new([
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
#
|
80
|
+
:in_input, FeatureType[:in] << 8,
|
81
|
+
:in_min,
|
82
|
+
:in_max,
|
83
|
+
:in_lcrit,
|
84
|
+
:in_crit,
|
85
|
+
:in_alarm, (FeatureType[:in] << 8) | 0x80,
|
86
|
+
:in_min_alarm,
|
87
|
+
:in_max_alarm,
|
88
|
+
:in_beep,
|
89
|
+
:in_lcrit_alarm,
|
90
|
+
:in_crit_alarm,
|
91
|
+
|
92
|
+
:fan_input, FeatureType[:fan] << 8,
|
93
|
+
:fan_min,
|
94
|
+
:fan_alarm, (FeatureType[:fan] << 8) | 0x80,
|
95
|
+
:fan_fault,
|
96
|
+
:fan_div,
|
97
|
+
:fan_beep,
|
98
|
+
:fan_pulses,
|
99
|
+
|
100
|
+
:temp_input, FeatureType[:temp] << 8,
|
101
|
+
:temp_max,
|
102
|
+
:temp_max_hyst,
|
103
|
+
:temp_min,
|
104
|
+
:temp_crit,
|
105
|
+
:temp_crit_hyst,
|
106
|
+
:temp_lcrit,
|
107
|
+
:temp_emergency,
|
108
|
+
:temp_emergency_hist,
|
109
|
+
:temp_alarm, (FeatureType[:temp] << 8) | 0x80,
|
110
|
+
:temp_max_alarm,
|
111
|
+
:temp_min_alarm,
|
112
|
+
:temp_crit_alarm,
|
113
|
+
:temp_fault,
|
114
|
+
:temp_type,
|
115
|
+
:temp_offset,
|
116
|
+
:temp_beep,
|
117
|
+
:temp_emergency_alarm,
|
118
|
+
:temp_lcrit_alarm,
|
119
|
+
|
120
|
+
:power_average, FeatureType[:power] << 8,
|
121
|
+
:power_average_highest,
|
122
|
+
:power_average_lowest,
|
123
|
+
:power_input,
|
124
|
+
:power_input_highest,
|
125
|
+
:power_input_lowest,
|
126
|
+
:power_cap,
|
127
|
+
:power_cap_hyst,
|
128
|
+
:power_max,
|
129
|
+
:power_crit,
|
130
|
+
:power_average_interval, (FeatureType[:power] << 8) | 0x80,
|
131
|
+
:power_alarm,
|
132
|
+
:power_cap_alarm,
|
133
|
+
:power_max_alarm,
|
134
|
+
:power_crit_alarm,
|
135
|
+
|
136
|
+
:energy_input, FeatureType[:energy] << 8,
|
137
|
+
|
138
|
+
:curr_input, FeatureType[:curr] << 8,
|
139
|
+
:curr_min,
|
140
|
+
:curr_max,
|
141
|
+
:curr_lcrit,
|
142
|
+
:curr_crit,
|
143
|
+
:curr_alarm, (FeatureType[:curr] << 8) | 0x80,
|
144
|
+
:curr_min_alarm,
|
145
|
+
:curr_max_alarm,
|
146
|
+
:curr_beep,
|
147
|
+
:curr_lcrit_alarm,
|
148
|
+
:curr_crit_alarm,
|
149
|
+
|
150
|
+
:humidity_input, FeatureType[:humidity] << 8,
|
151
|
+
|
152
|
+
:vid, FeatureType[:vid] << 8,
|
153
|
+
|
154
|
+
:intrusion_alarm, FeatureType[:intrusion] << 8,
|
155
|
+
:intrusion_beep
|
156
|
+
|
157
|
+
# :unknown, INT_MAX
|
158
158
|
])
|
159
159
|
|
160
160
|
class Feature < FFI::Struct
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
161
|
+
layout \
|
162
|
+
:name, :string,
|
163
|
+
:number, :int,
|
164
|
+
:type, FeatureType,
|
165
|
+
:mapping, :int,
|
166
|
+
:flags, :uint
|
167
167
|
end
|
168
168
|
|
169
169
|
class Subfeature < FFI::Struct
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
170
|
+
layout \
|
171
|
+
:name, :string,
|
172
|
+
:number, :int,
|
173
|
+
:type, SubfeatureType,
|
174
|
+
:mapping, :int,
|
175
|
+
:flags, :uint
|
176
176
|
end
|
177
177
|
|
178
178
|
end; end
|
data/lib/sensors/chip.rb
CHANGED
@@ -32,53 +32,53 @@ require 'sensors/subfeature'
|
|
32
32
|
module Sensors
|
33
33
|
|
34
34
|
class Chip
|
35
|
-
|
35
|
+
attr_reader :name
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
37
|
+
def initialize (name=nil)
|
38
|
+
if name.is_a?(C::ChipName) || name.is_a?(FFI::Pointer)
|
39
|
+
@chip_name = name.is_a?(C::ChipName) ? name : C::ChipName.new(name)
|
40
|
+
name = nil
|
41
|
+
else
|
42
|
+
@chip_name = C::ChipName.new
|
43
|
+
C::sensors_parse_chip_name(name, @chip_name)
|
44
44
|
|
45
|
-
|
46
|
-
|
45
|
+
ObjectSpace.define_finalizer self, Chip.finalizer(@chip_name.pointer)
|
46
|
+
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
48
|
+
FFI::MemoryPointer.new(512).tap {|pointer|
|
49
|
+
@name = if C::sensors_snprintf_chip_name(pointer, 512, to_ffi) < 0
|
50
|
+
name
|
51
|
+
else
|
52
|
+
pointer.typecast(:string)
|
53
|
+
end
|
54
|
+
}
|
55
|
+
end
|
56
56
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
57
|
+
def self.finalizer (pointer)
|
58
|
+
proc {
|
59
|
+
C::sensors_free_chip_name(pointer)
|
60
|
+
}
|
61
|
+
end
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
def features
|
64
|
+
Enumerator.new do |e|
|
65
|
+
number = FFI::MemoryPointer.new :int
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
67
|
+
until (feature = C::sensors_get_features(to_ffi, number)).null?
|
68
|
+
e << Feature.new(self, feature)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
72
|
|
73
|
-
|
73
|
+
alias to_s name
|
74
74
|
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
def inspect
|
76
|
+
"#<Chip: #{name || 'unknown'}>"
|
77
|
+
end
|
78
78
|
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
def to_ffi
|
80
|
+
@chip_name
|
81
|
+
end
|
82
82
|
end
|
83
83
|
|
84
84
|
end
|
data/lib/sensors/feature.rb
CHANGED
@@ -29,40 +29,40 @@
|
|
29
29
|
module Sensors
|
30
30
|
|
31
31
|
class Feature
|
32
|
-
|
32
|
+
attr_reader :chip, :label
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
34
|
+
def initialize (chip, pointer)
|
35
|
+
@chip = chip
|
36
|
+
@value = pointer.is_a?(C::Feature) ? pointer : C::Feature.new(pointer)
|
37
37
|
|
38
|
-
|
39
|
-
|
38
|
+
@label = C::sensors_get_label(chip.to_ffi, to_ffi)
|
39
|
+
end
|
40
40
|
|
41
|
-
|
41
|
+
C::Feature.layout.members.each {|name|
|
42
42
|
define_method name do
|
43
43
|
@value[name]
|
44
44
|
end
|
45
45
|
}
|
46
46
|
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
def subfeature (type)
|
48
|
+
Subfeature.new(self, C::sensors_get_subfeature(chip.to_ffi, to_ffi, C::SubfeatureType["#{feature.type}_#{type.downcase}".to_sym]))
|
49
|
+
end
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
def subfeatures
|
52
|
+
Enumerator.new do |e|
|
53
|
+
number = FFI::MemoryPointer.new :int
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
until (subfeature = C::sensors_get_all_subfeatures(chip.to_ffi, to_ffi, number)).null?
|
56
|
+
e << Subfeature.new(self, subfeature)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
60
|
|
61
|
-
|
61
|
+
alias to_s name
|
62
62
|
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
def to_ffi
|
64
|
+
@value
|
65
|
+
end
|
66
66
|
end
|
67
67
|
|
68
68
|
end
|
data/lib/sensors/subfeature.rb
CHANGED
@@ -29,37 +29,37 @@
|
|
29
29
|
module Sensors
|
30
30
|
|
31
31
|
class Subfeature
|
32
|
-
|
32
|
+
attr_reader :chip
|
33
33
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
34
|
+
def initialize (feature, pointer)
|
35
|
+
@chip = feature.chip
|
36
|
+
@feature = feature
|
37
|
+
@value = pointer.is_a?(C::Subfeature) ? pointer : C::Subfeature.new(pointer)
|
38
|
+
end
|
39
39
|
|
40
|
-
|
40
|
+
C::Subfeature.layout.members.each {|name|
|
41
41
|
define_method name do
|
42
42
|
@value[name]
|
43
43
|
end
|
44
44
|
}
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
46
|
+
def value
|
47
|
+
FFI::MemoryPointer.new(:double).tap {|result|
|
48
|
+
C::sensors_get_value(chip.to_ffi, to_ffi, result)
|
49
49
|
|
50
|
-
|
51
|
-
|
52
|
-
|
50
|
+
break result.typecast(:double)
|
51
|
+
}
|
52
|
+
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
def value= (value)
|
55
|
+
C::sensors_set_value(chip.to_ffi, to_ffi, value)
|
56
|
+
end
|
57
57
|
|
58
|
-
|
58
|
+
alias to_s name
|
59
59
|
|
60
|
-
|
61
|
-
|
62
|
-
|
60
|
+
def to_ffi
|
61
|
+
number
|
62
|
+
end
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: sensors
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.1
|
5
|
+
version: 0.0.1.1
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- meh.
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-09-
|
13
|
+
date: 2011-09-06 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ffi
|
@@ -23,6 +23,17 @@ dependencies:
|
|
23
23
|
version: "0"
|
24
24
|
type: :runtime
|
25
25
|
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: ffi-extra
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id002
|
26
37
|
description:
|
27
38
|
email: meh@paranoici.org
|
28
39
|
executables: []
|