rk3399_arm_lvds/display/LCDDisplay.cpp

189 lines
7.1 KiB
C++
Raw Normal View History

2024-03-05 03:46:18 +00:00
#include "LCDDisplay.h"
#include "Lcd.h"
#include <StopWatch.h>
#include <iostream>
#include <thread>
#include "stringex.hpp"
#include <algorithm>
using namespace std;
LCDDisplay::LCDDisplay(int language)
{
if(language >=0 && language < 3)
m_language = (LCDDisplay::Language)language;
else
m_language = LCDDisplay::Language::Chinese;
lcd.reset(new Lcd());
lcd->Lcd_Initial_Lcd(false);
map_Display = {map_Display_CN,map_Display_TC,map_Display_EN};
// lcd->Lcd_Clear_screen();
// lcd->Lcd_Display_Graphic_16x16(map_Display[DisType::Dis_Init].page, map_Display[DisType::Dis_Init].col, map_Display[DisType::Dis_Init].str.data(),map_Display[DisType::Dis_Init].str.size()/32);
}
LCDDisplay::~LCDDisplay()
{
lcd->Lcd_Clear_screen();
lcd.reset();
}
void LCDDisplay::DisplayState(DisType ds, unsigned int pagenum,ClearScreen clearscree)
{
if(clearscree == ClearScreen::All)
lcd->Lcd_Clear_screen();
if(clearscree == ClearScreen::TOP)
lcd->Lcd_Clear_Half_Screen(true);
if(clearscree == ClearScreen::BOT)
lcd->Lcd_Clear_Half_Screen(false);
if (map_Display[m_language_map[m_language]].count(ds) > 0)
{
m_status = ds;
StopWatch sw;
auto dsinfo = map_Display[m_language_map[m_language]][ds];
if (ds == DisType::Dis_Welcome)//show logo
{
lcd->Lcd_Display_Graphic_128x64(dsinfo.page, dsinfo.col, dsinfo.str.data());
}
else if(ds == DisType::Dis_Language_Chinese || ds == DisType::Dis_Language_Chinese_Traditional)
{
lcd->Lcd_Display_Graphic_16x16(dsinfo.page, dsinfo.col, dsinfo.str.data(), dsinfo.str.size() / 32);
}
else if(ds == DisType::Dis_Language_English)
lcd->Lcd_Display_String_8x16(dsinfo.page, dsinfo.col, (const char*)dsinfo.str.data());
else
{
if(m_language == Language::English)
lcd->Lcd_Display_String_8x16(dsinfo.page, dsinfo.col, (const char*)dsinfo.str.data());
else
lcd->Lcd_Display_Graphic_16x16(dsinfo.page, dsinfo.col, dsinfo.str.data(), dsinfo.str.size() / 32);
//lcd->Lcd_Display_String_8x16(dsinfo.page, dsinfo.col, (const char*)dsinfo.str.data());
//if (ds == DisType::Dis_Scan || ds == DisType::Dis_Set_Count) //扫描或者计数 更新下半部分内容
//{
//lcd->Lcd_Clear_Half_Screen(false);
//lcd->Lcd_Display_String_8x16(3, 96, "0");
//lcd->Lcd_Display_Graphic_16x16(map_Display[DisType::Dis_Scan_Page].page, map_Display[DisType::Dis_Scan_Page].col, map_Display[DisType::Dis_Scan_Page].str.data(), map_Display[DisType::Dis_Scan_Page].str.size() / 32);
//}
}
switch (ds)
{
case DisType::Dis_Count_Page:
case DisType::Dis_Scan_Page:
{
//std::string val = std::to_string(pagenum);
//auto offsetdot = bitnum(pagenum) - 1;
std::string val = string_format("%04d",pagenum);
int offsetdot = val.length();
//printf("\n val = %s lenght = %d",val.c_str(),val.size());
lcd->Lcd_Display_String_8x16(3, 112 - offsetdot * 8, val.c_str()); //8 -> 一个数字所占点个数宽度
lcd->Lcd_Display_Graphic_16x16(map_Display[m_language_map[m_language]][DisType::Dis_Scan_Page].page, map_Display[m_language_map[m_language]][DisType::Dis_Scan_Page].col,
map_Display[m_language_map[m_language]][DisType::Dis_Scan_Page].str.data(), map_Display[m_language_map[m_language]][DisType::Dis_Scan_Page].str.size() / 32);
break;
}
case DisType::Dis_Err_JamIn:
{
if(pagenum == 1)
lcd->Lcd_Display_String_8x16(3, 56, "P a 1 0 1"); //8 -> 一个数字所占点个数宽度
else if(pagenum == 2)
lcd->Lcd_Display_String_8x16(3, 56, "P a 1 0 2");
else if(pagenum == 3)
lcd->Lcd_Display_String_8x16(3, 56, "P a 1 0 3");
break;
}
case DisType::Dis_Err_AqrImgTimeout:
lcd->Lcd_Display_String_8x16(3, 56, "G p 0 0 1");
break;
case DisType::Dis_Err_CoverOpen:
lcd->Lcd_Display_String_8x16(3, 56, "C o 0 0 1");
break;
case DisType::Dis_Err_PaperScrew:
lcd->Lcd_Display_String_8x16(3, 56, "S K 0 0 1");
break;
case DisType::Dis_Err_DoubleFeed:
lcd->Lcd_Display_String_8x16(3, 56, "D b 0 0 1");
break;
case DisType::Dis_Err_NoPaper:
lcd->Lcd_Display_String_8x16(3, 56, "N o 0 0 1");
break;
case DisType::Dis_Err_Stable:
lcd->Lcd_Display_String_8x16(3, 56, "S T 0 0 1");
break;
case DisType::Dis_Err_FeedError:
lcd->Lcd_Display_String_8x16(3, 56, "P f 0 0 1");
break;
case DisType::Dis_Err_DogEar:
lcd->Lcd_Display_String_8x16(3, 56, "Z J 0 0 1");
break;
case DisType::Dis_Err_Size:
lcd->Lcd_Display_String_8x16(3, 56, "C C 0 0 1");
break;
case DisType::Dis_Set_Get_History_ScanNum:
{
std::string val = std::to_string(pagenum);
int offsetdot = 8 > val.length() ? val.length() : 8;
lcd->Lcd_Display_String_8x16(3, 128 - offsetdot * 8, val.c_str()); //8 -> 一个数字所占点个数宽度
break;
}
case DisType::Dis_Set_Get_Roller_ScanNum:
{
std::string val = std::to_string(pagenum);
int offsetdot = 8 > val.length() ? val.length() : 8;
lcd->Lcd_Display_String_8x16(3, 128 - offsetdot * 8, val.c_str()); //8 -> 一个数字所占点个数宽度
break;
}
default:
break;
}
}
else
{
switch (ds){
case DisType::Dis_Set_SleepMode_5M:
lcd->Lcd_Display_String_8x16(3, 112, "5M");
break;
case DisType::Dis_Set_SleepMode_10M:
lcd->Lcd_Display_String_8x16(3, 104, "10M");
break;
case DisType::Dis_Set_SleepMode_20M:
lcd->Lcd_Display_String_8x16(3, 104, "20M");
break;
case DisType::Dis_Set_SleepMode_30M:
lcd->Lcd_Display_String_8x16(3, 104, "30M");
break;
case DisType::Dis_Set_SleepMode_1H:
lcd->Lcd_Display_String_8x16(3, 112, "1H");
break;
case DisType::Dis_Set_SleepMode_2H:
lcd->Lcd_Display_String_8x16(3, 112, "2H");
break;
case DisType::Dis_Set_SleepMode_4H:
lcd->Lcd_Display_String_8x16(3, 112, "4H");
break;
default:
m_status= DisType::Dis_Unkown;
break;
}
}
}
int LCDDisplay::bitnum(unsigned int num)
{
int count = 0;
do
{
num = num / 10;
count++;
} while (num > 0);
return count;
}
DisType LCDDisplay::GetCurrentStatus() const
{
return m_status;
}
void LCDDisplay::set_language(Language language)
{
if(language != m_language)
m_language = language;
}