Esempio n. 1
0
void sndDialog::slotSave()
{
    QString tmp;
    tmp.setNum(comboSound->currentIndex());
    system("sysctl hw.snd.default_unit=" + tmp.toLatin1());

    // Try to set the default pulseaudio sink as well
    QString username = QString::fromLocal8Bit(getenv("LOGNAME"));
    system("su " + username.toLatin1() + " -c \"pactl set-default-sink " + tmp.toLatin1() + "\"");

    pcbsd::Utils::setConfFileValue( "/etc/sysctl.conf", "hw.snd.default_unit=", "hw.snd.default_unit=" + tmp );
    refreshDevices();
}
Esempio n. 2
0
/**
 * @brief connect all buttons of the ui
 * @return
 *      void
 */
void DLDConfigureOB::connectSignals ()
{
	// connect menu actions
	connect(mainWindow.actionQuit,		SIGNAL(triggered ()), this, SLOT(close ()));
	connect(mainWindow.actionRefresh,	SIGNAL(triggered ()), this, SLOT(refreshDevices ()));
	connect(mainWindow.actionPreferences,	SIGNAL(triggered ()), this, SLOT(showPreferences ()));
	connect(mainWindow.actionOpenBeaconConfiguratorHelp, SIGNAL(triggered ()), this, SLOT(showHelp()));
	connect(mainWindow.actionAboutQt,	SIGNAL(triggered ()), qApp, SLOT(aboutQt ()));
	connect(mainWindow.actionAboutOpenBeacon,SIGNAL(triggered ()), this, SLOT(aboutOpenBeacon ()));

	// connect main Window buttons with methods
	connect(mainWindow.selectFileButton,	SIGNAL(clicked ()), this, SLOT(selectFlashImage ()));
	connect(mainWindow.flashButton,		SIGNAL(clicked ()), this, SLOT(flashDevice ()));
	connect(mainWindow.refreshButton,	SIGNAL(clicked ()), this, SLOT(refreshDevices ()));
	connect(mainWindow.executeButton,	SIGNAL(clicked ()), this, SLOT(executeCommand ()));
	connect(mainWindow.clearButton,		SIGNAL(clicked ()), this, SLOT(clearConsole ()));

	// connect box signals
	connect(mainWindow.commandCombo,	SIGNAL(highlighted (int)), this, SLOT(commandHighlighted (int)));
	connect(mainWindow.commandCombo,	SIGNAL(currentIndexChanged (int)), this, SLOT(updateCommandBoxStatusTip (int)));
	connect(mainWindow.deviceCombo,		SIGNAL(currentIndexChanged (int)), this, SLOT(updateGroupBoxVisibility (int)));
	connect(mainWindow.deviceCombo,		SIGNAL(activated (int)), this, SLOT(openNewDevice (int)));

	// connect device
	connect(device,				SIGNAL(newData (QString)), this, SLOT(receivedNewData (QString)));
	connect(device,				SIGNAL(writeFailed ()), this, SLOT(writeFailed ()));

	// connect internal signals
	connect(this,		SIGNAL(deviceSelected (bool, bool)),	this, SLOT(endisableGroupBox (bool, bool)));
	connect(this,		SIGNAL(commandListChanged ()),		this, SLOT(refillCommandList ()));
	connect(this,		SIGNAL(devicepathsChanged ()),		this, SLOT(refreshDevices ()));
	connect(refreshTimer,	SIGNAL(timeout()),			this, SLOT(refreshDevices ()));
	connect(this,		SIGNAL(logFileChanged (QString)),	this, SLOT(changeLogFile (QString)));
	connect(batchProcess,	SIGNAL(readyReadStandardOutput ()),	this, SLOT(addCharToConsole ()));
	connect(batchProcess,	SIGNAL(error (QProcess::ProcessError)),	this, SLOT(printProcessError (QProcess::ProcessError)));
	connect(batchProcess,	SIGNAL(finished (int, QProcess::ExitStatus)),this, SLOT(processFinished (int, QProcess::ExitStatus)));
}
Esempio n. 3
0
void IpodHeader::setNoIpod()
{
    m_messageLabel->setText( i18n("<p align=\"center\"><b>No iPod was detected</b></p>" ) );

    QPalette p = palette();
    p.setColor( QPalette::Window, QColor(147, 18, 18) );
    p.setColor( QPalette::WindowText, Qt::white );
    setPalette( p );

    m_button->setText( i18n( "Refresh" ) );
    m_button->show();

    m_button->disconnect();

    connect(m_button, SIGNAL(clicked()),
            this, SIGNAL(refreshDevices()));
}
Esempio n. 4
0
/**
 * @brief constructor for OpenBeacon Configurator
 * @param logLevel the logLevel which should be used for the application
 * @return
 *      void
 */
