added KTM 1290 Superduke (2023) to CAN-Sources

This commit is contained in:
Marcel Peterkau 2023-12-03 23:49:41 +01:00
parent f8a195bd4b
commit aa3a2106aa
2 changed files with 36 additions and 9 deletions

View File

@ -58,11 +58,13 @@ const size_t GPSBaudRateString_Elements = sizeof(GPSBaudRateString) / sizeof(GPS
#ifdef FEATURE_ENABLE_CAN
typedef enum CANSource_e
{
KTM_890_ADV_R_2021
KTM_890_ADV_R_2021,
KTM_1290_SD_R_2023
} CANSource_t;
const char CANSourceString[][28] = {
"KTM 890 Adventure R (2021)"};
const char CANSourceString[][30] = {
"KTM 890 Adventure R (2021)",
"KTM 1290 Superduke R (2023)"};
const size_t CANSourceString_Elements = sizeof(CANSourceString) / sizeof(CANSourceString[0]);
#endif

View File

@ -14,7 +14,18 @@ void Init_CAN()
CAN0.init_Mask(0, 0, 0x07FF0000); // Init first mask...
CAN0.init_Mask(1, 0, 0x07FF0000); // Init second mask...
CAN0.init_Filt(0, 0, 0x012D0000); // Init first filter...
switch (LubeConfig.CANSource)
{
case KTM_890_ADV_R_2021:
CAN0.init_Filt(0, 0, 0x012D0000); // Init first filter...
break;
case KTM_1290_SD_R_2023:
CAN0.init_Filt(0, 0, 0x012D0000); // Init first filter...
break;
default:
break;
}
CAN0.setMode(MCP_NORMAL);
}
@ -33,19 +44,33 @@ void CAN_Process()
uint32_t Process_CAN_WheelSpeed()
{
#define FACTOR_RWP_KMH_890ADV 18 // Divider to convert Raw Data to km/h
#define FACTOR_RWP_KMH_1290SD 18 // Divider to convert Raw Data to km/h
can_frame canMsg;
static uint32_t lastRecTimestamp = 0;
uint16_t RearWheelSpeed_raw;
uint32_t milimeters_to_add = 0;
uint32_t RWP_millimeter_per_second = 0;
if (CAN0.readMsgBuf(&canMsg.can_id, &canMsg.can_dlc, canMsg.data) == CAN_OK)
{
RearWheelSpeed_raw = (uint16_t)canMsg.data[5] << 8 | canMsg.data[6];
// raw / FACTOR_RWP_KMH_890ADV -> km/h * 100000 -> cm/h / 3600 -> cm/s
// raw * 500 -> cm/s
uint32_t RWP_millimeter_per_second = (((uint32_t)RearWheelSpeed_raw * 1000000) / FACTOR_RWP_KMH_890ADV) / 3600;
switch (LubeConfig.CANSource)
{
case KTM_890_ADV_R_2021:
// raw / FACTOR_RWP_KMH_890ADV -> km/h * 100000 -> cm/h / 3600 -> cm/s
// raw * 500 -> cm/s
RearWheelSpeed_raw = (uint16_t)canMsg.data[5] << 8 | canMsg.data[6];
RWP_millimeter_per_second = (((uint32_t)RearWheelSpeed_raw * 1000000) / FACTOR_RWP_KMH_890ADV) / 3600;
break;
case KTM_1290_SD_R_2023:
// raw / FACTOR_RWP_KMH_1290SD -> km/h * 100000 -> cm/h / 3600 -> cm/s
// raw * 500 -> cm/s
RearWheelSpeed_raw = (uint16_t)canMsg.data[5] << 8 | canMsg.data[6];
RWP_millimeter_per_second = (((uint32_t)RearWheelSpeed_raw * 1000000) / FACTOR_RWP_KMH_1290SD) / 3600;
break;
default:
break;
}
uint32_t timesincelast = millis() - lastRecTimestamp;
lastRecTimestamp = millis();