irom static app_action_t application_function_i2c_sensor_calibrate(const string_t *src, string_t *dst)
{
	int intin;
	i2c_sensor_t sensor;
	double factor;
	double offset;

	if(parse_int(1, src, &intin, 0) != parse_ok)
	{
		string_cat(dst, "> invalid i2c sensor\n");
		return(app_action_error);
	}

	sensor = (i2c_sensor_t)intin;

	if(parse_float(2, src, &factor) != parse_ok)
	{
		string_cat(dst, "> invalid factor\n");
		return(app_action_error);
	}

	if(parse_float(3, src, &offset) != parse_ok)
	{
		string_cat(dst, "> invalid offset\n");
		return(app_action_error);
	}

	if(!i2c_sensor_setcal(sensor, factor, offset))
	{
		string_format(dst, "> invalid i2c sensor: %d\n", (int)sensor);
		return(app_action_error);
	}

	string_format(dst, "> i2c sensor %d calibration set to factor ", (int)sensor);
	string_double(dst, config.i2c_sensors.sensor[sensor].calibration.factor, 4, 1e10);
	string_cat(dst, ", offset: ");
	string_double(dst, config.i2c_sensors.sensor[sensor].calibration.offset, 4, 1e10);
	string_cat(dst, "\n");

	return(app_action_normal);
}
Example #2
0
int compute1(long double &a,string s,int angle=0)//算术综合运算
{
    if(!check_b(s))
        return 0;
    Stack<long double> ss(20);
    Stack<char> sf(20);
    int i=0,j;
    string s1,s2;
    char c;
    long double b;
    while(IsUselessChar(s[i]))
        i++;
    if(s[i]=='-')
    {
        ss.PushStack(-1);
        sf.PushStack('*');
        i++;
    }
    else if(s[i]=='+')
        i++;
    while(s[i])
    {
        s2="\0";
        if(IsUselessChar(s[i]))
            i++;
        else if(IsBracket(s[i])==1)
        {
            if(i>0&&!IsOperator1(s[i-1]))
                if(!sf.PushStack('*'))
                    return 0;
            s2=GetBracketData(s,i);
            if(!compute1(a,s2,angle)||!ss.PushStack(a))
                return 0;
        }
        else if(IsOperator1(s[i]))
        {
            if(s[i]=='!')
            {
                if(!ss.PopStack(b)||!factorial(a,(int)b)||!ss.PushStack(a))
                    return 0;
                i++;
                continue;
            }
            while(sf.GetTopData(c))
            {
                if(PRI(s[i])>PRI(c))
                    break;
                if(!ss.PopStack(b)||!ss.PopStack(a)||!sf.PopStack(c)||!Account1(a,b,c)||!ss.PushStack(a))
                    return 0;
            }
            if(!sf.PushStack(s[i++]))
                return 0;
        }
        else if(IsData(s[i])==1)
        {
            while(IsData(s[i])==1)
                s2+=s[i++];
            if(!ss.PushStack(string_double(s2)))
                return 0;
        }
        else if(s[i]=='S')
        {
            if(i>0&&!IsOperator1(s[i-1]))
                if(!sf.PushStack('*'))
                    return 0;
            s2="\0";
            for(j=0; j<4&&s[i]; j++,i++)
                s2+=s[i];
            if(s2!="Sqrt"||IsBracket(s[i])!=1)
                return 0;
            s2=GetBracketData(s,i);
            s1="\0";
            for(j=0; s2[j]; j++)
            {
                if(IsBracket(s2[j])==1)
                    s1+="("+GetBracketData(s2,j)+")";
                if(s2[j]==',')
                {
                    j++;
                    break;
                }
                else
                    s1+=s2[j];
            }
            if(!compute1(a,s1,angle))
                return 0;
            s1="\0";
            for(; s2[j]; j++)
                s1+=s2[j];
            if(!compute1(b,s1,angle)||!Sqrt(a,b)||!ss.PushStack(a))
                return 0;
        }
        else if(s[i]>='a'&&s[i]<='z'||s[i]=='L')
        {
            s1="\0";
            if(i>0&&!IsOperator1(s[i-1]))
                if(!sf.PushStack('*'))
                    return 0;
            while(s[i]>='a'&&s[i]<='z'||s[i]=='L'||s[i]=='^')
            {
                s1+=s[i++];
                if(s[i-1]=='e'&&s[i]!='^')
                    s1+='^';
            }
            if(s[i-1]=='e')
                s2="1";
            else if(IsBracket(s[i])==1)
                s2=GetBracketData(s,i);
            else if(IsData(s[i])==1)
            {
                while(s[i])
                {
                    if(IsData(s[i])==1)
                        s2+=s[i++];
                    else
                        break;
                }
            }
            else if(s[i]=='P'||s[i+1]=='i')
                s2="Pi";
            else if(s[i]=='S')
            {
                for(j=0; j<4&&s[i]; j++,i++)
                    s2+=s[i];
                if(s2!="Sqrt"||IsBracket(s[i])!=1)
                    return 0;
                s2+="("+GetBracketData(s,i)+")";
            }
            else
                return 0;
            if(!compute1(a,s2,angle)||!compute3(b,s1,a,angle)||!ss.PushStack(b))
                return 0;
        }
        else if(s[i]=='P')
        {
            if(i>0&&!IsOperator1(s[i-1])&&!sf.PushStack('*')||!ss.PushStack(P))
                return 0;
            i+=2;
        }
        else
            return 0;
    }
    while(sf.PopStack(c))
        if(!ss.PopStack(b)||!ss.PopStack(a)||!Account1(a,b,c)||!ss.PushStack(a))
            return 0;
    if(!ss.PopStack(a)||ss.State()>=0)
        return 0;
    return 1;
}