examples/asicwaves.rb in mindwave-0.1.4 vs examples/asicwaves.rb in mindwave-0.1.5
- old
+ new
@@ -1,10 +1,25 @@
#!/usr/bin/env ruby
require "bundler/setup"
require 'mindwave'
+require 'mysql2'
+require 'active_record'
+# Set up the database connection
+ActiveRecord::Base.establish_connection(
+ :adapter => "mysql2",
+ :host => "localhost",
+ :username => "svf",
+ :password => "idlinmal",
+ :database => "eeg"
+)
+
+# Define the EEG db/class
+class EEGSession < ActiveRecord::Base
+end
+
class EEG < Mindwave::Headset
# override Attention-Callback-Method
def asicCall(asic)
puts "DEBUG: ASIC array: #{asic}\n"
@@ -19,11 +34,47 @@
puts "highAlpha: #{parsed[3]}"
puts "lowBeta: #{parsed[4]}"
puts "highBeta: #{parsed[5]}"
puts "lowGamma: #{parsed[6]}"
puts "midGamma: #{parsed[7]}"
+
+ # INSERT wave values into the db
+ dbInsert(parsed)
+
end
+ def dbInsert(parsed)
+
+ # Time format (datetime with miliseconds)
+ f = '%Y%m%d %H:%M:%S.%3N'
+ # fetch the time and format it
+ t = Time.now.strftime(f)
+
+ # temp values
+ noise = 0
+ poor = 0
+ attention = 50
+ meditation = 50
+ blink = 1
+ # INSERT EEG wave values into MySQL db
+ sess = EEGSession.create!(datetime: t
+ amount_of_noise: noise,
+ poor_signal_level_string: poor,
+ attention: attention,
+ meditation: meditation,
+ blink: blink,
+ delta: parsed[0],
+ theta: parsed[1],
+ low_alpha: parsed[2],
+ high_alpha: parsed[3],
+ low_beta: parsed[4],
+ high_beta: parsed[5],
+ low_gamma: parsed[6],
+ mid_gamma: parsed[7]
+ )
+ end
+
+
end
# create a new instance
mw = EEG.new
# mw.log.level = Logger::DEBUG