rgb_led 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/Gemfile +3 -0
- data/License.md +21 -0
- data/Rakefile +6 -0
- data/Readme.md +64 -0
- data/Todo.md +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/rgb_led +12 -0
- data/lib/rgb_led.rb +3 -0
- data/lib/rgb_led/controller.rb +91 -0
- data/lib/rgb_led/rspec_formatter.rb +54 -0
- data/lib/rgb_led/version.rb +3 -0
- data/rgb_led.gemspec +27 -0
- data/src/rgb_led.ino +30 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 25b6c19e58af5b0db2a1058b5d674ffecfbb3e6f
|
4
|
+
data.tar.gz: a2268a464b44d42882c915e442d8bf9fa83304a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 75318c782f56471409ffe5f97a36b07e244a46531e75052097e891160c343ba9d05c8ab72b8d9327d837f81ede2c198f8d3c03705a756955d352c9425cc49aa8
|
7
|
+
data.tar.gz: df86999720e815813c5d2310f06fafcc452255a49057b48d7b00076242a75520fd7fe1e8c82396e1eee2e65f5107d9ef4742fc602f3a7f0cc3c22cdb3bb63575
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/License.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright © 2016 Ryan Scott Lewis <ryanscottlewis@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
*The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.*
|
14
|
+
|
15
|
+
**THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.**
|
data/Rakefile
ADDED
data/Readme.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# RGB LED
|
2
|
+
|
3
|
+
An RGB LED controller for AT microcontrollers with bonus RSpec formatter.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
|
7
|
+
### Bundler: `gem 'rgb_led'`
|
8
|
+
|
9
|
+
### RubyGems: `gem install rgb_led`
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
```rb
|
14
|
+
require 'rgb_led'
|
15
|
+
|
16
|
+
RGBLED::Controller.open('/dev/usbdevicepath') do |controller|
|
17
|
+
controller.red
|
18
|
+
sleep 1
|
19
|
+
controller.green
|
20
|
+
sleep 1
|
21
|
+
controller.blue
|
22
|
+
sleep 1
|
23
|
+
controller.update(1, 0.1, 0) # Yellow. Really depends on how bright each diode is within the LED
|
24
|
+
sleep 1
|
25
|
+
controller.off
|
26
|
+
end
|
27
|
+
```
|
28
|
+
|
29
|
+
## Without Block
|
30
|
+
|
31
|
+
```rb
|
32
|
+
require 'rgb_led'
|
33
|
+
|
34
|
+
controller = RGBLED::Controller.open('/dev/usbdevicepath')
|
35
|
+
# ...
|
36
|
+
controller.close
|
37
|
+
```
|
38
|
+
|
39
|
+
## RSpec Formatter
|
40
|
+
|
41
|
+
> Note: You can use multiple formatters with RSpec by passing multiple `--format` options.
|
42
|
+
|
43
|
+
**spec_helper.rb**
|
44
|
+
|
45
|
+
```rb
|
46
|
+
RSpec.configure do |config|
|
47
|
+
# ...
|
48
|
+
config.rgb_led_path = '/dev/usbdevicepath'
|
49
|
+
# ...
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
**.rspec**
|
54
|
+
|
55
|
+
```
|
56
|
+
--format RGBLED::RSpecFormatter
|
57
|
+
```
|
58
|
+
|
59
|
+
## Copyright
|
60
|
+
|
61
|
+
Copyright © 2016 Ryan Scott Lewis <ryanscottlewis@gmail.com>.
|
62
|
+
|
63
|
+
The MIT License (MIT) - See License.md for further details.
|
64
|
+
|
data/Todo.md
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
# TODO
|
2
|
+
|
3
|
+
* Sane defaults. Maybe a RGBLED.scan to find correct USB device? Or some kind of device reporter?
|
4
|
+
* i2c support
|
5
|
+
* ATTiny support? Much cheaper than ATMega. Must have 3 digital outputs with PWM support
|
6
|
+
* Custom colors for each state for RSpec formatter
|
7
|
+
* Other test suite formatters
|
8
|
+
* Use GPL? Look into other licenses
|
9
|
+
* Tests! Oh the irony..
|
10
|
+
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rgb_led"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/exe/rgb_led
ADDED
data/lib/rgb_led.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module RGBLED
|
2
|
+
class Controller
|
3
|
+
# Open the USB device for the RGB controller
|
4
|
+
#
|
5
|
+
# @param [String] path The path to the USB device
|
6
|
+
def self.open(path, &block)
|
7
|
+
new.open(path, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Open the USB device for the RGB controller
|
11
|
+
#
|
12
|
+
# @param [String] path The path to the USB device
|
13
|
+
def open(path, &block)
|
14
|
+
@io = File.open(path, 'r+') # TODO: r+ will create the file if it doesn't exist =(
|
15
|
+
|
16
|
+
@io.readbyte # Sync
|
17
|
+
|
18
|
+
if block_given?
|
19
|
+
yield(self)
|
20
|
+
|
21
|
+
close
|
22
|
+
end
|
23
|
+
|
24
|
+
self
|
25
|
+
end
|
26
|
+
|
27
|
+
# Close the device
|
28
|
+
def close
|
29
|
+
return if @io.nil?
|
30
|
+
|
31
|
+
@io.close
|
32
|
+
end
|
33
|
+
|
34
|
+
# Update the RGB LED color using floats between 0.0...1.0
|
35
|
+
#
|
36
|
+
# @param [#to_f] red
|
37
|
+
# @param [#to_f] green
|
38
|
+
# @param [#to_f] blue
|
39
|
+
def update(red, green, blue)
|
40
|
+
return false if @io.nil?
|
41
|
+
|
42
|
+
red = convert_float_to_byte(red)
|
43
|
+
green = convert_float_to_byte(green)
|
44
|
+
blue = convert_float_to_byte(blue)
|
45
|
+
|
46
|
+
@io.write(red)
|
47
|
+
@io.write(green)
|
48
|
+
@io.write(blue)
|
49
|
+
|
50
|
+
return true
|
51
|
+
end
|
52
|
+
|
53
|
+
# Turn off the LED entirely
|
54
|
+
def off
|
55
|
+
update(0, 0, 0)
|
56
|
+
end
|
57
|
+
|
58
|
+
# Set the RGB LED to the color red
|
59
|
+
#
|
60
|
+
# @param [#to_f] brightness
|
61
|
+
def red(brightness=1.0)
|
62
|
+
update(brightness, 0, 0)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Set the RGB LED to the color green
|
66
|
+
#
|
67
|
+
# @param [#to_f] brightness
|
68
|
+
def green(brightness=1.0)
|
69
|
+
update(0, brightness, 0)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Set the RGB LED to the color blue
|
73
|
+
#
|
74
|
+
# @param [#to_f] brightness
|
75
|
+
def blue(brightness=1.0)
|
76
|
+
update(0, 0, brightness)
|
77
|
+
end
|
78
|
+
|
79
|
+
protected
|
80
|
+
|
81
|
+
def convert_float_to_byte(value)
|
82
|
+
value = value.to_f
|
83
|
+
value = 0.0 if value < 0
|
84
|
+
value = 1.0 if value > 1
|
85
|
+
value = value * 255
|
86
|
+
|
87
|
+
value.to_i.chr
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
require 'rgb_led/controller'
|
3
|
+
|
4
|
+
RSpec.configuration.add_setting(:rgb_led_path, default: '/dev/cu.usbmodem1431')
|
5
|
+
|
6
|
+
module RGBLED
|
7
|
+
class RSpecFormatter
|
8
|
+
class << self
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
def path=(value)
|
12
|
+
value = value.to_s.strip
|
13
|
+
|
14
|
+
return nil if value.empty?
|
15
|
+
return nil unless File.exist?(value)
|
16
|
+
|
17
|
+
@path = value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(output)
|
22
|
+
@output = output || StringIO.new
|
23
|
+
@state = :green
|
24
|
+
end
|
25
|
+
|
26
|
+
def start(notification)
|
27
|
+
path = RSpec.configuration.rgb_led_path
|
28
|
+
@controller = RGBLED::Controller.open(path) unless path.nil?
|
29
|
+
|
30
|
+
@controller.off
|
31
|
+
end
|
32
|
+
|
33
|
+
def example_pending(notification)
|
34
|
+
@state = :yellow if @state == :green
|
35
|
+
end
|
36
|
+
|
37
|
+
def example_failed(notification)
|
38
|
+
@state = :red
|
39
|
+
end
|
40
|
+
|
41
|
+
def close(notification)
|
42
|
+
return if @controller.nil?
|
43
|
+
|
44
|
+
case @state
|
45
|
+
when :green then @controller.green
|
46
|
+
when :yellow then @controller.update(1, 0.1, 0)
|
47
|
+
when :red then @controller.red
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
RSpec::Core::Formatters.register(self, :start, :example_pending, :example_failed, :close)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
data/rgb_led.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rgb_led/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rgb_led"
|
8
|
+
spec.version = RGBLED::VERSION
|
9
|
+
spec.authors = ["Ryan Scott Lewis"]
|
10
|
+
spec.email = ["ryanscottlewis@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = "REG LED controller"
|
13
|
+
spec.description = "A controller for RGB LED using Arduino"
|
14
|
+
spec.homepage = "https://github.com/RyanScottLewis/rgb_led"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "pry", "0.10.4"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
data/src/rgb_led.ino
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
const int pinR = 3;
|
2
|
+
const int pinG = 5;
|
3
|
+
const int pinB = 6;
|
4
|
+
|
5
|
+
char inData[3];
|
6
|
+
int brightnessR = 0;
|
7
|
+
int brightnessG = 0;
|
8
|
+
int brightnessB = 0;
|
9
|
+
|
10
|
+
void setup() {
|
11
|
+
Serial.begin(9600);
|
12
|
+
Serial.flush();
|
13
|
+
while(!Serial);
|
14
|
+
Serial.print(0);
|
15
|
+
}
|
16
|
+
|
17
|
+
void loop() {
|
18
|
+
if (Serial.available() > 0) {
|
19
|
+
Serial.readBytes(inData, 3);
|
20
|
+
|
21
|
+
brightnessR = inData[0];
|
22
|
+
brightnessG = inData[1];
|
23
|
+
brightnessB = inData[2];
|
24
|
+
}
|
25
|
+
|
26
|
+
analogWrite(pinR, brightnessR);
|
27
|
+
analogWrite(pinG, brightnessG);
|
28
|
+
analogWrite(pinB, brightnessB);
|
29
|
+
}
|
30
|
+
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rgb_led
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Scott Lewis
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.10.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.10.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: A controller for RGB LED using Arduino
|
70
|
+
email:
|
71
|
+
- ryanscottlewis@gmail.com
|
72
|
+
executables:
|
73
|
+
- rgb_led
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- ".gitignore"
|
78
|
+
- Gemfile
|
79
|
+
- License.md
|
80
|
+
- Rakefile
|
81
|
+
- Readme.md
|
82
|
+
- Todo.md
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- exe/rgb_led
|
86
|
+
- lib/rgb_led.rb
|
87
|
+
- lib/rgb_led/controller.rb
|
88
|
+
- lib/rgb_led/rspec_formatter.rb
|
89
|
+
- lib/rgb_led/version.rb
|
90
|
+
- rgb_led.gemspec
|
91
|
+
- src/rgb_led.ino
|
92
|
+
homepage: https://github.com/RyanScottLewis/rgb_led
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.5.1
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: REG LED controller
|
116
|
+
test_files: []
|