A Chinese character input method for Microwindows
[Copy link]
Abstract : Microwindows is a commonly used open source embedded GUI software. This paper discusses a Chinese character input method under Microwindows. This input method is different from the general Chinese character input method design of Microwindows, and has been implemented on the SED-ED300 series of SED tax control machines. Keywords : embedded system; Microwindows; ARM Introduction
Microwindows is a layered architecture. The bottom layer provides various device drivers for the driver layer; the middle layer provides a hardware-independent graphics engine layer, which mainly provides graphics drawing, line segment drawing and font output, etc., and provides services to the upper layer by calling the bottom device driver; the top layer provides two API interfaces for application engineers to use, namely the Windows-based message loop programming method (Microwindows API) and the X-Windows-based C/S method (Nano-X API).
This design is developed in the Linux server/client mode, which provides program engineers with development APIs starting with GrXXX. These functions can be used to complete window creation and destruction, graphics drawing, character display, etc. All work is sent to the background server through Socket, and the server undertakes all the work, so that multiple clients can send applications at the same time and the server can manage the work mode uniformly.
One way to input Chinese characters is to embed it into the Nano-X server to implement it, and the other way is to do it in the kernel keyboard driver or make an application to implement it. The method of directly embedding it into the kernel keyboard driver is more intuitive, but when adding other Chinese character input methods, it is more troublesome to recompile and download the kernel. If it is implemented by program, it is more flexible and easy to maintain. It needs to shield Nano-X from reading the low-level keyboard driver function, and use an application to handle the keyboard event message transmission between the application and Nano-X, so as to realize the input of Chinese characters. This article focuses on the application processing method. 740)this.width=740" border=undefined> Figure 1 Chinese character input method program structure diagram Software operating environment
This system uses the embedded chip EP7312 based on ARM7 architecture, providing 16MB SDRAM as the main memory, 2MB Nor Flash as the kernel memory, 32MB Nand Flash as the file system memory, and some additional peripherals; the operating system is embedded Linux, and the middle layer uses Microwindows, which have become a major mainstream in embedded systems due to open source code, completely free, powerful functions and easy portability. At present, the SED-E300 series of SED tax control machines also run on this platform. Software Design
The Chinese character input method program is a Nano-X program, and the program structure is shown in Figure 1.
First, establish a connection with the Nano-X server; create a window and all required resources, such as a graphics device description table, font, and drawing area; select the type of event to be processed; perform actual work processing, detect event types, actual Chinese character output, specific input method processing, etc.; destroy the specified font, graphics device description table, and window; close the connection with the Nano-X server; and exit the application.
The program is divided into an input method management program and a specific input method program, and the division of labor between the two is different. The former is mainly to determine the current Chinese character input method type, read keyboard data and pass it to a specific Chinese character input method program; the latter receives keyboard data, performs specific Chinese character input method processing, and passes the Chinese character internal code to the Nano-X server.
Keyboard encoding
The keyboard array currently used is an 8×8 matrix keyboard. Conventional 26 English characters, 10 numbers, and some symbols are encoded in ASCII. Some function keys are encoded in the 'ESC' sequence, and its format is 'ESC'+'ch1'+'ch2', a total of 3 bytes. The hexadecimal value of the first byte is 0x1b, and the second and third bytes vary according to the function key. For example, the code of the 'input method switch' key is 0x1b 0x4f 0x51, and the code of the 'exit' function key is 0x1b 0x5b 0x54, etc.
/dev/sedkey is a keyboard device driver file. Linux applications can read the current keyboard input through file operations.
Input method management program
Chinese character input method management program (xin.c) is mainly responsible for reading keyboard data from the low-level keyboard driver /dev/sedkey and passing the keyboard data to the current Chinese character input method program through event messages. The specific structure diagram is shown in Figure 1.
The input method configuration file xin_config can flexibly configure the number and type of input methods. It is a text file. The input method management program will automatically analyze the configuration file to meet the user's input method needs. The file format is shown in Table 1.
If you want to configure an input method of "location + pinyin + Wubi", the content of xin_config is: /flash/qw /flash/py /flash/wbzx, where qw, py, and wbzx are independent input method programs. In this way, if you switch through the "input method switch" key, they are Western, location, pinyin, and Wubi, and they are cycled in sequence.
Input method management mainly includes three subroutines get_input(), run_input(), and kill_input(). Among them, the get_input() subroutine is mainly responsible for parsing the xin_config file to determine how many input methods there are, as well as the path and program file name; run_input() mainly executes the specified input method program; kill_input() is mainly responsible for deleting the specified input method program.
Chinese character input method program
Specific Chinese character input method programs include location, pinyin, Wubi, handwriting, etc. Among them, the location input method is the most typical input method. As long as 4 digital ASCII codes are received, they are combined into a Chinese character.
The Chinese character input method program mainly includes three subroutines: esc_proc(), quwei_translate_char(), and quwei_send_char(). Among them, the esc_proc() subroutine processes the input keyboard events. If it is a function key, the key value is directly passed to the GR_BOOT_ WINDOW_ID window; the quwei_translate _char() subroutine is mainly responsible for converting the 4-digit key into the Chinese character internal code; the quwei_send_char() subroutine is mainly responsible for passing the specified value to the GR_BOOT_WINDOW_ID window through the keyboard event.
Program operation and conclusion
After the program is compiled and linked, put it in a specified directory such as /flash, put xin, xin_config, qw, py, and wbzx in /flash, and execute the following commands:
/flash/nano-X /flash/nanwn /flash/xin /flash/app & Among them, app is an application program. Specifically, in the tax control machine, app is a tax control machine program.
As new Chinese character input methods are constantly introduced and users specify specific input methods, the advantages of this input method design will also be revealed. It does not require modifying the huge Microwindows program, but only requires directly customizing a new input method program according to the program structure of qw.c, and then modifying the corresponding xin_config file. It is very easy to expand. Conclusion
SED-E300 series tax control machines are high-end products developed on embedded Linux operating system and Microwindows graphics platform. The Chinese character input method introduced in this article is convenient and easy to expand, and has practical significance in the development of tax control, POS, handheld devices and other products.
|