From 00dd5c8d7a691973bd7f6c069a2e5199822c2cf2 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Wed, 18 Sep 2024 22:57:46 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=80=D1=83=D1=81=D1=81=D0=BA=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- solarium/solarium.ino | 271 +++++++++++++++++++++++++++++------------- 1 file changed, 187 insertions(+), 84 deletions(-) diff --git a/solarium/solarium.ino b/solarium/solarium.ino index 2d583d0..25dfdfd 100644 --- a/solarium/solarium.ino +++ b/solarium/solarium.ino @@ -120,20 +120,7 @@ unsigned long all_long_parameters[COUNT_LONG_PARAMETER]; #define time_seance 0 #define time_delay 1 #define COUNT_TEXT_PARAMETER 2 -char text_parameters[COUNT_TEXT_PARAMETER][20]; - -// ============================== Описываем свой символ "Рубль" ======================================================================== -// Просто "рисуем" символ единицами. Единицы при выводе на экран окажутся закрашенными точками, нули - не закрашенными -const byte rubl[8] = { - 0b00000, - 0b01110, - 0b01001, - 0b01001, - 0b01110, - 0b01000, - 0b11110, - 0b01000, -}; +char text_parameters[COUNT_TEXT_PARAMETER][SIZE_SCREEN_LINE]; LiquidCrystal_I2C lcd(0x27, SIZE_SCREEN_LINE, SIZE_SCREEN); // устанавливаем адрес 0x27, и дисплей 16 символов 2 строки @@ -218,7 +205,7 @@ struct parameter_menu { struct parameter_digit { byte param_index; param_limit limit; - char unit[5]; + char unit[8]; }; struct parameter_list { @@ -235,7 +222,7 @@ struct parameter_header { struct parameter_text { byte param_index; param_limit limit; - char unit[5]; + char unit[8]; }; union param_data { @@ -247,7 +234,7 @@ union param_data { }; struct menu_line { - char string[SIZE_SCREEN_LINE]; + char string[SIZE_SCREEN_LINE * 2]; type_menu_line type; param_data parameter; @@ -274,7 +261,7 @@ const menu_screen menu_main[] PROGMEM = { {0} }, { - " BHECEHO", + " ВНЕСЕНО", DIGIT_VIEW_LINE, { money_counter, @@ -282,7 +269,7 @@ const menu_screen menu_main[] PROGMEM = { 0, 0, }, - 0 + "руб" } }, { @@ -317,7 +304,7 @@ const menu_screen menu_main[] PROGMEM = { 0, 0, }, - "CEK" + "СЕК" }, }, }, @@ -345,7 +332,7 @@ const menu_screen menu_main[] PROGMEM = { 0, 0, }, - "MUH" + "МИН" } }, }, @@ -360,12 +347,12 @@ const menu_screen menu_main[] PROGMEM = { {0} }, { - " PAUSE", + " ПАУЗА", FIXED_LINE, {0} }, { - "", + " ", TEXT_PARAM_LINE, { time_seance, @@ -388,7 +375,7 @@ const menu_screen menu_main[] PROGMEM = { {0} }, { - " KOHEU", + " КОНЕЦ", FIXED_LINE, {0} }, @@ -405,17 +392,17 @@ const menu_screen menu_settings[] PROGMEM = { { { { - " MAIN MENU", + "ГЛАВНОЕ МЕНЮ", FIXED_LINE, {0} }, { - "Settings", + "Настройки", MENU_LINE, {SETTING_MENU} }, { - "Statistic", + "Статистика", MENU_LINE, {STATISTIC_MENU} } @@ -426,27 +413,27 @@ const menu_screen menu_settings[] PROGMEM = { { { { - " SETTINGS", + "НАСТРОЙКИ", FIXED_LINE, {0} }, { - "Solarium", + "Солярий", MENU_LINE, {SOLARIUM_MENU} }, { - "Bank", + "Банк", MENU_LINE, {BANK_MENU} }, { - "Password", + "Пароль", MENU_LINE, {PASSWORD_MENU} }, { - "Reset", + "Сброс", LIST_PARAM_LINE, { reset_device, @@ -456,7 +443,7 @@ const menu_screen menu_settings[] PROGMEM = { }, { " ", - "start" + "запуск" } } }, @@ -467,17 +454,17 @@ const menu_screen menu_settings[] PROGMEM = { { { { - " STATISTIC", + "СТАТИСТИКА", FIXED_LINE, {0} }, { - "Long counters", + "Длинные счетчики", MENU_LINE, {LONG_COUNTER_MENU} }, { - "Short counters", + "Короткие счетчики", MENU_LINE, {SHORT_COUNTER_MENU} } @@ -488,12 +475,12 @@ const menu_screen menu_settings[] PROGMEM = { { { { - " DEVICE", + "СОЛЯРИЙ", FIXED_LINE, {1} }, { - "Pause before", + "Пауза до", DIGIT_PARAM_LINE, { pause_before, @@ -501,11 +488,11 @@ const menu_screen menu_settings[] PROGMEM = { 0, 100, }, - "sec" + "сек" } }, { - "Pause after", + "Пауза после", DIGIT_PARAM_LINE, { pause_after, @@ -513,11 +500,11 @@ const menu_screen menu_settings[] PROGMEM = { 0, 3, }, - "min" + "мин" } }, { - "Price", + "Цена", DIGIT_PARAM_LINE, { price, @@ -525,11 +512,11 @@ const menu_screen menu_settings[] PROGMEM = { 0, 100, }, - 0 + "руб" } }, { - "Remote start", + "Удален.старт", LIST_PARAM_LINE, { remote_start, @@ -538,13 +525,13 @@ const menu_screen menu_settings[] PROGMEM = { 1, }, { - "Off", - "On " + "Вкл ", + "Выкл" } } }, { - "Type", + "Тип", LIST_PARAM_LINE, { solarium_type, @@ -561,7 +548,7 @@ const menu_screen menu_settings[] PROGMEM = { } }, { - "Regime", + "Режим", LIST_PARAM_LINE, { work_regime, @@ -576,7 +563,7 @@ const menu_screen menu_settings[] PROGMEM = { } }, { - "Signal", + "Реле", LIST_PARAM_LINE, { signal_rele, @@ -597,12 +584,12 @@ const menu_screen menu_settings[] PROGMEM = { { { { - " BANK", + "БАНК", FIXED_LINE, {0} }, { - "Rub/imp", + "Руб/имп", DIGIT_PARAM_LINE, { weight_impulse, @@ -620,12 +607,12 @@ const menu_screen menu_settings[] PROGMEM = { { { { - " PASSWORD", + "УСТАНОВКА ПАРОЛЯ", FIXED_LINE, {0} }, { - "Pasword", + "Пароль", DIGIT_PARAM_LINE, { password, @@ -643,12 +630,12 @@ const menu_screen menu_settings[] PROGMEM = { { { { - "LONG COUNTERS", + "ДЛИННЫЕ СЧЕТЧИКИ", FIXED_LINE, {0} }, { - "Starts", + "Запуски", DIGIT_VIEW_LINE, { long_starts_counter, @@ -660,7 +647,7 @@ const menu_screen menu_settings[] PROGMEM = { } }, { - "Money", + "Деньги", DIGIT_VIEW_LINE, { long_money_counter, @@ -668,11 +655,11 @@ const menu_screen menu_settings[] PROGMEM = { 0, 0, }, - 0 + "руб" } }, { - "Time", + "Время", DIGIT_VIEW_LINE, { long_time_counter, @@ -680,7 +667,7 @@ const menu_screen menu_settings[] PROGMEM = { 0, 0, }, - "sec" + "сек" } }, }, @@ -690,12 +677,12 @@ const menu_screen menu_settings[] PROGMEM = { { { { - "SHORT COUNTERS", + "КОРОТКИЕ СЧЕТЧИКИ", FIXED_LINE, {0} }, { - "Starts", + "Запуски", DIGIT_VIEW_LINE, { short_starts_counter, @@ -707,7 +694,7 @@ const menu_screen menu_settings[] PROGMEM = { } }, { - "Money", + "Деньги", DIGIT_VIEW_LINE, { short_money_counter, @@ -715,11 +702,11 @@ const menu_screen menu_settings[] PROGMEM = { 0, 0, }, - 0 + "руб" } }, { - "Time", + "Время", DIGIT_VIEW_LINE, { short_time_counter, @@ -727,7 +714,7 @@ const menu_screen menu_settings[] PROGMEM = { 0, 0, }, - "sec" + "сек" } }, }, @@ -952,15 +939,15 @@ void show_line(byte index_line) { if(current_menu_screen.menu_lines[index_line].type == MENU_LINE) { - lcd.print(current_menu_screen.menu_lines[index_line].string); + lcd.print(convertCyr( utf8rus( current_menu_screen.menu_lines[index_line].string))); } else if(current_menu_screen.menu_lines[index_line].type == FIXED_LINE) { - lcd.print(current_menu_screen.menu_lines[index_line].string); + lcd.print(convertCyr( utf8rus( current_menu_screen.menu_lines[index_line].string))); } else if(current_menu_screen.menu_lines[index_line].type == DIGIT_PARAM_LINE) { - char line[21]; + char line[SIZE_SCREEN_LINE * 2]; char format[9] = "%s %d %s"; if(start_edit_parameter && index_line == current_line_index) { @@ -969,11 +956,11 @@ void show_line(byte index_line) sprintf(line,format, current_menu_screen.menu_lines[index_line].string, all_byte_parameters[current_menu_screen.menu_lines[index_line].parameter.digit.param_index], current_menu_screen.menu_lines[index_line].parameter.digit.unit); - lcd.print(line); + lcd.print(convertCyr( utf8rus( line ))); } else if(current_menu_screen.menu_lines[index_line].type == LIST_PARAM_LINE) { - char line[21]; + char line[SIZE_SCREEN_LINE * 2]; char format[6] = "%s %s"; if(start_edit_parameter && index_line == current_line_index) { @@ -981,26 +968,23 @@ void show_line(byte index_line) } sprintf(line,format, current_menu_screen.menu_lines[index_line].string, current_menu_screen.menu_lines[index_line].parameter.list.list_data[all_byte_parameters[current_menu_screen.menu_lines[index_line].parameter.list.param_index]]); - lcd.print(line); + lcd.print(convertCyr( utf8rus( line ))); } else if(current_menu_screen.menu_lines[index_line].type == DIGIT_VIEW_LINE) { - char line[21]; + char line[SIZE_SCREEN_LINE * 2]; sprintf(line,"%s %ld %s", current_menu_screen.menu_lines[index_line].string, - all_long_parameters[current_menu_screen.menu_lines[index_line].parameter.digit.param_index], - current_menu_screen.menu_lines[index_line].parameter.digit.unit[0] >= 0x20 ? - current_menu_screen.menu_lines[index_line].parameter.digit.unit : - ""); - lcd.print(line); - current_menu_screen.menu_lines[index_line].parameter.digit.unit[0] < 0x20 ? lcd.write(0) : 0; + all_long_parameters[current_menu_screen.menu_lines[index_line].parameter.digit.param_index], + current_menu_screen.menu_lines[index_line].parameter.digit.unit); + lcd.print(convertCyr( utf8rus( line ))); } else if(current_menu_screen.menu_lines[index_line].type == TEXT_PARAM_LINE) { - char line[21]; + char line[SIZE_SCREEN_LINE * 2]; sprintf(line,"%s %s %s", current_menu_screen.menu_lines[index_line].string, text_parameters[current_menu_screen.menu_lines[index_line].parameter.text.param_index], current_menu_screen.menu_lines[index_line].parameter.text.unit); - lcd.print(line); + lcd.print(convertCyr( utf8rus( line ))); } } @@ -1125,12 +1109,15 @@ void get_money () remain = all_long_parameters[money_counter] % all_byte_parameters[price]; second = remain * 60 / all_byte_parameters[price]; - if(impulse) need_reload_menu = true; + if(impulse) + { + need_reload_menu = true; + } if (all_long_parameters[money_counter] >= all_byte_parameters[price]) { // достаточно денег для оказания услуги - sprintf(text_parameters[time_seance]," CEAHC %02d:%02d MUH", minute, second); + sprintf(text_parameters[time_seance],"СЕАНС %02d:%02d МИН", minute, second); digitalWrite(LEDPin, HIGH); // зажигаем светодиод @@ -1287,7 +1274,7 @@ void second_event() { memcpy_P( ¤t_menu_screen, &menu_main[3], sizeof(menu_screen)); menu_index = 3; - minute = all_byte_parameters[pause_after] * 60; + minute = all_byte_parameters[pause_after]; } need_clear_menu = true; @@ -1316,7 +1303,6 @@ void setup() lcd.init(); // инициализация LCD lcd.backlight(); // включаем подсветку - lcd.createChar(0, rubl); // создаем символ и записываем его в память LCD по 0 адресу pinMode(inhibitPin, OUTPUT); // устанавливает режим работы - выход pinMode(moneyPin, INPUT_PULLUP); // устанавливает режим работы - вход, подтягиваем к +5В через встроенный подтягивающий резистор (на всякий случай) @@ -1373,3 +1359,120 @@ void loop() countdown_timer(); // запускаем таймер обратного отсчета } } + +String utf8rus(String source) { + int i,k; + String target; + unsigned char n; + char m[2] = { '0', '\0' }; + + k = source.length(); i = 0; + + while (i < k) { + n = source[i]; i++; + + if (n >= 0xC0) { + switch (n) { + case 0xD0: { + n = source[i]; i++; + if (n == 0x81) { n = 0xA8; break; } + if (n >= 0x90 && n <= 0xBF) n = n + 0x30; + break; + } + case 0xD1: { + n = source[i]; i++; + if (n == 0x91) { n = 0xB8; break; } + if (n >= 0x80 && n <= 0x8F) n = n + 0x70; + break; + } + } + } + m[0] = n; target = target + String(m); + } + return target; +} + +String convertCyr( const String &s ){ + String target = s; + for( int idx = 0; idx