Skip to content

Commit

Permalink
implement parameters for EN06 5S protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
stancecoke committed Nov 9, 2024
1 parent 05d6fde commit ac14915
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@

//----------------------------- Display setting

#define DISPLAY_TYPE DISPLAY_TYPE_DEBUG
#define DISPLAY_TYPE DISPLAY_TYPE_KINGMETER_901U

//------------------------------Autodetect setting
#define AUTODETECT 0
Expand Down
2 changes: 2 additions & 0 deletions Inc/display_kingmeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ typedef struct
// Parameters received from display in setting mode:
uint16_t WheelSize_mm; // Unit: 1mm
uint8_t PAS_RUN_Direction; // KM_PASDIR_FORWARD / KM_PASDIR_BACKWARD
uint8_t ExecAutodetect; // 0 or 1, Use Parameter P18 of EN06 protocol
uint8_t Reverse; // 0 or 1, Use Parameter P19 of EN06 protocol
uint8_t PAS_SCN_Tolerance; // Number of PAS signals to start the motor
uint8_t PAS_N_Ratio; // 0..255 PAS ratio
uint8_t HND_HL_ThrParam; // KM_HND_HL_NO / KM_HND_HL_YES
Expand Down
17 changes: 12 additions & 5 deletions Src/display_kingmeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#define RXSTATE_SENDTXMSG 1
#define RXSTATE_MSGBODY 2
#define RXSTATE_DONE 3

uint8_t FirstRunFlag = 0;
UART_HandleTypeDef huart1;
UART_HandleTypeDef huart2;
UART_HandleTypeDef huart3;


#if (DISPLAY_TYPE == DISPLAY_TYPE_KINGMETER_618U)
Expand Down Expand Up @@ -456,8 +456,10 @@ static void KM_901U_Service(KINGMETER_t* KM_ctx)
// Decode Rx message
if(!CheckSum) //low-byte and high-byte
{
kingmeter_update();

KM_ctx->Settings.PAS_RUN_Direction = (KM_Message[4] & 0x80) >> 7; // KM_PASDIR_FORWARD / KM_PASDIR_BACKWARD
KM_ctx->Settings.ExecAutodetect = (KM_Message[6]>>7)&0x01; // Execute Autodetect (with P18 of EN06 protocol)
KM_ctx->Settings.Reverse = (KM_Message[6]>>6)&0x01; // set spinning direction (with P19 of EN06 protocol)
KM_ctx->Settings.PAS_SCN_Tolerance = KM_Message[5]; // 2..9
KM_ctx->Settings.PAS_N_Ratio = KM_Message[6]; // 0..255
KM_ctx->Settings.HND_HL_ThrParam = (KM_Message[7] & 0x80) >> 7; // KM_HND_HL_NO / KM_HND_HL_YES
Expand All @@ -469,8 +471,13 @@ static void KM_901U_Service(KINGMETER_t* KM_ctx)
KM_ctx->Rx.SPEEDMAX_Limit = KM_Message[11];
KM_ctx->Rx.CUR_Limit_mA = (KM_Message[8]&0x3F)*500;

if(KM_ctx->Rx.CUR_Limit_mA==21500)autodetect();

kingmeter_update();
if(KM_ctx->Settings.ExecAutodetect&&!FirstRunFlag){
autodetect();
FirstRunFlag=1;
}
//if(KM_ctx->Rx.CUR_Limit_mA==21500)autodetect();
//if(KM_ctx->Rx.CUR_Limit_mA==20500)get_internal_temp_offset();
}

// Prepare Tx message with handshake code
Expand Down
1 change: 1 addition & 0 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,7 @@ void kingmeter_update(void)
{
ui8_Push_Assist_flag=0;
}
i8_direction = KM.Settings.Reverse;
// MP.speedLimit=KM.Rx.SPEEDMAX_Limit;
// MP.battery_current_max = KM.Rx.CUR_Limit_mA;

Expand Down

0 comments on commit ac14915

Please sign in to comment.