/****************************************************************************
** File name    :  HTUnit.cpp
** Description  :  units changes for API
** Create date  :  2018.09.01
** Auther by    :  Liuyx
** Version info :  V1.0.01
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
** Update record:  
** DATE         AUTHER   DESC 
** -------------------------------------------------------------------------               
** 2018.09.01   Liuyx    first build
****************************************************************************/
#include "HTGlobal.h"

static const char *_FILE_ = "HTUnit.cpp" ;

//1:kV(千伏) 2 : V(伏) 3 : kA(千安) 4 : A(安) 5 : mA(毫安) 6 : ℃(度) 7 : Pa(帕) 8 : KPa(千帕) 9 : MPa(兆帕) 10 : pF(皮法-电容单位)
//11 : pC(皮库仑-电量单位) 12 : dB(分贝) 13 : μL(微升) 14 : mL(毫升) 15 : L(升) 16 : m / s(米 / 秒) 17 : rpm&r / min(转 / 分钟)

// 单位转换
double getChangeUnit(short Unit, short sysUnit, double val)
{
    double retval = val;
    switch (Unit)
    {
    case 1:   // kV
        if (sysUnit == 2) {
            retval = val * 1000;
        }
        break;
    case 2: // V
        if (sysUnit == 1) {
            retval = val / 1000;
        }
        break;
    case 3:  // kA
        if (sysUnit == 4) {  //A
            retval = val * 1000; 
        }
        else if (sysUnit == 5) { // mA
            retval = val * 1000 * 1000;
        }
        break;
    case 4: // A
        if (sysUnit == 3) {  //kA
            retval = val / 1000;
        }
        else if (sysUnit == 5) { // mA
            retval = val * 1000 ;
        }
        break;
    case 5: // mA
        if (sysUnit == 3) {  //kA
            retval = val / 1000 / 1000;
        }
        else if (sysUnit == 4) { // A
            retval = val / 1000;
        }
        break;
    case 6: //摄氏度
        //if (sysUnit == 26) ////华氏度
        //    retval = (val - 32 / 1.800f);
        break;
    case 7:  //Pa 
        if (sysUnit == 8) //KPa
            retval = (val / 1000 );
        else if (sysUnit == 9) //MPa
            retval = (val / 1000 / 1000);
        break;
    case 8:  //KPa
        if (sysUnit == 7) //Pa
            retval = (val * 1000);
        else if (sysUnit == 9) //MPa
            retval = (val / 1000 );
        break;
    case 9:  //MPa
        if (sysUnit == 7) //Pa
            retval = (val * 1000 * 1000);
        else if (sysUnit == 8) //KPa
            retval = (val * 1000);
        break;
    case 13: //μL
        if (sysUnit == 14) // mL
            retval = val / 1000;
        else if (sysUnit == 15) // L
            retval = val / 1000 / 1000;
        break;
    case 14: //mL
        if (sysUnit == 13) // μL
            retval = val * 1000;
        else if (sysUnit == 15) // L
            retval = val / 1000;
        break;
    case 15: //L
        if (sysUnit == 13) // μL
            retval = val * 1000 * 1000;
        else if (sysUnit == 14) // mL
            retval = val * 1000;
        break;
    default:;
    }
    return retval;
}
//（1）1法拉(F) = 1000毫法(mF)
//
//（2）1毫法(mF) = 1000微法(μF)
//
//（3）1微法(μF) = 1000纳法(nF)
//
//（4）1纳法(nF) = 1000皮法(pF)



// 比较double之差是否大于rate.
// return : >  true   <= : false
bool bCompare(double ov, double nv, double rate)
{
    double d= ((abs(nv - ov) / ov) * 100);
    return  d > rate ? true : false;
}


