Beispiel #1
0
double DIOStreamSubsystem::setClock( bool directionRead, double clockHz ) {
	double unusedClockHz = 0;
	int result;
	if( directionRead )
		result = DIO_StreamSetClocks( getDeviceIndex(), &clockHz, &unusedClockHz );
	else
		result = DIO_StreamSetClocks( getDeviceIndex(), &unusedClockHz, &clockHz );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	return ( this->clockHz = clockHz );
}	// DIOStreamSubsystem::setClock()
Beispiel #2
0
bool ofxKinectContext::open(ofxKinect& kinect, int id) {
	
	// rebuild if necessary (aka new kinects plugged in)
	buildDeviceList();
	
	if(numConnected() >= numTotal()) {
		ofLog(OF_LOG_WARNING, "ofxKinect: No available devices found");
		return false;
	}
	
	// is the id available?
	if(id < 0) {
		id = nextAvailableId();
	}
	if(isConnected(id)) {
		ofLog(OF_LOG_WARNING, "ofxKinect: Device %d already connected", id);
		return false;
	}
	
	// open and add to vector
	if(freenect_open_device(kinectContext, &kinect.kinectDevice, id) < 0) {
		ofLog(OF_LOG_ERROR, "ofxKinect: Could not open device %d", id);
		return false;
	}
	kinects.insert(pair<int,ofxKinect*>(id, &kinect));
	
	// set kinect id & serial from bus id
	int index = getDeviceIndex(id);
	kinect.deviceId = id;
	kinect.serial = deviceList[index].serial;

	return true;
}
Beispiel #3
0
bool ofxKinectContext::open(ofxKinect& kinect, int id) {
	
	// rebuild if necessary (aka new kinects plugged in)
	buildDeviceList();
	
	if(numConnected() >= numTotal()) {
		ofLogWarning("ofxKinect") << "no available devices found";
		return false;
	}
	
	// is the id available?
	if(id < 0) {
		id = nextAvailableId();
	}
	if(isConnected(id)) {
		ofLogWarning("ofxKinect") << "device " << id << " already connected";
		return false;
	}
	
	// open and add to vector
	if(freenect_open_device(kinectContext, &kinect.kinectDevice, id) < 0) {
		ofLogError("ofxKinect") << "could not open device " <<  id;
		return false;
	}
	kinects.insert(pair<int,ofxKinect*>(id, &kinect));
	
	// set kinect id & serial from bus id
	kinect.deviceId = id;
	kinect.serial = deviceList[getDeviceIndex(id)].serial;

	return true;
}
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_xcsoar_InternalGPS_setConnected(JNIEnv *env, jobject obj,
                                         jint connected)
{
  unsigned index = getDeviceIndex(env, obj);

  ScopeLock protect(device_blackboard->mutex);
  NMEAInfo &basic = device_blackboard->SetRealState(index);

  switch (connected) {
  case 0: /* not connected */
    basic.alive.Clear();
    basic.location_available.Clear();
    break;

  case 1: /* waiting for fix */
    basic.alive.Update(MonotonicClockMS() / 1000.);
    basic.gps.nonexpiring_internal_gps = true;
    basic.location_available.Clear();
    break;

  case 2: /* connected */
    basic.alive.Update(MonotonicClockMS() / 1000.);
    basic.gps.nonexpiring_internal_gps = true;
    break;
  }

  device_blackboard->ScheduleMerge();
}
Beispiel #5
0
bool ofxKinectContext::open(ofxKinect& kinect, string serial) {
	
	// rebuild if necessary (aka new kinects plugged in)
	buildDeviceList();
	
	if(numConnected() >= numTotal()) {
		ofLogWarning("ofxKinect") << "no available devices found";
		return false;
	}
	
	// is the serial available?
	if(isConnected(serial)) {
		ofLogWarning("ofxKinect") << "device " << serial << " already connected";
		return false;
	}
	
	// open and add to vector
	if(freenect_open_device_by_camera_serial(kinectContext, &kinect.kinectDevice, serial.c_str()) < 0) {
		ofLogError("ofxKinect") << "could not open device " << serial;
		return false;
	}
	int index = getDeviceIndex(serial);
	kinects.insert(pair<int,ofxKinect*>(deviceList[index].id, &kinect));
	kinect.deviceId = deviceList[index].id;
	kinect.serial = serial;
	
	return true;
}
Beispiel #6
0
/**
 * Ajoute une condition à la règle en cours d'édition (variable gloable lastRule)
 * \param device capteur concerné
 * \param field champ du capteur concerné
 * \param type nature de la comparaison à effectuer (enum Condition_type)
 * \param value valeur à comparer dans la condition (~seuil)
 */
