154 lines
2.7 KiB
C++
154 lines
2.7 KiB
C++
#include "display.h"
|
|
#include "config.h"
|
|
|
|
|
|
void LCDPrintLine(LiquidCrystal* display, uint8_t y, const char* value, uint8_t margin)
|
|
{
|
|
display->setCursor(margin, y);
|
|
|
|
uint8_t width = LCDWidth - (2 * margin);
|
|
|
|
if (value != NULL)
|
|
{
|
|
uint8_t length = strlen(value);
|
|
|
|
if (length >= width)
|
|
{
|
|
char* character = (char*)value;
|
|
for (uint8_t i = 0; i < width; i++)
|
|
{
|
|
display->write(byte(*character));
|
|
character++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
display->print(value);
|
|
width -= length;
|
|
|
|
while (width > 0)
|
|
{
|
|
display->write(' ');
|
|
width--;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (uint8_t i = 0; i < width; i++)
|
|
display->write(' ');
|
|
}
|
|
}
|
|
|
|
|
|
void LCDPrintLineCentered(LiquidCrystal* display, uint8_t y, const char* value, uint8_t margin)
|
|
{
|
|
display->setCursor(margin, y);
|
|
|
|
uint8_t width = LCDWidth - (2 * margin);
|
|
|
|
if (value != NULL)
|
|
{
|
|
uint8_t length = strlen(value);
|
|
|
|
if (length >= width)
|
|
{
|
|
char* character = (char*)value;
|
|
for (uint8_t i = 0; i < width; i++)
|
|
{
|
|
display->write(byte(*character));
|
|
character++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
uint8_t offset = (width - length) / 2;
|
|
width -= offset;
|
|
|
|
for (uint8_t i = 0; i < offset; i++)
|
|
display->write(' ');
|
|
|
|
display->print(value);
|
|
width -= length;
|
|
|
|
while (width > 0)
|
|
{
|
|
display->write(' ');
|
|
width--;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (uint8_t i = 0; i < width; i++)
|
|
display->write(' ');
|
|
}
|
|
}
|
|
|
|
|
|
const char* UniqueString(const char* value)
|
|
{
|
|
char* result = new char[strlen(value) + 1];
|
|
return strcpy(result, value);
|
|
}
|
|
|
|
|
|
#define ASCII0 0x30
|
|
|
|
|
|
const char* FormatTime(uint16_t time)
|
|
{
|
|
uint16_t minutes = time / 60;
|
|
uint8_t seconds = time % 60;
|
|
|
|
char* value = new char[9];
|
|
itoa(minutes, value, 10);
|
|
|
|
uint8_t length = strlen(value);
|
|
value[length] = ':'; length++;
|
|
|
|
value[length] = (seconds / 10) + ASCII0; length++;
|
|
value[length] = (seconds % 10) + ASCII0; length++;
|
|
value[length] = 0;
|
|
|
|
return value;
|
|
}
|
|
|
|
|
|
const char* FormatPercentage(uint8_t percentage)
|
|
{
|
|
char* value = new char[6];
|
|
|
|
|
|
itoa(percentage, value, 10);
|
|
|
|
uint8_t length = strlen(value);
|
|
value[length] = '%';
|
|
value[length + 1] = 0;
|
|
|
|
return value;
|
|
}
|
|
|
|
|
|
const char* FormatPercentageFixedWidth(uint8_t percentage)
|
|
{
|
|
char* value = new char[5];
|
|
|
|
if (percentage > 99)
|
|
{
|
|
value[0] = '1';
|
|
value[1] = '0';
|
|
}
|
|
else
|
|
{
|
|
value[0] = ' ';
|
|
value[1] = percentage > 9 ? (percentage / 10) + ASCII0 : ' ';
|
|
}
|
|
|
|
value[2] = (percentage % 10) + ASCII0;
|
|
value[3] = '%';
|
|
value[4] = 0;
|
|
|
|
return value;
|
|
}
|