DLDConfigureOB::DLDConfigureOB (int logLevel)
{
// settings
	settings = new QSettings ("DLD", "OpenBeacon Configurator");
	int xPos = settings->value("xPos", 10).toInt ();
	int yPos = settings->value("yPos", 10).toInt ();
	int windowWidth = settings->value("windowWidth", 465).toInt ();
	int windowHeight = settings->value("windowHeight", 531).toInt ();
	showRX = settings->value("showRX", false).toBool ();

// set logging
	QString logFile = settings->value("logFile", "").toString ();
	log = new DLDLog();
	log->setLogLevel (logLevel);
	if (!logFile.isEmpty())
	{
		log->setLogType (DLDLog::LOG_TO_FILE);
		log->setLogFile (logFile);
		log->infoLog ("logging to file.");
	} else
		log->infoLog ("logging to console.");

// device
	device = new OpenBeaconCommunication (log);

// ui
	mainWindow.setupUi (this);
	setGeometry (xPos, yPos, windowWidth, windowHeight);

	endisableGroupBox (false, false);
	refreshTimer = new QTimer (this);
	refreshTimer->start (settings->value("DeviceRefreshRate", 5).toInt () * 1000);

// flashing
	batchProcess = new QProcess (this);
	batchProcess->setReadChannel (QProcess::StandardOutput);

	connectSignals ();

	refillCommandList ();
	refreshDevices ();
}
Esempio n. 5
0
 void System::onPnPUnplug( const GUID& deviceClass, const wideString& devicePath )
 {
   // Refresh all currently connected devices,
   // since IDirectInput8::FindDevice doesn't do jack shit
   refreshDevices();
 }
Esempio n. 6
0
/**
 * Construct a new sound preferences pane. Initializes and populates all the
 * all the controls to the values obtained from SoundManager.
 */
