Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emokit_osc fixed #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

cmake_minimum_required (VERSION 2.6)
PROJECT(emokit)

Expand All @@ -22,10 +23,11 @@ ENDIF()
MESSAGE(STATUS ${LIBS})
INCLUDE_DIRECTORIES(${HIDAPI_INCLUDE_DIR} ${Mcrypt_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/include)

ADD_SUBDIRECTORY(include/oscpack/)
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(examples/emokitd)
ADD_SUBDIRECTORY(examples/contact)
# ADD_SUBDIRECTORY(examples/emokit_osc)
ADD_SUBDIRECTORY(examples/emokit_osc)

##########################################
## PKGCONFIG file ###
Expand Down
17 changes: 10 additions & 7 deletions INSTALL
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Installation instructions for Linux (assuming ubuntu/debian packages)

CMAKE
Download : http://www.cmake.org/cmake/resources/software.html
Go in the download folder and execute :
Go in the download folder and use the following commands :

tar xzvf cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2.tar.gz
cd cmake-2.8.10.2.tar.gz/
./bootstrap
make
sudo make install
Expand All @@ -14,10 +16,10 @@ First install the dependencies :
sudo apt-get install libmcrypt-dev libmhash-dev git

Download : http://sourceforge.net/projects/mcrypt/files/latest/download
Go in the download folder and execute :
Go in the download folder and use the following commands :

tar xzvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8.tar.gz/
./configure
make
make install
Expand All @@ -29,10 +31,10 @@ sudo apt-get install libudev-dev libusb-1.0-0-dev libtool

Download : https://github.com/signal11/hidapi/archive/master.zip
IT WILL NOT WORK if you downloaded from: hidapi-0.7.0.zip from https://github.com/signal11/hidapi/downloads or the command git clone git://github.com/signal11/hidapi.git
Extract the zip file and use the following commands :
Go in the download folder and use the following commands :

unzip hidapid-master.zip
cd hidapid-master
cd hidapid-master/
./bootstrap
./configure
make
Expand All @@ -41,9 +43,10 @@ sudo make install

EMOKIT
Download https://github.com/openyou/emokit/archive/master.zip
Go in the download folder and use the following commands :

unzip emokit-master.zip
cd emokit-master
cd emokit-master/
cmake .
make

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
Emokit
======
Summary
=======

Modified version by Gael Grosch for his bachelor project at EPFL (original can be found at openyou/emokit). The main contributions are some stability fixes and the adition of signal processing libraries.


Original info on Emokit
=======================

Reverse engineering and original code written by

Expand Down
21 changes: 13 additions & 8 deletions examples/emokit_osc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@

LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(oscpack)

IF(NOT oscpack_FOUND)
MESSAGE(STATUS "oscpack not found, not building emokit osc server")
ENDIF()
INCLUDE_DIRECTORIES(${oscpack_INCLUDE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
ADD_EXECUTABLE(emokit_osc emokit_osc.cpp)
ADD_DEPENDENCIES(emokit_osc epoc)
TARGET_LINK_LIBRARIES(emokit_osc ${oscpack_LIBS} epoc ${LIBS})
ADD_DEPENDENCIES(emokit_osc emokit)
TARGET_LINK_LIBRARIES(emokit_osc oscpack emokit ${LIBS})

SET_TARGET_PROPERTIES(emokit_osc PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib
BUILD_WITH_INSTALL_RPATH TRUE )

INSTALL (TARGETS emokit_osc
RUNTIME DESTINATION bin
)

38 changes: 0 additions & 38 deletions examples/emokit_osc/Findoscpack.cmake

This file was deleted.

113 changes: 50 additions & 63 deletions examples/emokit_osc/emokit_osc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,87 +7,74 @@
#include <cstdlib>
#include <csignal>
#include <iostream>
#include "oscpack/osc/OscOutboundPacketStream.h"
#include "oscpack/ip/UdpSocket.h"
#include "libepoc.h"
#include "../../include/oscpack/osc/OscOutboundPacketStream.h"
#include "../../include/oscpack/ip/UdpSocket.h"

#define ADDRESS "127.0.0.1"
#define PORT 9997

#define OUTPUT_BUFFER_SIZE 4096

void sigproc(int i)
extern "C"
{
std::cout << "closing epoc and quitting" << std::endl;
exit(0);
#include "emokit/emokit.h"
}

int main(int argc, char* argv[])
{
signal(SIGINT, sigproc);
#ifndef WIN32
signal(SIGQUIT, sigproc);
#endif

UdpTransmitSocket transmitSocket( IpEndpointName( ADDRESS, PORT ) );

char buffer[OUTPUT_BUFFER_SIZE];
#define ADDRESS "127.0.0.1"
#define PORT 9997

#define OUTPUT_BUFFER_SIZE 4096

int main(int argc, char **argv)
{

emokit_device* d;
d = emokit_create();

FILE *input;
FILE *output;
enum headset_type type;

char raw_frame[32];
struct epoc_frame frame;
epoc_device* d;
uint8_t data[32];
if (argc < 2)
std::cout << "Current epoc devices connected " << emokit_get_count(d, EMOKIT_VID, EMOKIT_PID) << "\n";
if(emokit_open(d, EMOKIT_VID, EMOKIT_PID, 1) != 0)
{
fputs("Missing argument\nExpected: epocd [consumer|research|special]\n", stderr);
return 1;
}

if(strcmp(argv[1], "research") == 0)
type = RESEARCH_HEADSET;
else if(strcmp(argv[1], "consumer") == 0)
type = CONSUMER_HEADSET;
else if(strcmp(argv[1], "special") == 0)
type = SPECIAL_HEADSET;
else {
fputs("Bad headset type argument\nExpected: epocd [consumer|research|special] source [dest]\n", stderr);
std::cout << "CANNOT CONNECT\n";
return 1;
}

epoc_init(type);

d = epoc_create();
printf("Current epoc devices connected: %d\n", epoc_get_count(d, EPOC_VID, EPOC_PID));
if(epoc_open(d, EPOC_VID, EPOC_PID, 0) != 0)
{
printf("CANNOT CONNECT\n");
return 1;
}
UdpTransmitSocket transmitSocket( IpEndpointName( ADDRESS, PORT ) );
char buffer[OUTPUT_BUFFER_SIZE];
char raw_frame[32];
struct emokit_frame frame;

std::cout << "Connected\n";
while(1)
{
if(epoc_read_data(d, data) > 0)
std::cout << "Starting read\n";
if(emokit_read_data(d) > 0)
{
epoc_get_next_frame(&frame, data);
struct emokit_frame c;
c = emokit_get_next_frame(d);

osc::OutboundPacketStream p( buffer, OUTPUT_BUFFER_SIZE );
p << osc::BeginBundleImmediate
<< osc::BeginMessage( "/epoc/channels" )
<< frame.F3 << frame.FC6 << frame.P7 << frame.T8 << frame.F7 << frame.F8 << frame.T7 << frame.P8 << frame.AF4 << frame.F4 << frame.AF3 << frame.O2 << frame.O1 << frame.FC5 << osc::EndMessage
<< osc::BeginMessage( "/epoc/gyro" )
<< frame.gyroX << frame.gyroY << osc::EndMessage
<< osc::EndBundle;

p << osc::BeginMessage( "/emokit/channels" )
<< c.F3 << c.FC6 << c.P7 << c.T8 << c.F7 << c.F8
<< c.T7 << c.P8 << c.AF4 << c.F4 << c.AF3 << c.O2
<< c.O1 << c.FC5
<< osc::EndMessage;
transmitSocket.Send( p.Data(), p.Size() );

osc::OutboundPacketStream q( buffer, OUTPUT_BUFFER_SIZE );
q << osc::BeginMessage( "/emokit/gyro" )
<< (int)frame.gyroX << (int)frame.gyroY << osc::EndMessage;
transmitSocket.Send( q.Data(), q.Size() );

osc::OutboundPacketStream info( buffer, OUTPUT_BUFFER_SIZE );
info << osc::BeginMessage( "/emokit/info" )
<< (int)c.battery
<< c.cq.F3 << c.cq.FC6 << c.cq.P7 << c.cq.T8 << c.cq.F7 << c.cq.F8
<< c.cq.T7 << c.cq.P8 << c.cq.AF4 << c.cq.F4 << c.cq.AF3 << c.cq.O2
<< c.cq.O1 << c.cq.FC5
<< osc::EndMessage;
transmitSocket.Send( info.Data(), info.Size() );

}
}

epoc_close(d);
epoc_delete(d);
fflush(stdout);
emokit_close(d);
emokit_delete(d);
return 0;

}

59 changes: 59 additions & 0 deletions examples/emokit_osc/processing/emokit_osc/emokit_osc.pde
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* This example is yet to be improved. It does not handle exceptions and may prove faulty.
*/

//Import OSC libs
import oscP5.*;
import netP5.*;

//OSC
OscP5 oscP5;

int[] vals;


void setup() {
//Graphical
size(100, 300);
smooth();
noStroke();
//osc
oscP5 = new OscP5(this, 9997);

vals = new int[14];
for (int i = 0; i < vals.length; i++) {
vals[i] = 0;
}

}

//Main function, draw frame
void draw() {
background(255);
fill(0);
text("Levels : \n", 40, 30);
for (int i=0 ; i<14 ; i++){
text(vals[i], 40, 75+i*12);
}
}


//If new OSC value, update happens here
void oscEvent(OscMessage msg) {
if(msg.checkAddrPattern("/emokit/channels")){
println("1) Channel readings:");
for(int i=0 ; i<14 ; i++){
vals[i] = msg.get(i).intValue();
println("[" + i + "] : " + vals[i]);
}
println();
} else if(msg.checkAddrPattern("/emokit/gyro")){
println("2) Gyro:");
println("x: " + msg.get(0).intValue() + " ; y: " + msg.get(1).intValue());
println();
} else
if (msg.checkAddrPattern("/emokit/infos")) {
//Todo
}
}

2 changes: 1 addition & 1 deletion examples/emokitd/emokitd.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ int main(int argc, char **argv)

d = emokit_create();
printf("Current epoc devices connected: %d\n", emokit_get_count(d, EMOKIT_VID, EMOKIT_PID));
int r = emokit_open(d, EMOKIT_VID, EMOKIT_PID, 0);
int r = emokit_open(d, EMOKIT_VID, EMOKIT_PID, 1);
if(r != 0)
{
printf("CANNOT CONNECT: %d\n", r);
Expand Down
Loading