Merge pull request #775 from XPila/MK3-new_lang

Mk3 new lang
This commit is contained in:
XPila 2018-05-28 19:43:18 +02:00 committed by GitHub
commit 5ce404583e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 38 deletions

View File

@ -1271,11 +1271,13 @@ void setup()
// If they differ, an update procedure may need to be performed. At the end of this block, the current firmware version
// is being written into the EEPROM, so the update procedure will be triggered only once.
/// lang_selected = eeprom_read_byte((uint8_t*)EEPROM_LANG);
/// if (lang_selected >= LANG_NUM){
/// lcd_mylang();
/// }
lang_select(1);
lang_selected = eeprom_read_byte((uint8_t*)EEPROM_LANG);
if (lang_selected >= LANG_NUM)
{
lcd_mylang();
}
lang_select(lang_selected);
puts_P(_n("\nNew ML support"));
printf_P(_n(" lang_selected = %d\n"), lang_selected);
printf_P(_n(" &_SEC_LANG = 0x%04x\n"), &_SEC_LANG);

View File

@ -74,4 +74,22 @@ const char* lang_select(unsigned char lang)
ui = pgm_read_word(((uint16_t*)(((char*)lang_table + 16)))); //read relative offset of first string (language name)
return (const char*)((char*)lang_table + ui); //return calculated pointer
#endif //(LANG_MODE == 0)
}
}
unsigned char lang_get_count()
{
uint16_t ui = (uint16_t)&_SEC_LANG; //pointer to _SEC_LANG reserved space
ui += 0x00ff; //add 1 page
ui &= 0xff00; //align to page
lang_table_t* _lang_table = ui; //table pointer
if (pgm_read_dword(((uint32_t*)(_lang_table + 0))) == 0x4bb45aa5) return 2;
return 1;
}
const char* lang_get_name(unsigned char lang)
{
if (lang == 0) return MSG_LANGUAGE_NAME + 2;
return lang_get_sec_lang_str(MSG_LANGUAGE_NAME);
}
const char MSG_LANGUAGE_NAME[] PROGMEM_I1 = ISTR("English"); ////c=0 r=0

View File

@ -44,15 +44,16 @@
// Language indices into their particular symbol tables.
#define LANG_ID_EN 0
#define LANG_ID_CZ 1
#define LANG_ID_PRI 0
#define LANG_ID_SEC 1
// Language is not defined and it shall be selected from the menu.
#define LANG_ID_FORCE_SELECTION 254
// Language is not defined on a virgin RAMBo board.
#define LANG_ID_UNDEFINED 255
// Default language ID, if no language is selected.
#define LANG_ID_DEFAULT LANG_ID_CZ
#define LANG_ID_DEFAULT LANG_ID_PRI
// Number of languages available in the language table.
#define LANG_NUM 2
@ -72,6 +73,8 @@ extern const char _SEC_LANG[LANG_SIZE_RESERVED];
extern const char* lang_get_translation(const char* s);
extern const char* lang_get_sec_lang_str(const char* s);
extern const char* lang_select(unsigned char lang);
extern unsigned char lang_get_count();
extern const char* lang_get_name(unsigned char lang);
#if defined(__cplusplus)
}
@ -79,9 +82,11 @@ extern const char* lang_select(unsigned char lang);
#define CAT2(_s1, _s2) _s1
#define CAT4(_s1, _s2, _s3, _s4) _s1
#define MSG_LANGUAGE_NAME_EXPLICIT(i) ((i==0)?PSTR("ENG"):PSTR("CZE"))
extern const char MSG_LANGUAGE_NAME[];
#include "messages.h"
#endif //__LANGUAGE_H

View File

