J
J
Julia2016-12-23 20:54:16
Programming
Julia, 2016-12-23 20:54:16

How to write a class for Balance Board?

Hi all.
I come to you for advice.
I have a Balance Board , I can get values ​​​​from it all the time, but only from a while loop. What is not correct, but only for the sake of the test is written.
I want clear business to organize a code on another. What would the class work in parallel. For example, I get values ​​and display them in Qt Widget and so on.
The first thing that comes to mind is, of course, Thread.
But I don't know what to do right? What would be your advice.
To somehow catch the changes ..
I hope you understand me

#include "b_board.h"
#include "wiiuse.h"
#include "qdebug.h"

BalanceBoard::BalanceBoard()
{
  initializeBoard();
}

BalanceBoard::~BalanceBoard()
{

}

bool BalanceBoard::initializeBoard()
{
   
   
  wiimote** wiimotes = wiiuse_init(1);
 
  int found = wiiuse_find(wiimotes, 1, 60);
  if (found != 1){
    return false;
  }
  int connected = wiiuse_connect(wiimotes, 1);
  if (connected != 1){
    return false;
  } 
   
  b_work = true;


  while (b_work)
  {
    if (wiiuse_poll(wiimotes, 1))
    {

      switch (wiimotes[0]->event) {
      case WIIUSE_EVENT:
        // generic event occured 
        handle_event(wiimotes[0]);
      case WIIUSE_STATUS:
        break;

      case WIIUSE_DISCONNECT:

      case WIIUSE_UNEXPECTED_DISCONNECT:
        break;

      case WIIUSE_READ_DATA:
        break;

      case WIIUSE_WII_BOARD_CTRL_INSERTED:

        break;

      case WIIUSE_WII_BOARD_CTRL_REMOVED:
        
        break;

      default:
        break;
      }

    }

  }
  return true;

}

void BalanceBoard::work()
{

}


void BalanceBoard::handle_event(struct wiimote_t* wm)
{
  //show events specific to supported expansions
  if (wm->exp.type == EXP_WII_BOARD){
    struct wii_board_t* wb = (wii_board_t*)&wm->exp.wb;
    float total = wb->tl + wb->tr + wb->bl + wb->br; //weight
    float x = ((wb->tr + wb->br) / total) * 2 - 1;

    float y = ((wb->tl + wb->tr) / total) * 2 - 1;
    qDebug() << "Weight: " << total;

    qDebug() << "Interpolated weight:: " << wb->tl << "  " << wb->tr << "  " << wb->bl << "  " << wb->br;

    qDebug() << "Raw: " << total << "  " << wb->rtl << "  " << wb->rtr << "  " << wb->rbl << "  " << wb->rbr;
    
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel K, 2016-12-23
@PavelK

Why not convert to signal slots? If, nevertheless, the value comes constantly, then yes, to take it out in a separate stream.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question