#ifndef LIBOCELLI_SCREEN_INFO_HPP
#define LIBOCELLI_SCREEN_INFO_HPP
//----------------------------------------------------------------------------
///
/// \brief   Navigation screen
///
///
///
/// \date   20220905
/// \author Maximilian Seesslen <mes@seesslen.net>
///
//----------------------------------------------------------------------------


//---Includes-----------------------------------------------------------------


//---Own------------------------------

#include <ctype.h>     // strupr

#include <ocelli/screen.hpp>
#include <ocelli/button.hpp>
#include <biwak/gdisplay.h>
#include "git_version.h"
#include <hwinfo/hwinfo.h>


//---Declaration--------------------------------------------------------------


struct SVersion{
   const char *name;
   const char *version;
};

SVersion version[]{
   {.name="CANDIS",      .version=GIT_SHORT },
   {.name="ARENA",    .version=GIT_SHORT_libarena },
   {.name="BIWAK",    .version=GIT_SHORT_libbiwak },
   {.name="LEPTO",    .version=GIT_SHORT_liblepto },
#if defined( STM32 )
   {.name="MINUTNIK", .version=GIT_SHORT_libminutnik },
#endif
   {.name="OCELLI",   .version=GIT_SHORT_libocelli },
   //{.name="LIBSTM",      .version=GIT_SHORT_libstm },
   {.name="FOSH",   .version=GIT_SHORT_libfosh },
   {.name="TH-NOTO",   .version=GIT_SHORT_theme_noto },
};

#define STRINGIFICATE_HELP(exp) "" #exp ""
#define STRINGIFICATE(exp) STRINGIFICATE_HELP(exp)

#if ! defined(STM32)
//#define     MCU_REV_LONG        "-"
char *strupr( char *buf )
{
    char *org=buf;
    while(*buf)
    {
        *buf=toupper(*buf);
        buf++;
    }
    return(org);
}
#endif
class CScreenInfo: public OScreen
{
   private:
      const SEepromBoardInfo &m_info;

   public:
      CScreenInfo( const SEepromBoardInfo &info )
         :m_info(info)
      {
      }
      virtual void draw() override
      {
         OWidget::display().setFg( green );
         OWidget::display().setFont( getFont11() );
         //OWidget::display().setFont( getFont8() );
         OWidget::display().drawBar(0,0,239,319, black, black);
         OWidget::display().setBg( black );
         OWidget::display().setDrawBackground(true);
         int row=0;
         int border=4;
         int lineDist=OWidget::display().fontBaseYSize()+5; // 19;
         int x2=120;
         int x3=120;
         int x1=0;
         char buf[0x10];

         OWidget::display().drawText(border+x1,border+(row * lineDist), "SERIAL" );
         snprintf(buf, sizeof(buf), "%ld", (long int)m_info.production.serialNumber);
         OWidget::display().drawText(border+x3,border+(row * lineDist), buf );
         row++;

         OWidget::display().drawText(border+x1,border+(row * lineDist), "ART-ID" );
         snprintf(buf, sizeof(buf), "0x%X", m_info.main.articleId);
         OWidget::display().drawText(border+x3,border+(row * lineDist), buf );
         row++;

         OWidget::display().drawText(border+x1,border+(row * lineDist), "PR-DATE" );
         snprintf(buf, sizeof(buf), "%d.%d.%d", m_info.production.dateDay
                  , m_info.production.dateMonth, m_info.production.dateYear);
         OWidget::display().drawText(border+x3,border+(row * lineDist), buf );
         row++;

         OWidget::display().drawText(border+x1,border+(row * lineDist), "MCU-PF" );
         OWidget::display().drawText(border+x3,border+(row * lineDist), "STM32" );
         row++;

         OWidget::display().drawText(border+x1,border+(row * lineDist), "MCU-REV" );
         snprintf(buf, sizeof(buf), "%s", STRINGIFICATE( MCU_REV_LONG ) );
         OWidget::display().drawText(border+x3,border+(row * lineDist), strupr( buf ) );
         row++;

         row++;
         for(int i1=0; i1<arraySize(version); i1++)
         {
            OWidget::display().drawText(border+x1,border+(row * lineDist), version[i1].name );
            OWidget::display().drawText(border+x2,border+(row * lineDist), version[i1].version );
            row++;
         }

         OScreen::draw();
      }
};


//---fin----------------------------------------------------------------------
#endif // ? ! LIBOCELLI_SCREEN_INFO_HPP
