Commit b206cef0 authored by Adrien Dorsaz's avatar Adrien Dorsaz

Some stuff which won't work right now

parent 75af6917
# Add more folders to ship with the application, here
folder_01.source = qml/sbs2-HelloWorld
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
#folder_01.source = qml/sbs2-HelloWorld
#folder_01.target = qml
#DEPLOYMENTFOLDERS = folder_01
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
......@@ -16,16 +16,55 @@ QML_IMPORT_PATH =
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp \
mycallback.cpp
emotions.cpp \
mycallback.cpp \
emoactor.cpp
# Please do not modify the following two lines. Required for deployment.
include(qmlapplicationviewer/qmlapplicationviewer.pri)
qtcAddDeployment()
#include(qmlapplicationviewer/qmlapplicationviewer.pri)
#qtcAddDeployment()
include(./think-core/src/sbs2.pri)
HEADERS += \
mycallback.h
mycallback.h \
emotions.h \
emoactor.h
OTHER_FILES += \
android/src/org/kde/necessitas/ministro/IMinistro.aidl \
android/src/org/kde/necessitas/ministro/IMinistroCallback.aidl \
android/src/org/kde/necessitas/origo/QtApplication.java \
android/src/org/kde/necessitas/origo/QtActivity.java \
android/res/values-fr/strings.xml \
android/res/drawable-mdpi/icon.png \
android/res/values-de/strings.xml \
android/res/drawable-hdpi/icon.png \
android/res/values-zh-rCN/strings.xml \
android/res/values-ru/strings.xml \
android/res/values/libs.xml \
android/res/values/strings.xml \
android/res/values-nb/strings.xml \
android/res/values-ms/strings.xml \
android/res/values-pl/strings.xml \
android/res/values-zh-rTW/strings.xml \
android/res/values-pt-rBR/strings.xml \
android/res/values-fa/strings.xml \
android/res/drawable/logo.png \
android/res/drawable/icon.png \
android/res/values-it/strings.xml \
android/res/layout/splash.xml \
android/res/drawable-ldpi/icon.png \
android/res/values-nl/strings.xml \
android/res/values-es/strings.xml \
android/res/values-id/strings.xml \
android/res/values-el/strings.xml \
android/res/values-et/strings.xml \
android/res/values-ja/strings.xml \
android/res/values-ro/strings.xml \
android/res/values-rs/strings.xml \
android/version.xml \
android/AndroidManifest.xml
FORMS += \
uiMain.ui
uiEmoActor.ui
#ifndef EMOACTORCALLBACK_H
#define EMOACTORCALLBACK_H
#endif // EMOACTORCALLBACK_H
#include "emoactor.h"
emoactor::emoactor(QWidget *parent, Qt::WFlags f)
: QWidget(parent, f)
{
setupUi(this);
//create MyCallback object
MyCallback* myCallback = new MyCallback();
Sbs2EmotivDataReader* sbs2DataReader = Sbs2EmotivDataReader::New(myCallback,0);
Emotions emotions = new Emotions();
QObject::connect(myCallback, SIGNAL(arousalValue(double)), emotions, SLOT(compute_arousal(double)));
QObject::connect(myCallback, SIGNAL(valenceValue(double)), emotions, SLOT(compute_valence(double)));
QObject::connect(emotions, SIGNAL(giveEmotion(QString)), uiEmotiveLabel, SLOT(setText(QString)));
// Required to properly quit
QObject::connect(app.data(), SIGNAL(aboutToQuit()), sbs2DataReader, SLOT(aboutToQuit()));
}
#ifndef EMOACTOR_H
#define EMOACTOR_H
#include "emotions.h"
#include "ui_emoactor.h"
class emoactor : public QWidget, public Ui_Emoactor
{
public:
emoactor(QWidget *parent=0, Qt::WFlags f=0);
};
#endif // EMOACTOR_H
#include "emotions.h"
Emotions::Emotions()
{
arousal_max=UNSET_VALUE;
arousal_min=UNSET_VALUE;
valence_max=UNSET_VALUE;
valence_min=UNSET_VALUE;
max_diff_arousal=0;
max_diff_valence=0;
resetValues();
}
void Emotions::resetValues(){
arousal=UNSET_VALUE;
arousal_4s=UNSET_VALUE;
arousal_20s=UNSET_VALUE;
arousal_wait_4s=true;
arousal_wait_20s=true;
valence=UNSET_VALUE;
valence_4s=UNSET_VALUE;
valence_20s=UNSET_VALUE;
valence_wait_4s=true;
valence_wait_20s=true;
}
void Emotions::wait_arousal_4s(){
arousal_wait_4s=false;
}
void Emotions::wait_arousal_20s(){
arousal_wait_20s=false;
}
void Emotions::wait_valence_4s(){
valence_wait_4s=false;
}
void Emotions::wait_valence_20s(){
valence_wait_20s=false;
}
void Emotions::compute_arousal(double value){
if(arousal_wait_4s){
QTimer::singleShot(4000, this, SLOT(wait_arousal_4s()));
}else{
if(arousal_4s==UNSET_VALUE)
arousal_4s=value;
}
if(arousal_wait_20s){
QTimer::singleShot(20000, this, SLOT(wait_arousal_20s()));
}else{
if(arousal_20s==UNSET_VALUE)
arousal_20s=value;
}
if(arousal_4s!=-1 && arousal_20s!=-1){
double arousal_diff = abs(arousal_4s-arousal_20s);
if(max_diff_arousal < arousal_diff)
max_diff_arousal = arousal_diff;
arousal=(arousal_4s-arousal_20s)/max_diff_arousal;
if(arousal_max<arousal || arousal_max==UNSET_VALUE)
arousal_max=arousal;
if(arousal_min>arousal || arousal_max==UNSET_VALUE)
arousal_min=arousal;
computeEmotion();
}
}
void Emotions::compute_valence(double value){
if(valence_wait_4s){
QTimer::singleShot(4000, this, SLOT(wait_valence_4s()));
}else{
if(valence_4s==UNSET_VALUE)
valence_4s=value;
}
if(valence_wait_20s){
QTimer::singleShot(20000, this, SLOT(wait_valence_20s()));
}else{
if(valence_20s==UNSET_VALUE)
valence_20s=value;
}
if(valence_4s!=-1 && valence_20s!=-1){
double valence_diff = abs(valence_4s-valence_20s);
if(max_diff_valence < valence_diff)
max_diff_valence = valence_diff;
valence=(valence_4s-valence_20s)/max_diff_valence;
if(valence_max<valence || arousal_min==UNSET_VALUE)
valence_max=valence;
if(valence_min>valence || arousal_min==UNSET_VALUE)
valence_min=valence;
computeEmotion();
}
}
void Emotions::computeEmotion(){
QString emotion = *(new QString("error_novalue"));
//TODO : use better algorithm to suppress too high/min value
double arousal_center = (arousal_max+arousal_min)/2;
double arousal_mean_exited = arousal_max/2;
double arousal_mean_calm = arousal_min/2;
double valence_center = (valence_max+valence_min)/2;
double valence_mean_positive = valence_max/2;
double valence_mean_negative = valence_min/2;
if(valence!=UNSET_VALUE && arousal!=UNSET_VALUE){
if(arousal >= arousal_center
&& valence >= valence_center){
emotion="calm";
}else if(arousal < arousal_center
&& valence < valence_center){
emotion="sad";
}else if((arousal > arousal_center && arousal <= arousal_mean_exited)
&& valence < valence_center){
emotion="fear";
}else if((arousal > arousal_mean_exited)
&& valence < valence_center){
emotion="angry";
}else if((arousal > arousal_center && arousal <= arousal_mean_exited)
&& valence > valence_center){
emotion="joy";
}else if((arousal>arousal_mean_exited)
&& valence > valence_center){
emotion="surprise";
}
emit giveEmotion(emotion);
resetValues();
}
}
#ifndef EMOTIONS_H
#define EMOTIONS_H
#include <QString>
#include <QTimer>
#include <math.h>
#define UNSET_VALUE INFINITY
class Emotions : public QObject{
Q_OBJECT
public:
Emotions();
private:
double arousal;
double arousal_4s;
double arousal_20s;
double arousal_max;
double arousal_min;
bool arousal_wait_4s;
bool arousal_wait_20s;
double valence;
double valence_4s;
double valence_20s;
double valence_max;
double valence_min;
bool valence_wait_4s;
bool valence_wait_20s;
double max_diff_arousal;
double max_diff_valence;
double max_arousal;
double min_arousal;
double max_valence;
double min_valence;
void resetValues();
void computeEmotion();
public slots:
void compute_arousal(double value);
void compute_valence(double value);
void wait_arousal_4s();
void wait_arousal_20s();
void wait_valence_4s();
void wait_valence_20s();
signals:
void giveEmotion(QString emotion);
};
#endif // EMOTIONS_H
#include <QApplication>
#include <QtDeclarative>
//#include "qmlapplicationviewer.h"
//#include <QtDeclarative>
#include <QScopedPointer>
#include <mycallback.h>
#include <hardware/emotiv/sbs2emotivdatareader.h>
#include <mycallback.h>
Q_DECL_EXPORT int main(int argc, char *argv[])
{
QScopedPointer<QApplication> app(createApplication(argc, argv));
//QScopedPointer<QApplication> app(createApplication(argc, argv));
QScopedPointer<QApplication> app(new QApplication(argc, argv));
//set path where recorded data will be stored
qDebug() << "catalogPath: "<<Sbs2Common::setDefaultCatalogPath();
//set path where application data is stored
qDebug() << "rootAppPath: "<<Sbs2Common::setDefaultRootAppPath();
//create MyCallback object
MyCallback* myCallback = new MyCallback();
Sbs2EmotivDataReader* sbs2DataReader = Sbs2EmotivDataReader::New(myCallback,0);
//required for proper closing of the app
QObject::connect(app.data(), SIGNAL(aboutToQuit()), sbs2DataReader, SLOT(aboutToQuit()));
QObject::connect((QObject*)viewer.engine(), SIGNAL(quit()), app.data(), SLOT(quit()));
//QObject::connect((QObject*)viewer.engine(), SIGNAL(quit()), app.data(), SLOT(quit()));
return app->exec();
}
......@@ -14,7 +14,44 @@ void MyCallback::getData(Sbs2Packet *packet)
setPacket(packet);
if (currentPacketCounter%8 == 0)
emit timeTick8();
emit timeTick8();
emit valueSignal((QVariant)thisPacket->filteredValues["O2"]);
double f3=thisPacket->values["F3"];
double f4=thisPacket->values["F4"];
double af3=thisPacket->values["AF3"];
double af4=thisPacket->values["AF4"];
changeBand("alpha");
double f3_alpha=thisPacket->filteredValues["F3"];
double f4_alpha=thisPacket->filteredValues["F4"];
double af3_alpha=thisPacket->filteredValues["AF3"];
double af4_alpha=thisPacket->filteredValues["AF4"];
changeBand("beta");
double f3_beta=thisPacket->filteredValues["F3"];
double f4_beta=thisPacket->filteredValues["F4"];
double af3_beta=thisPacket->filteredValues["AF3"];
double af4_beta=thisPacket->filteredValues["AF4"];
double arousal = (f3_alpha/f3_beta + f4_alpha/f4_beta)/2;
// With bipolar measure :
double valence = ((f4-af4_alpha)/(f4-af4_beta) - (f3-af3_alpha)/(f3-af3_beta));
emit arousalValue(arousal);
emit valenceValue(valence);
}
void MyCallback::changeBand(QString name)
{
qDebug()<<"MyCallBack : change band to "<<name;
// Values found in emokit_dsp.c (see colorOfMind)
if (name.compare("alpha")){
lowFreq = 8;
highFreq = 12;
}else if (name.compare("beta")){
lowFreq = 16;
highFreq = 24;
}
sbs2DataHandler->turnFilterOn(lowFreq, highFreq, 32); //Need to understand what is "filterOrder" (last param.)
sbs2DataHandler->filter();
}
......@@ -6,14 +6,22 @@
class MyCallback : public Sbs2Callback
{
Q_OBJECT
private:
int lowFreq;
int highFreq;
QVector<double>* maxValues;
QVector<double>* minValues;
void changeBand(QString band);
public:
explicit MyCallback(QObject *parent = 0);
void getData(Sbs2Packet *packet);
signals:
void valueSignal(QVariant value);
public slots:
void arousalValue(double value);
void valenceValue(double value);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment