Mostrar datos de Raspberry Pi en la pantalla LCD de la terminal Wio

#include»TFT_eSPI.h»

#include»Free_Fonts.h» //incluye el archivo de encabezado

TFT_eSPI tft;

búfer de caracteres[100];

Cadena CPU_temp, CPU_usage, Ram_total, Ram_used, Ram_free, Disk_total, Disk_used, Disk_Per;

const sin firmar char ram[] = {

0x00, 0xC3, 0x18, 0xC3, 0x00, 0x00, 0xE7, 0x18, 0xE7, 0x00, 0x00, 0xC3,

0x18, 0xC3, 0x00, 0x00, 0xC3, 0x18, 0xC3, 0x00, 0x00, 0xE7, 0x18, 0xE7,

0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0xC0, 0xFF, 0xFF, 0xFF, 0x03, 0xE0,

0x01, 0x00, 0x80, 0x07, 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x7F, 0x00, 0x00,

0x00, 0xFE, 0x72, 0xF0, 0xFF, 0x0F, 0x4E, 0x60, 0xF8, 0xFF, 0x1F, 0x06,

0x60, 0x3C, 0x00, 0x3C, 0x06, 0x72, 0x1C, 0x00, 0x38, 0x4E, 0x7F, 0x0C,

0x00, 0x30, 0xFE, 0x7F, 0x0C, 0x00, 0x30, 0xFE, 0x60, 0x0C, 0x00, 0x30,

0x06, 0x60, 0x0C, 0x00, 0x30, 0x06, 0x60, 0x0C, 0x00, 0x30, 0x06, 0x7F,

0x0C, 0x00, 0x30, 0xFE, 0x7F, 0x0C, 0x00, 0x30, 0xFE, 0x60, 0x0C, 0x00,

0x30, 0x06, 0x60, 0x0C, 0x00, 0x30, 0x06, 0x60, 0x0C, 0x00, 0x30, 0x06,

0x7F, 0x0C, 0x00, 0x30, 0xFE, 0x7F, 0x0C, 0x00, 0x30, 0xFE, 0x72, 0x1C,

0x00, 0x38, 0x4E, 0x60, 0x3C, 0x00, 0x3C, 0x06, 0x60, 0xF8, 0xFF, 0x1F,

0x06, 0x72, 0xF0, 0xFF, 0x0F, 0x4E, 0x7F, 0x00, 0x00, 0x00, 0xFE, 0xFF,

0x00, 0x00, 0x00, 0xFF, 0xE0, 0x01, 0x00, 0x80, 0x07, 0xC0, 0xFF, 0xFF,

0xFF, 0x03, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0xE7, 0x18, 0xE7, 0x00,

0x00, 0xC3, 0x18, 0xC3, 0x00, 0x00, 0xC3, 0x18, 0xC3, 0x00, 0x00, 0xE7,

0x18, 0xE7, 0x00, 0x00, 0xC3, 0x18, 0xC3, 0x00, };

cpu de caracteres sin firmar const[] = {

0x00, 0x42, 0x18, 0x42, 0x00, 0x00, 0x42, 0x18, 0x42, 0x00, 0x00, 0x42,

0x18, 0x42, 0x00, 0x00, 0x42, 0x18, 0x42, 0x00, 0x00, 0x00, 0x00, 0x00,

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0xFF, 0xFF, 0x01, 0xC0,

0x00, 0x00, 0x00, 0x03, 0x40, 0x00, 0x00, 0x00, 0x02, 0x4F, 0x00, 0x00,

0x00, 0xF2, 0x40, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00, 0x02,

0x40, 0x00, 0x00, 0x00, 0x02, 0x40, 0xF0, 0xFF, 0x0F, 0x02, 0x4F, 0xF8,

0xFF, 0x1F, 0xF2, 0x40, 0x18, 0x00, 0x18, 0x02, 0x40, 0xD8, 0xBD, 0x1E,

0x02, 0x40, 0x78, 0xBC, 0x1E, 0x02, 0x40, 0x78, 0xA4, 0x1E, 0x02, 0x4F,

0x78, 0xBC, 0x1E, 0xF2, 0x4F, 0x78, 0xBC, 0x1E, 0xF2, 0x40, 0x78, 0x84,

0x1E, 0x02, 0x40, 0x78, 0x84, 0x1E, 0x02, 0x40, 0xD8, 0x85, 0x1B, 0x02,

0x40, 0x18, 0x00, 0x18, 0x02, 0x4F, 0xF8, 0xFF, 0x1F, 0xF2, 0x40, 0xF0,

0xFF, 0x0F, 0x02, 0x40, 0x00, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x00,

0x02, 0x40, 0x00, 0x00, 0x00, 0x02, 0x4F, 0x00, 0x00, 0x00, 0xF2, 0x40,

0x00, 0x00, 0x00, 0x02, 0xC0, 0x00, 0x00, 0x00, 0x03, 0x80, 0xFF, 0xFF,

0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x00, 0x42, 0x18, 0x42, 0x00, 0x00, 0x42, 0x18, 0x42, 0x00, 0x00, 0x42,

0x18, 0x42, 0x00, 0x00, 0x42, 0x18, 0x42, 0x00, };

