teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

Committer:
MasashiNomura
Date:
Wed Jan 23 11:58:53 2019 +0000
Revision:
42:cc8501b824ba
Parent:
41:45c982b1c5b6
Child:
53:b09c062cc31c
20190123 Modify for 45inc.; Add CMD for engine accel etc

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