myo-ruby 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e975468502cb8bd8d418b80a96f0a2328c783de
4
- data.tar.gz: 78ab8fda314e09dc2f17a98a12df84653818d764
3
+ metadata.gz: 9787925c5406af339c1283cf6a8ce408227e1ec5
4
+ data.tar.gz: e23f9ffe47699aea492475cfe66262a681c96196
5
5
  SHA512:
6
- metadata.gz: b2e370703889ab28a6e9087554b996a4aaf756d4e93dade9515669b442fa10bd360d5e5eafd82f235bbbff8de67cf2d0e063b5db6b259cc00b5befde0190e03e
7
- data.tar.gz: 3fae5cede62230f999092068236709960d258c0a4d9990e930843536565e5e1ce8dc343d34428b5deb20d6fc0e0c9a4bcb3294a0909754931b116385f2227868
6
+ metadata.gz: 2c2c653220a99b7e78d2f6e2e0f207f1186eb6db50b942778077f795aafba01768823c22fb1504704d349a20078debcb8126f5187648335a25f2f6205158c39d
7
+ data.tar.gz: 15d037fe829eaf2507e2389b2c81917df752634567337fbd670c9f93b6f94d624edcb3e63efbccaf2c7b146495df14d37d6df825a02c7b8d361ee42c9d46eb56
data/.gitignore CHANGED
@@ -13,3 +13,4 @@
13
13
  *.o
14
14
  *.a
15
15
  mkmf.log
16
+ test.rb
data/README.md CHANGED
@@ -1,46 +1,52 @@
1
- # Myo
1
+ # myo-ruby
2
2
 
3
- Connect to Myo armband in Ruby
3
+ Connect to [Myo armband](https://www.thalmic.com/en/myo/) in Ruby
4
4
 
5
- ## Installation
5
+ ## Usage
6
6
 
7
- Add this line to your application's Gemfile:
7
+ You must start __Myo Connect.app__ first.
8
8
 
9
9
  ```ruby
10
- gem 'myo'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
10
+ require 'myo'
18
11
 
19
- $ gem install myo-ruby
20
-
21
- ## Example
22
-
23
- You should start __Myo Connect.app__ first.
24
-
25
- ```ruby
26
12
  Myo.connect do |myo|
27
13
  myo.on :connected do
28
14
  puts "Myo connected!"
29
15
  end
30
16
 
31
- myo.on :pose do |m, pose, edge|
17
+ myo.on :pose do |pose, edge|
32
18
  puts "#{pose}: #{edge}"
33
19
  end
34
20
 
35
- myo.on :periodic do |m, orientation|
21
+ myo.on :periodic do |orientation|
36
22
  puts orientation.accel.x
37
23
  end
38
24
  end
39
25
  ```
40
26
 
27
+ ## Installation
28
+
29
+ Add this line to your application's Gemfile:
30
+
31
+ ```ruby
32
+ gem 'myo-ruby'
33
+ ```
34
+
35
+ And then execute:
36
+
37
+ ```
38
+ $ bundle
39
+ ```
40
+
41
+ Or install it yourself as:
42
+
43
+ ```
44
+ $ gem install myo-ruby
45
+ ```
46
+
41
47
  ## Contributing
42
48
 
43
- 1. Fork it ( https://github.com/uetchy/myo.rb/fork )
49
+ 1. Fork it ( https://github.com/uetchy/myo-ruby/fork )
44
50
  2. Create your feature branch (`git checkout -b my-new-feature`)
45
51
  3. Commit your changes (`git commit -am 'Add some feature'`)
46
52
  4. Push to the branch (`git push origin my-new-feature`)
data/lib/myo.rb CHANGED
@@ -9,6 +9,7 @@ module Myo
9
9
  MYO_API_VERSION = 3
10
10
  SOCKET_URL = "ws://127.0.0.1:10138/myo/#{MYO_API_VERSION}"
11
11
 
12
+ # Define event handler for each Myo armband
12
13
  def self.connect
13
14
  client = Client.new(SOCKET_URL)
14
15
  yield(client)
data/lib/myo/client.rb CHANGED
@@ -16,11 +16,13 @@ class Myo::Chamber
16
16
  conn = EventMachine::WebSocketClient.connect(@socket_url)
17
17
 
18
18
  conn.callback do
19
- @callbacks_[:connected].call(self)
19
+ return unless @callbacks_[:connected]
20
+ instance_eval(&@callbacks_[:connected])
20
21
  end
21
22
 
22
23
  conn.errback do |e|
23
- @callbacks_[:error].call(self)
24
+ return unless @callbacks_[:error]
25
+ instance_eval(e, &@callbacks_[:error])
24
26
  end
25
27
 
26
28
  conn.stream do |msg|
@@ -29,11 +31,13 @@ class Myo::Chamber
29
31
  event = JSON.parse(msg.data)[1]
30
32
  case event['type']
31
33
  when 'pose'
34
+ break unless @callbacks_[:pose]
32
35
  pose = event['pose']
33
- @callbacks_[:pose].call(self, @pool_[:prev_pose], :off) if @pool_[:prev_pose]
34
- @callbacks_[:pose].call(self, pose, :on)
36
+ instance_eval(@pool_[:prev_pose], :off, &@callbacks_[:pose]) if @pool_[:prev_pose]
37
+ instance_eval(pose, :on, &@callbacks_[:pose])
35
38
  @pool_[:prev_pose] = pose
36
39
  when 'orientation'
40
+ break unless @callbacks_[:periodic]
37
41
  e = OpenStruct.new({
38
42
  :accel => OpenStruct.new({
39
43
  :x => event['accelerometer'][0],
@@ -48,7 +52,7 @@ class Myo::Chamber
48
52
  :orientation => OpenStruct.new(event['orientation'])
49
53
  })
50
54
  @pool_[:latest_orientation] = e
51
- @callbacks_[:periodic].call(self, e)
55
+ instance_eval(e, &@callbacks_[:periodic])
52
56
  end
53
57
  end
54
58
 
data/lib/myo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Myo
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/myo.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["uetchy@randompaper.co"]
11
11
  spec.summary = %q{Connect to Myo armband in Ruby}
12
12
  spec.description = %q{Connect to Myo armband in Ruby}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/uetchy/myo-ruby"
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_development_dependency "bundler", "~> 1.7"
22
22
  spec.add_development_dependency "rake", "~> 10.0"
23
23
  spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "yard"
24
25
 
25
26
  spec.add_dependency "em-websocket-client", "~> 0.1.2"
26
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myo-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yasuaki Uechi
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: em-websocket-client
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +99,7 @@ files:
85
99
  - myo.gemspec
86
100
  - spec/myo_spec.rb
87
101
  - spec/spec_helper.rb
88
- homepage: ''
102
+ homepage: https://github.com/uetchy/myo-ruby
89
103
  licenses:
90
104
  - MIT
91
105
  metadata: {}
@@ -112,3 +126,4 @@ summary: Connect to Myo armband in Ruby
112
126
  test_files:
113
127
  - spec/myo_spec.rb
114
128
  - spec/spec_helper.rb
129
+ has_rdoc: