From de5023fb43ee69e7d37c518400d89a42a5cfcda9 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Mon, 11 Feb 2019 16:53:46 +0100 Subject: [PATCH] Fix LCD center text Fix LCD center text (#5195) --- sonoff/xdsp_01_lcd.ino | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sonoff/xdsp_01_lcd.ino b/sonoff/xdsp_01_lcd.ino index 190c8732b..e0b72618f 100644 --- a/sonoff/xdsp_01_lcd.ino +++ b/sonoff/xdsp_01_lcd.ino @@ -99,15 +99,20 @@ void LcdDisplayOnOff(uint8_t on) void LcdCenter(uint8_t row, char* txt) { - int offset; - int len; char line[Settings.display_cols[0] +2]; + int len = strlen(txt); + int offset = 0; + if (len >= Settings.display_cols[0]) { + len = Settings.display_cols[0] + } else { + offset = (Settings.display_cols[0] - len) / 2; + } memset(line, 0x20, Settings.display_cols[0]); line[Settings.display_cols[0]] = 0; - len = strlen(txt); - offset = (len < Settings.display_cols[0]) ? offset = (Settings.display_cols[0] - len) / 2 : 0; - strlcpy(line +offset, txt, len +1); + for (uint8_t i = 0; i < len; i++) { + line[offset +i] = txt[i]; + } lcd->setCursor(0, row); lcd->print(line); }