int getDevice(struct sensor_extend_t list[], struct sensor_info *info, 
                char buf[], char classPath[], int number )
{
        int ret = 0;
        
        if ((!strlen(buf)) || (list == NULL)) {
                return 0;
        }
             
        while(ret < number){
                if (!strncmp(buf, list[ret].sensors.name, strlen(buf))) {
                        
                        info->priData = list[ret].sensors.lsg;		                            	                             
            		setSensorData(sNumber, &list[ret].sList);
            		
                        strncpy(info->sensorName, buf,strlen(buf));
                        strncpy(info->classPath, classPath, strlen(classPath));
                        #ifdef DEBUG_SENSOR
                                ALOGD("sensorName:%s,classPath:%s,lsg:%f\n",
                                       info->sensorName,info->classPath, info->priData);
                        #endif
               
            		return 1 ;
                }
                ret++;
        }
                
        return 0;
        
}
예제 #2
0
void tgPIDController::control(double dt, double setPoint, double sensorData)
{
	if (dt <= 0.0)
	{
		throw std::runtime_error ("Timestep must be positive.");
	}
	
	setSensorData(sensorData);
	setNewSetPoint(setPoint);
	control(dt);
}
int searchDevice(char buf[], char classPath[])
{       
        int ret = 0;
        
        if(!found) {
                found = otherDeviceDetect(buf);
                
                #ifdef DEBUG_SENSOR                
                        ALOGD("found:%d\n", found);
                #endif
                
                if(found == 1) {
                        found = 0;
                        return 1;
                }else if(found == 2) {
                        return 1;
                }
        }

        if((seStatus[ID_A].isUsed == true) && (seStatus[ID_A].isFound == false)) {
                
                ret = getDevice(gsensorList, &gsensorInfo, buf, classPath, 
                        ARRAY_SIZE(gsensorList));
                
                if(ret == 1){
                        seStatus[ID_A].isFound = true;
                        sNumber++; 
                        return 1;     
                }      
        }

        
        if((seStatus[ID_M].isUsed == true) && (seStatus[ID_M].isFound == false)) {
                ret = getDevice(magSensorList, &magSensorInfo, buf, classPath, 
                        ARRAY_SIZE(magSensorList));
                
                if(ret == 1){
                        seStatus[ID_M].isFound = true;
                        sNumber++;
                        
                        if(!strncmp(buf, magSensorList[1].sensors.name, strlen(buf))) {
                                setSensorData(sNumber, &oriSensorList[0].sList);
                                sNumber++;
                        }
                        return 1;
                }       
        }
                
        if((seStatus[ID_GY].isUsed == true) && (seStatus[ID_GY].isFound == false)) { 
                ret = getDevice(gyrSensorList, &gyrSensorInfo, buf, classPath, 
                        ARRAY_SIZE(gyrSensorList));
                        
                if(ret == 1){
                        seStatus[ID_GY].isFound = true;
                        sNumber++;
                        return 1;    
                }       
        }
        
        if((seStatus[ID_L].isUsed == true) && (seStatus[ID_L].isFound == false)) {
                ret = getDevice(ligSensorList, &ligSensorInfo, buf, classPath, 
                        ARRAY_SIZE(ligSensorList));
                        
                if(ret == 1){
                        seStatus[ID_L].isFound = true;
                        sNumber++;
                        return 1;    
                }       
        }
        
        if((seStatus[ID_P].isUsed == true) && (seStatus[ID_P].isFound == false)) {
                ret = getDevice(proSensorList, &proSensorInfo, buf, classPath, 
                        ARRAY_SIZE(proSensorList));
                        
                if(ret == 1){
                        seStatus[ID_P].isFound = true;
                        sNumber++;
                        return 1;    
                }       
        }
        
        return 0;
}