static void outputSendMouse(int x, int y, int b1, int b2, int b3, int wheel, int b6, int b7)
{
	uint8_t event[4] = {0, 0, 0, 0};

	checkDeviceReplugged();
	if( keyboardFd == -1 || mouseFd == -1 )
		openDevices();
	if( keyboardFd == -1 || mouseFd == -1 )
		return;

	//printf("outputSendMouse: %d %d b %d %d %d %d", x, y, b1, b2, b3, wheel);

	event[0] |= b1 ? 1 : 0;
	event[0] |= b2 ? 2 : 0;
	event[0] |= b3 ? 4 : 0;
	event[0] |= b6 ? 32 : 0;
	event[0] |= b7 ? 64 : 0;
	event[1] = (x > SCHAR_MAX) ? SCHAR_MAX : (x < SCHAR_MIN + 1) ? SCHAR_MIN + 1 : x;
	event[2] = (y > SCHAR_MAX) ? SCHAR_MAX : (y < SCHAR_MIN + 1) ? SCHAR_MIN + 1 : y;
	event[3] = (wheel >= 0) ? wheel : UCHAR_MAX + 1 + wheel;
	if( write(mouseFd, event, sizeof(event)) != sizeof(event))
	{
		close(keyboardFd);
		close(mouseFd);
		keyboardFd = -1;
		mouseFd = -1;
	}
}
Beispiel #2
0
void MidiApple::updateDeviceList()
{
	closeDevices();
	openDevices();
	
	emit readablePortsChanged();
	emit writablePortsChanged();
}
Beispiel #3
0
MidiApple::MidiApple() :
	MidiClient(),
	m_inputDevices(),
	m_outputDevices(),
	m_inputSubs(),
	m_outputSubs()
{
	openDevices();
}
Beispiel #4
0
MidiWinMM::MidiWinMM() :
	MidiClient(),
	m_inputDevices(),
	m_outputDevices(),
	m_inputSubs(),
	m_outputSubs()
{
	openDevices();
}
void openInput()
{
	if( !deviceExist(DEV_KEYBOARD) || !deviceExist(DEV_MOUSE) )
	{
		flashCustomKernel();
		return;
	}
	openDevices();
	if( keyboardFd == -1 || mouseFd == -1 )
	{
		changeDevicePermissions();
		openDevices();
	}
	if( keyboardFd == -1 || mouseFd == -1 )
	{
		openDevicesSuperuser();
	}
	if( (keyboardFd == -1 || mouseFd == -1) )
	{
		char cmd[256];
		createDialog();
		addDialogText("Your kernel is supported by this app");
		addDialogText("But your system is not rooted - cannot open device files");
		addDialogText("Please execute following command from the root shell, and restart this app:");
		sprintf(cmd, "chmod 666 %s %s", DEV_KEYBOARD, DEV_MOUSE);
		addDialogText(cmd);
		addDialogText("If this does not help, disable SELinux with command:");
		strcpy(cmd, "tbsbiahudb'7"); // "setenforce 0" xor 0x7, in case Google Play has automated app removal bot
		for (int i = 0; i < strlen(cmd); i++)
			cmd[i] ^= 0x7;
		addDialogText(cmd);
		addDialogText("Press Back to exit");
		while( true )
			mainLoop();
		exit(0);
	}
	if( keyboardFd == -1 || mouseFd == -1 )
		flashCustomKernel();
	readKeyMappings();
}
void openInput()
{
	openDevices();
	if( devicesExist() && (keyboardFd == -1 || mouseFd == -1) )
	{
		changeDevicePermissions();
		openDevices();
	}
	if( keyboardFd == -1 || mouseFd == -1 )
		flashCustomKernel();
	for( int k = SDLK_FIRST; k < SDLK_LAST; k++ )
	{
		for( int s = 0; s < SDL_NUM_SCANCODES; s++ )
		{
			if( scancodes_table[s] == k )
			{
				keycode_to_scancode[k] = s;
				break;
			}
		}
	}
}
void VideoGrabber::Main()
{
	if ( !channel ) return ;

	PTRACE( 1, "Going to grab from video device" );
	while ( run ) {
		mutex.Wait();
		State s = state;
		mutex.Signal();

		// prepare for the state...
		closeDevices();
		switch( s ) {
			case SPreview:
				if( !openDevices() ) {
					stopPreview();
					ancaInfo->setInt( VG_STATE, VG_IDLE );
				}
				break;
			case SCall:
				openReader();
				break;
			case SSleep:
				break;
		}
		preparing = false;

		// do
		switch( s ) {
			case SSleep:
			case SCall:
				goSleep();
				break;
			case SPreview:
				while ( state == SPreview && run && !reconfigure ) {
					channel->Read( buffer, bufferSize );
					channel->Write( buffer, bufferSize );

					Sleep( 50 );
				}
		}
	}
}
static void outputSendKeys()
{
	uint8_t event[8] = {0, 0, 0, 0, 0, 0, 0, 0};

	checkDeviceReplugged();
	if( keyboardFd == -1 || mouseFd == -1 )
		openDevices();
	if( keyboardFd == -1 || mouseFd == -1 )
		return;

	event[0] |= keys[KEY_LCTRL] ? 0x1 : 0;
	event[0] |= keys[KEY_RCTRL] ? 0x10 : 0;
	event[0] |= keys[KEY_LSHIFT] ? 0x2 : 0;
	event[0] |= keys[KEY_RSHIFT] ? 0x20 : 0;
	event[0] |= keys[KEY_LALT] ? 0x4 : 0;
	event[0] |= keys[KEY_RALT] ? 0x40 : 0;
	event[0] |= keys[KEY_LSUPER] ? 0x8 : 0;
	event[0] |= keys[KEY_RSUPER] ? 0x80 : 0;
	
	int pos = 2;
	for(int i = 1; i < MAX_KEYCODES - MAX_MODIFIERS; i++)
	{
		if( keys[i] )
		{
			event[pos] = i;
			pos++;
			if( pos >= sizeof(event) )
				break;
		}
	}
	//printf("Send key event: %d %d %d %d %d %d %d %d", event[0], event[1], event[2], event[3], event[4], event[5], event[6], event[7]);
	if( write(keyboardFd, event, sizeof(event)) != sizeof(event))
	{
		close(keyboardFd);
		close(mouseFd);
		keyboardFd = -1;
		mouseFd = -1;
	}
}
static void outputSendKeys()
{
	uint8_t event[8] = {0, 0, 0, 0, 0, 0, 0, 0};

	if( keyboardFd == -1 || mouseFd == -1 )
		openDevices();
	if( keyboardFd == -1 || mouseFd == -1 )
		return;

	event[0] |= keys[SDLK_LCTRL] ? 0x1 : 0;
	event[0] |= keys[SDLK_RCTRL] ? 0x10 : 0;
	event[0] |= keys[SDLK_LSHIFT] ? 0x2 : 0;
	event[0] |= keys[SDLK_RSHIFT] ? 0x20 : 0;
	event[0] |= keys[SDLK_LALT] ? 0x4 : 0;
	event[0] |= keys[SDLK_RALT] ? 0x40 : 0;
	event[0] |= keys[SDLK_LSUPER] ? 0x8 : 0;
	event[0] |= keys[SDLK_RSUPER] ? 0x80 : 0;
	
	int pos = 2;
	for(int i = 1; i < SDLK_LAST; i++)
	{
		if( keys[i] && keycode_to_scancode[i] < 255 )
		{
			event[pos] = keycode_to_scancode[i];
			pos++;
			if( pos >= sizeof(event) )
				break;
		}
	}
	//printf("Send key event: %d %d %d %d %d %d %d %d", event[0], event[1], event[2], event[3], event[4], event[5], event[6], event[7]);
	if( write(keyboardFd, event, sizeof(event)) != sizeof(event))
	{
		close(keyboardFd);
		close(mouseFd);
		keyboardFd = -1;
		mouseFd = -1;
	}
}
static void outputSendMouse(int x, int y, int b1, int b2, int b3, int wheel)
{
	uint8_t event[4] = {0, 0, 0, 0};

	if( keyboardFd == -1 || mouseFd == -1 )
		openDevices();
	if( keyboardFd == -1 || mouseFd == -1 )
		return;

	event[0] |= b1 ? 1 : 0;
	event[0] |= b2 ? 2 : 0;
	event[0] |= b3 ? 4 : 0;
	event[1] = x;
	event[2] = y;
	event[3] = wheel >= 0 ? wheel : 256 + wheel;
	if( write(mouseFd, event, sizeof(event)) != sizeof(event))
	{
		close(keyboardFd);
		close(mouseFd);
		keyboardFd = -1;
		mouseFd = -1;
	}
}
Beispiel #11
0
RTC::ReturnCode_t HockeyArmController::onInitialize()
{
  // Registration: InPort/OutPort/Service
  // <rtc-template block="registration">
  // Set InPort buffers
  addInPort("ArmXY_in", m_armXY_inIn);
  
  // Set OutPort buffer
  addOutPort("ArmXY_out", m_ArmXY_outOut);
  
  // Set service provider to Ports
  
  // Set service consumers to Ports
  m_AHServicePort.registerConsumer("AHCommonDataService", "AHCommon::AHCommonDataService", m_ahCommonDataService);
  
  // Set CORBA Service Ports
  addPort(m_AHServicePort);
  
  // </rtc-template>

  // <rtc-template block="bind_config">
  // Bind variables and configuration variable
  bindParameter("arm_offset", m_arm_offset, "208.0");
  bindParameter("arm_len_1", m_arm_len_1, "560.0");
  bindParameter("arm_len_2", m_arm_len_2, "319.0");
  bindParameter("initial_enc_x", m_initial_enc_x, "1177");
  bindParameter("initial_enc_y", m_initial_enc_y, "1658");
  bindParameter("slow_limit_x", m_slow_limit_x, "5000");
  bindParameter("slow_limit_y", m_slow_limit_y, "5000");
  
  // </rtc-template>

  /* --- コンポーネント入出力の初期化 --- */
  // 入力の初期化
  m_armXY_in.data.length(2);
  m_armXY_in.data[0] = g_initXY.x;
  m_armXY_in.data[1] = g_initXY.y;
  // 出力の初期化
  m_ArmXY_out.data.length(2);
  m_ArmXY_out.data[0] = g_initXY.x;
  m_ArmXY_out.data[1] = g_initXY.y;
  m_ArmXY_outOut.write();

  /* --- A-IOボードのオープン --- */
  if (openDevices(1, g_opened[0])) return RTC::RTC_ERROR;
  if (openDevices(2, g_opened[1])) return RTC::RTC_ERROR;

  /* --- 位置決め制御インスタンスの初期化 --- */
  
  // X軸
  g_posController[0].init(1, ENCODER_EVAL, SLOW_LIMIT_X*ENCODER_EVAL, 3000);
  g_posController[0].start(true);
  g_posController[0].startMove();
  g_posController[0].servoOn();
  // Y軸
  g_posController[1].init(2, ENCODER_EVAL, SLOW_LIMIT_Y*ENCODER_EVAL, 3000);
  g_posController[1].start(true);
  g_posController[1].startMove();
  g_posController[1].servoOn();

  usleep(500000);

  /* --- clear encoder count with Z --- */
  std::cerr << "!!!" << std::endl;
  clearEncoderCountWithZ(g_posController[0], g_posController[1]);

  /* --- アームを初期位置に移動する --- */
  g_posController[0].moveTo(rad2pulse(g_initTh.x - M_PI/2, 2500*ENCODER_EVAL) * MOTOR_X_RATIO + INIT_ENC_X, 300);
  g_posController[1].moveTo(rad2pulse(g_initTh.y         , 2500*ENCODER_EVAL) * MOTOR_Y_RATIO + INIT_ENC_Y, 300);
  fprintf(stderr, "ARM init OK!\n");

  return RTC::RTC_OK;
}