disco de caracteres sin firmar const[] = {

0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0xFF, 0xFF, 0x03, 0xFC, 0xFB,

0xFF, 0xDF, 0x06, 0x06, 0x02, 0x00, 0x40, 0x0C, 0x06, 0x02, 0x00, 0x5F,

0x18, 0x06, 0x02, 0x00, 0x51, 0x30, 0x06, 0x02, 0x00, 0x59, 0x60, 0x06,

0x02, 0x00, 0x59, 0x40, 0x06, 0x02, 0x00, 0x59, 0x60, 0x06, 0x02, 0x00,

0x59, 0x60, 0x06, 0x02, 0x00, 0x59, 0x60, 0x06, 0x02, 0x00, 0x5F, 0x60,

0x06, 0x02, 0x00, 0x40, 0x60, 0x06, 0xFE, 0xFF, 0x7F, 0x60, 0x06, 0x00,

0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x00,

0x60, 0x06, 0x00, 0x00, 0x00, 0x60, 0x06, 0x00, 0x00, 0x00, 0x60, 0xC6,

0xFF, 0xFF, 0xFF, 0x63, 0x66, 0x00, 0x00, 0x00, 0x66, 0x26, 0x00, 0x00,

0x00, 0x64, 0x26, 0x00, 0x00, 0x00, 0x64, 0x26, 0x00, 0x00, 0x00, 0x64,

0x26, 0xFC, 0xFF, 0x3F, 0x64, 0x26, 0xFC, 0xFF, 0x3F, 0x64, 0x26, 0x00,

0x00, 0x00, 0x64, 0x26, 0x00, 0x00, 0x00, 0x64, 0x26, 0xFC, 0xFF, 0x3F,

0x64, 0x26, 0x00, 0x00, 0x00, 0x64, 0x26, 0x00, 0x00, 0x00, 0x64, 0x26,

0x00, 0x00, 0x00, 0x64, 0x26, 0xFC, 0xFF, 0x3F, 0x64, 0x26, 0x00, 0x00,

0x00, 0x64, 0x26, 0x00, 0x00, 0x00, 0x64, 0x26, 0x00, 0x00, 0x00, 0x64,

0x26, 0x00, 0x00, 0x00, 0x64, 0xEC, 0xFF, 0xFF, 0xFF, 0x37, 0xF8, 0xFF,

0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, };

String getStringPartByNr (datos de cadena, separador de caracteres, índice int)

{

// dividir una cadena y devolver el índice parte nr

// dividir por separador

int datos de cadena = 0; //variable para contar parte de datos nr

String ParteDatos = «»; //variable para perforar el texto de retorno

for(int i = 0; i

si (datos[i]==separador) {

//Contar el número de veces que aparece el carácter separador en el texto

datos de cadena++;

}else if(stringData==índice) {

// obtener el texto cuando el separador es el correcto

dataPart.concat(datos[i]);

}else if(cadena de datos>índice) {

//devuelve el texto y se detiene si aparece el siguiente separador, para ahorrar tiempo de CPU

devolver parte de datos;

romper;

}

}

//devuelve el texto si esta es la última parte

devolver parte de datos;

}

