Class: L8::Smartlight

Inherits:
Object
  • Object
show all
Defined in:
lib/l8/smartlight.rb

Constant Summary collapse

CMD_L8_DISP_CHAR =
0x7f
CMD_L8_LED_SET =
0x43
CMD_L8_MATRIX_OFF =
0x45
CMD_L8_MATRIX_SET =
0x44
CMD_L8_POWEROFF =
0x9d
CMD_L8_SET_LOW_BRIGHTNESS =
0x9a
CMD_L8_SET_ORIENTATION =
0x80
CMD_L8_STATUSLEDS_ENABLE =
0x9e
CMD_L8_SUPERLED_SET =
0x4b

Instance Method Summary collapse

Constructor Details

#initialize(serial_port) ⇒ Smartlight

Returns a new instance of Smartlight.



15
16
17
18
19
# File 'lib/l8/smartlight.rb', line 15

def initialize(serial_port)
  @serial_port = Serial.new(serial_port)

  Kernel.at_exit { @serial_port.close }
end

Instance Method Details

#clear_matrixObject



21
22
23
# File 'lib/l8/smartlight.rb', line 21

def clear_matrix
  send_command [CMD_L8_MATRIX_OFF]
end

#disable_status_ledsObject



41
42
43
# File 'lib/l8/smartlight.rb', line 41

def disable_status_leds
  send_command [CMD_L8_STATUSLEDS_ENABLE, 0]
end

#display_character(character) ⇒ Object



33
34
35
# File 'lib/l8/smartlight.rb', line 33

def display_character(character)
  send_command [CMD_L8_DISP_CHAR, character.bytes[0], 0]
end

#enable_status_ledsObject



37
38
39
# File 'lib/l8/smartlight.rb', line 37

def enable_status_leds
  send_command [CMD_L8_STATUSLEDS_ENABLE, 1]
end

#power_offObject



53
54
55
# File 'lib/l8/smartlight.rb', line 53

def power_off
  send_command [CMD_L8_POWEROFF]
end

#set_brightness(level) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/l8/smartlight.rb', line 45

def set_brightness(level)
  brightness = 0
  brightness = 2 if level == :low
  brightness = 1 if level == :medium

  send_command [CMD_L8_SET_LOW_BRIGHTNESS, brightness]
end

#set_led(x, y, r, g, b) ⇒ Object



25
26
27
# File 'lib/l8/smartlight.rb', line 25

def set_led(x, y, r, g, b)
  send_command [CMD_L8_LED_SET, x, y, b, g, r, 0x00]
end

#set_matrix(pixels) ⇒ Object



57
58
59
60
61
# File 'lib/l8/smartlight.rb', line 57

def set_matrix(pixels)
  data = Util.pixels_to_two_byte_array(pixels)

  send_command [CMD_L8_MATRIX_SET] + data
end

#set_orientation(orientation) ⇒ Object



63
64
65
66
67
68
69
70
# File 'lib/l8/smartlight.rb', line 63

def set_orientation(orientation)
  value = 1
  value = 2 if orientation == :down
  value = 5 if orientation == :right
  value = 6 if orientation == :left

  send_command [CMD_L8_SET_ORIENTATION, value]
end

#set_superled(r, g, b) ⇒ Object



29
30
31
# File 'lib/l8/smartlight.rb', line 29

def set_superled(r,g,b)
  send_command [CMD_L8_SUPERLED_SET, b, g, r]
end