void addCondition(char *device, char *field, char *type, char *value)
{
	Condition *condition = malloc(sizeof(Condition));
	condition->device = getDeviceIndex(device);
	condition->field = getFieldIndex(field);
	condition->type = getConditionTypeIndex(type);
	condition->next = NULL;
    
	if(compare("true", value) == 0)
	{
		condition->value = 1.f;
	}
	else
	{
		condition->value = atof(value);
	}
    
	Condition *lastCondition = getLastCondition(lastRule);

	if(lastCondition == NULL)
	{
		lastRule->conditions = condition;
	}
	else
	{
		lastCondition->next = condition;
	}
    
    if(DEBUG_MODE == 1)
    {
        printf("New condition added : %s->%s %s %f\n", device, field, type, condition->value);
    }
}
Beispiel #7
0
bool ofxKinectContext::open(ofxKinect& kinect, string serial) {
	
	// rebuild if necessary (aka new kinects plugged in)
	buildDeviceList();
	
	if(numConnected() >= numTotal()) {
		ofLog(OF_LOG_WARNING, "ofxKinect: No available devices found");
		return false;
	}
	
	// is the serial available?
	if(isConnected(serial)) {
		ofLog(OF_LOG_WARNING, "ofxKinect: Device %s already connected", serial.c_str());
		return false;
	}
	
	// open and add to vector
	if(freenect_open_device_by_camera_serial(kinectContext, &kinect.kinectDevice, serial.c_str()) < 0) {
		ofLog(OF_LOG_ERROR, "ofxKinect: Could not open device %s", serial.c_str());
		return false;
	}
	int id = getDeviceIndex(serial);
	kinects.insert(pair<int,ofxKinect*>(id, &kinect));
	kinect.deviceId = id;
	kinect.serial = deviceList[id].serial;
	
	return true;
}
Beispiel #8
0
unsigned short Counter::readCount() {
	assert( counterIndex >= 0 );
	unsigned short count;
	const int result = CTR_8254Read( getDeviceIndex(), 0 /* BlockIndex */, counterIndex, &count );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	return count;
}	// Counter::ReadCount()
Beispiel #9
0
Counter &Counter::setCount( unsigned short count ) {
	if( typeid( parent ) != typeid( USB_CTR_15_Family ) )
		throw OperationFailedException( "Supported only in USB-CTR-15" );
	assert( counterIndex >= 0 );
	const int result = CTR_8254Load( getDeviceIndex(), 0 /* BlockIndex */, counterIndex, count );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	return *this;
}	// Counter::setCount()
Beispiel #10
0
string ofxKinectContext::nextAvailableSerial() {
	if(!isInited())
		init();
	
	int id = nextAvailableId();
	if(id == -1) {
		return "";
	}
	return deviceList[getDeviceIndex(id)].serial;
}
Beispiel #11
0
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_xcsoar_NonGPSSensors_setBarometricPressure(
    JNIEnv* env, jobject obj, jfloat pressure) {
  const unsigned int index = getDeviceIndex(env, obj);
  ScopeLock protect(device_blackboard->mutex);
  NMEAInfo &basic = device_blackboard->SetRealState(index);
  basic.ProvideStaticPressure(
      AtmosphericPressure::HectoPascal(fixed(pressure)));
  device_blackboard->ScheduleMerge();
}
Beispiel #12
0
Counter &Counter::setMode( int mode ) {
	assert( counterIndex >= 0 );
	if(
		mode < MODE_TERMINAL_COUNT
		|| mode > MODE_HW_TRIGGERED
	)
		throw IllegalArgumentException( "Invalid mode" );
	const int result = CTR_8254Mode( getDeviceIndex(), 0 /* BlockIndex */, counterIndex, mode );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	return *this;
}	// Counter::setMode()
Beispiel #13
0
int DIOStreamSubsystem::write( const UShortArray &values ) {
	if(
		&values == 0
		|| values.size() < 1
	)
		throw IllegalArgumentException( "Invalid values" );
	unsigned long bytesTransferred;
	const int result = DIO_StreamFrame( getDeviceIndex(), values.size(), ( unsigned short * ) values.data(), &bytesTransferred );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	return bytesTransferred / sizeof( unsigned short );
}	// DIOStreamSubsystem::write()
Beispiel #14
0
UShortArray Counter::readCountAndStatus() {
	assert( counterIndex >= 0 );
	unsigned short count;
	unsigned char status;
	const int result = CTR_8254ReadStatus( getDeviceIndex(), 0 /* BlockIndex */, counterIndex, &count, &status );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	UShortArray values( 2 );
	values.at( 0 ) = count;
	values.at( 1 ) = status;
	return values;
}	// Counter::readCountAndStatus()
Beispiel #15
0
UShortArray DIOStreamSubsystem::read( int numSamples ) {
	if( numSamples < 1 )
		throw IllegalArgumentException( "Invalid number of samples" );
	UShortArray values( numSamples );
	unsigned long bytesTransferred;
	const int result = DIO_StreamFrame( getDeviceIndex(), values.size(), values.data(), &bytesTransferred );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	const int samplesTransferred = bytesTransferred / sizeof( unsigned short );
	if( samplesTransferred != numSamples )
		values.resize( samplesTransferred );
	return values;
}	// DIOStreamSubsystem::read()
Beispiel #16
0
unsigned short Counter::readCountAndSetModeAndCount( int mode, unsigned short count ) {
	assert( counterIndex >= 0 );
	if(
		mode < MODE_TERMINAL_COUNT
		|| mode > MODE_HW_TRIGGERED
	)
		throw IllegalArgumentException( "Invalid mode" );
	unsigned short prevCount;
	const int result = CTR_8254ReadModeLoad( getDeviceIndex(), 0 /* BlockIndex */, counterIndex, mode, count, &prevCount );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	return prevCount;
}	// Counter::readCountAndSetModeAndCount()
Beispiel #17
0
/**
 * Ajoute une action à la règle en cours d'édition (variable gloable lastRule)
 * \param device capteur concerné
 * \param state état du field du device
 * \param field champ du capteur concerné
 */
