建立UI-扫描服务程序之间的管道通信(还需优化);实现计数扫描模式

This commit is contained in:
gb 2024-02-07 12:43:27 +08:00
parent aa26512313
commit d35cea52c5
11 changed files with 692 additions and 206 deletions

View File

@ -32,7 +32,7 @@ static std::string device_opt_json[] = {
scanner_hw::scanner_hw() : mb_events_("motorboard-event")
{
set_where("hardware");
mb_events_.enable_wait_log(false);
// mb_events_.enable_wait_log(false);
memset(&img_base_, 0, sizeof(img_base_));
img_base_.bpp = 8;
img_base_.bppc = 8;
@ -354,6 +354,7 @@ void scanner_hw::thread_image_capture(void)
safe_fifo<int> avail_mem("v4l2-mem");
int used_v4l2_mem = 0, times = 0, minh = 210 * dpi_ / 25.4,
err = SCANNER_ERR_OK;
uint8_t scanmode = count_mode_ ? devui::SCAN_COUNT_MODE : devui::SCAN_NORMAL;
chronograph watch;
std::pair<int, int> mbev;
std::function<IMAGE_HANDLER_PROTO> img_callback(img_handler_);
@ -369,18 +370,21 @@ void scanner_hw::thread_image_capture(void)
utils::to_log(LOG_LEVEL_DEBUG, "scanning thread working ...\n");
motor_->clear_error();
motor_->start();
// to_lifter_ = 0;
while(scanning_ && times++ < 5)
{
if(mb_events_.take(mbev, true, to_lifter_))
if(mb_events_.take(mbev, true, to_lifter_)
&& mbev.first == MOTOR_BORD_EVENT_LIFTER_READY)
{
utils::to_log(LOG_LEVEL_DEBUG, "take first motorboard event: %d - 0x%08x\n", mbev.first, mbev.second);
break;
}
else
utils::to_log(LOG_LEVEL_FATAL, "Wait Lifter event before scanning failed.\n");
utils::to_log(LOG_LEVEL_FATAL, "Wait Lifter event(%d - 0x%08x) before scanning failed.\n", mbev.first, mbev.second);
motor_->start();
}
times = 0;
devui::send_message(devui::UI_STATUS_SCANNING, &scanmode, sizeof(scanmode));
while(scanning_ && mbev.first == MOTOR_BORD_EVENT_LIFTER_READY) // auto scan cycle ...
{
times++;
@ -396,41 +400,52 @@ void scanner_hw::thread_image_capture(void)
if(err != SCANNER_ERR_DEVICE_DOUBLE_FEEDING)
break;
}
else
err = SCANNER_ERR_OK;
img.height = get_image_real_height(minh);
size_t size = 0;
int ind = -1;
void* frame = camera_->read_frame(to_stream_, size, ind);
dyn_mem_shared_ptr mem = nullptr;
if(!frame)
else if(mbev.first == MOTOR_BORD_EVENT_SCAN_DONE)
{
if(err == SCANNER_ERR_OK)
err = SCANNER_ERR_DEVICE_CIS_STREAM;
break;
}
img.prc_time = watch.elapse_ms();
mem = new dyn_mem_shared(frame, size, put_v4l2_mem, (void*)ind);
used_v4l2_mem++;
img.pos.paper_ind++;
img.pos.status = hg_err_2_image_status(err);
img_handler_(mem, true, &img);
mem->release();
if((!scan_cntless_ && img.pos.paper_ind == scan_count_) || is_scan_fatal())
break;
// retrieve V4L2 memory ...
retrieve_v4l2_mem(&avail_mem, &used_v4l2_mem);
if(used_v4l2_mem >= camera_->get_mem_count())
else
{
err = SCANNER_ERR_DEVICE_CIS_OUT_OF_MEM;
stop_scan();
utils::to_log(LOG_LEVEL_FATAL, "Scanning stopped for that V4L2 is out of memory!\n");
break;
err = SCANNER_ERR_OK;
}
img.pos.paper_ind++;
devui::send_message(devui::UI_STATUS_PAPER_CNT, nullptr, 0);
if(!count_mode_)
{
img.height = get_image_real_height(minh);
size_t size = 0;
int ind = -1;
void* frame = camera_->read_frame(to_stream_, size, ind);
dyn_mem_shared_ptr mem = nullptr;
if(!frame)
{
if(err == SCANNER_ERR_OK)
err = SCANNER_ERR_DEVICE_CIS_STREAM;
break;
}
img.prc_time = watch.elapse_ms();
mem = new dyn_mem_shared(frame, size, put_v4l2_mem, (void*)ind);
used_v4l2_mem++;
img.pos.status = hg_err_2_image_status(err);
img_handler_(mem, true, &img);
mem->release();
if((!scan_cntless_ && img.pos.paper_ind == scan_count_) || is_scan_fatal())
break;
// retrieve V4L2 memory ...
retrieve_v4l2_mem(&avail_mem, &used_v4l2_mem);
if(used_v4l2_mem >= camera_->get_mem_count())
{
err = SCANNER_ERR_DEVICE_CIS_OUT_OF_MEM;
stop_scan();
utils::to_log(LOG_LEVEL_FATAL, "Scanning stopped for that V4L2 is out of memory!\n");
break;
}
}
watch.reset();
@ -445,10 +460,30 @@ void scanner_hw::thread_image_capture(void)
camera_->add_v4l2_memory(ind);
}
{
uint8_t scan = devui::SCAN_PAUSED;
devui::send_message(devui::UI_STATUS_SCANNING, &scan, sizeof(scan));
}
if(!auto_scan_ || !scanning_)
break;
// wait paper ...
while(auto_scan_)
{
if(mb_events_.take(mbev, true))
{
if(mbev.first == MOTOR_BORD_EVENT_PAPER_READY)
{
motor_->start();
printf("paper ready: %d-%x\n", mbev.first, mbev.second);
mb_events_.take(mbev, true, to_lifter_);
break;
}
printf("motor-board event is %d\n", mbev.first);
}
}
printf("motor-board event is %d\n", mbev.first);
}
if(scanning_ && mbev.first != MOTOR_BORD_EVENT_LIFTER_READY && times == 0)
@ -469,6 +504,11 @@ void scanner_hw::thread_image_capture(void)
}
utils::to_log(LOG_LEVEL_DEBUG, "scanning thread exited.\n");
{
uint8_t scan = devui::SCAN_STOPPED;
devui::send_message(devui::UI_STATUS_SCANNING, &scan, sizeof(scan));
}
scanning_ = false;
img_handler_((dyn_mem_ptr)WORKER_STATUS_IDLE, false, (LPPACKIMAGE)err);
}
@ -636,7 +676,7 @@ void scanner_hw::enable(const char* name, bool able)
}
// operation ...
int scanner_hw::open(std::function<IMAGE_HANDLER_PROTO> image_handler, std::string* cfgjson)
int scanner_hw::open(std::function<IMAGE_HANDLER_PROTO> image_handler, std::string* cfgjson, bool count_mode)
{
std::string tips("");
refer_guard<gb_json> cfg(new gb_json());
@ -647,96 +687,101 @@ int scanner_hw::open(std::function<IMAGE_HANDLER_PROTO> image_handler, std::stri
if(!image_handler)
return SCANNER_ERR_INVALID_PARAMETER;
count_mode_ = count_mode;
img_handler_ = image_handler;
img_controller_.reset(new FpgaComm(baud_));
if(!img_controller_->is_ok())
return DEV_ERR(HD_001);
if(!count_mode_)
{
img_controller_.reset(new FpgaComm(baud_));
if(!img_controller_->is_ok())
return DEV_ERR(HD_001);
img_base_.resolution_x = dpi_;
img_base_.resolution_y = dpi_y_;
if(mode_ == "\345\275\251\350\211\262")
{
img_base_.width = cis::get_line_stream_length(dpi_, true);
img_controller_->setColorMode(COLOR_MODE);
}
else
{
img_base_.width = cis::get_line_stream_length(dpi_, false);
img_controller_->setColorMode(GRAY_MODE);
}
img_base_.width *= 2; // two sides
img_controller_->setDpi(dpi_ == 300 ? DPI_300 : DPI_600);
img_controller_->setDelayTime(delay_);
img_controller_->setSample(sample_);
img_controller_->setSp(sp_);
img_controller_->enableLed(cis_led_);
img_controller_->setVsp(vsp_a_, vsp_b_);
utils::to_log(LOG_LEVEL_DEBUG, "FPGA Sp = %d, Sample = %d\n", sp_, sample_);
if(cfgjson)
{
cfg->set_value("color", mode_.c_str());
cfg->set_value("dpi", (std::to_string(dpi_) + " * " + std::to_string(dpi_y_)).c_str());
cfg->set_value("sample", sample_);
cfg->set_value("Sp", sp_);
cfg->set_value("Vsp-A", vsp_a_);
cfg->set_value("Vsp-B", vsp_b_);
cfg->set_value("Led-On", cis_led_);
}
void(FpgaComm::* exposure[])(int) = {&FpgaComm::setAExposureB, &FpgaComm::setAExposureG
, &FpgaComm::setAExposureR, &FpgaComm::setBExposureB, &FpgaComm::setBExposureG, &FpgaComm::setBExposureR};
tips = "Exposure(BGR): ";
for(int i = 0; i < SIDE_COUNT; ++i)
{
tips += "\tSide_" + std::to_string(i) + "[";
for(int j = 0; j < COLOR_IND_COUNT; ++j)
img_base_.resolution_x = dpi_;
img_base_.resolution_y = dpi_y_;
if(mode_ == "\345\275\251\350\211\262")
{
(img_controller_.get()->*exposure[i * SIDE_COUNT + j])(exposure_[i][j]);
tips += std::to_string(exposure_[i][j]) + ", ";
img_base_.width = cis::get_line_stream_length(dpi_, true);
img_controller_->setColorMode(COLOR_MODE);
}
tips.erase(tips.length() - 2);
tips += "];";
}
utils::to_log(LOG_LEVEL_DEBUG, "%s\n", tips.c_str());
if(cfgjson)
{
char val[128] = {0};
else
{
img_base_.width = cis::get_line_stream_length(dpi_, false);
img_controller_->setColorMode(GRAY_MODE);
}
img_base_.width *= 2; // two sides
sprintf(val, "(%u, %u, %u)", exposure_[SIDE_FRONT][COLOR_IND_RED], exposure_[SIDE_FRONT][COLOR_IND_GREEN], exposure_[SIDE_FRONT][COLOR_IND_BLUE]);
cfg->set_value("exposure-A(RGB)", val);
img_controller_->setDpi(dpi_ == 300 ? DPI_300 : DPI_600);
img_controller_->setDelayTime(delay_);
img_controller_->setSample(sample_);
img_controller_->setSp(sp_);
img_controller_->enableLed(cis_led_);
img_controller_->setVsp(vsp_a_, vsp_b_);
utils::to_log(LOG_LEVEL_DEBUG, "FPGA Sp = %d, Sample = %d\n", sp_, sample_);
if(cfgjson)
{
cfg->set_value("color", mode_.c_str());
cfg->set_value("dpi", (std::to_string(dpi_) + " * " + std::to_string(dpi_y_)).c_str());
cfg->set_value("sample", sample_);
cfg->set_value("Sp", sp_);
cfg->set_value("Vsp-A", vsp_a_);
cfg->set_value("Vsp-B", vsp_b_);
cfg->set_value("Led-On", cis_led_);
}
sprintf(val, "(%u, %u, %u)", exposure_[SIDE_BACK][COLOR_IND_RED], exposure_[SIDE_BACK][COLOR_IND_GREEN], exposure_[SIDE_BACK][COLOR_IND_BLUE]);
cfg->set_value("exposure-B(RGB)", val);
}
for(int i = 0; i < CIS_SECTOR_COUNT; ++i)
{
tips = "Gain: Sector_" + std::to_string(i + 1) + "[F=";
tips += std::to_string(gain_[SIDE_FRONT][i]) + "x + " + std::to_string(off_[SIDE_FRONT][i]) + "];\t[B="
+ std::to_string(gain_[SIDE_BACK][i]) + "x + " + std::to_string(off_[SIDE_BACK][i]) + "]";
img_controller_->setAGain(i, gain_[SIDE_FRONT][i]);
img_controller_->setBGain(i, gain_[SIDE_BACK][i]);
img_controller_->setAOffset(i, off_[SIDE_FRONT][i]);
img_controller_->setBOffset(i, off_[SIDE_BACK][i]);
void(FpgaComm::* exposure[])(int) = {&FpgaComm::setAExposureB, &FpgaComm::setAExposureG
, &FpgaComm::setAExposureR, &FpgaComm::setBExposureB, &FpgaComm::setBExposureG, &FpgaComm::setBExposureR};
tips = "Exposure(BGR): ";
for(int i = 0; i < SIDE_COUNT; ++i)
{
tips += "\tSide_" + std::to_string(i) + "[";
for(int j = 0; j < COLOR_IND_COUNT; ++j)
{
(img_controller_.get()->*exposure[i * SIDE_COUNT + j])(exposure_[i][j]);
tips += std::to_string(exposure_[i][j]) + ", ";
}
tips.erase(tips.length() - 2);
tips += "];";
}
utils::to_log(LOG_LEVEL_DEBUG, "%s\n", tips.c_str());
}
if(cfgjson)
{
if(cfgjson)
{
char val[128] = {0};
sprintf(val, "(%u, %u, %u)", exposure_[SIDE_FRONT][COLOR_IND_RED], exposure_[SIDE_FRONT][COLOR_IND_GREEN], exposure_[SIDE_FRONT][COLOR_IND_BLUE]);
cfg->set_value("exposure-A(RGB)", val);
sprintf(val, "(%u, %u, %u)", exposure_[SIDE_BACK][COLOR_IND_RED], exposure_[SIDE_BACK][COLOR_IND_GREEN], exposure_[SIDE_BACK][COLOR_IND_BLUE]);
cfg->set_value("exposure-B(RGB)", val);
}
for(int i = 0; i < CIS_SECTOR_COUNT; ++i)
{
char key[40] = {0}, val[128] = {0};
tips = "Gain: Sector_" + std::to_string(i + 1) + "[F=";
tips += std::to_string(gain_[SIDE_FRONT][i]) + "x + " + std::to_string(off_[SIDE_FRONT][i]) + "];\t[B="
+ std::to_string(gain_[SIDE_BACK][i]) + "x + " + std::to_string(off_[SIDE_BACK][i]) + "]";
img_controller_->setAGain(i, gain_[SIDE_FRONT][i]);
img_controller_->setBGain(i, gain_[SIDE_BACK][i]);
img_controller_->setAOffset(i, off_[SIDE_FRONT][i]);
img_controller_->setBOffset(i, off_[SIDE_BACK][i]);
utils::to_log(LOG_LEVEL_DEBUG, "%s\n", tips.c_str());
}
if(cfgjson)
{
for(int i = 0; i < CIS_SECTOR_COUNT; ++i)
{
char key[40] = {0}, val[128] = {0};
sprintf(key, "gain-sec-%d", i + 1);
sprintf(val, "A = %ux + %u, B = %ux + %u"
, gain_[SIDE_FRONT][i], off_[SIDE_FRONT][i]
, gain_[SIDE_BACK][i], off_[SIDE_BACK][i]);
cfg->set_value(key, val);
sprintf(key, "gain-sec-%d", i + 1);
sprintf(val, "A = %ux + %u, B = %ux + %u"
, gain_[SIDE_FRONT][i], off_[SIDE_FRONT][i]
, gain_[SIDE_BACK][i], off_[SIDE_BACK][i]);
cfg->set_value(key, val);
}
}
}
auto cb = [this](int ev, unsigned int data) -> void
{
printf("MBEV: %d-%x\n", ev, data);
mb_events_.save(std::make_pair(ev, data), true);
};
mb_events_.clear();
@ -770,41 +815,44 @@ int scanner_hw::open(std::function<IMAGE_HANDLER_PROTO> image_handler, std::stri
else
utils::to_log(LOG_LEVEL_FATAL, "Get motor-board confige failed.\n");
camera_.reset(new GVideoISP1());
camera_->open(/*3888*/cis::get_sector_pixels(0, dpi_, true) * CIS_SECTOR_COUNT, fh);
std::this_thread::sleep_for(std::chrono::milliseconds(20));
img_controller_->setFrameHeight(frame_h_);
img_controller_->capture();
size_t size;
int _int;
auto data = camera_->read_frame(100, size, _int);
if(data)
camera_->add_v4l2_memory(_int);
std::this_thread::sleep_for(std::chrono::milliseconds(20));
img_controller_->setFrameHeight(fh / 2 * 3);
// if(1)
// {
// // debug ...
// unsigned int vals[] = {0x5ffa, 0x3300c9d, 0x1, 0xaa00aa, 0x340030aa, 0x1380193
// , 0x1270131, 0x340030aa, 0x168000c, 0x168017b, 0, 0x0afa3f
// , 0x3e8};
// for(int i = 0; i < _countof(vals); ++i)
// img_controller_->write(i, vals[i]);
// }
std::vector<int> regs;
img_controller_->update(&regs);
if(cfgjson)
if(!count_mode_)
{
gb_json *c = new gb_json();
c->clear(true);
for(auto& v: regs)
*c += v;
cfg->set_value("controller", c);
c->release();
*cfgjson = std::move(cfg->to_string());
camera_.reset(new GVideoISP1());
camera_->open(/*3888*/cis::get_sector_pixels(0, dpi_, true) * CIS_SECTOR_COUNT, fh);
std::this_thread::sleep_for(std::chrono::milliseconds(20));
img_controller_->setFrameHeight(frame_h_);
img_controller_->capture();
size_t size;
int _int;
auto data = camera_->read_frame(100, size, _int);
if(data)
camera_->add_v4l2_memory(_int);
std::this_thread::sleep_for(std::chrono::milliseconds(20));
img_controller_->setFrameHeight(fh / 2 * 3);
// if(1)
// {
// // debug ...
// unsigned int vals[] = {0x5ffa, 0x3300c9d, 0x1, 0xaa00aa, 0x340030aa, 0x1380193
// , 0x1270131, 0x340030aa, 0x168000c, 0x168017b, 0, 0x0afa3f
// , 0x3e8};
// for(int i = 0; i < _countof(vals); ++i)
// img_controller_->write(i, vals[i]);
// }
std::vector<int> regs;
img_controller_->update(&regs);
if(cfgjson)
{
gb_json *c = new gb_json();
c->clear(true);
for(auto& v: regs)
*c += v;
cfg->set_value("controller", c);
c->release();
*cfgjson = std::move(cfg->to_string());
}
}
return SCANNER_ERR_OK;
@ -813,7 +861,7 @@ int scanner_hw::start_scan(void)
{
unsigned int val = 0;
if(!camera_.get() || !motor_.get() || !img_controller_.get())
if(!motor_.get() || (!count_mode_ && (!camera_.get() || !img_controller_.get())))
return DEV_ERR(NOT_READY);
motor_->clear_error();
@ -843,8 +891,8 @@ int scanner_hw::start_scan(void)
}
int scanner_hw::stop_scan(void)
{
// scanning_ = auto_scan_ = false;
// mb_events_.trigger();
scanning_ = auto_scan_ = false;
mb_events_.trigger();
if(motor_.get())
{
motor_->set_auto_paper(false, false);

View File

@ -61,6 +61,7 @@ class scanner_hw : public sane_opt_provider
std::string family_ = "G200";
PACKIMAGE img_base_;
volatile bool auto_scan_ = false;
bool count_mode_ = true;
bool scan_cntless_ = true;
int scan_count_ = 1;
int cis_length_ = 3888;
@ -118,7 +119,7 @@ public:
// operation ...
public:
int open(std::function<IMAGE_HANDLER_PROTO> image_handler, std::string* cfgjson = nullptr);
int open(std::function<IMAGE_HANDLER_PROTO> image_handler, std::string* cfgjson = nullptr, bool count_mode = false);
int start_scan(void);
int stop_scan(void);
int close(bool from_worker = false);

View File

@ -11,6 +11,7 @@
#include <base/utils.h>
#include <base/ui.h>
#include "../../ui/Displaydef.h"
#define MOTOR_UART "/dev/ttyS4"
@ -606,7 +607,7 @@ void MotorBoard::PutMsg(int type, int value, int clearscreen)
{
// if(m_statecontrol.get())
// m_statecontrol->PutMsg(type,value,clearscreen);
devui::display_message(type, clearscreen, value);
// devui::send_message(type, clearscreen, value);
}
void MotorBoard::errormsg(uint value)

View File

@ -282,13 +282,30 @@ void async_scanner::init(void)
{
cis_ = new scanner_hw();
auto uicb = [this](int ev_type) -> std::string
auto uicb = [this](devui::LPMSGSTREAM pack) -> void
{
std::string ret("");
if(devui::UI_CMD_COUNT_PAPER == pack->msg)
{
auto receiver = [this](dyn_mem_ptr data, bool img, LPPACKIMAGE lpinfo) -> void
{
img_prcr_->process(lpinfo, data, img);
};
bool auto_scan = true;
std::string prev(cfg_mgr_->get_option_value(SANE_OPT_NAME(WAIT_TO_SCAN), SANE_ACTION_GET_VALUE));
cis_->set_value(SANE_OPT_NAME(WAIT_TO_SCAN), &auto_scan);
cis_->open(receiver, nullptr, true);
cis_->start_scan();
}
else if(devui::UI_CMD_STOP_SCAN == pack->msg)
{
cis_->stop_scan();
return ret;
bool auto_scan = false;
cis_->set_value(SANE_OPT_NAME(WAIT_TO_SCAN), &auto_scan);
}
};
devui::init_ui(uicb);
devui::init_ui(uicb, false);
}
bool async_scanner::on_energy_conservation(bool normal)
{

View File

@ -1,42 +1,231 @@
#include "ui.h"
#include "utils.h"
#include <string.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ipc class
class ui_messenger
namespace devui
{
public:
ui_messenger()
{}
~ui_messenger()
{}
class ui_messenger
{
std::function<void(LPMSGSTREAM)> cb_;
safe_fifo<std::string> sent_que_;
volatile bool run_ = true;
bool ui_;
bool ready_ = true;
safe_thread workers_;
int fdo_ = -1;
int fdi_ = -1;
std::string fmode(int m)
{
if(m == O_RDONLY)
return "O_RDONLY";
if(m == O_WRONLY)
return "O_WRONLY";
return "Unk";
}
void init(void)
{
const char* fifo[] = {"/tmp/worker", "/tmp/ui"};
int mode[] = {O_RDONLY, O_WRONLY};
int *fd[] = {&fdi_, &fdo_};
if(ui_)
{
mkfifo(fifo[!ui_], 0777);
mkfifo(fifo[ui_], 0777);
fdo_ = open(fifo[1], mode[1]);
fdi_ = open(fifo[0], mode[0]);
}
else
{
fdi_ = open(fifo[1], mode[0]);
fdo_ = open(fifo[0], mode[1]);
}
if(fdo_ == -1 || fdi_ == -1)
{
printf("Out fd = %d, In fd = %d\n", fdo_, fdi_);
this->close();
}
else
{
auto r = [this](void) -> void
{
receiver();
};
auto s = [this](void) -> void
{
sender();
};
workers_.start(r, "receiver");
workers_.start(s, "sender");
}
}
void close(void)
{
ready_ = false;
if(fdo_ != -1)
::close(fdo_);
if(fdi_ != -1)
::close(fdi_);
fdi_ = fdo_ = -1;
}
void receiver(void)
{
std::string rcv("");
char buf[300] = {0};
LPMSGSTREAM pack = nullptr;
printf("ui-receiver running ...\n");
while(run_)
{
int r = read(fdi_, buf, _countof(buf));
if(r == -1)
{
printf("Read UI message failed: %d(%s)\n", errno, strerror(errno));
utils::to_log(LOG_LEVEL_FATAL, "Read UI message failed: %d(%s)\n", errno, strerror(errno));
this->close();
break;
}
if(rcv.length())
{
rcv += std::string(buf, r);
pack = (LPMSGSTREAM)&rcv[0];
if(pack->whole_size() <= rcv.length())
{
cb_(pack);
rcv.erase(0, pack->whole_size());
}
}
else
{
int off = 0;
pack = (LPMSGSTREAM)buf;
if(pack->whole_size() <= r)
{
cb_(pack);
off = pack->whole_size();
}
if(off < r)
{
rcv = std::string(buf + off, r - off);
}
}
}
printf("ui-receiver exited.\n");
}
void sender(void)
{
printf("ui-sender running ...\n");
while(run_)
{
std::string cont("");
if(sent_que_.take(cont, true))
{
int s = 0, off = 0;
do
{
s = write(fdo_, cont.c_str() + off, cont.length() - off);
if(s == -1)
{
printf("Send UI message failed: %d(%s)\n", errno, strerror(errno));
utils::to_log(LOG_LEVEL_FATAL, "Send UI message failed: %d(%s)\n", errno, strerror(errno));
this->close();
break;
}
off += s;
}while(off < cont.length());
if(s == -1)
break;
}
}
printf("ui-sender exited.\n");
}
public:
ui_messenger(std::function<void(LPMSGSTREAM)> uicb
, bool ui) : sent_que_("ui-sent-que")
, cb_(uicb), ui_(ui)
{
sent_que_.enable_wait_log(false);
init();
}
~ui_messenger()
{
close();
}
public:
bool send(std::string& msg)
{
if(ready_)
sent_que_.save(msg, true);
return ready_;
}
void stop(void)
{
sent_que_.trigger();
run_ = false;
this->close();
}
};
};
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// interface
static MUTEX msg_lk_;
static ui_messenger *msgr = nullptr;
static MUTEX msg_lk_;
static devui::ui_messenger *msgr = nullptr;
namespace devui
{
void init_ui(std::function<std::string(int)> uicb)
void init_ui(std::function<void(LPMSGSTREAM)> uicb, bool ui)
{
SIMPLE_LOCK(msg_lk_);
if(!msgr)
msgr = new ui_messenger(uicb, ui);
}
void uninit_ui(void)
{
SIMPLE_LOCK(msg_lk_);
if(msgr)
{
msgr->stop();
delete msgr;
}
msgr = nullptr;
}
void display_message(uint32_t msgid, uint8_t clear_mode, uint8_t draw_mode)
bool send_message(uint32_t msgid, uint8_t* data, uint8_t size)
{
SIMPLE_LOCK(msg_lk_);
std::string stream("");
MSGSTREAM pack;
bool ret = false;
memset(&pack, 0, sizeof(pack));
pack.ver = 1;
pack.msg = msgid;
pack.size = size;
if(size)
pack.data[0] = data[0];
stream = std::string((char*)&pack, sizeof(pack));
if(size > 1)
stream += std::string((char*)data + 1, size - 1);
{
SIMPLE_LOCK(msg_lk_);
if(msgr)
ret = msgr->send(stream);
}
return ret;
}
};

View File

@ -9,12 +9,45 @@
#include <functional>
#include <string>
#include "../../ui/Displaydef.h"
namespace devui
{
void init_ui(std::function<std::string(int)> uicb);
enum scan
{
SCAN_STOPPED = 0, // scanning work is stopped
SCAN_PAUSED, // finished ONE turn scanning in auto-scan
SCAN_NORMAL,
SCAN_COUNT_MODE,
};
enum uicmd
{
UI_CMD_COUNT_PAPER = 0x10,
UI_CMD_STOP_SCAN,
UI_STATUS_SCANNING = 0x1000, // begin scanning. data: (enum scan)
UI_STATUS_PAPER_CNT, // ONE paper has pass through. data: none
};
#pragma pack(push)
#pragma pack(1)
typedef struct _msg_stream
{
uint16_t ver;
uint32_t msg;
uint16_t size; // bytes of data
uint8_t data[1];
uint32_t whole_size(void)
{
if(size)
return sizeof(*this) + size - 1;
else
return sizeof(*this);
}
}MSGSTREAM, *LPMSGSTREAM;
#pragma pack(pop)
void init_ui(std::function<void(LPMSGSTREAM)> uicb, bool ui);
void uninit_ui(void);
void display_message(uint32_t msgid, uint8_t clear_mode = (uint8_t)ClearScreen::All, uint8_t draw_mode = (uint8_t)DisDrawtype::DD_All); // see Displaydef.h
bool send_message(uint32_t msgid, uint8_t* data = nullptr, uint8_t size = 0); // re-init if return false
};

View File

@ -49,3 +49,6 @@
#define WORDS_FUNCTION_COUNT "\345\274\240\346\225\260\357\274\232"
#define WORDS_STATUS_READY "\345\260\261\347\273\252"
#define WORDS_STATUS_SCANNING_NORMAL "\346\255\243\345\234\250\346\211\253\346\217\217\342\200\246"
#define WORDS_STATUS_SCANNING_COUNT "\346\255\243\345\234\250\350\256\241\346\225\260\346\211\253\346\217\217\342\200\246"
#define WORDS_STATUS_TOTAL "\346\200\273\357\274\232"

View File

@ -3,6 +3,7 @@
#include <string.h>
#include "Displaydef.h"
#include <base/words.h>
#include <base/ui.h>
#include "keymonitor.h"
#include "Lcd.h"
#include "font.h"
@ -243,7 +244,9 @@ enum
MENU_CMD_ID_WELCOME = 0xa0,
};
static uint8_t welcome[] = {128, 32
namespace welcome
{
static uint8_t ddjx[] = {128, 32
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
@ -277,7 +280,86 @@ static uint8_t welcome[] = {128, 32
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static uint8_t mugui[] = {128, 32
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xC0
, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x18, 0x1C, 0x1C, 0x70, 0xE0, 0x80, 0x80, 0x90, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF8, 0xF8
, 0xF0, 0xB0, 0x90, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 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x9F, 0x1F, 0x87, 0xCB, 0xF3, 0xC7, 0xDF, 0xDF, 0xFF, 0xDF
, 0xFF, 0xA2, 0xE2, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0xC6, 0x86, 0xC4, 0xC4, 0x8C, 0x0C, 0x8C
};
static uint8_t qiaoting[] = {128, 32
, 0x1C, 0x7F, 0xE7, 0x7E, 0x0F, 0x0B, 0x0C, 0xFF, 0xFF, 0x3F, 0x03, 0x03, 0x02, 0x02, 0x00, 0x07
, 0xD8, 0x88, 0x08, 0x0C, 0x0E, 0x0C, 0x18, 0x30, 0xE0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x80, 0x80, 0x80, 0x80, 0xC0, 0xC0, 0xE0, 0xFC, 0xFC, 0xE0, 0xC0, 0xC0, 0x80, 0x80, 0x80
, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xC0, 0xF0, 0xF0, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x7C, 0x3E, 0x00, 0x00, 0x40, 0x70, 0xFC, 0x3F, 0xFC, 0x78, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x03, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x0F, 0x03, 0x06, 0x0C, 0x98, 0x00, 0x80
, 0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 0xF8, 0xF8, 0xF8, 0xFC, 0xFC, 0xFC, 0xFC, 0xFF, 0xFF, 0xFF
, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
, 0x03, 0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x03, 0x01, 0x07, 0x01, 0x03, 0x07, 0x03, 0x07
, 0x07, 0x05, 0x07, 0x03, 0x03, 0x03, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
, 0x60, 0x20, 0x60, 0x7F, 0x70, 0xF0, 0xFB, 0xBF, 0xB0, 0xF0, 0xBF, 0xF0, 0xF0, 0x70, 0x7F, 0x60
, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D, 0x1F, 0x1F, 0x1F, 0x1F
, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x0F, 0x0F, 0x0F, 0x1F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F
, 0x3F, 0x7F, 0x7F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xFE, 0xFE, 0x7E
};
static uint8_t* pics[] = {ddjx, mugui, qiaoting};
static int index_ = 0;
static uint8_t* get_current_pic(void)
{
uint8_t* cur = pics[index_++];
index_ %= _countof(pics);
return cur;
}
};
ui_mgr::ui_mgr() : disp_data_("lcd-msg")
{
@ -307,12 +389,63 @@ ui_mgr::ui_mgr() : disp_data_("lcd-msg")
thread_display();
};
disp_thrd_.start(display, "thread_display");
auto statu = [this](devui::LPMSGSTREAM pack) -> void
{
if(pack->msg == devui::UI_STATUS_SCANNING)
{
scanning_ = pack->data[0] != devui::SCAN_STOPPED;
set_ready_status_enabled(!scanning_);
if(scanning_)
{
paper_cnt_ = 0;
if(pack->data[0] != devui::SCAN_PAUSED)
{
DISPDATA dd;
paper_total_ = 0;
memset(&dd, 0, sizeof(dd));
dd.cnt = dd.mask = -1;
disp_data_.save(dd, true);
dd.mask = 0;
dd.cnt = custom_font::get_string_font(pack->data[0] == devui::SCAN_NORMAL ? WORDS_STATUS_SCANNING_NORMAL : WORDS_STATUS_SCANNING_COUNT, dd.ptr);
hold_pos_.x = dd.ptr[0][0] * 1;
hold_pos_.y = dd.ptr[0][1];
disp_data_.save(dd, true);
}
}
}
else if(pack->msg == devui::UI_STATUS_PAPER_CNT)
{
DISPDATA dd;
char num[40] = {0};
int cnt = 0;
paper_cnt_++;
paper_total_++;
sprintf(num, "%03d", paper_cnt_);
dd.x = hold_pos_.x;
dd.y = hold_pos_.y;
dd.cnt = custom_font::get_string_font(num, dd.ptr);
cnt = disp_data_.save(dd, true);
sprintf(num, "%s%d", WORDS_STATUS_TOTAL, paper_total_);
dd.y += Lcd::LCD_LINE_PER_PAGE;
dd.x = Lcd::LCD_WIDTH;
dd.cnt = custom_font::get_string_font(num, dd.ptr, custom_font::FONT_SIZE_8);
for(int i = 0; i < dd.cnt; ++i)
dd.x -= dd.ptr[i][0] + 1;
cnt = disp_data_.save(dd, true);
}
};
devui::init_ui(statu, true);
}
ui_mgr::~ui_mgr()
{
run_ = false;
menu_mode_ = false;
disp_data_.trigger();
devui::uninit_ui();
clear();
}
@ -342,7 +475,8 @@ void ui_mgr::init(void)
root_ = new dev_menu();
// 分纸强度低中高<E4B8AD><E9AB98>? {
// 分纸强度(低中高)
{
child = new dev_menu(true);
child->add_menu(WORDS_MENU_LOW, MENU_CMD_ID_SEPARATE_LOW);
{
@ -372,7 +506,8 @@ void ui_mgr::init(void)
root_->add_menu(WORDS_MENU_SEPARATE_STRENGTH, child);
child->release();
}
// 休眠时间不休眠<E4BC91><E79CA0>?min, 10min, 20min, 30min, 1h, 2h, 4h<34><68>? {
// 休眠时间不休眠5min, 10min, 20min, 30min, 1h, 2h, 4h
{
child = new dev_menu(true);
child->add_menu(WORDS_MENU_SLEEP_NONE, MENU_CMD_ID_SLEEP_NEVER);
{
@ -451,13 +586,16 @@ void ui_mgr::init(void)
child->release();
}
// 计数模式、手动模式、清理纸道、历史张数、滚轴张数、清除滚轴张<E8BDB4><E5BCA0>?确定<EFBC8C><E58F96>?、进入休眠、关<E38081><E585B3>? root_->add_menu(WORDS_MENU_COUNT_MODE, MENU_CMD_ID_COUNT_MODE);
// 计数模式、手动模式、清理纸道、历史张数、滚轴张数、清除滚轴张数(确定,取消)、进入休眠、关机
root_->add_menu(WORDS_MENU_COUNT_MODE, MENU_CMD_ID_COUNT_MODE);
{
auto f = [this](dev_menu* m, int id) -> MENU_CMD_HANDLER_RET
{
// 保持界面:第一行显示当前保持的功能
// 第二行显示当前功能的信息过程中只更新该<E696B0><E8AFA5>? //
// 任意按键的反应第一行显示“退出当前功能<E58A9F><E883BD>? // 第二行显示“确定”、“取消”,菜单键在此两项中跳转
// 第二行显示当前功能的信息,过程中只更新该行
//
// 任意按键的反应:第一行显示“退出当前功能”
// 第二行显示“确定”、“取消”,菜单键在此两项中跳转
DISPDATA dd;
memset(&dd, 0, sizeof(dd));
@ -477,12 +615,13 @@ void ui_mgr::init(void)
hold_pos_.x += 2;
disp_data_.save(dd, true);
auto test = [this](void) -> void
{
thread_test_hold_ui();
};
disp_thrd_.stop("thread_test_hold_ui");
disp_thrd_.start(test, "thread_test_hold_ui");
// auto test = [this](void) -> void
// {
// thread_test_hold_ui();
// };
// disp_thrd_.stop("thread_test_hold_ui");
// disp_thrd_.start(test, "thread_test_hold_ui");
devui::send_message(devui::UI_CMD_COUNT_PAPER);
return true;
};
@ -627,7 +766,7 @@ void ui_mgr::init(void)
dd.x = 0;
dd.y = 0;
dd.cnt = 1;
dd.ptr[0] = welcome;
dd.ptr[0] = welcome::get_current_pic();
disp_data_.save(dd, true);
return false;
@ -739,6 +878,7 @@ void ui_mgr::thread_test_hold_ui(void)
while(!menu_mode_)
{
rol_cnt_++;
his_cnt_++;
sprintf(number, "%d", cnt++);
if(size == custom_font::FONT_SIZE_16 && (Lcd::LCD_WIDTH - dd.x) / font_size_.cx < strlen(number))
{
@ -766,7 +906,7 @@ void ui_mgr::thread_display(void)
// welcome
{
uint8_t *ptr[] = {welcome};
uint8_t *ptr[] = {welcome::get_current_pic()};
lcd_->write_line(ptr, 1);
}
@ -816,6 +956,16 @@ int ui_mgr::get_ready_watch_ms(void)
void ui_mgr::key_event(int key)
{
if(scanning_)
{
if(key == (int)KeyMonitor::HGKey::Key_Cancle)
{
devui::send_message(devui::UI_CMD_STOP_SCAN);
}
return;
}
reset_ready_watch();
set_ready_status_enabled(true);
@ -841,6 +991,7 @@ void ui_mgr::key_event(int key)
else if(key == (int)KeyMonitor::HGKey::Key_Cancle)
{
// stop scanning here ...
devui::send_message(devui::UI_CMD_STOP_SCAN);
}
else if(key == -1) // interrupted by status message, we return to main menu
{

View File

@ -93,6 +93,9 @@ class ui_mgr : public refer
volatile bool menu_mode_ = false; // whether LCD is displaying menu
volatile bool run_ = true;
volatile bool ready_enable_ = true;
bool scanning_ = false;
int paper_total_ = 0;
int paper_cnt_ = 0;
SIZE font_size_ = {16, 16};
POINT hold_pos_ = {0, 0};

View File

@ -24,56 +24,65 @@ namespace custom_font
void init_8x8(void)
{
static uint8_t num0[] = {8, 8
, 0x30, 0xF8, 0x04, 0xF8, 0x00, 0x00, 0x00, 0x00
static uint8_t num0[] = {6, 8
, 0x00, 0x7C, 0x44, 0x7C, 0x00, 0x00
};
font_map8x8_["\060\000\000"] = num0;
static uint8_t num1[] = {8, 8
, 0x00, 0x08, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00
static uint8_t num1[] = {6, 8
, 0x00, 0x08, 0xFC, 0x00, 0x00, 0x00
};
font_map8x8_["\061\000\000"] = num1;
static uint8_t num2[] = {8, 8
, 0x80, 0xC4, 0xA0, 0x9C, 0x00, 0x00, 0x00, 0x00
static uint8_t num2[] = {6, 8
, 0x00, 0xCC, 0xA4, 0xB4, 0x9C, 0x00
};
font_map8x8_["\062\000\000"] = num2;
static uint8_t num3[] = {8, 8
, 0x00, 0x0C, 0x04, 0xEC, 0x00, 0x00, 0x00, 0x00
static uint8_t num3[] = {6, 8
, 0x00, 0x44, 0x54, 0x7C, 0x00, 0x00
};
font_map8x8_["\063\000\000"] = num3;
static uint8_t num4[] = {8, 8
, 0x20, 0x28, 0xFC, 0xFE, 0x20, 0x00, 0x00, 0x00
static uint8_t num4[] = {6, 8
, 0x20, 0x28, 0xFC, 0xFE, 0x20, 0x00
};
font_map8x8_["\064\000\000"] = num4;
static uint8_t num5[] = {8, 8
, 0x00, 0x9C, 0x94, 0xB4, 0x60, 0x00, 0x00, 0x00
static uint8_t num5[] = {6, 8
, 0x00, 0x9C, 0x94, 0xB4, 0x60, 0x00
};
font_map8x8_["\065\000\000"] = num5;
static uint8_t num6[] = {8, 8
, 0x00, 0xF0, 0x28, 0xE0, 0x00, 0x00, 0x00, 0x00
static uint8_t num6[] = {6, 8
, 0x00, 0xF8, 0x94, 0x94, 0x74, 0x00
};
font_map8x8_["\066\000\000"] = num6;
static uint8_t num7[] = {8, 8
, 0x04, 0x04, 0xE4, 0x1C, 0x00, 0x00, 0x00, 0x00
static uint8_t num7[] = {6, 8
, 0x04, 0x04, 0xE4, 0x1C, 0x00, 0x00
};
font_map8x8_["\067\000\000"] = num7;
static uint8_t num8[] = {8, 8
, 0x00, 0xF8, 0x24, 0xFC, 0x00, 0x00, 0x00, 0x00
static uint8_t num8[] = {6, 8
, 0x00, 0x7C, 0x54, 0x7C, 0x00, 0x00
};
font_map8x8_["\070\000\000"] = num8;
static uint8_t num9[] = {8, 8
, 0x08, 0x3C, 0xA0, 0x7C, 0x00, 0x00, 0x00, 0x00
static uint8_t num9[] = {6, 8
, 0x00, 0x5C, 0x54, 0x3C, 0x00, 0x00
};
font_map8x8_["\071\000\000"] = num9;
static uint8_t zong[] = {8, 8
, 0x00, 0x60, 0x6E, 0x4B, 0x7A, 0x4B, 0x6C, 0x60
};
font_map8x8_["\346\200\273"] = zong;
static uint8_t maohao[] = {8, 8
, 0x00, 0x50, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00
};
font_map8x8_["\357\274\232"] = maohao;
}
@ -507,6 +516,37 @@ namespace custom_font
, 0x00, 0x00, 0x00, 0x00
};
font_map_["\357\274\232"] = maohao;
static uint8_t zheng[] = {16, 16
, 0x00, 0x00, 0x00, 0x02, 0x02, 0xE2, 0x02, 0x02, 0x02, 0xFE, 0xFE, 0x82, 0x82, 0x82, 0x82, 0x82
, 0x00, 0x00, 0x40, 0x40, 0x40, 0x7F, 0x40, 0x40, 0x40, 0x7F, 0x7F, 0x40, 0x40, 0x40, 0x40, 0x40
};
font_map_["\346\255\243"] = zheng;
static uint8_t zai[] = {16, 16
, 0x00, 0x00, 0x08, 0x08, 0x88, 0xC8, 0x68, 0x3C, 0x0F, 0x08, 0xE8, 0xE8, 0x08, 0x08, 0x08, 0x08
, 0x00, 0x08, 0x04, 0x02, 0xFF, 0x40, 0x40, 0x41, 0x41, 0x41, 0x7F, 0x7F, 0x41, 0x41, 0x41, 0x41
};
font_map_["\345\234\250"] = zai;
static uint8_t sao[] = {16, 16
, 0x00, 0x00, 0x10, 0x10, 0xFF, 0xFF, 0x10, 0x90, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0xF8
, 0x00, 0x02, 0x86, 0x82, 0xFF, 0xFF, 0x01, 0x00, 0x40, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0xFF
};
font_map_["\346\211\253"] = sao;
static uint8_t miao[] = {16, 16
, 0x00, 0x00, 0x10, 0x10, 0xFF, 0x11, 0x10, 0x10, 0x88, 0x88, 0xFF, 0x88, 0x88, 0xBF, 0x8A, 0x88
, 0x00, 0x04, 0x86, 0x82, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0x44, 0x44, 0x7F, 0x7F, 0x44, 0x44, 0xFF
};
font_map_["\346\217\217"] = miao;
static uint8_t ellipsis[] = {16, 16
, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0xC0, 0xC0, 0x00, 0x00, 0x00
, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
font_map_["\342\200\246"] = ellipsis;
}
~font_init()
{}

View File

@ -60,8 +60,8 @@ add_packagedirs("sdk")
add_defines("BUILD_AS_DEVICE")
add_defines("VER_MAIN=2")
add_defines("VER_FAMILY=200")
add_defines("VER_DATE=20240206")
add_defines("VER_BUILD=21")
add_defines("VER_DATE=20240207")
add_defines("VER_BUILD=31")
target("conf")
set_kind("phony")