mindwave 0.1.3 → 0.1.4
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 +4 -4
- data/README.md +48 -5
- data/examples/asicwaves.rb +43 -0
- data/lib/mindwave.rb +51 -1
- data/lib/mindwave/version.rb +1 -1
- data/mindwave.gemspec +2 -2
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3749b5d8725c89d97767c7e754aa85925bac04be
|
4
|
+
data.tar.gz: 0a386a4d2adb90b2bc3e140a5f25d0f26f8fd579
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ae1104d21949242e4a843ea29db60a8331f41084ab65c016c155c3f34b87234d89db6cca8bdd7635ab59c9cdddf20f400e1f3dffdb37f72684f73ec574cf2a8e
|
7
|
+
data.tar.gz: 25b4a5d9cf33b14f05045bf55f71db5cd5e59f564815e59ff5bfa3680233da4a0ab5d83cbf4c5fcc9404cf1cf7c17f06bbf5957cd2b3b52a4ee7a3490b7601b2
|
data/README.md
CHANGED
@@ -4,11 +4,10 @@
|
|
4
4
|
[](https://travis-ci.org/whotwagner/mindwave)
|
5
5
|
[](http://inch-ci.org/github/whotwagner/mindwave)
|
6
6
|
[](https://codeclimate.com/github/whotwagner/mindwave)
|
7
|
+
[](https://badge.fury.io/rb/mindwave)
|
7
8
|
|
8
9
|
|
9
|
-
This gem is a library for
|
10
|
-
|
11
|
-
Even if this library is written for the Mindwave-Headset most of the code should work with the Mindwave-Mobile-Headset too. The big difference is that the methods "connect and disconnect" are not needed for Mindwave Mobile Headsets.
|
10
|
+
This gem is a library for Neurosky Mindwave headsets. It reads out EEG-data from the ThinkGear Serial Stream and provides callback-methods for processing the data. this library works for Mindwave and Mindwave-Mobile.
|
12
11
|
|
13
12
|
## Installation
|
14
13
|
|
@@ -90,6 +89,52 @@ thread = Thread.new { mw.run }
|
|
90
89
|
# ..and run it
|
91
90
|
thread.join
|
92
91
|
|
92
|
+
mw.close
|
93
|
+
```
|
94
|
+
|
95
|
+
Callback for EEG-powers:
|
96
|
+
```ruby
|
97
|
+
#!/usr/bin/env ruby
|
98
|
+
|
99
|
+
require 'mindwave'
|
100
|
+
|
101
|
+
class EEG < Mindwave::Headset
|
102
|
+
# override Attention-Callback-Method
|
103
|
+
def asicCall(asic)
|
104
|
+
|
105
|
+
puts "DEBUG: ASIC array: #{asic}\n"
|
106
|
+
|
107
|
+
# pass asic to parseASIC and store result
|
108
|
+
parsed = parseASIC(asic)
|
109
|
+
|
110
|
+
# print the values of the waves to STDOUT
|
111
|
+
puts "delta: #{parsed[0]}"
|
112
|
+
puts "theta: #{parsed[1]}"
|
113
|
+
puts "lowAlpha: #{parsed[2]}"
|
114
|
+
puts "highAlpha: #{parsed[3]}"
|
115
|
+
puts "lowBeta: #{parsed[4]}"
|
116
|
+
puts "highBeta: #{parsed[5]}"
|
117
|
+
puts "lowGamma: #{parsed[6]}"
|
118
|
+
puts "midGamma: #{parsed[7]}"
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
# create a new instance
|
124
|
+
mw = EEG.new
|
125
|
+
# mw.log.level = Logger::DEBUG
|
126
|
+
|
127
|
+
# if we hit ctrl+c then just stop the run()-method
|
128
|
+
Signal.trap("INT") do
|
129
|
+
mw.stop
|
130
|
+
end
|
131
|
+
|
132
|
+
# Create a new Thread
|
133
|
+
thread = Thread.new { mw.run }
|
134
|
+
# ..and run it
|
135
|
+
thread.join
|
136
|
+
|
137
|
+
|
93
138
|
mw.close
|
94
139
|
```
|
95
140
|
|
@@ -107,8 +152,6 @@ mw.close
|
|
107
152
|
|
108
153
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
109
154
|
|
110
|
-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
111
|
-
|
112
155
|
## Contributing
|
113
156
|
|
114
157
|
Bug reports and pull requests are welcome on GitHub at https://github.com/whotwagner/mindwave. I am highly interested at pull requests for the mindwave-mobile-headset.
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require 'mindwave'
|
5
|
+
|
6
|
+
class EEG < Mindwave::Headset
|
7
|
+
# override Attention-Callback-Method
|
8
|
+
def asicCall(asic)
|
9
|
+
|
10
|
+
puts "DEBUG: ASIC array: #{asic}\n"
|
11
|
+
|
12
|
+
# pass asic to parseASIC and store result
|
13
|
+
parsed = parseASIC(asic)
|
14
|
+
|
15
|
+
# print the values of the waves to STDOUT
|
16
|
+
puts "delta: #{parsed[0]}"
|
17
|
+
puts "theta: #{parsed[1]}"
|
18
|
+
puts "lowAlpha: #{parsed[2]}"
|
19
|
+
puts "highAlpha: #{parsed[3]}"
|
20
|
+
puts "lowBeta: #{parsed[4]}"
|
21
|
+
puts "highBeta: #{parsed[5]}"
|
22
|
+
puts "lowGamma: #{parsed[6]}"
|
23
|
+
puts "midGamma: #{parsed[7]}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
# create a new instance
|
29
|
+
mw = EEG.new
|
30
|
+
# mw.log.level = Logger::DEBUG
|
31
|
+
|
32
|
+
# if we hit ctrl+c then just stop the run()-method
|
33
|
+
Signal.trap("INT") do
|
34
|
+
mw.stop
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create a new Thread
|
38
|
+
thread = Thread.new { mw.run }
|
39
|
+
# ..and run it
|
40
|
+
thread.join
|
41
|
+
|
42
|
+
|
43
|
+
mw.close
|
data/lib/mindwave.rb
CHANGED
@@ -126,7 +126,7 @@ attr_accessor :headsetid, :device, :rate, :log
|
|
126
126
|
# stores the current heart-value
|
127
127
|
# @!attribute [r] runner
|
128
128
|
# @see #stop
|
129
|
-
attr_reader :attention, :meditation, :asic
|
129
|
+
attr_reader :attention, :meditation, :asic, :poor, :headsetstatus, :heart, :runner
|
130
130
|
|
131
131
|
# If connectserial is true, then this constructor opens a serial connection
|
132
132
|
# and automatically connects to the headset
|
@@ -376,6 +376,37 @@ def parse_payload(payload)
|
|
376
376
|
|
377
377
|
end
|
378
378
|
|
379
|
+
# this method parses the raw ASIC values and returns the values of each
|
380
|
+
# of the wave types
|
381
|
+
#
|
382
|
+
# @param [Integer] asic value
|
383
|
+
#
|
384
|
+
# @returns [Array<Integer>] Array of: delta,theta,lowAlpha,highAlpha,lowBeta,highBeta,lowGamma,midGamma
|
385
|
+
def parseASIC(asic)
|
386
|
+
# assign #{asic} to the array 'a'
|
387
|
+
a = "#{asic}"
|
388
|
+
# strip off square brackets
|
389
|
+
a = a.delete! '[]'
|
390
|
+
# convert to array of integers
|
391
|
+
a = a.split(",").map(&:to_i)
|
392
|
+
|
393
|
+
# define wave values
|
394
|
+
delta = convertToBigEndianInteger(a[0..3])
|
395
|
+
theta = convertToBigEndianInteger(a[3..6])
|
396
|
+
lowAlpha = convertToBigEndianInteger(a[6..9])
|
397
|
+
highAlpha = convertToBigEndianInteger(a[9..12])
|
398
|
+
lowBeta = convertToBigEndianInteger(a[12..15])
|
399
|
+
highBeta = convertToBigEndianInteger(a[15..18])
|
400
|
+
lowGamma = convertToBigEndianInteger(a[18..21])
|
401
|
+
midGamma = convertToBigEndianInteger(a[21..24])
|
402
|
+
|
403
|
+
# stuff wave values in array
|
404
|
+
asicArray = [delta,theta,lowAlpha,highAlpha,lowBeta,highBeta,lowGamma,midGamma]
|
405
|
+
|
406
|
+
# return array of wave values
|
407
|
+
return asicArray
|
408
|
+
end
|
409
|
+
|
379
410
|
# this method sends a byte to the serial connection
|
380
411
|
# (Mindwave only)
|
381
412
|
#
|
@@ -526,6 +557,7 @@ end
|
|
526
557
|
#
|
527
558
|
# @return [Integer] single value generated from the 2 bytes
|
528
559
|
def convertRaw(rawval1,rawval2)
|
560
|
+
|
529
561
|
raw = rawval1*256 + rawval2
|
530
562
|
if raw >= 32768
|
531
563
|
raw = raw - 65536
|
@@ -534,5 +566,23 @@ def convertRaw(rawval1,rawval2)
|
|
534
566
|
return raw
|
535
567
|
end
|
536
568
|
|
569
|
+
# converts a raw ASIC power packet of three bytes to a single value
|
570
|
+
#
|
571
|
+
# @param [Integer] threeBytes[0] first byte-packet of the ASIC wave code
|
572
|
+
# @param [Integer] threeBytes[1] second byte-packet of the ASIC wave code
|
573
|
+
# @param [Integer] threeBytes[2] third byte-packet of the ASIC wave code
|
574
|
+
#
|
575
|
+
# @return [Integer] single value generated from the 3 bytes
|
576
|
+
def convertToBigEndianInteger(threeBytes)
|
577
|
+
# see MindwaveDataPoints.py at
|
578
|
+
# https://github.com/robintibor/python-mindwave-mobile
|
579
|
+
#
|
580
|
+
bigEndianInteger = (threeBytes[0] << 16) |\
|
581
|
+
(((1 << 16) - 1) & (threeBytes[1] << 8)) |\
|
582
|
+
((1 << 8) -1) & threeBytes[2]
|
583
|
+
return bigEndianInteger
|
584
|
+
end
|
585
|
+
|
586
|
+
|
537
587
|
end
|
538
588
|
end
|
data/lib/mindwave/version.rb
CHANGED
data/mindwave.gemspec
CHANGED
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["code@feedyourhead.at"]
|
11
11
|
|
12
12
|
spec.summary = "mindwave is a ruby-implementation for Neurosky's Mindwave Headset"
|
13
|
-
spec.description = "This
|
14
|
-
spec.homepage = "https://
|
13
|
+
spec.description = " This gem is a library for Neurosky Mindwave headsets. It reads out EEG-data from the ThinkGear Serial Stream and provides callback-methods for processing the data. this library works for Mindwave and Mindwave-Mobile."
|
14
|
+
spec.homepage = "https://github.com/whotwagner/mindwave"
|
15
15
|
spec.licenses = ["GPL"]
|
16
16
|
|
17
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mindwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wolfgang Hotwagner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,7 +52,9 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
-
description:
|
55
|
+
description: " This gem is a library for Neurosky Mindwave headsets. It reads out
|
56
|
+
EEG-data from the ThinkGear Serial Stream and provides callback-methods for processing
|
57
|
+
the data. this library works for Mindwave and Mindwave-Mobile."
|
56
58
|
email:
|
57
59
|
- code@feedyourhead.at
|
58
60
|
executables: []
|
@@ -70,11 +72,12 @@ files:
|
|
70
72
|
- Rakefile
|
71
73
|
- bin/console
|
72
74
|
- bin/setup
|
75
|
+
- examples/asicwaves.rb
|
73
76
|
- examples/mindwaver.rb
|
74
77
|
- lib/mindwave.rb
|
75
78
|
- lib/mindwave/version.rb
|
76
79
|
- mindwave.gemspec
|
77
|
-
homepage: https://
|
80
|
+
homepage: https://github.com/whotwagner/mindwave
|
78
81
|
licenses:
|
79
82
|
- GPL
|
80
83
|
metadata: {}
|