teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Fri Jan 18 11:52:00 2019 +0000
Revision:
38:24ee50452755
Parent:
36:2cc739c7e4cb
Child:
41:45c982b1c5b6
20190118 Modify for 45inc. check User SW (include analogIn)

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