Skip to content

Commit ac14915

Browse files
committed
implement parameters for EN06 5S protocol
1 parent 05d6fde commit ac14915

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

Inc/config.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
//----------------------------- Display setting
102102

103-
#define DISPLAY_TYPE DISPLAY_TYPE_DEBUG
103+
#define DISPLAY_TYPE DISPLAY_TYPE_KINGMETER_901U
104104

105105
//------------------------------Autodetect setting
106106
#define AUTODETECT 0

Inc/display_kingmeter.h

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ typedef struct
6666
// Parameters received from display in setting mode:
6767
uint16_t WheelSize_mm; // Unit: 1mm
6868
uint8_t PAS_RUN_Direction; // KM_PASDIR_FORWARD / KM_PASDIR_BACKWARD
69+
uint8_t ExecAutodetect; // 0 or 1, Use Parameter P18 of EN06 protocol
70+
uint8_t Reverse; // 0 or 1, Use Parameter P19 of EN06 protocol
6971
uint8_t PAS_SCN_Tolerance; // Number of PAS signals to start the motor
7072
uint8_t PAS_N_Ratio; // 0..255 PAS ratio
7173
uint8_t HND_HL_ThrParam; // KM_HND_HL_NO / KM_HND_HL_YES

Src/display_kingmeter.c

+12-5
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
3333
#define RXSTATE_SENDTXMSG 1
3434
#define RXSTATE_MSGBODY 2
3535
#define RXSTATE_DONE 3
36-
36+
uint8_t FirstRunFlag = 0;
3737
UART_HandleTypeDef huart1;
38-
UART_HandleTypeDef huart2;
38+
UART_HandleTypeDef huart3;
3939

4040

4141
#if (DISPLAY_TYPE == DISPLAY_TYPE_KINGMETER_618U)
@@ -456,8 +456,10 @@ static void KM_901U_Service(KINGMETER_t* KM_ctx)
456456
// Decode Rx message
457457
if(!CheckSum) //low-byte and high-byte
458458
{
459-
kingmeter_update();
459+
460460
KM_ctx->Settings.PAS_RUN_Direction = (KM_Message[4] & 0x80) >> 7; // KM_PASDIR_FORWARD / KM_PASDIR_BACKWARD
461+
KM_ctx->Settings.ExecAutodetect = (KM_Message[6]>>7)&0x01; // Execute Autodetect (with P18 of EN06 protocol)
462+
KM_ctx->Settings.Reverse = (KM_Message[6]>>6)&0x01; // set spinning direction (with P19 of EN06 protocol)
461463
KM_ctx->Settings.PAS_SCN_Tolerance = KM_Message[5]; // 2..9
462464
KM_ctx->Settings.PAS_N_Ratio = KM_Message[6]; // 0..255
463465
KM_ctx->Settings.HND_HL_ThrParam = (KM_Message[7] & 0x80) >> 7; // KM_HND_HL_NO / KM_HND_HL_YES
@@ -469,8 +471,13 @@ static void KM_901U_Service(KINGMETER_t* KM_ctx)
469471
KM_ctx->Rx.SPEEDMAX_Limit = KM_Message[11];
470472
KM_ctx->Rx.CUR_Limit_mA = (KM_Message[8]&0x3F)*500;
471473

472-
if(KM_ctx->Rx.CUR_Limit_mA==21500)autodetect();
473-
474+
kingmeter_update();
475+
if(KM_ctx->Settings.ExecAutodetect&&!FirstRunFlag){
476+
autodetect();
477+
FirstRunFlag=1;
478+
}
479+
//if(KM_ctx->Rx.CUR_Limit_mA==21500)autodetect();
480+
//if(KM_ctx->Rx.CUR_Limit_mA==20500)get_internal_temp_offset();
474481
}
475482

476483
// Prepare Tx message with handshake code

Src/main.c

+1
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,7 @@ void kingmeter_update(void)
20002000
{
20012001
ui8_Push_Assist_flag=0;
20022002
}
2003+
i8_direction = KM.Settings.Reverse;
20032004
// MP.speedLimit=KM.Rx.SPEEDMAX_Limit;
20042005
// MP.battery_current_max = KM.Rx.CUR_Limit_mA;
20052006

0 commit comments

Comments
 (0)