Skip to content

Commit

Permalink
add further Rx parameters WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
stancecoke committed Oct 27, 2024
1 parent 1f3ee89 commit 2bd0ae1
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Inc/display_No_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,16 @@ typedef struct
// Parameters received from display in operation mode:
uint8_t AssistLevel; // Byte 4, Level in Display
uint8_t NumberOfPasMagnets; // Byte 18, same Number as in display setting
uint8_t Headlight; // KM_HEADLIGHT_OFF / KM_HEADLIGHT_ON / KM_HEADLIGHT_LOW / KM_HEADLIGHT_HIGH
uint8_t Battery; // KM_BATTERY_NORMAL / KM_BATTERY_LOW
uint8_t PushAssist; // KM_PUSHASSIST_OFF / KM_PUSHASSIST_ON
uint8_t PowerAssist; // KM_POWERASSIST_OFF / KM_POWERASSIST_ON
uint8_t Headlight; // Byte 5, Bit 5
uint16_t WheelSizeInch_x10; // HiByte 14, LowByte 15
uint8_t PushAssist; // Byte 5, Bit 2
uint8_t ZeroStart; // Byte 5, Bit 6
uint8_t Throttle_mode; // Byte 3, numbers not read out yet
uint8_t Start_delay_PAS; // Byte 9, same Number as in display setting
uint8_t CruiseControl; // KM_CRUISE_OFF / KM_CRUISE_ON
uint8_t OverSpeed; // KM_OVERSPEED_OFF / KM_OVERSPEED_ON
uint16_t SPEEDMAX_Limit; // Unit: km/h
uint8_t GearRatio; // Byte 6, same Number as in display setting
uint8_t BoostPower; // Byte 10, same Number as in display setting
uint16_t SPEEDMAX_Limit; // Byte 15, same Number as in display setting
uint16_t Voltage_min_x10; // HiByte 14, LowByte 15
uint8_t CUR_Limit_A; // Byte 13, same Number as in display setting

Expand Down Expand Up @@ -73,8 +75,6 @@ typedef struct

uint8_t RxBuff[KM_MAX_RXBUFF];
uint8_t RxCnt;

RX_SETTINGS_t Settings;
RX_PARAM_t Rx;
TX_PARAM_t Tx;

Expand Down
1 change: 1 addition & 0 deletions Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ int32_t map (int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t
void autodetect();
void runPIcontrol();
void kingmeter_update(void);
void No2_update(void);

extern uint16_t switchtime[3];
extern uint32_t ui32_tim1_counter;
Expand Down
13 changes: 13 additions & 0 deletions Src/display_No_2.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,20 @@ void No2_Service(No2_t* No2_ctx)
No2_ctx->Rx.NumberOfPasMagnets = No2_Message[18];
No2_ctx->Rx.CUR_Limit_A = No2_Message[13];
No2_ctx->Rx.Voltage_min_x10 = (No2_Message[14]<<8)+No2_Message[15];
No2_ctx->Rx.WheelSizeInch_x10 = (No2_Message[7]<<8)+No2_Message[8];
No2_ctx->Rx.Throttle_mode = No2_Message[3];
No2_ctx->Rx.Start_delay_PAS = No2_Message[9];
No2_ctx->Rx.BoostPower = No2_Message[10];
No2_ctx->Rx.ZeroStart = (No2_Message[5]>>6)&0x01;
No2_ctx->Rx.Headlight = (No2_Message[5]>>5)&0x01;
No2_ctx->Rx.PushAssist = (No2_Message[5]>>2)&0x01;
No2_ctx->Rx.SPEEDMAX_Limit = No2_Message[12];
No2_ctx->Rx.GearRatio = No2_Message[6];

No2_update(); //get/set parameters in main.c

//to do: apply speed and power data to TxBuffer

TxBuffer[13]=calculate_checksum(TxBuffer, 14);
HAL_UART_Transmit(&huart1, (uint8_t *)&TxBuffer,14,50);
}
Expand Down
54 changes: 54 additions & 0 deletions Src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2037,8 +2037,62 @@ int main(void)
EE_WriteVariable(EEPROM_INT_TEMP_V25,temp>>5);
HAL_FLASH_Lock();
}
#if (DISPLAY_TYPE == DISPLAY_TYPE_NO2)
void No2_update(void)
{
/* Prepare Tx parameters */

#if (SPEEDSOURCE == EXTERNAL)
No2.Tx.Wheeltime_ms = ((MS.Speed>>3)*PULSES_PER_REVOLUTION); //>>3 because of 8 kHz counter frequency, so 8 tics per ms
#else
if(__HAL_TIM_GET_COUNTER(&htim2) < 12000)
{
No2.Tx.Wheeltime_ms = (MS.Speed*GEAR_RATIO*6)>>9; //>>9 because of 500kHZ timer2 frequency, 512 tics per ms should be OK *6 because of 6 hall interrupts per electric revolution.

}
else
{
No2.Tx.Wheeltime_ms = 64000;
}

#endif
if(MS.Temperature>130) No2.Tx.Error = 7; //motor failure
else if(MS.int_Temperature>80)No2.Tx.Error = 9; //controller failure
else No2.Tx.Error = 0; //no failure


No2.Tx.Current_x10 = (uint16_t) (MS.Battery_Current/100); //MS.Battery_Current is in mA


/* Apply Rx parameters */

MS.assist_level = No2.Rx.AssistLevel;

if(!No2.Rx.Headlight)
{
HAL_GPIO_WritePin(LIGHT_GPIO_Port, LIGHT_Pin, GPIO_PIN_RESET);

}
else // KM_HEADLIGHT_ON, KM_HEADLIGHT_LOW, KM_HEADLIGHT_HIGH
{
HAL_GPIO_WritePin(LIGHT_GPIO_Port, LIGHT_Pin, GPIO_PIN_SET);

}


if(No2.Rx.PushAssist)
{
ui8_Push_Assist_flag=1;
}
else
{
ui8_Push_Assist_flag=0;
}

}

#endif

#if (DISPLAY_TYPE & DISPLAY_TYPE_KINGMETER || DISPLAY_TYPE & DISPLAY_TYPE_DEBUG)
void kingmeter_update(void)
{
Expand Down

0 comments on commit 2bd0ae1

Please sign in to comment.