peterhinch / micropython-samples

Assorted code ideas, unofficial MP FAQ, plus index to my other repositories.
MIT License
459 stars 92 forks source link

Flip Screen of SSD1306 #3

Closed ppontre closed 6 years ago

ppontre commented 6 years ago

Hi Peter, I can't sort out how to flip screen on Micropython ESP32 using the library. I've got a TTGO board with ESP, Battery, SSD1306. I need to flip the screen upside down Any suggestion ? Thanx in advance Paolo

peterhinch commented 6 years ago

Hi Paolo, it can be done but it would be a substantial rewrite. I can't see a simple way to fix _printchar() but a rewritten _printchar_bitwise() function could invert each character. The _newline() method would need adapting so that text flow was reversed. Pete

ppontre commented 6 years ago

Thanx Pteter for yr prompt answer. Here’s my update:

  1. There’s some trick, consisting in 2 commands: flip (vert) and mirro (horiz) the entire display.

After these commands, no other change is required.

Unfortunately i could not succeed in finding and issuing the command

  1. It seems there’s a trade-off between beautiful fonts and flip feature: yuou can’t have both.

I succeeded in flipping a display arranged with a 8x8 font, no auto-cr, all-manual….

  1. This evening i’ll have another trial Regairds Paolo

Inviato da Postahttps://go.microsoft.com/fwlink/?LinkId=550986 per Windows 10

Da: Peter Hinchmailto:notifications@github.com Inviato: giovedì 15 febbraio 2018 08:06 A: peterhinch/micropython-samplesmailto:micropython-samples@noreply.github.com Cc: ppontremailto:ppontre@hotmail.com; Authormailto:author@noreply.github.com Oggetto: Re: [peterhinch/micropython-samples] Flip Screen of SSD1306 (#3)

Hi Paolo, it can be done but it would be a substantial rewrite. I can't see a simple way to fix _printchar() but a rewritten _printchar_bitwise() function could invert each character. The _newline() method would need adapting so that text flow was reversed. Pete

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/peterhinch/micropython-samples/issues/3#issuecomment-365842248, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AADUzOBvJCBgIrJJjC6hD547g9l1-ns3ks5tU9dkgaJpZM4SF8oo.

robhamerling commented 6 years ago

@Paolo

I succeeded in flipping a display arranged with a 8x8 font, no auto-cr, all-manual…. 1. This evening i’ll have another trial

Hi Paolo, would you be so kind to publish your fix? Besides an SSD1306 I'm also using an SH1106 for which the driver has a rotate method builtin, which serves my needs. I would like a similar solution for a SSD1306 display just as your described here. Regards, Rob.

peterhinch commented 6 years ago

@ppontre @robhamerling You may like to look at this update: the CWriter class supports upside down display on any device whose driver is subclassed from frmebuf (e.g. SSD1306).

robhamerling commented 6 years ago

@peterhinch Thanks for this pointer, looks very nice. However currently I'm satisfied with the fixed 8x8 font and needed only flipping. Maybe useful for a new project. BTW: In the meantime I found how to perform flipping by modifying a few bits in ssd1306 registers. I opened an issue (#4015) at github.com/micropython and suggested a solution.

peterhinch commented 6 years ago

My update aims for generality by supporting any display whose driver is subclassed from framebuf.

Alas inverting the display means using the CWriter class. This is over an order of magnitude slower than Writer as it renders glyphs one pixel at a time rather than via bit blitting.

Your SSD1306-specific method evidently won't carry that speed penalty. It also has the advantage that the same coordinates apply to graphics and text, whereas mine only flips text.