5 Commits

Author SHA1 Message Date
ba94373f3e Update param freq 2024-08-01 20:56:09 +02:00
25da5cde32 Fix dumb config typo 2024-07-24 09:35:22 +02:00
10aa474124 Fix DRS 2024-07-23 15:13:22 +02:00
5fb5d271b1 Fix display issues and inc logic 2024-07-22 19:35:23 +02:00
a4bea0d78b add commit hash (manual!) 2024-07-22 19:32:24 +02:00
9 changed files with 443 additions and 313 deletions

View File

@ -21,19 +21,19 @@
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "app_azure_rtos.h" #include "app_azure_rtos.h"
#include "stm32h7xx.h" #include "stm32h7xx.h"
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
#include "app.h" #include "app.h"
#include "app_touchgfx.h"
#include "leds.h" #include "leds.h"
#include "main.h" #include "main.h"
#include "ui.h"
#include "vehicle.h"
#include "app_touchgfx.h"
#include "tx_api.h" #include "tx_api.h"
#include "tx_port.h" #include "tx_port.h"
#include "ui.h"
#include "vehicle.h"
/* USER CODE END Includes */ /* USER CODE END Includes */
@ -56,10 +56,11 @@
#if (USE_STATIC_ALLOCATION == 1) #if (USE_STATIC_ALLOCATION == 1)
/* USER CODE BEGIN TX_Pool_Buffer */ /* USER CODE BEGIN TX_Pool_Buffer */
/* USER CODE END TX_Pool_Buffer */ /* USER CODE END TX_Pool_Buffer */
#if defined ( __ICCARM__ ) #if defined(__ICCARM__)
#pragma data_alignment=4 #pragma data_alignment = 4
#endif #endif
__ALIGN_BEGIN static UCHAR tx_byte_pool_buffer[TX_APP_MEM_POOL_SIZE] __ALIGN_END; __ALIGN_BEGIN static UCHAR
tx_byte_pool_buffer[TX_APP_MEM_POOL_SIZE] __ALIGN_END;
static TX_BYTE_POOL tx_app_byte_pool; static TX_BYTE_POOL tx_app_byte_pool;
#endif #endif
@ -69,6 +70,7 @@ TX_THREAD app_thread;
TX_THREAD ui_thread; TX_THREAD ui_thread;
TX_THREAD vehicle_thread; TX_THREAD vehicle_thread;
TX_THREAD led_thread; TX_THREAD led_thread;
TX_THREAD params_thread;
TX_QUEUE gui_button_queue; TX_QUEUE gui_button_queue;
TX_EVENT_FLAGS_GROUP gui_update_events; TX_EVENT_FLAGS_GROUP gui_update_events;
/* USER CODE END PV */ /* USER CODE END PV */
@ -79,12 +81,11 @@ TX_EVENT_FLAGS_GROUP gui_update_events;
/* USER CODE END PFP */ /* USER CODE END PFP */
/** /**
* @brief Define the initial system. * @brief Define the initial system.
* @param first_unused_memory : Pointer to the first unused memory * @param first_unused_memory : Pointer to the first unused memory
* @retval None * @retval None
*/ */
VOID tx_application_define(VOID *first_unused_memory) VOID tx_application_define(VOID *first_unused_memory) {
{
/* USER CODE BEGIN tx_application_define_1*/ /* USER CODE BEGIN tx_application_define_1*/
/* USER CODE END tx_application_define_1 */ /* USER CODE END tx_application_define_1 */
@ -92,22 +93,20 @@ VOID tx_application_define(VOID *first_unused_memory)
UINT status = TX_SUCCESS; UINT status = TX_SUCCESS;
VOID *memory_ptr; VOID *memory_ptr;
if (tx_byte_pool_create(&tx_app_byte_pool, "Tx App memory pool", tx_byte_pool_buffer, TX_APP_MEM_POOL_SIZE) != TX_SUCCESS) if (tx_byte_pool_create(&tx_app_byte_pool, "Tx App memory pool",
{ tx_byte_pool_buffer,
TX_APP_MEM_POOL_SIZE) != TX_SUCCESS) {
/* USER CODE BEGIN TX_Byte_Pool_Error */ /* USER CODE BEGIN TX_Byte_Pool_Error */
/* USER CODE END TX_Byte_Pool_Error */ /* USER CODE END TX_Byte_Pool_Error */
} } else {
else
{
/* USER CODE BEGIN TX_Byte_Pool_Success */ /* USER CODE BEGIN TX_Byte_Pool_Success */
/* USER CODE END TX_Byte_Pool_Success */ /* USER CODE END TX_Byte_Pool_Success */
memory_ptr = (VOID *)&tx_app_byte_pool; memory_ptr = (VOID *)&tx_app_byte_pool;
status = App_ThreadX_Init(memory_ptr); status = App_ThreadX_Init(memory_ptr);
if (status != TX_SUCCESS) if (status != TX_SUCCESS) {
{
/* USER CODE BEGIN App_ThreadX_Init_Error */ /* USER CODE BEGIN App_ThreadX_Init_Error */
while (1) { while (1) {
} }
@ -117,21 +116,22 @@ VOID tx_application_define(VOID *first_unused_memory)
/* USER CODE BEGIN App_ThreadX_Init_Success */ /* USER CODE BEGIN App_ThreadX_Init_Success */
/* USER CODE END App_ThreadX_Init_Success */ /* USER CODE END App_ThreadX_Init_Success */
} }
#else #else
/* /*
* Using dynamic memory allocation requires to apply some changes to the linker file. * Using dynamic memory allocation requires to apply some changes to the
* ThreadX needs to pass a pointer to the first free memory location in RAM to the tx_application_define() function, linker file.
* ThreadX needs to pass a pointer to the first free memory location in RAM to
the tx_application_define() function,
* using the "first_unused_memory" argument. * using the "first_unused_memory" argument.
* This require changes in the linker files to expose this memory location. * This require changes in the linker files to expose this memory location.
* For EWARM add the following section into the .icf file: * For EWARM add the following section into the .icf file:
place in RAM_region { last section FREE_MEM }; place in RAM_region { last section FREE_MEM };
* For MDK-ARM * For MDK-ARM
- either define the RW_IRAM1 region in the ".sct" file - either define the RW_IRAM1 region in the ".sct" file
- or modify the line below in "tx_initialize_low_level.S to match the memory region being used - or modify the line below in "tx_initialize_low_level.S to match the
LDR r1, =|Image$$RW_IRAM1$$ZI$$Limit| memory region being used LDR r1, =|Image$$RW_IRAM1$$ZI$$Limit|
* For STM32CubeIDE add the following section into the .ld file: * For STM32CubeIDE add the following section into the .ld file:
._threadx_heap : ._threadx_heap :
@ -141,13 +141,17 @@ VOID tx_application_define(VOID *first_unused_memory)
. = . + 64K; . = . + 64K;
. = ALIGN(8); . = ALIGN(8);
} >RAM_D1 AT> RAM_D1 } >RAM_D1 AT> RAM_D1
* The simplest way to provide memory for ThreadX is to define a new section, see ._threadx_heap above. * The simplest way to provide memory for ThreadX is to define a new
section, see ._threadx_heap above.
* In the example above the ThreadX heap size is set to 64KBytes. * In the example above the ThreadX heap size is set to 64KBytes.
* The ._threadx_heap must be located between the .bss and the ._user_heap_stack sections in the linker script. * The ._threadx_heap must be located between the .bss and the
* Caution: Make sure that ThreadX does not need more than the provided heap memory (64KBytes in this example). ._user_heap_stack sections in the linker script.
* Caution: Make sure that ThreadX does not need more than the provided
heap memory (64KBytes in this example).
* Read more in STM32CubeIDE User Guide, chapter: "Linker script". * Read more in STM32CubeIDE User Guide, chapter: "Linker script".
* The "tx_initialize_low_level.S" should be also modified to enable the "USE_DYNAMIC_MEMORY_ALLOCATION" flag. * The "tx_initialize_low_level.S" should be also modified to enable the
"USE_DYNAMIC_MEMORY_ALLOCATION" flag.
*/ */
/* USER CODE BEGIN DYNAMIC_MEM_ALLOC */ /* USER CODE BEGIN DYNAMIC_MEM_ALLOC */
@ -208,6 +212,15 @@ VOID tx_application_define(VOID *first_unused_memory)
Error_Handler(); Error_Handler();
} }
void *params_thread_stack = mem;
mem += THREAD_STACK_SIZE;
if (tx_thread_create(&params_thread, "Params Thread", params_thread_entry, 0,
params_thread_stack, THREAD_STACK_SIZE,
THREAD_PRIO_PARAMS, THREAD_PRIO_UI, TX_NO_TIME_SLICE,
TX_AUTO_START) != TX_SUCCESS) {
Error_Handler();
}
if (MX_TouchGFX_Init(mem) != TX_SUCCESS) { if (MX_TouchGFX_Init(mem) != TX_SUCCESS) {
Error_Handler(); Error_Handler();
} }
@ -215,5 +228,4 @@ VOID tx_application_define(VOID *first_unused_memory)
mem += 4096; mem += 4096;
/* USER CODE END DYNAMIC_MEM_ALLOC */ /* USER CODE END DYNAMIC_MEM_ALLOC */
#endif #endif
} }

View File

@ -27,7 +27,6 @@ extern "C" {
/* Includes ------------------------------------------------------------------*/ /* Includes ------------------------------------------------------------------*/
#include "app_azure_rtos_config.h" #include "app_azure_rtos_config.h"
#include "app_threadx.h" #include "app_threadx.h"
/* Private includes ----------------------------------------------------------*/ /* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */ /* USER CODE BEGIN Includes */
@ -44,6 +43,7 @@ extern "C" {
#define THREAD_STACK_SIZE 4096 #define THREAD_STACK_SIZE 4096
#define THREAD_PRIO_APP 10 #define THREAD_PRIO_APP 10
#define THREAD_PRIO_PARAMS 8
#define THREAD_PRIO_UI 6 #define THREAD_PRIO_UI 6
#define THREAD_PRIO_VEHICLE 7 #define THREAD_PRIO_VEHICLE 7
#define THREAD_PRIO_LED 11 #define THREAD_PRIO_LED 11

View File

@ -7,18 +7,20 @@ extern "C" {
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <tx_port.h>
#include "util.h" #include "util.h"
CountedEnum(ParamType, size_t, PF_PLIM, PF_TLIM, PF_SLIM, PF_TVEC, PF_PG, PF_REKU); CountedEnum(ParamType, size_t, PF_PLIM, PF_TLIM, PF_SLIM, PF_TVEC, PF_PG,
PF_REKU);
typedef struct { typedef struct {
unsigned plim; //< Power limit unsigned plim; //< Power limit
unsigned tlim; //< Torque limit unsigned tlim; //< Torque limit
unsigned slim; //< Speed limit unsigned slim; //< Speed limit
unsigned tvec; //< Torque vectoring unsigned tvec; //< Torque vectoring
unsigned pg; //< Power ground unsigned pg; //< Power ground
unsigned reku; //< Rekuperation unsigned reku; //< Rekuperation
} Params; } Params;
extern Params params; extern Params params;
@ -28,8 +30,13 @@ void params_inc(ParamType param);
void params_dec(ParamType param); void params_dec(ParamType param);
void params_broadcast(ParamType param); void params_broadcast(ParamType param);
/** FT24 only
* Broadcasts the current registered params to the CAN bus every second
*/
void params_thread_entry(ULONG _);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
#endif // INC_PARAMS_H #endif // INC_PARAMS_H

View File

@ -1,17 +1,29 @@
#include "params.h" #include "params.h"
#include <tx_api.h>
#include "can-halal.h" #include "can-halal.h"
#include "leds.h"
#include "vehicle.h" #include "vehicle.h"
/** /**
* Decrements the given value if it is above the minimum allowed value * Decrements the given value if it is above the minimum allowed value
*/ */
#define DEC_IF_ABOVE(param_val, min_val, decr_amt) ((param_val) = ((param_val) - (decr_amt) ) > (min_val) ? ((param_val) - (decr_amt)) : (min_val)) // TODO these functions take into account that the parameters are unsigned, it's
#define INC_IF_BELOW(param_val, max_val, incr_amt) ((param_val) = ((param_val) + (incr_amt)) > (max_val) ? ((param_val) + (incr_amt)) : (max_val)) // definitely better to have them signed but would need to be tested with the
// autobox
#define DEC_IF_ABOVE(param_val, min_val, decr_amt) \
((param_val) = (((int)(param_val) - (int)(decr_amt)) > (int)(min_val)) \
? ((param_val) - (decr_amt)) \
: (min_val))
#define INC_IF_BELOW(param_val, max_val, incr_amt) \
((param_val) = (((param_val) + (incr_amt)) < (max_val)) \
? ((param_val) + (incr_amt)) \
: (max_val))
Params params = {0}; Params params = {0};
void params_init() void params_init() {
{
// Default values // Default values
params.plim = 20; params.plim = 20;
params.tlim = 1400; params.tlim = 1400;
@ -21,81 +33,89 @@ void params_init()
params.reku = 0; params.reku = 0;
} }
void params_inc(ParamType param) void params_inc(ParamType param) {
{ switch (param) {
switch (param) case PF_PLIM:
{ INC_IF_BELOW(params.plim, 80, 1);
case PF_PLIM: break;
INC_IF_BELOW(params.plim, 80, 1); case PF_TLIM:
break; INC_IF_BELOW(params.tlim, 1500, 100);
case PF_TLIM: break;
INC_IF_BELOW(params.tlim, 1500, 100); case PF_SLIM:
break; INC_IF_BELOW(params.slim, 100, 1);
case PF_SLIM: break;
INC_IF_BELOW(params.slim, 100, 1); case PF_TVEC:
break; INC_IF_BELOW(params.tvec, 100, 1);
case PF_TVEC: break;
INC_IF_BELOW(params.tvec, 100, 1); case PF_PG:
break; INC_IF_BELOW(params.pg, 100, 1);
case PF_PG: break;
INC_IF_BELOW(params.pg, 100, 1); case PF_REKU:
break; INC_IF_BELOW(params.reku, 100, 1);
case PF_REKU: break;
INC_IF_BELOW(params.reku, 100, 1);
break;
} }
} }
void params_dec(ParamType param) void params_dec(ParamType param) {
{ switch (param) {
switch (param) case PF_PLIM:
{ DEC_IF_ABOVE(params.plim, 0, 1);
case PF_PLIM: break;
DEC_IF_ABOVE(params.plim, 0, 1); case PF_TLIM:
break; DEC_IF_ABOVE(params.tlim, 0, 100);
case PF_TLIM: break;
DEC_IF_ABOVE(params.tlim, 0, 100); case PF_SLIM:
break; DEC_IF_ABOVE(params.slim, 0, 1);
case PF_SLIM: break;
DEC_IF_ABOVE(params.slim, 0, 1); case PF_TVEC:
break; DEC_IF_ABOVE(params.tvec, 0, 1);
case PF_TVEC: break;
DEC_IF_ABOVE(params.tvec, 0, 1); case PF_PG:
break; DEC_IF_ABOVE(params.pg, 0, 1);
case PF_PG: break;
DEC_IF_ABOVE(params.pg, 0, 1); case PF_REKU:
break; DEC_IF_ABOVE(params.reku, 0, 1);
case PF_REKU: break;
DEC_IF_ABOVE(params.reku, 0, 1);
break;
} }
} }
void params_broadcast(ParamType param) void params_broadcast(ParamType param) {
{
int32_t value; int32_t value;
switch (param) switch (param) {
{ case PF_PLIM:
case PF_PLIM: value = params.plim;
value = params.plim; break;
break; case PF_TLIM:
case PF_TLIM: value = params.tlim;
value = params.tlim; break;
break; case PF_SLIM:
case PF_SLIM: value = params.slim;
value = params.slim; break;
break; case PF_TVEC:
case PF_TVEC: value = params.tvec;
value = params.tvec; break;
break; case PF_PG:
case PF_PG: value = params.pg;
value = params.pg; break;
break; case PF_REKU:
case PF_REKU: value = params.reku;
value = params.reku; break;
break; default:
default: return;
return;
} }
vehicle_broadcast_param(param, value); vehicle_broadcast_param(param, value);
} }
void params_thread_entry(ULONG _) {
tx_thread_sleep(TX_TIMER_TICKS_PER_SECOND);
while (1) {
for (size_t i = 0; i < ParamType_COUNT; i++) {
led_set(1, 0, 255, 0);
params_broadcast(i);
}
// Wait one second
tx_thread_sleep(TX_TIMER_TICKS_PER_SECOND);
}
}

View File

@ -13,8 +13,8 @@
#include "leds.h" #include "leds.h"
#define DRS_BUTTON_IDX (6) #define DRS_BUTTON_IDX (6)
#define DRS_PRESS_WAIT_CYCLES (10) #define DRS_PRESS_WAIT_CYCLES (1000)
static drs_press_buf_cycles = 0; static int drs_press_buf_cycles = 0;
void ui_thread_entry(ULONG _) { void ui_thread_entry(ULONG _) {
GPIO_TypeDef *button_ports[NUM_BUTTONS] = {BTN1_GPIO_Port, BTN2_GPIO_Port, GPIO_TypeDef *button_ports[NUM_BUTTONS] = {BTN1_GPIO_Port, BTN2_GPIO_Port,

View File

@ -1,16 +1,14 @@
#include "vehicle.h" #include "vehicle.h"
#include "main.h"
#include "ui.h"
#include "vehicle_state.h"
#include "can-halal.h" #include "can-halal.h"
#include "main.h"
#include "stm32h7xx.h" #include "stm32h7xx.h"
#include "stm32h7xx_hal.h" #include "stm32h7xx_hal.h"
#include "stm32h7xx_hal_fdcan.h" #include "stm32h7xx_hal_fdcan.h"
#include "stm32h7xx_hal_gpio.h" #include "stm32h7xx_hal_gpio.h"
#include "tx_api.h" #include "tx_api.h"
#include "ui.h"
#include "vehicle_state.h"
#define CAN_ID_AMS_SLAVE_PANIC 0x9 #define CAN_ID_AMS_SLAVE_PANIC 0x9
#define CAN_ID_AMS_STATUS 0xA #define CAN_ID_AMS_STATUS 0xA
@ -98,7 +96,8 @@ void vehicle_broadcast_param(ParamType param, int32_t value) {
void vehicle_broadcast_buttons(GPIO_PinState *button_states) { void vehicle_broadcast_buttons(GPIO_PinState *button_states) {
uint8_t data = (button_states[0] << 2) | (button_states[1] << 0) | uint8_t data = (button_states[0] << 2) | (button_states[1] << 0) |
(button_states[2] << 1) | (button_states[3] << 3); (button_states[2] << 1) | (button_states[3] << 3) |
(button_states[6] << 4);
ftcan_transmit(CAN_ID_STW_BUTTONS, &data, 1); ftcan_transmit(CAN_ID_STW_BUTTONS, &data, 1);
} }
@ -112,142 +111,144 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
} }
} else { } else {
switch (id) { switch (id) {
case CAN_ID_AMS_SLAVE_PANIC: case CAN_ID_AMS_SLAVE_PANIC:
vehicle_state.last_ams_slave_panic.id = data[0]; vehicle_state.last_ams_slave_panic.id = data[0];
vehicle_state.last_ams_slave_panic.kind = data[1]; vehicle_state.last_ams_slave_panic.kind = data[1];
ptr = &data[2]; ptr = &data[2];
vehicle_state.last_ams_slave_panic.arg = vehicle_state.last_ams_slave_panic.arg =
ftcan_unmarshal_unsigned(&ptr, 4); ftcan_unmarshal_unsigned(&ptr, 4);
break; break;
case CAN_ID_AMS_STATUS: case CAN_ID_AMS_STATUS:
vehicle_state.ts_state = data[0] & 0x7F; vehicle_state.ts_state = data[0] & 0x7F;
vehicle_state.sdc_closed = (data[0] & 0x80) >> 7; vehicle_state.sdc_closed = (data[0] & 0x80) >> 7;
vehicle_state.soc_ts = data[1]; vehicle_state.soc_ts = data[1];
ptr = &data[2]; ptr = &data[2];
vehicle_state.min_cell_volt = vehicle_state.min_cell_volt =
ftcan_unmarshal_unsigned(&ptr, 2) * CAN_AMS_STATUS_VOLTAGE_FACTOR; ftcan_unmarshal_unsigned(&ptr, 2) * CAN_AMS_STATUS_VOLTAGE_FACTOR;
vehicle_state.max_cell_temp = vehicle_state.max_cell_temp =
ftcan_unmarshal_signed(&ptr, 2) * CAN_AMS_STATUS_TEMP_FACTOR; ftcan_unmarshal_signed(&ptr, 2) * CAN_AMS_STATUS_TEMP_FACTOR;
vehicle_state.imd_ok = (data[6] >> 7); vehicle_state.imd_ok = (data[6] >> 7);
// TODO: Separate temperatures for left and right side of battery // TODO: Separate temperatures for left and right side of battery
vehicle_state.temps.bat_l = vehicle_state.max_cell_temp; vehicle_state.temps.bat_l = vehicle_state.max_cell_temp;
vehicle_state.temps.bat_r = vehicle_state.max_cell_temp; vehicle_state.temps.bat_r = vehicle_state.max_cell_temp;
break; break;
case CAN_ID_SDCL_TX: case CAN_ID_SDCL_TX:
vehicle_state.sdcl_state[0] = data[0] & CAN_SDCL_STATE_1_MASK; vehicle_state.sdcl_state[0] = data[0] & CAN_SDCL_STATE_1_MASK;
vehicle_state.sdcl_state[1] = data[0] & CAN_SDCL_STATE_2_MASK; vehicle_state.sdcl_state[1] = data[0] & CAN_SDCL_STATE_2_MASK;
vehicle_state.sdcl_state[2] = data[0] & CAN_SDCL_STATE_3_MASK; vehicle_state.sdcl_state[2] = data[0] & CAN_SDCL_STATE_3_MASK;
break; break;
case CAN_ID_PDU_RESPONSE: case CAN_ID_PDU_RESPONSE:
vehicle_state.pdu_sdc_active = data[0] & CAN_PDU_RESPONSE_SDC_TX_MASK; vehicle_state.pdu_sdc_active = data[0] & CAN_PDU_RESPONSE_SDC_TX_MASK;
break; break;
case CAN_ID_AMS_ERROR: case CAN_ID_AMS_ERROR:
vehicle_state.last_ams_error.kind = data[0]; vehicle_state.last_ams_error.kind = data[0];
vehicle_state.last_ams_error.arg = data[1]; vehicle_state.last_ams_error.arg = data[1];
break; break;
case CAN_ID_JETSON_TX: case CAN_ID_JETSON_TX:
vehicle_state.last_jetson_msg = HAL_GetTick(); vehicle_state.last_jetson_msg = HAL_GetTick();
vehicle_state.as_ok = data[0] & CAN_JETSON_TX_AS_OK_MASK; vehicle_state.as_ok = data[0] & CAN_JETSON_TX_AS_OK_MASK;
vehicle_state.desired_speed = vehicle_state.desired_speed =
((int8_t)data[1]) * CAN_JETSON_TX_SPEED_FACTOR; ((int8_t)data[1]) * CAN_JETSON_TX_SPEED_FACTOR;
vehicle_state.desired_angle = vehicle_state.desired_angle =
((int8_t)data[2]) * CAN_JETSON_TX_ANGLE_FACTOR; ((int8_t)data[2]) * CAN_JETSON_TX_ANGLE_FACTOR;
break; break;
case CAN_ID_ABX_DRIVER: case CAN_ID_ABX_DRIVER:
vehicle_state.brake_press_f = vehicle_state.brake_press_f =
(data[1] | ((data[2] & 0x0F) << 8)) * CAN_ABX_DRIVER_PRESS_FACTOR; (data[1] | ((data[2] & 0x0F) << 8)) * CAN_ABX_DRIVER_PRESS_FACTOR;
vehicle_state.brake_press_r = vehicle_state.brake_press_r =
((data[2] >> 4) | (data[3] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR; ((data[2] >> 4) | (data[3] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR;
vehicle_state.speed = data[5] * CAN_ABX_DRIVER_SPEED_FACTOR; vehicle_state.speed = data[5] * CAN_ABX_DRIVER_SPEED_FACTOR;
break; break;
case CAN_ID_ABX_HYDRAULICS: case CAN_ID_ABX_HYDRAULICS:
vehicle_state.hyd_press_a = vehicle_state.hyd_press_a =
(data[0] | ((data[1] & 0x0F) << 8)) * CAN_ABX_DRIVER_PRESS_FACTOR; (data[0] | ((data[1] & 0x0F) << 8)) * CAN_ABX_DRIVER_PRESS_FACTOR;
vehicle_state.hyd_press_b = vehicle_state.hyd_press_b =
((data[1] >> 4) | (data[2] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR; ((data[1] >> 4) | (data[2] << 4)) * CAN_ABX_DRIVER_PRESS_FACTOR;
break; break;
case CAN_ID_ABX_TIMINGS: case CAN_ID_ABX_TIMINGS:
vehicle_state.lap_best = (data[0] | (data[1] << 8)) * 0.01f; vehicle_state.lap_best = (data[0] | (data[1] << 8)) * 0.01f;
vehicle_state.lap_last = (data[2] | (data[3] << 8)) * 0.01f; vehicle_state.lap_last = (data[2] | (data[3] << 8)) * 0.01f;
break; break;
case CAN_ID_ABX_BRAKE_T: case CAN_ID_ABX_BRAKE_T:
vehicle_state.temps.brake_fl = (data[0] | (data[1] << 8)) * 0.01f; vehicle_state.temps.brake_fl = (data[0] | (data[1] << 8)) * 0.01f;
vehicle_state.temps.brake_fr = (data[2] | (data[3] << 8)) * 0.01f; vehicle_state.temps.brake_fr = (data[2] | (data[3] << 8)) * 0.01f;
vehicle_state.temps.brake_rl = (data[4] | (data[5] << 8)) * 0.01f; vehicle_state.temps.brake_rl = (data[4] | (data[5] << 8)) * 0.01f;
vehicle_state.temps.brake_rr = (data[6] | (data[7] << 8)) * 0.01f; vehicle_state.temps.brake_rr = (data[6] | (data[7] << 8)) * 0.01f;
break; break;
case CAN_ID_CS_INTERNAL: case CAN_ID_CS_INTERNAL:
vehicle_state.temps.inv_l = vehicle_state.temps.inv_l =
(data[0] | (data[1] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR; (data[0] | (data[1] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
vehicle_state.temps.inv_r = vehicle_state.temps.inv_r =
(data[2] | (data[3] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR; (data[2] | (data[3] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
vehicle_state.temps.mot_l = vehicle_state.temps.mot_l =
(data[4] | (data[5] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR; (data[4] | (data[5] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
vehicle_state.temps.mot_r = vehicle_state.temps.mot_r =
(data[6] | (data[7] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR; (data[6] | (data[7] << 8)) * CAN_CS_INTERNAL_TEMP_FACTOR;
break; break;
case CAN_ID_ABX_MISC: case CAN_ID_ABX_MISC:
vehicle_state.distance_total = vehicle_state.distance_total =
(data[3] | (data[4] << 8)) * CAN_ABX_MISC_DISTANCE_TOTAL_FACTOR; (data[3] | (data[4] << 8)) * CAN_ABX_MISC_DISTANCE_TOTAL_FACTOR;
vehicle_state.soc_lv = data[5]; vehicle_state.soc_lv = data[5];
vehicle_state.lv_bat_voltage = vehicle_state.lv_bat_voltage =
data[6] * CAN_ABX_MISC_LV_BAT_VOLTAGE_FACTOR; data[6] * CAN_ABX_MISC_LV_BAT_VOLTAGE_FACTOR;
break; break;
case CAN_ID_EPSC_OUT: case CAN_ID_EPSC_OUT:
vehicle_state.last_epsc_msg = HAL_GetTick(); vehicle_state.last_epsc_msg = HAL_GetTick();
vehicle_state.measured_angle = vehicle_state.measured_angle =
((int16_t)((data[0] << 8) | (data[1]))) * CAN_EPSC_OUT_ANGLE_FACTOR; ((int16_t)((data[0] << 8) | (data[1]))) * CAN_EPSC_OUT_ANGLE_FACTOR;
break; break;
case CAN_ID_AS_MISSION_FB: case CAN_ID_AS_MISSION_FB:
vehicle_state.active_mission = data[0] & 0b111; vehicle_state.active_mission = data[0] & 0b111;
break; break;
case CAN_ID_STW_STATUS: case CAN_ID_STW_STATUS:
vehicle_state.as_state = data[0] & 0b111; vehicle_state.as_state = data[0] & 0b111;
vehicle_state.r2d_progress = data[0] >> 4; vehicle_state.r2d_progress = data[0] >> 4;
vehicle_state.errors.invl_ready = (data[1] >> 0) & 1; vehicle_state.errors.invl_ready = (data[1] >> 0) & 1;
vehicle_state.errors.invr_ready = (data[1] >> 1) & 1; vehicle_state.errors.invr_ready = (data[1] >> 1) & 1;
vehicle_state.errors.sdc_bfl = (data[1] >> 2) & 1; vehicle_state.errors.sdc_bfl = (data[1] >> 2) & 1;
vehicle_state.errors.sdc_brl = (data[1] >> 3) & 1; vehicle_state.errors.sdc_brl = (data[1] >> 3) & 1;
vehicle_state.errors.sdc_acc = (data[1] >> 4) & 1; vehicle_state.errors.sdc_acc = (data[1] >> 4) & 1;
vehicle_state.errors.sdc_hvb = (data[1] >> 5) & 1; vehicle_state.errors.sdc_hvb = (data[1] >> 5) & 1;
vehicle_state.lap_count = data[2] & 0b111111; vehicle_state.lap_count = data[2] & 0b111111;
vehicle_state.ini_chk_state = data[3]; vehicle_state.ini_chk_state = data[3];
vehicle_state.errors.err_sdc = (data[4] >> 0) & 1; vehicle_state.errors.err_sdc = (data[4] >> 0) & 1;
vehicle_state.errors.err_ams = (data[4] >> 1) & 1; vehicle_state.errors.err_ams = (data[4] >> 1) & 1;
vehicle_state.errors.err_pdu = (data[4] >> 2) & 1; vehicle_state.errors.err_pdu = (data[4] >> 2) & 1;
vehicle_state.errors.err_ini_chk = (data[4] >> 3) & 1; vehicle_state.errors.err_ini_chk = (data[4] >> 3) & 1;
vehicle_state.errors.err_con_mon = (data[4] >> 4) & 1; vehicle_state.errors.err_con_mon = (data[4] >> 4) & 1;
vehicle_state.errors.err_scs = (data[4] >> 5) & 1; vehicle_state.errors.err_scs = (data[4] >> 5) & 1;
vehicle_state.errors.err_sbspd = (data[4] >> 6) & 1; vehicle_state.errors.err_sbspd = (data[4] >> 6) & 1;
vehicle_state.errors.err_appsp = (data[4] >> 7) & 1; vehicle_state.errors.err_appsp = (data[4] >> 7) & 1;
vehicle_state.errors.err_as = (data[5] >> 0) & 1; vehicle_state.errors.err_as = (data[5] >> 0) & 1;
vehicle_state.errors.err_ros = (data[5] >> 1) & 1; vehicle_state.errors.err_ros = (data[5] >> 1) & 1;
vehicle_state.errors.err_res = (data[5] >> 2) & 1; vehicle_state.errors.err_res = (data[5] >> 2) & 1;
vehicle_state.errors.err_invl = (data[5] >> 3) & 1; vehicle_state.errors.err_invl = (data[5] >> 3) & 1;
vehicle_state.errors.err_invr = (data[5] >> 4) & 1; vehicle_state.errors.err_invr = (data[5] >> 4) & 1;
break; break;
case CAN_ID_ABX_PARAM_CONFIRMED: case CAN_ID_ABX_PARAM_CONFIRMED:
vehicle_state.last_param_confirmed = data[0]; vehicle_state.last_param_confirmed = data[0];
tx_event_flags_set(&gui_update_events, GUI_UPDATE_PARAM_CONFIRMED, TX_OR); tx_event_flags_set(&gui_update_events, GUI_UPDATE_PARAM_CONFIRMED,
break; TX_OR);
case CAN_ID_SHUNT_CURRENT: { break;
// The first two bytes of shunt result messages are metadata case CAN_ID_SHUNT_CURRENT: {
const uint8_t *result_ptr = &data[2]; // The first two bytes of shunt result messages are metadata
vehicle_state.ts_current = ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3; const uint8_t *result_ptr = &data[2];
break; vehicle_state.ts_current =
} ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
case CAN_ID_SHUNT_VOLTAGE1: { break;
const uint8_t *result_ptr = &data[2]; }
vehicle_state.ts_voltage_bat = case CAN_ID_SHUNT_VOLTAGE1: {
ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3; const uint8_t *result_ptr = &data[2];
break; vehicle_state.ts_voltage_bat =
} ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
case CAN_ID_SHUNT_VOLTAGE2: { break;
const uint8_t *result_ptr = &data[2]; }
vehicle_state.ts_voltage_veh = case CAN_ID_SHUNT_VOLTAGE2: {
ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3; const uint8_t *result_ptr = &data[2];
break; vehicle_state.ts_voltage_veh =
} ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
break;
}
} }
} }
tx_event_flags_set(&gui_update_events, GUI_UPDATE_VEHICLE_STATE, TX_OR); tx_event_flags_set(&gui_update_events, GUI_UPDATE_VEHICLE_STATE, TX_OR);

View File

@ -29,6 +29,7 @@ cDefinitions:
cxxDefinitions: cxxDefinitions:
- USE_HAL_DRIVER - USE_HAL_DRIVER
- STM32H7A3xx - STM32H7A3xx
- COMPILER_GIT_BUILD_HASH="a07d51f"
asDefinitions: [] asDefinitions: []
@ -170,3 +171,4 @@ customMakefileRules:
makeFlags: makeFlags:
# - -O # use this option when the output of make is mixed up only works for make version 4.0 and upwards # - -O # use this option when the output of make is mixed up only works for make version 4.0 and upwards
# - --silent # use this option to silence the output of the build # - --silent # use this option to silence the output of the build
# - -j1

View File

@ -17,7 +17,7 @@ CountedEnum(DataFieldType, size_t, DF_TSState, DF_ASState, DF_ActiveMission,
DF_Speed, DF_BBal, DF_BPF, DF_BPR, DF_DistanceTotal, DF_TempMotL, DF_Speed, DF_BBal, DF_BPF, DF_BPR, DF_DistanceTotal, DF_TempMotL,
DF_TempMotR, DF_TempInvL, DF_TempInvR, DF_TempBrakeFL, DF_TempMotR, DF_TempInvL, DF_TempInvR, DF_TempBrakeFL,
DF_TempBrakeFR, DF_TempBrakeRL, DF_TempBrakeRR, DF_LapBest, DF_TempBrakeFR, DF_TempBrakeRL, DF_TempBrakeRR, DF_LapBest,
DF_LapLast, DF_LVBatVoltage); DF_LapLast, DF_LVBatVoltage, DF_GitBuildHash);
enum class NamedFieldKind { Float, Bool, Text, Int }; enum class NamedFieldKind { Float, Bool, Text, Int };

View File

@ -9,17 +9,27 @@
#include <algorithm> #include <algorithm>
#include <cstring> #include <cstring>
#define _STRINGIZE(x) #x
#define STRINGIZE(x) _STRINGIZE(x)
#ifndef COMPILER_GIT_BUILD_HASH
#define COMPILER_GIT_BUILD_HASH "git id not found"
#endif
static const char* git_hash = STRINGIZE(COMPILER_GIT_BUILD_HASH);
#define VEH_FIELD(FIELD) []() { return (void *)&vehicle_state.FIELD; } #define VEH_FIELD(FIELD) []() { return (void *)&vehicle_state.FIELD; }
#define VEH_BIT_FIELD(FIELD) \ #define VEH_BIT_FIELD(FIELD) \
[]() { \ []() { \
static int x; \ static int x; \
x = vehicle_state.FIELD; \ x = vehicle_state.FIELD; \
return (void *)&x; \ return (void *)&x; \
} }
void *get_tsstate_text() { void *get_tsstate_text()
{
const char *text; const char *text;
switch (vehicle_state.ts_state) { switch (vehicle_state.ts_state)
{
case TS_INACTIVE: case TS_INACTIVE:
text = "INACT"; text = "INACT";
break; break;
@ -47,9 +57,11 @@ void *get_tsstate_text() {
return (void *)text; return (void *)text;
} }
void *get_asstate_text() { void *get_asstate_text()
{
const char *text; const char *text;
switch (vehicle_state.as_state) { switch (vehicle_state.as_state)
{
case AS_OFF: case AS_OFF:
text = "OFF"; text = "OFF";
break; break;
@ -74,9 +86,11 @@ void *get_asstate_text() {
return (void *)text; return (void *)text;
} }
void *get_mission_text() { void *get_mission_text()
{
const char *text; const char *text;
switch (vehicle_state.active_mission) { switch (vehicle_state.active_mission)
{
case MISSION_NONE: case MISSION_NONE:
text = "NONE"; text = "NONE";
break; break;
@ -107,9 +121,11 @@ void *get_mission_text() {
return (void *)text; return (void *)text;
} }
void *get_r2dprog_text() { void *get_r2dprog_text()
{
const char *text; const char *text;
switch (vehicle_state.r2d_progress) { switch (vehicle_state.r2d_progress)
{
case R2D_NONE: case R2D_NONE:
text = "NONE"; text = "NONE";
break; break;
@ -143,61 +159,106 @@ void *get_r2dprog_text() {
return (void *)text; return (void *)text;
} }
void *get_inichk_text() { void *get_inichk_text()
{
return (void *)inichkstate_str(vehicle_state.ini_chk_state); return (void *)inichkstate_str(vehicle_state.ini_chk_state);
} }
void *get_sdc_text() { void *get_sdc_text()
{
const char *text; const char *text;
if (vehicle_state.errors.sdc_bfl) { if (vehicle_state.errors.sdc_bfl)
{
text = "BFL"; text = "BFL";
} else if (vehicle_state.errors.sdc_brl) { }
else if (vehicle_state.errors.sdc_brl)
{
text = "BRL"; text = "BRL";
} else if (vehicle_state.errors.sdc_acc) { }
else if (vehicle_state.errors.sdc_acc)
{
text = "ACC"; text = "ACC";
} else if (vehicle_state.errors.sdc_hvb) { }
else if (vehicle_state.errors.sdc_hvb)
{
text = "HVB"; text = "HVB";
} else { }
else
{
text = "CLOSED"; text = "CLOSED";
} }
return (void *)text; return (void *)text;
} }
void *get_err_text() { void *get_err_text()
{
const char *text; const char *text;
if (vehicle_state.errors.err_sdc) { if (vehicle_state.errors.err_sdc)
{
text = "SDC"; text = "SDC";
} else if (vehicle_state.errors.err_ams) { }
else if (vehicle_state.errors.err_ams)
{
text = "AMS"; text = "AMS";
} else if (vehicle_state.errors.err_pdu) { }
else if (vehicle_state.errors.err_pdu)
{
text = "PDU"; text = "PDU";
} else if (vehicle_state.errors.err_ini_chk) { }
else if (vehicle_state.errors.err_ini_chk)
{
text = "IniChk"; text = "IniChk";
} else if (vehicle_state.errors.err_con_mon) { }
else if (vehicle_state.errors.err_con_mon)
{
text = "ConMon"; text = "ConMon";
} else if (vehicle_state.errors.err_scs) { }
else if (vehicle_state.errors.err_scs)
{
text = "SCS"; text = "SCS";
} else if (vehicle_state.errors.err_sbspd) { }
else if (vehicle_state.errors.err_sbspd)
{
text = "sBSPD"; text = "sBSPD";
} else if (vehicle_state.errors.err_appsp) { }
else if (vehicle_state.errors.err_appsp)
{
text = "APPSp"; text = "APPSp";
} else if (vehicle_state.errors.err_as) { }
else if (vehicle_state.errors.err_as)
{
text = "AS"; text = "AS";
} else if (vehicle_state.errors.err_ros) { }
else if (vehicle_state.errors.err_ros)
{
text = "ROS"; text = "ROS";
} else if (vehicle_state.errors.err_res) { }
else if (vehicle_state.errors.err_res)
{
text = "RES"; text = "RES";
} else if (vehicle_state.errors.err_invl) { }
else if (vehicle_state.errors.err_invl)
{
text = "INVL"; text = "INVL";
} else if (vehicle_state.errors.err_invr) { }
else if (vehicle_state.errors.err_invr)
{
text = "INVR"; text = "INVR";
} else { }
else
{
text = "NONE"; text = "NONE";
} }
return (void *)text; return (void *)text;
} }
void *get_zero() { void *get_compiler_build_hash()
{
return (void *)git_hash;
}
void *get_zero()
{
static float zero = 0.0f; static float zero = 0.0f;
return &zero; return &zero;
} }
@ -265,7 +326,7 @@ NamedFieldDescription dataFieldDescs[] = {
VEH_FIELD(lap_last)}, VEH_FIELD(lap_last)},
[DF_LVBatVoltage] = {NamedFieldKind::Float, "LVVBAT", 2, 2, [DF_LVBatVoltage] = {NamedFieldKind::Float, "LVVBAT", 2, 2,
VEH_FIELD(lv_bat_voltage)}, VEH_FIELD(lv_bat_voltage)},
}; [DF_GitBuildHash] = {NamedFieldKind::Text, "BLDHASH", 1, 0, get_compiler_build_hash}};
static_assert(sizeof(dataFieldDescs) / sizeof(dataFieldDescs[0]) == static_assert(sizeof(dataFieldDescs) / sizeof(dataFieldDescs[0]) ==
DataFieldType_COUNT, DataFieldType_COUNT,
@ -275,7 +336,7 @@ static_assert(sizeof(dataFieldDescs) / sizeof(dataFieldDescs[0]) ==
NamedFieldDescription paramFieldDescs[] = { NamedFieldDescription paramFieldDescs[] = {
[PF_PLIM] = {NamedFieldKind::Int, "PLIM", 2, 0, PARAM_FIELD(plim)}, [PF_PLIM] = {NamedFieldKind::Int, "PLIM", 2, 0, PARAM_FIELD(plim)},
[PF_TLIM] = {NamedFieldKind::Int, "TLIM", 2, 1, PARAM_FIELD(plim)}, [PF_TLIM] = {NamedFieldKind::Int, "TLIM", 4, 1, PARAM_FIELD(tlim)},
[PF_SLIM] = {NamedFieldKind::Int, "SLIM", 2, 2, PARAM_FIELD(slim)}, [PF_SLIM] = {NamedFieldKind::Int, "SLIM", 2, 2, PARAM_FIELD(slim)},
[PF_TVEC] = {NamedFieldKind::Int, "TVEC", 2, 1, PARAM_FIELD(tvec)}, [PF_TVEC] = {NamedFieldKind::Int, "TVEC", 2, 1, PARAM_FIELD(tvec)},
[PF_PG] = {NamedFieldKind::Int, "PG", 2, 0, PARAM_FIELD(pg)}, [PF_PG] = {NamedFieldKind::Int, "PG", 2, 0, PARAM_FIELD(pg)},
@ -291,31 +352,38 @@ size_t dataFieldAlphaIndexByField[DataFieldType_COUNT];
ParamType paramByAlphaIndex[ParamType_COUNT]; ParamType paramByAlphaIndex[ParamType_COUNT];
size_t paramAlphaIndexByParam[ParamType_COUNT]; size_t paramAlphaIndexByParam[ParamType_COUNT];
template <class T> struct NFAlphabeticComp { template <class T>
struct NFAlphabeticComp
{
NFAlphabeticComp(const NamedFieldDescription *fieldDescs) NFAlphabeticComp(const NamedFieldDescription *fieldDescs)
: fieldDescs{fieldDescs} {} : fieldDescs{fieldDescs} {}
const NamedFieldDescription *fieldDescs; const NamedFieldDescription *fieldDescs;
bool operator()(const T &a, const T &b) const { bool operator()(const T &a, const T &b) const
{
return strcmp(fieldDescs[a].title, fieldDescs[b].title) < 0; return strcmp(fieldDescs[a].title, fieldDescs[b].title) < 0;
} }
}; };
template <class T> template <class T>
void namedFieldSort(const NamedFieldDescription *fieldDescs, T *fieldByAlpha, void namedFieldSort(const NamedFieldDescription *fieldDescs, T *fieldByAlpha,
size_t *alphaIndexByField, size_t numFields) { size_t *alphaIndexByField, size_t numFields)
for (size_t i = 0; i < numFields; i++) { {
for (size_t i = 0; i < numFields; i++)
{
fieldByAlpha[i] = static_cast<T>(i); fieldByAlpha[i] = static_cast<T>(i);
} }
std::sort(fieldByAlpha, fieldByAlpha + numFields, std::sort(fieldByAlpha, fieldByAlpha + numFields,
NFAlphabeticComp<T>(fieldDescs)); NFAlphabeticComp<T>(fieldDescs));
for (size_t i = 0; i < numFields; i++) { for (size_t i = 0; i < numFields; i++)
{
alphaIndexByField[fieldByAlpha[i]] = i; alphaIndexByField[fieldByAlpha[i]] = i;
} }
} }
void namedFieldSort() { void namedFieldSort()
{
namedFieldSort(dataFieldDescs, dataFieldByAlphaIndex, namedFieldSort(dataFieldDescs, dataFieldByAlphaIndex,
dataFieldAlphaIndexByField, DataFieldType_COUNT); dataFieldAlphaIndexByField, DataFieldType_COUNT);
namedFieldSort(paramFieldDescs, paramByAlphaIndex, paramAlphaIndexByParam, namedFieldSort(paramFieldDescs, paramByAlphaIndex, paramAlphaIndexByParam,
@ -326,7 +394,9 @@ template <class T>
NamedField<T>::NamedField(const NamedFieldDescription *fieldDescs) NamedField<T>::NamedField(const NamedFieldDescription *fieldDescs)
: fieldDescs{fieldDescs} {} : fieldDescs{fieldDescs} {}
template <class T> void NamedField<T>::setType(T type) { template <class T>
void NamedField<T>::setType(T type)
{
this->type = type; this->type = type;
desc = &fieldDescs[type]; desc = &fieldDescs[type];
@ -338,11 +408,15 @@ template <class T> void NamedField<T>::setType(T type) {
updateValue(); updateValue();
} }
template <class T> const T &NamedField<T>::getType() { return type; } template <class T>
const T &NamedField<T>::getType() { return type; }
template <class T> void NamedField<T>::updateValue() { template <class T>
void NamedField<T>::updateValue()
{
void *val = desc->getValue(); void *val = desc->getValue();
switch (desc->kind) { switch (desc->kind)
{
case NamedFieldKind::Float: case NamedFieldKind::Float:
setFloatValue(*static_cast<float *>(val)); setFloatValue(*static_cast<float *>(val));
break; break;
@ -358,32 +432,45 @@ template <class T> void NamedField<T>::updateValue() {
} }
} }
template <class T> void NamedField<T>::setFloatValue(float floatValue) { template <class T>
void NamedField<T>::setFloatValue(float floatValue)
{
fieldValue.f = floatValue; fieldValue.f = floatValue;
updateValueBuffer(); updateValueBuffer();
} }
template <class T> void NamedField<T>::setBoolValue(int boolValue) { template <class T>
void NamedField<T>::setBoolValue(int boolValue)
{
fieldValue.b = boolValue; fieldValue.b = boolValue;
updateValueBuffer(); updateValueBuffer();
} }
template <class T> void NamedField<T>::setIntValue(int intValue) { template <class T>
void NamedField<T>::setIntValue(int intValue)
{
fieldValue.i = intValue; fieldValue.i = intValue;
updateValueBuffer(); updateValueBuffer();
} }
template <class T> void NamedField<T>::setStrValue(const char *strValue) { template <class T>
void NamedField<T>::setStrValue(const char *strValue)
{
touchgfx::Unicode::strncpy(valueBuffer, strValue, touchgfx::Unicode::strncpy(valueBuffer, strValue,
sizeof(valueBuffer) / sizeof(*valueBuffer)); sizeof(valueBuffer) / sizeof(*valueBuffer));
updateValueBuffer(); updateValueBuffer();
} }
template <class T> void NamedField<T>::updateValueBuffer() { template <class T>
switch (desc->kind) { void NamedField<T>::updateValueBuffer()
case NamedFieldKind::Float: { {
switch (desc->kind)
{
case NamedFieldKind::Float:
{
size_t width = desc->int_digits; size_t width = desc->int_digits;
if (desc->decimal_digits != 0) { if (desc->decimal_digits != 0)
{
width += desc->decimal_digits + 1; // 1 digit for the decimal point width += desc->decimal_digits + 1; // 1 digit for the decimal point
} }
float params[3] = {(float)width, (float)desc->decimal_digits, fieldValue.f}; float params[3] = {(float)width, (float)desc->decimal_digits, fieldValue.f};
@ -392,7 +479,8 @@ template <class T> void NamedField<T>::updateValueBuffer() {
params); params);
break; break;
} }
case NamedFieldKind::Bool: { case NamedFieldKind::Bool:
{
const char *str = fieldValue.b ? "YES" : "NO"; const char *str = fieldValue.b ? "YES" : "NO";
touchgfx::Unicode::strncpy(valueBuffer, str, touchgfx::Unicode::strncpy(valueBuffer, str,
sizeof(valueBuffer) / sizeof(*valueBuffer)); sizeof(valueBuffer) / sizeof(*valueBuffer));