// DO NOT USE THIS ONE!


//#include "Arduino.h"
#include <Wire.h>
#include "SSD1306Ascii.h"
#include "SSD1306AsciiWire.h"
#include "Universal_terminal.h"

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

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

const char* fontName[] = {
  "Arial10",
  "Arial_bold_14",
  "Callibri11",
  "Callibri11_bold",
  "Callibri11_italic",
  "Callibri13",
  "Corsiva_12",
  "fixed_bold10x15",
  "font5x7",
  "font8x8",
  "Iain5x7",
  "lcd5x7",
  "Stang5x7",
  "System5x7",
  "TimesNewRoman16",
  "TimesNewRoman16_bold",
  "TimesNewRoman16_italic",
  "utf8font10x16",
  "Verdana12",
  "Verdana12_bold",
  "Verdana12_italic",
  "X11fixed7x14",
  "X11fixed7x14B",
  "ZevvPeep8x16"
};
const uint8_t* fontList[] = {
  Arial14,
  Arial_bold_14,
  Callibri11,
  Callibri11_bold,
  Callibri11_italic,
  Callibri15,
  Corsiva_12,
  fixed_bold10x15,
  font5x7,
  font8x8,
  Iain5x7,
  lcd5x7,
  Stang5x7,
  System5x7,
  TimesNewRoman16,
  TimesNewRoman16_bold,
  TimesNewRoman16_italic,
  utf8font10x16,
  Verdana12,
  Verdana12_bold,
  Verdana12_italic,
  X11fixed7x14,
  X11fixed7x14B,
  ZevvPeep8x16
};
uint8_t nFont = sizeof(fontList) / sizeof(uint8_t*);

SSD1306AsciiWire oled;

Universal_terminal ut;

//----------------------------------------------------------------------
// 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 callbackPrint(const char str, unsigned char, unsigned char){
  //oled.print(buffer);
}

//------------------------------------------------------------------------------
void setup() {
  Wire.begin();
  Wire.setClock(400000L);
  Serial.begin(115200); // Any baud rate should work

  ut.begin(callbackPrint);

#if RST_PIN >= 0
  oled.begin(&Adafruit128x64, I2C_ADDRESS, RST_PIN);
#else // RST_PIN >= 0
  oled.begin(&Adafruit128x64, I2C_ADDRESS);
#endif // RST_PIN >= 0

  /*
    for (uint8_t i = 0; i < nFont; i++) {
      oled.setFont(System5x7);
      oled.clear();
      oled.println(fontName[i]);
      oled.println();
      oled.setFont(fontList[i]);
      oled.println(" mob 7020336035:");
      oled.println(" arduino chacha ");
      oled.println("ARVIND PATIL  ");
      delay(3000);
    }
    oled.clear();
    oled.print("Done!");
  */

oled.setFont(font8x8);
oled.setScrollMode(SCROLL_MODE_AUTO);
/*
char buffer[40];
int freq = 123456;
float freqkHz = freq / 1000.0;
sprintf(buffer, "%.2f kHz", freqkHz);
oled.print(buffer);
*/
}


void loop() {
  oledAuto.print("123");
  //ut.print("123");
  delay(100);
}