mycallback.cpp 1.85 KB
Newer Older
1 2 3 4 5
#include "mycallback.h"

MyCallback::MyCallback(QObject *parent) :
    Sbs2Callback(parent)
{
6
    filterReady=0;
7 8 9 10 11 12 13 14 15 16
}

/**
  Reimplemented callback method. This method sees single packets and handles them.
  */
void MyCallback::getData(Sbs2Packet *packet)
{
    //set current packet, increment counters
    setPacket(packet);

17
    if (currentPacketCounter%8 == 0){
18
        emit timeTick8();
19
    }
20

21 22 23 24
    if(filterReady==0){
        initFilter();
    }
    sbs2DataHandler->filter2bands();
25

26
    // alpha band
27 28 29 30 31
    double f3_alpha=thisPacket->filteredValues["F3"];
    double f4_alpha=thisPacket->filteredValues["F4"];
    double af3_alpha=thisPacket->filteredValues["AF3"];
    double af4_alpha=thisPacket->filteredValues["AF4"];

32 33 34 35 36
    // beta band
    double f3_beta=thisPacket->filteredValues2ndBand["F3"];
    double f4_beta=thisPacket->filteredValues2ndBand["F4"];
    double af3_beta=thisPacket->filteredValues2ndBand["AF3"];
    double af4_beta=thisPacket->filteredValues2ndBand["AF4"];
37

38 39 40
    // Goal is to use af3/af4 because they are hairless copmared to f3/f4
    // So we'll apply same idea than colorOfMind but we use sensors otherwise

41
    // colorOfMind : (front beta power)/(front alpha power)
42
    double arousal = (af3_beta/af3_alpha + af4_beta/af4_alpha)/2;
43
    // colorOfMind : Valence = (left beta power)/(left alpha power) – (right beta power)/(right alpha power)
44
    double valence = (af3_beta/af3_alpha - af4_beta/af4_alpha);
45

46
    emit arousalValence(arousal,valence);
47 48
}

49 50 51 52 53 54 55 56 57 58 59 60
void MyCallback::initFilter(){
    lowFreq = 8;
    highFreq = 13;
    lowFreq2nd = 13;
    highFreq2nd = 30;

    qDebug() << "Mycallback : turn filter on...";
    sbs2DataHandler->turnFilterOn2bands(lowFreq, highFreq, 32, lowFreq2nd, highFreq2nd, 32);
    qDebug() << "Mycallback : filternow...";
    sbs2DataHandler->filter2bands();
    qDebug() << "Mycallback : filter activated !";
    filterReady=1;
61
}