Эх сурвалжийг харах

Change color definition from macro to enum.

Vladimir N. Shilov 1 жил өмнө
parent
commit
a97df4007b
2 өөрчлөгдсөн 74 нэмэгдсэн , 60 устгасан
  1. 15 1
      lib/st7735/st7735.h
  2. 59 59
      lib/stab/stab.c

+ 15 - 1
lib/st7735/st7735.h

@@ -230,9 +230,23 @@
 #define ST7735_YELLOW  0xFFE0
 #define ST7735_WHITE   0xFFFF
 #define ST7735_GREY    0x7BEF
-#define ST7735_SILVER   0xE75F
+#define ST7735_SILVER  0xE75F
 #define ST7735_COLOR565(r, g, b) (((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3))
 
+typedef enum {
+Black   = 0x0000,
+Blue    = 0x001F,
+Red     = 0xF800,
+Orange  = 0xFEAD,
+Green   = 0x07E0,
+Cyan    = 0x07FF,
+Magenta = 0xF81F,
+Yellow  = 0xFFE0,
+White   = 0xFFFF,
+Grey    = 0x7BEF,
+Silver  = 0xE75F
+} Color_t;
+
 typedef enum {
   GAMMA_10 = 0x01,
   GAMMA_25 = 0x02,

+ 59 - 59
lib/stab/stab.c

@@ -762,46 +762,46 @@ static void ADC_cb(ADCDriver *adcp) {
  * @brief Подпрограмма обновления меню
  */
 static void RefreshMenu (void) {
-  ST7735_FillScreen(ST7735_BLACK);
-  ST7735_WriteString(0, 70, "Ст Прийняти та запис.", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-  ST7735_WriteString(0, 80, "Рз Прийняти без запису", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-  ST7735_WriteString(X_centred(11), 40, "Управління:", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-  ST7735_WriteString(0, 50, "P- Вибір", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+  ST7735_FillScreen(Black);
+  ST7735_WriteString(0, 70, "Ст Прийняти та запис.", LiberM_7x10, Silver, Black);
+  ST7735_WriteString(0, 80, "Рз Прийняти без запису", LiberM_7x10, Silver, Black);
+  ST7735_WriteString(X_centred(11), 40, "Управління:", LiberM_7x10, Silver, Black);
+  ST7735_WriteString(0, 50, "P- Вибір", LiberM_7x10, Silver, Black);
 #ifdef INTERFACE_ALT
 
 #else
-  ST7735_WriteString(0, 0, "Оберіть", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+  ST7735_WriteString(0, 0, "Оберіть", LiberM_7x10, Silver, Black);
 #endif
   //
   switch (cnt_dspMenu) { //Проверяем режимы меню
     case 2:  { //Если мы в начальном меню, то...
  #ifdef INTERFACE_ALT
       chsnprintf(buf, 24, "%3u V", U_LINE);
-      ST7735_WriteString(X_position(16, 0, 7), 0, buf, LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-      ST7735_WriteString(0, 10, "Рном=         Вт", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+      ST7735_WriteString(X_position(16, 0, 7), 0, buf, LiberM_7x10, Silver, Black);
+      ST7735_WriteString(0, 10, "Рном=         Вт", LiberM_7x10, Silver, Black);
  #else
-      ST7735_WriteString(X_position(8, 0, 7), 0, "/введіть Рном", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+      ST7735_WriteString(X_position(8, 0, 7), 0, "/введіть Рном", LiberM_7x10, Silver, Black);
       chsnprintf(buf, 24, "Рном=      Вт, (%3u V)", U_LINE);
-      ST7735_WriteString(0, 10, buf, LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+      ST7735_WriteString(0, 10, buf, LiberM_7x10, Silver, Black);
  #endif
-      ST7735_WriteString(0, 20, "Потужність навантаж.", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-      ST7735_WriteString(X_position(8, 0, 7), 50, "/зменшення", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-      ST7735_WriteString(0, 60, "P+ Збільшення", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+      ST7735_WriteString(0, 20, "Потужність навантаж.", LiberM_7x10, Silver, Black);
+      ST7735_WriteString(X_position(8, 0, 7), 50, "/зменшення", LiberM_7x10, Silver, Black);
+      ST7735_WriteString(0, 60, "P+ Збільшення", LiberM_7x10, Silver, Black);
       break;
     }
 
     case 1:  { //Если мы в меню выбора уставки, то...
  #ifdef INTERFACE_ALT
-      ST7735_WriteString(0, 10, "Руст=         Вт", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+      ST7735_WriteString(0, 10, "Руст=         Вт", LiberM_7x10, Silver, Black);
 #else
-      ST7735_WriteString(X_position(9, 0, 7), 0, "уставку", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-      ST7735_WriteString(0, 10, "Руст=      Вт", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+      ST7735_WriteString(X_position(9, 0, 7), 0, "уставку", LiberM_7x10, Silver, Black);
+      ST7735_WriteString(0, 10, "Руст=      Вт", LiberM_7x10, Silver, Black);
 #endif
-      ST7735_WriteString(0, 20, "=======Уставка=======", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-      ST7735_WriteString(0, 60, "P+ Вибір", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+      ST7735_WriteString(0, 20, "=======Уставка=======", LiberM_7x10, Silver, Black);
+      ST7735_WriteString(0, 60, "P+ Вибір", LiberM_7x10, Silver, Black);
 #ifdef USE_EEPROM
       if (!fl.writable) {  // Если уставки не пишутся в EEPROM, то...
-        ST7735_WriteString(0, 70, "Ст Прийняти без запису", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+        ST7735_WriteString(0, 70, "Ст Прийняти без запису", LiberM_7x10, Silver, Black);
       }
 #endif
       break;
@@ -817,7 +817,7 @@ static void RefreshMenu (void) {
  * @param str - номер строки, куда печатать минуса
  */
 static void menu_print_minus(const uint8_t str) {
-  ST7735_WriteString(0, str, "----------------------", LiberM_7x10, ST7735_RED, ST7735_BLACK);
+  ST7735_WriteString(0, str, "----------------------", LiberM_7x10, Red, Black);
 }
 
 /**
@@ -853,18 +853,18 @@ void Stab_Init(void) {
   pp_Delay(10);   // Подождем 10 полупериодов для гарантированного разрешения
 
   //ST7735_Init(); // done in main()
-  ST7735_FillScreen(ST7735_BLACK);
-  ST7735_WriteString(X_centred(12), 1, "Стабілізатор", LiberM_7x10, ST7735_YELLOW, ST7735_BLACK);
-  ST7735_WriteString(X_centred(10), 10, "потужності", LiberM_7x10, ST7735_YELLOW, ST7735_BLACK);
-  ST7735_WriteString(X_centred(4), 20, "ТЕНа", LiberM_7x10, ST7735_YELLOW, ST7735_BLACK);
+  ST7735_FillScreen(Black);
+  ST7735_WriteString(X_centred(12), 1, "Стабілізатор", LiberM_7x10, Yellow, Black);
+  ST7735_WriteString(X_centred(10), 10, "потужності", LiberM_7x10, Yellow, Black);
+  ST7735_WriteString(X_centred(4), 20, "ТЕНа", LiberM_7x10, Yellow, Black);
 #ifdef INTERFACE_ALT
-  ST7735_WriteString(X_centred(12), 50, "STAB-AVR", Font_11x18, ST7735_GREEN, ST7735_BLACK);
+  ST7735_WriteString(X_centred(12), 50, "STAB-AVR", Font_11x18, Green, Black);
 #else
-  ST7735_WriteString(X_centred(8), 50, "STAB-AVR", LiberM_7x10, ST7735_GREEN, ST7735_BLACK);
+  ST7735_WriteString(X_centred(8), 50, "STAB-AVR", LiberM_7x10, Green, Black);
 #endif
-  ST7735_WriteString(X_centred(VERSION_LEN), 70, VERSION, LiberM_7x10, ST7735_RED, ST7735_BLACK);
-  ST7735_WriteString(X_centred(10), 100, "JohnJohnov", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-  ST7735_WriteString(X_centred(17), 110, "alcodistillers.ru", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+  ST7735_WriteString(X_centred(VERSION_LEN), 70, VERSION, LiberM_7x10, Red, Black);
+  ST7735_WriteString(X_centred(10), 100, "JohnJohnov", LiberM_7x10, Silver, Black);
+  ST7735_WriteString(X_centred(17), 110, "alcodistillers.ru", LiberM_7x10, Silver, Black);
 #ifdef USE_EEPROM
   EEPROM_read_Pnoms(); // Прочитаем из EEPROM записанные номиналы ТЭНов
 #endif
@@ -953,17 +953,17 @@ void Stab_WorkCycle(void) {
         if (!Pnom || Pnom > 9999) {
           Pnomold = Pnom;
 #ifdef INTERFACE_ALT
-          ST7735_WriteString(X_position(3, 0, 11), 0, "****", Font_11x18, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(3, 0, 11), 0, "****", Font_11x18, Silver, Black);
 #else
-          ST7735_WriteString(X_position(6, 0, 7), 10, "****", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(6, 0, 7), 10, "****", LiberM_7x10, Silver, Black);
 #endif
         } else if ((Pnomold != Pnom) || fl.dspRefresh) {
           Pnomold = Pnom;
           chsnprintf(buf, 24, "%u", Pnom);
 #ifdef INTERFACE_ALT
-          ST7735_WriteString(X_position(6, Pnom, 11), 0, buf, Font_11x18, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(6, Pnom, 11), 0, buf, Font_11x18, Silver, Black);
 #else
-          ST7735_WriteString(X_position(9, Pnom, 7), 10, buf, LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(9, Pnom, 7), 10, buf, LiberM_7x10, Silver, Black);
 #endif
         }
         fl.dspRefresh = 0;
@@ -976,15 +976,15 @@ void Stab_WorkCycle(void) {
           uint16_t p = calc_proportion(PDMold, Pnom, CICLE); // Считаем уставку с округлением
           chsnprintf(buf, 24, "%u", p);
 #ifdef INTERFACE_ALT
-          ST7735_WriteString(X_position(6, p, 11), 0, buf, Font_11x18, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(6, p, 11), 0, buf, Font_11x18, Silver, Black);
 #else
-          ST7735_WriteString(X_position(9, p, 7), 10, buf, LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(9, p, 7), 10, buf, LiberM_7x10, Silver, Black);
 #endif
 #ifdef USE_EEPROM
           if (PDMset[1][cnt_PDMcount]) { // Если значение записано в EEPROM
-            ST7735_WriteString(X_position(20, 0, 7), 1, "R", LiberM_7x10, ST7735_SILVER, ST7735_BLACK); // поставим значок
+            ST7735_WriteString(X_position(20, 0, 7), 1, "R", LiberM_7x10, Silver, Black); // поставим значок
           } else {
-            ST7735_WriteString(X_position(20, 0, 7), 10, " ", LiberM_7x10, ST7735_SILVER, ST7735_BLACK); // а если не записано - уберем
+            ST7735_WriteString(X_position(20, 0, 7), 10, " ", LiberM_7x10, Silver, Black); // а если не записано - уберем
           }
 #endif
         }
@@ -1011,16 +1011,16 @@ void Stab_WorkCycle(void) {
 #endif
 
         if (fl.dspRefresh) {  //Обновляем дисплей
-          ST7735_FillScreen(ST7735_BLACK);
+          ST7735_FillScreen(Black);
 #ifdef INTERFACE_ALT
-          ST7735_WriteString(X_position(8, 0, 7), str_ust, "Вт       ,  %", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(8, 0, 7), str_ust, "Вт       ,  %", LiberM_7x10, Silver, Black);
 #else
-          ST7735_WriteString(0, str_ust, "Руст      Вт;    ,  %", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(0, str_ust, "Руст      Вт;    ,  %", LiberM_7x10, Silver, Black);
 #endif
-          ST7735_WriteString(0, str_Ureal, "Напруга мережі    ,  В", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(0, str_Ureal, "Напруга мережі    ,  В", LiberM_7x10, Silver, Black);
           chsnprintf(buf, 24, "Ном. потужність %u Вт", Pnom);
-          ST7735_WriteString(0, str_Pnom, buf, LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-          //ST7735_WriteString(X_position(0, 0, 7), str_Relay, "Реле ", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(0, str_Pnom, buf, LiberM_7x10, Silver, Black);
+          //ST7735_WriteString(X_position(0, 0, 7), str_Relay, "Реле ", LiberM_7x10, Silver, Black);
         }
 
         static uint16_t U_real_old = 0;
@@ -1028,9 +1028,9 @@ void Stab_WorkCycle(void) {
           U_real_old = U_real;
           chsnprintf(buf, 24, "%u", U_real_old);
 #ifdef INTERFACE_ALT
-          ST7735_WriteString(X_position(7, U_real_old, 11) + 5, str_Ureal_big, buf, Font_11x18, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(7, U_real_old, 11) + 5, str_Ureal_big, buf, Font_11x18, Silver, Black);
 #else
-          ST7735_WriteString(X_position(16, U_real_old, 7), str_Ureal, buf, LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(16, U_real_old, 7), str_Ureal, buf, LiberM_7x10, Silver, Black);
 #endif
         }
         static uint8_t U_real_dec_old = 0;
@@ -1038,9 +1038,9 @@ void Stab_WorkCycle(void) {
           U_real_dec_old = U_real_dec;
           chsnprintf(buf, 24, "%u", U_real_dec);
 #ifdef INTERFACE_ALT
-          ST7735_WriteString(X_position(9, 0, 11), str_Ureal_big, buf, Font_11x18, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(9, 0, 11), str_Ureal_big, buf, Font_11x18, Silver, Black);
 #else
-          ST7735_WriteString(X_position(18, 0, 7), str_Ureal_big, buf, Font_11x18, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(18, 0, 7), str_Ureal_big, buf, Font_11x18, Silver, Black);
 #endif
         }
 
@@ -1049,9 +1049,9 @@ void Stab_WorkCycle(void) {
           Pust_old = Pust;
           chsnprintf(buf, 24, "%u", Pust_old);
 #ifdef INTERFACE_ALT
-          ST7735_WriteString(X_position(3,Pust_old,11), str_ust_big, buf, Font_11x18, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(3,Pust_old,11), str_ust_big, buf, Font_11x18, Silver, Black);
 #else
-          ST7735_WriteString(X_position(8,Pust_old,7), str_ust, buf, LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(8,Pust_old,7), str_ust, buf, LiberM_7x10, Silver, Black);
 #endif
         }
 
@@ -1064,16 +1064,16 @@ void Stab_WorkCycle(void) {
           uint8_t percent_dec = x % 10; // посчитаем десятые процента
           chsnprintf(buf, 24, "%u.%u", percent, percent_dec);
 #ifdef INTERFACE_ALT
-          ST7735_WriteString(X_position(7,100,11) + 5, str_ust_big, buf, Font_11x18, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(7,100,11) + 5, str_ust_big, buf, Font_11x18, Silver, Black);
 #else
-          ST7735_WriteString(X_position(13, 0, 7), str_ust, buf, LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(X_position(13, 0, 7), str_ust, buf, LiberM_7x10, Silver, Black);
 #endif
         }
 
         if (fl.Udown || fl.NotZero) {
-          ST7735_WriteString(0, str_Ustat, "---- Аварія мережі ---", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(0, str_Ustat, "---- Аварія мережі ---", LiberM_7x10, Red, Black);
         } else if (fl.Ulow) {
-          ST7735_WriteString(0, str_Ustat, "- Недост.напр. мережі -", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(0, str_Ustat, "- Недост.напр. мережі -", LiberM_7x10, Orange, Black);
         } else {
           menu_print_minus(str_Ustat);
         }
@@ -1082,9 +1082,9 @@ void Stab_WorkCycle(void) {
           static uint8_t count_1 = 0;
           uint8_t x1 = 5 - count_1;
           uint8_t x2 = 20 - x1;
-          ST7735_WriteString(0, str_Razgon, "------ <Разгон!> ------", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-          ST7735_WriteString(X_position(x1, 0, 7), str_Razgon, "<", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
-          ST7735_WriteString(X_position(x2, 0, 7), str_Razgon, ">", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+          ST7735_WriteString(0, str_Razgon, "------ <Разгон!> ------", LiberM_7x10, Yellow, Black);
+          ST7735_WriteString(X_position(x1, 0, 7), str_Razgon, "<", LiberM_7x10, Silver, Black);
+          ST7735_WriteString(X_position(x2, 0, 7), str_Razgon, ">", LiberM_7x10, Silver, Black);
           if (++count_1 > 5) count_1 = 0;
         } else {
           menu_print_minus(str_Razgon);
@@ -1093,7 +1093,7 @@ void Stab_WorkCycle(void) {
         {
           static uint8_t trigger = 1;
           if (trigger && fl.stab_off) {
-            ST7735_WriteString(0, str_Relay, "!! АВАРІЙНА ЗУПИНКА !!", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+            ST7735_WriteString(0, str_Relay, "!! АВАРІЙНА ЗУПИНКА !!", LiberM_7x10, Red, Black);
             trigger = 0;
           } else {
             menu_print_minus(str_Relay);
@@ -1102,9 +1102,9 @@ void Stab_WorkCycle(void) {
         }
 
         //if (fl.TRelay) {
-        //  ST7735_WriteString(X_position(5, 0, 7), str_Relay, "включено", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+        //  ST7735_WriteString(X_position(5, 0, 7), str_Relay, "включено", LiberM_7x10, Silver, Black);
         //} else {
-        //  ST7735_WriteString(X_position(5, 0, 7), str_Relay, "        ", LiberM_7x10, ST7735_SILVER, ST7735_BLACK);
+        //  ST7735_WriteString(X_position(5, 0, 7), str_Relay, "        ", LiberM_7x10, Silver, Black);
         //}
         fl.dspRefresh = 0;
       }