-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathansihelpers.cpp
More file actions
55 lines (47 loc) · 1.93 KB
/
Copy pathansihelpers.cpp
File metadata and controls
55 lines (47 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Arduino.h>
#include "api.h"
// Limpia pantalla y mueve cursor arriba izquierda
void cls() {
Serial.print("\033[2J\033[H");
}
// Convierte nombre de color de texto a código ANSI (30-37)
int fgColorCodeFromName(const String& colorName) {
if (colorName.equalsIgnoreCase("black")) return 30;
if (colorName.equalsIgnoreCase("red")) return 31;
if (colorName.equalsIgnoreCase("green")) return 32;
if (colorName.equalsIgnoreCase("yellow")) return 33;
if (colorName.equalsIgnoreCase("blue")) return 34;
if (colorName.equalsIgnoreCase("magenta")) return 35;
if (colorName.equalsIgnoreCase("cyan")) return 36;
if (colorName.equalsIgnoreCase("white")) return 37;
return 37; // Default white
}
// Convierte nombre de color de fondo a código ANSI (40-47)
int bgColorCodeFromName(const String& colorName) {
if (colorName.equalsIgnoreCase("black")) return 40;
if (colorName.equalsIgnoreCase("red")) return 41;
if (colorName.equalsIgnoreCase("green")) return 42;
if (colorName.equalsIgnoreCase("yellow")) return 43;
if (colorName.equalsIgnoreCase("blue")) return 44;
if (colorName.equalsIgnoreCase("magenta")) return 45;
if (colorName.equalsIgnoreCase("cyan")) return 46;
if (colorName.equalsIgnoreCase("white")) return 47;
return -1; // No background / invalid
}
// Función para imprimir texto con color y fondo opcional
void printColorBg(const String& fgColor, const String& bgColor, const String& text) {
int fgCode = fgColorCodeFromName(fgColor);
int bgCode = bgColorCodeFromName(bgColor);
Serial.print("\033[");
Serial.print(fgCode);
if (bgCode != -1) {
Serial.print(";");
Serial.print(bgCode);
}
Serial.print("m");
Serial.print(text);
Serial.print("\033[0m"); // Reset colores
}
void printColorBgln(const String& fgColor, const String& bgColor, const String& text) {
printColorBg(fgColor, bgColor, text + "\n");
}