Class: RGBLED::Controller
- Inherits:
-
Object
- Object
- RGBLED::Controller
- Defined in:
- lib/rgb_led/controller.rb
Class Method Summary collapse
-
.open(path, &block) ⇒ Object
Open the USB device for the RGB controller.
Instance Method Summary collapse
-
#blue(brightness = 1.0) ⇒ Object
Set the RGB LED to the color blue.
-
#close ⇒ Object
Close the device.
-
#green(brightness = 1.0) ⇒ Object
Set the RGB LED to the color green.
-
#off ⇒ Object
Turn off the LED entirely.
-
#open(path, &block) ⇒ Object
Open the USB device for the RGB controller.
-
#red(brightness = 1.0) ⇒ Object
Set the RGB LED to the color red.
-
#update(red, green, blue) ⇒ Object
Update the RGB LED color using floats between 0.0…1.0.
Class Method Details
.open(path, &block) ⇒ Object
Open the USB device for the RGB controller
6 7 8 |
# File 'lib/rgb_led/controller.rb', line 6 def self.open(path, &block) new.open(path, &block) end |
Instance Method Details
#blue(brightness = 1.0) ⇒ Object
Set the RGB LED to the color blue
75 76 77 |
# File 'lib/rgb_led/controller.rb', line 75 def blue(brightness=1.0) update(0, 0, brightness) end |
#close ⇒ Object
Close the device
28 29 30 31 32 |
# File 'lib/rgb_led/controller.rb', line 28 def close return if @io.nil? @io.close end |
#green(brightness = 1.0) ⇒ Object
Set the RGB LED to the color green
68 69 70 |
# File 'lib/rgb_led/controller.rb', line 68 def green(brightness=1.0) update(0, brightness, 0) end |
#off ⇒ Object
Turn off the LED entirely
54 55 56 |
# File 'lib/rgb_led/controller.rb', line 54 def off update(0, 0, 0) end |
#open(path, &block) ⇒ Object
Open the USB device for the RGB controller
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rgb_led/controller.rb', line 13 def open(path, &block) @io = File.open(path, 'r+') # TODO: r+ will create the file if it doesn't exist =( @io.readbyte # Sync if block_given? yield(self) close end self end |
#red(brightness = 1.0) ⇒ Object
Set the RGB LED to the color red
61 62 63 |
# File 'lib/rgb_led/controller.rb', line 61 def red(brightness=1.0) update(brightness, 0, 0) end |
#update(red, green, blue) ⇒ Object
Update the RGB LED color using floats between 0.0…1.0
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rgb_led/controller.rb', line 39 def update(red, green, blue) return false if @io.nil? red = convert_float_to_byte(red) green = convert_float_to_byte(green) blue = convert_float_to_byte(blue) @io.write(red) @io.write(green) @io.write(blue) return true end |