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

@@ -1,6 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# coding=utf-8 # coding=utf-8
from __future__ import print_function from __future__ import print_function
import argparse
import json import json
import os import os
import io import io
@@ -10,8 +11,7 @@ import fontTables
import re import re
import subprocess import subprocess
TRANSLATION_CPP = "Translation.cpp" HERE = os.path.dirname(__file__)
UNIT_H = "unit.h"
try: try:
to_unicode = unicode to_unicode = unicode
@@ -19,6 +19,10 @@ except NameError:
to_unicode = str to_unicode = str
def log(message):
print(message, file=sys.stdout)
# Loading a single JSON file # Loading a single JSON file
def loadJson(fileName, skipFirstLine): def loadJson(fileName, skipFirstLine):
with io.open(fileName, mode="r", encoding="utf-8") as f: with io.open(fileName, mode="r", encoding="utf-8") as f:
@@ -30,24 +34,16 @@ def loadJson(fileName, skipFirstLine):
return obj return obj
# Reading all language translations into a dictionary by langCode def readTranslation(jsonDir, langCode):
def readTranslations(jsonDir): fileName = 'translation_{}.json'.format(langCode)
langDict = {}
UnitDict = {}
# Read all translation files from the input dir
for fileName in os.listdir(jsonDir):
fileWithPath = os.path.join(jsonDir, fileName) fileWithPath = os.path.join(jsonDir, fileName)
lf = fileName.lower()
# Read only translation_XX.json
if lf.startswith("translation_") and lf.endswith(".json"):
try: try:
lang = loadJson(fileWithPath, False) lang = loadJson(fileWithPath, False)
except json.decoder.JSONDecodeError as e: except json.decoder.JSONDecodeError as e:
print("Failed to decode " + lf) log("Failed to decode " + fileName)
print(str(e)) log(str(e))
sys.exit(2) sys.exit(2)
# Extract lang code from file name # Extract lang code from file name
@@ -58,20 +54,13 @@ def readTranslations(jsonDir):
except KeyError: except KeyError:
langCodeFromJson = "(missing)" langCodeFromJson = "(missing)"
try:
TempUnitF_FromJson = lang["tempUnitFahrenheit"]
except KeyError:
TempUnitF_FromJson = True # Default to true.
# ...cause they should be the same! # ...cause they should be the same!
if langCode != langCodeFromJson: if langCode != langCodeFromJson:
raise ValueError( raise ValueError(
"Invalid languageCode " + langCodeFromJson + " in file " + fileName "Invalid languageCode " + langCodeFromJson + " in file " + fileName
) )
langDict[langCode] = lang return lang
UnitDict[langCode] = TempUnitF_FromJson
return langDict, UnitDict
def writeStart(f): def writeStart(f):
@@ -85,26 +74,6 @@ def writeStart(f):
) )
def writeStartUnit(f):
f.write(
to_unicode(
"""// WARNING: THIS FILE WAS AUTO GENERATED BY make_translation.py. PLEASE DO NOT EDIT.
/**
* °F Fahrenheit Support
* You will find the default Fahrenheit configuration in the translation_xx.json
* If tempUnitFahrenheit is set to:
* true - you can switch in menu settings to Fahrenheit or Celsius.
* false - you see only Celsius. All settings are then is in Celsius only.
*/
#ifndef _UNIT_H
#define _UNIT_H\n
"""
)
)
def escapeC(s): def escapeC(s):
return s.replace('"', '\\"') return s.replace('"', '\\"')
@@ -220,9 +189,9 @@ def getFontMapAndTable(textList):
symbolMap[sym] = "\\x%0.2X" % index symbolMap[sym] = "\\x%0.2X" % index
index = index + 1 index = index + 1
if len(textList) > (253 - len(forcedFirstSymbols)): if len(textList) > (253 - len(forcedFirstSymbols)):
print("Error, too many used symbols for this version") log("Error, too many used symbols for this version")
exit(1) exit(1)
print("Generating fonts for {} symbols".format(len(textList))) log("Generating fonts for {} symbols".format(len(textList)))
for sym in textList: for sym in textList:
if sym not in symbolMap: if sym not in symbolMap:
@@ -235,12 +204,12 @@ def getFontMapAndTable(textList):
fontSmallTable = fontTables.getSmallFontMap() fontSmallTable = fontTables.getSmallFontMap()
for sym in forcedFirstSymbols: for sym in forcedFirstSymbols:
if sym not in fontTable: if sym not in fontTable:
print("Missing Large font element for {}".format(sym)) log("Missing Large font element for {}".format(sym))
exit(1) exit(1)
fontLine = fontTable[sym] fontLine = fontTable[sym]
fontTableStrings.append(fontLine + "//{} -> {}".format(symbolMap[sym], sym)) fontTableStrings.append(fontLine + "//{} -> {}".format(symbolMap[sym], sym))
if sym not in fontSmallTable: if sym not in fontSmallTable:
print("Missing Small font element for {}".format(sym)) log("Missing Small font element for {}".format(sym))
exit(1) exit(1)
fontLine = fontSmallTable[sym] fontLine = fontSmallTable[sym]
fontSmallTableStrings.append( fontSmallTableStrings.append(
@@ -249,13 +218,13 @@ def getFontMapAndTable(textList):
for sym in textList: for sym in textList:
if sym not in fontTable: if sym not in fontTable:
print("Missing Large font element for {}".format(sym)) log("Missing Large font element for {}".format(sym))
exit(1) exit(1)
if sym not in forcedFirstSymbols: if sym not in forcedFirstSymbols:
fontLine = fontTable[sym] fontLine = fontTable[sym]
fontTableStrings.append(fontLine + "//{} -> {}".format(symbolMap[sym], sym)) fontTableStrings.append(fontLine + "//{} -> {}".format(symbolMap[sym], sym))
if sym not in fontSmallTable: if sym not in fontSmallTable:
print("Missing Small font element for {}".format(sym)) log("Missing Small font element for {}".format(sym))
exit(1) exit(1)
fontLine = fontSmallTable[sym] fontLine = fontSmallTable[sym]
fontSmallTableStrings.append( fontSmallTableStrings.append(
@@ -279,21 +248,20 @@ def convStr(symbolConversionTable, text):
outputString = "" outputString = ""
for c in text.replace("\\r", "").replace("\\n", "\n"): for c in text.replace("\\r", "").replace("\\n", "\n"):
if c not in symbolConversionTable: if c not in symbolConversionTable:
print("Missing font definition for {}".format(c)) log("Missing font definition for {}".format(c))
else: else:
outputString = outputString + symbolConversionTable[c] outputString = outputString + symbolConversionTable[c]
return outputString return outputString
def writeLanguage(languageCode, defs, f): def writeLanguage(lang, defs, f):
print("Generating block for " + languageCode) languageCode = lang['languageCode']
lang = langDict[languageCode] log("Generating block for " + languageCode)
# Iterate over all of the text to build up the symbols & counts # Iterate over all of the text to build up the symbols & counts
textList = getLetterCounts(defs, lang) textList = getLetterCounts(defs, lang)
# From the letter counts, need to make a symbol translator & write out the font # From the letter counts, need to make a symbol translator & write out the font
(fontTableText, symbolConversionTable) = getFontMapAndTable(textList) (fontTableText, symbolConversionTable) = getFontMapAndTable(textList)
f.write(to_unicode("\n#ifdef LANG_" + languageCode + "\n"))
f.write(fontTableText) f.write(fontTableText)
try: try:
langName = lang["languageLocalName"] langName = lang["languageLocalName"]
@@ -486,29 +454,13 @@ def writeLanguage(languageCode, defs, f):
) )
f.write(to_unicode("};\n\n")) f.write(to_unicode("};\n\n"))
f.write("const bool HasFahrenheit = " + (
# ----- Block end "true" if lang.get('tempUnitFahrenheit', True) else "false") +
f.write(to_unicode("#endif\n")) ";\n")
def writeUnit(languageCode, defs, f, UnitCodes):
print("Generating unit block for " + languageCode)
lang = langDict[languageCode]
unit = UnitDict[UnitCodes]
try:
langName = lang["languageLocalName"]
except KeyError:
langName = languageCode
f.write(to_unicode(" #ifdef LANG_" + languageCode + "\n"))
if unit:
f.write(to_unicode(" #define ENABLED_FAHRENHEIT_SUPPORT" + "\n"))
else:
f.write(to_unicode(" //#define ENABLED_FAHRENHEIT_SUPPORT" + "\n"))
# ----- Block end
f.write(to_unicode(" #endif /* ---- " + langName + " ---- */\n"))
def readVersion(jsonDir):
def readVersion():
with open(os.path.relpath(jsonDir + "/../source/version.h"), "r") as version_file: with open(os.path.relpath(jsonDir + "/../source/version.h"), "r") as version_file:
try: try:
for line in version_file: for line in version_file:
@@ -535,37 +487,6 @@ def readVersion():
return version return version
def read_opts():
"""Reading input parameters
First parameter = json directory
Second parameter = translation directory
Third paramter = unit directory
"""
if len(sys.argv) > 1:
jsonDir = sys.argv[1]
else:
jsonDir = "."
if len(sys.argv) > 2:
outFileTranslationCPP = sys.argv[2]
else:
outDir = os.path.relpath(jsonDir + "/../source/Core/Gen")
if not os.path.exists(outDir):
os.makedirs(outDir)
outFileTranslationCPP = os.path.join(outDir, TRANSLATION_CPP)
if len(sys.argv) > 3:
outFileUnitH = sys.argv[3]
else:
outDir = os.path.relpath(jsonDir + "/../source/Core/Inc")
outFileUnitH = os.path.join(outDir, UNIT_H)
if len(sys.argv) > 4:
raise Exception("Too many parameters!")
return jsonDir, outFileTranslationCPP, outFileUnitH
def orderOutput(langDict): def orderOutput(langDict):
# These languages go first # These languages go first
mandatoryOrder = ["EN"] mandatoryOrder = ["EN"]
@@ -581,41 +502,33 @@ def orderOutput(langDict):
return mandatoryOrder return mandatoryOrder
def writeTarget(outFileTranslationCPP, outFileUnitH, defs, langCodes, UnitCodes): def parseArgs():
# Start writing the file parser = argparse.ArgumentParser()
with io.open(outFileTranslationCPP, "w", encoding="utf-8", newline="\n") as f: parser.add_argument(
writeStart(f) '--output', '-o',
for langCode in langCodes: help='Target file', type=argparse.FileType('w'), required=True)
writeLanguage(langCode, defs, f) parser.add_argument('languageCode', help='Language to generate')
return parser.parse_args()
with io.open(outFileUnitH, "w", encoding="utf-8", newline="\n") as f:
writeStartUnit(f)
for langCode, UnitCode in zip(langCodes, UnitCodes):
writeUnit(langCode, defs, f, UnitCode)
f.write(to_unicode("\n#endif /* _UNIT_H */\n"))
if __name__ == "__main__": if __name__ == "__main__":
try: jsonDir = HERE
jsonDir, outFileTranslationCPP, outFileUnitH = read_opts()
except: args = parseArgs()
print("usage: make_translation.py {json dir} {cpp dir}")
sys.exit(1)
try: try:
buildVersion = readVersion() buildVersion = readVersion(jsonDir)
except: except:
print("error: could not get/extract build version") log("error: could not get/extract build version")
sys.exit(1) sys.exit(1)
print("Build version: " + buildVersion) log("Build version: " + buildVersion)
print("Making " + outFileTranslationCPP + " from " + jsonDir) log("Making " + args.languageCode + " from " + jsonDir)
print("Making " + outFileUnitH + " from " + jsonDir)
langDict, UnitDict = readTranslations(jsonDir) lang = readTranslation(jsonDir, args.languageCode)
defs = loadJson(os.path.join(jsonDir, "translations_def.js"), True) defs = loadJson(os.path.join(jsonDir, "translations_def.js"), True)
langCodes = orderOutput(langDict) out = args.output
UnitCodes = orderOutput(UnitDict) writeStart(out)
writeTarget(outFileTranslationCPP, outFileUnitH, defs, langCodes, UnitCodes) writeLanguage(lang, defs, out)
print("Done") log("Done")

View File

@@ -53,9 +53,7 @@ uint32_t TipThermoModel::convertTipRawADCTouV(uint16_t rawADC) {
} }
uint32_t TipThermoModel::convertTipRawADCToDegC(uint16_t rawADC) { return convertuVToDegC(convertTipRawADCTouV(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)); } 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 // 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; return 0;
} }
#ifdef ENABLED_FAHRENHEIT_SUPPORT
uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); } uint32_t TipThermoModel::convertuVToDegF(uint32_t tipuVDelta) { return convertCtoF(convertuVToDegC(tipuVDelta)); }
uint32_t TipThermoModel::convertCtoF(uint32_t degC) { uint32_t TipThermoModel::convertCtoF(uint32_t degC) {
@@ -211,7 +208,6 @@ uint32_t TipThermoModel::convertFtoC(uint32_t degF) {
} }
return ((degF - 32) * 5) / 9; return ((degF - 32) * 5) / 9;
} }
#endif
uint32_t TipThermoModel::getTipInC(bool sampleNow) { uint32_t TipThermoModel::getTipInC(bool sampleNow) {
int32_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(getTipRawTemp(sampleNow)); int32_t currentTipTempInC = TipThermoModel::convertTipRawADCToDegC(getTipRawTemp(sampleNow));
@@ -224,13 +220,12 @@ uint32_t TipThermoModel::getTipInC(bool sampleNow) {
return 0; return 0;
return currentTipTempInC; return currentTipTempInC;
} }
#ifdef ENABLED_FAHRENHEIT_SUPPORT
uint32_t TipThermoModel::getTipInF(bool sampleNow) { uint32_t TipThermoModel::getTipInF(bool sampleNow) {
uint32_t currentTipTempInF = getTipInC(sampleNow); uint32_t currentTipTempInF = getTipInC(sampleNow);
currentTipTempInF = convertCtoF(currentTipTempInF); currentTipTempInF = convertCtoF(currentTipTempInF);
return currentTipTempInF; return currentTipTempInF;
} }
#endif
uint32_t TipThermoModel::getTipMaxInC() { uint32_t TipThermoModel::getTipMaxInC() {
uint32_t maximumTipTemp = TipThermoModel::convertTipRawADCToDegC(0x7FFF - (21 * 5)); // back off approx 5 deg c from ADC max 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_ #define SRC_TIPTHERMOMODEL_H_
#include "BSP.h" #include "BSP.h"
#include "stdint.h" #include "stdint.h"
#include "unit.h"
class TipThermoModel { class TipThermoModel {
public: public:
// These are the main two functions // These are the main two functions
static uint32_t getTipInC(bool sampleNow = false); static uint32_t getTipInC(bool sampleNow = false);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static uint32_t getTipInF(bool sampleNow = false); static uint32_t getTipInF(bool sampleNow = false);
#endif
// Calculates the maximum temperature can can be read by the ADC range // Calculates the maximum temperature can can be read by the ADC range
static uint32_t getTipMaxInC(); static uint32_t getTipMaxInC();
static uint32_t convertTipRawADCToDegC(uint16_t rawADC); static uint32_t convertTipRawADCToDegC(uint16_t rawADC);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static uint32_t convertTipRawADCToDegF(uint16_t rawADC); static uint32_t convertTipRawADCToDegF(uint16_t rawADC);
#endif
// Returns the uV of the tip reading before the op-amp compensating for pullups // Returns the uV of the tip reading before the op-amp compensating for pullups
static uint32_t convertTipRawADCTouV(uint16_t rawADC); static uint32_t convertTipRawADCTouV(uint16_t rawADC);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static uint32_t convertCtoF(uint32_t degC); static uint32_t convertCtoF(uint32_t degC);
static uint32_t convertFtoC(uint32_t degF); static uint32_t convertFtoC(uint32_t degF);
#endif
private: private:
static uint32_t convertuVToDegC(uint32_t tipuVDelta); static uint32_t convertuVToDegC(uint32_t tipuVDelta);
#ifdef ENABLED_FAHRENHEIT_SUPPORT
static uint32_t convertuVToDegF(uint32_t tipuVDelta); static uint32_t convertuVToDegF(uint32_t tipuVDelta);
#endif
}; };
#endif /* SRC_TIPTHERMOMODEL_H_ */ #endif /* SRC_TIPTHERMOMODEL_H_ */

View File

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

View File

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

View File

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

View File

@@ -67,9 +67,7 @@ void resetSettings() {
systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety systemSettings.autoStartMode = AUTO_START_MODE; // Auto start off for safety
systemSettings.lockingMode = LOCKING_MODE; // Disable locking 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 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 systemSettings.temperatureInF = TEMPERATURE_INF; // default to 0
#endif
systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow systemSettings.descriptionScrollSpeed = DESCRIPTION_SCROLL_SPEED; // default to slow
systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV systemSettings.CalibrationOffset = CALIBRATION_OFFSET; // the adc offset in uV
systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit systemSettings.powerLimit = POWER_LIMIT; // 30 watts default limit

View File

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

View File

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

View File

@@ -2,10 +2,9 @@
ifndef model ifndef model
model:=TS100 model:=TS100
endif endif
OUTPUT_EXE=$(model)_$(lang)
ifndef lang 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
lang:= EN
endif
# Enumerate all of the include directories # Enumerate all of the include directories
APP_INC_DIR = ./Core/Inc APP_INC_DIR = ./Core/Inc
@@ -104,7 +103,6 @@ INCLUDES = -I$(APP_INC_DIR) \
$(DEVICE_INCLUDES) $(DEVICE_INCLUDES)
TRANSLATION_FILES=$(wildcard ../../Translations/translation_*.json) TRANSLATION_FILES=$(wildcard ../../Translations/translation_*.json)
GENERATED_TRANSLATION_SOURCE=Core/Gen/Translation.cpp
SOURCE := $(shell find $(SOURCE_THREADS_DIR) -type f -name '*.c') \ SOURCE := $(shell find $(SOURCE_THREADS_DIR) -type f -name '*.c') \
$(shell find $(SOURCE_CORE_DIR) -type f -name '*.c') \ $(shell find $(SOURCE_CORE_DIR) -type f -name '*.c') \
$(shell find $(SOURCE_DRIVERS_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_CORE_DIR) -type f -name '*.cpp') \
$(shell find $(SOURCE_DRIVERS_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 $(DEVICE_BSP_DIR) -type f -name '*.cpp') \
$(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp') \ $(shell find $(SOURCE_MIDDLEWARES_DIR) -type f -name '*.cpp')
$(GENERATED_TRANSLATION_SOURCE)
# output folder # output folder
HEXFILE_DIR=Hexfile 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 OPTIM=-Os -flto -finline-small-functions -findirect-inlining -fdiagnostics-color -ffunction-sections -fdata-sections
# global defines --------------------------------------------------------------- # 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 # Without debug code
DEBUG= DEBUG=
@@ -169,8 +166,6 @@ endif
LINKER_FLAGS= -Wl,--gc-sections \ LINKER_FLAGS= -Wl,--gc-sections \
-Wl,--wrap=malloc \ -Wl,--wrap=malloc \
-Wl,--wrap=free \ -Wl,--wrap=free \
-o$(OUT_HEXFILE).elf \
-Wl,-Map=$(OUT_HEXFILE).map \
-lm \ -lm \
-Wl,--undefined=vTaskSwitchContext \ -Wl,--undefined=vTaskSwitchContext \
-Wl,--undefined=pxCurrentTCB \ -Wl,--undefined=pxCurrentTCB \
@@ -275,33 +270,39 @@ OBJS_S = $(S_SRCS:.S=.o)
OUT_OBJS=$(addprefix $(OUTPUT_DIR)/,$(OBJS)) OUT_OBJS=$(addprefix $(OUTPUT_DIR)/,$(OBJS))
OUT_OBJS_CPP=$(addprefix $(OUTPUT_DIR)/,$(OBJS_CPP)) OUT_OBJS_CPP=$(addprefix $(OUTPUT_DIR)/,$(OBJS_CPP))
OUT_OBJS_S=$(addprefix $(OUTPUT_DIR)/,$(OBJS_S)) 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 # The rule to create the target directory
# #
# Create hexfile # Create hexfile
%.hex : %.elf %.hex : %.elf Makefile
$(OBJCOPY) $^ -O ihex $@ $(OBJCOPY) $< -O ihex $@
%.bin : %.elf %.bin : %.elf Makefile
$(SIZE) --format=berkeley $^ $(SIZE) --format=berkeley $<
$(OBJCOPY) $^ -O binary $@ $(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) @test -d $(@D) || mkdir -p $(@D)
@echo Linking $(OUTPUT_EXE).elf @echo Linking $@
@$(CPP) $(CXXFLAGS) $(OUT_OBJS_S) $(OUT_OBJS) $(OUT_OBJS_CPP) $(LIBS) $(LINKER_FLAGS) @$(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) @test -d $(@D) || mkdir -p $(@D)
@echo Compiling ${<} @echo Compiling ${<}
@$(CC) -c $(CFLAGS) $< -o $@ @$(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) @test -d $(@D) || mkdir -p $(@D)
@echo Compiling ${<} @echo Compiling ${<}
@$(CPP) -c $(CXXFLAGS) $< -o $@ @$(CPP) -c $(CXXFLAGS) $< -o $@
@@ -311,13 +312,13 @@ $(OUT_OBJS_S): $(OUTPUT_DIR)/%.o: %.S Makefile
@echo 'Building file: $<' @echo 'Building file: $<'
@$(AS) -c $(AFLAGS) $< -o $@ @$(AS) -c $(AFLAGS) $< -o $@
$(APP_INC_DIR)/unit.h $(GENERATED_TRANSLATION_SOURCE): $(TRANSLATION_FILES) Makefile ../Translations/make_translation.py Core/Gen/Translation.%.cpp: ../Translations/translation_%.json Makefile ../Translations/make_translation.py ../Translations/translations_commons.js
@echo 'Building translations' @test -d $(@D) || mkdir -p $(@D)
@cd ../Translations && python3 make_translation.py @echo 'Generating translations for language $*'
@python3 ../Translations/make_translation.py -o $(PWD)/$@ $*
clean : 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 $(OUTPUT_DIR_BASE)
rm -Rf $(HEXFILE_DIR) rm -Rf $(HEXFILE_DIR)
@@ -328,7 +329,8 @@ style:
done done
@echo "Done" @echo "Done"
.PHONY: style .PHONY: style all clean default
.SECONDARY:
# pull in dependency info for *existing* .o files # pull in dependency info for *existing* .o files
-include $(OUT_OBJS:.o=.d) -include $(OUT_OBJS:.o=.d)

View File

@@ -123,16 +123,8 @@ if [ ${#BUILD_LANGUAGES[@]} -gt 0 ] && [ ${#BUILD_MODELS[@]} -gt 0 ]; then
checkLastCommand checkLastCommand
for model in "${BUILD_MODELS[@]}"; do for model in "${BUILD_MODELS[@]}"; do
for lang in "${BUILD_LANGUAGES[@]}"; do echo "Building firmware for $model in ${BUILD_LANGUAGES[@]}"
echo "Building firmware for $model in $lang" make -j$(nproc) model="$model" "${BUILD_LANGUAGES[@]/#/firmware-}" >/dev/null
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
checkLastCommand checkLastCommand
done done
else else