configuración vacía () {

// inicializa los puertos serie:

Serial.begin(115200);

Serial.flush();

tft.begin();

tft.setRotation(3);

//Pantalla de inicio cuando no hay datos

tft.llenar pantalla(TFT_BLANCO);

mientras(1) {

Pantalla de inicio();

si (Serial.disponible())

romper;

}

}

bucle vacío () {

// Intenta obtener los datos del puerto serie

if (Serial.disponible() > 0) {

índice int = 0;

int numChar = Serial.disponible();

if (numChar>50) {

numChar=50;

}

memset (búfer, 0, tamaño de (búfer));

while (numChar–) {

buffer[index++] = Serie.leer();

}

CPU_temp = getStringPartByNr(búfer, ‘.’, 0);

CPU_usage = getStringPartByNr(búfer, ‘:’, 1);

Ram_total = getStringPartByNr(búfer, ‘:’, 2);

Ram_used = getStringPartByNr(buffer, ‘:’, 3);

Ram_free = getStringPartByNr(búfer, ‘:’, 4);

Disk_total = getStringPartByNr(buffer, ‘:’, 5);

Disk_used = getStringPartByNr(buffer, ‘:’, 6);

Disk_Per = getStringPartByNr(búfer, ‘:’, 7);

}

//comprobando que el último dato no esté vacío

if (Disk_Per != «») {

PantallaTemporal();

retraso (2000);

RamScreen();

retraso (2000);

PantallaDisco();

retraso (2000);

}

}

void TempScreen() {

tft.llenar pantalla(TFT_NEGRO);

tft.setTextColor(TFT_WHITE);

tft.establecerTamañoTexto(1);

tft.setFreeFont(FSSB12); //seleccione Libre, Sans, Negrita, Oblicua, 12pt.

tft.drawString(«Datos de CPU de Raspberry»,40,17);

tft.drawFastHLine(0,45,320,TFT_RED);

tft.drawFastHLine(0,46,320,TFT_RED);

tft.drawFastHLine(0,47,320,TFT_RED);

tft.drawRoundRect(34,66,82,32,5,TFT_WHITE);

tft.fillRoundRect(35,67,80,30,5,TFT_DARKGREY);

tft.setFreeFont(FMB12);

tft.setTextColor(TFT_WHITE);

tft.drawString(«TEMP:»,40,70);

tft.drawRoundRect(34,116,92,32,5,TFT_WHITE);

tft.fillRoundRect(35,117,90,30,5,TFT_DARKGREY);

tft.drawString(«USO:»,40,120);

tft.drawFastHLine(0,220,320,TFT_RED);

tft.drawFastHLine(0,221,320,TFT_RED);

tft.drawFastHLine(0,222,320,TFT_RED);

tft.fillCircle(15,80, 5, TFT_DARKGREY);

tft.fillCircle(15,130, 5, TFT_DARKGREY);

tft.drawCircle(15,80,6,TFT_WHITE);

tft.drawCircle(15,130,6,TFT_WHITE);

tft.setTextColor(TFT_WHITE);

tft.drawString(CPU_temp+’C’,130,70);

tft.drawString(Uso_CPU+’%’,130,120);

tft.drawXBitmap(245,110,cpu, 40, 40, TFT_DARKGREY);

}

