NAME
Device::MindWave
SYNOPSIS
use Device::MindWave;
my $mw = Device::MindWave->new(port => '/dev/ttyUSB0');
$mw->auto_connect();
while (my $packet = $mw->read_packet()) {
print $packet->as_string(),"\n";
}
...
DESCRIPTION
Provides for connecting to and disconnecting from a NeuroSky MindWave headset, as well as reading and parsing the data that it produces.
CONSTRUCTOR
- new
-
Arguments (hash):
- port
-
The port name (e.g. 'COM4', '/dev/ttyUSB0').
- fh
-
An object representing the MindWave. Must implement
read
andwrite
, as per IO::Handle. This library will not reattemptread
s on the filehandle if fewer characters than requested are returned.
One of
port
andfh
must be provided. Returns a new instance of Device::MindWave.
PUBLIC METHODS
- connect_nb
-
Takes a headset ID as its argument, sends a message to the dongle to connect to that headset, and returns immediately. The caller must use
read_packet
to determine whether the connection was made successfully.The headset ID can be provided as either one 16-bit number or two 8-bit numbers in network byte order. For example, if the headset has the ID '12AB', then the argument can be
0x12AB
, or0x12
and0xAB
. (The identifier is printed at the bottom of the label inside the battery compartment.) - connect
-
As per
connect_nb
, except that it blocks until either the connection is successfully established or an error occurs (e.g. request denied by dongle due to existing connection). Dies on error. - auto_connect_nb
-
As per
connect_nb
, except that it does not take any arguments and the dongle message is such that it will attempt to connect to any headset within range. - auto_connect
-
As per
connect
, except forauto_connect_nb
. - disconnect_nb
-
Sends a message to the dongle to disconnect from the headset. The caller must use
read_packet
to determine whether the connection was closed successfully. - disconnect
-
As per
disconnect_nb
, except that it blocks until either the connection is closed or an error occurs (e.g. request denied by dongle because it is not currently connected to a headset). Dies on error. - read_packet
-
Attempts to parse and return a packet from the dongle. The returned packet objects implement Device::MindWave::Packet. If a checksum error is encountered, then the read operation is retried, but all other errors will result in a die. By default, the read timeout is one second.
When not connected to a headset, this method will return dongle communication protocol packets. Each of these implements the Device::MindWave::Packet::Dongle interface. When connected to a headset, this method will return ThinkGear packets: see Device::MindWave::Packet::ThinkGear.
AUTHOR
Tom Harrison, <tomhrr at cpan.org>
ACKNOWLEDGEMENTS
COPYRIGHT AND LICENCE
Copyright (C) 2014 Tom Harrison
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.