Example #1
0
bool KEventAdapterChain::transform(const EventWrapper& input, EventWrapper& output)
{
	char buf1[512];
	char buf2[512];
	
	bool done = false;
	const EventWrapper* pi = &input;
	EventWrapper my1(0, &buf1, sizeof(buf1));
	EventWrapper my2(0, &buf2, sizeof(buf2));
	EventWrapper* po = &my1;

	Node* node = m_list.begin();
	while(node)
	{
		if(node->adapter->transform(*pi, *po))
		{
			pi = po;
			po = (po == &my1) ? &my2 : &my1;
			done = TRUE;
		}
		node = m_list.next(node);
	}
	
	if(done)
	{
		output.evt = pi->evt;
		output.len = pi->len;
		memcpy((void*)output.data, pi->data, pi->len);
	}

	return done;
}
Example #2
0
MainWindow::MainWindow(QWidget* _parent)
  :QMainWindow(_parent),
    m_settings(new Settings()),
    m_ui(new Ui::MainWindow()),
    m_copterCtrl(),
    m_tcpServer(),
    m_tcpConnection(),
    m_accelerometerInputFd(-1),
    m_accelerometerInputNotifier(0),
    m_lastTiltX(0),
    m_lastTiltY(0)
{
  m_ui->setupUi(this);
  const auto s_ctrl_path = m_settings->getControlPath();
  QSharedPointer<CopterMotor> mx1(new CopterMotor(m_settings, s_ctrl_path+"ehrpwm.0/pwm/ehrpwm.0:0/duty_percent", m_ui->motor_x1));
  QSharedPointer<CopterMotor> mx2(new CopterMotor(m_settings, s_ctrl_path+"ehrpwm.0/pwm/ehrpwm.0:1/duty_percent", m_ui->motor_x2));
  QSharedPointer<CopterMotor> my1(new CopterMotor(m_settings, s_ctrl_path+"ehrpwm.1/pwm/ehrpwm.1:0/duty_percent", m_ui->motor_y1));
  QSharedPointer<CopterMotor> my2(new CopterMotor(m_settings, s_ctrl_path+"ehrpwm.1/pwm/ehrpwm.1:1/duty_percent", m_ui->motor_y2));
  QSharedPointer<CopterAxis>  m_axisX(new CopterAxis(mx1, mx2));
  QSharedPointer<CopterAxis>  m_axisY(new CopterAxis(my1, my2));
  m_copterCtrl = new CopterCtrl(m_settings, m_axisX, m_axisY, m_ui->motor_all);

  m_tcpServer.listen(QHostAddress::Any, m_settings->getTcpPort());
  connect(&m_tcpServer, SIGNAL(newConnection()), this, SLOT(onConnection()));

  auto const s_accel_input_path = m_settings->getAccelInputPath();
  m_accelerometerInputFd = ::open(s_accel_input_path.toLatin1().data(), O_SYNC, O_RDONLY);
  if (m_accelerometerInputFd == -1)
    qDebug() << "Cannot open accelerometer input file " << s_accel_input_path << ", reason: " << errno;

  m_accelerometerInputNotifier = new QSocketNotifier(m_accelerometerInputFd, QSocketNotifier::Read, this);
  connect(m_accelerometerInputNotifier, SIGNAL(activated(int)), this, SLOT(onAccelerometerRead()));
  m_accelerometerInputNotifier->setEnabled(true);

  m_copterCtrl->adjustPower(0);

  showFullScreen();
  showMaximized();
}