static void yas_work_func(struct work_struct *work)
{
	struct yas_data acc[1];
	struct yas_state *st =
		container_of((struct delayed_work *)work,
				struct yas_state, work);
	uint32_t time_before, time_after;
	int32_t delay;
	int ret, i;

	time_before = jiffies_to_msecs(jiffies);
	mutex_lock(&st->lock);
	ret = st->acc.measure(acc, 1);
	if (ret == 1) {
		for (i = 0; i < 3; i++)
			st->accel_data[i]
				= acc[0].xyz.v[i] - st->calib_bias[i];
	}
	mutex_unlock(&st->lock);

	IIF("%s: acc(x, y, z) = (%d, %d, %d)\n", __func__, st->accel_data[0]
		, st->accel_data[1], st->accel_data[2]);

	if (ret == 1)
		irq_work_queue(&st->iio_irq_work);
	time_after = jiffies_to_msecs(jiffies);
	delay = MSEC_PER_SEC / st->sampling_frequency
		- (time_after - time_before);
	if (delay <= 0)
		delay = 1;
	schedule_delayed_work(&st->work, msecs_to_jiffies(delay));
}
示例#2
0
/*!
  \param Func
*/
xbShort xbExpn::ProcessFunction( char * Func )
{
/* 1 - pop function from stack
   2 - verify function name and get no of parms needed 
   3 - verify no of parms >= remainder of stack
   4 - pop parms off stack
   5 - execute function
   6 - push result back on stack
*/


  char   *buf = 0;
  xbExpNode *p1, *p2, *p3, *WorkNode, *FuncNode;
  xbShort  ParmsNeeded,len;
  char   ptype = 0;  /* process type s=string, l=logical, d=double */
  xbDouble DoubResult = 0;
  xbLong   IntResult = 0;
  FuncNode = (xbExpNode *) Pop();

  ParmsNeeded = GetFuncInfo( Func, 1 );

  if( ParmsNeeded == -1 ) {
    return XB_INVALID_FUNCTION;
  }
  else {
    ParmsNeeded = 0;
    if( FuncNode->Sibling1 ) ParmsNeeded++;
    if( FuncNode->Sibling2 ) ParmsNeeded++;
    if( FuncNode->Sibling3 ) ParmsNeeded++;
  }

  if( ParmsNeeded > GetStackDepth())
    return XB_INSUFFICIENT_PARMS;

  p1 = p2 = p3 = NULL;
  if( ParmsNeeded > 2 ) p3 = (xbExpNode *) Pop(); 
  if( ParmsNeeded > 1 ) p2 = (xbExpNode *) Pop(); 
  if( ParmsNeeded > 0 ) p1 = (xbExpNode *) Pop(); 
  memset( WorkBuf, 0x00, WorkBufMaxLen+1);

  if( strncmp( Func, "ABS", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = ABS( GetDoub( p1 ));
  }
  else if( strncmp( Func, "ASC", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = ASC( p1->StringResult );
  }
  else if( strncmp( Func, "AT", 2 ) == 0 ) {  
    ptype = 'd';
    DoubResult = AT( p1->StringResult, p2->StringResult );
  }
  else if( strncmp( Func, "CDOW", 4 ) == 0 ) {  
    ptype = 's';
    buf = CDOW( p1->StringResult );
  }
  else if( strncmp( Func, "CHR", 3 ) == 0 ) {  
    ptype = 's';
    buf = CHR( GetInt( p1 ));
  }
  else if( strncmp( Func, "CMONTH", 6 ) == 0 ) {  
    ptype = 's';
    buf = CMONTH( p1->StringResult );
  }
  else if( strncmp( Func, "CTOD", 4 ) == 0 ) {  
    ptype = 's';
    buf = CTOD( p1->StringResult );
  }
  else if( strncmp( Func, "DATE", 4 ) == 0 ) {  
    ptype = 's';
    buf = DATE();
  }
  else if( strncmp( Func, "DAY", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = DAY( p1->StringResult );
  }
  else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'C' ) {  
    ptype = 's';
    buf = DESCEND( p1->StringResult.c_str() );
  }
  else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'N' ) {  
    ptype = 'd';
    DoubResult = DESCEND( GetDoub( p1 ));
  }
  else if( strncmp( Func, "DESCEND", 7 ) == 0 && p1->ExpressionType == 'D' ) {  
    xbDate d( p1->StringResult );
    ptype = 'd';
    DoubResult = DESCEND( d );
  }
  else if( strncmp( Func, "DOW", 3 ) == 0 ) {
    ptype = 'd';
    DoubResult = DOW( p1->StringResult );
  }
  else if( strncmp( Func, "DTOC", 4 ) == 0 ) {  
    ptype = 's';
    buf = DTOC( p1->StringResult );
  }
  else if( strncmp( Func, "DTOS", 4 ) == 0 ) {  
    ptype = 's';
    buf = DTOS( p1->StringResult );
  }
  else if( strncmp( Func, "EXP", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = EXP( GetDoub( p1 ));
  }
  else if( strncmp( Func, "IIF", 3 ) == 0 ){
    ptype = 's';
    buf = IIF( p1->IntResult, p2->StringResult, p3->StringResult );
  }
  else if( strncmp( Func, "INT", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = INT( GetDoub( p1 ));
  }
  else if( strncmp( Func, "ISALPHA", 7 ) == 0 ) {  
    ptype = 'l';
    IntResult = ISALPHA( p1->StringResult );
  }
  else if( strncmp( Func, "ISLOWER", 7 ) == 0 ) {  
    ptype = 'l';
    IntResult = ISLOWER( p1->StringResult );
  }
  else if( strncmp( Func, "ISUPPER", 7 ) == 0 ) {  
    ptype = 'l';
    IntResult = ISUPPER( p1->StringResult );
  }
  else if( strncmp( Func, "LEN", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = LEN( p1->StringResult );
  }
  else if( strncmp( Func, "LEFT", 4 ) == 0 ) {  
    ptype = 's';
    buf = LEFT( p1->StringResult, INT( p2->DoubResult ));
  }
  else if( strncmp( Func, "LTRIM", 5 ) == 0 ) {  
    ptype = 's';
    buf = LTRIM( p1->StringResult );
  }  
  else if( strncmp( Func, "LOG", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = LOG( GetDoub( p1 ));
  }  
  else if( strncmp( Func, "LOWER", 5 ) == 0 ) {  
    ptype = 's';
    buf = LOWER( p1->StringResult );
  }  
  else if( strncmp( Func, "MAX", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = MAX( GetDoub( p1 ), GetDoub( p2 ));
  }  
  else if( strncmp( Func, "MIN", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = MIN( GetDoub( p1 ), GetDoub( p2 ));
  }  
  else if( strncmp( Func, "MONTH", 5 ) == 0 ) {  
    ptype = 'd';
    DoubResult = MONTH( p1->StringResult );
  } 

  else if( strncmp( Func, "RECNO", 5 ) == 0 )
  {
    ptype = 'd';
    DoubResult = RECNO( FuncNode->dbf );
  }

  else if( strncmp( Func, "REPLICATE", 9 ) == 0 ) {
    ptype = 's';
    buf = REPLICATE( p1->StringResult, GetInt( p2 ));
  }
  else if( strncmp( Func, "RIGHT", 5 ) == 0 ) {
    ptype = 's';
    buf = RIGHT( p1->StringResult, GetInt( p2 ));
  }
  else if( strncmp( Func, "RTRIM", 5 ) == 0 ) {  
    ptype = 's';
    buf = RTRIM( p1->StringResult );
  }  
  else if( strncmp( Func, "SPACE", 5 ) == 0 ) {  
    ptype = 's';
    buf = SPACE( INT( GetDoub( p1 )));
  }
  else if( strncmp( Func, "SQRT", 4 ) == 0 ) {  
    ptype = 'd';
    DoubResult = SQRT( GetDoub( p1 ));
  }
  else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 1 ) {
    ptype = 's';
    buf = STRZERO( p1->StringResult );
  }   
  else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 2 ) {
    ptype = 's';
    buf = STRZERO( p1->StringResult, GetInt( p2 ));
  }   
  else if( strncmp( Func, "STRZERO", 7 ) == 0 && ParmsNeeded == 3 ) {
    ptype = 's';
    buf = STRZERO( p1->StringResult, GetInt( p2 ), GetInt( p3 ));
  }   

  else if( strncmp( Func, "STR", 3 ) == 0 && p3 ) {
    ptype = 's';
    if(p1->ExpressionType == 'N')
      buf = STR( p1->DoubResult, GetInt( p2 ), GetInt( p3 ));
    else
      buf = STR( p1->StringResult, GetInt( p2 ), GetInt( p3 ));
  }   

  else if( strncmp( Func, "STR", 3 ) == 0 && p2 ) {
    ptype = 's';
    buf = STR( p1->StringResult, GetInt( p2 ));
  }

  else if( strncmp( Func, "STR", 3 ) == 0 && p1 ) {
    ptype = 's';
    buf = STR( p1->StringResult );
  }
   
  else if( strncmp( Func, "SUBSTR", 6 ) == 0 ) {
    ptype = 's';
    buf = SUBSTR( p1->StringResult, GetInt( p2 ), GetInt( p3 )); 
  }
  else if( strncmp( Func, "TRIM", 4 ) == 0 ) {  
    ptype = 's';
    buf = TRIM( p1->StringResult );
  }  
  else if( strncmp( Func, "UPPER", 5 ) == 0 ) {  
    ptype = 's';
    buf = UPPER( p1->StringResult );
  }  
  else if( strncmp( Func, "VAL", 3 ) == 0 ) {  
    ptype = 'd';
    DoubResult = VAL( p1->StringResult );
  }  
  else if( strncmp( Func, "YEAR", 4 ) == 0 ) {  
    ptype = 'd';
    DoubResult = YEAR( p1->StringResult );
  }  
  if( p1 && !p1->InTree ) delete p1;
  if( p2 && !p2->InTree ) delete p2;
  if( p3 && !p3->InTree ) delete p3;
  if( !FuncNode->InTree ) delete FuncNode;
  if( buf ){
    len = strlen( buf );
    WorkNode = new xbExpNode;
    if( !WorkNode )
      return XB_NO_MEMORY;
    WorkNode->ResultLen = len + 1;
    
  } else {    
    len = 0;
    WorkNode = new xbExpNode;
    if( !WorkNode )
      return XB_NO_MEMORY;
    WorkNode->ResultLen = 0;
  }

  switch( ptype ){
   case 's':                               /* string or char result */
    WorkNode->DataLen = len;
    WorkNode->ExpressionType = 'C';
    WorkNode->Type = 's';
    WorkNode->StringResult = buf;
    break;
   case 'd':                               /* numeric result */
    WorkNode->DataLen = 0;
    WorkNode->ExpressionType = 'N';
    WorkNode->Type = 'd';
    WorkNode->DoubResult = DoubResult;
    break;
   case 'l':                               /* logical result */
    WorkNode->DataLen = 0;
    WorkNode->ExpressionType = 'L';
    WorkNode->Type = 'l';
    WorkNode->IntResult = IntResult;
    break;
   default:
    std::cout << "\nInternal error. " << ptype;
    break;
  }
  Push(WorkNode);
  return XB_NO_ERROR;
}