📄 main.c
字号:
/***************************************************************************
main.c - description
-------------------
begin : Sat Jan 31 14:03:47 CST 2004
copyright : (C) |YEAR| by Ye2004g
email : yeh.huang@microtek.com.tw
***************************************************************************/
#include <stdio.h>
//#include <stdlib.h>
//#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/poll.h>
#include <sys/ioctl.h>
#include <sys/timeb.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include "USB_INTERFACE.h"
#include "ES03_ASIC.h"
#include "USB2_SQ.h"
#include "SM58002_SPC.h"
#include "SQ113_ASIC_Cmd.h"
#define KEY_MENU 0x01
#define KEY_SET 0x02
#define KEY_LEFT 0x03
#define KEY_RIGHT 0x04
#define KEY_STOP 0x05
#define KEY_COPY 0x06
#define KEY_MEM_COPY 0x07
#define KEY_COLOR 0x08
#define LED_COLOR 0x02
#define LED_MONO 0x01
#define LED_ERROR 0x00
#define BEEP 0x03
#define MOTOR 0x04
#define HOME 0x05
#define RESET 0x06
#define STATE_IDLE 0x00
#define STATE_SCAN 0x01
#define STATE_MENU 0x02
#define STATE_SET 0x03
#define STATE_HIDE 0x04
#define TOTAL_STATE 4
#define SCAN_MODE_COLOR 0x00000001
#define SCAN_MODE_GRAY 0x00000002
#define SCAN_MODE_MONO 0x00000003
#define SCAN_MODE_SHADING 0x00000004
#define SCAN_MODE_STILL 0x00000008
#define SCAN_MODE_SCROLL_LEFT 0x00000010
#define SCAN_MODE_SCROLL_RIGHT 0x00000020
#define SCAN_MODE_SCROLL_TO_HOME 0x00000030
#define SCAN_FILE_JPG 1
#define SCAN_FILE_PNM 2
#define SCAN_FILE_BMP 3
#define SCAN_FILE_USB 4
#define HP_START 0
#define EPSON_START 4
#define CANON_START 8
extern int scan_image(int file_type,int mode,int res);
/*
* Transform
*
* by Suixin Zhao 8/26/2006
* implement by cleanjpg.c
*
*/
extern int Transform(char *strFileSrc, char *strFileDes, int nMonoFlag);
char default_info[32];
const int key_index[]={2,3,6,5,1,4,7,8};
#define MENU_TOTAL 4
#define HIDE_MENU_TOTAL 5
char *menu_items[]={"MENU SELECT\n OUTPUT MODE","MENU SELECT\n MONO ONLY","MENU SELECT\n COPY NUMBER","MENU SELECT\n PRINTER MODE"};
int set_index[MENU_TOTAL*2]={0,1,2,3,4,4+98,103,103+11};
char *set_items[]={"OUTPUT MODE\n USB",
"OUTPUT MODE\n PRINTER",
"MONO ONLY\n NO",
"MONO ONLY\n YES",
"COPY NUMBER\n 1",
"COPY NUMBER\n 2",
"COPY NUMBER\n 3",
"COPY NUMBER\n 4",
"COPY NUMBER\n 5",
"COPY NUMBER\n 6",
"COPY NUMBER\n 7",
"COPY NUMBER\n 8",
"COPY NUMBER\n 9",
"COPY NUMBER\n 10",
"COPY NUMBER\n 11",
"COPY NUMBER\n 12",
"COPY NUMBER\n 13",
"COPY NUMBER\n 14",
"COPY NUMBER\n 15",
"COPY NUMBER\n 16",
"COPY NUMBER\n 17",
"COPY NUMBER\n 18",
"COPY NUMBER\n 19",
"COPY NUMBER\n 20",
"COPY NUMBER\n 21",
"COPY NUMBER\n 22",
"COPY NUMBER\n 23",
"COPY NUMBER\n 24",
"COPY NUMBER\n 25",
"COPY NUMBER\n 26",
"COPY NUMBER\n 27",
"COPY NUMBER\n 28",
"COPY NUMBER\n 29",
"COPY NUMBER\n 30",
"COPY NUMBER\n 31",
"COPY NUMBER\n 32",
"COPY NUMBER\n 33",
"COPY NUMBER\n 34",
"COPY NUMBER\n 35",
"COPY NUMBER\n 36",
"COPY NUMBER\n 37",
"COPY NUMBER\n 38",
"COPY NUMBER\n 39",
"COPY NUMBER\n 40",
"COPY NUMBER\n 41",
"COPY NUMBER\n 42",
"COPY NUMBER\n 43",
"COPY NUMBER\n 44",
"COPY NUMBER\n 45",
"COPY NUMBER\n 46",
"COPY NUMBER\n 47",
"COPY NUMBER\n 48",
"COPY NUMBER\n 49",
"COPY NUMBER\n 50",
"COPY NUMBER\n 51",
"COPY NUMBER\n 52",
"COPY NUMBER\n 53",
"COPY NUMBER\n 54",
"COPY NUMBER\n 55",
"COPY NUMBER\n 56",
"COPY NUMBER\n 57",
"COPY NUMBER\n 58",
"COPY NUMBER\n 59",
"COPY NUMBER\n 60",
"COPY NUMBER\n 61",
"COPY NUMBER\n 62",
"COPY NUMBER\n 63",
"COPY NUMBER\n 64",
"COPY NUMBER\n 65",
"COPY NUMBER\n 66",
"COPY NUMBER\n 67",
"COPY NUMBER\n 68",
"COPY NUMBER\n 69",
"COPY NUMBER\n 70",
"COPY NUMBER\n 71",
"COPY NUMBER\n 72",
"COPY NUMBER\n 73",
"COPY NUMBER\n 74",
"COPY NUMBER\n 75",
"COPY NUMBER\n 76",
"COPY NUMBER\n 77",
"COPY NUMBER\n 78",
"COPY NUMBER\n 79",
"COPY NUMBER\n 80",
"COPY NUMBER\n 81",
"COPY NUMBER\n 82",
"COPY NUMBER\n 83",
"COPY NUMBER\n 84",
"COPY NUMBER\n 85",
"COPY NUMBER\n 86",
"COPY NUMBER\n 87",
"COPY NUMBER\n 88",
"COPY NUMBER\n 89",
"COPY NUMBER\n 90",
"COPY NUMBER\n 91",
"COPY NUMBER\n 92",
"COPY NUMBER\n 93",
"COPY NUMBER\n 94",
"COPY NUMBER\n 95",
"COPY NUMBER\n 96",
"COPY NUMBER\n 97",
"COPY NUMBER\n 98",
"COPY NUMBER\n 99",
"PRINTER MODE\n HP INKJET",
"PRINTER MODE\n HP 3845/6840",
"PRINTER MODE\n HP LASERJET",
"PRINTER MODE\n HP 1020/1160",
"PRINTER MODE\n EPSON INKJET ",
"PRINTER MODE\n EPSON STYLUS",
"PRINTER MODE\n EPSON LASERJET",
"PRINTER MODE\n EPSON EPL-6200",
"PRINTER MODE\n CANON INKJET",
"PRINTER MODE\n CANON PIXMA",
"PRINTER MODE\n CANON LASERJET",
"PRINTER MODE\n CANON C3500",
};
char *printer[]={"deskjet", //HP INKJET ?
"deskjet2", //HP 3845/6840 ?
"laserjet", //HP LASERJET
"stphoto2", //HP 1020/1160 ?
"stphoto", //EPSON INKJET ?
"stcolor", //EPSON STYLUS\n C45/C65/C83
"stcolor2", //EPSON LASERJET ?
"stcolor", //EPSON EPL-6200\n ACULASER C8600 ?
"stcolor", //CANON INKJET ?
"stcolor", //CANON PIXMA\nip1000/ip1500 ?
"stcolor", //CANON LASERJET ?
"stcolor", //CANON C3500 ?
};
char *hide_menu_items[]={"MENU SELECT\n BACKBOARD TYPE","MENU SELECT\n MONO ONLY","MENU SELECT\n SCAN MODE","MENU SELECT\n IMAGE SIZE UP","MENU SELECT\nIMAGE SIZE DOWN"};
int hide_set_index[HIDE_MENU_TOTAL*2]={0,1,2,3,4,6,7,7+40,48,48+22};
char *hide_set_items[]={"BACKBOARD TYPE:\n NORMAL",
"BACKBOARD TYPE:\n WIDE",
"MONO ONLY: \n NO",
"MONO ONLY: \n YES",
"SCAN MODE:\n R",
"SCAN MODE:\n G",
"SCAN MODE:\n B",
"IMAGE SIZE:\n UP=0",
"IMAGE SIZE:\n UP=15",
"IMAGE SIZE:\n UP=30",
"IMAGE SIZE:\n UP=45",
"IMAGE SIZE:\n UP=60",
"IMAGE SIZE:\n UP=75",
"IMAGE SIZE:\n UP=90",
"IMAGE SIZE:\n UP=105",
"IMAGE SIZE:\n UP=120",
"IMAGE SIZE:\n UP=135", //10
"IMAGE SIZE:\n UP=150",
"IMAGE SIZE:\n UP=165",
"IMAGE SIZE:\n UP=180",
"IMAGE SIZE:\n UP=195",
"IMAGE SIZE:\n UP=210",
"IMAGE SIZE:\n UP=225",
"IMAGE SIZE:\n UP=240",
"IMAGE SIZE:\n UP=255",
"IMAGE SIZE:\n UP=270",
"IMAGE SIZE:\n UP=285", //20
"IMAGE SIZE:\n UP=300",
"IMAGE SIZE:\n UP=315",
"IMAGE SIZE:\n UP=330",
"IMAGE SIZE:\n UP=345",
"IMAGE SIZE:\n UP=360",
"IMAGE SIZE:\n UP=375",
"IMAGE SIZE:\n UP=390",
"IMAGE SIZE:\n UP=405",
"IMAGE SIZE:\n UP=420",
"IMAGE SIZE:\n UP=435", //30
"IMAGE SIZE:\n UP=450",
"IMAGE SIZE:\n UP=465",
"IMAGE SIZE:\n UP=480",
"IMAGE SIZE:\n UP=495",
"IMAGE SIZE:\n UP=510",
"IMAGE SIZE:\n UP=525",
"IMAGE SIZE:\n UP=540",
"IMAGE SIZE:\n UP=555",
"IMAGE SIZE:\n UP=570",
"IMAGE SIZE:\n UP=585", //40
"IMAGE SIZE:\n UP=600", //41
"IMAGE SIZE:\n DOWN=2330",
"IMAGE SIZE:\n DOWN=2345",
"IMAGE SIZE:\n DOWN=2360",
"IMAGE SIZE:\n DOWN=2375",
"IMAGE SIZE:\n DOWN=2380",
"IMAGE SIZE:\n DOWN=2395",
"IMAGE SIZE:\n DOWN=2410",
"IMAGE SIZE:\n DOWN=2425",
"IMAGE SIZE:\n DOWN=2440",
"IMAGE SIZE:\n DOWN=2455", //10
"IMAGE SIZE:\n DOWN=2470",
"IMAGE SIZE:\n DOWN=2485",
"IMAGE SIZE:\n DOWN=2500",
"IMAGE SIZE:\n DOWN=2515",
"IMAGE SIZE:\n DOWN=2530",
"IMAGE SIZE:\n DOWN=2545",
"IMAGE SIZE:\n DOWN=2560",
"IMAGE SIZE:\n DOWN=2575",
"IMAGE SIZE:\n DOWN=2590",
"IMAGE SIZE:\n DOWN=2605", //20
"IMAGE SIZE:\n DOWN=2620",
"IMAGE SIZE:\n DOWN=2635",
"IMAGE SIZE:\n DOWN=2650", //23
};
int setting[MENU_TOTAL+1]={0,0,0,0,0x00006000}; //0.media 1.printmode 2.pagenum 3.printerindex 4.version
int hide_setting[HIDE_MENU_TOTAL]={0,0,0,0,0}; //0.board type 1.mono only 2.scan mode 3.printer size 4.image size
char **my_menu_items;
int *my_set_index;
char **my_set_items;
int *my_setting,my_menu_total,in_hide;
int state = STATE_IDLE;
int fd_buttons = 0;
int fd_leds = 0;
int scan_mode = SCAN_MODE_COLOR | SCAN_MODE_SHADING;
int scan_res = 200;
int menu_item = 0;
int cur_set;
int csbu_state = 0;
int csbu_inq = 0, csbu_rep = 0;
int fd_usb;
int comb_key[0], comb = 0, comb_rel;
time_t comb_time;
char cmdline[256];
/*
* by Suixin Zhao
* 8/26/2006
*
* g_nFileSerial
* indication that serial number of file name for JPG format only
*
*/
int g_nFileSerial = 1;
extern char image_path[256];
extern char *image_path_prefix;
extern DWORD kDefaultSideEdge;
DWORD kOrgDefaultSideEdge;
int idle_menu(void);
int idle_left(void);
int idle_right(void);
int idle_stop(void);
int idle_copy(void);
int idle_memcopy(void);
int idle_color(void);
int menu_set(void);
int menu_left(void);
int menu_right(void);
int menu_stop(void);
int set_set(void);
int set_left(void);
int set_right(void);
int set_stop(void);
typedef int (*sub_func)(void);
// STATE_IDLE STATE_SCAN STATE_MENU STATE_SET
const sub_func sub_funcs[9][TOTAL_STATE]={ {NULL, NULL, NULL, NULL},
//KEY_MENU
{idle_menu, NULL, NULL, NULL},
//KEY_SET
{NULL, NULL, menu_set, set_set},
//KEY_LEFT
{idle_left, NULL, menu_left, set_left},
//KEY_RIGHT
{idle_right, NULL, menu_right, set_right},
//KEY_STOP
{NULL, NULL, menu_stop, set_stop},
//KEY_COPY
{idle_copy, NULL, NULL, NULL},
//KEY_MEMCOPY
{idle_memcopy, NULL, NULL, NULL},
//KEY_COLOR
{idle_color, NULL, NULL, NULL}
};
int init_control_panel()
{
fd_buttons = open("/dev/buttons", O_RDONLY);
if (fd_buttons < 0)
{
perror("open device buttons");
return 0;
}
fd_leds = open("/dev/leds", O_RDWR);
if (fd_leds < 0)
{
perror("open device leds");
return 0;
}
return 1;
}
void led_on(int index)
{
ioctl(fd_leds,0,index);
return;
}
void led_off(int index)
{
ioctl(fd_leds,1,index);
return;
}
void beep(int ms)
{
ioctl(fd_leds,0,BEEP);
mcp_sleep_ms(ms);
ioctl(fd_leds,1,BEEP);
}
void motor_off()
{
ioctl(fd_leds,0,MOTOR);
return;
}
void motor_on()
{
ioctl(fd_leds,1,MOTOR);
return;
}
void home_on()
{
ioctl(fd_leds,1,HOME);
return;
}
void home_off()
{
ioctl(fd_leds,2,HOME);
return;
}
void scanner_reset()
{
//ioctl(fd_leds,0,RESET);
//usleep(1000*500);
static int flag=0;
ioctl(fd_leds,flag,RESET);
flag=!flag;
//usleep(1000*800);
//ioctl(fd_leds,0,RESET);
//usleep(1000*500);
//ioctl(fd_leds,2,RESET);
}
int chk_usbd()
{
int fd_udisk;
fd_udisk = open("/dev/sda1", O_RDONLY);
if (fd_udisk<0)return 0;
else close(fd_udisk);
return 1;
}
void lcd_printf(char *string)
{
char buf[40];
//int i;
int len=strlen(string);
strcpy(buf,string);
if(len%2==0)
{
buf[len]=0x20;
len++;
buf[len]=0x00;
}
/*
printf("lcd printf length=%d: %s\n",len,buf);
printf("string:");
for(i=0;i<len+1;i++)printf("%2X",buf[i]);
printf("\n");
*/
write(fd_leds,buf,len);
return;
}
int get_key()
{
struct pollfd mypoll;
int code;
int bk;
mypoll.fd = fd_buttons;
mypoll.events = POLLIN;
// Wait time for read key
if (poll(&mypoll, 1, 100) != 1) { // org 20
return 0;
}
bk = read(fd_buttons, &code, sizeof(int));
if (bk == 4) {
if (code<128) {
code = key_index[code - 1];
}
else {
code = 128 + key_index[code - 128 - 1];
}
printf("read key = %d, bk = %d\n", code, bk);
return code;
}
return 0;
}
int show_default_info()
{
char info[64];
strcpy(info,default_info);
if(setting[3]>=HP_START && setting[3]<EPSON_START)strcat(info,"\n HP MODE");
else if(setting[3]>=EPSON_START && setting[3]<CANON_START)strcat(info,"\n EPSON MODE");
else strcat(info,"\n CANON MODE");
lcd_printf(info);
return 1;
}
int update_setting_info()
{
char info[64];
int i;
if(hide_setting[0])
{
if(hide_setting[1])strcpy(default_info,"DCCB 300WP ");
else strcpy(default_info,"DCCB 200WP ");
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -