From cad00d6a3fde85c88445201949c2ea78cb61041b Mon Sep 17 00:00:00 2001 From: Ian Winter Date: Wed, 20 Dec 2023 21:07:18 +0000 Subject: [PATCH] Added option to rotate display to web interface. --- README.md | 1 + firmware/lib/cw-commons/CWPreferences.h | 5 ++++- firmware/lib/cw-commons/CWWebServer.h | 3 +++ firmware/lib/cw-commons/SettingsWebPage.h | 8 ++++++++ firmware/src/main.cpp | 5 +++-- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 06d0f55..496c8a1 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ https://github.com/jnthas/clockwise/wiki/Connecting-the-LDR) about that. - *NTP Server*: Configure your prefered NTP Server. You can use one of the [NTP Pool Project](https://www.ntppool.org/) pools or a local one. Default is `time.google.com`. - *LDR Pin*: The ESP32 GPIO pin where the LDR is connected to. The default is 35. There is a link there where you can read the current value of LDR and test if it's working. - *Posix Timezone String*: To avoid remote lookups of ezTime, provide a Posix string that corresponds to your timezone ([explanation](https://github.com/ropg/ezTime#timezones-1)). Leave empty to obtain this automatically from the server. +- *Display Rotation*: Allows you to rotate the display. This is useful if you need to adjust the direction in which cables protrude relative to the displayed image. ## How to change the clockface (PlatformIO) diff --git a/firmware/lib/cw-commons/CWPreferences.h b/firmware/lib/cw-commons/CWPreferences.h index 9077852..6a464ff 100644 --- a/firmware/lib/cw-commons/CWPreferences.h +++ b/firmware/lib/cw-commons/CWPreferences.h @@ -24,7 +24,7 @@ struct ClockwiseParams const char* const PREF_CANVAS_FILE = "canvasFile"; const char* const PREF_CANVAS_SERVER = "canvasServer"; const char* const PREF_MANUAL_POSIX = "manualPosix"; - + const char* const PREF_DISPLAY_ROTATION = "displayRotation"; bool swapBlueGreen; bool use24hFormat; @@ -39,6 +39,7 @@ struct ClockwiseParams String canvasFile; String canvasServer; String manualPosix; + uint8_t displayRotation; ClockwiseParams() { @@ -67,6 +68,7 @@ struct ClockwiseParams preferences.putString(PREF_CANVAS_FILE, canvasFile); preferences.putString(PREF_CANVAS_SERVER, canvasServer); preferences.putString(PREF_MANUAL_POSIX, manualPosix); + preferences.putUInt(PREF_DISPLAY_ROTATION, displayRotation); } void load() @@ -84,6 +86,7 @@ struct ClockwiseParams canvasFile = preferences.getString(PREF_CANVAS_FILE, ""); canvasServer = preferences.getString(PREF_CANVAS_SERVER, "raw.githubusercontent.com"); manualPosix = preferences.getString(PREF_MANUAL_POSIX, ""); + displayRotation = preferences.getUInt(PREF_DISPLAY_ROTATION, 0); } }; diff --git a/firmware/lib/cw-commons/CWWebServer.h b/firmware/lib/cw-commons/CWWebServer.h index 12590c6..8eebdee 100644 --- a/firmware/lib/cw-commons/CWWebServer.h +++ b/firmware/lib/cw-commons/CWWebServer.h @@ -125,6 +125,8 @@ struct ClockwiseWebServer ClockwiseParams::getInstance()->canvasServer = value; } else if (key == ClockwiseParams::getInstance()->PREF_MANUAL_POSIX) { ClockwiseParams::getInstance()->manualPosix = value; + } else if (key == ClockwiseParams::getInstance()->PREF_DISPLAY_ROTATION) { + ClockwiseParams::getInstance()->displayRotation = value.toInt(); } ClockwiseParams::getInstance()->save(); client.println("HTTP/1.0 204 No Content"); @@ -160,6 +162,7 @@ struct ClockwiseWebServer client.printf(HEADER_TEMPLATE_S, ClockwiseParams::getInstance()->PREF_CANVAS_FILE, ClockwiseParams::getInstance()->canvasFile.c_str()); client.printf(HEADER_TEMPLATE_S, ClockwiseParams::getInstance()->PREF_CANVAS_SERVER, ClockwiseParams::getInstance()->canvasServer.c_str()); client.printf(HEADER_TEMPLATE_S, ClockwiseParams::getInstance()->PREF_MANUAL_POSIX, ClockwiseParams::getInstance()->manualPosix.c_str()); + client.printf(HEADER_TEMPLATE_D, ClockwiseParams::getInstance()->PREF_DISPLAY_ROTATION, ClockwiseParams::getInstance()->displayRotation); client.printf(HEADER_TEMPLATE_S, "CW_FW_VERSION", CW_FW_VERSION); client.printf(HEADER_TEMPLATE_S, "CW_FW_NAME", CW_FW_NAME); diff --git a/firmware/lib/cw-commons/SettingsWebPage.h b/firmware/lib/cw-commons/SettingsWebPage.h index 7bd6272..7a42c3f 100644 --- a/firmware/lib/cw-commons/SettingsWebPage.h +++ b/firmware/lib/cw-commons/SettingsWebPage.h @@ -135,6 +135,14 @@ const char SETTINGS_PAGE[] PROGMEM = R""""( icon: "fa-globe", save: "updatePreference('manualPosix', posixString.value)", property: "manualPosix" + }, + { + title: "Rotation", + description: "Rotation of the matrix display.", + formInput: "", + icon: "fa-rotate-right", + save: "updatePreference('displayRotation', rotation.value)", + property: "displayRotation" } ]; diff --git a/firmware/src/main.cpp b/firmware/src/main.cpp index a5b4f74..8a3365b 100644 --- a/firmware/src/main.cpp +++ b/firmware/src/main.cpp @@ -25,7 +25,7 @@ CWDateTime cwDateTime; bool autoBrightEnabled; long autoBrightMillis = 0; -void displaySetup(bool swapBlueGreen, uint8_t displayBright) +void displaySetup(bool swapBlueGreen, uint8_t displayBright, uint8_t displayRotation) { HUB75_I2S_CFG mxconfig(64, 64, 1); @@ -46,6 +46,7 @@ void displaySetup(bool swapBlueGreen, uint8_t displayBright) dma_display->begin(); dma_display->setBrightness8(displayBright); dma_display->clearScreen(); + dma_display->setRotation(displayRotation); } void automaticBrightControl() @@ -84,7 +85,7 @@ void setup() pinMode(ClockwiseParams::getInstance()->ldrPin, INPUT); - displaySetup(ClockwiseParams::getInstance()->swapBlueGreen, ClockwiseParams::getInstance()->displayBright); + displaySetup(ClockwiseParams::getInstance()->swapBlueGreen, ClockwiseParams::getInstance()->displayBright, ClockwiseParams::getInstance()->displayRotation); clockface = new Clockface(dma_display); autoBrightEnabled = (ClockwiseParams::getInstance()->autoBrightMax > 0);