Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-11-19 18:06:44 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-11-19 18:06:44 +0300
commita7cb2ae0d094c9e313afd0a3276c312b4ca25806 (patch)
treec774d44c4715866da3bb940070fc661986322c37 /src/Display
parentbe5f583491490febf0384214d168286c250e6712 (diff)
LCD now uses vuprintf instead of deriving from Print
Diffstat (limited to 'src/Display')
-rw-r--r--src/Display/Display.cpp4
-rw-r--r--src/Display/Lcd/Lcd.cpp20
-rw-r--r--src/Display/Lcd/Lcd.h8
-rw-r--r--src/Display/Menu.cpp12
-rw-r--r--src/Display/MenuItem.cpp57
5 files changed, 51 insertions, 50 deletions
diff --git a/src/Display/Display.cpp b/src/Display/Display.cpp
index aaf0778e..64a59fdb 100644
--- a/src/Display/Display.cpp
+++ b/src/Display/Display.cpp
@@ -139,7 +139,7 @@ void Display::Exit() noexcept
lcd->Clear();
lcd->SetFont(LargeFontNumber);
lcd->SetCursor(20, 0);
- lcd->print("Shutting down...");
+ lcd->printf("Shutting down...");
}
lcd->FlushAll();
}
@@ -256,7 +256,7 @@ void Display::UpdatingFirmware() noexcept
lcd->Clear();
lcd->SetFont(LargeFontNumber);
lcd->SetCursor(20, 0);
- lcd->print("Updating firmware...");
+ lcd->printf("Updating firmware...");
lcd->FlushAll();
}
}
diff --git a/src/Display/Lcd/Lcd.cpp b/src/Display/Lcd/Lcd.cpp
index 16da815c..16e46bca 100644
--- a/src/Display/Lcd/Lcd.cpp
+++ b/src/Display/Lcd/Lcd.cpp
@@ -305,6 +305,26 @@ void Lcd::WriteSpaces(PixelNumber numPixels) noexcept
justSetCursor = false;
}
+// printf to LCD
+int Lcd::printf(const char* fmt, ...) noexcept
+{
+ va_list vargs;
+ va_start(vargs, fmt);
+ int ret = vuprintf([this](char c) -> bool
+ {
+ if (c != 0)
+ {
+ write(c);
+ }
+ return true;
+ },
+ fmt,
+ vargs
+ );
+ va_end(vargs);
+ return ret;
+}
+
// Set the left margin. This is where the cursor goes to when we print newline.
void Lcd::SetLeftMargin(PixelNumber c) noexcept
{
diff --git a/src/Display/Lcd/Lcd.h b/src/Display/Lcd/Lcd.h
index 7142b523..fabb53c3 100644
--- a/src/Display/Lcd/Lcd.h
+++ b/src/Display/Lcd/Lcd.h
@@ -8,6 +8,7 @@
#include <Print.h>
#include "Fonts/LcdFont.h"
#include <Hardware/SharedSpi/SharedSpiClient.h>
+#include <General/SafeVsnprintf.h>
// Enumeration for specifying drawing modes
enum class PixelMode : uint8_t
@@ -23,7 +24,7 @@ typedef uint8_t PixelNumber;
// This drives the GLCD in serial mode so that it needs just 2 pins.
// Derive the LCD class from the Print class so that we can print stuff to it in alpha mode
-class Lcd : public Print
+class Lcd
{
public:
// Construct a GLCD driver.
@@ -51,7 +52,7 @@ public:
// Write a single character in the current font. Called by the 'print' functions.
// c = character to write
// Returns the number of characters written (1 if we wrote it, 0 otherwise)
- size_t write(uint8_t c) noexcept override; // write a character
+ size_t write(uint8_t c) noexcept; // write a character
// Write a space
void WriteSpaces(PixelNumber numPixels) noexcept;
@@ -140,6 +141,9 @@ public:
// data = bitmap image, must be ((width + 7)/8) bytes long
void BitmapRow(PixelNumber top, PixelNumber left, PixelNumber width, const uint8_t data[], bool invert) noexcept;
+ // printf to LCD
+ int printf(const char* fmt, ...) noexcept;
+
protected:
virtual void HardwareInit() noexcept = 0;
diff --git a/src/Display/Menu.cpp b/src/Display/Menu.cpp
index 5243354f..3677680c 100644
--- a/src/Display/Menu.cpp
+++ b/src/Display/Menu.cpp
@@ -223,20 +223,16 @@ void Menu::LoadError(const char *msg, unsigned int line) noexcept
lcd.Clear();
lcd.SetFont(0);
- lcd.print("Error loading menu\nFile: ");
- lcd.print((numNestedMenus > 0) ? filenames[numNestedMenus - 1].c_str() : "(none)");
+ lcd.printf("Error loading menu\nFile: %s", (numNestedMenus > 0) ? filenames[numNestedMenus - 1].c_str() : "(none)");
if (line != 0)
{
- lcd.print("\nLine ");
- lcd.print(line);
+ lcd.printf("\nLine %u", line);
if (errorColumn != 0)
{
- lcd.print(" column ");
- lcd.print(errorColumn);
+ lcd.printf(" column %u", errorColumn);
}
}
- lcd.write('\n');
- lcd.print(msg);
+ lcd.printf("\n%s", msg);
lastActionTime = millis();
timeoutValue = ErrorTimeout;
diff --git a/src/Display/MenuItem.cpp b/src/Display/MenuItem.cpp
index a43bac4f..614cf173 100644
--- a/src/Display/MenuItem.cpp
+++ b/src/Display/MenuItem.cpp
@@ -116,7 +116,7 @@ TextMenuItem::TextMenuItem(PixelNumber r, PixelNumber c, PixelNumber w, Alignmen
void TextMenuItem::CorePrint(Lcd& lcd) noexcept
{
- lcd.print(text);
+ lcd.printf("%s", text);
}
void TextMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, PixelNumber tOffset) noexcept
@@ -138,7 +138,7 @@ void TextMenuItem::UpdateWidthAndHeight(Lcd& lcd) noexcept
lcd.SetCursor(lcd.GetNumRows(), 0);
lcd.SetRightMargin(lcd.GetNumCols());
lcd.TextInvert(false);
- lcd.print(text);
+ lcd.printf("%s", text);
width = lcd.GetColumn();
if (align == LeftAlign)
{
@@ -160,7 +160,7 @@ ButtonMenuItem::ButtonMenuItem(PixelNumber r, PixelNumber c, PixelNumber w, Font
void ButtonMenuItem::CorePrint(Lcd& lcd) noexcept
{
lcd.WriteSpaces(1); // space at start in case highlighted
- lcd.print(text);
+ lcd.printf("%s", text);
lcd.WriteSpaces(1); // space at end to allow for highlighting
}
@@ -249,41 +249,34 @@ void ValueMenuItem::CorePrint(Lcd& lcd) noexcept
if (error)
{
- lcd.print("***");
+ lcd.printf("***");
}
else
{
switch (currentFormat)
{
case PrintFormat::asFloat:
- lcd.print(currentValue.f, decimals);
+ lcd.printf("%.*f", decimals, (double)currentValue.f);
break;
case PrintFormat::asPercent:
- lcd.print(currentValue.f, decimals);
- lcd.print('%');
+ lcd.printf("%.*f%%", decimals, (double)currentValue.f);
break;
case PrintFormat::asUnsigned:
- lcd.print(currentValue.u);
+ lcd.printf("%u", currentValue.u);
break;
case PrintFormat::asSigned:
- lcd.print(currentValue.i);
+ lcd.printf("%d", currentValue.i);
break;
case PrintFormat::asText:
- lcd.print(textValue);
+ lcd.printf("%s", textValue);
break;
case PrintFormat::asIpAddress:
- lcd.print(currentValue.u & 0x000000FF);
- lcd.print(':');
- lcd.print((currentValue.u >> 8) & 0x0000000FF);
- lcd.print(':');
- lcd.print((currentValue.u >> 16) & 0x0000000FF);
- lcd.print(':');
- lcd.print((currentValue.u >> 24) & 0x0000000FF);
+ lcd.printf("%u.%u.%u.%u", currentValue.u & 0x000000FF, (currentValue.u >> 8) & 0x0000000FF, (currentValue.u >> 16) & 0x0000000FF, (currentValue.u >> 24) & 0x0000000FF);
break;
case PrintFormat::asTime:
@@ -291,25 +284,13 @@ void ValueMenuItem::CorePrint(Lcd& lcd) noexcept
unsigned int hours = currentValue.u/3600,
minutes = (currentValue.u / 60) % 60,
seconds = currentValue.u % 60;
- lcd.print(hours);
- lcd.print(':');
- if (minutes < 10)
- {
- lcd.print('0');
- }
- lcd.print(minutes);
- lcd.print(':');
- if (seconds < 10)
- {
- lcd.print('0');
- }
- lcd.print(seconds);
+ lcd.printf("%u:%02u:%02u", hours, minutes, seconds);
}
break;
case PrintFormat::undefined:
default:
- lcd.print("***");
+ lcd.printf("***");
break;
}
}
@@ -818,7 +799,7 @@ void FilesMenuItem::Draw(Lcd& lcd, PixelNumber rightMargin, bool highlight, Pixe
lcd.SetRightMargin(rightMargin);
lcd.ClearToMargin();
lcd.SetCursor(row, column);
- lcd.print(reply.c_str());
+ lcd.printf("%s", reply.c_str());
break;
}
}
@@ -847,13 +828,13 @@ void FilesMenuItem::ListFiles(Lcd& lcd, PixelNumber rightMargin, bool highlight,
if (m_uListingFirstVisibleIndex == 0)
{
lcd.SetCursor(row, column);
- lcd.print(" ..");
+ lcd.printf(" ..");
lcd.ClearToMargin();
if (highlight && m_uListingSelectedIndex == 0)
{
// Overwriting the initial spaces with '>' avoids shifting the following text when we change the selection
lcd.SetCursor(row, column);
- lcd.print(">");
+ lcd.write('>');
}
line = 1;
dirEntriesToSkip = 0;
@@ -892,17 +873,17 @@ void FilesMenuItem::ListFiles(Lcd& lcd, PixelNumber rightMargin, bool highlight,
// If there's actually a file to describe (not just ensuring viewport line clear)
if (gotFileInfo)
{
- lcd.print(" ");
+ lcd.printf(" ");
if (oFileInfo.isDirectory)
{
- lcd.print("./");
+ lcd.printf("./");
}
- lcd.print(oFileInfo.fileName.c_str());
+ lcd.printf("%s", oFileInfo.fileName.c_str());
lcd.ClearToMargin();
if (highlight && m_uListingSelectedIndex == line + m_uListingFirstVisibleIndex)
{
lcd.SetCursor(row + (lcd.GetFontHeight() * line), column);
- lcd.print(">");
+ lcd.write('>');
}
}
else