Skip to content

Commit

Permalink
Initial specification for orientation of display.
Browse files Browse the repository at this point in the history
  • Loading branch information
chl33 committed Aug 2, 2024
1 parent 9967051 commit a6fbb33
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# og3x-oled
# og3x-oled

This is simple OLED support for the [og3](https://github.com/chl33/og3) library for ESP projects using the Arduino framework with [Platformio](https://platformio.org/).

Expand Down
7 changes: 6 additions & 1 deletion include/og3/oled.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ class Oled : public Module {
kTenPt = 0,
kSixteenPt = 1,
};
enum class Orientation {
kDefault = 0,
kFlipVertical = 1,
};

Oled(const char* name, ModuleSystem* updater, const char* initial_txt,
FontSize font_size = kSixteenPt);
FontSize font_size = kSixteenPt, Orientation orientation=Orientation::kFlipVertical);

void setup();
void clear();
Expand All @@ -32,6 +36,7 @@ class Oled : public Module {
SSD1306Wire m_display;
#endif
const char* m_initial_txt;
const Orientation m_orientation;
FontSize m_font_size;
int m_start = 0;
bool m_ok = false;
Expand Down
2 changes: 1 addition & 1 deletion include/og3/oled_display_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class OledDisplayRing : public Oled {
static const char* kName;

OledDisplayRing(ModuleSystem* updater, const char* initial_txt, unsigned switch_time_msec,
FontSize font_size = kSixteenPt);
FontSize font_size = kSixteenPt, Orientation orientation=Orientation::kFlipVertical);

// Add the callback which will be called when it is its turn.
using CallbackFn = std::function<void()>;
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "og3x-oled",
"version": "0.1.1",
"version": "0.1.2",
"description": "Add support for SSD1306 OLED to chl33/og3",
"keywords": "esp32, esp8266, oled",
"authors": [
Expand Down
7 changes: 5 additions & 2 deletions src/oled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
namespace og3 {

Oled::Oled(const char* name, ModuleSystem* modules, const char* initial_txt,
Oled::FontSize font_size)
Oled::FontSize font_size, Oled::Orientation orientation)
: Module(name, modules),
#ifndef NATIVE
m_display(0x3c, SDA, SCL, GEOMETRY_128_32),
#endif
m_initial_txt(initial_txt),
m_orientation(orientation),
m_font_size(font_size) {
add_init_fn([this]() { setup(); });
}
Expand All @@ -27,7 +28,9 @@ void Oled::setup() {
}
#ifndef NATIVE
m_display.clear();
m_display.flipScreenVertically();
if (m_orientation == Orientation::kFlipVertical) {
m_display.flipScreenVertically();
}
m_display.setTextAlignment(TEXT_ALIGN_LEFT);
m_display.setFont(ArialMT_Plain_16);
m_display.drawString(0, 0, m_initial_txt);
Expand Down
5 changes: 3 additions & 2 deletions src/oled_display_ring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ namespace og3 {
const char* OledDisplayRing::kName = "oled_ring";

OledDisplayRing::OledDisplayRing(ModuleSystem* modules, const char* initial_txt,
unsigned switch_time_msec, FontSize font_size)
: Oled(kName, modules, initial_txt, font_size),
unsigned switch_time_msec, FontSize font_size,
Orientation orientation)
: Oled(kName, modules, initial_txt, font_size, orientation),
m_switch_time_msec(switch_time_msec),
m_scheduler(
1, m_switch_time_msec, [this]() { timerCallback(); }, nullptr) {
Expand Down

0 comments on commit a6fbb33

Please sign in to comment.