Main Page | Modules | Class Hierarchy | Data Structures | File List | Data Fields | Globals | Related Pages

MaiaEmgAnalize.h

Go to the documentation of this file.
00001 
00002 // This code is part of the MaiaProject free software
00003 //
00004 // Keyboard and Mouse Emulator - Virtual keyboard Engine
00005 //
00006 // Copyright (c) 2002-2003 Luca Clivio <luca.clivio@maiaproject.org>
00007 // Tel. +39-347-2538040
00008 // via B.Croce 2, 20037 Paderno Dugnano (Milano) - Italy
00009 //
00010 // Developers:
00011 //    Simone Mangano <simone.mangano@maiaproject.org>
00012 //    Andrea Tosato  <andrea.tosato@maiaproject.org>
00013 //
00014 //  -----------------------------------------------------------------------------
00015 //  This program is free software; This program is free software; 
00016 //  you can redistribute it and/or modify it under the terms of the 
00017 //  GNU General Public License as published by the Free Software Foundation; 
00018 //  either version 2 of the License, or (at your option) any later version.
00019 //  but WITHOUT ANY WARRANTY; without even the implied warranty of                              
00020 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                                
00021 //  GNU General Public License for more details.                                                
00022 //  You should have received a copy of the GNU General Public License                           
00023 //  along with this program; if not, write to the Free Software                                 
00024 //  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                                   
00026 
00027 #ifndef _MaiaEmgAnalize_h_
00028 #define _MaiaEmgAnalize_h_
00029 
00036 #include <wx/wx.h>
00037 
00038 #include <iostream>
00039 
00040 #include <stdio.h>
00041 #include <unistd.h>
00042 #include <fcntl.h>
00043 #include <sys/ioctl.h>
00044 #include <sys/wait.h>
00045 #include <sys/types.h>
00046 #include <string.h>
00047 #include <termios.h>
00048 
00049 #include <openmaia/libopenmaia.h>
00050 
00051 
00052 #define DATAVECTORSIZE 1024*30 //Number of data stored
00053 #define FILTERORDER 5 //Filter order
00054 
00055 #define BAUDRATE B57600
00056 #define MODEMDEVICE "/dev/ttyS0"
00057 
00058 #define uint8_t unsigned char
00059 #define uint16_t unsigned short
00060 
00061 // This packet is transmitted from modEEG after an a5 and 5a control characters
00062 typedef struct modeeg_packet
00063 {
00064         uint8_t         version;        // = 2
00065         uint8_t         count;          // packet counter. Increases by 1 each packet.
00066         uint16_t        data[6];        // 10-bit sample (= 0 - 1023) in big endian (Motorola) format.
00067         uint8_t         switches;       // State of PD5 to PD2, in bits 3 to 0.
00068 } modeeg_packet_t;
00069 
00070 
00071 
00072 class MaiaEmgAnalize: public wxThread
00073 {
00074  private:
00075   int fd;   // file descriptor of the serial device
00076   struct termios oldtio;   // original termios structure
00077 
00078   unsigned short *dataVector;   // pointer to the shared data vector
00079   int *dataIndex;                  // pointer to current index in the data vector
00080 
00081   double *filteredVector;// pointer to shared filtered data vector
00082 
00083   bool fromStdInput;//Indicate if data is get from standard input
00084 
00085 
00086   uint8_t old_count;  //last packet count number
00087 
00088   unsigned short LittleEndianize(unsigned short) ;  // convert in little endian
00089 
00090 
00091   omConnector *connector;
00092   int clickThreshold; //Treshold for identifying click
00093   int clickIgnoreSamples; // If a click is identified in this samples window is ignored
00094   bool IsClick(); //Analize filteredVector to identify CLICK
00095 
00096  public:
00097   MaiaEmgAnalize( unsigned short *, int *, double *, bool, wxString);
00098   void *Entry();
00099   void OnExit() ;
00100 };
00101 
00102 #endif // _MaiaEmgAnalize_h_