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

Max length of a column/line? #64

Open
picontrolit opened this issue Sep 10, 2019 · 6 comments
Open

Max length of a column/line? #64

picontrolit opened this issue Sep 10, 2019 · 6 comments

Comments

@picontrolit
Copy link

Is it possible to automatically CR/LF if a certain line length is reached?
Cheers, Alex

@greiman
Copy link
Owner

greiman commented Sep 10, 2019

No.

I don't think doing an auto CR/LF is very useful since it would split words/numbers.

I can't solve the word wrap problem since print gives me no look ahead. I get one character at a time with write calls.

@picontrolit
Copy link
Author

For me it would not matter if words or numbers are "split". I am simulating and old school 8bit homecomputer. A simple program like "10 PRINT "ALEX ";:GOTO 10 at the moment writes to a single line. It should rather behave like on a C64 when it reaches col 40 jumping to the next line (col 1).
Any idea how to achieve that with your lib would be welcome.

@greiman
Copy link
Owner

greiman commented Sep 11, 2019

The best place to insert a CR/LF would be in the calling routine in your simulator.

write(char c) processes one character at a time so it is not easy to insert a CR/LF at this level.

@greiman
Copy link
Owner

greiman commented Sep 11, 2019

Here is an example with an auto CR/LF class. It is not well debugged and you may want to modify the functionality.

#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"

// 0X3C+SA0 - 0x3C or 0x3D
#define I2C_ADDRESS 0x3C

// Define proper RST_PIN if required.
#define RST_PIN -1

SSD1306AsciiWire oled;
//----------------------------------------------------------------------
// auto CR/LF class
class AutoCRLF : public Print {
  public:
  size_t write(uint8_t c) {
    size_t rtn = 0;
    if (c == '\n' || c == '\r') {
      col = 0;
      return oled.write(c);
    }  
   //  18, choose value for your font and display. try 20 for 128 pixel display
    if (col > 18) {
      // acts as CR/LF
      oled.write('\n');
      col = 0;
      rtn = 1;
    }
    col++;
    return rtn + oled.write(c);
  }
  uint8_t col = 0;
};
AutoCRLF oledAuto;
//------------------------------------------------------------------------------
void setup() {
  Wire.begin();
  Wire.setClock(400000L);

#if RST_PIN >= 0
  oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
  oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0
  oled.setFont(Adafruit5x7);
  oled.clear();
  oled.setScrollMode(SCROLL_MODE_AUTO);
}

void loop() {
  oledAuto.print("ABC");
  delay(200);
} 

@b1n0-kun
Copy link

Dear greiman.
I've just tested your oledAuto class (a very simple long line) and it worked like a charm.
Can you show me how to put that oledAuto snippet into library file (not so prefer to define same class in every project tho)
Thank you !

@greiman
Copy link
Owner

greiman commented Dec 18, 2023

Look at this tutorial.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants