tinderfridge 0.4.0 → 0.8.0
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/tinderfridge/device.rb +67 -3
- data/lib/tinderfridge/device_collection.rb +52 -0
- data/lib/tinderfridge/device_info.txt +3 -0
- data/lib/tinderfridge/devices/brick_hat/brick_hat.json +11 -0
- data/lib/tinderfridge/devices/{brick_hat.rb → brick_hat/brick_hat.rb} +0 -0
- data/lib/tinderfridge/devices/brick_hat_zero/brick_hat_zero.json +11 -0
- data/lib/tinderfridge/devices/{brick_hat_zero.rb → brick_hat_zero/brick_hat_zero.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_accelerometer_v2/bricklet_accelerometer_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_air_quality/bricklet_air_quality.json +11 -0
- data/lib/tinderfridge/devices/bricklet_air_quality/bricklet_air_quality.rb +20 -0
- data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.json +10 -0
- data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.rb +19 -0
- data/lib/tinderfridge/devices/bricklet_analog_in_v3/bricklet_analog_in_v3.json +10 -0
- data/lib/tinderfridge/devices/bricklet_analog_out_v3/bricklet_analog_out_v3.json +11 -0
- data/lib/tinderfridge/devices/bricklet_barometer_v2/bricklet_barometer_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_can_v2/bricklet_can_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_co2_v2/bricklet_co2_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_color_v2/bricklet_color_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_color_v2/bricklet_color_v2.rb +31 -0
- data/lib/tinderfridge/devices/bricklet_compass/bricklet_compass.json +10 -0
- data/lib/tinderfridge/devices/bricklet_dc_v2/bricklet_dc_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_distance_ir_v2/bricklet_distance_ir_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_distance_us_v2/bricklet_distance_us_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_dmx/bricklet_dmx.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_dmx.rb → bricklet_dmx/bricklet_dmx.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_dual_button_v2/bricklet_dual_button_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_e_paper_296x128/bricklet_e_paper_296x128.json +10 -0
- data/lib/tinderfridge/devices/bricklet_energy_monitor/bricklet_energy_monitor.json +10 -0
- data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_gps_v2.rb → bricklet_gps_v2/bricklet_gps_v2.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_hall_effect_v2/bricklet_hall_effect_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_humidity_v2/bricklet_humidity_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_imu_v3/bricklet_imu_v3.json +10 -0
- data/lib/tinderfridge/devices/bricklet_industrial_analog_out_v2/bricklet_industrial_analog_out_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_industrial_counter/bricklet_industrial_counter.json +11 -0
- data/lib/tinderfridge/devices/bricklet_industrial_digital_in_4_v2/bricklet_industrial_digital_in_4_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_industrial_digital_out_4_v2/bricklet_industrial_digital_out_4_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_industrial_dual_0_20ma_v2/bricklet_industrial_dual_0_20ma_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_industrial_dual_ac_relay/bricklet_industrial_dual_ac_relay.json +11 -0
- data/lib/tinderfridge/devices/bricklet_industrial_dual_analog_in_v2/bricklet_industrial_dual_analog_in_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_industrial_dual_relay/bricklet_industrial_dual_relay.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_industrial_dual_relay.rb → bricklet_industrial_dual_relay/bricklet_industrial_dual_relay.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_industrial_ptc/bricklet_industrial_ptc.json +11 -0
- data/lib/tinderfridge/devices/bricklet_industrial_quad_relay_v2/bricklet_industrial_quad_relay_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_io16_v2/bricklet_io16_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_io4_v2/bricklet_io4_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_isolator/bricklet_isolator.json +10 -0
- data/lib/tinderfridge/devices/bricklet_isolator/bricklet_isolator.rb +17 -0
- data/lib/tinderfridge/devices/bricklet_joystick_v2/bricklet_joystick_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_joystick_v2/bricklet_joystick_v2.rb +15 -0
- data/lib/tinderfridge/devices/bricklet_laser_range_finder_v2/bricklet_laser_range_finder_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_lcd_128x64.rb → bricklet_lcd_128x64/bricklet_lcd_128x64.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_led_strip_v2/bricklet_led_strip_v2.json +11 -0
- data/lib/tinderfridge/devices/{bricklet_led_strip_v2.rb → bricklet_led_strip_v2/bricklet_led_strip_v2.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_linear_poti_v2/bricklet_linear_poti_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_load_cell_v2/bricklet_load_cell_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_motion_detector_v2/bricklet_motion_detector_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_motion_detector_v2/bricklet_motion_detector_v2.rb +22 -0
- data/lib/tinderfridge/devices/bricklet_motorized_linear_poti/bricklet_motorized_linear_poti.json +10 -0
- data/lib/tinderfridge/devices/bricklet_motorized_linear_poti/bricklet_motorized_linear_poti.rb +42 -0
- data/lib/tinderfridge/devices/bricklet_multi_touch_v2/bricklet_multi_touch_v2.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_multi_touch_v2.rb → bricklet_multi_touch_v2/bricklet_multi_touch_v2.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_nfc/bricklet_nfc.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_nfc.rb → bricklet_nfc/bricklet_nfc.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_one_wire/bricklet_one_wire.json +11 -0
- data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_outdoor_weather.rb → bricklet_outdoor_weather/bricklet_outdoor_weather.rb} +0 -0
- data/lib/tinderfridge/devices/bricklet_particulate_matter/bricklet_particulate_matter.json +11 -0
- data/lib/tinderfridge/devices/bricklet_performance_dc/bricklet_performance_dc.json +11 -0
- data/lib/tinderfridge/devices/bricklet_piezo_speaker_v2/bricklet_piezo_speaker_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_ptc_v2/bricklet_ptc_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_real_time_clock_v2/bricklet_real_time_clock_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_remote_switch_v2/bricklet_remote_switch_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_remote_switch_v2/bricklet_remote_switch_v2.rb +15 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_button/bricklet_rgb_led_button.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_rgb_led_button.rb → bricklet_rgb_led_button/bricklet_rgb_led_button.rb} +9 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_v2/bricklet_rgb_led_v2.json +10 -0
- data/lib/tinderfridge/devices/{bricklet_rgb_led_v2.rb → bricklet_rgb_led_v2/bricklet_rgb_led_v2.rb} +7 -0
- data/lib/tinderfridge/devices/bricklet_rotary_encoder_v2/bricklet_rotary_encoder_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_rotary_encoder_v2/bricklet_rotary_encoder_v2.rb +20 -0
- data/lib/tinderfridge/devices/bricklet_rotary_poti_v2/bricklet_rotary_poti_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_rs232_v2/bricklet_rs232_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_rs485/bricklet_rs485.json +11 -0
- data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.json +11 -0
- data/lib/tinderfridge/devices/{bricklet_segment_display_4x7_v2.rb → bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb} +23 -1
- data/lib/tinderfridge/devices/bricklet_servo_v2/bricklet_servo_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_silent_stepper_v2/bricklet_silent_stepper_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_solid_state_relay_v2/bricklet_solid_state_relay_v2.json +11 -0
- data/lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.json +10 -0
- data/lib/tinderfridge/devices/bricklet_temperature_ir_v2/bricklet_temperature_ir_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_temperature_v2/bricklet_temperature_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_thermal_imaging/bricklet_thermal_imaging.json +10 -0
- data/lib/tinderfridge/devices/bricklet_thermocouple_v2/bricklet_thermocouple_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_uv_light_v2/bricklet_uv_light_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_voltage_current_v2/bricklet_voltage_current_v2.json +10 -0
- data/lib/tinderfridge/devices/bricklet_voltage_current_v2/bricklet_voltage_current_v2.rb +18 -0
- data/lib/tinderfridge/devices/bricklet_xmc1400_breakout/bricklet_xmc1400_breakout.json +10 -0
- data/lib/tinderfridge/ip_connection.rb +56 -4
- data/lib/tinderfridge/tinkerforge.rb +3 -0
- data/lib/tinderfridge/version.rb +1 -1
- metadata +106 -23
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1f848437f1877596a58521fdbe213042f6561b42a91c91b60eca2fd3ab1a690
|
|
4
|
+
data.tar.gz: '09c7adcf40fabf6eae5ca89316428aeb6cabfa5f4abccbaaf27bd3901535afca'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a84bc2687015ef1c65dd61cac031a7b6e6ff57e22a811784e6160dd5b002badf5f55f11c3883ffa754a6f42d0b5a6e5a085a4c930700c899956d06ec8f533d98
|
|
7
|
+
data.tar.gz: c12dcf3ef70b1111f665a3098ab213a75819c2953b3c7cb2ebc020bd00b016588ec70ca0bebbdf72666a84edcc4be345f7aaa67c8ee4f8841262c1fc4afb80a7
|
data/lib/tinderfridge/device.rb
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require 'tinkerforge/ip_connection'
|
|
2
2
|
|
|
3
3
|
module Tinkerforge
|
|
4
|
+
|
|
4
5
|
class Device
|
|
5
6
|
|
|
6
7
|
#----------------------------------------------------------------------#
|
|
@@ -41,7 +42,7 @@ module Tinkerforge
|
|
|
41
42
|
def inherited(klass)
|
|
42
43
|
if info = Tinkerforge.device_info(klass)
|
|
43
44
|
begin
|
|
44
|
-
require("tinderfridge/devices/#{info[2][1]}")
|
|
45
|
+
require("tinderfridge/devices/#{info[2][1]}/#{info[2][1]}")
|
|
45
46
|
rescue LoadError
|
|
46
47
|
# No extension found for this device
|
|
47
48
|
end
|
|
@@ -66,20 +67,42 @@ module Tinkerforge
|
|
|
66
67
|
# Returns the device's IPConnection object.
|
|
67
68
|
attr_reader :ipcon
|
|
68
69
|
|
|
70
|
+
# Returns device information.
|
|
71
|
+
#
|
|
72
|
+
# Device information is an array:
|
|
73
|
+
# - 0 : Device Identifier
|
|
74
|
+
# - 1 : Device Display Name
|
|
75
|
+
# - 2 : Associated class name and source file
|
|
76
|
+
def device_info
|
|
77
|
+
Tinkerforge.device_info device_identifier
|
|
78
|
+
end
|
|
79
|
+
|
|
69
80
|
# Returns a programmer-friendly representation of the device.
|
|
70
81
|
def inspect
|
|
71
82
|
"%s (%s@%s:%s)" % [self.class, @uid_string, ipcon.host, ipcon.port]
|
|
72
83
|
end
|
|
73
84
|
|
|
85
|
+
# Returns the device's properties.
|
|
86
|
+
def properties
|
|
87
|
+
@properties ||= {
|
|
88
|
+
'device_identifier' => device_identifier,
|
|
89
|
+
'device_display_name' => device_display_name,
|
|
90
|
+
}.merge load_properties
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
alias props properties
|
|
94
|
+
|
|
74
95
|
# Returns the device's state.
|
|
75
96
|
def state
|
|
97
|
+
|
|
98
|
+
# BrickDaemon inherits from Device, but has no #get_identity.
|
|
99
|
+
return {} unless respond_to? 'get_identity'
|
|
100
|
+
|
|
76
101
|
identity = get_identity
|
|
77
102
|
|
|
78
103
|
[
|
|
79
104
|
[ 'uid' , uid_string ],
|
|
80
105
|
[ 'update_time' , Time.now.gmtime ],
|
|
81
|
-
[ 'device_identifier' , device_identifier ],
|
|
82
|
-
[ 'device_display_name', device_display_name ],
|
|
83
106
|
[ 'firmware_version' , identity[4].join('.') ],
|
|
84
107
|
|
|
85
108
|
[ 'connected', { 'uid' => identity[1], 'position' => identity[2] } ],
|
|
@@ -92,6 +115,20 @@ module Tinkerforge
|
|
|
92
115
|
].compact.to_h
|
|
93
116
|
end
|
|
94
117
|
|
|
118
|
+
# Opens the online documentation for the device (Mac OS only).
|
|
119
|
+
#
|
|
120
|
+
# When the URL for the documentation is not known, does nothing.
|
|
121
|
+
def open_documentation
|
|
122
|
+
if properties['documentation_en_url'] and ( RUBY_PLATFORM =~ /darwin/ )
|
|
123
|
+
`open #{properties['documentation_en_url']}`
|
|
124
|
+
properties['documentation_en_url']
|
|
125
|
+
else
|
|
126
|
+
nil
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
alias doc open_documentation
|
|
131
|
+
|
|
95
132
|
# Identifies a Tinkerforge device by blinking its status led.
|
|
96
133
|
#
|
|
97
134
|
# Supports recent devices. When invoked on older devices, does nothing.
|
|
@@ -112,5 +149,32 @@ module Tinkerforge
|
|
|
112
149
|
end
|
|
113
150
|
end
|
|
114
151
|
|
|
152
|
+
private
|
|
153
|
+
|
|
154
|
+
def load_properties
|
|
155
|
+
if device_info
|
|
156
|
+
properties_file = File.join(
|
|
157
|
+
File.dirname(__FILE__),
|
|
158
|
+
'devices',
|
|
159
|
+
device_info[2][1],
|
|
160
|
+
device_info[2][1],
|
|
161
|
+
) + '.json'
|
|
162
|
+
|
|
163
|
+
if File.readable? properties_file
|
|
164
|
+
begin
|
|
165
|
+
require 'json'
|
|
166
|
+
JSON.load File.read properties_file
|
|
167
|
+
rescue
|
|
168
|
+
{}
|
|
169
|
+
end
|
|
170
|
+
else
|
|
171
|
+
{}
|
|
172
|
+
end
|
|
173
|
+
else
|
|
174
|
+
{}
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
115
178
|
end
|
|
179
|
+
|
|
116
180
|
end
|
|
@@ -63,11 +63,27 @@ module Tinkerforge
|
|
|
63
63
|
end.size
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
+
# Returns the properties of devices in the collection.
|
|
67
|
+
def properties
|
|
68
|
+
smap 'properties'
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
alias props properties
|
|
72
|
+
|
|
66
73
|
# Returns the state of devices in the collection.
|
|
67
74
|
def state
|
|
68
75
|
smap 'state'
|
|
69
76
|
end
|
|
70
77
|
|
|
78
|
+
# Opens the online documentation for the devices in the collection (Mac OS only).
|
|
79
|
+
#
|
|
80
|
+
# When the URL for a device's documentation is not known, does nothing.
|
|
81
|
+
def open_documentation
|
|
82
|
+
smap 'open_documentation'
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
alias doc open_documentation
|
|
86
|
+
|
|
71
87
|
# Turns off light sources such as screens and RGB LEDs for devices in the collection.
|
|
72
88
|
#
|
|
73
89
|
# Ignores devices that do not support the blackout method.
|
|
@@ -80,6 +96,42 @@ module Tinkerforge
|
|
|
80
96
|
smap('ipcon').values.compact.uniq
|
|
81
97
|
end
|
|
82
98
|
|
|
99
|
+
# Returns an array of devices in the collection matching the selector.
|
|
100
|
+
#
|
|
101
|
+
# Selector argument can be:
|
|
102
|
+
# - Device Identifier
|
|
103
|
+
# - Class name or Device Display Name (Regexp)
|
|
104
|
+
# Selection by regular expression is case-insensitive by default.
|
|
105
|
+
#
|
|
106
|
+
# @example Select by class name and Device Display Name
|
|
107
|
+
# # All 'analog' devices
|
|
108
|
+
# tf = Tinkerforge.connect.discover(1)
|
|
109
|
+
# tf.find_all /analog/
|
|
110
|
+
def find_all(selector)
|
|
111
|
+
case selector
|
|
112
|
+
when Integer
|
|
113
|
+
values.select { |v| v.device_identifier == selector}
|
|
114
|
+
when Regexp
|
|
115
|
+
r = Regexp.new selector.source, Regexp::IGNORECASE
|
|
116
|
+
values.select { |v| v.class.to_s.split('::').last =~ r || v.device_display_name =~ r }
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Returns the first device in the collection matching the selector.
|
|
121
|
+
#
|
|
122
|
+
# Selector argument can be:
|
|
123
|
+
# - Device Identifier
|
|
124
|
+
# - Class name or Device Display Name (Regexp)
|
|
125
|
+
# Selection by regular expression is case-insensitive by default.
|
|
126
|
+
#
|
|
127
|
+
# @example Select by Device Identifier
|
|
128
|
+
# # Remote Switch Bricklet 2.0
|
|
129
|
+
# tf = Tinkerforge.connect('myhost.local').discover(1)
|
|
130
|
+
# tf.find 289
|
|
131
|
+
def find(selector)
|
|
132
|
+
find_all(selector).first
|
|
133
|
+
end
|
|
134
|
+
|
|
83
135
|
private
|
|
84
136
|
|
|
85
137
|
def smap(m)
|
|
@@ -139,3 +139,6 @@
|
|
|
139
139
|
2157 Servo Bricklet 2.0 Tinkerforge::BrickletServoV2 bricklet_servo_v2
|
|
140
140
|
2161 IMU Bricklet 3.0 Tinkerforge::BrickletIMUV3 bricklet_imu_v3
|
|
141
141
|
2162 Industrial Dual AC Relay Bricklet Tinkerforge::BrickletIndustrialDualACRelay bricklet_industrial_dual_ac_relay
|
|
142
|
+
2164 Industrial PTC Bricklet Tinkerforge::BrickletIndustrialPTC bricklet_industrial_ptc
|
|
143
|
+
2165 DC Bricklet 2.0 Tinkerforge::BrickletDCV2 bricklet_dc_v2
|
|
144
|
+
2166 Silent Stepper Bricklet 2.0 Tinkerforge::BrickletSilentStepperV2 bricklet_silent_stepper_v2
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Tinkerforge
|
|
2
|
+
|
|
3
|
+
class BrickletAirQuality
|
|
4
|
+
|
|
5
|
+
# Returns the device's state.
|
|
6
|
+
def state
|
|
7
|
+
av = get_all_values
|
|
8
|
+
super.merge(
|
|
9
|
+
'iaq_index' => av[0],
|
|
10
|
+
'iaq_index_accuracy' => av[1],
|
|
11
|
+
'temperature' => av[2],
|
|
12
|
+
'temperature_offset' => get_temperature_offset,
|
|
13
|
+
'humidity' => av[3],
|
|
14
|
+
'air_pressure' => av[4],
|
|
15
|
+
)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Tinkerforge
|
|
2
|
+
|
|
3
|
+
class BrickletAmbientLightV3
|
|
4
|
+
|
|
5
|
+
ILLUMINANCE_RANGES = [ 64000, 32000, 16000, 8000, 1300, 600, 100000 ]
|
|
6
|
+
|
|
7
|
+
# Returns the device's state.
|
|
8
|
+
def state
|
|
9
|
+
super.merge(
|
|
10
|
+
'configuration' => conf = get_configuration,
|
|
11
|
+
'illuminance_range' => ILLUMINANCE_RANGES[ conf[0] ],
|
|
12
|
+
'integration_time' => 50 + conf[1] * 50,
|
|
13
|
+
'illuminance_raw' => get_illuminance,
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
module Tinkerforge
|
|
2
|
+
|
|
3
|
+
class BrickletColorV2
|
|
4
|
+
|
|
5
|
+
GAINS = [1, 4, 16, 60]
|
|
6
|
+
INTEGRATION_TIMES = [2.4, 24, 101, 154, 700]
|
|
7
|
+
|
|
8
|
+
# Switches off the Bricklet's white LED.
|
|
9
|
+
def blackout
|
|
10
|
+
set_light false
|
|
11
|
+
true
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
# Returns the device's state.
|
|
15
|
+
def state
|
|
16
|
+
super.merge(
|
|
17
|
+
'configuration' => config = get_configuration,
|
|
18
|
+
'gain' => GAINS[ config[0] ],
|
|
19
|
+
'integration_time' => INTEGRATION_TIMES[ config[1] ],
|
|
20
|
+
'color_rgbc' => color = get_color,
|
|
21
|
+
'illuminance_raw' => illum = get_illuminance,
|
|
22
|
+
'illuminance' => illum * 700.0 / GAINS[ config[0] ] / INTEGRATION_TIMES[ config[1] ],
|
|
23
|
+
'color_temperature' => get_color_temperature,
|
|
24
|
+
'saturated' => color[0,3].include?(65535),
|
|
25
|
+
'light' => get_light,
|
|
26
|
+
)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|