Beispiel #1
0
/*
 * Read data from the input device
 */
void Joystick::readPendingInputData(void)
{
  struct js_event *js;
  QByteArray buf;

  //qDebug() << "in" << __FUNCTION__ << ", data size: " << inputDevice.size();

  buf = inputDevice.readAll();
  if (buf.length() < (int)(sizeof(struct js_event))) {
	qWarning("Too few bytes read: %d", buf.length());
	return;
  }

  js = (struct js_event *)buf.data();

  //qDebug() << "Joystick: type: " << js->type << "number: " << js->number << "value: " << js->value;

  // Handle button press
  if (js->type == 1) {
	emit(buttonChanged(js->number, static_cast<quint16>(js->value)));
	return;
  }

  // Handle axis movement
  if (js->type == 2) {
	quint16 value = (quint16)(js->value / 256.0 + 128);
	emit(axisChanged(js->number, value));
	return;
  }
}
Beispiel #2
0
void MainWindow::setWorld(World* world) {
    timer = new QTimer(this);
    this->world = world;

    pushButtons = new QPushButton*[world->getHeight() * world->getWidth()];
    QPushButton* pushButton;

    for (int i =0;i<world->getHeight();i++)
    {
        for(int j=0;j < world->getWidth();j++)
        {
            pushButton = new QPushButton(ui->widget);
            pushButton->setGeometry(i*BUTTON_HEIGHT, j*BUTTON_WIDTH, BUTTON_HEIGHT, BUTTON_WIDTH);
            setButtonColor(pushButton, QString::fromStdString(deathColor));

            pushButton->setProperty("cellPositionX", QVariant(i));
            pushButton->setProperty("cellPositionY", QVariant(j));

            QObject::connect(pushButton, SIGNAL(clicked()), this, SLOT(buttonChanged()));
            pushButtons[i * world->getHeight() + j] = pushButton;
        }
    }

    QObject::connect(ui->pushButtonStep, SIGNAL(clicked()), this, SLOT(doStepWorld()));
    QObject::connect(ui->pushButtonClear, SIGNAL(clicked()), this, SLOT(btnClear()));
    QObject::connect(ui->pushButtonRun, SIGNAL(clicked()), this, SLOT(btnRun()));
    QObject::connect(ui->pushButtonStop, SIGNAL(clicked()), this, SLOT(btnStop()));
    QObject::connect(ui->pushButtonRand, SIGNAL(clicked()), this, SLOT(btnRand()));
    setWindowTitle("The World of Empress");
    world->doStep();
    world->doStep();
    updateView();
}
Beispiel #3
0
void ButtonRead::run()
{
    char key_value[8] = {0,0,0,0,0,0,0,0};
    char pre_state[4] = {0,0,0,0};
    int i = 0;
    int number = 0, value = 0;

    while(true){
        this->is.read(key_value, 8);
        for(i=0; i<4; ++i){
            /* Check state */
            if(key_value[i*2] != pre_state[i]){
                /* State changed, print message */
                pre_state[i] = key_value[i*2];
                if(key_value[i*2 + 1] == '0'){
                    value = 2;
                }else{
                    value = 1;
                }
                number = i;
                emit buttonChanged(number, value);
            }
        }
    }
}
Beispiel #4
0
void TraktorF1MK2::processButtons(const Transfer& input_)
{
  bool shiftPressed(isButtonPressed(input_, Button::Shift));
  Device::Button changedButton(Device::Button::Unknown);
  bool buttonPressed(false);

  for (int i = 0; i < kF1MK2_buttonsDataSize - 1; i++) // Skip the last byte (encoder value)
  {
    for (int k = 0; k < 8; k++)
    {
      uint8_t btn = (i * 8) + k;
      Button currentButton(static_cast<Button>(btn));
      if (currentButton == Button::Shift)
      {
        continue;
      }
      buttonPressed = isButtonPressed(input_, currentButton);
      if (buttonPressed != m_buttonStates[btn])
      {
        m_buttonStates[btn] = buttonPressed;
        changedButton = deviceButton(currentButton);
        if (changedButton != Device::Button::Unknown)
        {
          if (currentButton >= Button::Pad8 && currentButton <= Button::Pad9)
          {
            keyChanged(btn, buttonPressed ? 1.0 : 0.0, shiftPressed);
          }
          else
          {
            buttonChanged(changedButton, buttonPressed, shiftPressed);
          }
        }
      }
    }
  }

  // encoder
  uint8_t currentValue = input_.data()[kF1MK2_buttonsDataSize];
  if (currentValue != m_encoderValue)
  {
    bool valueIncreased = ((static_cast<uint8_t>(m_encoderValue) < currentValue)
                            || ((m_encoderValue == 0xff) && (currentValue == 0x00)))
                          && (!((m_encoderValue == 0x0) && (currentValue == 0xff)));
    m_encoderValue = currentValue;
    encoderChanged(0, valueIncreased, shiftPressed);
  }

  // pots/faders
  for (uint8_t potIndex = 0, i = kF1MK2_buttonsDataSize + 1; potIndex < 8; i += 2, potIndex++)
  {
    unsigned value = (input_.data()[i]) | (input_.data()[i + 1] << 8);
    if (m_potentiometersValues[potIndex] != value)
    {
      m_potentiometersValues[potIndex] = value;
      controlChanged(potIndex, value / 1024.0, shiftPressed);
    }
  }
}
Beispiel #5
0
void ofxGamepadLinux::update() {
	struct js_event event;
	while (read(fd, &event, sizeof(struct js_event)) > 0) {

	    /* see what to do with the event */
	    switch (event.type & ~JS_EVENT_INIT) {
	      case JS_EVENT_AXIS:
		axisChanged(event.number, event.value);
		break;
	      case JS_EVENT_BUTTON:
		buttonChanged(event.number, event.value);
		break;
	    }
	}

}
Beispiel #6
0
void ActionButton::onActionChanged()
{
	if (FAction)
	{
		setIcon(FAction->icon());
		setText(FAction->text());
		setMenu(FAction->menu());
	}
	else
	{
		setIcon(QIcon());
		setText(QString::null);
		setMenu(NULL);
	}
	emit buttonChanged();
}
Beispiel #7
0
void AMGenericLinuxJoystick::onJoystickEvents(QVector<AMGenericLinuxJoystickEvent> events)
{
    for(int i=0,cc=events.count(); i<cc; i++) {
        const AMGenericLinuxJoystickEvent& event = events.at(i);

        if ((event.type & ~JS_EVENT_INIT) == JS_EVENT_BUTTON) {
            bool newState = (bool)event.value;
            if(buttonStates_.at(event.number) != newState)
                emit buttonChanged(event.number, (buttonStates_[event.number] = newState), event.time);
        }
        if((event.type & ~JS_EVENT_INIT) == JS_EVENT_AXIS) {
            int newValue = event.value;
            if(axisPositions_.at(event.number) != newValue)
                emit axisChanged(event.number, (axisPositions_[event.number] = newValue), event.time);
        }
    }
}
void MouseButton::wheelEvent(QWheelEvent *event)
{

    if (!mouseGrabber()) {
        KPushButton::wheelEvent(event);
    }   else {
        const Button oldButton = m_button;
        releaseMouse();
        if (event->delta() > 0) {
            setButton(WheelUp);
        } else {
            setButton(WheelDown);
        }
        setChecked(false);
        emit buttonChanged(oldButton, m_button);
    }

}
void MouseConfig::selectionChanged()
{
    Q3ListViewItem *item = lstCmd->currentItem();
    if (item == NULL){
        lblCmd->setText("");
        cmbButton->setCurrentItem(0);
        cmbButton->setEnabled(false);
        return;
    }
    lblCmd->setText(item->text(0));
    int n = ShortcutsPlugin::stringToButton(item->text(1).latin1());
    if (n == 0)
        chkAlt->setChecked((n & Qt::AltButton) != 0);
    chkCtrl->setChecked((n & Qt::ControlButton) != 0);
    chkShift->setChecked((n & Qt::ShiftButton) != 0);
    cmbButton->setEnabled(true);
    cmbButton->setCurrentItem(n);
    buttonChanged(0);
}
void MouseButton::mouseReleaseEvent(QMouseEvent *event)
{

    if (!mouseGrabber()) {
        KPushButton::mouseReleaseEvent(event);
    } else {
        releaseMouse();
        const Button oldButton = m_button;
        switch (event->button()) {
        case Qt::NoButton: setButton(NoButton); break;
        case Qt::LeftButton: setButton(LeftButton); break;
        case Qt::RightButton: setButton(RightButton); break;
        case Qt::MidButton: setButton(MiddleButton); break;
        case Qt::XButton1: setButton(SpecialButton1); break;
        case Qt::XButton2: setButton(SpecialButton2); break;
        default: setButton(NoButton); break;
        }
        setChecked(false);
        emit buttonChanged(oldButton, m_button);
    }

}
Beispiel #11
0
void ProgramManager::programReady(){
  // updateButtons(getProgramVector()->buttons);
  //   static uint16_t buttons = programVector->buttons;
  //  if(buttons & (1<<PUSHBUTTON) != getProgramVector()->buttons & (1<<PUSHBUTTON))
  //    togglePushButton();
  if(buttons != programVector->buttons){
    for(int i=1; i<NOF_BUTTONS; ++i) // skip bypass button
      if((buttons & (1<<i)) != (programVector->buttons & (1<<i)))
  	buttonChanged(i, programVector->buttons & (1<<i));
  }
#ifdef DEBUG_DWT
  programVector->cycles_per_block = *DWT_CYCCNT;
  // getProgramVector()->cycles_per_block = *DWT_CYCCNT;
    // (*DWT_CYCCNT + getProgramVector()->cycles_per_block)>>1;
#endif /* DEBUG_DWT */
#ifdef DEBUG_AUDIO
  clearPin(GPIOC, GPIO_Pin_5); // PC5 DEBUG
#endif

#ifdef AUDIO_TASK_SUSPEND
  vTaskSuspend(xProgramHandle);
#elif defined AUDIO_TASK_SEMAPHORE
  xSemaphoreTake(xSemaphore, 0);
#elif defined AUDIO_TASK_YIELD
  taskYIELD(); // this will only suspend the task if another is ready to run
#elif defined AUDIO_TASK_DIRECT
  while(audioStatus != AUDIO_READY_STATUS);
  audioStatus = AUDIO_PROCESSING_STATUS;
#else
  #error "Invalid AUDIO_TASK setting"
#endif
#ifdef DEBUG_DWT
  *DWT_CYCCNT = 0; // reset the performance counter
#endif /* DEBUG_DWT */
#ifdef DEBUG_AUDIO
  setPin(GPIOC, GPIO_Pin_5); // PC5 DEBUG
#endif
  buttons = programVector->buttons;
}
Beispiel #12
0
/**
 * \brief Returns true when a valid button is triggered
 *
 * @param button
 * @param joy
 * @return
 */
bool TeleopNaoJoy::buttonTriggered(int button, const Joy::ConstPtr& joy) const {
    return (buttonPressed(button, joy) && buttonChanged(button, joy, m_previousJoystick));
}