sensors 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sensors.rb +51 -0
- data/lib/sensors/c.rb +43 -0
- data/lib/sensors/c/functions.rb +53 -0
- data/lib/sensors/c/types.rb +178 -0
- data/lib/sensors/chip.rb +84 -0
- data/lib/sensors/feature.rb +68 -0
- data/lib/sensors/subfeature.rb +65 -0
- metadata +70 -0
data/lib/sensors.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
11
|
+
# of conditions and the following disclaimer in the documentation and/or other materials
|
12
|
+
# provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
15
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
|
17
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those of the
|
25
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
26
|
+
# or implied.
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'sensors/c'
|
30
|
+
|
31
|
+
require 'sensors/chip'
|
32
|
+
|
33
|
+
module Sensors
|
34
|
+
def self.initialize (config=nil)
|
35
|
+
C::sensors_cleanup()
|
36
|
+
C::sensors_init(config ? File.new(config, ?r) : nil)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.chips (match=nil)
|
40
|
+
Enumerator.new do |e|
|
41
|
+
number = FFI::MemoryPointer.new :int
|
42
|
+
match = Chip.new(match.to_s) if match
|
43
|
+
|
44
|
+
until (chip = C::sensors_get_detected_chips(match.to_ffi, number)).null?
|
45
|
+
e << Chip.new(chip)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
Sensors.initialize
|
data/lib/sensors/c.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
11
|
+
# of conditions and the following disclaimer in the documentation and/or other materials
|
12
|
+
# provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
15
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
|
17
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those of the
|
25
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
26
|
+
# or implied.
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'ffi'
|
30
|
+
require 'ffi/extra'
|
31
|
+
|
32
|
+
module Sensors
|
33
|
+
|
34
|
+
module C
|
35
|
+
extend FFI::Library
|
36
|
+
|
37
|
+
ffi_lib 'sensors'
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
require 'sensors/c/types'
|
43
|
+
require 'sensors/c/functions'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
11
|
+
# of conditions and the following disclaimer in the documentation and/or other materials
|
12
|
+
# provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
15
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
|
17
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those of the
|
25
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
26
|
+
# or implied.
|
27
|
+
#++
|
28
|
+
|
29
|
+
module Sensors; module C
|
30
|
+
|
31
|
+
attach_function :sensors_init, [:buffer_out], :int
|
32
|
+
attach_function :sensors_cleanup, [], :void
|
33
|
+
|
34
|
+
attach_function :sensors_parse_chip_name, [:string, :pointer], :int
|
35
|
+
attach_function :sensors_free_chip_name, [:pointer], :void
|
36
|
+
attach_function :sensors_snprintf_chip_name, [:pointer, :size_t, :pointer], :int
|
37
|
+
|
38
|
+
attach_function :sensors_get_adapter_name, [:pointer], :string
|
39
|
+
|
40
|
+
attach_function :sensors_get_label, [:pointer, :pointer], :string
|
41
|
+
|
42
|
+
attach_function :sensors_get_value, [:pointer, :int, :pointer], :int
|
43
|
+
attach_function :sensors_set_value, [:pointer, :int, :double], :int
|
44
|
+
|
45
|
+
attach_function :sensors_do_chip_sets, [:pointer], :int
|
46
|
+
attach_function :sensors_get_detected_chips, [:pointer, :pointer], :pointer
|
47
|
+
|
48
|
+
attach_function :sensors_get_features, [:pointer, :pointer], :pointer
|
49
|
+
|
50
|
+
attach_function :sensors_get_all_subfeatures, [:pointer, :pointer, :pointer], :pointer
|
51
|
+
attach_function :sensors_get_subfeature, [:pointer, :pointer, SubfeatureType], :pointer
|
52
|
+
|
53
|
+
end; end
|
@@ -0,0 +1,178 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
11
|
+
# of conditions and the following disclaimer in the documentation and/or other materials
|
12
|
+
# provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
15
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
|
17
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those of the
|
25
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
26
|
+
# or implied.
|
27
|
+
#++
|
28
|
+
|
29
|
+
module Sensors; module C
|
30
|
+
|
31
|
+
# :string, :libsensors_version # TODO: look how to get an extern var
|
32
|
+
|
33
|
+
BusType = FFI::Enum.new([
|
34
|
+
:any, -1,
|
35
|
+
:i2c,
|
36
|
+
:isa,
|
37
|
+
:pci,
|
38
|
+
:spi,
|
39
|
+
:virtual,
|
40
|
+
:acpi,
|
41
|
+
:hid
|
42
|
+
])
|
43
|
+
|
44
|
+
module BusNumber
|
45
|
+
Any = -1
|
46
|
+
Ignore = -2
|
47
|
+
end
|
48
|
+
|
49
|
+
class BusId < FFI::Struct
|
50
|
+
layout \
|
51
|
+
:type, :short,
|
52
|
+
:nr, :short
|
53
|
+
end
|
54
|
+
|
55
|
+
class ChipName < FFI::Struct
|
56
|
+
layout \
|
57
|
+
:prefix, :string,
|
58
|
+
:bus, BusId,
|
59
|
+
:addr, :int,
|
60
|
+
:path, :string
|
61
|
+
end
|
62
|
+
|
63
|
+
FeatureType = FFI::Enum.new([
|
64
|
+
:in, 0x00,
|
65
|
+
:fan, 0x01,
|
66
|
+
:temp, 0x02,
|
67
|
+
:power, 0x03,
|
68
|
+
:energy, 0x04,
|
69
|
+
:curr, 0x05,
|
70
|
+
:humidity, 0x06,
|
71
|
+
:max_main,
|
72
|
+
:vid, 0x10,
|
73
|
+
:intrusion, 0x11,
|
74
|
+
:max_other,
|
75
|
+
:beep_enable, 0x18
|
76
|
+
# :unknown, INT_MAX
|
77
|
+
])
|
78
|
+
|
79
|
+
SubfeatureType = FFI::Enum.new([
|
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
|
+
])
|
159
|
+
|
160
|
+
class Feature < FFI::Struct
|
161
|
+
layout \
|
162
|
+
:name, :string,
|
163
|
+
:number, :int,
|
164
|
+
:type, FeatureType,
|
165
|
+
:mapping, :int,
|
166
|
+
:flags, :uint
|
167
|
+
end
|
168
|
+
|
169
|
+
class Subfeature < FFI::Struct
|
170
|
+
layout \
|
171
|
+
:name, :string,
|
172
|
+
:number, :int,
|
173
|
+
:type, SubfeatureType,
|
174
|
+
:mapping, :int,
|
175
|
+
:flags, :uint
|
176
|
+
end
|
177
|
+
|
178
|
+
end; end
|
data/lib/sensors/chip.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
11
|
+
# of conditions and the following disclaimer in the documentation and/or other materials
|
12
|
+
# provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
15
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
|
17
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those of the
|
25
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
26
|
+
# or implied.
|
27
|
+
#++
|
28
|
+
|
29
|
+
require 'sensors/feature'
|
30
|
+
require 'sensors/subfeature'
|
31
|
+
|
32
|
+
module Sensors
|
33
|
+
|
34
|
+
class Chip
|
35
|
+
attr_reader :name
|
36
|
+
|
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
|
+
|
45
|
+
ObjectSpace.define_finalizer self, Chip.finalizer(@chip_name.pointer)
|
46
|
+
end
|
47
|
+
|
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
|
+
|
57
|
+
def self.finalizer (pointer)
|
58
|
+
proc {
|
59
|
+
C::sensors_free_chip_name(pointer)
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
def features
|
64
|
+
Enumerator.new do |e|
|
65
|
+
number = FFI::MemoryPointer.new :int
|
66
|
+
|
67
|
+
until (feature = C::sensors_get_features(to_ffi, number)).null?
|
68
|
+
e << Feature.new(self, feature)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
alias to_s name
|
74
|
+
|
75
|
+
def inspect
|
76
|
+
"#<Chip: #{name || 'unknown'}>"
|
77
|
+
end
|
78
|
+
|
79
|
+
def to_ffi
|
80
|
+
@chip_name
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
11
|
+
# of conditions and the following disclaimer in the documentation and/or other materials
|
12
|
+
# provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
15
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
|
17
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those of the
|
25
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
26
|
+
# or implied.
|
27
|
+
#++
|
28
|
+
|
29
|
+
module Sensors
|
30
|
+
|
31
|
+
class Feature
|
32
|
+
attr_reader :chip, :label
|
33
|
+
|
34
|
+
def initialize (chip, pointer)
|
35
|
+
@chip = chip
|
36
|
+
@value = pointer.is_a?(C::Feature) ? pointer : C::Feature.new(pointer)
|
37
|
+
|
38
|
+
@label = C::sensors_get_label(chip.to_ffi, to_ffi)
|
39
|
+
end
|
40
|
+
|
41
|
+
C::Feature.layout.members.each {|name|
|
42
|
+
define_method name do
|
43
|
+
@value[name]
|
44
|
+
end
|
45
|
+
}
|
46
|
+
|
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
|
+
|
51
|
+
def subfeatures
|
52
|
+
Enumerator.new do |e|
|
53
|
+
number = FFI::MemoryPointer.new :int
|
54
|
+
|
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
|
+
|
61
|
+
alias to_s name
|
62
|
+
|
63
|
+
def to_ffi
|
64
|
+
@value
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
|
3
|
+
#
|
4
|
+
# Redistribution and use in source and binary forms, with or without modification, are
|
5
|
+
# permitted provided that the following conditions are met:
|
6
|
+
#
|
7
|
+
# 1. Redistributions of source code must retain the above copyright notice, this list of
|
8
|
+
# conditions and the following disclaimer.
|
9
|
+
#
|
10
|
+
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
11
|
+
# of conditions and the following disclaimer in the documentation and/or other materials
|
12
|
+
# provided with the distribution.
|
13
|
+
#
|
14
|
+
# THIS SOFTWARE IS PROVIDED BY meh ''AS IS'' AND ANY EXPRESS OR IMPLIED
|
15
|
+
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL meh OR
|
17
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
18
|
+
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
19
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
20
|
+
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
21
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
22
|
+
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
23
|
+
#
|
24
|
+
# The views and conclusions contained in the software and documentation are those of the
|
25
|
+
# authors and should not be interpreted as representing official policies, either expressed
|
26
|
+
# or implied.
|
27
|
+
#++
|
28
|
+
|
29
|
+
module Sensors
|
30
|
+
|
31
|
+
class Subfeature
|
32
|
+
attr_reader :chip
|
33
|
+
|
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
|
+
|
40
|
+
C::Subfeature.layout.members.each {|name|
|
41
|
+
define_method name do
|
42
|
+
@value[name]
|
43
|
+
end
|
44
|
+
}
|
45
|
+
|
46
|
+
def value
|
47
|
+
FFI::MemoryPointer.new(:double).tap {|result|
|
48
|
+
C::sensors_get_value(chip.to_ffi, to_ffi, result)
|
49
|
+
|
50
|
+
break result.typecast(:double)
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def value= (value)
|
55
|
+
C::sensors_set_value(chip.to_ffi, to_ffi, value)
|
56
|
+
end
|
57
|
+
|
58
|
+
alias to_s name
|
59
|
+
|
60
|
+
def to_ffi
|
61
|
+
number
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensors
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- meh.
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-09-02 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: ffi
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
description:
|
27
|
+
email: meh@paranoici.org
|
28
|
+
executables: []
|
29
|
+
|
30
|
+
extensions: []
|
31
|
+
|
32
|
+
extra_rdoc_files: []
|
33
|
+
|
34
|
+
files:
|
35
|
+
- lib/sensors.rb
|
36
|
+
- lib/sensors/subfeature.rb
|
37
|
+
- lib/sensors/feature.rb
|
38
|
+
- lib/sensors/c/types.rb
|
39
|
+
- lib/sensors/c/functions.rb
|
40
|
+
- lib/sensors/c.rb
|
41
|
+
- lib/sensors/chip.rb
|
42
|
+
homepage: http://github.com/meh/ruby-sensors
|
43
|
+
licenses: []
|
44
|
+
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "0"
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.8.5
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: Bindings and wrapper for libsensors
|
69
|
+
test_files: []
|
70
|
+
|