Class: AmbientOrb
- Inherits:
-
Object
- Object
- AmbientOrb
- Defined in:
- lib/ambient-orb.rb,
lib/ambient-orb/version.rb
Constant Summary collapse
- SERIAL_PORT_BAUD_RATE =
These are fixed characteristics of the orb.
19200- SERIAL_PORT_DATA_BITS =
8- SERIAL_PORT_STOP_BITS =
1- SERIAL_PORT_PARITY =
SerialPort::NONE
- COLOR_RED =
Colors are specified as an integer from 0 to 36, inclusive. Common colors are assigned constants for convenience.
0- COLOR_ORANGE =
3- COLOR_YELLOW =
6- COLOR_GREEN =
12- COLOR_BLUE =
24- COLOR_PURPLE =
27- ANIMATION_NONE =
Animation is specified as an integer from 0 to 9, inclusive.
0- ANIMATION_VERY_SLOW =
1- ANIMATION_SLOW =
2- ANIMATION_MEDIUM_SLOW =
3- ANIMATION_MEDIUM =
4- ANIMATION_MEDIUM_FAST =
5- ANIMATION_FAST =
6- ANIMATION_VERY_FAST =
7- ANIMATION_CRESCENDO =
8- ANIMATION_HEARTBEAT =
9- VERSION =
'0.0.2'
Instance Method Summary collapse
- #chip ⇒ Object
- #device ⇒ Object
-
#initialize(options = {}) ⇒ AmbientOrb
constructor
A new instance of AmbientOrb.
- #logger ⇒ Object
- #update(color, animation) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AmbientOrb
Returns a new instance of AmbientOrb.
34 35 36 |
# File 'lib/ambient-orb.rb', line 34 def initialize( = {}) @opts = end |
Instance Method Details
#chip ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ambient-orb.rb', line 52 def chip @chip ||= begin chip = @opts[:chip] || autodetect_chip unless chip raise ArgumentError, 'invalid chip' end logger.info("using chip #{chip}") chip end end |
#device ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ambient-orb.rb', line 38 def device @device ||= begin dev = @opts[:device] || autodetect_device unless dev && File.exist?(dev) && File.stat(dev).chardev? raise ArgumentError, 'invalid device' end logger.info("selected device #{dev}") dev end end |
#logger ⇒ Object
66 67 68 69 70 |
# File 'lib/ambient-orb.rb', line 66 def logger @logger ||= begin @opts[:logger] || Logger.new(nil) end end |
#update(color, animation) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ambient-orb.rb', line 72 def update(color, animation) if (color < 0 || color > 36) raise ArgumentError, 'color must be between 0 and 36' end if (animation < 0 || animation > 9) raise ArgumentError, 'animation must be between 0 and 9' end logger.info("updating with color=#{color}, animation=#{animation}") color_ord = (color + (37 * animation)) / 94 + 32 animation_ord = (color + (37 * animation)) % 94 + 32 send("~A#{color_ord.chr}#{animation_ord.chr}") end |