tinderfridge 0.1.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tinderfridge/device.rb +105 -0
- data/lib/tinderfridge/device_collection.rb +101 -4
- data/lib/tinderfridge/device_info.txt +2 -0
- data/lib/tinderfridge/devices/brick_hat/brick_hat.json +10 -0
- data/lib/tinderfridge/devices/brick_hat/brick_hat.rb +18 -0
- data/lib/tinderfridge/devices/brick_hat_zero/brick_hat_zero.json +10 -0
- data/lib/tinderfridge/devices/brick_hat_zero/brick_hat_zero.rb +14 -0
- data/lib/tinderfridge/devices/bricklet_air_quality/bricklet_air_quality.json +3 -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 +3 -0
- data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.rb +19 -0
- data/lib/tinderfridge/devices/bricklet_color_v2/bricklet_color_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_color_v2/bricklet_color_v2.rb +31 -0
- data/lib/tinderfridge/devices/bricklet_dmx/bricklet_dmx.json +3 -0
- data/lib/tinderfridge/devices/bricklet_dmx/bricklet_dmx.rb +18 -0
- data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.rb +31 -0
- data/lib/tinderfridge/devices/bricklet_imu_v3/bricklet_imu_v3.json +3 -0
- data/lib/tinderfridge/devices/bricklet_industrial_dual_relay/bricklet_industrial_dual_relay.json +3 -0
- data/lib/tinderfridge/devices/bricklet_industrial_dual_relay/bricklet_industrial_dual_relay.rb +20 -0
- data/lib/tinderfridge/devices/bricklet_isolator/bricklet_isolator.json +3 -0
- data/lib/tinderfridge/devices/bricklet_isolator/bricklet_isolator.rb +17 -0
- data/lib/tinderfridge/devices/bricklet_joystick_v2/bricklet_joystick_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_joystick_v2/bricklet_joystick_v2.rb +15 -0
- data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.json +3 -0
- data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.rb +31 -0
- data/lib/tinderfridge/devices/bricklet_led_strip_v2/bricklet_led_strip_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_led_strip_v2/bricklet_led_strip_v2.rb +55 -0
- data/lib/tinderfridge/devices/bricklet_motion_detector_v2/bricklet_motion_detector_v2.json +3 -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 +3 -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 +3 -0
- data/lib/tinderfridge/devices/bricklet_multi_touch_v2/bricklet_multi_touch_v2.rb +16 -0
- data/lib/tinderfridge/devices/bricklet_nfc/bricklet_nfc.json +3 -0
- data/lib/tinderfridge/devices/bricklet_nfc/bricklet_nfc.rb +16 -0
- data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.json +3 -0
- data/lib/tinderfridge/devices/bricklet_outdoor_weather/bricklet_outdoor_weather.rb +19 -0
- data/lib/tinderfridge/devices/bricklet_performance_dc/bricklet_performance_dc.json +3 -0
- data/lib/tinderfridge/devices/bricklet_remote_switch_v2/bricklet_remote_switch_v2.json +3 -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 +3 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_button/bricklet_rgb_led_button.rb +34 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_v2/bricklet_rgb_led_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_rgb_led_v2/bricklet_rgb_led_v2.rb +32 -0
- data/lib/tinderfridge/devices/bricklet_rotary_encoder_v2/bricklet_rotary_encoder_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_rotary_encoder_v2/bricklet_rotary_encoder_v2.rb +20 -0
- data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb +128 -0
- data/lib/tinderfridge/devices/bricklet_servo_v2/bricklet_servo_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_voltage_current_v2/bricklet_voltage_current_v2.json +3 -0
- data/lib/tinderfridge/devices/bricklet_voltage_current_v2/bricklet_voltage_current_v2.rb +18 -0
- data/lib/tinderfridge/ip_connection.rb +76 -21
- data/lib/tinderfridge/tinkerforge.rb +3 -0
- data/lib/tinderfridge/version.rb +1 -1
- metadata +59 -4
@@ -0,0 +1,18 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletDMX
|
4
|
+
|
5
|
+
# Returns the device's state.
|
6
|
+
def state
|
7
|
+
super.merge(
|
8
|
+
'dmx_mode' => get_dmx_mode,
|
9
|
+
'frame_duration' => get_frame_duration,
|
10
|
+
'frame_error_count' => get_frame_error_count,
|
11
|
+
'communication_led_config' => get_communication_led_config,
|
12
|
+
'error_led_config' => get_error_led_config,
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletGPSV2
|
4
|
+
|
5
|
+
# Returns latitude and longitude as reported by the GPS Bricklet.
|
6
|
+
#
|
7
|
+
# Nil when there is no fix (position not determined).
|
8
|
+
def coordinates
|
9
|
+
if get_status[0]
|
10
|
+
c = get_coordinates
|
11
|
+
[
|
12
|
+
c[0] / (c[1] == 'N' ? 1000000.0 : -1000000.0),
|
13
|
+
c[2] / (c[3] == 'E' ? 1000000.0 : -1000000.0)
|
14
|
+
]
|
15
|
+
else
|
16
|
+
nil
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns a Time object representing the time as reported by the GPS Bricklet.
|
21
|
+
def time
|
22
|
+
# FIXME: This will not work after 31-Dec-2099.
|
23
|
+
dt = get_date_time.map &:to_s
|
24
|
+
dt = dt[0].rjust(6,'0').unpack('a2a2a2').reverse + dt[1].rjust(9,'0').concat('000').unpack('a2a2a2a6')
|
25
|
+
dt[0].prepend '20'
|
26
|
+
Time.gm *dt.map(&:to_i)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
data/lib/tinderfridge/devices/bricklet_industrial_dual_relay/bricklet_industrial_dual_relay.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletIndustrialDualRelay
|
4
|
+
|
5
|
+
# Returns the device's state.
|
6
|
+
def state
|
7
|
+
super.merge(
|
8
|
+
'relays' => get_value.each_with_index.map do |v,i|
|
9
|
+
{
|
10
|
+
'value' => v,
|
11
|
+
'output' => v ? 'A' : 'B',
|
12
|
+
'monoflop' => ['time', 'time_remaining'].zip( get_monoflop(i)[1,2] ).to_h,
|
13
|
+
}
|
14
|
+
end
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletIsolator
|
4
|
+
|
5
|
+
# Returns the device's state.
|
6
|
+
def state
|
7
|
+
super.merge(
|
8
|
+
'statistics' => get_statistics,
|
9
|
+
'spitfp_baudrate_config' => get_spitfp_baudrate_config,
|
10
|
+
'spitfp_baudrate' => get_spitfp_baudrate,
|
11
|
+
'isolator_spitfp_error_count' => get_isolator_spitfp_error_count,
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletLCD128x64
|
4
|
+
|
5
|
+
# Returns the current setting for the backlight (0..100).
|
6
|
+
def backlight
|
7
|
+
get_display_configuration[1]
|
8
|
+
end
|
9
|
+
|
10
|
+
# Sets the brightness of the backlight (0..100).
|
11
|
+
def backlight=(brightness)
|
12
|
+
state = get_display_configuration
|
13
|
+
state[1] = brightness.to_i
|
14
|
+
set_display_configuration *state
|
15
|
+
end
|
16
|
+
|
17
|
+
# Switches off the backlight.
|
18
|
+
def blackout
|
19
|
+
self.backlight = 0
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
# Clears the display, including the GUI.
|
24
|
+
def clear
|
25
|
+
clear_display
|
26
|
+
remove_all_gui
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletLEDStripV2
|
4
|
+
|
5
|
+
# Switches off all connected LEDs. Use in case of misconfiguration or other trouble.
|
6
|
+
#
|
7
|
+
# Sends the connected LEDs 6144 zeros (2048 RGB values or 1536 RGBW values).
|
8
|
+
def blackout
|
9
|
+
a = Array.new(1024,0)
|
10
|
+
6.times { |n| set_led_values( n*1024, a ) }
|
11
|
+
true
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns the channels as defined by the channel mapping.
|
15
|
+
def channels
|
16
|
+
if ch = lookup_channel_mapping(get_channel_mapping)
|
17
|
+
ch[1].chars
|
18
|
+
else
|
19
|
+
ch
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the device's state.
|
24
|
+
def state
|
25
|
+
super.merge(
|
26
|
+
'chip_type' => get_chip_type,
|
27
|
+
'channel_mapping' => get_channel_mapping,
|
28
|
+
'channels' => channels,
|
29
|
+
'frame_duration' => get_frame_duration,
|
30
|
+
'clock_frequency' => get_clock_frequency,
|
31
|
+
'supply_voltage' => get_supply_voltage,
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def lookup_channel_mapping(selector=nil)
|
38
|
+
@@channel_mapping_table ||= self.class.constants.map do |c|
|
39
|
+
(c.to_s =~ /^CHANNEL_MAPPING_(\w{3,4})$/ ) ? [self.class.const_get(c), $1] : nil
|
40
|
+
end.compact.sort_by { |l| l[0] }
|
41
|
+
case selector
|
42
|
+
when NilClass
|
43
|
+
@@channel_mapping_table
|
44
|
+
when Integer
|
45
|
+
@@channel_mapping_table.select { |n,s| n == selector }.first
|
46
|
+
when String
|
47
|
+
@@channel_mapping_table.select { |n,s| s == selector }.first
|
48
|
+
else
|
49
|
+
raise ArgumentError, 'Unknown selector'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletMotionDetectorV2
|
4
|
+
|
5
|
+
# Switches off all three blue backlight LEDs.
|
6
|
+
def blackout
|
7
|
+
set_indicator(0, 0, 0)
|
8
|
+
true
|
9
|
+
end
|
10
|
+
|
11
|
+
# Returns the device's state.
|
12
|
+
def state
|
13
|
+
super.merge(
|
14
|
+
'motion_detected' => get_motion_detected == 1,
|
15
|
+
'sensitivity' => get_sensitivity,
|
16
|
+
'indicator' => get_indicator,
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
data/lib/tinderfridge/devices/bricklet_motorized_linear_poti/bricklet_motorized_linear_poti.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletMotorizedLinearPoti
|
4
|
+
|
5
|
+
# Returns the position of the potentiometer (an integer in the range 0..100).
|
6
|
+
def position
|
7
|
+
get_position
|
8
|
+
end
|
9
|
+
|
10
|
+
# Moves the potentiometer to the given position.
|
11
|
+
#
|
12
|
+
# If the potentiometer was locked before, it will be locked at the new position.
|
13
|
+
# The drive mode (speed) will be the same as the last time the position was set.
|
14
|
+
def position=(position)
|
15
|
+
set_motor_position( position, *get_motor_position[1,2] )
|
16
|
+
end
|
17
|
+
|
18
|
+
alias move_to position=
|
19
|
+
|
20
|
+
# Locks the position of the potentiometer. If a position is given, moves to that position first.
|
21
|
+
def lock(position=nil)
|
22
|
+
set_motor_position( position || get_position, get_motor_position[1], true )
|
23
|
+
end
|
24
|
+
|
25
|
+
alias hold lock
|
26
|
+
|
27
|
+
# Releases the potentiometer, so its position can be changed by hand. If a position is given, moves to that position first.
|
28
|
+
def release(position=nil)
|
29
|
+
set_motor_position( position || get_position, get_motor_position[1], false )
|
30
|
+
end
|
31
|
+
|
32
|
+
# Returns the device's state.
|
33
|
+
def state
|
34
|
+
super.merge(
|
35
|
+
'position' => get_position,
|
36
|
+
'motor_position' => get_motor_position,
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletMultiTouchV2
|
4
|
+
|
5
|
+
# Returns the device's state.
|
6
|
+
def state
|
7
|
+
super.merge(
|
8
|
+
'electrode_config' => get_electrode_config.map { |c| c ? '1' : '0' }.join,
|
9
|
+
'electrode_sensitivity' => get_electrode_sensitivity,
|
10
|
+
'touch_led_config' => get_touch_led_config,
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletNFC
|
4
|
+
|
5
|
+
# Returns the device's state.
|
6
|
+
def state
|
7
|
+
super.merge(
|
8
|
+
'mode' => get_mode,
|
9
|
+
'detection_led_config' => get_detection_led_config,
|
10
|
+
'maximum_timeout' => get_maximum_timeout,
|
11
|
+
)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletOutdoorWeather
|
4
|
+
|
5
|
+
# Returns the last measured data for all sensors.
|
6
|
+
#
|
7
|
+
# The result is a Hash, with sensor identifiers as the keys. Values per sensor are:
|
8
|
+
# - 0: Temperature (°C)
|
9
|
+
# - 1: Relative humidity (%RH)
|
10
|
+
# - 2: Last change (seconds)
|
11
|
+
def sensors
|
12
|
+
get_sensor_identifiers.map do |id|
|
13
|
+
[ id, get_sensor_data(id).each_with_index.map { |v,i| i == 0 ? v/10.0 : v } ]
|
14
|
+
end.to_h
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletRGBLEDButton
|
4
|
+
|
5
|
+
# Returns the button's current color as three values for red, green, and blue (integers in the range 0..255).
|
6
|
+
def rgb
|
7
|
+
get_color
|
8
|
+
end
|
9
|
+
|
10
|
+
# Sets the button's color using three values for red, green, and blue (integers in the range 0..255).
|
11
|
+
#
|
12
|
+
# Values can be supplied as an array or as three separate values.
|
13
|
+
def rgb=(*rgb)
|
14
|
+
set_color *rgb.flatten
|
15
|
+
end
|
16
|
+
|
17
|
+
# Switches off the button's LED.
|
18
|
+
def blackout
|
19
|
+
self.rgb = 0, 0, 0
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns the device's state.
|
24
|
+
def state
|
25
|
+
super.merge(
|
26
|
+
'color_rgb' => get_color,
|
27
|
+
'color_calibration' => get_color_calibration,
|
28
|
+
'pressed' => get_button_state == 0,
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|