Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HbUserOpe.cpp
- Committer:
- MasashiNomura
- Date:
- 2019-01-16
- Revision:
- 36:2cc739c7e4cb
- Parent:
- 34:234b87f3e6ce
- Child:
- 38:24ee50452755
File content as of revision 36:2cc739c7e4cb:
#include "HbUserOpe.h"
#include "fpga.h"
//=========================================
//コンストラクタ
//=========================================
HbUserOpe::HbUserOpe(){
oldOpe.w = curOpe.w = 0;
AinAxlVal = AinTrtlVal = 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;
}
INT16 HbUserOpe::GetAinThrottle()
{
INT16 ret = 0;
AinTrtlVal = AinThrottle.read();
ret = (INT16)(MAX_12BIT_DATA * AinTrtlVal);
if(gf_DbgPrint.bf.ana2 == true){
sp.printf("Trottle Val=%d analog val=%f\r\n",ret,AinTrtlVal);
gf_DbgPrint.bf.ana2 = false;
}
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 == F_ENG_UP) {return curOpe.bf.f_eng_up;}
else if(styp == F_ENG_DOWN) {return curOpe.bf.f_eng_down;}
else if(styp == R_ENG_UP) {return curOpe.bf.r_eng_up;}
else if(styp == R_ENG_DOWN) {return curOpe.bf.r_eng_down;}
else if(styp == R_1) {return curOpe.bf.rsv_1;}
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::ChkCtrlSwBoth(SW_TYPE styp1,SW_TYPE styp2)
{
bool sw1,sw2;
sw1 = sw2 = false;
if(styp1 == BRK_L) {sw1 = curOpe.bf.brk_l;}
else if(styp1 == BRK_R) {sw1 = curOpe.bf.brk_r;}
else if(styp1 == FLT_ON) {sw1 = curOpe.bf.flt_on;}
else if(styp1 == FLT_OFF) {sw1 = curOpe.bf.flt_off;}
else if(styp1 == F_ENG_UP) {sw1 = curOpe.bf.f_eng_up;}
else if(styp1 == F_ENG_DOWN) {sw1 = curOpe.bf.f_eng_down;}
else if(styp1 == R_ENG_UP) {sw1 = curOpe.bf.r_eng_up;}
else if(styp1 == R_ENG_DOWN) {sw1 = curOpe.bf.r_eng_down;}
else if(styp1 == R_1) {sw1 = curOpe.bf.rsv_1;}
else if(styp1 == ALL_STOP) {sw1 = curOpe.bf.all_stop;}
else {sw1 = false;}
if(styp2 == BRK_L) {sw2 = curOpe.bf.brk_l;}
else if(styp2 == BRK_R) {sw2 = curOpe.bf.brk_r;}
else if(styp2 == FLT_ON) {sw2 = curOpe.bf.flt_on;}
else if(styp2 == FLT_OFF) {sw2 = curOpe.bf.flt_off;}
else if(styp2 == F_ENG_UP) {sw2 = curOpe.bf.f_eng_up;}
else if(styp2 == F_ENG_DOWN) {sw2 = curOpe.bf.f_eng_down;}
else if(styp2 == R_ENG_UP) {sw2 = curOpe.bf.r_eng_up;}
else if(styp2 == R_ENG_DOWN) {sw2 = curOpe.bf.r_eng_down;}
else if(styp2 == R_1) {sw2 = curOpe.bf.rsv_1;}
else if(styp2 == ALL_STOP) {sw2 = curOpe.bf.all_stop;}
else {sw2 = false;}
return sw1 && sw2;
}
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 == F_ENG_UP) {return curOpe.bf.f_eng_up && !oldOpe.bf.f_eng_up;}
else if(styp == F_ENG_DOWN) {return curOpe.bf.f_eng_down && !oldOpe.bf.f_eng_down;}
else if(styp == R_ENG_UP) {return curOpe.bf.r_eng_up && !oldOpe.bf.r_eng_up;}
else if(styp == R_ENG_DOWN) {return curOpe.bf.r_eng_down && !oldOpe.bf.r_eng_down;}
else if(styp == R_1) {return curOpe.bf.rsv_1 && !oldOpe.bf.rsv_1;}
else if(styp == ALL_STOP) {return curOpe.bf.all_stop && !oldOpe.bf.all_stop;}
else{return false;}
}