static void *
commandListenerThread() 
{
	command 	cmd;
		
	syslog(LOG_INFO, "Start listening for commands\n");
	
	/* Start reading the message queue */
	while(running)
	{	
		getCommand(&cmd);
			
		if (strstr(cmd.cmd, CMD_RUMBLE))
		{
			setControllerRumble(getDeviceHandle(cmd.id), cmd.val);
		}
		else if (strstr(cmd.cmd, CMD_LED))
		{
			setControllerLeds(getDeviceHandle(cmd.id), cmd.val);
		}
	}

	syslog(LOG_INFO, "Stopped listening for commands\n");
	return (NULL);
}
Beispiel #2
0
/* 2. Live video capture is not supported in Windows  */
static void checkDeviceParams(const uint8_T *devName, uint32_T simOutput, uint32_T pixelFormat, uint32_T imWidth)
{
    MW_videoInfo_t *h;

#if (defined(MATLAB_MEX_FILE) || defined(RSIM_WITH_SL_SOLVER)) && !defined(__linux__)
	/* Check if live video capture in simulation is supported */
	if (simOutput == SIM_OUTPUT_LIVE_VIDEO) {
	    MW_ERROR_EXIT("Live video capture is not supported on Windows platforms. "
			"Select a simulation output that generates a synthetic image.\n");
	}
#endif

	/* Check if we have a device instance with the same name */
	h = getDeviceHandle(devName);
	if (h != NULL) {
	    MW_ERROR_EXIT1("Each Video Capture block must use a unique Video device name. "
			"Video device name %s is already used.", devName);
	}

	/* Check that pixel format is in range */
	if ((pixelFormat != MW_YCBCR422) && (pixelFormat != MW_RGB)) {
		MW_ERROR_EXIT1("Unknown Pixel format %d.", pixelFormat);
	}

	/* Image width must be even in YCbCr 4:2:2 mode */
	if ((pixelFormat == MW_YCBCR422) && ((imWidth & 0x1) != 0)) {
		MW_ERROR_EXIT1("%s: Image width must be even when Pixel order is YCbCr 4:2:2. "
			"This format has half as many chroma samples as that of luminance plane.",  devName);
	}
}
Beispiel #3
0
qint32 QUsbDevice::open()
{
    if (mConnected)
        return -1;

    if (!guidFromString(mFilter.guid, &mGuid))
        return -1;

    if (!getDeviceHandle(mGuid, &mDevHandle)) return -1;
    else if (!getWinUSBHandle(mDevHandle, &mUsbHandle)) return -2;
    else if (!getUSBDeviceSpeed(mUsbHandle, &mDevSpeed)) return -3;
    else if (!queryDeviceEndpoints(mUsbHandle, &mPipeId)) return -4;

    ulong timeout = mTimeout; /* SetPipePolicy requires an unsigned long */
    if (!WinUsb_SetPipePolicy(mUsbHandle, mConfig.readEp, PIPE_TRANSFER_TIMEOUT, sizeof(timeout), &timeout)) {
        qWarning("Error WinUsb_SetPipePolicy: %d.\n", GetLastError()); return -5; }
    if (!WinUsb_SetPipePolicy(mUsbHandle, mConfig.writeEp, PIPE_TRANSFER_TIMEOUT, sizeof(timeout), &timeout)) {
        qWarning("Error WinUsb_SetPipePolicy: %d.\n", GetLastError()); return -6; }

    bool enable = true;
    if (!WinUsb_SetPipePolicy(mUsbHandle, mConfig.readEp, IGNORE_SHORT_PACKETS, sizeof(enable), &enable)) {
        qWarning("Error WinUsb_SetPipePolicy: %d.\n", GetLastError()); return -7; }

    mConnected = true;

    return 0;
}
Beispiel #4
0
/* Simulink interface for video capture terminate function */
void MW_videoCaptureTerminate(const uint8_T *devName)
{
    MW_videoInfo_t *h = getDeviceHandle(devName);

#ifdef _MW_V4L2_DEBUG_LVL2_
	printf("\nTerminate for device %s\n", devName);
#endif
    if (h != NULL) {
        terminateDevice(h);
    }
}
Beispiel #5
0
SEXP getWindowsHandle(SEXP which)
{
    void * handle;

    if(length(which) != 1) error(_("'%s' must be length 1"), "which");
    if (isString(which)) handle = getConsoleHandle(CHAR(STRING_ELT(which,0)));
    else if (isInteger(which)) handle = getDeviceHandle(INTEGER(which)[0]);
    else handle = NULL;

    if (handle)
	return R_MakeExternalPtr(handle,R_NilValue,R_NilValue);
    else
	return R_NilValue;
}
static void *
buttonReaderThread() 
{
	buttons btns;
	uint8_t i;
			
	syslog(LOG_INFO, "Start reading controller buttons\n");
				
	/* Start reading the buttons of each controller */
	while(running)
	{
		for(i=0; i<MAX_DEVS; i++)
		{	
			getControllerInput(getDeviceHandle(i), &btns[i]);
			witeButtonToSHM(&btns[i], i);
		}
	}
	syslog(LOG_INFO, "Stopped reading controller buttons\n");	
	return (NULL);
}
Beispiel #7
0
/* is output. In code generation, always outputs live video */
void MW_videoCaptureOutput(const uint8_T *devName, uint8_T *pln0, uint8_T *pln1, uint8_T *pln2)
{
	MW_videoInfo_t *h = getDeviceHandle(devName);

#if (defined(MATLAB_MEX_FILE) || defined(RSIM_WITH_SL_SOLVER)) && defined(__linux__) 
	if (h->simOutput == SIM_OUTPUT_LIVE_VIDEO) {
        readV4L2Frame(h, pln0, pln1, pln2);
	}
	else {
        genSimOutput(h, pln0, pln1, pln2);
	}
#elif (defined(MATLAB_MEX_FILE) || defined(RSIM_WITH_SL_SOLVER)) && !defined(__linux__) 
	genSimOutput(h, pln0, pln1, pln2);
#else
	readV4L2Frame(h, pln0, pln1, pln2);
	if (h->pixelOrder == PIXEL_ORDER_PLANAR) {
		/*interleaved2planar(pln0, pln0);*/
	}
#endif
	h->frmCount++;
}
Beispiel #8
0
MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
	// Query the selected music device (defaults to MT_AUTO device).
	Common::String selDevStr = ConfMan.hasKey("music_driver") ? ConfMan.get("music_driver") : Common::String("auto");
	DeviceHandle hdl = getDeviceHandle(selDevStr.empty() ? Common::String("auto") : selDevStr);
	DeviceHandle reslt = 0;

	_forceTypeMT32 = false;

	// Check whether the selected music driver is compatible with the
	// given flags.
	switch (getMusicType(hdl)) {
	case MT_PCSPK:
		if (flags & MDT_PCSPK)
			reslt = hdl;
		break;

	case MT_PCJR:
		if (flags & MDT_PCJR)
			reslt = hdl;
		break;

	case MT_CMS:
		if (flags & MDT_CMS)
			reslt = hdl;
		break;

	case MT_ADLIB:
		if (flags & MDT_ADLIB)
			reslt = hdl;
		break;

	case MT_C64:
		if (flags & MDT_C64)
			reslt = hdl;
		break;

	case MT_AMIGA:
		if (flags & MDT_AMIGA)
			reslt = hdl;
		break;

	case MT_APPLEIIGS:
		if (flags & MDT_APPLEIIGS)
			reslt = hdl;
		break;

	case MT_TOWNS:
		if (flags & MDT_TOWNS)
			reslt = hdl;
		break;

	case MT_PC98:
		if (flags & MDT_PC98)
			reslt = hdl;
		break;

	case MT_GM:
	case MT_GS:
	case MT_MT32:
		if (flags & MDT_MIDI)
			reslt = hdl;
		break;

	case MT_NULL:
		reslt = hdl;
		break;

	default:
		break;
	}

	Common::String failedDevStr;
	if (getMusicType(hdl) == MT_INVALID) {
		// If the expressly selected driver or device cannot be found (no longer compiled in, turned off, etc.)
		// we display a warning and continue.
		failedDevStr = selDevStr;
		Common::String warningMsg = Common::String::format(_("The selected audio device '%s' was not found (e.g. might be turned off or disconnected)."), failedDevStr.c_str()) + " " + _("Attempting to fall back to the next available device...");
		GUI::MessageDialog dialog(warningMsg);
		dialog.runModal();
	}

	MusicType tp = getMusicType(reslt);
	if (tp != MT_INVALID && tp != MT_AUTO) {
		if (checkDevice(reslt)) {
			return reslt;
		} else {
			// If the expressly selected device cannot be used we display a warning and continue.
			failedDevStr = getDeviceString(hdl, MidiDriver::kDeviceName);
			Common::String warningMsg = Common::String::format(_("The selected audio device '%s' cannot be used. See log file for more information."), failedDevStr.c_str()) + " " + _("Attempting to fall back to the next available device...");
			GUI::MessageDialog dialog(warningMsg);
			dialog.runModal();
		}
	}

	// If the selected driver did not match the flags setting,
	// we try to determine a suitable and "optimal" music driver.
	const MusicPlugin::List p = MusicMan.getPlugins();
	// If only MDT_MIDI but not MDT_PREFER_MT32 or MDT_PREFER_GM is set we prefer the other devices (which will always be
	// detected since they are hard coded and cannot be disabled).
	bool skipMidi = !(flags & (MDT_PREFER_GM | MDT_PREFER_MT32));
	while (flags != MDT_NONE) {
		if ((flags & MDT_MIDI) && !skipMidi) {
			// If a preferred MT32 or GM device has been selected that device gets returned if available.
			Common::String devStr;
			if (flags & MDT_PREFER_MT32)
				devStr = ConfMan.hasKey("mt32_device") ? ConfMan.get("mt32_device") : Common::String("null");
			else if (flags & MDT_PREFER_GM)
				devStr = ConfMan.hasKey("gm_device") ? ConfMan.get("gm_device") : Common::String("null");
			else
				devStr = "auto";
			
			// Default to Null device here, since we also register a default null setting for
			// the MT32 or GM device in the config manager.
			hdl = getDeviceHandle(devStr.empty() ? Common::String("null") : devStr);
			const MusicType type = getMusicType(hdl);

			// If we have a "Don't use GM/MT-32" setting we skip this part and jump
			// to AdLib, PC Speaker etc. detection right away.
			if (type != MT_NULL) {
				if (type == MT_INVALID) {
					// If the preferred (expressly requested) selected driver or device cannot be found (no longer compiled in, turned off, etc.)
					// we display a warning and continue. Don't warn about the missing device if we did already (this becomes relevant if the
					// missing device is selected as preferred device and also as GM or MT-32 device).
					if (failedDevStr != devStr) {
						Common::String warningMsg = Common::String::format(_("The preferred audio device '%s' was not found (e.g. might be turned off or disconnected)."), devStr.c_str()) + " " + _("Attempting to fall back to the next available device...");
						GUI::MessageDialog dialog(warningMsg);
						dialog.runModal();
					}
				} else if (type != MT_AUTO) {
					if (checkDevice(hdl)) {
						if (flags & MDT_PREFER_MT32)
							// If we have a preferred MT32 device we disable the gm/mt32 mapping (more about this in mididrv.h).
							_forceTypeMT32 = true;
						return hdl;
					} else {
						// If the preferred (expressly requested) device cannot be used we display a warning and continue.
						// Don't warn about the failing device if we did already (this becomes relevant if the failing
						// device is selected as preferred device and also as GM or MT-32 device).
						if (failedDevStr != getDeviceString(hdl, MidiDriver::kDeviceName)) {
							Common::String warningMsg = Common::String::format(_("The preferred audio device '%s' cannot be used. See log file for more information."), getDeviceString(hdl, MidiDriver::kDeviceName).c_str()) + " " + _("Attempting to fall back to the next available device...");
							GUI::MessageDialog dialog(warningMsg);
							dialog.runModal();
						}
					}
				}

				// If no specific device is selected (neither in the scummvm nor in the game domain)
				// and there is no preferred MT32 or GM device selected either or if the detected device is unavailable we arrive here.
				// If MT32 is preferred we try for the first available device with music type 'MT_MT32' (usually the mt32 emulator).
				if (flags & MDT_PREFER_MT32) {
					for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) {
						MusicDevices i = (**m)->getDevices();
						for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
							if (d->getMusicType() == MT_MT32) {
								hdl = d->getHandle();
								if (checkDevice(hdl))
									return hdl;
							}
						}
					}
				}

				// Now we default to the first available device with music type 'MT_GM' if not
				// MT-32 is preferred or if MT-32 is preferred but all other devices have failed.
				if (!(flags & MDT_PREFER_MT32) || flags == (MDT_PREFER_MT32 | MDT_MIDI)) {
					for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) {
						MusicDevices i = (**m)->getDevices();
						for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
							if (d->getMusicType() == MT_GM || d->getMusicType() == MT_GS) {
								hdl = d->getHandle();
								if (checkDevice(hdl))
									return hdl;
							}
						}
					}
					// Detection flags get removed after final detection attempt to avoid further attempts.
					flags &= ~(MDT_MIDI | MDT_PREFER_GM | MDT_PREFER_MT32);
				}
			}
		}

		// The order in this list is important, since this is the order of preference
		// (e.g. MT_ADLIB is checked before MT_PCJR and MT_PCSPK for a good reason).
		// Detection flags get removed after detection attempt to avoid further attempts.
		if (flags & MDT_TOWNS) {
			tp = MT_TOWNS;
			flags &= ~MDT_TOWNS;
		} else if (flags & MDT_PC98) {
			tp = MT_PC98;
			flags &= ~MDT_PC98;
		} else if (flags & MDT_ADLIB) {
			tp = MT_ADLIB;
			flags &= ~MDT_ADLIB;
		} else if (flags & MDT_PCJR) {
			tp = MT_PCJR;
			flags &= ~MDT_PCJR;
		} else if (flags & MDT_PCSPK) {
			tp = MT_PCSPK;
			flags &= ~MDT_PCSPK;
		} else if (flags & MDT_C64) {
			tp = MT_C64;
			flags &= ~MDT_C64;
		} else if (flags & MDT_AMIGA) {
			tp = MT_AMIGA;
			flags &= ~MDT_AMIGA;
		} else if (flags & MDT_APPLEIIGS) {
			tp = MT_APPLEIIGS;
			flags &= ~MDT_APPLEIIGS;
		} else if (flags & MDT_MIDI) {
			// If we haven't tried to find a MIDI device yet we do this now.
			skipMidi = false;
			continue;
		} else if (flags) {
			// Invalid flags. Set them to MDT_NONE to leave detection loop.
			flags = MDT_NONE;
			tp = MT_AUTO;
		}

		for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) {
			MusicDevices i = (**m)->getDevices();
			for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
				if (d->getMusicType() == tp) {
					hdl = d->getHandle();
					if (checkDevice(hdl))
						return hdl;
				}
			}
		}
	}

	return 0;
}
Beispiel #9
0
MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
	// Query the selected music device (defaults to MT_AUTO device).
	DeviceHandle hdl = getDeviceHandle(ConfMan.get("music_driver"));

	_forceTypeMT32 = false;

	// Check whether the selected music driver is compatible with the
	// given flags.
	switch (getMusicType(hdl)) {
	case MT_PCSPK:
		if (flags & MDT_PCSPK)
			return hdl;
		break;

	case MT_PCJR:
		if (flags & MDT_PCJR)
			return hdl;
		break;

	case MT_CMS:
		if (flags & MDT_CMS)
			return hdl;
		break;

	case MT_ADLIB:
		if (flags & MDT_ADLIB)
			return hdl;
		break;

	case MT_C64:
		if (flags & MDT_C64)
			return hdl;
		break;

	case MT_AMIGA:
		if (flags & MDT_AMIGA)
			return hdl;
		break;

	case MT_APPLEIIGS:
		if (flags & MDT_APPLEIIGS)
			return hdl;
		break;

	case MT_TOWNS:
		if (flags & MDT_TOWNS)
			return hdl;
		break;

	case MT_PC98:
		if (flags & MDT_PC98)
			return hdl;
		break;

	case MT_GM:
	case MT_GS:
	case MT_MT32:
		if (flags & MDT_MIDI)
			return hdl;
		break;

	case MT_NULL:
		return hdl;

	default:
		break;
	}

	// If the selected driver did not match the flags setting,
	// we try to determine a suitable and "optimal" music driver.
	const MusicPlugin::List p = MusicMan.getPlugins();
	// If only MDT_MIDI but not MDT_PREFER_MT32 or MDT_PREFER_GM is set we prefer the other devices (which will always be
	// detected since they are hard coded and cannot be disabled.
	for (int l = (flags & (MDT_PREFER_GM | MDT_PREFER_MT32)) ? 1 : 0; l < 2; ++l) {
		if ((flags & MDT_MIDI) && (l == 1)) {
			// If a preferred MT32 or GM device has been selected that device gets returned.
			if (flags & MDT_PREFER_MT32)
				hdl = getDeviceHandle(ConfMan.get("mt32_device"));
			else if (flags & MDT_PREFER_GM)
				hdl = getDeviceHandle(ConfMan.get("gm_device"));
			else
				hdl = getDeviceHandle("auto");

			const MusicType type = getMusicType(hdl);

			// If we have a "Don't use GM/MT-32" setting we skip this part and jump
			// to AdLib, PC Speaker etc. detection right away.
			if (type != MT_NULL) {
				if (type != MT_AUTO && type != MT_INVALID) {
					if (flags & MDT_PREFER_MT32)
						// If we have a preferred MT32 device we disable the gm/mt32 mapping (more about this in mididrv.h).
						_forceTypeMT32 = true;

					return hdl;
				}

				// If no specific device is selected (neither in the scummvm nor in the game domain)
				// and there is no preferred MT32 or GM device selected either we arrive here.
				// If MT32 is preferred we try for the first available device with music type 'MT_MT32' (usually the mt32 emulator).
				if (flags & MDT_PREFER_MT32) {
					for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) {
						MusicDevices i = (**m)->getDevices();
						for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
							if (d->getMusicType() == MT_MT32)
								return d->getHandle();
						}
					}
				}

				// Now we default to the first available device with music type 'MT_GM'
				for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) {
					MusicDevices i = (**m)->getDevices();
					for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
						if (d->getMusicType() == MT_GM || d->getMusicType() == MT_GS)
							return d->getHandle();
					}
				}
			}
		}

		MusicType tp = MT_AUTO;
		if (flags & MDT_TOWNS)
			tp = MT_TOWNS;
		else if (flags & MDT_PC98)
			tp = MT_PC98;
		else if (flags & MDT_ADLIB)
			tp = MT_ADLIB;
		else if (flags & MDT_PCJR)
			tp = MT_PCJR;
		else if (flags & MDT_PCSPK)
			tp = MT_PCSPK;
		else if (flags & MDT_C64)
			tp = MT_C64;
		else if (flags & MDT_AMIGA)
			tp = MT_AMIGA;
		else if (flags & MDT_APPLEIIGS)
			tp = MT_APPLEIIGS;
		else if (l == 0)
			// If we haven't tried to find a MIDI device yet we do this now.
			continue;
		else
			tp = MT_AUTO;

		for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); ++m) {
			MusicDevices i = (**m)->getDevices();
			for (MusicDevices::iterator d = i.begin(); d != i.end(); ++d) {
				if (d->getMusicType() == tp)
					return d->getHandle();
			}
		}
	}

	return 0;
}