class Tinkerforge::BrickletSegmentDisplay4x7V2

Public Instance Methods

bar_graph(value1, value2=value1) click to toggle source

Displays an 8-segment bar graph for 1 or 2 values in the range 0..1.

@example

my_bricklet.bar_graph 0.5
my_bricklet.bar_graph 0.5, 0.8
# File lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb, line 131
def bar_graph(value1, value2=value1)
  value1, value2 = [value1, value2].map { |v| (v.to_f.clamp(0,1) * 8).round }

  frame = [false] * 35

  [ 5, 1, 13,  9, 21, 17, 29, 25 ].first(value1).each do |n|
    frame[n] = true
  end

  [ 4, 2, 12, 10, 20, 18, 28, 26 ].first(value2).each do |n|
    frame[n] = true
  end

  self.segments = frame
  [value1, value2]
end
blackout()
Alias for: clear
clear() click to toggle source

Clears the display.

# File lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb, line 6
def clear
  set_segments [false]*8, [false]*8, [false]*8, [false]*8, [false]*2, false
  true
end
Also aliased as: blackout
glyphs() click to toggle source

Returns the definition of glyphs for Unicode chracters.

# File lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb, line 65
def glyphs
  @@glyphs ||= {

    '0' => '1111110',
    '1' => '0110000',
    '2' => '1101101',
    '3' => '1111001',
    '4' => '0110011',
    '5' => '1011011',
    '6' => '1011111',
    '7' => '1110000',
    '8' => '1111111',
    '9' => '1111011',

    'A' => '1110111',
    'b' => '0011111',
    'c' => '0001101',
    'C' => '1001110',
    'd' => '0111101',
    'E' => '1001111',
    'F' => '1000111',
    'G' => '1011110',
    'H' => '0110111',
    'h' => '0010111',
    'I' => '0110000',
    'i' => '0010000',
    'J' => '0111000',
    'L' => '0001110',
    'l' => '0001100',
    'n' => '0010101',
    'O' => '1111110',
    'o' => '0011101',
    'P' => '1100111',
    'q' => '1110011',
    'r' => '0000101',
    'S' => '1011011',
    't' => '0001111',
    'U' => '0111110',
    'u' => '0011100',
    'V' => '0111110',
    'v' => '0011100',
    'y' => '0110011',

    'ö' => '1011101',
    'ü' => '1011100',

    ' ' => '0000000',

    '_' => '0001000',
    '-' => '0000001',
    '=' => '0001001',

    '(' => '1001110',
    ')' => '1111000',

    '[' => '1001110',
    ']' => '1111000',

  }
end
print(text='') click to toggle source

Displays a string.

segments() click to toggle source

Returns the state of all 35 segments.

# File lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb, line 14
def segments
  get_segments.flatten
end
segments=(*segments) click to toggle source

Sets the state of all 35 segments.

# File lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb, line 19
def segments=(*segments)
  segs = segments.flatten
  set_segments segs[0,8], segs[8,8], segs[16,8], segs[24,8], segs[32,2], segs[34]
end
segments_string() click to toggle source

Returns the state of all 35 segments as a string of 1s and 0s.

# File lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb, line 25
def segments_string
  segments.map { |s| s ? '1' : '0' }.join
end
segments_string=(segments) click to toggle source

Sets the state of all 35 segments using a string of 1s and 0s.

For readability, the string may include spaces and underscores, which will be ignored. @example

my_bricklet.segments_string = '10000110 11000110 11000110 00000110 00 0'
# File lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb, line 34
def segments_string=(segments)
  self.segments = segments.gsub(/[ _]/, '').ljust(35, '0').chars.map { |s| s == '1' }
end
state() click to toggle source

Returns the device's state.

Calls superclass method
# File lib/tinderfridge/devices/bricklet_segment_display_4x7_v2/bricklet_segment_display_4x7_v2.rb, line 39
def state
  super.merge( 'brightness' => get_brightness )
end