teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Wed Jan 16 10:51:07 2019 +0000
Revision:
36:2cc739c7e4cb
Parent:
34:234b87f3e6ce
Child:
38:24ee50452755
2019/01/16 modify for 45inc Alfa HB / no debug, no checking

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MasashiNomura 22:24c9c2dedca9 1 #include "HbUserOpe.h"
MasashiNomura 22:24c9c2dedca9 2 #include "fpga.h"
MasashiNomura 22:24c9c2dedca9 3 //=========================================
MasashiNomura 22:24c9c2dedca9 4 //コンストラクタ
MasashiNomura 22:24c9c2dedca9 5 //=========================================
MasashiNomura 22:24c9c2dedca9 6 HbUserOpe::HbUserOpe(){
MasashiNomura 22:24c9c2dedca9 7 oldOpe.w = curOpe.w = 0;
MasashiNomura 36:2cc739c7e4cb 8 AinAxlVal = AinTrtlVal = 0;
MasashiNomura 22:24c9c2dedca9 9 }
MasashiNomura 22:24c9c2dedca9 10
MasashiNomura 22:24c9c2dedca9 11 //=========================================
MasashiNomura 22:24c9c2dedca9 12 //デストラクタ
MasashiNomura 22:24c9c2dedca9 13 //=========================================
MasashiNomura 22:24c9c2dedca9 14 HbUserOpe::~HbUserOpe(){
MasashiNomura 22:24c9c2dedca9 15 }
MasashiNomura 22:24c9c2dedca9 16
MasashiNomura 22:24c9c2dedca9 17 typUserSw HbUserOpe::GetUserOpe()
MasashiNomura 22:24c9c2dedca9 18 {
MasashiNomura 22:24c9c2dedca9 19 oldOpe = curOpe;
MasashiNomura 22:24c9c2dedca9 20 curOpe.w = fpgaGetUserSw();
MasashiNomura 22:24c9c2dedca9 21 return curOpe;
MasashiNomura 23:79e20be4bc5b 22 }
MasashiNomura 33:eb260dbfc22a 23 INT16 HbUserOpe::GetAinAccel()
MasashiNomura 33:eb260dbfc22a 24 {
MasashiNomura 34:234b87f3e6ce 25 // max rpm 8500 ユーザー使用分として7000をマックスとする(仮)
MasashiNomura 34:234b87f3e6ce 26 // 0 ~ 1.00 -> 0.01 ~ 0.97を使用する(遊び分として)
MasashiNomura 33:eb260dbfc22a 27 INT16 ret = 0;
MasashiNomura 34:234b87f3e6ce 28 AinAxlVal = AinAxl.read();
MasashiNomura 34:234b87f3e6ce 29 if(MIN_EFF_ANA_VAL > AinAxlVal){
MasashiNomura 33:eb260dbfc22a 30 ret = 0;
MasashiNomura 34:234b87f3e6ce 31 } else if(AinAxlVal >= MIN_EFF_ANA_VAL && AinAxlVal <= MAX_EFF_ANA_VAL){
MasashiNomura 34:234b87f3e6ce 32 ret = (MAX_RPM_USERSET - MIN_RPM_TOTAL) * (AinAxlVal - MIN_EFF_ANA_VAL) / (MAX_EFF_ANA_VAL - MIN_EFF_ANA_VAL) + MIN_RPM_TOTAL;
MasashiNomura 34:234b87f3e6ce 33 } else if(AinAxlVal > MAX_EFF_ANA_VAL){
MasashiNomura 34:234b87f3e6ce 34 ret = MAX_RPM_USERSET;
MasashiNomura 33:eb260dbfc22a 35 }else{
MasashiNomura 33:eb260dbfc22a 36 ret = 0;
MasashiNomura 33:eb260dbfc22a 37 }
MasashiNomura 33:eb260dbfc22a 38 if(gf_DbgPrint.bf.ana1 == true){
MasashiNomura 34:234b87f3e6ce 39 sp.printf("Axl Rpm=%d val=%f\r\n",ret,AinAxlVal);
MasashiNomura 33:eb260dbfc22a 40 gf_DbgPrint.bf.ana1 = false;
MasashiNomura 33:eb260dbfc22a 41 }
MasashiNomura 33:eb260dbfc22a 42 //sp.printf("Axl Rpm=%d val=%f\r\n",ret,anaval);
MasashiNomura 33:eb260dbfc22a 43 return ret;
MasashiNomura 33:eb260dbfc22a 44 }
MasashiNomura 34:234b87f3e6ce 45
MasashiNomura 36:2cc739c7e4cb 46 INT16 HbUserOpe::GetAinThrottle()
MasashiNomura 36:2cc739c7e4cb 47 {
MasashiNomura 36:2cc739c7e4cb 48 INT16 ret = 0;
MasashiNomura 36:2cc739c7e4cb 49 AinTrtlVal = AinThrottle.read();
MasashiNomura 36:2cc739c7e4cb 50 ret = (INT16)(MAX_12BIT_DATA * AinTrtlVal);
MasashiNomura 36:2cc739c7e4cb 51 if(gf_DbgPrint.bf.ana2 == true){
MasashiNomura 36:2cc739c7e4cb 52 sp.printf("Trottle Val=%d analog val=%f\r\n",ret,AinTrtlVal);
MasashiNomura 36:2cc739c7e4cb 53 gf_DbgPrint.bf.ana2 = false;
MasashiNomura 36:2cc739c7e4cb 54 }
MasashiNomura 36:2cc739c7e4cb 55 return ret;
MasashiNomura 36:2cc739c7e4cb 56 }
MasashiNomura 36:2cc739c7e4cb 57
MasashiNomura 23:79e20be4bc5b 58 bool HbUserOpe::ChkCtrlSW(SW_TYPE styp)
MasashiNomura 23:79e20be4bc5b 59 {
MasashiNomura 36:2cc739c7e4cb 60 if(styp == BRK_L) {return curOpe.bf.brk_l;}
MasashiNomura 36:2cc739c7e4cb 61 else if(styp == BRK_R) {return curOpe.bf.brk_r;}
MasashiNomura 36:2cc739c7e4cb 62 else if(styp == FLT_ON) {return curOpe.bf.flt_on;}
MasashiNomura 34:234b87f3e6ce 63 else if(styp == FLT_OFF) {return curOpe.bf.flt_off;}
MasashiNomura 36:2cc739c7e4cb 64 else if(styp == F_ENG_UP) {return curOpe.bf.f_eng_up;}
MasashiNomura 36:2cc739c7e4cb 65 else if(styp == F_ENG_DOWN) {return curOpe.bf.f_eng_down;}
MasashiNomura 36:2cc739c7e4cb 66 else if(styp == R_ENG_UP) {return curOpe.bf.r_eng_up;}
MasashiNomura 36:2cc739c7e4cb 67 else if(styp == R_ENG_DOWN) {return curOpe.bf.r_eng_down;}
MasashiNomura 36:2cc739c7e4cb 68 else if(styp == R_1) {return curOpe.bf.rsv_1;}
MasashiNomura 36:2cc739c7e4cb 69 else if(styp == ALL_STOP) {return curOpe.bf.all_stop;}
MasashiNomura 31:56c554c560c1 70 else {return false;}
MasashiNomura 26:732bc37fbefd 71 }
MasashiNomura 23:79e20be4bc5b 72 bool HbUserOpe::ChkCtrlSwAny()
MasashiNomura 23:79e20be4bc5b 73 {
MasashiNomura 23:79e20be4bc5b 74 UINT16 mask = 0x1;
MasashiNomura 34:234b87f3e6ce 75 for(int i = 0; i < 10; ++i){
MasashiNomura 23:79e20be4bc5b 76 if(curOpe.w & mask){
MasashiNomura 23:79e20be4bc5b 77 return true;
MasashiNomura 23:79e20be4bc5b 78 }
MasashiNomura 23:79e20be4bc5b 79 mask = mask << 1;
MasashiNomura 23:79e20be4bc5b 80 }
MasashiNomura 23:79e20be4bc5b 81 return false;
MasashiNomura 23:79e20be4bc5b 82 }
MasashiNomura 36:2cc739c7e4cb 83 bool HbUserOpe::ChkCtrlSwBoth(SW_TYPE styp1,SW_TYPE styp2)
MasashiNomura 36:2cc739c7e4cb 84 {
MasashiNomura 36:2cc739c7e4cb 85 bool sw1,sw2;
MasashiNomura 36:2cc739c7e4cb 86 sw1 = sw2 = false;
MasashiNomura 36:2cc739c7e4cb 87 if(styp1 == BRK_L) {sw1 = curOpe.bf.brk_l;}
MasashiNomura 36:2cc739c7e4cb 88 else if(styp1 == BRK_R) {sw1 = curOpe.bf.brk_r;}
MasashiNomura 36:2cc739c7e4cb 89 else if(styp1 == FLT_ON) {sw1 = curOpe.bf.flt_on;}
MasashiNomura 36:2cc739c7e4cb 90 else if(styp1 == FLT_OFF) {sw1 = curOpe.bf.flt_off;}
MasashiNomura 36:2cc739c7e4cb 91 else if(styp1 == F_ENG_UP) {sw1 = curOpe.bf.f_eng_up;}
MasashiNomura 36:2cc739c7e4cb 92 else if(styp1 == F_ENG_DOWN) {sw1 = curOpe.bf.f_eng_down;}
MasashiNomura 36:2cc739c7e4cb 93 else if(styp1 == R_ENG_UP) {sw1 = curOpe.bf.r_eng_up;}
MasashiNomura 36:2cc739c7e4cb 94 else if(styp1 == R_ENG_DOWN) {sw1 = curOpe.bf.r_eng_down;}
MasashiNomura 36:2cc739c7e4cb 95 else if(styp1 == R_1) {sw1 = curOpe.bf.rsv_1;}
MasashiNomura 36:2cc739c7e4cb 96 else if(styp1 == ALL_STOP) {sw1 = curOpe.bf.all_stop;}
MasashiNomura 36:2cc739c7e4cb 97 else {sw1 = false;}
MasashiNomura 36:2cc739c7e4cb 98 if(styp2 == BRK_L) {sw2 = curOpe.bf.brk_l;}
MasashiNomura 36:2cc739c7e4cb 99 else if(styp2 == BRK_R) {sw2 = curOpe.bf.brk_r;}
MasashiNomura 36:2cc739c7e4cb 100 else if(styp2 == FLT_ON) {sw2 = curOpe.bf.flt_on;}
MasashiNomura 36:2cc739c7e4cb 101 else if(styp2 == FLT_OFF) {sw2 = curOpe.bf.flt_off;}
MasashiNomura 36:2cc739c7e4cb 102 else if(styp2 == F_ENG_UP) {sw2 = curOpe.bf.f_eng_up;}
MasashiNomura 36:2cc739c7e4cb 103 else if(styp2 == F_ENG_DOWN) {sw2 = curOpe.bf.f_eng_down;}
MasashiNomura 36:2cc739c7e4cb 104 else if(styp2 == R_ENG_UP) {sw2 = curOpe.bf.r_eng_up;}
MasashiNomura 36:2cc739c7e4cb 105 else if(styp2 == R_ENG_DOWN) {sw2 = curOpe.bf.r_eng_down;}
MasashiNomura 36:2cc739c7e4cb 106 else if(styp2 == R_1) {sw2 = curOpe.bf.rsv_1;}
MasashiNomura 36:2cc739c7e4cb 107 else if(styp2 == ALL_STOP) {sw2 = curOpe.bf.all_stop;}
MasashiNomura 36:2cc739c7e4cb 108 else {sw2 = false;}
MasashiNomura 36:2cc739c7e4cb 109
MasashiNomura 36:2cc739c7e4cb 110 return sw1 && sw2;
MasashiNomura 36:2cc739c7e4cb 111 }
MasashiNomura 36:2cc739c7e4cb 112
MasashiNomura 30:13ada1a24c59 113 bool HbUserOpe::ChkCtrlSwRiseEdge(SW_TYPE styp)
MasashiNomura 26:732bc37fbefd 114 {
MasashiNomura 34:234b87f3e6ce 115 if(styp == BRK_L) {return curOpe.bf.brk_l && !oldOpe.bf.brk_l;}
MasashiNomura 34:234b87f3e6ce 116 else if(styp == BRK_R) {return curOpe.bf.brk_r && !oldOpe.bf.brk_r;}
MasashiNomura 34:234b87f3e6ce 117 else if(styp == FLT_ON) {return curOpe.bf.flt_on && !oldOpe.bf.flt_on;}
MasashiNomura 34:234b87f3e6ce 118 else if(styp == FLT_OFF) {return curOpe.bf.flt_off && !oldOpe.bf.flt_off;}
MasashiNomura 36:2cc739c7e4cb 119 else if(styp == F_ENG_UP) {return curOpe.bf.f_eng_up && !oldOpe.bf.f_eng_up;}
MasashiNomura 36:2cc739c7e4cb 120 else if(styp == F_ENG_DOWN) {return curOpe.bf.f_eng_down && !oldOpe.bf.f_eng_down;}
MasashiNomura 36:2cc739c7e4cb 121 else if(styp == R_ENG_UP) {return curOpe.bf.r_eng_up && !oldOpe.bf.r_eng_up;}
MasashiNomura 36:2cc739c7e4cb 122 else if(styp == R_ENG_DOWN) {return curOpe.bf.r_eng_down && !oldOpe.bf.r_eng_down;}
MasashiNomura 36:2cc739c7e4cb 123 else if(styp == R_1) {return curOpe.bf.rsv_1 && !oldOpe.bf.rsv_1;}
MasashiNomura 34:234b87f3e6ce 124 else if(styp == ALL_STOP) {return curOpe.bf.all_stop && !oldOpe.bf.all_stop;}
MasashiNomura 31:56c554c560c1 125 else{return false;}
MasashiNomura 26:732bc37fbefd 126 }