bool CA3mLgm::open() { if (_isConnected) return true; // init values busyCounter = 0; status = FREE; // get the encrypted A3M protocol QString script = getScript(); if(script != "-1") { // check the validity of the script QScriptValue result = engine.evaluate(script); if(engine.hasUncaughtException()) { QString xml = CXmlFactory::deviceEvent(QString::number(id), "1017", "A3M script protocol for LGM error (line:" + QString::number(engine.uncaughtExceptionLineNumber()) + ","+ result.toString() + ")"); emit deviceEvent(xml); return false; } CHRstcpipC* parent = (CHRstcpipC*) deviceParent; socket = parent->getSocket(); _isConnected = true; // timer used when we send a command and to check if the response is not received timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(sendBufferContent())); // get the reader serial number sendCmd(GET_SER_NUM); // get the reader firmware version sendCmd(GET_VER_NUM); QByteArray p; p.resize(1); p[0] = 0x00; // set the initial state for the LED sendCmd(SET_LED, p); // set the reader in the wiegand mode sendCmd(CMD_WIEGAND_FORMAT); return true; } return false; }
void DeviceManager::start() { connect(&chargeTimer, SIGNAL(timeout()), this, SLOT(chargeTimerHit())); chargeTimer.setInterval(10000); chargeTimer.start(); // Connect udev listener, fire a chargeTimerHit (implicit device detect), if hit udevListener = new UdevListener(); connect(udevListener, SIGNAL(deviceEvent()), this, SLOT(chargeTimerHit())); // Connect movescount Id feedback to local handler connect(movesCount, SIGNAL(logMoveID(QString,QDateTime,QString)), this, SLOT(logMovescountID(QString,QDateTime,QString))); }
int ConnectionWaiter::exec() { connect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(deviceEvent())); connect(USBMonitor::instance(), SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(deviceEvent())); connect(&timer, SIGNAL(timeout()), this, SLOT(perform())); timer.start(1000); emit timeChanged(0); eventLoop.exec(); return result; }
void UdevListener::fdActivated(int fd) { struct udev_device *device; const char *vendorId; if (fd == this->fd) { device = udev_monitor_receive_device(mon); if (device != NULL) { // Check vendor ID, if it matches Suunto, we issue a new device scan vendorId = udev_device_get_sysattr_value(device, "idVendor"); if (vendorId != NULL && strcmp(vendorId, SUUNTO_USB_VENDOR_ID) == 0) { emit deviceEvent(); } udev_device_unref(device); } } }
void X11Device::processEvent(const XEvent &event) { DeviceEvent deviceEvent(ENoEvent); X11Session *session = static_cast<X11Session *>(getSession()); if (m_callbacks.size() == 0) return; switch (event.type) { case ClientMessage: /* The window close button pressed */ if ((event.xclient.format == 32) && ((unsigned) event.xclient.data.l[0] == m_deleteWindow)) { deviceEvent.setType(EQuitEvent); } break; case FocusIn: /* Deactivate auto-repeat */ XAutoRepeatOff(session->m_display); deviceEvent.setType(EGainFocusEvent); m_modifierState = 0; m_buttonState = 0; break; case FocusOut: /* Reactivate auto-repeat */ XAutoRepeatOn(session->m_display); deviceEvent.setType(ELoseFocusEvent); m_modifierState = 0; m_buttonState = 0; break; case ButtonPress: deviceEvent.setType(EMouseButtonDownEvent); translateMouse(event, deviceEvent); m_buttonState |= deviceEvent.getMouseButton(); break; case ButtonRelease: deviceEvent.setType(EMouseButtonUpEvent); translateMouse(event, deviceEvent); m_buttonState &= ~deviceEvent.getMouseButton(); break; case MotionNotify: { deviceEvent.setType(m_buttonState == 0 ? EMouseMotionEvent : EMouseDragEvent); translateMouse(event, deviceEvent); deviceEvent.setMouseButton(m_buttonState); if (m_grab) warpMouse(Point2i(getSize().x / 2, getSize().y/2)); int xpos = deviceEvent.getMousePosition().x; int ypos = deviceEvent.getMousePosition().y; if (xpos > m_size.x || xpos < 0 || ypos > m_size.y || ypos < 0) return; } break; case KeyPress: if (translateKeyboard(event, deviceEvent)) { deviceEvent.setType(EKeyDownEvent); int special = deviceEvent.getKeyboardSpecial(); /* Update the current modifier state */ if (special == EKeyLShift || special == EKeyRShift) { m_modifierState |= EShiftModifier; } else if (special == EKeyLAlt || special == EKeyRAlt) { m_modifierState |= EAltModifier; } else if (special == EKeyLControl || special == EKeyRControl) { m_modifierState |= EControlModifier; } deviceEvent.setKeyboardModifiers(m_modifierState); } break; case KeyRelease: if (translateKeyboard(event, deviceEvent)) { deviceEvent.setType(EKeyUpEvent); int special = deviceEvent.getKeyboardSpecial(); /* Update the current modifier state */ if (special == EKeyLShift || special == EKeyRShift) { m_modifierState = m_modifierState & (~EShiftModifier); } else if (special == EKeyLAlt || special == EKeyRAlt) { m_modifierState = m_modifierState & (~EAltModifier); } else if (special == EKeyLControl || special == EKeyRControl) { m_modifierState = m_modifierState & (~EControlModifier); } deviceEvent.setKeyboardModifiers(m_modifierState); } break; case MapNotify: case UnmapNotify: m_modifierState = 0; break; case ConfigureNotify: { Vector2i size(event.xconfigure.width, event.xconfigure.height); if (m_size != size) { m_size = size; deviceEvent.setType(EResizeEvent); } } break; case ReparentNotify: case Expose: break; default: Log(EWarn, "Unknown event %i received", event.type); } if (deviceEvent.getType() != ENoEvent) fireDeviceEvent(deviceEvent); }
void ConnectionWaiter::quit() { disconnect(USBMonitor::instance(), SIGNAL(deviceDiscovered(USBPortInfo)), this, SLOT(deviceEvent())); disconnect(USBMonitor::instance(), SIGNAL(deviceRemoved(USBPortInfo)), this, SLOT(deviceEvent())); timer.stop(); eventLoop.exit(); }