douban.fm.arduino 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in douban.fm.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 ehonlia
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,44 @@
1
+ # Douban.fm.arduino
2
+
3
+ Swtich Douban.fm channel via Arduino.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'douban.fm.arduino'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install douban.fm.arduino
18
+
19
+ ## Usage
20
+
21
+ <pre>
22
+ $ douban.fm.arduino -h
23
+
24
+ Usage: douban.fm [OPTIONS]
25
+ -d, --device device the serial device where to read arduino serial output
26
+ -r, --remote remote remote host where douban.fm is running, in format of <IP>:<Port>
27
+ -v, --version show current version
28
+ -h, --help show this message
29
+ </pre>
30
+
31
+ Now because the limitation of my breadboard (because of size),
32
+ there are only three channels available to switch, which are
33
+ private, 咖啡, and 民谣.
34
+
35
+ Well, with only software you might not be able to do anything. But I'm really sorry that it is too late today.
36
+ I will try to draw the circuit later.
37
+
38
+ ## Contributing
39
+
40
+ 1. Fork it
41
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
42
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
43
+ 4. Push to the branch (`git push origin my-new-feature`)
44
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'douban.fm.arduino'
4
+ require 'optparse'
5
+ require 'ostruct'
6
+ require 'serialport'
7
+ require 'net/http'
8
+
9
+ class DoubanFMArduinoCLI
10
+ def parse
11
+ options = OpenStruct.new
12
+ options.verbose = false
13
+
14
+ opts = OptionParser.new do |opts|
15
+ opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} [OPTIONS]"
16
+
17
+ opts.on('-d', '--device device',
18
+ 'the serial device where to read arduino serial output',
19
+ 'usually it is /dev/tty.usbserial-*') do |device|
20
+ options.device = device
21
+ end
22
+
23
+ opts.on('-r', '--remote remote',
24
+ 'remote host where douban.fm is running, in format of <IP>:<Port>',
25
+ 'by deafult it is localhost:3000') do |remote|
26
+ unless remote.split(':').length == 2
27
+ puts opts
28
+ exit
29
+ end
30
+
31
+ options.remote = remote
32
+ end
33
+
34
+ opts.on('-v', '--version', 'show current version') do
35
+ puts DoubanFM::VERSION
36
+ exit
37
+ end
38
+
39
+ opts.on_tail('-h', '--help', 'show this message') do
40
+ puts opts
41
+ exit
42
+ end
43
+ end
44
+
45
+ opts.parse!
46
+
47
+ options
48
+ end
49
+
50
+ def main
51
+ options = parse
52
+
53
+ if options.device.nil?
54
+ puts 'device must be specified'
55
+ exit
56
+ end
57
+
58
+ if options.remote.nil?
59
+ options.remote = 'localhost:3000'
60
+ end
61
+
62
+ port_str = "#{options.device}"
63
+ baud_rate = 9600
64
+ data_bits = 8
65
+ stop_bits = 1
66
+ parity = SerialPort::NONE
67
+
68
+
69
+ sp = SerialPort.new(port_str, baud_rate, data_bits, stop_bits, parity)
70
+
71
+ %w[INT TERM].each do |signal|
72
+ trap(signal) do
73
+ sp.close
74
+ puts 'stopped'
75
+ exit
76
+ end
77
+ end
78
+
79
+ puts 'started'
80
+
81
+ while true do
82
+ while (channel_id = sp.gets) do
83
+ uri = URI("http://#{options.remote}/channel/#{channel_id}")
84
+ Net::HTTP.get(uri)
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ DoubanFMArduinoCLI.new.main
@@ -0,0 +1,20 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'douban.fm.arduino/version'
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "douban.fm.arduino"
7
+ gem.version = DoubanFMArduino::VERSION
8
+ gem.authors = ["honnix"]
9
+ gem.email = ["hxliang1982@gmail.com"]
10
+ gem.description = %q{douban.fm.arduino}
11
+ gem.summary = %q{douban.fm.arduino}
12
+ gem.homepage = "https://github.com/honnix/douban.fm.arduino"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_dependency 'serialport', '1.1.0'
20
+ end
@@ -0,0 +1,36 @@
1
+ int LENGTH = 3;
2
+
3
+ int ledPins[] = {12, 11, 10};
4
+ int buttonPins[] = {5, 4, 3};
5
+ int channelIds[] = {0, 32, 8};
6
+
7
+ void setup() {
8
+ Serial.begin(9600);
9
+ for (int i = 0; i < LENGTH; ++i) {
10
+ pinMode(ledPins[i], OUTPUT);
11
+ pinMode(buttonPins[i], INPUT);
12
+ }
13
+ }
14
+
15
+ void loop() {
16
+ for (int i = 0; i < LENGTH; ++i) {
17
+ if (digitalRead(buttonPins[i])) {
18
+ turnOnLed(i);
19
+ }
20
+ }
21
+
22
+ delay(1);
23
+ }
24
+
25
+ void turnOnLed(int which) {
26
+ for (int i = 0; i < LENGTH; ++i) {
27
+ if (i == which) {
28
+ digitalWrite(ledPins[i], HIGH);
29
+ Serial.print(channelIds[i]);
30
+ } else {
31
+ digitalWrite(ledPins[i], LOW);
32
+ }
33
+ }
34
+
35
+ delay(1000);
36
+ }
@@ -0,0 +1 @@
1
+ require 'douban.fm.arduino/version'
@@ -0,0 +1,3 @@
1
+ module DoubanFMArduino
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: douban.fm.arduino
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - honnix
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: serialport
16
+ requirement: &70152469417760 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70152469417760
25
+ description: douban.fm.arduino
26
+ email:
27
+ - hxliang1982@gmail.com
28
+ executables:
29
+ - douban.fm.arduino
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .gitignore
34
+ - Gemfile
35
+ - LICENSE.txt
36
+ - README.md
37
+ - Rakefile
38
+ - bin/douban.fm.arduino
39
+ - douban.fm.arduino.gemspec
40
+ - douban_fm.ino
41
+ - lib/douban.fm.arduino.rb
42
+ - lib/douban.fm.arduino/version.rb
43
+ homepage: https://github.com/honnix/douban.fm.arduino
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.15
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: douban.fm.arduino
67
+ test_files: []
68
+ has_rdoc: