//Process Input Data
void VoiceRecognitionShield::processData()
{
	byte functionID = getOneSheeldInstance().getFunctionId();

	if(functionID==VOICE_GET)
	{
		if (voice!=0)
		{
			free(voice);
		}
		
		voicetextLength=getOneSheeldInstance().getArgumentLength(0);
		voice = (char*)malloc(sizeof(char)*(voicetextLength+1));
		for (int j=0; j<voicetextLength; j++)
		{
			voice[j]=getOneSheeldInstance().getArgumentData(0)[j];
		}
		voice[voicetextLength]='\0';

		
		newCommand=true;

		//Invoke Users function
		if(!isInACallback())
		{
			if(isCallBackAssigned)
			{
				enteringACallback();
				(*changeCallBack)(voice);
				exitingACallback();
			}
			//Invoke Users function
			if (usedSetOnWithString)
			{
				String convertedIncomingVoice (voice);
				enteringACallback();
				(*changeCallBackString)(convertedIncomingVoice);
				exitingACallback();
			}
		}

	}
	else if(functionID==VOICE_GET_ERROR && !isInACallback())
	{
		errorNumber=getOneSheeldInstance().getArgumentData(0)[0];
		//Invoke User Function
		if(errorAssigned)
		{
			enteringACallback();
			(*errorCallBack)(errorNumber);
			exitingACallback();
		}
	}
}
//Twitter Input Data Processing
void TwitterShieldClass::processData()
{
	//Checking Function-ID
	byte functionId = getOneSheeldInstance().getFunctionId();
	if( functionId == TWITTER_GET_TWEET)
	{	
		isItNewTweet = true;
		if(userName!=0)
		{
			free(userName);
		}
		if (tweetText!=0)
		{
			free(tweetText);
		}
		int userNameLength=getOneSheeldInstance().getArgumentLength(0);
		userName = (char*)malloc(sizeof(char)*(userNameLength+1));
		for (int j=0; j<userNameLength; j++)
		{
			userName[j]=getOneSheeldInstance().getArgumentData(0)[j];
		}
		userName[userNameLength]='\0';

		int tweetLength=getOneSheeldInstance().getArgumentLength(1);
		tweetText = (char*)malloc(sizeof(char)*(tweetLength+1));

		for(int i=0 ;i<tweetLength;i++)
		{
			tweetText[i]=getOneSheeldInstance().getArgumentData(1)[i];
		}
			tweetText[tweetLength]='\0';
		//Users Function Invoked
		if(!isInACallback())
		{
			if(isCallBackAssigned)
			{
				enteringACallback();
				(*changeCallBack)(userName,tweetText);
				exitingACallback();
			}

			if(usedSetOnWithString)
			{
				String usernameString(userName);
				String tweetTextString(tweetText);
				enteringACallback();
				(*changeCallBackString)(usernameString,tweetTextString);
				exitingACallback();
			}
		}
	}
}
//Phone Input Data Processing 
void PhoneShieldClass::processData()
{
	//Checking Function-ID
	byte functionId= getOneSheeldInstance().getFunctionId();

	if (functionId==PHONE_IS_RINGING)
	{
		value =getOneSheeldInstance().getArgumentData(0)[0];
	}
	else if (functionId==PHONE_GET_NUMBER)
	{
		if(number!=0)
		{
			free(number);
		}
		
		byte length=getOneSheeldInstance().getArgumentLength(0);
		
		number=(char*)malloc(sizeof(char)*(length+1));
		
		for (int i=0; i< length;i++)
			{
				number[i]=getOneSheeldInstance().getArgumentData(0)[i];
			}

			number[length]='\0';
			//Users Function Invoked
			if(!isInACallback())
			{
				if (isCallBackAssigned)
				{
					enteringACallback();
					(*changeCallBack)(value,number);
					exitingACallback();
				}
				if(usedSetOnString)
				{
					enteringACallback();
					String phoneNumberAsString(number);
					(*changeCallBackString)(value,phoneNumberAsString);
					exitingACallback();
				}
			}
	}
}
Esempio n. 4
0
//Phone Input Data Processing 
void PushButtonShield::processData()
{
	//Checking Function-ID
	byte functionId =getOneSheeldInstance().getFunctionId();
	if(functionId==PUSHBUTTON_VALUE)
	{
		value=getOneSheeldInstance().getArgumentData(0)[0];
		//Users Function Invoked
		if(isCallBackAssigned && !isInACallback())
		{
			enteringACallback();
			(*changeCallBack)(!!value);
			exitingACallback();
		}
	}
}
//Keypad Input Data Processing
void KeypadShieldClass::processData()
{
  //Checking Function-ID
  byte functionId=getOneSheeldInstance().getFunctionId();
  if (functionId==KEYPAD_VALUE)
   { 
     row=getOneSheeldInstance().getArgumentData(0)[0];
     col=getOneSheeldInstance().getArgumentData(1)[0];
     //Users Function Invoked
     if (isCallbackAssigned && !isInACallback())
      {
        enteringACallback();
        (*buttonChangeCallback)(row,col);
        exitingACallback();
      }
   }
}
//Keyboard Input Data Processing 
void KeyboardShield::processData()
{
	//Checking Function-ID
	byte functionId=getOneSheeldInstance().getFunctionId();
	if (functionId==KEYBOARD_GET_CHAR)
	{
		
		character=getOneSheeldInstance().getArgumentData(0)[0];
		//Users Function Invoked
		if(isCallBackAssigned && !isInACallback())
		{
			enteringACallback();
			(*buttonChangeCallBack)(character);
			exitingACallback();
		}
	}
}
//GamePad Input Data Processing  
void GamePadShield::processData()
{
	//Checking Function-ID
	byte functionId =getOneSheeldInstance().getFunctionId();
	if(functionId==GAMEPAD_VALUE)
	{
		value=getOneSheeldInstance().getArgumentData(0)[0];
		//Users Function Invoked
		if(isCallBackAssigned && !isInACallback())
		{
			enteringACallback();
			(*buttonChangeCallBack)(!!(value & (1<<UP_BIT)),      !!(value & (1<<DOWN_BIT)),
									!!(value & (1<<LEFT_BIT)), 	  !!(value & (1<<RIGHT_BIT)),
									!!(value & (1<<ORANGE_BIT)),  !!(value & (1<<RED_BIT)), 
									!!(value & (1<<GREEN_BIT)),   !!(value & (1<<BLUE_BIT)));
			exitingACallback();
		}
	}
}
Esempio n. 8
0
//GPS Input Data Processing 
void GPSShieldClass::processData ()
{
	//Checking Function-ID
	byte functionId=getOneSheeldInstance().getFunctionId();
	if(functionId==GPS_VALUE)
	{

		LatValue=getOneSheeldInstance().convertBytesToFloat(getOneSheeldInstance().getArgumentData(0));

		LonValue=getOneSheeldInstance().convertBytesToFloat(getOneSheeldInstance().getArgumentData(1));

		isInit=true;  									//setting a flag 
	}
	//Users Function Invoked
	if (isCallBackAssigned && !isInACallback())
	{
		enteringACallback();
		(*changeCallBack)(LatValue,LonValue);
		exitingACallback();
	}
}
Esempio n. 9
0
//Light Input Data Processing
void LightSensorShield::processData()
{
	//Checking Function-ID
	byte functionId =getOneSheeldInstance().getFunctionId();
	if(functionId==LIGHT_VALUE)
	{
		value=0;
		data[0]=getOneSheeldInstance().getArgumentData(0)[0];
		data[1]=getOneSheeldInstance().getArgumentData(0)[1];
		data[2]=getOneSheeldInstance().getArgumentData(0)[2];
		value|=data[0];
		value|=(data[1]<<8);
		value|=(data[2]<<16);
		//Users Function Invoked
		if(isCallBackAssigned && !isInACallback())
		{
			enteringACallback();
			(*changeCallBack)(value);
			exitingACallback();
		}
	}
}
//MagnetometerSensor Data processing 	
void MagnetometerSensorShield::processData()
{
	//Check Function-ID
	byte functionId=getOneSheeldInstance().getFunctionId();
	
		if(functionId==MAGNETOMETER_VALUE)
		{
			//Process X-Axis Value
			valueX=getOneSheeldInstance().convertBytesToFloat(getOneSheeldInstance().getArgumentData(0));
			//Process Y-Axis Value
			valueY=getOneSheeldInstance().convertBytesToFloat(getOneSheeldInstance().getArgumentData(1));
			//Process Z-Axis Value
			valueZ=getOneSheeldInstance().convertBytesToFloat(getOneSheeldInstance().getArgumentData(2));
			
			//User Function Invoked
			if(isCallBackAssigned && !isInACallback())
			{
				enteringACallback();
				(*changeCallBack)(valueX,valueY,valueZ);
				exitingACallback();
			}
		}
}
Esempio n. 11
0
void OneSheeldClass::processRemoteData()
{
  byte functionId = getFunctionId();

  if(functionId == READ_MESSAGE_FLOAT)
  {
    char remoteAddress[37];
    memcpy(remoteAddress,getArgumentData(0),36);
    remoteAddress[36]='\0';  // processed the remote address 

    int keyLength = getArgumentLength(1);
    char key[keyLength+1];
    memcpy(key,getArgumentData(1),keyLength);
    key[keyLength]='\0';

    float incomingValue = convertBytesToFloat(getArgumentData(2));

    if(!isInACallback())
    {
      if(isSetOnFloatMessageInvoked)
      {
        enteringACallback();
        (*changeFloatCallBack)(remoteAddress,key,incomingValue);
        exitingACallback();
      }

      if(usedSetOnFloatWithString)
      {
        String remoteAddressInString(remoteAddress);
        String keyInString(key);
        enteringACallback();
        (*changeFloatCallBackWithString)(remoteAddressInString,keyInString,incomingValue);
        exitingACallback();
      }
    }

  }
  else if(functionId == READ_MESSAGE_STRING)
  {
    char remoteAddress[37];
    memcpy(remoteAddress,getArgumentData(0),36);
    remoteAddress[36]='\0';  // processed the remote address 

    int keyLength = getArgumentLength(1);
    char key[keyLength+1];
    memcpy(key,getArgumentData(1),keyLength);
    key[keyLength]='\0';
    
    int stringDataLength = getArgumentLength(2);
    char stringData[stringDataLength+2];
    memcpy(stringData,getArgumentData(2),stringDataLength);
    stringData[stringDataLength]='\0';

    if(!isInACallback())
    {    
      if(isSetOnStringMessageInvoked)
      {
        enteringACallback();
        (*changeStringCallBack)(remoteAddress,key,stringData);
        exitingACallback();
      }

      if(usedSetOnStringWithString)
      {
        String remoteAddressInString(remoteAddress);
        String keyInString(key);
        String stringDataInString(stringData);
        enteringACallback();
        (*changeStringCallBackWithString)(remoteAddressInString,keyInString,stringDataInString);
        exitingACallback();
      }
    }
  }
}
void FaceDetectionShield::processData()
{
	byte functionId = getOneSheeldInstance().getFunctionId();

	if(functionId == FACE_GET)
	{
		int currentFaceID = getOneSheeldInstance().getArgumentData(0)[0]|((getOneSheeldInstance().getArgumentData(0)[1])<<8);
		int currentX = getOneSheeldInstance().getArgumentData(1)[0]|((getOneSheeldInstance().getArgumentData(1)[1])<<8);
		int currentY = getOneSheeldInstance().getArgumentData(1)[2]|((getOneSheeldInstance().getArgumentData(1)[3])<<8);
		unsigned int currentHeight = getOneSheeldInstance().getArgumentData(2)[0]|((getOneSheeldInstance().getArgumentData(2)[1])<<8);
		unsigned int currentWidth = getOneSheeldInstance().getArgumentData(2)[2]|((getOneSheeldInstance().getArgumentData(2)[3])<<8);
		int i;
		byte currentRightEye = getOneSheeldInstance().getArgumentData(3)[0];
		byte currentLeftEye = getOneSheeldInstance().getArgumentData(3)[1];
		byte currentSmile = getOneSheeldInstance().getArgumentData(3)[2];

		for(i =0 ;i <MAX_FACES;i++)
		{
			if(facesArray[i].faceID==currentFaceID)
			{
				facesArray[i].leftEyeOpened = currentLeftEye;
				facesArray[i].rightEyeOpened = currentRightEye;
				facesArray[i].smiling = currentSmile;
				facesArray[i].xCoordinate = currentX;
				facesArray[i].yCoordinate = currentY;
				facesArray[i].faceWidth = currentWidth;
				facesArray[i].faceHeight = currentHeight;
				break;
			}
		}

		if(i == MAX_FACES)
		{
			i=0;
			while(facesArray[i].faceID>= 0 && i<MAX_FACES)
			{
				i++;
			}
			facesArray[i].faceID = currentFaceID;
			facesArray[i].leftEyeOpened = currentLeftEye;
			facesArray[i].rightEyeOpened = currentRightEye;
			facesArray[i].smiling = currentSmile;
			facesArray[i].xCoordinate = currentX;
			facesArray[i].yCoordinate = currentY;
			facesArray[i].faceWidth = currentWidth;
			facesArray[i].faceHeight = currentHeight;
			counter++;
		}

		if(!isInACallback())
		{
			if(onNewFaceCallback)
			{
				enteringACallback();
				(*onNewFaceCallback)(facesArray[i]);
				exitingACallback();
			}
		}
	}else if(functionId == FACE_OUT_OF_BOUNDS)
	{
		int currentFaceID = getOneSheeldInstance().getArgumentData(0)[0]|((getOneSheeldInstance().getArgumentData(0)[1])<<8);
		for( int i =0 ;i <MAX_FACES;i++)
		{
			if(facesArray[i].faceID==currentFaceID)
			{
				eraseFaceData(i);
				if(counter!=0){counter--;}
				break;
			}
		}
		rearrangeFaces();
		if(!isInACallback())
		{
			if(isdeletedAssigned)
			{
				enteringACallback();
				(*onDeletedFaceCallback)(currentFaceID);
				exitingACallback();
			}
		}
	}
}
//Process Input Data
void BarcodeScannerShield::processData()
{
	byte functionID = getOneSheeldInstance().getFunctionId();

	if(functionID==BARCODE_GET_1D)
	{
		isNewBarcode = true;
		barcodeFormat = getOneSheeldInstance().getArgumentData(0)[0];
		barcodeMaxLength = getOneSheeldInstance().getArgumentData(1)[0]|((getOneSheeldInstance().getArgumentData(1)[1])<<8);

		if (barcodeData!=0)
		{
			free(barcodeData);
		}
		
		barcodeDataLength=getOneSheeldInstance().getArgumentLength(2);
		index = barcodeDataLength;
		barcodeData = (char*)malloc(sizeof(char)*(barcodeDataLength+1));
		for (int j=0; j<barcodeDataLength; j++)
		{
			barcodeData[j]=getOneSheeldInstance().getArgumentData(2)[j];
		}
		barcodeData[barcodeDataLength]='\0';
		//Invoke Users function
		if(!isInACallback())
		{
			if(isCallbackAssigned)
			{
				enteringACallback();
				(*barcodeCallback)(barcodeFormat,NO_CATEGORY,barcodeMaxLength,barcodeData);
				exitingACallback();
			}
		}

	}
	else if(functionID==BARCODE_GET_2D)
	{
		isNewBarcode = true;
		barcodeFormat = getOneSheeldInstance().getArgumentData(0)[0];
		barcodeCategory = getOneSheeldInstance().getArgumentData(1)[0];
		barcodeMaxLength = getOneSheeldInstance().getArgumentData(2)[0]|((getOneSheeldInstance().getArgumentData(2)[1])<<8);

		if (barcodeData!=0)
		{
			free(barcodeData);
		}
		
		barcodeDataLength=getOneSheeldInstance().getArgumentLength(3);
		index= barcodeDataLength;
		barcodeData = (char*)malloc(sizeof(char)*(barcodeDataLength+1));
		for (int j=0; j<barcodeDataLength; j++)
		{
			barcodeData[j]=getOneSheeldInstance().getArgumentData(3)[j];
		}
		barcodeData[barcodeDataLength]='\0';

		//Invoke Users function
		if(!isInACallback())
		{
			if(isCallbackAssigned)
			{
				enteringACallback();
				(*barcodeCallback)(barcodeFormat,barcodeCategory,barcodeMaxLength,barcodeData);
				exitingACallback();
			}
		}
	}
	else if(functionID==BARCODE_GET_NEXT && !isInACallback())
	{
		isNext= true;
		if (barcodeData!=0)
		{
			free(barcodeData);
		}
		barcodeDataLength=getOneSheeldInstance().getArgumentLength(0);
		index+=barcodeDataLength;
		barcodeData = (char*)malloc(sizeof(char)*(barcodeDataLength+1));
		for (int j=0; j<barcodeDataLength; j++)
		{
			barcodeData[j]=getOneSheeldInstance().getArgumentData(0)[j];
		}
		barcodeData[barcodeDataLength]='\0';
		//Invoke User Function
		if(isNextDataResponseCallbackAssigned)
		{
			enteringACallback();
			(*nextDataResponseCallback)(barcodeDataLength,barcodeData);
			exitingACallback();
		}
	}
	else if(functionID==BARCODE_GET_PARAMETER && !isInACallback())
	{
		byte parameterLength = getOneSheeldInstance().getArgumentLength(0);
		byte valueLength = getOneSheeldInstance().getArgumentLength(1);
		char  parameter[parameterLength+1];
		char  value[valueLength+1];
		
		for (int j=0; j<parameterLength; j++)
		{
			parameter[j]=getOneSheeldInstance().getArgumentData(0)[j];
		}
		parameter[parameterLength]='\0';
		for (int j=0; j<valueLength; j++)
		{
			value[j]=getOneSheeldInstance().getArgumentData(1)[j];
		}
		value[valueLength]='\0';
		//Invoke User Function
		if(isParameterCallbackAssigned)
		{
			enteringACallback();
			(*parameterValueCallback)(parameter,value);
			exitingACallback();
		}
	} 
	else if(functionID==BARCODE_GET_ERROR && !isInACallback())
	{
		errorNumber=getOneSheeldInstance().getArgumentData(0)[0];
		//Invoke User Function
		if(isErrorCallbackAssigned)
		{
			enteringACallback();
			(*errorCallback)(errorNumber);
			exitingACallback();
		}
	}
}