Renders bit-per-pixel text entered on stdin to a simulated display on stdout.
#include <boost/property_tree/info_parser.hpp>
#include <iostream>
#include <assert.h>
#include <boost/exception/diagnostic_information.hpp>
#include <boost/program_options.hpp>
bool quit = false;
int main(int argc, char *argv[])
try {
std::string fontpath, confpath, lcdname;
std::string imgpath(argv[0]);
int dispW, dispH;
bool uselcd = false;
{
int found = 0;
while (!imgpath.empty() && (found < 3)) {
imgpath.pop_back();
if (imgpath.back() == '/') {
++found;
}
}
imgpath += "images/";
}
{
boost::program_options::options_description optdesc(
"Options for bit-per-pxiel text rendering test"
);
optdesc.add_options()
(
"help,h",
"Show this help message"
)
(
"font",
boost::program_options::value<std::string>(&fontpath)->
default_value(imgpath + "font_8x16.bppia"),
"Font file"
)
(
"st7920",
"Use a graphic ST7920 LCD instead of console output"
)
(
"conf,c",
boost::program_options::value<std::string>(&confpath)->
default_value("samples/pins.conf"),
"Pin configuration file; required if ST7920 LCD used"
)
(
"lcdname",
boost::program_options::value<std::string>(&lcdname)->
default_value("lcdGraphic"),
"Name of LCD inside pin configuration"
)
(
"width,x",
boost::program_options::value<int>(&dispW)->
default_value(144),
"ST7920 display width in pixels"
)
(
"height,y",
boost::program_options::value<int>(&dispH)->
default_value(32),
"ST7920 display height in pixels"
)
;
boost::program_options::variables_map vm;
boost::program_options::store(
boost::program_options::parse_command_line(argc, argv, optdesc),
vm
);
boost::program_options::notify(vm);
if (vm.count("help")) {
std::cout << "Bit-per-pxiel text rendering test\nOnce running, input "
"text to render in stdin and press enter to render the text.\n"
"Enter a blank line to quit.\n\t" << argv[0] << " [options]\n" <<
optdesc << std::endl;
return 0;
}
if (vm.count("st7920")) {
uselcd = true;
}
}
std::make_shared<duds::ui::graphics::BppFont>();
font->load(fontpath);
std::cout << "Estimated character size is " << cdim << std::endl;
std::shared_ptr<duds::hardware::devices::displays::ST7920> lcd;
std::shared_ptr<duds::hardware::interface::DigitalPort> port;
if (uselcd) {
boost::property_tree::ptree tree;
boost::property_tree::read_info(confpath, tree);
pc.
parse(tree.get_child(
"pins"));
lcd = std::make_shared<duds::hardware::devices::displays::ST7920>(
);
lcd->initialize();
}
char inbuf[256] = { 0 };
do {
std::cin.getline(inbuf, 255);
if (std::cin.good() && inbuf[0]) {
std::cout << "Rendering \"" << inbuf << "\"";
std::cout << ", size " << label->width() << 'x' << label->height() <<
std::endl;
assert(label->dimensions() == font->lineDimensions(inbuf));
if (uselcd) {
std::max((dim.
w - label->width()) / 2, 0),
std::max((dim.
h - label->height()) / 2, 0)
);
lcd->write(&frame);
} else {
}
}
} while (std::cin.good() && inbuf[0]);
} catch (...) {
std::cerr << "Test failed in main():\n" <<
boost::current_exception_diagnostic_information() << std::endl;
return 1;
}