DlgPrefSound::DlgPrefSound(QWidget* pParent, SoundManager* pSoundManager,
                           PlayerManager* pPlayerManager, UserSettingsPointer pConfig)
        : DlgPreferencePage(pParent),
          m_pSoundManager(pSoundManager),
          m_pPlayerManager(pPlayerManager),
          m_pConfig(pConfig),
          m_settingsModified(false),
          m_bLatencyChanged(false),
          m_bSkipConfigClear(true),
          m_loading(false) {
    setupUi(this);

    connect(m_pSoundManager, SIGNAL(devicesUpdated()),
            this, SLOT(refreshDevices()));

    apiComboBox->clear();
    apiComboBox->addItem(tr("None"), "None");
    updateAPIs();
    connect(apiComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(apiChanged(int)));

    sampleRateComboBox->clear();
    foreach (unsigned int srate, m_pSoundManager->getSampleRates()) {
        if (srate > 0) {
            // no ridiculous sample rate values. prohibiting zero means
            // avoiding a potential div-by-0 error in ::updateLatencies
            sampleRateComboBox->addItem(tr("%1 Hz").arg(srate), srate);
        }
    }
    connect(sampleRateComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(sampleRateChanged(int)));
    connect(sampleRateComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(updateAudioBufferSizes(int)));
    connect(audioBufferComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(audioBufferChanged(int)));

    deviceSyncComboBox->clear();
    deviceSyncComboBox->addItem(tr("Default (long delay)"));
    deviceSyncComboBox->addItem(tr("Experimental (no delay)"));
    deviceSyncComboBox->addItem(tr("Disabled (short delay)"));
    deviceSyncComboBox->setCurrentIndex(2);
    connect(deviceSyncComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(syncBuffersChanged(int)));

    engineClockComboBox->clear();
    engineClockComboBox->addItem(tr("Soundcard Clock"));
    engineClockComboBox->addItem(tr("Network Clock"));
    engineClockComboBox->setCurrentIndex(0);
    connect(engineClockComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(engineClockChanged(int)));

    keylockComboBox->clear();
    for (int i = 0; i < EngineBuffer::KEYLOCK_ENGINE_COUNT; ++i) {
        keylockComboBox->addItem(
                EngineBuffer::getKeylockEngineName(
                        static_cast<EngineBuffer::KeylockEngine>(i)));
    }

    m_pLatencyCompensation = new ControlProxy("[Master]", "microphoneLatencyCompensation", this);
    m_pMasterDelay = new ControlProxy("[Master]", "delay", this);
    m_pHeadDelay = new ControlProxy("[Master]", "headDelay", this);
    m_pBoothDelay = new ControlProxy("[Master]", "boothDelay", this);

    latencyCompensationSpinBox->setValue(m_pLatencyCompensation->get());
    latencyCompensationWarningLabel->setWordWrap(true);
    masterDelaySpinBox->setValue(m_pMasterDelay->get());
    headDelaySpinBox->setValue(m_pHeadDelay->get());
    boothDelaySpinBox->setValue(m_pBoothDelay->get());

    connect(latencyCompensationSpinBox, SIGNAL(valueChanged(double)),
            this, SLOT(latencyCompensationSpinboxChanged(double)));
    connect(masterDelaySpinBox, SIGNAL(valueChanged(double)),
            this, SLOT(masterDelaySpinboxChanged(double)));
    connect(headDelaySpinBox, SIGNAL(valueChanged(double)),
            this, SLOT(headDelaySpinboxChanged(double)));
    connect(boothDelaySpinBox, SIGNAL(valueChanged(double)),
            this, SLOT(boothDelaySpinboxChanged(double)));

    m_pMicMonitorMode = new ControlProxy("[Master]", "talkover_mix", this);
    micMonitorModeComboBox->addItem(tr("Master output only"),
        QVariant(static_cast<int>(EngineMaster::MicMonitorMode::MASTER)));
    micMonitorModeComboBox->addItem(tr("Master and booth outputs"),
        QVariant(static_cast<int>(EngineMaster::MicMonitorMode::MASTER_AND_BOOTH)));
    micMonitorModeComboBox->addItem(tr("Direct monitor (recording and broadcasting only)"),
        QVariant(static_cast<int>(EngineMaster::MicMonitorMode::DIRECT_MONITOR)));
    int modeIndex = micMonitorModeComboBox->findData(
        static_cast<int>(m_pMicMonitorMode->get()));
    micMonitorModeComboBox->setCurrentIndex(modeIndex);
    micMonitorModeComboBoxChanged(modeIndex);
    connect(micMonitorModeComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(micMonitorModeComboBoxChanged(int)));

    initializePaths();
    loadSettings();

    connect(apiComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(settingChanged()));
    connect(sampleRateComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(settingChanged()));
    connect(audioBufferComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(settingChanged()));
    connect(deviceSyncComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(settingChanged()));
    connect(engineClockComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(settingChanged()));
    connect(keylockComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(settingChanged()));

    connect(queryButton, SIGNAL(clicked()),
            this, SLOT(queryClicked()));

    connect(m_pSoundManager, SIGNAL(outputRegistered(AudioOutput, AudioSource*)),
            this, SLOT(addPath(AudioOutput)));
    connect(m_pSoundManager, SIGNAL(outputRegistered(AudioOutput, AudioSource*)),
            this, SLOT(loadSettings()));

    connect(m_pSoundManager, SIGNAL(inputRegistered(AudioInput, AudioDestination*)),
            this, SLOT(addPath(AudioInput)));
    connect(m_pSoundManager, SIGNAL(inputRegistered(AudioInput, AudioDestination*)),
            this, SLOT(loadSettings()));

    m_pMasterAudioLatencyOverloadCount =
            new ControlProxy("[Master]", "audio_latency_overload_count", this);
    m_pMasterAudioLatencyOverloadCount->connectValueChanged(this, &DlgPrefSound::bufferUnderflow);

    m_pMasterLatency = new ControlProxy("[Master]", "latency", this);
    m_pMasterLatency->connectValueChanged(this, &DlgPrefSound::masterLatencyChanged);

    // TODO: remove this option by automatically disabling/enabling the master mix
    // when recording, broadcasting, headphone, and master outputs are enabled/disabled
    m_pMasterEnabled = new ControlProxy("[Master]", "enabled", this);
    masterMixComboBox->addItem(tr("Disabled"));
    masterMixComboBox->addItem(tr("Enabled"));
    masterMixComboBox->setCurrentIndex(m_pMasterEnabled->get() ? 1 : 0);
    connect(masterMixComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(masterMixChanged(int)));
    m_pMasterEnabled->connectValueChanged(this, &DlgPrefSound::masterEnabledChanged);

    m_pMasterMonoMixdown = new ControlProxy("[Master]", "mono_mixdown", this);
    masterOutputModeComboBox->addItem(tr("Stereo"));
    masterOutputModeComboBox->addItem(tr("Mono"));
    masterOutputModeComboBox->setCurrentIndex(m_pMasterMonoMixdown->get() ? 1 : 0);
    connect(masterOutputModeComboBox, SIGNAL(currentIndexChanged(int)),
            this, SLOT(masterOutputModeComboBoxChanged(int)));
    m_pMasterMonoMixdown->connectValueChanged(this, &DlgPrefSound::masterMonoMixdownChanged);

    m_pKeylockEngine =
            new ControlProxy("[Master]", "keylock_engine", this);

#ifdef __LINUX__
    qDebug() << "RLimit Cur " << RLimit::getCurRtPrio();
    qDebug() << "RLimit Max " << RLimit::getMaxRtPrio();

    if (RLimit::isRtPrioAllowed()) {
        limitsHint->setText(tr("Realtime scheduling is enabled."));
    }
#else
    // the limits warning is a Linux only thing
    limitsHint->hide();
#endif // __LINUX__
}
Esempio n. 7
0
// XInputGetState implementation
DWORD WINAPI hooked_XInputGetState(DWORD dwUserIndex, XINPUT_STATE *pState)
{
	// We dont support >= 2
	if (dwUserIndex >= 2 || !diAvailable) {
		return ERROR_DEVICE_NOT_CONNECTED;
	}
	// First init
	if (di == NULL) {
		setupDInput();
	}
	ZeroMemory(pState, sizeof(XINPUT_STATE));

	// Make the reads on 0 then dispatch on the rest
	if (dwUserIndex == 0) {
		// Check if we have to refresh the list of devices
		// basically if < 0 dont do anything, if > 0 reduce by 1, if == 0 refresh, this sets a simple timer
		if (mustRefreshDevices >= 0) {
			if (--mustRefreshDevices == 0) {
				refreshDevices();
			}
		}
		// Read DI joysticks
		for (auto it = joysticks.begin(); it != joysticks.end(); ) {
			BOOL isNew = joystickStates.find(it->first) == joystickStates.end();
			LPDIJOYSTATE2 state = &joystickStates[it->first];

			// Poll the device
			if (FAILED(poll(it->second, state))) {
				// We cant poll the device
				// it must be removed from the list of available joysticks
				it->second->Unacquire();
				it->second->Release();
				joystickStates.erase(it->first);
				it = joysticks.erase(it);
				continue;
			}

			// Check if the device wants to be changed
			int desired = readDirectInputControllerChange(state);
			// Set the virtual controller if necessary
			selectController(desired, &it->first, -1, isNew);
			++it;
		}

		// Read XInput
		for (int i = 0; i < 4; i++) {
			// Read XInputGetStateEx to get the GUIDE button (though it seems to be broken on win10 now)
			if (ExportByOrdinal100(i, &xinputStates[i]) != ERROR_SUCCESS) {
				xinputReady[i] = false;
				continue;
			}
			BOOL isNew = !xinputReady[i];
			xinputReady[i] = true;
			// Check if the device wants to be changed
			int desired = readXInputControllerChange(&xinputStates[i]);
			// Set the virtual controller if necessary
			selectController(desired, NULL, i, isNew);
		}
	}

	// Get the mapping
	VirtualControllerMapping* mapping = &virtualControllers[dwUserIndex];
	
	if (mapping->free) {
		// No device for this one, give the empty device
		return ERROR_SUCCESS;
	}

	// We have something

	if (mapping->xinput >= 0) {
		// XInput!
		if (!xinputReady[mapping->xinput]) {
			// But it was disconnected...
			mapping->free = true;
			return ERROR_SUCCESS;
		}
		// Else, just copy the input to the pState
		memcpy(pState, &xinputStates[mapping->xinput], sizeof(XINPUT_STATE));
		return ERROR_SUCCESS;
	}

	// This is a DirectInput device

	if (joysticks.find(mapping->guid) == joysticks.end()) {
		// But it has been destroy
		mapping->free = true;
		return ERROR_SUCCESS;
	}

	// Do the actual mapping now
	LPDIJOYSTATE2 js = &joystickStates[mapping->guid];
	pState->dwPacketNumber = GetTickCount();

	// If the DirectInput Controller is bound to this slot, inject button inputs
	if (js->rgbButtons[0]) // SQUARE
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_X;
	if (js->rgbButtons[3]) // TRIANGLE
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_Y;
	if (js->rgbButtons[1]) // X
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_A;
	if (js->rgbButtons[2]) // CIRCLE
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_B;
	if (js->rgbButtons[5]) // R1
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_RIGHT_SHOULDER;
	if (js->rgbButtons[7]) // R2
		pState->Gamepad.bRightTrigger = 255;
	if (js->rgbButtons[4]) // L1
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_LEFT_SHOULDER;
	if (js->rgbButtons[6]) // L2
		pState->Gamepad.bLeftTrigger = 255;
	// Modified SELECT to also function as RESTART in training room and/or TAUNT in versus -meign
	if (js->rgbButtons[8]) // SELECT
		//pState->Gamepad.wButtons |= XINPUT_GAMEPAD_BACK;
		(pState->Gamepad.bRightTrigger = 255) |= pState->Gamepad.wButtons |= XINPUT_GAMEPAD_X | XINPUT_GAMEPAD_Y | XINPUT_GAMEPAD_A | XINPUT_GAMEPAD_B | XINPUT_GAMEPAD_RIGHT_SHOULDER | XINPUT_GAMEPAD_LEFT_THUMB | XINPUT_GAMEPAD_BACK;
	if (js->rgbButtons[9]) // START
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_START;
	if (js->rgbButtons[10]) // LS
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_LEFT_THUMB;
	if (js->rgbButtons[11]) // RS
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_RIGHT_THUMB;
	if (js->rgdwPOV[0] == 0 * 4500 || js->rgdwPOV[0] == 1 * 4500 || js->rgdwPOV[0] == 7 * 4500) // DPAD UP
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_DPAD_UP;
	if (js->rgdwPOV[0] == 1 * 4500 || js->rgdwPOV[0] == 2 * 4500 || js->rgdwPOV[0] == 3 * 4500) // DPAD RIGHT
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_DPAD_RIGHT;
	if (js->rgdwPOV[0] == 3 * 4500 || js->rgdwPOV[0] == 4 * 4500 || js->rgdwPOV[0] == 5 * 4500) // DPAD DOWN
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_DPAD_DOWN;
	if (js->rgdwPOV[0] == 5 * 4500 || js->rgdwPOV[0] == 6 * 4500 || js->rgdwPOV[0] == 7 * 4500) // DPAD LEFT
		pState->Gamepad.wButtons |= XINPUT_GAMEPAD_DPAD_LEFT;
	
	// Added left and right analog joystick support with slight deadzones -meign
	if (js->lX <= 31767) // LS LEFT
		pState->Gamepad.sThumbLX = -32768;
	if (js->lX >= 33767) // LS RIGHT
		pState->Gamepad.sThumbLX = 32767;
	if (js->lY <= 31767) // LS UP
		pState->Gamepad.sThumbLY = 32767;
	if (js->lY >= 33767) // LS DOWN
		pState->Gamepad.sThumbLY = -32768;
	
	// Experimental right analog scaling movement (CFN map), works with PS3 TE stick in RS mode, unverified with PS4 controller -meign
	if (js->lZ <= 31767) {// RS LEFT
		int d2x = js->lZ;
		pState->Gamepad.sThumbRX = -32768 + d2x;
	}
	if (js->lZ >= 33767) {// RS RIGHT
		int d2x = js->lZ;
		pState->Gamepad.sThumbRX = d2x - 32768;
	}
	if (js->lRz <= 31767) {// RS UP
		int d2x = js->lRz;
		pState->Gamepad.sThumbRY = 32767 - d2x;
	}
	if (js->lRz >= 33767) {// RS DOWN
		int d2x = js->lRz;
		pState->Gamepad.sThumbRY = 32767 - d2x;
	}

	// As seen on x360ce
	// prevent sleep
	SetThreadExecutionState(ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);

	//Controller is connected!
	return ERROR_SUCCESS;
}
Esempio n. 8
0
int setupDInput()
{
	if (!diAvailable) {
		return FALSE;
	}
	// Create a DirectInput8 instance
	if (di != NULL) {
		return TRUE;
	}
	HRESULT hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION, IID_IDirectInput8, (VOID**)&di, NULL);
	if (FAILED(hr)) {
		// If it is not available for any reason, avoid getting back in setupDInput
		diAvailable = false;
		MessageBox(NULL, GetLastErrorAsString().c_str(), "SF5DInput - Direct Input", MB_ICONERROR);
		exit(hr);
	}

	// DI is ready, now create a message-only window
	WNDCLASSEX wndClass = {};
	wndClass.cbSize = sizeof(WNDCLASSEX);
	wndClass.lpfnWndProc = reinterpret_cast<WNDPROC>(messageCallback);
	GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCTSTR)&wndClass.hInstance, &wndClass.hInstance);
	wndClass.lpszClassName = "SF5DInput";

	if (!RegisterClassEx(&wndClass)) {
		MessageBox(NULL, GetLastErrorAsString().c_str(), "SF5DInput - Registering Window Class", MB_ICONERROR);
		exit(1);
	}

	hWnd = CreateWindowEx(0L, wndClass.lpszClassName, "SF5DInput", 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);	
	if (!hWnd) {
		MessageBox(NULL, GetLastErrorAsString().c_str(), "SF5DInput - Create Internal Window", MB_ICONERROR);
		exit(2);
	}

	// Message only window is ready, now we can create a notification filter to register to device notificaitons

	DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;

	ZeroMemory(&NotificationFilter, sizeof(NotificationFilter));
	NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
	NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
	// This is GUID_DEVINTERFACE_USB_DEVICE, it scans all usb devices
	NotificationFilter.dbcc_classguid = { 0xA5DCBF10L, 0x6530, 0x11D2, { 0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED } };

	hDeviceNotify = RegisterDeviceNotification(
		hWnd,                       // events recipient
		&NotificationFilter,        // type of device
		DEVICE_NOTIFY_WINDOW_HANDLE // type of recipient handle
	);

	if (NULL == hDeviceNotify) {
		MessageBox(NULL, GetLastErrorAsString().c_str(), "SF5DInput - Registering Device Notification", MB_ICONERROR);
		exit(1);
	}

	// WOOH we are ready to go!

	// Get all the devices
	refreshDevices();
	return TRUE;
}
Esempio n. 9
0
/**
 * @brief slot: show preference dialog
 * @return
 *      void
 */
