1
0
forked from me/IronOS

Generate per-language translation sources (#806)

This generates dedicates Translation.cpp files for translation language
and derives all language-specific data from them.

The Makefile is extended to also take care of generating these source
files.
This allows reuse of nearly all object files between builds of different
languages for the same model and regenerating the translation sources if
necessary.
This speeds up the release builds and the normal write-compile-cycle
considerably.
It also eliminates miscompilations when manually building different
languages.
This commit is contained in:
Thomas Weißschuh
2021-02-02 09:44:34 +01:00
committed by GitHub
parent 5e372310cd
commit 15e51f9faa
36 changed files with 108 additions and 266 deletions

View File

@@ -53,9 +53,7 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
}
uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) { return convertuVToDegC(convertTipRawADCTouV(rawADC)); }
#ifdef ENABLED_FAHRENHEIT_SUPPORT
uint32_t TipThermoModel::convertTipRawADCToDegF(uint16_t rawADC) { return convertuVToDegF(convertTipRawADCTouV(rawADC)); }
#endif
// Table that is designed to be walked to find the best sample for the lookup
@@ -196,7 +194,6 @@ uint32_t TipThermoModel::convertuVToDegC(uint32_t tipuVDelta) {
return 0;
}
#ifdef ENABLED_FAHRENHEIT_SUPPORT
uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); }
uint32_t TipThermoModel::convertCtoF(uint32_t degC) {
@@ -211,7 +208,6 @@ uint32_t TipThermoModel::convertFtoC(uint32_t degF) {
}
return ((degF - 32) * 5) / 9;
}
#endif
uint32_t TipThermoModel::getTipInC(bool sampleNow) {
int32_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(getTipRawTemp(sampleNow));
@@ -224,13 +220,12 @@ uint32_t TipThermoModel::getTipInC(bool sampleNow) {
return 0;
return currentTipTempInC;
}
#ifdef ENABLED_FAHRENHEIT_SUPPORT
uint32_t TipThermoModel::getTipInF(bool sampleNow) {
uint32_t currentTipTempInF = getTipInC(sampleNow);
currentTipTempInF = convertCtoF(currentTipTempInF);
return currentTipTempInF;
}
#endif
uint32_t TipThermoModel::getTipMaxInC() {
uint32_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(0x7FFF - (21 * 5)); // back off approx 5 deg c from ADC max

View File

@@ -9,34 +9,25 @@
#define SRC_TIPTHERMOMODEL_H_
#include "BSP.h"
#include "stdint.h"
#include "unit.h"
class TipThermoModel {
public:
// These are the main two functions
static uint32_t getTipInC(bool sampleNow = false);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static uint32_t getTipInF(bool sampleNow = false);
#endif
// Calculates the maximum temperature can can be read by the ADC range
static uint32_t getTipMaxInC();
static uint32_t convertTipRawADCToDegC(uint16_t rawADC);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static uint32_t convertTipRawADCToDegF(uint16_t rawADC);
#endif
// Returns the uV of the tip reading before the op-amp compensating for pullups
static uint32_t convertTipRawADCTouV(uint16_t rawADC);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static uint32_t convertCtoF(uint32_t degC);
static uint32_t convertFtoC(uint32_t degF);
#endif
private:
static uint32_t convertuVToDegC(uint32_t tipuVDelta);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static uint32_t convertuVToDegF(uint32_t tipuVDelta);
#endif
};
#endif /* SRC_TIPTHERMOMODEL_H_ */

View File

@@ -10,7 +10,6 @@
#include "FreeRTOS.h"
#include "cmsis_os.h"
#include "unit.h"
#ifdef __cplusplus
extern "C" {

View File

@@ -9,9 +9,8 @@
#ifndef SETTINGS_H_
#define SETTINGS_H_
#include "unit.h"
#include <stdint.h>
#define SETTINGSVERSION (0x24)
#define SETTINGSVERSION (0x25)
/*Change this if you change the struct below to prevent people getting \
out of sync*/
@@ -37,9 +36,7 @@ typedef struct {
// down screen until its <50C
uint8_t detailedIDLE : 1; // Detailed idle screen
uint8_t detailedSoldering : 1; // Detailed soldering screens
#ifdef ENABLED_FAHRENHEIT_SUPPORT
uint8_t temperatureInF : 1; // Should the temp be in F or C (true is F)
#endif
uint8_t descriptionScrollSpeed : 1; // Description scroll speed
uint8_t lockingMode : 2; // Store the locking mode
uint8_t KeepAwakePulse; // Keep Awake pulse power in 0.1 watts (10 = 1Watt)

View File

@@ -8,9 +8,9 @@
#ifndef TRANSLATION_H_
#define TRANSLATION_H_
#include "stdint.h"
#include "unit.h"
extern const uint8_t USER_FONT_12[];
extern const uint8_t USER_FONT_6x8[];
extern const bool HasFahrenheit;
extern const char *SettingsShortNames[29][2];
extern const char *SettingsDescriptions[29];
@@ -70,9 +70,7 @@ extern const char *SymbolMinus;
extern const char *SymbolSpace;
extern const char *SymbolDot;
extern const char *SymbolDegC;
#ifdef ENABLED_FAHRENHEIT_SUPPORT
extern const char *SymbolDegF;
#endif
extern const char *SymbolMinutes;
extern const char *SymbolSeconds;
extern const char *SymbolWatts;

View File

@@ -67,9 +67,7 @@ void resetSettings() {
systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety
systemSettings.lockingMode = LOCKING_MODE; // Disable locking for safety
systemSettings.coolingTempBlink = COOLING_TEMP_BLINK; // Blink the temperature on the cooling screen when its > 50C
#ifdef ENABLED_FAHRENHEIT_SUPPORT
systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0
#endif
systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow
systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV
systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit

View File

@@ -13,7 +13,6 @@
#include "cmsis_os.h"
#include "main.hpp"
#include "string.h"
#include "unit.h"
void gui_Menu(const menuitem *menu);
@@ -33,10 +32,8 @@ static bool settings_setShutdownTime(void);
static void settings_displayShutdownTime(void);
static bool settings_setSensitivity(void);
static void settings_displaySensitivity(void);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static bool settings_setTempF(void);
static void settings_displayTempF(void);
#endif
static bool settings_setAdvancedSolderingScreens(void);
static void settings_displayAdvancedSolderingScreens(void);
static bool settings_setAdvancedIDLEScreens(void);
@@ -168,9 +165,7 @@ const menuitem UIMenu[] = {
* Cooldown blink
* Reverse Temp change buttons + -
*/
#ifdef ENABLED_FAHRENHEIT_SUPPORT
{(const char *)SettingsDescriptions[5], settings_setTempF, settings_displayTempF}, /* Temperature units*/
#endif
{(const char *)SettingsDescriptions[5], settings_setTempF, settings_displayTempF}, /* Temperature units, this has to be the first element in the array to work with the logic in settings_enterUIMenu() */
{(const char *)SettingsDescriptions[7], settings_setDisplayRotation, settings_displayDisplayRotation}, /*Display Rotation*/
{(const char *)SettingsDescriptions[10], settings_setCoolingBlinkEnabled, settings_displayCoolingBlinkEnabled}, /*Cooling blink warning*/
{(const char *)SettingsDescriptions[15], settings_setScrollSpeed, settings_displayScrollSpeed}, /*Scroll Speed for descriptions*/
@@ -341,15 +336,12 @@ static void settings_displayQCInputV(void) {
#endif
static bool settings_setSleepTemp(void) {
// If in C, 10 deg, if in F 20 deg
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) {
systemSettings.SleepTemp += 20;
if (systemSettings.SleepTemp > 580)
systemSettings.SleepTemp = 60;
return systemSettings.SleepTemp == 580;
} else
#endif
{
} else {
systemSettings.SleepTemp += 10;
if (systemSettings.SleepTemp > 300)
systemSettings.SleepTemp = 10;
@@ -405,7 +397,6 @@ static void settings_displayShutdownTime(void) {
OLED::print(SymbolMinutes);
}
}
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static bool settings_setTempF(void) {
systemSettings.temperatureInF = !systemSettings.temperatureInF;
if (systemSettings.temperatureInF) {
@@ -436,7 +427,6 @@ static void settings_displayTempF(void) {
OLED::print((systemSettings.temperatureInF) ? SymbolDegF : SymbolDegC);
}
#endif
static bool settings_setSensitivity(void) {
systemSettings.sensitivity++;
@@ -540,7 +530,6 @@ static void settings_displayDisplayRotation(void) {
}
static bool settings_setBoostTemp(void) {
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) {
if (systemSettings.BoostTemp == 0) {
systemSettings.BoostTemp = 480; // loop back at 480
@@ -552,9 +541,7 @@ static bool settings_setBoostTemp(void) {
systemSettings.BoostTemp = 0; // jump to off
}
return systemSettings.BoostTemp == 840;
} else
#endif
{
} else {
if (systemSettings.BoostTemp == 0) {
systemSettings.BoostTemp = 250; // loop back at 250
} else {
@@ -907,7 +894,7 @@ static bool settings_enterPowerMenu(void) {
}
static void settings_displayUIMenu(void) { displayMenu(2); }
static bool settings_enterUIMenu(void) {
gui_Menu(UIMenu);
gui_Menu(HasFahrenheit ? UIMenu : UIMenu + 1);
return false;
}
static void settings_displayAdvancedMenu(void) { displayMenu(3); }

View File

@@ -18,7 +18,6 @@ extern "C" {
#include "main.hpp"
#include "stdlib.h"
#include "string.h"
#include "unit.h"
#include <MMA8652FC.hpp>
#include <gui.hpp>
#include <history.hpp>
@@ -69,11 +68,9 @@ void GUIDelay() {
void gui_drawTipTemp(bool symbol) {
// Draw tip temp handling unit conversion & tolerance near setpoint
uint32_t Temp = 0;
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) {
Temp = TipThermoModel::getTipInF();
} else
#endif
{
Temp = TipThermoModel::getTipInC();
}
@@ -82,19 +79,15 @@ void gui_drawTipTemp(bool symbol) {
if (symbol) {
if (OLED::getFont() == 0) {
// Big font, can draw nice symbols
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
else
#endif
OLED::drawSymbol(1);
} else {
// Otherwise fall back to chars
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
OLED::print(SymbolDegF);
else
#endif
OLED::print(SymbolDegC);
}
}
@@ -252,15 +245,12 @@ static void gui_solderingTempAdjust() {
autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN;
}
// constrain between 10-450 C
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) {
if (systemSettings.SolderingTemp > 850)
systemSettings.SolderingTemp = 850;
if (systemSettings.SolderingTemp < 60)
systemSettings.SolderingTemp = 60;
} else
#endif
{
} else {
if (systemSettings.SolderingTemp > 450)
systemSettings.SolderingTemp = 450;
if (systemSettings.SolderingTemp < 10)
@@ -282,11 +272,9 @@ static void gui_solderingTempAdjust() {
OLED::print(SymbolSpace);
OLED::printNumber(systemSettings.SolderingTemp, 3);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
else
#endif
{
OLED::drawSymbol(1);
}
@@ -330,22 +318,16 @@ static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
if (checkVoltageForExit())
return 1; // return non-zero on error
#endif
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF) {
currentTempTargetDegC = stayOff ? 0 : TipThermoModel::convertFtoC(min(systemSettings.SleepTemp, systemSettings.SolderingTemp));
} else
#endif
{
} else {
currentTempTargetDegC = stayOff ? 0 : min(systemSettings.SleepTemp, systemSettings.SolderingTemp);
}
// draw the lcd
uint16_t tipTemp;
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
tipTemp = TipThermoModel::getTipInF();
else
#endif
{
else {
tipTemp = TipThermoModel::getTipInC();
}
@@ -357,12 +339,9 @@ static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
OLED::setCursor(0, 8);
OLED::print(SleepingTipAdvancedString);
OLED::printNumber(tipTemp, 3);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
OLED::print(SymbolDegF);
else
#endif
{
else {
OLED::print(SymbolDegC);
}
@@ -373,12 +352,9 @@ static int gui_SolderingSleepingMode(bool stayOff, bool autoStarted) {
OLED::setFont(0);
OLED::print(SleepingSimpleString);
OLED::printNumber(tipTemp, 3);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
OLED::drawSymbol(0);
else
#endif
{
else {
OLED::drawSymbol(1);
}
}
@@ -613,21 +589,15 @@ static void gui_solderingMode(uint8_t jumpToSleep) {
// Update the setpoints for the temperature
if (boostModeOn) {
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.BoostTemp);
else
#endif
{
else {
currentTempTargetDegC = (systemSettings.BoostTemp);
}
} else {
#ifdef ENABLED_FAHRENHEIT_SUPPORT
if (systemSettings.temperatureInF)
currentTempTargetDegC = TipThermoModel::convertFtoC(systemSettings.SolderingTemp);
else
#endif
{
else {
currentTempTargetDegC = (systemSettings.SolderingTemp);
}
}

View File

@@ -2,10 +2,9 @@
ifndef model
model:=TS100
endif
OUTPUT_EXE=$(model)_$(lang)
ifndef lang
lang:= EN
endif
ALL_LANGUAGES=BG CS DA DE EN ES FI FR HR HU IT LT NL NL_BE NO PL PT RU SK SL SR_CYRL SR_LATN SV TR UK
# Enumerate all of the include directories
APP_INC_DIR = ./Core/Inc
@@ -104,7 +103,6 @@ INCLUDES = -I$(APP_INC_DIR) \
$(DEVICE_INCLUDES)
TRANSLATION_FILES=$(wildcard ../../Translations/translation_*.json)
GENERATED_TRANSLATION_SOURCE=Core/Gen/Translation.cpp
SOURCE := $(shell find $(SOURCE_THREADS_DIR) -type f -name '*.c') \
$(shell find $(SOURCE_CORE_DIR) -type f -name '*.c') \
$(shell find $(SOURCE_DRIVERS_DIR) -type f -name '*.c') \
@@ -114,8 +112,7 @@ SOURCE_CPP := $(shell find $(SOURCE_THREADS_DIR) -type f -name '*.cpp') \
$(shell find $(SOURCE_CORE_DIR) -type f -name '*.cpp') \
$(shell find $(SOURCE_DRIVERS_DIR) -type f -name '*.cpp') \
$(shell find $(DEVICE_BSP_DIR) -type f -name '*.cpp') \
$(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp') \
$(GENERATED_TRANSLATION_SOURCE)
$(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp')
# output folder
HEXFILE_DIR=Hexfile
@@ -126,7 +123,7 @@ OUTPUT_DIR=Objects/$(model)
OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections
# global defines ---------------------------------------------------------------
GLOBAL_DEFINES += $(DEV_GLOBAL_DEFS) -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG -D MODEL_$(model) -D VECT_TAB_OFFSET=$(bootldr_size)U
GLOBAL_DEFINES += $(DEV_GLOBAL_DEFS) -D USE_RTOS_SYSTICK -D MODEL_$(model) -D VECT_TAB_OFFSET=$(bootldr_size)U
# Without debug code
DEBUG=
@@ -169,8 +166,6 @@ endif
LINKER_FLAGS= -Wl,--gc-sections \
-Wl,--wrap=malloc \
-Wl,--wrap=free \
-o$(OUT_HEXFILE).elf \
-Wl,-Map=$(OUT_HEXFILE).map \
-lm \
-Wl,--undefined=vTaskSwitchContext \
-Wl,--undefined=pxCurrentTCB \
@@ -275,49 +270,55 @@ OBJS_S = $(S_SRCS:.S=.o)
OUT_OBJS=$(addprefix $(OUTPUT_DIR)/,$(OBJS))
OUT_OBJS_CPP=$(addprefix $(OUTPUT_DIR)/,$(OBJS_CPP))
OUT_OBJS_S=$(addprefix $(OUTPUT_DIR)/,$(OBJS_S))
OUT_HEXFILE=$(addprefix $(HEXFILE_DIR)/,$(OUTPUT_EXE))
all: $(OUT_HEXFILE).hex $(OUT_HEXFILE).bin
default : firmware-EN
firmware-%: $(HEXFILE_DIR)/$(model)_%.hex $(HEXFILE_DIR)/$(model)_%.bin
@true
ALL_FIRMWARE_TARGETS=$(addprefix firmware-,$(ALL_LANGUAGES))
all: $(ALL_FIRMWARE_TARGETS)
#
# The rule to create the target directory
#
# Create hexfile
%.hex : %.elf
$(OBJCOPY) $^ -O ihex $@
%.hex : %.elf Makefile
$(OBJCOPY) $< -O ihex $@
%.bin : %.elf
$(SIZE) --format=berkeley $^
$(OBJCOPY) $^ -O binary $@
%.bin : %.elf Makefile
$(SIZE) --format=berkeley $<
$(OBJCOPY) $< -O binary $@
$(OUT_HEXFILE).elf : $(OUT_OBJS_S) $(OUT_OBJS) $(OUT_OBJS_CPP) Makefile $(LDSCRIPT)
$(HEXFILE_DIR)/$(model)_%.elf : $(OUT_OBJS_S) $(OUT_OBJS) $(OUT_OBJS_CPP) $(OUTPUT_DIR)/Core/Gen/Translation.%.o Makefile $(LDSCRIPT)
@test -d $(@D) || mkdir -p $(@D)
@echo Linking $(OUTPUT_EXE).elf
@$(CPP) $(CXXFLAGS) $(OUT_OBJS_S) $(OUT_OBJS) $(OUT_OBJS_CPP) $(LIBS) $(LINKER_FLAGS)
@echo Linking $@
@$(CPP) $(CXXFLAGS) $(OUT_OBJS_S) $(OUT_OBJS) $(OUT_OBJS_CPP) $(OUTPUT_DIR)/Core/Gen/Translation.$*.o $(LIBS) $(LINKER_FLAGS) -o$@ -Wl,-Map=$@.map
$(OUT_OBJS): $(OUTPUT_DIR)/%.o : %.c Makefile $(APP_INC_DIR)/unit.h
$(OUT_OBJS): $(OUTPUT_DIR)/%.o : %.c Makefile
@test -d $(@D) || mkdir -p $(@D)
@echo Compiling ${<}
@$(CC) -c $(CFLAGS) $< -o $@
$(OUT_OBJS_CPP): $(OUTPUT_DIR)/%.o : %.cpp Makefile $(APP_INC_DIR)/unit.h
$(OUTPUT_DIR)/%.o : %.cpp Makefile
@test -d $(@D) || mkdir -p $(@D)
@echo Compiling ${<}
@$(CPP) -c $(CXXFLAGS) $< -o $@
$(OUT_OBJS_S): $(OUTPUT_DIR)/%.o: %.S Makefile
@test -d $(@D) || mkdir -p $(@D)
@echo 'Building file: $<'
@$(AS) -c $(AFLAGS) $< -o $@
$(APP_INC_DIR)/unit.h $(GENERATED_TRANSLATION_SOURCE): $(TRANSLATION_FILES) Makefile ../Translations/make_translation.py
@echo 'Building translations'
@cd ../Translations && python3 make_translation.py
Core/Gen/Translation.%.cpp: ../Translations/translation_%.json Makefile ../Translations/make_translation.py ../Translations/translations_commons.js
@test -d $(@D) || mkdir -p $(@D)
@echo 'Generating translations for language $*'
@python3 ../Translations/make_translation.py -o $(PWD)/$@ $*
clean :
rm -f $(GENERATED_TRANSLATION_SOURCE) $(SOURCE_CORE_DIR)/Translation.cpp
rm -Rf $(SOURCE_CORE_DIR)/Translation.cpp Core/Gen
rm -Rf $(OUTPUT_DIR_BASE)
rm -Rf $(HEXFILE_DIR)
@@ -328,7 +329,8 @@ style:
done
@echo "Done"
.PHONY: style
.PHONY: style all clean default
.SECONDARY:
# pull in dependency info for *existing* .o files
-include $(OUT_OBJS:.o=.d)

View File

@@ -123,16 +123,8 @@ if [ ${#BUILD_LANGUAGES[@]} -gt 0 ] && [ ${#BUILD_MODELS[@]} -gt 0 ]; then
checkLastCommand
for model in "${BUILD_MODELS[@]}"; do
for lang in "${BUILD_LANGUAGES[@]}"; do
echo "Building firmware for $model in $lang"
make -j lang="$lang" model="$model" >/dev/null
checkLastCommand
echo "Cleanup Temp files for $model in $lang"
rm -rf Objects/*/Core/ >/dev/null
checkLastCommand
done
echo "Cleanup model change"
rm -rf Objects/ >/dev/null
echo "Building firmware for $model in ${BUILD_LANGUAGES[@]}"
make -j$(nproc) model="$model" "${BUILD_LANGUAGES[@]/#/firmware-}" >/dev/null
checkLastCommand
done
else