teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

HbUserOpe.cpp

Committer:
MasashiNomura
Date:
2018-12-22
Revision:
34:234b87f3e6ce
Parent:
33:eb260dbfc22a
Child:
36:2cc739c7e4cb

File content as of revision 34:234b87f3e6ce:

#include "HbUserOpe.h"
#include "fpga.h"
//=========================================
//コンストラクタ
//=========================================
HbUserOpe::HbUserOpe(){
    oldOpe.w = curOpe.w = 0;
    AinAxlVal = 0;
}

//=========================================
//デストラクタ
//=========================================
HbUserOpe::~HbUserOpe(){
}

typUserSw HbUserOpe::GetUserOpe()
{
    oldOpe = curOpe;
    curOpe.w = fpgaGetUserSw();
    return curOpe;
}
INT16 HbUserOpe::GetAinAccel()
{
    // max rpm 8500 ユーザー使用分として7000をマックスとする(仮)
    // 0 ~ 1.00 -> 0.01 ~ 0.97を使用する(遊び分として)
    INT16 ret = 0;
    AinAxlVal = AinAxl.read();
    if(MIN_EFF_ANA_VAL > AinAxlVal){
        ret = 0;
    } else if(AinAxlVal >= MIN_EFF_ANA_VAL && AinAxlVal <= MAX_EFF_ANA_VAL){
        ret = (MAX_RPM_USERSET - MIN_RPM_TOTAL) * (AinAxlVal - MIN_EFF_ANA_VAL) / (MAX_EFF_ANA_VAL - MIN_EFF_ANA_VAL) + MIN_RPM_TOTAL;
    } else if(AinAxlVal > MAX_EFF_ANA_VAL){
        ret = MAX_RPM_USERSET;
    }else{
        ret = 0;
    }
    if(gf_DbgPrint.bf.ana1 == true){
        sp.printf("Axl Rpm=%d val=%f\r\n",ret,AinAxlVal);
        gf_DbgPrint.bf.ana1 = false;
    }
    //sp.printf("Axl Rpm=%d val=%f\r\n",ret,anaval);
    return ret;
}

bool HbUserOpe::ChkCtrlSW(SW_TYPE styp)
{
            if(styp == BRK_L)   {return curOpe.bf.brk_l;}
    else    if(styp == BRK_R)   {return curOpe.bf.brk_r;}
    else    if(styp == FLT_ON)     {return curOpe.bf.flt_on;}
    else    if(styp == FLT_OFF)     {return curOpe.bf.flt_off;}
    else    if(styp == FL_BRK)     {return curOpe.bf.full_brk;}
    else    if(styp == MOT_STOP){return curOpe.bf.mot_stop;}
    else    if(styp == R_1)     {return curOpe.bf.rsv_1;}
    else    if(styp == R_2)     {return curOpe.bf.rsv_2;}
    else    if(styp == R_3)     {return curOpe.bf.rsv_3;}
    else    if(styp == ALL_STOP){return curOpe.bf.all_stop;}
    else {return false;}
}
bool HbUserOpe::ChkCtrlSwAny()
{
    UINT16 mask = 0x1;
    for(int i = 0; i < 10; ++i){
        if(curOpe.w & mask){
            return true;
        }
        mask = mask << 1;
    }
    return false;
}
bool HbUserOpe::ChkCtrlSwRiseEdge(SW_TYPE styp)
{
            if(styp == BRK_L)       {return curOpe.bf.brk_l     && !oldOpe.bf.brk_l;}
    else    if(styp == BRK_R)       {return curOpe.bf.brk_r     && !oldOpe.bf.brk_r;}
    else    if(styp == FLT_ON)      {return curOpe.bf.flt_on    && !oldOpe.bf.flt_on;}
    else    if(styp == FLT_OFF)     {return curOpe.bf.flt_off    && !oldOpe.bf.flt_off;}
    else    if(styp == FL_BRK)      {return curOpe.bf.full_brk  && !oldOpe.bf.full_brk;}
    else    if(styp == MOT_STOP)    {return curOpe.bf.mot_stop    && !oldOpe.bf.mot_stop;}
    else    if(styp == R_1)         {return curOpe.bf.rsv_1    && !oldOpe.bf.rsv_1;}
    else    if(styp == R_2)         {return curOpe.bf.rsv_2    && !oldOpe.bf.rsv_2;}
    else    if(styp == R_3)         {return curOpe.bf.rsv_3    && !oldOpe.bf.rsv_3;}
    else    if(styp == ALL_STOP)    {return curOpe.bf.all_stop  && !oldOpe.bf.all_stop;}
    else{return false;}
}