void DLDConfigureOB::showPreferences ()
{
	QDialog * preferenceDialog = new QDialog;
	preferences.setupUi (preferenceDialog);

	// fill with defaults: (from settings)
	QString logFile = settings->value("logFile", "").toString ();
	preferences.flashBasepathEdit->setText (settings->value("FlashBasepath", "ttyUSB").toString ());
	preferences.openBeaconBasepathEdit->setText (settings->value("OpenBeaconBasepath", "ttyACM").toString ());
	preferences.refreshSpin->setValue (settings->value("DeviceRefreshRate", 5).toInt ());
	preferences.logFileEdit->setText (logFile);
	preferences.sam7PathEdit->setText (settings->value("sam7Path", "/usr/local/bin/sam7").toString ());
	preferences.showTagPacketsCheck->setChecked (showRX);

	// fill command table
	QStringList		tableHeader;
	tableHeader << tr ("Command") << tr ("Command description");
	preferences.commandTable->setColumnCount(2);
	preferences.commandTable->setHorizontalHeaderLabels (tableHeader);
	preferences.commandTable->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents);
	preferences.commandTable->setShowGrid(true);

	QMap<QString, QString> cmdMap = getCommandMap ();
	QMapIterator<QString, QString> i (cmdMap);
	while (i.hasNext())
	{
		i.next();
		QTableWidgetItem * cmdNameItem = new QTableWidgetItem(i.key());
		QTableWidgetItem * cmdDescItem = new QTableWidgetItem(i.value());
		preferences.commandTable->insertRow(0);
		preferences.commandTable->setItem(0, 0, cmdNameItem);
		preferences.commandTable->setItem(0, 1, cmdDescItem);
	}

	// connect buttons:
	connect(preferences.addButton,		SIGNAL(clicked ()), this, SLOT(insertCommandTableRow ()));
	connect(preferences.deleteButton,	SIGNAL(clicked ()), this, SLOT(deleteCommandTableRow ()));
	connect(preferences.logFileButton,	SIGNAL(clicked ()), this, SLOT(selectLogFile ()));
	connect(preferences.sam7PathButton,	SIGNAL(clicked ()), this, SLOT(selectSam7File ()));
	connect(preferences.defaultCommandsButton,SIGNAL(clicked ()), this, SLOT(fillDefaultCommands ()));

	// connect entry checks
	connect(preferences.flashBasepathEdit,	SIGNAL(editingFinished ()), this, SLOT(checkFilled ()));
	connect(preferences.openBeaconBasepathEdit,SIGNAL(editingFinished ()), this, SLOT(checkFilled ()));

	if (preferenceDialog->exec () == QDialog::Accepted)
	{
		int refreshRate = preferences.refreshSpin->value ();
		settings->setValue("FlashBasepath", preferences.flashBasepathEdit->text ());
		settings->setValue("OpenBeaconBasepath", preferences.openBeaconBasepathEdit->text ());
		settings->setValue("DeviceRefreshRate", refreshRate);
		settings->setValue("showRX", showRX);
		showRX = preferences.showTagPacketsCheck->isChecked();
		settings->setValue("sam7Path", preferences.sam7PathEdit->text ());

		QString newLogFile = preferences.logFileEdit->text();
		if (logFile != newLogFile)
		{
			emit logFileChanged (newLogFile);
			settings->setValue("logFile", newLogFile);
			log->infoLog (QString("Logpath changed to: %1").arg(newLogFile));
		}

		QMap<QString, QString> newCmdMap;
		log->debugLog ("Current command list:");
		for (int row = 0; row < preferences.commandTable->rowCount(); row++)
		{
			QTableWidgetItem *cmdNameItem = preferences.commandTable->item(row, 0);
			QTableWidgetItem *cmdDescItem = preferences.commandTable->item(row, 1);
			if (cmdNameItem && cmdDescItem)
			{
				newCmdMap.insert (cmdNameItem->text(), cmdDescItem->text());
				log->debugLog (QString ("Name: %1\tDesc: %2").arg(cmdNameItem->text()).arg(cmdDescItem->text()));
			}
		}
		writeCommandMap (newCmdMap);
		refreshDevices ();
		refreshTimer->setInterval (refreshRate * 1000);
	}
}