Driver wishlist

This commit is contained in:
Jasper Blanckenburg 2024-06-12 21:04:22 +02:00
parent f0db650c30
commit 0076387f21
6 changed files with 103 additions and 0 deletions

View File

@ -21,6 +21,8 @@ void vehicle_thread_entry(ULONG hfdcan_addr);
void vehicle_broadcast_buttons(GPIO_PinState *button_states);
void vehicle_broadcast_wishlist();
#endif // SIMULATOR
#ifdef __cplusplus

View File

@ -7,6 +7,7 @@ extern "C" {
#include "params.h"
#include "stw_defines.h"
#include <stdbool.h>
#include <stdint.h>
#define NUM_CONES 12
@ -112,6 +113,7 @@ typedef struct {
int sdc_closed;
int pdu_sdc_active;
int imd_ok;
bool drs_active;
int sdcl_state[3];
R2DProgress r2d_progress;
@ -148,6 +150,7 @@ typedef struct {
IniChkState ini_chk_state;
unsigned lap_count;
unsigned lap_count_endu;
float lap_last;
float lap_best;
@ -191,7 +194,15 @@ typedef struct {
ParamType last_param_confirmed;
} VehicleState;
typedef struct {
bool initialized;
uint8_t power_limit;
uint8_t speed_limit;
} DriverWishlist;
extern VehicleState vehicle_state;
extern DriverWishlist wishlist;
#ifdef __cplusplus
} // extern "C"

View File

@ -24,10 +24,12 @@
#define CAN_ID_CS_INTERNAL 0x108
#define CAN_ID_ABX_MISC 0x109
#define CAN_ID_ABX_HYDRAULICS 0x110
#define CAN_ID_ABX_ENDURANCE 0x113
#define CAN_ID_EPSC_OUT 0x321
#define CAN_ID_MISSION_SELECTED 0x400
#define CAN_ID_STW_BUTTONS 0x401
#define CAN_ID_STW_PARAM_SET 0x402
#define CAN_ID_STW_DRIVERWISHLIST 0x403
#define CAN_ID_AS_MISSION_FB 0x410
#define CAN_ID_STW_STATUS 0x412
#define CAN_ID_ABX_PARAM_CONFIRMED 0x413
@ -55,6 +57,7 @@
void vehicle_thread_entry(ULONG hfdcan_addr) {
memset(&vehicle_state, 0, sizeof(vehicle_state));
memset(&vehicle_state.cone_pos, 0xFF, sizeof(vehicle_state.cone_pos));
memset(&wishlist, 0, sizeof(wishlist));
ftcan_init((void *)hfdcan_addr);
ftcan_add_filter(CAN_ID_AMS_SLAVE_PANIC, 0x7FF);
@ -68,6 +71,7 @@ void vehicle_thread_entry(ULONG hfdcan_addr) {
ftcan_add_filter(CAN_ID_ABX_BRAKE_T, 0x7FF);
ftcan_add_filter(CAN_ID_CS_INTERNAL, 0x7FF);
ftcan_add_filter(CAN_ID_ABX_MISC, 0x7FF);
ftcan_add_filter(CAN_ID_ABX_ENDURANCE, 0x7FF);
ftcan_add_filter(CAN_ID_ABX_HYDRAULICS, 0x7FF);
ftcan_add_filter(CAN_ID_EPSC_OUT, 0x7FF);
ftcan_add_filter(CAN_ID_AS_MISSION_FB, 0x7FF);
@ -80,6 +84,7 @@ void vehicle_thread_entry(ULONG hfdcan_addr) {
while (1) {
tx_thread_sleep(10);
vehicle_broadcast_wishlist();
}
}
@ -102,6 +107,17 @@ void vehicle_broadcast_buttons(GPIO_PinState *button_states) {
ftcan_transmit(CAN_ID_STW_BUTTONS, &data, 1);
}
void vehicle_broadcast_wishlist() {
if (!wishlist.initialized) {
return;
}
uint8_t data[2];
data[0] = wishlist.power_limit;
data[1] = wishlist.speed_limit;
ftcan_transmit(CAN_ID_STW_DRIVERWISHLIST, data, 2);
}
void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
const uint8_t *ptr;
if ((id & CAN_ID_STW_CONES_MASK) == CAN_ID_STW_CONES_BASE) {
@ -166,6 +182,18 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
vehicle_state.hyd_press_b =
((data[1] >> 4) | (data[2] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR;
break;
case CAN_ID_ABX_ENDURANCE:
vehicle_state.power_limit = data[0];
vehicle_state.speed_limit = data[1];
if (!wishlist.initialized) {
wishlist.initialized = true;
wishlist.power_limit = vehicle_state.power_limit;
wishlist.speed_limit = vehicle_state.speed_limit;
}
vehicle_state.lap_count_endu = data[2];
vehicle_state.bat_delta_overall = ((int8_t)data[3]) * 1.0f;
vehicle_state.bat_delta_last = ((int8_t)data[4]) * 1.0f;
break;
case CAN_ID_ABX_TIMINGS:
vehicle_state.lap_best = (data[0] | (data[1] << 8)) * 0.01f;
vehicle_state.lap_last = (data[2] | (data[3] << 8)) * 0.01f;
@ -225,6 +253,7 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
vehicle_state.errors.err_res = (data[5] >> 2) & 1;
vehicle_state.errors.err_invl = (data[5] >> 3) & 1;
vehicle_state.errors.err_invr = (data[5] >> 4) & 1;
vehicle_state.drs_active = (data[5] >> 5) & 1;
break;
case CAN_ID_ABX_PARAM_CONFIRMED:
vehicle_state.last_param_confirmed = data[0];

View File

@ -1,6 +1,7 @@
#include "vehicle_state.h"
VehicleState vehicle_state;
DriverWishlist wishlist;
const char *inichkstate_str(IniChkState state) {
switch (vehicle_state.ini_chk_state) {

View File

@ -60,6 +60,11 @@ public:
void updateDetails();
void updateProgress();
void decreasePowerLimit() override;
void increasePowerLimit() override;
void decreaseSpeedLimit() override;
void increaseSpeedLimit() override;
protected:
BatDelta lastLapDelta;
BatDelta overallDelta;
@ -67,6 +72,8 @@ protected:
ValueBuffer slimBuffer;
ValueBuffer socBuffer;
ValueBuffer tbatBuffer;
bool limitsChangable();
};
#endif // ENDURANCEVIEW_HPP

View File

@ -1,3 +1,4 @@
#include "main.h"
#include "touchgfx/Color.hpp"
#include "touchgfx/Unicode.hpp"
#include "vehicle_state.h"
@ -5,6 +6,10 @@
#include <cmath>
#include <gui/endurance_screen/EnduranceView.hpp>
#ifndef SIMULATOR
#include "stm32h7xx_hal_gpio.h"
#endif
EnduranceView::EnduranceView()
: lastLapDelta(lastLapBox, lastLapBat),
overallDelta(overallBox, overallBat), plimBuffer(powerLimit, 2, 0),
@ -39,6 +44,54 @@ void EnduranceView::updateDetails() {
void EnduranceView::updateProgress() { progressBar.update(); }
void EnduranceView::decreasePowerLimit() {
if (!limitsChangable()) {
return;
}
if (wishlist.power_limit > 15) {
wishlist.power_limit--;
}
}
void EnduranceView::increasePowerLimit() {
if (!limitsChangable()) {
return;
}
if (wishlist.power_limit < 40) {
wishlist.power_limit++;
}
}
void EnduranceView::decreaseSpeedLimit() {
if (!limitsChangable()) {
return;
}
if (wishlist.speed_limit > 40) {
wishlist.speed_limit--;
}
}
void EnduranceView::increaseSpeedLimit() {
if (!limitsChangable()) {
return;
}
if (wishlist.speed_limit < 100) {
wishlist.speed_limit++;
}
}
bool EnduranceView::limitsChangable() {
#ifdef SIMULATOR
return true;
#else
return HAL_GPIO_ReadPin(BTN3_GPIO_Port, BTN3_Pin) == GPIO_PIN_SET;
#endif
}
BatDelta::BatDelta(touchgfx::BoxWithBorder &box,
touchgfx::TextAreaWithOneWildcard &field)
: box(box), field(field), value(INT_MIN) {}