Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to rotate display to web interface. #58

Merged
merged 1 commit into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion firmware/lib/cw-commons/CWPreferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,6 +39,7 @@ struct ClockwiseParams
String canvasFile;
String canvasServer;
String manualPosix;
uint8_t displayRotation;


ClockwiseParams() {
Expand Down Expand Up @@ -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()
Expand All @@ -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);
}

};
3 changes: 3 additions & 0 deletions firmware/lib/cw-commons/CWWebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions firmware/lib/cw-commons/SettingsWebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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: "<select name='rotation' id='rotation'><option value='0'" + (settings.displayrotation == 0 ? " selected='selected'" : "") + ">0</option><option value='1'" + (settings.displayrotation == 1 ? " selected='selected'" : "") + ">90</option><option value='2'" + (settings.displayrotation == 2 ? " selected='selected'" : "") + ">180</option><option value='3'" + (settings.displayrotation == 3 ? " selected='selected'" : "") + ">270</option></select>",
icon: "fa-rotate-right",
save: "updatePreference('displayRotation', rotation.value)",
property: "displayRotation"
}
];

Expand Down
5 changes: 3 additions & 2 deletions firmware/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand Down