DebugPrinter类是一种在显示屏上打印调试消息的简单方法,无需向屏幕添加控件。
在使用DebugPrinter之前,需要分配一个实例并将其传递给Application类,且DebugPrinter实例必须兼容所使用的LCD类。 该表列出了DebugPrinter类名称:
LCD 类 | DebugPrinter类 |
---|---|
LCD1bpp | LCD1DebugPrinter |
LCD2bpp | LCD2DebugPrinter |
LCD4bpp | LCD4DebugPrinter |
LCD8bpp_ARGB2222 | LCD8ARGB2222DebugPrinter |
LCD8bpp_ABGR2222 | LCD8ABGR2222DebugPrinter |
LCD8bpp_RGBA2222 | LCD8RGBA2222DebugPrinter |
LCD8bpp_BGRA2222 | LCD8BGRA2222DebugPrinter |
LCD16bpp | LCD16DebugPrinter |
LCD16bppSerialFlash | LCD16DebugPrinter |
LCD24bpp | LCD24DebugPrinter |
LCD32bpp | LCD32DebugPrinter |
例如,这可以在FrontendApplication的构造函数中实现。
#include <gui/common/FrontendApplication.hpp>
#include <touchgfx/lcd/LCD16DebugPrinter.hpp>
LCD16DebugPrinter lcd16DebugPrinter;
FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
: FrontendApplicationBase(m, heap)
{
lcd16DebugPrinter.setPosition(0, 0, 240, 40);
lcd16DebugPrinter.setScale(3);
lcd16DebugPrinter.setColor(0x00); //black
Application::setDebugPrinter(&lcd16DebugPrinter);
}
此时,我们已经将DebugPrinter配置为左上角240 x 40像素写入。 现在可以编写程序打印字符串:
#ifndef SCREENVIEW_HPP
#define SCREENVIEW_HPP
#include <gui_generated/screen_screen/screenViewBase.hpp>
#include <gui/screen_screen/screenPresenter.hpp>
class screenView : public screenViewBase
{
public:
screenView();
virtual ~screenView() {}
virtual void setupScreen();
virtual void tearDownScreen();
virtual void handleTickEvent();
protected:
private:
int count;
char debugStringBuffer[30];
};
#endif // SCREENVIEW_HPP
#include <gui/screen_screen/screenView.hpp>
#include <stdio.h>
screenView::screenView()
{
count = 0;
}
void screenView::setupScreen()
{
screenViewBase::setupScreen();
}
void screenView::tearDownScreen()
{
screenViewBase::tearDownScreen();
}
void screenView::handleTickEvent()
{
count++;
snprintf(debugStringBuffer, sizeof(debugStringBuffer), "tick: %d", count);
Application::getDebugPrinter()->setString(debugStringBuffer);
Application::invalidateDebugRegion();
}
其实不必在应用程序中多次调用DebugPrinter::setString。 只需要更改缓存区的内容,但是请调用invalidateDebugRegion,这将使DebugPrinter绘制新内容。