@ -3759,14 +3759,12 @@ void lcd_force_language_selection() {
static void lcd_language_menu()
{
START_MENU();
if (langsel == LANGSEL_OFF) {
if (langsel == LANGSEL_OFF)
MENU_ITEM(back, _T(MSG_SETTINGS), 0);
} else if (langsel == LANGSEL_ACTIVE) {
else if (langsel == LANGSEL_ACTIVE)
MENU_ITEM(back, _T(MSG_WATCH), 0);
}
for (int i=0;i<LANG_NUM;i++){
MENU_ITEM(setlang, MSG_LANGUAGE_NAME_EXPLICIT(i), i);
}
for (int i=0; i < lang_get_count(); i++)
MENU_ITEM(setlang, lang_get_name(i), i);
END_MENU();
}
@ -4594,71 +4592,76 @@ void lcd_mylang_drawmenu(int cursor) {
}
*/
void lcd_mylang_drawmenu(int cursor) {
void lcd_mylang_drawmenu(int cursor)
{
unsigned char lang_cnt = lang_get_count();
int first = 0;
if (cursor>3) first = cursor-3;
if (cursor==LANG_NUM && LANG_NUM>4) first = LANG_NUM-4;
if (cursor==LANG_NUM && LANG_NUM==4) first = LANG_NUM-4;
if (cursor==lang_cnt && lang_cnt>4) first = lang_cnt-4;
if (cursor==lang_cnt && lang_cnt==4) first = lang_cnt-4;
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(1, 0);
lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+0));
lcd_printPGM(lang_get_name(first+0));
lcd.setCursor(0, 1);
lcd.print(" ");
lcd.setCursor(1, 1);
lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+1));
lcd_printPGM(lang_get_name(first+1));
lcd.setCursor(0, 2);
lcd.print(" ");
if (LANG_NUM > 2){
if (lang_cnt > 2){
lcd.setCursor(1, 2);
lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+2));
lcd_printPGM(lang_get_name(first+2));
}
lcd.setCursor(0, 3);
lcd.print(" ");
if (LANG_NUM>3) {
if (lang_cnt>3) {
lcd.setCursor(1, 3);
lcd_printPGM(MSG_LANGUAGE_NAME_EXPLICIT(first+3));
lcd_printPGM(lang_get_name(first+3));
}
if (cursor==1) lcd.setCursor(0, 0);
if (cursor==2) lcd.setCursor(0, 1);
if (cursor>2) lcd.setCursor(0, 2);
if (cursor==LANG_NUM && LANG_NUM>3) lcd.setCursor(0, 3);
if (cursor==lang_cnt && lang_cnt>3) lcd.setCursor(0, 3);
lcd.print(">");
if (cursor<LANG_NUM-1 && LANG_NUM>4) {
if (cursor<lang_cnt-1 && lang_cnt>4) {
lcd.setCursor(19,3);
lcd.print("\x01");
}
if (cursor>3 && LANG_NUM>4) {
if (cursor>3 && lang_cnt>4) {
lcd.setCursor(19,0);
lcd.print("^");
}
}
}
void lcd_mylang_drawcursor(int cursor) {
unsigned char lang_cnt = lang_get_count();
if (cursor==1) lcd.setCursor(0, 1);
if (cursor>1 && cursor<LANG_NUM) lcd.setCursor(0, 2);
if (cursor==LANG_NUM) lcd.setCursor(0, 3);
if (cursor>1 && cursor<lang_cnt) lcd.setCursor(0, 2);
if (cursor==lang_cnt) lcd.setCursor(0, 3);
lcd.print(">");
}
void lcd_mylang() {
void lcd_mylang()
{
int enc_dif = 0;
int cursor_pos = 1;
lang_selected=255;
int hlaska=1;
int counter=0;
unsigned char lang_cnt = lang_get_count();
lcd_set_custom_characters_arrows();
lcd_implementation_clear();
@ -4667,7 +4670,6 @@ void lcd_mylang() {
lcd_mylang_drawmenu(cursor_pos);
enc_dif = encoderDiff;
while ( (lang_selected == 255) ) {
@ -4686,8 +4688,8 @@ void lcd_mylang() {
cursor_pos ++;
}
if (cursor_pos > LANG_NUM) {
cursor_pos = LANG_NUM;
if (cursor_pos > lang_cnt) {
cursor_pos = lang_cnt;
}
if (cursor_pos < 1) {

View File

@ -217,6 +217,9 @@
#MSG_SELFTEST_ENDSTOPS c=0 r=0
"Endstops"
#MSG_LANGUAGE_NAME c=0 r=0
"English"
#MSG_Enqueing c=0 r=0
"enqueing \x22"

View File

@ -290,6 +290,10 @@
"Endstops"
"Endstops"
#MSG_LANGUAGE_NAME c=0 r=0
"English"
"Cestina"
#MSG_Enqueing c=0 r=0
"enqueing \x22"
"enqueing \x22"

View File

@ -26,7 +26,9 @@ OBJCOPY=C:/arduino-1.6.8/hardware/tools/avr/bin/avr-objcopy.exe
# Selected language:
LANG=$1
#if [ -z "$LANG" ]; then LANG='cz'; fi
#
# Params:
IGNORE_MISSING_TEXT=1
function finish
{
@ -67,8 +69,16 @@ echo "OK" >&2
#check for messages declared in progmem1, but not found in lang_en.txt
echo -n " checking textaddr.txt..." >&2
if cat textaddr.txt | grep "^ADDR NF"; then echo "NG! - some strings not found in lang_en.txt!"; finish 1; fi
echo "OK" >&2
if cat textaddr.txt | grep "^ADDR NF" >/dev/null; then
echo "NG! - some texts not found in lang_en.txt!"
if [ $(("0$IGNORE_MISSING_TEXT")) -eq 0 ]; then
finish 1
else
echo " missing text ignored!" >&2
fi
else
echo "OK" >&2
fi
#update progmem1 id entries in binary file
echo -n " extracting binary..." >&2