You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovaCNeurofeedbackScoreCounter.cpp 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include "ovaCNeurofeedbackScoreCounter.h"
  2. REGISTER_OBJECT_FACTORY(CNeurofeedbackScoreCounter, "ovaCNeurofeedbackScoreCounter");
  3. CNeurofeedbackScoreCounter::CNeurofeedbackScoreCounter(OMK::Controller& controller, const OMK::ObjectDescriptor& objectDesc)
  4. :OMK::SimulatedObject(controller, objectDesc)
  5. {
  6. }
  7. CNeurofeedbackScoreCounter::~CNeurofeedbackScoreCounter()
  8. {
  9. }
  10. void CNeurofeedbackScoreCounter::init()
  11. {
  12. registerForSignal(g_sVrpnButtonStateUpdate);
  13. registerForSignal(g_sVrpnAnalogStateUpdate);
  14. m_shouldCare = false;
  15. m_wasZero = false;
  16. m_score = 0;
  17. m_oScale[0] = 1;
  18. m_oScale[1] = 1;
  19. m_oScale[2] = 1;
  20. m_oScaleTarget[0] = 1;
  21. m_oScaleTarget[1] = 1;
  22. m_oScaleTarget[2] = 1;
  23. sendValuedEvent("OpenViBE_score_counter", g_sManipulate3DEntity_SetScale, ScaleType(m_oScale));
  24. }
  25. void CNeurofeedbackScoreCounter::compute()
  26. {
  27. double speed = .01;
  28. m_oScale = (float)speed * m_oScaleTarget + float(1 - speed) * m_oScale;
  29. sendValuedEvent("OpenViBE_score_counter", g_sManipulate3DEntity_SetScale, ScaleType(m_oScale));
  30. }
  31. bool CNeurofeedbackScoreCounter::processEvent(OMK::Event* pEvent)
  32. {
  33. if (pEvent->eventId == g_sVrpnButtonStateUpdate)
  34. {
  35. VrpnButtonStateEvent* event = dynamic_cast <VrpnButtonStateEvent*>(pEvent);
  36. if (event)
  37. {
  38. const VrpnButtonState& vrpnButtonState = event->value;
  39. if (vrpnButtonState.first<int(sizeof(m_button) / sizeof(m_button[0])))
  40. {
  41. m_button[vrpnButtonState.first] = (vrpnButtonState.second ? true : false);
  42. if (vrpnButtonState.first == 3)
  43. {
  44. if (m_button[vrpnButtonState.first])
  45. {
  46. m_shouldCare = true;
  47. #ifdef _DEBUG_
  48. std::cout << "Should care\n";
  49. #endif
  50. }
  51. else
  52. {
  53. m_shouldCare = false;
  54. #ifdef _DEBUG_
  55. std::cout << "Should not care\n";
  56. #endif
  57. }
  58. }
  59. }
  60. }
  61. return true;
  62. }
  63. if (pEvent->eventId == g_sVrpnAnalogStateUpdate)
  64. {
  65. VrpnAnalogStateEvent* event = dynamic_cast <VrpnAnalogStateEvent*>(pEvent);
  66. if (event)
  67. {
  68. const VrpnAnalogState& vrpnAnalogState = event->value;
  69. auto it = vrpnAnalogState.begin();
  70. if (m_wasZero)
  71. {
  72. if (*it >= 1E-3)
  73. {
  74. if (m_shouldCare)
  75. {
  76. m_oScaleTarget[1] += .2;
  77. m_score += 1;
  78. m_shouldCare = false;
  79. std::cout << "NeW SCoRe : " << m_score << "\n";
  80. }
  81. m_wasZero = false;
  82. }
  83. }
  84. else
  85. {
  86. if (*it < 1E-3)
  87. {
  88. m_wasZero = true;
  89. }
  90. }
  91. }
  92. }
  93. return false;
  94. }