tinderfridge 0.7.0 → 0.10.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 +44 -3
- data/lib/tinderfridge/device_collection.rb +3 -1
- data/lib/tinderfridge/devices/brick_master/brick_master.json +11 -0
- data/lib/tinderfridge/devices/brick_master/brick_master.rb +11 -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 +2 -1
- data/lib/tinderfridge/devices/bricklet_air_quality/bricklet_air_quality.rb +15 -0
- data/lib/tinderfridge/devices/bricklet_ambient_light_v3/bricklet_ambient_light_v3.json +2 -1
- data/lib/tinderfridge/devices/bricklet_analog_in_v3/bricklet_analog_in_v3.json +2 -1
- data/lib/tinderfridge/devices/bricklet_analog_out_v3/bricklet_analog_out_v3.json +2 -1
- data/lib/tinderfridge/devices/bricklet_barometer_v2/bricklet_barometer_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_co2_v2/bricklet_co2_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_co2_v2/bricklet_co2_v2.rb +19 -0
- data/lib/tinderfridge/devices/bricklet_color_v2/bricklet_color_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_compass/bricklet_compass.json +2 -1
- 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 +2 -1
- data/lib/tinderfridge/devices/bricklet_dmx/bricklet_dmx.json +2 -1
- 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 +2 -1
- data/lib/tinderfridge/devices/bricklet_energy_monitor/bricklet_energy_monitor.json +2 -1
- data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_gps_v2/bricklet_gps_v2.rb +21 -1
- data/lib/tinderfridge/devices/bricklet_hall_effect_v2/bricklet_hall_effect_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_hall_effect_v2/bricklet_hall_effect_v2.rb +16 -0
- data/lib/tinderfridge/devices/bricklet_humidity_v2/bricklet_humidity_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_imu_v3/bricklet_imu_v3.json +2 -1
- data/lib/tinderfridge/devices/bricklet_industrial_analog_out_v2/bricklet_industrial_analog_out_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 +2 -1
- 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 +2 -1
- data/lib/tinderfridge/devices/bricklet_joystick_v2/bricklet_joystick_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_laser_range_finder_v2/bricklet_laser_range_finder_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.json +2 -1
- data/lib/tinderfridge/devices/bricklet_lcd_128x64/bricklet_lcd_128x64.rb +46 -0
- data/lib/tinderfridge/devices/bricklet_led_strip_v2/bricklet_led_strip_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_linear_poti_v2/bricklet_linear_poti_v2.json +2 -1
- 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 +2 -1
- data/lib/tinderfridge/devices/bricklet_motorized_linear_poti/bricklet_motorized_linear_poti.json +2 -1
- data/lib/tinderfridge/devices/bricklet_multi_touch_v2/bricklet_multi_touch_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_nfc/bricklet_nfc.json +2 -1
- data/lib/tinderfridge/devices/bricklet_oled_128x64_v2/bricklet_oled_128x64_v2.rb +79 -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 +2 -1
- data/lib/tinderfridge/devices/bricklet_particulate_matter/bricklet_particulate_matter.json +11 -0
- data/lib/tinderfridge/devices/bricklet_piezo_speaker_v2/bricklet_piezo_speaker_v2.json +2 -1
- 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 +2 -1
- data/lib/tinderfridge/devices/bricklet_remote_switch_v2/bricklet_remote_switch_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_rgb_led_button/bricklet_rgb_led_button.json +2 -1
- data/lib/tinderfridge/devices/bricklet_rgb_led_v2/bricklet_rgb_led_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_rotary_encoder_v2/bricklet_rotary_encoder_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_rotary_poti_v2/bricklet_rotary_poti_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb +25 -1
- 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 +2 -1
- data/lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.rb +20 -0
- data/lib/tinderfridge/devices/bricklet_temperature_ir_v2/bricklet_temperature_ir_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_temperature_ir_v2/bricklet_temperature_ir_v2.rb +14 -0
- data/lib/tinderfridge/devices/bricklet_temperature_v2/bricklet_temperature_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_thermal_imaging/bricklet_thermal_imaging.json +2 -1
- data/lib/tinderfridge/devices/bricklet_thermocouple_v2/bricklet_thermocouple_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_uv_light_v2/bricklet_uv_light_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_voltage_current_v2/bricklet_voltage_current_v2.json +2 -1
- data/lib/tinderfridge/devices/bricklet_xmc1400_breakout/bricklet_xmc1400_breakout.json +2 -1
- data/lib/tinderfridge/ip_connection.rb +19 -11
- data/lib/tinderfridge/shared/display_ibm437_encoding.rb +41 -0
- data/lib/tinderfridge/tinkerforge.rb +24 -9
- data/lib/tinderfridge/version.rb +1 -1
- metadata +27 -5
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'tinderfridge/shared/display_ibm437_encoding'
|
2
|
+
|
3
|
+
module Tinkerforge
|
4
|
+
|
5
|
+
class BrickletOLED128x64V2
|
6
|
+
|
7
|
+
include Tinkerforge::Shared::IBM437_encoding
|
8
|
+
|
9
|
+
# Encodes a string in the IBM437 character set used by some displays.
|
10
|
+
#
|
11
|
+
# Characters that can not be encoded are replaced with '?'.
|
12
|
+
#
|
13
|
+
# See:
|
14
|
+
# - https://en.wikipedia.org/wiki/Code_page_437
|
15
|
+
def encode(string)
|
16
|
+
ibm437_encode(string)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Turns the display all black.
|
20
|
+
def blackout
|
21
|
+
c = get_display_configuration
|
22
|
+
|
23
|
+
if c[1] # inverted
|
24
|
+
set_display_configuration c[0], false, c[2]
|
25
|
+
end
|
26
|
+
|
27
|
+
clear_display
|
28
|
+
|
29
|
+
if ! c[2] # buffered
|
30
|
+
draw_buffered_frame(true)
|
31
|
+
end
|
32
|
+
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
# Returns true if automatic draw is set to false.
|
37
|
+
def buffered?
|
38
|
+
! get_display_configuration[2]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Draws the currently buffered frame.
|
42
|
+
def redraw(force_complete_redraw=false)
|
43
|
+
draw_buffered_frame force_complete_redraw
|
44
|
+
end
|
45
|
+
|
46
|
+
alias flush redraw
|
47
|
+
|
48
|
+
# Returns the device's state.
|
49
|
+
def state
|
50
|
+
super.merge(
|
51
|
+
'display_configuration' => get_display_configuration,
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Clears the display and prints upto 8 lines of text.
|
56
|
+
#
|
57
|
+
# Text may contain newline characters to separate lines.
|
58
|
+
# Lines longer than 21 characters will be wrapped.
|
59
|
+
#
|
60
|
+
# Text is automatically encoded in the IBM437 character set.
|
61
|
+
# @example
|
62
|
+
# my_oled.put_screen "Hello, World!\n\nRuby #{RUBY_VERSION}"
|
63
|
+
def put_screen(text='', test: false)
|
64
|
+
lines = text.split("\n")
|
65
|
+
lines = lines.map { |s| s.empty? ? '' : s.scan(/.{1,21}/) }.flatten
|
66
|
+
lines = lines[0,8].map { |l| encode l }
|
67
|
+
|
68
|
+
return lines if test
|
69
|
+
|
70
|
+
clear_display
|
71
|
+
lines.each_with_index do |s,l|
|
72
|
+
write_line l, 0, s
|
73
|
+
end
|
74
|
+
nil
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -6,5 +6,6 @@
|
|
6
6
|
],
|
7
7
|
"weight": 3,
|
8
8
|
"documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/RealTime_Clock_V2.html",
|
9
|
-
"versions_identifier": "bricklets:real_time_clock_v2"
|
9
|
+
"versions_identifier": "bricklets:real_time_clock_v2",
|
10
|
+
"released": "2018-06-07"
|
10
11
|
}
|
@@ -6,5 +6,6 @@
|
|
6
6
|
],
|
7
7
|
"weight": 6,
|
8
8
|
"documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Rotary_Encoder_V2.html",
|
9
|
-
"versions_identifier": "bricklets:rotary_encoder_v2"
|
9
|
+
"versions_identifier": "bricklets:rotary_encoder_v2",
|
10
|
+
"released": "2018-02-26"
|
10
11
|
}
|
data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.json
CHANGED
@@ -6,5 +6,6 @@
|
|
6
6
|
],
|
7
7
|
"weight": 11,
|
8
8
|
"documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Segment_Display_4x7_V2.html",
|
9
|
-
"versions_identifier": "bricklets:segment_display_4x7_v2"
|
9
|
+
"versions_identifier": "bricklets:segment_display_4x7_v2",
|
10
|
+
"released": "2019-05-20"
|
10
11
|
}
|
data/lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb
CHANGED
@@ -12,7 +12,7 @@ module Tinkerforge
|
|
12
12
|
|
13
13
|
# Returns the state of all 35 segments.
|
14
14
|
def segments
|
15
|
-
|
15
|
+
get_segments.flatten
|
16
16
|
end
|
17
17
|
|
18
18
|
# Sets the state of all 35 segments.
|
@@ -120,9 +120,33 @@ module Tinkerforge
|
|
120
120
|
'[' => '1001110',
|
121
121
|
']' => '1111000',
|
122
122
|
|
123
|
+
'°' => '1100011',
|
124
|
+
|
123
125
|
}
|
124
126
|
end
|
125
127
|
|
128
|
+
# Displays an 8-segment bar graph for 1 or 2 values in the range 0..1.
|
129
|
+
#
|
130
|
+
# @example
|
131
|
+
# my_bricklet.bar_graph 0.5
|
132
|
+
# my_bricklet.bar_graph 0.5, 0.8
|
133
|
+
def bar_graph(value1, value2=value1)
|
134
|
+
value1, value2 = [value1, value2].map { |v| (v.to_f.clamp(0,1) * 8).round }
|
135
|
+
|
136
|
+
frame = [false] * 35
|
137
|
+
|
138
|
+
[ 5, 1, 13, 9, 21, 17, 29, 25 ].first(value1).each do |n|
|
139
|
+
frame[n] = true
|
140
|
+
end
|
141
|
+
|
142
|
+
[ 4, 2, 12, 10, 20, 18, 28, 26 ].first(value2).each do |n|
|
143
|
+
frame[n] = true
|
144
|
+
end
|
145
|
+
|
146
|
+
self.segments = frame
|
147
|
+
[value1, value2]
|
148
|
+
end
|
149
|
+
|
126
150
|
end
|
127
151
|
|
128
152
|
end
|
data/lib/tinderfridge/devices/bricklet_sound_pressure_level/bricklet_sound_pressure_level.json
CHANGED
@@ -6,5 +6,6 @@
|
|
6
6
|
],
|
7
7
|
"weight": 2.6,
|
8
8
|
"documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Sound_Pressure_Level.html",
|
9
|
-
"versions_identifier": "bricklets:sound_pressure_level"
|
9
|
+
"versions_identifier": "bricklets:sound_pressure_level",
|
10
|
+
"released": "2018-06-07"
|
10
11
|
}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
class BrickletSoundPressureLevel
|
4
|
+
|
5
|
+
WEIGHTINGS = [ 'dB(A)', 'dB(B)','dB(C)', 'dB(D)', 'dB(Z)', 'ITU-R 468']
|
6
|
+
|
7
|
+
# Returns the device's state.
|
8
|
+
def state
|
9
|
+
super.merge(
|
10
|
+
'configuration' => conf = get_configuration,
|
11
|
+
'weighting' => WEIGHTINGS[ conf[1] ],
|
12
|
+
'sampling_rate' => 2 ** (3 - conf[0]) * 10,
|
13
|
+
'bin_size' => 2 ** (3 - conf[0]) * 40,
|
14
|
+
'sound_pressure' => get_decibel,
|
15
|
+
)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -6,5 +6,6 @@
|
|
6
6
|
],
|
7
7
|
"weight": 3,
|
8
8
|
"documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Temperature_IR_V2.html",
|
9
|
-
"versions_identifier": "bricklets:temperature_ir_v2"
|
9
|
+
"versions_identifier": "bricklets:temperature_ir_v2",
|
10
|
+
"released": "2018-02-26"
|
10
11
|
}
|
@@ -6,5 +6,6 @@
|
|
6
6
|
],
|
7
7
|
"weight": 10,
|
8
8
|
"documentation_en_url": "https://www.tinkerforge.com/en/doc/Hardware/Bricklets/Voltage_Current_V2.html",
|
9
|
-
"versions_identifier": "bricklets:voltage_current_v2"
|
9
|
+
"versions_identifier": "bricklets:voltage_current_v2",
|
10
|
+
"released": "2018-06-07"
|
10
11
|
}
|
@@ -10,6 +10,9 @@ module Tinkerforge
|
|
10
10
|
# Returns the port for the IP Connection.
|
11
11
|
attr_reader :port
|
12
12
|
|
13
|
+
# Returns the network socket used by the IP Connection.
|
14
|
+
attr_reader :socket
|
15
|
+
|
13
16
|
# Returns a programmer-friendly representation of the object.
|
14
17
|
def inspect
|
15
18
|
"%s (%s:%s)" % [self.class, host, port]
|
@@ -117,17 +120,22 @@ module Tinkerforge
|
|
117
120
|
|
118
121
|
end
|
119
122
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
123
|
+
|
124
|
+
class << self
|
125
|
+
|
126
|
+
# Creates an IP Connection object connected to the given host and port.
|
127
|
+
#
|
128
|
+
# If no host and port are specified, uses the TINKERFORGE_HOST and TINKERFORGE_PORT environment variables, when defined.
|
129
|
+
# Otherwise defaults to 'localhost' and port 4223.
|
130
|
+
def connect(host=nil, port=nil)
|
131
|
+
ipcon = IPConnection.new
|
132
|
+
ipcon.connect(
|
133
|
+
( host || ENV['TINKERFORGE_HOST'] || 'localhost' ),
|
134
|
+
( port || ENV['TINKERFORGE_PORT'] || 4223 )
|
135
|
+
)
|
136
|
+
ipcon
|
137
|
+
end
|
138
|
+
|
131
139
|
end
|
132
140
|
|
133
141
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Tinkerforge
|
2
|
+
|
3
|
+
module Shared
|
4
|
+
|
5
|
+
module IBM437_encoding
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
# Encodes a string in the IBM437 character set used by some displays.
|
10
|
+
#
|
11
|
+
# Characters that can not be encoded are replaced with '?'.
|
12
|
+
#
|
13
|
+
# See:
|
14
|
+
# - https://en.wikipedia.org/wiki/Code_page_437
|
15
|
+
def ibm437_encode(string)
|
16
|
+
string.encode('IBM437', fallback: ibm437_encoding_fallback_table)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Ruby's IBM437 encoding does not include codepoints 0..31 and 127.
|
20
|
+
# This fallback table defines those, minus 0,
|
21
|
+
# and defines '?' as default for undefined characters.
|
22
|
+
def ibm437_encoding_fallback_table
|
23
|
+
@@ibm437_encoding_fallback_table ||= Hash.new('?').merge(
|
24
|
+
{
|
25
|
+
'☺'=> "\x01", '☻'=> "\x02", '♥'=> "\x03", '♦'=> "\x04",
|
26
|
+
'♣'=> "\x05", '♠'=> "\x06", '•'=> "\x07", '◘'=> "\x08",
|
27
|
+
'○'=> "\x09", '◙'=> "\x0a", '♂'=> "\x0b", '♀'=> "\x0c",
|
28
|
+
'♪'=> "\x0d", '♫'=> "\x0e", '☼'=> "\x0f", '►'=> "\x10",
|
29
|
+
'◄'=> "\x11", '↕'=> "\x12", '‼'=> "\x13", '¶'=> "\x14",
|
30
|
+
'§'=> "\x15", '▬'=> "\x16", '↨'=> "\x17", '↑'=> "\x18",
|
31
|
+
'↓'=> "\x19", '→'=> "\x1a", '←'=> "\x1b", '∟'=> "\x1c",
|
32
|
+
'↔'=> "\x1d", '▲'=> "\x1e", '▼'=> "\x1f", '⌂'=> "\x7f"
|
33
|
+
}
|
34
|
+
)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -5,16 +5,31 @@ module Tinkerforge
|
|
5
5
|
ALL_VERSIONS_URL = 'https://download.tinkerforge.com/all_versions.txt'
|
6
6
|
LATEST_VERSIONS_URL = 'https://download.tinkerforge.com/latest_versions.txt'
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# Returns the directory where Tinkerforge bindings appear to be installed.
|
11
|
+
def lib_dir
|
12
|
+
File.dirname File.dirname Device.instance_method('uid').source_location.first
|
13
|
+
end
|
14
|
+
|
15
|
+
# Attempts to load all files that are part of Tinkerforge. Returns a list of files loaded.
|
16
|
+
def require_everything
|
17
|
+
Dir.glob(File.join lib_dir, 'tinkerforge', '*.rb').map do |file|
|
18
|
+
require(file) ? file : nil
|
19
|
+
end.compact
|
20
|
+
end
|
21
|
+
|
22
|
+
# Discovers local devices.
|
23
|
+
#
|
24
|
+
# Connects to 'localhost', and returns devices discovered there. If no port is specified, defaults to port 4223.
|
25
|
+
# @example
|
26
|
+
# Tinkerforge.local.ls
|
27
|
+
# @example Mac only
|
28
|
+
# Tinkerforge.local.doc
|
29
|
+
def local(port=4223)
|
30
|
+
connect('localhost', port).discover(0.25)
|
31
|
+
end
|
12
32
|
|
13
|
-
# Attempts to load all files that are part of Tinkerforge. Returns a list of files loaded.
|
14
|
-
def self.require_everything
|
15
|
-
Dir.glob(File.join lib_dir, 'tinkerforge', '*.rb').map do |file|
|
16
|
-
require(file) ? file : nil
|
17
|
-
end.compact
|
18
33
|
end
|
19
34
|
|
20
35
|
end
|