#include <biwak/eadisplay_spi.h>
#include <biwak/linux/boardgui.h>
#include "ui_boardgui.h"
#include <QString>


#define LINES  3
QString qLines[LINES];


CEaDisplay::CEaDisplay( EEaDisplayType _eEaDisplayType,
            CSpi &_spi, EGpioPeripheral eGpioPeripheralCS, EGpioPin eGpioPinCS
                      , EGpioPeripheral eGpioPeripheralRS, EGpioPin eGpioPinRS
            )
   :eEaDisplayType(_eEaDisplayType)
   ,spi(_spi)
   ,outputCS(eGpioPeripheralCS, eGpioPinCS)
   ,outputRS(eGpioPeripheralRS, eGpioPinRS)
{
   return;
}

void CEaDisplay::putString(const char *text)
{
   //if(&qtp)
   //      qtp.display(string);
               //ui->textBrowser->print();
   qLines[yPos].truncate(xPos);
   qLines[yPos].insert(xPos, text);
   xPos+=strlen(text);

   qpf.getUi()->textBrowser->clear();

   for(int i1=0;i1<LINES; i1++)
   {
      qpf.getUi()->textBrowser->insertPlainText( qLines[i1] );
      if(i1!=LINES-1)
         qpf.getUi()->textBrowser->insertPlainText( "\n" );
   }
   return;
}

void CEaDisplay::gotoxy(int x, int y)
{
   xPos=x;
   yPos=y;
   //qtp.getUi()->textBrowser->textCursor().setPos(x, y);
   //QTextBrowser
   //qtp.getUi()->textBrowser->home();
   //qtp.getUi()->plainTextEdit->anchorAt(QPoint(x,y));
   //QPlainTextEdit
   //qpf.getUi()->plainTextEdit->clear();
         //textCursor().movePosition(
         //   QTextCursor::Start, QTextCursor::MoveAnchor, 1);

   return;
}


void CEaDisplay::clear()
{
   qpf.getUi()->textBrowser->clear();
   for(int i1=0;i1<LINES; i1++)
      qLines[i1].clear();

   return;
}


//---fin----------------------------------------------------------------------