void addAction(char *device, char *state, char *field) {
	Action *action = malloc(sizeof(Action));
	action->device = getDeviceIndex(device);
	action->state = getState(state);
	action->field = getFieldIndex(field);
	action->next = NULL;
    
	Action *lastAction = getLastAction(lastRule);
    
	if(lastAction == NULL)
	{
		lastRule->actions = action;
	}
	else
	{
		lastAction->next = action;
	}

	if(DEBUG_MODE == 1)
    {
        printf("New action added : %s -> %s\n", device, getStateName(getState(state)));
    }
}
Beispiel #18
0
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_xcsoar_NonGPSSensors_setBarometricPressure(
    JNIEnv* env, jobject obj, jfloat pressure, jfloat sensor_noise_variance) {
  /* We use a Kalman filter to smooth Android device pressure sensor
     noise.  The filter requires two parameters: the first is the
     variance of the distribution of second derivatives of pressure
     values that we expect to see in flight, and the second is the
     maximum time between pressure sensor updates in seconds before
     the filter gives up on smoothing and uses the raw value.

     The pressure acceleration variance used here is actually wider
     than the maximum likelihood variance observed in the data: it
     turns out that the distribution is more heavy-tailed than a
     normal distribution, probably because glider pilots usually
     experience fairly constant pressure change most of the time. */
  static constexpr fixed KF_VAR_ACCEL(0.0075);
  static constexpr fixed KF_MAX_DT(60);

  // XXX this shouldn't be a global variable
  static SelfTimingKalmanFilter1d kalman_filter(KF_MAX_DT, KF_VAR_ACCEL);

  const unsigned int index = getDeviceIndex(env, obj);
  ScopeLock protect(device_blackboard->mutex);

  /* Kalman filter updates are also protected by the blackboard
     mutex. These should not take long; we won't hog the mutex
     unduly. */
  kalman_filter.Update(fixed(pressure), fixed(sensor_noise_variance));

  NMEAInfo &basic = device_blackboard->SetRealState(index);
  basic.ProvideNoncompVario(ComputeNoncompVario(kalman_filter.GetXAbs(),
                                                kalman_filter.GetXVel()));
  basic.ProvideStaticPressure(
      AtmosphericPressure::HectoPascal(kalman_filter.GetXAbs()));
  device_blackboard->ScheduleMerge();
}
Beispiel #19
0
static orxSTATUS orxFASTCALL orxJoystick_Android_JoystickEventHandler(const orxEVENT *_pstEvent)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;
  orxANDROID_JOYSTICK_EVENT *pstJoystickEvent;
  orxS32 s32DeviceIndex;

  /* Gets payload */
  pstJoystickEvent = (orxANDROID_JOYSTICK_EVENT *) _pstEvent->pstPayload;

  /* Depending on ID */
  switch(pstJoystickEvent->u32Type)
  {
    case orxANDROID_EVENT_JOYSTICK_ADDED:
      if(newDeviceIndex(pstJoystickEvent->u32DeviceId) != orxSTATUS_SUCCESS)
      {
        orxDEBUG_PRINT(orxDEBUG_LEVEL_JOYSTICK, "couldn't add new device %d", pstJoystickEvent->u32DeviceId);
      }
      break;

    case orxANDROID_EVENT_JOYSTICK_REMOVED:
      s32DeviceIndex = getDeviceIndex(pstJoystickEvent->u32DeviceId);
      if(s32DeviceIndex != -1)
      {
        sstJoystick.au32DeviceIds[s32DeviceIndex] = 0;
      }
      else
      {
        orxDEBUG_PRINT(orxDEBUG_LEVEL_JOYSTICK, "unknown device %d", pstJoystickEvent->u32DeviceId);
      }
      break;

    case orxANDROID_EVENT_JOYSTICK_CHANGED:
      break;

    case orxANDROID_EVENT_JOYSTICK_DOWN:
      s32DeviceIndex = getDeviceIndex(pstJoystickEvent->u32DeviceId);

      if(s32DeviceIndex != -1)
      {
        switch(pstJoystickEvent->u32KeyCode)
        {
          case 19: // KEYCODE_DPAD_UP
            sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_V_1] = -orxFLOAT_1;
            break;
          case 20: // KEYCODE_DPAD_DOWN
            sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_V_1] = orxFLOAT_1;
            break;
          case 21: // KEYCODE_DPAD_LEFT
            sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_U_1] = -orxFLOAT_1;
            break;
          case 22: // KEYCODE_DPAD_RIGHT
            sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_U_1] = orxFLOAT_1;
            break;
          case 96: // KEYCODE_BUTTON_A
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_1_1] = 1;
            break;
          case 97: // KEYCODE_BUTTON_B
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_2_1] = 1;
            break;
          case 98: // KEYCODE_BUTTON_C
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_3_1] = 1;
            break;
          case 99: // KEYCODE_BUTTON_X
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_4_1] = 1;
            break;
          case 100: // KEYCODE_BUTTON_Y
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_5_1] = 1;
            break;
          case 101: // KEYCODE_BUTTON_Z
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_6_1] = 1;
            break;
          case 102: // KEYCODE_BUTTON_L1
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_7_1] = 1;
            break;
          case 103: // KEYCODE_BUTTON_R1
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_8_1] = 1;
            break;
          case 104: // KEYCODE_BUTTON_L2
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_9_1] = 1;
            break;
          case 105: // KEYCODE_BUTTON_R2
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_10_1] = 1;
            break;
          case 106: // KEYCODE_BUTTON_THUMBL
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_11_1] = 1;
            break;
          case 107: // KEYCODE_BUTTON_THUMBR
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_12_1] = 1;
            break;
          case 108: // KEYCODE_BUTTON_START
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_13_1] = 1;
            break;
          case 109: // KEYCODE_BUTTON_SELECT
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_14_1] = 1;
            break;
          default:
            orxDEBUG_PRINT(orxDEBUG_LEVEL_JOYSTICK, "unknown keycode %d", pstJoystickEvent->u32KeyCode);
            break;
        }
      }
      else
      {
        orxDEBUG_PRINT(orxDEBUG_LEVEL_JOYSTICK, "unknown device %d", pstJoystickEvent->u32DeviceId);
      }
      break;

    case orxANDROID_EVENT_JOYSTICK_UP:
      s32DeviceIndex = getDeviceIndex(pstJoystickEvent->u32DeviceId);

      if(s32DeviceIndex != -1)
      {
        switch(pstJoystickEvent->u32KeyCode)
        {
          case 19: // KEYCODE_DPAD_UP
          case 20: // KEYCODE_DPAD_DOWN
            sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_V_1] = orxFLOAT_0;
            break;
          case 21: // KEYCODE_DPAD_LEFT
          case 22: // KEYCODE_DPAD_RIGHT
            sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_U_1] = orxFLOAT_0;
            break;
          case 96: // KEYCODE_BUTTON_A
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_1_1] = 0;
            break;
          case 97: // KEYCODE_BUTTON_B
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_2_1] = 0;
            break;
          case 98: // KEYCODE_BUTTON_C
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_3_1] = 0;
            break;
          case 99: // KEYCODE_BUTTON_X
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_4_1] = 0;
            break;
          case 100: // KEYCODE_BUTTON_Y
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_5_1] = 0;
            break;
          case 101: // KEYCODE_BUTTON_Z
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_6_1] = 0;
            break;
          case 102: // KEYCODE_BUTTON_L1
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_7_1] = 0;
            break;
          case 103: // KEYCODE_BUTTON_R1
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_8_1] = 0;
            break;
          case 104: // KEYCODE_BUTTON_L2
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_9_1] = 0;
            break;
          case 105: // KEYCODE_BUTTON_R2
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_10_1] = 0;
            break;
          case 106: // KEYCODE_BUTTON_THUMBL
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_11_1] = 0;
            break;
          case 107: // KEYCODE_BUTTON_THUMBR
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_12_1] = 0;
            break;
          case 108: // KEYCODE_BUTTON_START
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_13_1] = 0;
            break;
          case 109: // KEYCODE_BUTTON_SELECT
            sstJoystick.astJoyInfoList[s32DeviceIndex].au8ButtonInfoList[orxJOYSTICK_BUTTON_14_1] = 0;
            break;
          default:
            orxDEBUG_PRINT(orxDEBUG_LEVEL_JOYSTICK, "unknown keycode %d", pstJoystickEvent->u32KeyCode);
            break;
        }
      }
      else
      {
        orxDEBUG_PRINT(orxDEBUG_LEVEL_JOYSTICK, "unknown device %d", pstJoystickEvent->u32DeviceId);
      }
      break;

    case orxANDROID_EVENT_JOYSTICK_MOVE:
      s32DeviceIndex = getDeviceIndex(pstJoystickEvent->u32DeviceId);

      if(s32DeviceIndex != -1)
      {
        sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_X_1] = pstJoystickEvent->stAxisData.fX;
        sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_Y_1] = pstJoystickEvent->stAxisData.fY;
        sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_Z_1] = pstJoystickEvent->stAxisData.fZ;
        sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_R_1] = pstJoystickEvent->stAxisData.fRZ;
        sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_U_1] = pstJoystickEvent->stAxisData.fHAT_X;
        sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_V_1] = pstJoystickEvent->stAxisData.fHAT_Y;
        sstJoystick.astJoyInfoList[s32DeviceIndex].afAxisInfoList[orxJOYSTICK_AXIS_POV_1] = pstJoystickEvent->stAxisData.fRTRIGGER != orxFLOAT_0 ? pstJoystickEvent->stAxisData.fRTRIGGER : -pstJoystickEvent->stAxisData.fLTRIGGER;
      }
      else
      {
        orxDEBUG_PRINT(orxDEBUG_LEVEL_JOYSTICK, "unknown device %d", pstJoystickEvent->u32DeviceId);
      }
      break;
  }

  /* Done! */
  return eResult;
}
Beispiel #20
0
DIOStreamSubsystem &DIOStreamSubsystem::close() {
	const int result = DIO_StreamClose( getDeviceIndex() );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	return *this;
}	// DIOStreamSubsystem::close()
Beispiel #21
0
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_xcsoar_InternalGPS_setLocation(JNIEnv *env, jobject obj,
                                        jlong time, jint n_satellites,
                                        jdouble longitude, jdouble latitude,
                                        jboolean hasAltitude, jdouble altitude,
                                        jboolean hasBearing, jdouble bearing,
                                        jboolean hasSpeed, jdouble ground_speed,
                                        jboolean hasAccuracy, jdouble accuracy,
                                        jboolean hasAcceleration, jdouble acceleration)
{
  unsigned index = getDeviceIndex(env, obj);

  ScopeLock protect(device_blackboard->mutex);
  NMEAInfo &basic = device_blackboard->SetRealState(index);
  basic.UpdateClock();
  basic.alive.Update(basic.clock);

  BrokenDateTime date_time = BrokenDateTime::FromUnixTimeUTC(time / 1000);
  double second_of_day = date_time.GetSecondOfDay() +
    /* add the millisecond fraction of the original timestamp for
       better accuracy */
    unsigned(time % 1000) / 1000.;

  if (second_of_day < basic.time &&
      basic.date_time_utc.IsDatePlausible() &&
      (BrokenDate)date_time > (BrokenDate)basic.date_time_utc)
    /* don't wrap around when going past midnight in UTC */
    second_of_day += 24u * 3600u;

  basic.time = second_of_day;
  basic.time_available.Update(basic.clock);
  basic.date_time_utc = date_time;

  basic.gps.satellites_used = n_satellites;
  basic.gps.satellites_used_available.Update(basic.clock);
  basic.gps.real = true;
  basic.gps.nonexpiring_internal_gps = true;
  basic.location = GeoPoint(Angle::Degrees(longitude),
                            Angle::Degrees(latitude));
  basic.location_available.Update(basic.clock);

  if (hasAltitude) {
    auto GeoidSeparation = EGM96::LookupSeparation(basic.location);
    basic.gps_altitude = altitude - GeoidSeparation;
    basic.gps_altitude_available.Update(basic.clock);
  } else
    basic.gps_altitude_available.Clear();

  if (hasBearing) {
    basic.track = Angle::Degrees(bearing);
    basic.track_available.Update(basic.clock);
  } else
    basic.track_available.Clear();

  if (hasSpeed) {
    basic.ground_speed = ground_speed;
    basic.ground_speed_available.Update(basic.clock);
  }

  if (hasAccuracy)
    basic.gps.hdop = accuracy;

  if (hasAcceleration)
    basic.acceleration.ProvideGLoad(acceleration, true);

  device_blackboard->ScheduleMerge();
}
Beispiel #22
0
// Returns the offset in the properties list to the first value for the device.
int32_t fiftyoneDegreesGetDeviceOffset(char* userAgent) {
    return getDeviceIndex(userAgent) * _propertiesCount;
}
Beispiel #23
0
//----------------------------------------------------------------------------//
SoundDevices::SoundDevices()
{
	ALDEVICEINFO	ALDeviceInfo;
	char *devices;
	int index;
	const char *defaultDeviceName;
	const char *actualDeviceName;

	// DeviceInfo vector stores, for each enumerated device, it's device name, selection status, spec version #, and extension support
	vDeviceInfo.empty();
	vDeviceInfo.reserve(10);

	defaultDeviceIndex = 0;

	// grab function pointers for 1.0-API functions, and if successful proceed to enumerate all devices

	if (alcIsExtensionPresent(nullptr, "ALC_ENUMERATION_EXT")) 
	{
		devices = (char *)alcGetString(nullptr, ALC_DEVICE_SPECIFIER);
		defaultDeviceName = (char *)alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
		index = 0;
		// go through device list (each device terminated with a single nullptr, list terminated with double nullptr)
		while (devices != nullptr) 
		{
			if (strcmp(defaultDeviceName, devices) == 0) 
			{
				defaultDeviceIndex = index;
			}
			ALCdevice *device = alcOpenDevice(devices);
			if (device) {
				ALCcontext *context = alcCreateContext(device, nullptr);
				if (context) {
					alcMakeContextCurrent(context);
					// if new actual device name isn't already in the list, then add it...
					actualDeviceName = alcGetString(device, ALC_DEVICE_SPECIFIER);
					bool bNewName = (getDeviceIndex(actualDeviceName) < 0);
					if ((bNewName) && (actualDeviceName != nullptr) && (strlen(actualDeviceName) > 0)) {
						memset(&ALDeviceInfo, 0, sizeof(ALDEVICEINFO));
						ALDeviceInfo.bSelected = true;
						ALDeviceInfo.strDeviceName = actualDeviceName;
						alcGetIntegerv(device, ALC_MAJOR_VERSION, sizeof(int), &ALDeviceInfo.iMajorVersion);
						alcGetIntegerv(device, ALC_MINOR_VERSION, sizeof(int), &ALDeviceInfo.iMinorVersion);

						ALDeviceInfo.pvstrExtensions = new std::vector<Ogre::String>;

						// Check for ALC Extensions
						if (alcIsExtensionPresent(device, "ALC_EXT_CAPTURE") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("ALC_EXT_CAPTURE");
						if (alcIsExtensionPresent(device, "ALC_EXT_EFX") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("ALC_EXT_EFX");

						// Check for AL Extensions
						if (alIsExtensionPresent("AL_EXT_OFFSET") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_OFFSET");

						if (alIsExtensionPresent("AL_EXT_LINEAR_DISTANCE") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_LINEAR_DISTANCE");
						if (alIsExtensionPresent("AL_EXT_EXPONENT_DISTANCE") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("AL_EXT_EXPONENT_DISTANCE");
						
						if (alIsExtensionPresent("EAX2.0") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("EAX2.0");
						if (alIsExtensionPresent("EAX3.0") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("EAX3.0");
						if (alIsExtensionPresent("EAX4.0") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("EAX4.0");
						if (alIsExtensionPresent("EAX5.0") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("EAX5.0");

						if (alIsExtensionPresent("EAX-RAM") == AL_TRUE)
							ALDeviceInfo.pvstrExtensions->push_back("EAX-RAM");

						// Get Source Count
						ALDeviceInfo.uiSourceCount = getMaxNumSources();

						vDeviceInfo.push_back(ALDeviceInfo);
					}
					alcMakeContextCurrent(nullptr);
					alcDestroyContext(context);
				}
				alcCloseDevice(device);
			}
			devices += strlen(devices) + 1;
			index += 1;
		}
	}

	resetFilters();
}
Beispiel #24
0
DIOStreamSubsystem &DIOStreamSubsystem::open( bool directionRead ) {
	const int result = DIO_StreamOpen( getDeviceIndex(), directionRead );
	if( result != AIOUSB_SUCCESS )
		throw OperationFailedException( result );
	return *this;
}	// DIOStreamSubsystem::open()
Beispiel #25
0
// Returns the offset in the properties list to the first value for the device.
int32_t getDeviceOffset(char* userAgent) {
    return getDeviceIndex(userAgent) * _propertiesCount;
}
Beispiel #26
0
gcc_visibility_default
JNIEXPORT void JNICALL
Java_org_xcsoar_InternalGPS_setLocation(JNIEnv *env, jobject obj,
                                        jlong time, jint n_satellites,
                                        jdouble longitude, jdouble latitude,
                                        jboolean hasAltitude, jdouble altitude,
                                        jboolean hasBearing, jdouble bearing,
                                        jboolean hasSpeed, jdouble ground_speed,
                                        jboolean hasAccuracy, jdouble accuracy,
                                        jboolean hasAcceleration, jdouble acceleration)
{
  unsigned index = getDeviceIndex(env, obj);

  ScopeLock protect(device_blackboard->mutex);
  NMEAInfo &basic = device_blackboard->SetRealState(index);
  basic.UpdateClock();
  basic.connected.Update(basic.clock);

  BrokenDateTime date_time = BrokenDateTime::FromUnixTimeUTC(time / 1000);
  fixed second_of_day = fixed(date_time.GetSecondOfDay()) +
    /* add the millisecond fraction of the original timestamp for
       better accuracy */
    fixed((unsigned)(time % 1000)) / 1000u;

  if (second_of_day < basic.time &&
      (BrokenDate)date_time > (BrokenDate)basic.date_time_utc)
    /* don't wrap around when going past midnight in UTC */
    second_of_day += fixed(24u * 3600u);

  basic.time = second_of_day;
  basic.time_available.Update(basic.clock);
  basic.date_time_utc = date_time;

  basic.gps.satellites_used = n_satellites;
  basic.gps.satellites_used_available.Update(basic.clock);
  basic.gps.real = true;
  basic.gps.android_internal_gps = true;
  basic.location = GeoPoint(Angle::Degrees(fixed(longitude)),
                            Angle::Degrees(fixed(latitude)));
  basic.location_available.Update(basic.clock);

  if (hasAltitude) {
    fixed GeoidSeparation = EGM96::LookupSeparation(basic.location);
    basic.gps_altitude = fixed(altitude) - GeoidSeparation;
    basic.gps_altitude_available.Update(basic.clock);
  } else
    basic.gps_altitude_available.Clear();

  if (hasBearing) {
    basic.track = Angle::Degrees(fixed(bearing));
    basic.track_available.Update(basic.clock);
  } else
    basic.track_available.Clear();

  if (hasSpeed) {
    basic.ground_speed = fixed(ground_speed);
    basic.ground_speed_available.Update(basic.clock);
  }

  if (hasAccuracy)
    basic.gps.hdop = fixed(accuracy);

  if (hasAcceleration) {
    // TODO: use ACCELERATION_STATE::complement() ?!?
    basic.acceleration.available = true;
    basic.acceleration.g_load = fixed(acceleration);
  }

  device_blackboard->ScheduleMerge();
}