Class: Mindset::LoopbackConnection

Inherits:
Object
  • Object
show all
Defined in:
lib/mindset.rb

Overview

A fake Mindset connection which just replays data previously captured (and serialized to JSON). This is used to provide a uniform interface for displaying either realtime or captured EEG data. Note: This expects a PacketStore object to be stored in @data before read_packet is called.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ LoopbackConnection

Returns a new instance of LoopbackConnection.



245
246
247
248
249
250
# File 'lib/mindset.rb', line 245

def initialize(data=nil)
  @data = data
  @counter = 0
  @wave_idx = 0
  @esense_idx = 0
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



243
244
245
# File 'lib/mindset.rb', line 243

def data
  @data
end

Instance Method Details

#disconnectObject



291
292
293
# File 'lib/mindset.rb', line 291

def disconnect
  @data = {}
end

#read_packet(verbose = false) ⇒ Object

Simulate a read of the Mindset device by returning an Array of Packet objects. This assumes it will be called 8 times a second.

According to the MDT, Mindset packets are sent at the following intervals:

1 packet per second: eSense, ASIC EEG, POOR_SIGNAL
512 packets per second: RAW

Each read will therefore return 64 RAW packets. Every eighth read will also return 1 eSense, ASIC_EEG, and POOR_SIGNAL packet.



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/mindset.rb', line 263

def read_packet(verbose=false)
  packets = @data[:wave][@wave_idx, 64].map { |val| 
            Packet.factory(:wave, val)  }
  @wave_idx += 64
  @wave_idx = 0 if @wave_idx >= @data[:wave].count

  if @counter == 7
    packets << Packet.factory(:delta, @data[:delta][@esense_idx])
    packets << Packet.factory(:theta, @data[:theta][@esense_idx])
    packets << Packet.factory(:lo_alpha, @data[:lo_alpha][@esense_idx])
    packets << Packet.factory(:hi_alpha, @data[:hi_alpha][@esense_idx])
    packets << Packet.factory(:lo_beta, @data[:lo_beta][@esense_idx])
    packets << Packet.factory(:hi_beta, @data[:hi_beta][@esense_idx])
    packets << Packet.factory(:lo_gamma, @data[:lo_gamma][@esense_idx])
    packets << Packet.factory(:mid_gamma, @data[:mid_gamma][@esense_idx])
    packets << Packet.factory(:signal_quality, 
                              @data[:signal_quality][@esense_idx])
    packets << Packet.factory(:attention, @data[:attention][@esense_idx])
    packets << Packet.factory(:meditation, @data[:meditation][@esense_idx])
    packets << Packet.factory(:blink, @data[:blink][@esense_idx])
    @esense_idx += 1
    @esense_idx = 0 if @esense_idx >= @data[:delta].count
  end

  @counter = (@counter + 1) % 8
  packets
end