greiman / SSD1306Ascii

Text only Arduino Library for SSD1306 OLED displays
MIT License
504 stars 121 forks source link

Inverse lines and underlining #28

Closed DragonSifu closed 6 years ago

DragonSifu commented 6 years ago

Doing underlining and inverting is quite easy:

  1. add 2 variables to the class: uint8_t m_underline; // Underline flag. uint8_t m_inverse; // Inverse flag.

  2. add 2 set methods: /**

    • @brief Set the flag for underlining. */ void setU(uint8_t flag) {m_underline = flag;} /**
    • @brief Set the flag for inverse display */ void setI(uint8_t flag) {m_inverse = flag;}
  3. change the init method (add 2 lines): m_underline=0; m_inverse=0;

  4. change the write method: ssd1306WriteRamBuf((b); to ssd1306WriteRamBuf((b|m_underline)^m_inverse); and ssd1306WriteRamBuf(0); to ssd1306WriteRamBuf(m_underline^m_inverse);

Usage: underline:

      oled.clear();
      oled.setU(128);
      oled.print("MENU");
      oled.setU(0);

inverse (a little bit more tricky, because you have to underline the previous line completely and pad both prev. line and current line with blanks (to avoid missing inverted dots):

      if(line==invertedLine)
      {
            oled.setU(128);
            oled.setI(127);
            oled.print(' ');
            uint8_t ml=strlen(Strings[line);
            strcpy((char*)gbuf,Strings[line]);
            if(ml<16)
            {
                for (size_t s = ml ;s < 16; s++) {
                    gbuf[s]=' ';
                }
                gbuf[16]=0;
            }
            oled.print((char *)gbuf);
          }
         if(line== invertedLine-1)
     {
        oled.setU(128);
        uint8_t ml=strlen(Strings[line]);
        strcpy((char*)gbuf,Strings[line]);
        if(ml<16)
        {
            for (size_t s = ml ;s < 16; s++) {
                gbuf[s]=' ';
            }
            gbuf[16]=0;
        }
        oled.print((char *)gbuf);
     }
 //        normal display:          
                       oled.setU(0);
            oled.setI(0);

I think, the code should be integrated.

greiman commented 6 years ago

I am not adding features since I want to minimize the size of this library. There are oled libraries with many features.

Also your mod won't work for large fonts.