Compare commits
	
		
			5 Commits
		
	
	
		
			a07d51f223
			...
			2024
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 59262443c9 | |||
| 25da5cde32 | |||
| 10aa474124 | |||
| 5fb5d271b1 | |||
| a4bea0d78b | 
							
								
								
									
										7
									
								
								.stm32env
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								.stm32env
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,7 @@
 | 
				
			|||||||
 | 
					# environment variable file used by stm32-for-vscode and the STM32Make.make makefile
 | 
				
			||||||
 | 
					# Other environment variables can be added here. If wanting to use the generated makefile in CI/CD context please
 | 
				
			||||||
 | 
					# configure the following variables: GCC_PATH, OPENOCD
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					ARM_GCC_PATH = /Applications/ArmGNUToolchain/13.2.Rel1/arm-none-eabi/bin
 | 
				
			||||||
 | 
					OPENOCD = /opt/homebrew/bin/openocd
 | 
				
			||||||
 | 
					 
 | 
				
			||||||
@ -5,8 +5,10 @@
 | 
				
			|||||||
/**
 | 
					/**
 | 
				
			||||||
 * 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 definitely better to have them
 | 
				
			||||||
#define INC_IF_BELOW(param_val, max_val, incr_amt) ((param_val) = ((param_val) + (incr_amt)) > (max_val) ? ((param_val) + (incr_amt)) : (max_val))
 | 
					// 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};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -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,
 | 
				
			||||||
 | 
				
			|||||||
@ -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);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -228,12 +227,14 @@ void ftcan_msg_received_cb(uint16_t id, size_t datalen, const uint8_t *data) {
 | 
				
			|||||||
        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,
 | 
				
			||||||
 | 
					                           TX_OR);
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      case CAN_ID_SHUNT_CURRENT: {
 | 
					      case CAN_ID_SHUNT_CURRENT: {
 | 
				
			||||||
        // The first two bytes of shunt result messages are metadata
 | 
					        // The first two bytes of shunt result messages are metadata
 | 
				
			||||||
        const uint8_t *result_ptr = &data[2];
 | 
					        const uint8_t *result_ptr = &data[2];
 | 
				
			||||||
      vehicle_state.ts_current = ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
 | 
					        vehicle_state.ts_current =
 | 
				
			||||||
 | 
					            ftcan_unmarshal_signed(&result_ptr, 4) * 1e-3;
 | 
				
			||||||
        break;
 | 
					        break;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      case CAN_ID_SHUNT_VOLTAGE1: {
 | 
					      case CAN_ID_SHUNT_VOLTAGE1: {
 | 
				
			||||||
 | 
				
			|||||||
@ -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
 | 
				
			||||||
 | 
				
			|||||||
@ -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 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -9,6 +9,14 @@
 | 
				
			|||||||
#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) \
 | 
				
			||||||
  []() {                     \
 | 
					  []() {                     \
 | 
				
			||||||
@ -17,9 +25,11 @@
 | 
				
			|||||||
    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));
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user