SANE属性name及fixed-id定义,单独放sane_name.h文件中统一管理
This commit is contained in:
parent
0ad5a10dd5
commit
4a454d6473
|
@ -134,6 +134,7 @@ void hg_scanner::init(void)
|
|||
else if (pimg == IMG_RECEIVER_FINISHED)
|
||||
{
|
||||
status_ = size;
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "Scan finished with error: %s\n", scanner_error_name(status_).c_str());
|
||||
if (scan_over_notify_)
|
||||
scan_over_notify_(status_);
|
||||
}
|
||||
|
@ -310,7 +311,7 @@ char* hg_scanner::get_value(const char* name, void* value, size_t* size, int* er
|
|||
if (err)
|
||||
*err = status_;
|
||||
}
|
||||
else if (strcmp(name, SANE_FULL_NAME(DUMP_IMG_PATH)) == 0)
|
||||
else if (strcmp(name, SANE_OPT_NAME(DUMP_IMG_PATH)) == 0)
|
||||
{
|
||||
ret = (char*)malloc(dump_path_.length() + 1);
|
||||
strcpy(ret, dump_path_.c_str());
|
||||
|
@ -354,10 +355,10 @@ int hg_scanner::set_value(const char* name, void* val)
|
|||
std::string t(dev_opts_->get_option_value_type(name, &size));
|
||||
uint16_t after = 0;
|
||||
|
||||
if (strcmp(SANE_FULL_NAME(RESOLUTION), name) == 0)
|
||||
if (strcmp(SANE_OPT_NAME(RESOLUTION), name) == 0)
|
||||
dpi_ = *(int*)val;
|
||||
|
||||
if (strcmp(name, SANE_FULL_NAME(DUMP_IMG)) == 0)
|
||||
if (strcmp(name, SANE_OPT_NAME(DUMP_IMG)) == 0)
|
||||
{
|
||||
if (*(bool*)val && dump_path_.empty())
|
||||
{
|
||||
|
@ -366,7 +367,7 @@ int hg_scanner::set_value(const char* name, void* val)
|
|||
dump_path_ += std::string(PATH_SEPARATOR);
|
||||
}
|
||||
}
|
||||
else if (strcmp(name, SANE_FULL_NAME(DUMP_IMG_PATH)) == 0)
|
||||
else if (strcmp(name, SANE_OPT_NAME(DUMP_IMG_PATH)) == 0)
|
||||
{
|
||||
dump_path_ = (char*)val;
|
||||
|
||||
|
@ -494,8 +495,8 @@ int hg_scanner::get_image_info(SANE_Parameters* pii)
|
|||
else
|
||||
{
|
||||
// default ...
|
||||
double *w = (double*)get_value(SANE_FULL_NAME(PAPER_W), nullptr, nullptr),
|
||||
*h = (double*)get_value(SANE_FULL_NAME(PAPER_H), nullptr, nullptr);
|
||||
double *w = (double*)get_value(SANE_OPT_NAME(PAPER_W), nullptr, nullptr),
|
||||
*h = (double*)get_value(SANE_OPT_NAME(PAPER_H), nullptr, nullptr);
|
||||
int res = dpi_;
|
||||
SIZE size(paper::size("A3"));
|
||||
|
||||
|
@ -634,9 +635,9 @@ int hg_scanner::file_transfer(const char* local, const char* remote, bool to_rem
|
|||
tx_prg_ = now;
|
||||
status_ = err;
|
||||
if (err)
|
||||
utils::to_log(LOG_LEVEL_WARNING, "File transfer error: %d (at %llu/%llu)\n", err, txed, total);
|
||||
utils::to_log(LOG_LEVEL_WARNING, "File transfer error: %s (at %llu/%llu)\n", scanner_error_name(err).c_str(), txed, total);
|
||||
else if (txed >= total)
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "File transfer finished(%llu/%llu) with error %d\n", txed, total, err);
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "File transfer finished(%llu/%llu) with error %d\n", txed, total, scanner_error_name(err).c_str());
|
||||
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -272,7 +272,7 @@ void async_usb_host::thread_read_bulk(void)
|
|||
else
|
||||
{
|
||||
// handle the error ...
|
||||
utils::to_log(LOG_LEVEL_FATAL, "thread_read_bulk FATAL error: %d\r\n", err);
|
||||
utils::to_log(LOG_LEVEL_FATAL, "thread_read_bulk FATAL error: %d(%s)\r\n", err, libusb_error_name(err));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ scanner_handler::scanner_handler(void) : usb_(nullptr), status_(SCANNER_ERR_NOT_
|
|||
else if (pack->cmd == PACK_CMD_FILE_WRITE_REQ_ROGER)
|
||||
{
|
||||
*used = sizeof(PACK_BASE);
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "Send file finished with error: %d\r\n", pack->data);
|
||||
utils::to_log(LOG_LEVEL_DEBUG, "Send file finished with error: %s\r\n", scanner_error_name(pack->data).c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <algorithm>
|
||||
#include <string.h>
|
||||
|
||||
#define IS_PTR_NUMBER(ptr) (((unsigned long long)(ptr)) < 0x10000)
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// sane_opt
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#define OS_WIN 0
|
||||
#endif
|
||||
|
||||
#include <math.h> // for fabs
|
||||
|
||||
#define SIZE_KB(n) ((n) * 1024)
|
||||
#define SIZE_MB(n) SIZE_KB((n) * 1024)
|
||||
#define SIZE_GB(n) SIZE_MB((n) * 1024)
|
||||
|
@ -15,6 +17,7 @@
|
|||
#define SEC_2_US(s) MSEC_2_US(SEC_2_MS(s))
|
||||
|
||||
#define MM_PER_INCH 25.4f
|
||||
#define IS_DOUBLE_EQUAL(a, b) fabs((a) - (b)) < .000001
|
||||
|
||||
#define ALIGN_TO(v, align) (((v) + (align) - 1) / (align) * (align))
|
||||
#define ALIGN_INT(v) ALIGN_TO(v, sizeof(int))
|
||||
|
@ -26,6 +29,43 @@
|
|||
return #e;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// console definitions
|
||||
enum console_color
|
||||
{
|
||||
COLOR_CHAR_BLACK = 0x30,
|
||||
COLOR_CHAR_RED,
|
||||
COLOR_CHAR_GREEN,
|
||||
COLOR_CHAR_YELLOW,
|
||||
COLOR_CHAR_BLUE,
|
||||
COLOR_CHAR_MAGENTA,
|
||||
COLOR_CHAR_CYAN,
|
||||
COLOR_CHAR_WHITE,
|
||||
|
||||
COLOR_BKG_NONE = 0x3f,
|
||||
COLOR_BKG_BLACK = 0x40,
|
||||
COLOR_BKG_RED,
|
||||
COLOR_BKG_GREEN,
|
||||
COLOR_BKG_YELLOW,
|
||||
COLOR_BKG_BLUE,
|
||||
COLOR_BKG_MAGENTA,
|
||||
COLOR_BKG_CYAN,
|
||||
COLOR_BKG_WHITE,
|
||||
};
|
||||
enum console_display_mode
|
||||
{
|
||||
MODE_DEFAULT = 0,
|
||||
MODE_HILIGHT,
|
||||
MODE_DIM,
|
||||
MODE_UNDER_LINE = 4,
|
||||
MODE_BLINK,
|
||||
MODE_REVERSE = 7,
|
||||
MODE_HIDDEN,
|
||||
MODE_NON_BOLD = 22,
|
||||
MODE_NON_BLINK = 25,
|
||||
MODE_NON_REVERSE = 27,
|
||||
};
|
||||
|
||||
#if !OS_WIN // migrate codes from windows to linux ...
|
||||
#include <unistd.h>
|
||||
#include <stdint.h>
|
||||
|
|
|
@ -723,6 +723,18 @@ namespace utils
|
|||
return len > 0 ? path : lnk_file;
|
||||
#endif
|
||||
}
|
||||
std::string from_console(const char* tips, console_color clr)
|
||||
{
|
||||
std::string cmd("");
|
||||
char in[2] = {0};
|
||||
|
||||
if(tips && tips[0])
|
||||
printf_with_color(tips, clr);
|
||||
while((in[0] = getchar()) != 0x0a)
|
||||
cmd += in;
|
||||
|
||||
return std::move(cmd);
|
||||
}
|
||||
std::string get_ini_value(const char* seg, const char* key, const char* cfg_file)
|
||||
{
|
||||
char buf[512] = { 0 };
|
||||
|
@ -788,6 +800,29 @@ namespace utils
|
|||
|
||||
return err;
|
||||
}
|
||||
void printf_with_color(const char* msg, console_color text_clr, console_color bkg_clr, console_display_mode mode)
|
||||
{
|
||||
char buf[80] = {0};
|
||||
|
||||
// sprintf(buf, "\033[%xm %%s \033[0m", text_clr);
|
||||
if(mode != console_display_mode::MODE_DEFAULT)
|
||||
{
|
||||
if(bkg_clr != console_color::COLOR_BKG_NONE)
|
||||
sprintf(buf, "\033[%d;%x;%xm%%s\033[0m", mode, text_clr, bkg_clr);
|
||||
else
|
||||
sprintf(buf, "\033[%d;%xm%%s\033[0m", mode, text_clr);
|
||||
}
|
||||
else if(bkg_clr != console_color::COLOR_BKG_NONE)
|
||||
{
|
||||
sprintf(buf, "\033[%x;%xm%%s\033[0m", text_clr, bkg_clr);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buf, "\033[%xm%%s\033[0m", text_clr);
|
||||
}
|
||||
|
||||
printf(buf, msg);
|
||||
}
|
||||
|
||||
bool is_match_pattern(const char* text, const char* pattern)
|
||||
{
|
||||
|
|
|
@ -44,9 +44,11 @@ namespace utils
|
|||
std::string get_module_full_path(const char* part_name = nullptr/*nullptr to get main-pe/first module's full path*/);
|
||||
std::string find_file(const char* root_dir, const char* part_name, bool recursive = false);
|
||||
std::string target_file_from_link(const char* lnk_file);
|
||||
std::string from_console(const char* tips = nullptr, console_color clr = console_color::COLOR_CHAR_GREEN);
|
||||
std::string get_ini_value(const char* seg, const char* key, const char* cfg_file); // return "" if not found
|
||||
std::string load_mini_file(const char* file, int* err); // <= 1MB
|
||||
int save_2_file(void* data, size_t len, const char* file, bool append = false/*append or new*/, size_t max_size = -1/*in append mode, truncate file if size is exceeded this value if was not -1*/);
|
||||
void printf_with_color(const char* msg, console_color text_clr, console_color bkg_clr = COLOR_BKG_NONE, console_display_mode mode = console_display_mode::MODE_DEFAULT);
|
||||
|
||||
bool is_match_pattern(const char* text, const char* pattern);
|
||||
const char* to_lower(std::string& str); // return str.c_str()
|
||||
|
|
Loading…
Reference in New Issue