一、打开touchgfx designer ,加上提按键0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,<<,>>,%,*,/,clear,=按键。
如下:
二、加上每个按键的虚函数。如下是0按键的,其他类似。
三、增加textArea1,textArea3,textArea3。分别加入wildcard1 并且勾选使用这个缓冲更新数据。
四、给每个设置字体为Large,40pt
并且在Texts的Typographies里面设置wildcard Ranges 0~f
五、Screep1view.hpp中加入头文件:
#ifndef SCREEN1VIEW_HPP
#define SCREEN1VIEW_HPP
#include <gui_generated/screen1_screen/Screen1ViewBase.hpp>
#include <gui/screen1_screen/Screen1Presenter.hpp>
class Screen1View : public Screen1ViewBase
{
public:
Screen1View();
virtual ~Screen1View() {}
virtual void setupScreen();
virtual void tearDownScreen();
virtual void function_bt0();
virtual void function_bt1();
virtual void function_bt2();
virtual void function_bt3();
virtual void function_bt4();
virtual void function_bt5();
virtual void function_bt6();
virtual void function_bt7();
virtual void function_bt8();
virtual void function_bt9();
virtual void function_bta();
virtual void function_btb();
virtual void function_btc();
virtual void function_btd();
virtual void function_bte();
virtual void function_btf();
virtual void function_bt_eq();
virtual void function_bt_right();
virtual void function_bt_left();
virtual void function_bt_mul();
virtual void function_bt_els();
virtual void function_bt_div();
virtual void function_bt_clr();
void updateGFXElements(uint8_t bt_val);
protected:
uint32_t dat_a;
uint32_t dat_b;
uint32_t dat_c;
uint8_t point;
char oldchar;
};
#endif // SCREEN1VIEW_HPP
六、Screep1view.cpp中加入虚函数和更新按键函数的具体实现如下:
#include <gui/screen1_screen/Screen1View.hpp>
Screen1View::Screen1View()
{
}
void Screen1View::setupScreen()
{
Screen1ViewBase::setupScreen();
}
void Screen1View::tearDownScreen()
{
Screen1ViewBase::tearDownScreen();
}
void Screen1View::function_bt0()
{
updateGFXElements(0);
}
void Screen1View::function_bt1()
{
updateGFXElements(1);
}
void Screen1View::function_bt2()
{
updateGFXElements(2);
}
void Screen1View::function_bt3()
{
updateGFXElements(3);
}
void Screen1View::function_bt4()
{
updateGFXElements(4);
}
void Screen1View::function_bt5()
{
updateGFXElements(5);
}
void Screen1View::function_bt6()
{
updateGFXElements(6);
}
void Screen1View::function_bt7()
{
updateGFXElements(7);
}
void Screen1View::function_bt8()
{
updateGFXElements(8);
}
void Screen1View::function_bt9()
{
updateGFXElements(9);
}
void Screen1View::function_bta()
{
updateGFXElements(0x0a);
}
void Screen1View::function_btb()
{
updateGFXElements(0x0b);
}
void Screen1View::function_btc()
{
updateGFXElements(0x0c);
}
void Screen1View::function_btd()
{
updateGFXElements(0x0d);
}
void Screen1View::function_bte()
{
updateGFXElements(0x0e);
}
void Screen1View::function_btf()
{
updateGFXElements(0x0f);
}
void Screen1View::function_bt_eq()
{
updateGFXElements(0x20);
}
void Screen1View::function_bt_right()
{
updateGFXElements(0x21);
}
void Screen1View::function_bt_left()
{
updateGFXElements(0x22);
}
void Screen1View::function_bt_els()
{
updateGFXElements(0x23);
}
void Screen1View::function_bt_mul()
{
updateGFXElements(0x24);
}
void Screen1View::function_bt_div()
{
updateGFXElements(0x25);
}
void Screen1View::function_bt_clr()
{
updateGFXElements(0x26);
}
void Screen1View::updateGFXElements(uint8_t bt_val)
{
if( bt_val <= 0x0f)
{
if(point == 0)
{
dat_a <<=4;
dat_a +=bt_val;
}
else
{
dat_b <<=4;
dat_b +=bt_val;
}
}
else
{ switch(bt_val)
{
case 0x20: //=
if(oldchar == 0x21)
dat_c = dat_a >> dat_b;
else
{
if(oldchar == 0x22)
{
dat_c =dat_a << dat_b;
}
else
{
if(oldchar == 0x23)
{
if(dat_b !=0)
dat_c =dat_a%dat_b;
}
else
{
if(oldchar == 0x24)
dat_c =dat_a*dat_b;
else
{
if(oldchar == 0x25)
{
if(dat_b !=0)
dat_c =dat_a/dat_b;
}
else
{
if(oldchar == 0x26)
{
point =0;oldchar =0x0;dat_a=dat_b=dat_c=0;
}
}
}
}
}
}
point =0;oldchar =0;
break;
case 0x21:point =1;oldchar =0x21;break;//>>
case 0x22:point =1;oldchar =0x22;break;//<<
case 0x23:point =1;oldchar =0x23;break;//%
case 0x24:point =1;oldchar =0x24;break;//*
case 0x25:point =1;oldchar =0x25;break;//div
case 0x26:point =0;oldchar =0x0;dat_a=dat_b=dat_c=0;break;//clear
}
}
touchgfx::Unicode::snprintf(textArea1Buffer,TEXTAREA1_SIZE,"%x", dat_a );
textArea1.invalidate();
touchgfx::Unicode::snprintf(textArea2Buffer,TEXTAREA2_SIZE,"%x", dat_b );
textArea2.invalidate();
touchgfx::Unicode::snprintf(textArea3Buffer,TEXTAREA3_SIZE,"%x", dat_c );
textArea3.invalidate();
}