myo-ruby 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e975468502cb8bd8d418b80a96f0a2328c783de
4
+ data.tar.gz: 78ab8fda314e09dc2f17a98a12df84653818d764
5
+ SHA512:
6
+ metadata.gz: b2e370703889ab28a6e9087554b996a4aaf756d4e93dade9515669b442fa10bd360d5e5eafd82f235bbbff8de67cf2d0e063b5db6b259cc00b5befde0190e03e
7
+ data.tar.gz: 3fae5cede62230f999092068236709960d258c0a4d9990e930843536565e5e1ce8dc343d34428b5deb20d6fc0e0c9a4bcb3294a0909754931b116385f2227868
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /vendor/bundle/
3
+ /.yardoc
4
+ /Gemfile.lock
5
+ /_yardoc/
6
+ /coverage/
7
+ /doc/
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in myo.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Yasuaki Uechi
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.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Myo
2
+
3
+ Connect to Myo armband in Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'myo'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install myo-ruby
20
+
21
+ ## Example
22
+
23
+ You should start __Myo Connect.app__ first.
24
+
25
+ ```ruby
26
+ Myo.connect do |myo|
27
+ myo.on :connected do
28
+ puts "Myo connected!"
29
+ end
30
+
31
+ myo.on :pose do |m, pose, edge|
32
+ puts "#{pose}: #{edge}"
33
+ end
34
+
35
+ myo.on :periodic do |m, orientation|
36
+ puts orientation.accel.x
37
+ end
38
+ end
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/uetchy/myo.rb/fork )
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
data/lib/myo/client.rb ADDED
@@ -0,0 +1,75 @@
1
+ class Myo::Chamber
2
+ attr_accessor :callbacks_
3
+
4
+ def initialize(socket_url)
5
+ @socket_url = socket_url
6
+ @callbacks_ = {}
7
+ @pool_ = {}
8
+ end
9
+
10
+ def getRoll
11
+ @pool_[:latest_orientation].accel.x
12
+ end
13
+
14
+ def start
15
+ EM.run do
16
+ conn = EventMachine::WebSocketClient.connect(@socket_url)
17
+
18
+ conn.callback do
19
+ @callbacks_[:connected].call(self)
20
+ end
21
+
22
+ conn.errback do |e|
23
+ @callbacks_[:error].call(self)
24
+ end
25
+
26
+ conn.stream do |msg|
27
+ conn.close_connection if msg.data == "done"
28
+
29
+ event = JSON.parse(msg.data)[1]
30
+ case event['type']
31
+ when 'pose'
32
+ pose = event['pose']
33
+ @callbacks_[:pose].call(self, @pool_[:prev_pose], :off) if @pool_[:prev_pose]
34
+ @callbacks_[:pose].call(self, pose, :on)
35
+ @pool_[:prev_pose] = pose
36
+ when 'orientation'
37
+ e = OpenStruct.new({
38
+ :accel => OpenStruct.new({
39
+ :x => event['accelerometer'][0],
40
+ :y => event['accelerometer'][1],
41
+ :z => event['accelerometer'][2]
42
+ }),
43
+ :gyro => OpenStruct.new({
44
+ :x => event['gyroscope'][0],
45
+ :y => event['gyroscope'][1],
46
+ :z => event['gyroscope'][2]
47
+ }),
48
+ :orientation => OpenStruct.new(event['orientation'])
49
+ })
50
+ @pool_[:latest_orientation] = e
51
+ @callbacks_[:periodic].call(self, e)
52
+ end
53
+ end
54
+
55
+ conn.disconnect do
56
+ EM::stop_event_loop
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ class Myo::Client
63
+ def initialize(socket_url)
64
+ @socket_url = socket_url
65
+ @chamber = Myo::Chamber.new(@socket_url)
66
+ end
67
+
68
+ def on(event_name, &block)
69
+ @chamber.callbacks_[event_name.to_sym] = block
70
+ end
71
+
72
+ def start
73
+ @chamber.start
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module Myo
2
+ VERSION = "0.1.0"
3
+ end
data/lib/myo.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'em-websocket-client'
2
+ require 'json'
3
+ require 'ostruct'
4
+
5
+ require 'myo/version'
6
+ require 'myo/client'
7
+
8
+ module Myo
9
+ MYO_API_VERSION = 3
10
+ SOCKET_URL = "ws://127.0.0.1:10138/myo/#{MYO_API_VERSION}"
11
+
12
+ def self.connect
13
+ client = Client.new(SOCKET_URL)
14
+ yield(client)
15
+ client.start
16
+ end
17
+ end
data/myo.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'myo/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "myo-ruby"
8
+ spec.version = Myo::VERSION
9
+ spec.authors = ["Yasuaki Uechi"]
10
+ spec.email = ["uetchy@randompaper.co"]
11
+ spec.summary = %q{Connect to Myo armband in Ruby}
12
+ spec.description = %q{Connect to Myo armband in Ruby}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_dependency "em-websocket-client", "~> 0.1.2"
26
+ end
data/spec/myo_spec.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe Myo do
4
+ it 'has a version number' do
5
+ expect(Myo::VERSION).not_to be nil
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'myo'
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: myo-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Yasuaki Uechi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: em-websocket-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.2
69
+ description: Connect to Myo armband in Ruby
70
+ email:
71
+ - uetchy@randompaper.co
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/myo.rb
83
+ - lib/myo/client.rb
84
+ - lib/myo/version.rb
85
+ - myo.gemspec
86
+ - spec/myo_spec.rb
87
+ - spec/spec_helper.rb
88
+ homepage: ''
89
+ licenses:
90
+ - MIT
91
+ metadata: {}
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubyforge_project:
108
+ rubygems_version: 2.4.2
109
+ signing_key:
110
+ specification_version: 4
111
+ summary: Connect to Myo armband in Ruby
112
+ test_files:
113
+ - spec/myo_spec.rb
114
+ - spec/spec_helper.rb