void RamScreen() {

tft.llenar pantalla(TFT_NEGRO);

tft.setTextColor(TFT_WHITE);

tft.establecerTamañoTexto(1);

tft.setFreeFont(FSSB12); //seleccione Libre, Sans, Negrita, Oblicua, 12pt.

tft.drawString(«Datos RAM de Raspberry»,40,17);

tft.drawFastHLine(0,45,320,TFT_BLUE);

tft.drawFastHLine(0,46,320,TFT_BLUE);

tft.drawFastHLine(0,47,320,TFT_BLUE);

tft.drawRoundRect(34,66,92,32,5,TFT_WHITE);

tft.fillRoundRect(35,67,90,30,5,TFT_PINK);

tft.setFreeFont(FMB12);

tft.setTextColor(TFT_WHITE);

tft.drawString(«TOTAL:»,40,70);

tft.drawRoundRect(34,116,92,32,5,TFT_WHITE);

tft.fillRoundRect(35,117,90,30,5,TFT_PINK);

tft.drawString(«USADO:»,40,120);

tft.drawRoundRect(34,166,92,32,5,TFT_WHITE);

tft.fillRoundRect(35,167,90,30,5,TFT_PINK);

tft.drawString(«GRATIS:»,40,170);

tft.drawFastHLine(0,220,320,TFT_BLUE);

tft.drawFastHLine(0,221,320,TFT_BLUE);

tft.drawFastHLine(0,222,320,TFT_BLUE);

tft.fillCircle(15,80, 5, TFT_PINK);

tft.fillCircle(15,130, 5, TFT_PINK);

tft.fillCircle(15,180, 5, TFT_PINK);

tft.drawCircle(15,80,6,TFT_WHITE);

tft.drawCircle(15,130,6,TFT_WHITE);

tft.drawCircle(15,180,6,TFT_WHITE);

tft.setTextColor(TFT_WHITE);

tft.drawString(Ram_total+»MB»,130,70);

tft.drawString(Ram_used+»MB», 130,120);

tft.drawString(Ram_free+»MB», 130,170);

tft.drawXBitmap(245,110, ram, 40, 40, TFT_PINK);

}

anular pantalla de disco () {

tft.llenar pantalla(TFT_NEGRO);

tft.setTextColor(TFT_WHITE);

tft.establecerTamañoTexto(1);

tft.setFreeFont(FSSB12);

tft.drawString(«Datos de disco de Raspberry»,35,17);

tft.drawFastHLine(0,45,320,TFT_NARANJA);

tft.drawFastHLine(0,46,320,TFT_NARANJA);

tft.drawFastHLine(0,47,320,TFT_NARANJA);

tft.drawRoundRect(34,66,92,32,5,TFT_WHITE);

tft.fillRoundRect(35,67,90,30,5,TFT_DARKCYAN);

tft.setFreeFont(FMB12);

tft.drawString(«TOTAL:»,40,70);

tft.drawRoundRect(34,116,92,32,5,TFT_WHITE);

tft.fillRoundRect(35,117,90,30,5,TFT_DARKCYAN);

tft.drawString(«USADO:»,40,120);

tft.drawRoundRect(34,166,92,32,5,TFT_WHITE);

tft.fillRoundRect(35,167,90,30,5,TFT_DARKCYAN);

tft.drawString(«PERC.:»,40,170);

tft.drawFastHLine(0,220,320,TFT_NARANJA);

tft.drawFastHLine(0,221,320,TFT_NARANJA);

tft.drawFastHLine(0,222,320,TFT_NARANJA);

tft.fillCircle(15,80, 5, TFT_DARKCYAN);

tft.fillCircle(15,130, 5, TFT_DARKCYAN);

tft.fillCircle(15,180, 5, TFT_DARKCYAN);

tft.drawCircle(15,80,6,TFT_WHITE);

tft.drawCircle(15,130,6,TFT_WHITE);

tft.drawCircle(15,180,6,TFT_WHITE);

if (Disk_Per != 0) {

int perc = atoi(Disk_Per.c_str());

relación de flotación = perc*(0.01) * 30;

tft.drawRect(180,168,10,30,TFT_WHITE);

tft.fillRect(180,(168+(30-(int)ratio)),10,(int)ratio,TFT_WHITE);

}

tft.drawString(Disk_total+’B’,130,70);

tft.drawString(Disco_usado+’B’, 130,120);

tft.drawString(Disk_Per+’%’, 130,170);

tft.drawXBitmap(245,110,disco, 40, 40, TFT_DARKCYAN);

}

void Pantalla de inicio () {

tft.setFreeFont(FSSB9);

tft.setTextColor(TFT_NEGRO);

tft.drawString(«Iniciando…», 120,120);

}