CN107015803A - Button monitor method and system based on Linux inner core - Google Patents
Button monitor method and system based on Linux inner core Download PDFInfo
- Publication number
- CN107015803A CN107015803A CN201710168451.XA CN201710168451A CN107015803A CN 107015803 A CN107015803 A CN 107015803A CN 201710168451 A CN201710168451 A CN 201710168451A CN 107015803 A CN107015803 A CN 107015803A
- Authority
- CN
- China
- Prior art keywords
- button
- file
- key
- inner core
- linux
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/38—Creation or generation of source code for implementing user interfaces
Abstract
The invention discloses a kind of button monitor method based on Linux inner core and system, wherein method comprises the following steps:Operating system opens the button monitoring file under preset path, button monitoring file correspondence virtually turns to the specified button of device node by linux kernel, the button monitoring file includes being provided with the polling cycle of detection button in a SQL for being used to monitor the specified button, the SQL and reports the event functions of key-press status;Operating system reads the button monitoring file according to the polling cycle of the setting with polling mode, and the content in the button monitoring file is read in design variables;Whether if reading successfully, it is preset value to judge the content in the design variables, the state value that preset value correspondence specified button is pressed or lifted, if so, then being reported key-press status according to the event functions.The present invention can effectively situation is pressed or lifted to physical button in detecting system.
Description
Technical field
Field, more particularly to a kind of button monitor method based on Linux inner core are driven the present invention relates to linux system
And system.
Background technology
Button is one of most-often used mode of man-machine interaction under development, almost most equipment all possess have by
This input method of key.But button of the prior art monitors the detection success for being unable to effective detection and cannot ensure button
Rate.
The content of the invention
The technical problem to be solved in the present invention is to be directed to button monitoring in the prior art and is unable to effective detection and can not be true
Protect button detection success rate defect there is provided one kind effectively reach detect button purpose while can effectively ensure again by
The button monitor method based on Linux inner core and system of the detection success rate of key.
The technical solution adopted for the present invention to solve the technical problems is:
A kind of button monitor method based on Linux inner core is provided, comprised the following steps:
Operating system opens the button monitoring file under preset path, and button monitoring file correspondence is empty by linux kernel
Intend turning to the specified button of device node, the button monitoring file includes a self-defined letter for being used to monitor the specified button
The polling cycle of detection button is provided with number, the SQL and the event functions of key-press status are reported;
Operating system reads the button monitoring file according to the polling cycle of the setting with polling mode, and by the button
Content in monitoring file is read in design variables;
Whether if reading successfully, it is preset value to judge the content in the design variables, preset value correspondence specified button
The state value for being pressed or lifting, if so, then being reported key-press status according to the event functions.
Above-mentioned technical proposal is connect, the button monitoring file is pre-stored in the device file of linux system.
Above-mentioned technical proposal is connect, if the content in the button monitoring file is read successfully, the value more than or equal to 0 is returned to,
The value less than 0 is returned if failure is read.
Above-mentioned technical proposal is connect, if the content in the button monitoring file reads failure, default printf is called
Print error message.
Above-mentioned technical proposal is connect, when operating system reads the button monitoring file with polling mode, a poll is often completed
Cycle, then the polling cycle of the detection button is passed into a delay function to realize that delay, delay are entered back into down after terminating
Polling cycle once.
Above-mentioned technical proposal is connect, key-press status is reported especially by the form of function pointer.
Present invention also offers a kind of button monitoring system based on Linux inner core, including:
Monitoring file setup module, for specified button virtually to be turned into device node by linux kernel, the equipment section
Point shows as button monitoring file, and the button monitoring file includes a SQL for being used to monitor the specified button, should
The polling cycle of detection button is provided with SQL and the event functions of key-press status are reported;
Read module, is supervised for reading the button according to the polling cycle of the setting with polling mode by operating system
File is listened, and the content in the button monitoring file is read in design variables;
Module is monitored, for whether when read module is read successfully, it to be preset value to judge the content in the design variables,
The preset value correspondence specified button state value that is pressed or lifts, if so, then according to the event functions by key-press status
Report.
Above-mentioned technical proposal is connect, the button monitoring file is pre-stored in the device file of linux system.
Above-mentioned technical proposal is connect, the system also includes time delay module, is pressed for reading this in operating system with polling mode
During key monitoring file, a polling cycle is often completed, then the polling cycle of the detection button is passed into a delay function
Realize that delay, delay enter back into polling cycle next time after terminating.
Above-mentioned technical proposal is connect, the monitoring module reports key-press status especially by the form of function pointer.
The beneficial effect comprise that:The monitor method of the button of the present invention is implemented by linux system, passes through
Button is invented to a device node in Linux inner core, operating system reads the device node by way of poll
The value of file judges whether button is pressed or lifts, and the present invention can effectively physical button be pressed in detecting system
Or lift situation.The detection success rate of button can be effectively ensured again while detection button purpose is effectively accomplished.
Brief description of the drawings
Below in conjunction with drawings and Examples, the invention will be further described, in accompanying drawing:
Fig. 1 is the flow chart of button monitor method of the embodiment of the present invention based on Linux inner core;
Fig. 2 is the flow chart of button monitor method of the another embodiment of the present invention based on Linux inner core;
Fig. 3 is button monitoring system structural representation of the embodiment of the present invention based on Linux inner core;
Fig. 4 is button monitoring system structural representation of the another embodiment of the present invention based on Linux inner core;
Fig. 5 is button monitoring system structural representation of the third embodiment of the invention based on Linux inner core.
Embodiment
In order to make the purpose , technical scheme and advantage of the present invention be clearer, it is right below in conjunction with drawings and Examples
The present invention is further elaborated.It should be appreciated that specific embodiment described herein is only to explain the present invention, not
For limiting the present invention.
First related terms are explained below:
Linux:It is a set of free class Unix operating systems using with Free propagation, is one and is based on POSIX and UNIX
Multi-user, multitask, the operating system for supporting multithreading and multi -CPU.It can run main unix tool software, using journey
Sequence and procotol.It supports 32 and 64 hardware.Linux inherits design philosophys of the Unix using network as core, is one
The stable multiple-user network operating system of individual performance.
The method that the present invention proposes a set of monitoring system button in inner nuclear layer, being capable of effective physics in detecting system
The situation that button is pressed or lifted.
In one embodiment of the present of invention, as shown in figure 1, the button monitor method based on Linux inner core is including following
Step:
S101, operating system open the button monitoring file under preset path, and button monitoring file correspondence is by Linux
Core virtually turns to the specified button of device node, and the button monitoring file, which includes one, to be used to monitor the self-defined of the specified button
The polling cycle of detection button is provided with function, the SQL and the event functions of key-press status are reported;
S102, operating system read the button monitoring file according to the polling cycle of setting with polling mode, and this is pressed
Content in key monitoring file is read in design variables;
Whether if S103, reading successfully, it is preset value to judge the content in the design variables, and preset value correspondence is specified
The state value that button is pressed or lifted, if so, then performing step S104;
S104, according to event functions key-press status is reported, specifically report system application layer.
Preferably, button monitoring file is pre-stored in the device file of linux system.
Further, if the content in the button monitoring file is read successfully, the value more than or equal to 0 is can return to, if reading
Failure is taken then to return to the value less than 0.
If as shown in Fig. 2 the content also included in step S105, the button monitoring file reads failure, calling default
Printf print error message.
In step S102, when operating system reads the button monitoring file with polling mode, a polling cycle is often completed,
The polling cycle for detecting button then is passed into a delay function to realize that delay, delay enter back into poll next time after terminating
Cycle.
In step S104, key-press status can be reported into system application layer especially by the form of function pointer.Function refers to
A categorical variable can be designed in pin, this makes it possible to report away various key-press events.This design is carried significantly
The high autgmentability of the function, the extension for other key-press events of later stage serves extraordinary compatible act on.
In the preferred embodiment of the present invention, a SQL set_ for being used to monitor the specified button can be designed
Delt_ in key_listener (long delt_time, void ((void*)) key_fun (int fun_type)), the function
What time was represented is the time slice for detecting button, i.e. polling cycle, and what key_fun was represented is to detect the readjustment letter after button
Number, fun_type represents the key-press event information reported.
Designed SQL set_key_listener (long delt_time, void ((void*)) key_
Fun (int fun_type)) realize that logical method is as follows:
1st, the function defined in check_key.h files is declared
Need the definition of function being stored in check_key.h header files in C language development process, so subsequently
The mode of header file can be quoted to call the function included in header file.The method declared in the present embodiment in header file
It is as follows:
set_key_listener(long delt_time,void((void*))key_fun(int fun_type));
Next a simple illustration is done to this method.Set_key_listener is the title of the function of definition, should
Comprising 2 parameters in function, one is delt_time, what this parameter was represented is the polling cycle of the detection of button,
What ((void*)) key_fun (int fun_type) was represented is the callback information of function, is just passed through after key-press event is detected
The mode of ((void*)) key_fun (int fun_type) function pointer passes key information.
Benefit analysis:
A) definition of function is stored in check_key.h header file, so subsequently only needed when in use
To quote header file by include sentences is calling for realizable function
B) delt_time variables are devised, outside delt_time variables can be passed through so in the detection cycle of button
The detection cycle come inside fine regulation of value, it is ensured that the accuracy requirement of button detection and the balance of resource overhead.
C) type information of button is passed by the form of ((void*)) key_fun (int fun_type) function pointer
Pass the external world, the state flow of exposure button.
2nd, button poll detection method
Button detection is carried out in the present embodiment by way of button poll, polling method is exactly constantly to detect button
Whether it is pressed.All all files in linux system, so button is invented a device node and hung over by kernel
Under/dev/input/even files, judge whether button is pressed by constantly reading the value of this document.
Next describe how to read/dev/input/even device files.Pass through calling system body
Open methods open a device file, specifically int key_fd=open ("/dev/input/event ", O_
RDONLY) method opens a file.Wherein/dev/input/event represents the device file name for needing to open, O_
It in unfolding mode, the present embodiment is to open device file by read-only mode that what RDONLY was represented, which is,.Open functions will return to one
Individual device file descriptor, the device file descriptor is received using key_fd.
If key_fd, which is more than 0, represents File Open success, if key_fd, which is less than 0, represents file open failed.If
File open failed then needs to terminate to read and by the way that error message is printed, specifically printf (" open/dev/
input/event device error!N ") mode carrys out print error message.If File Open success, is next accomplished by
Read the information in file.
File, which is read, to be realized by polling mode, is realized wireless circulating using while (true) modes, is wirelessly being followed
The continuous content of reading/dev/input/event device nodes in ring.The mode of specific reading/dev/input/event contents
It is read (key_fd ,s &t, sizeof (t)), the content of this function is that the content in key_fd files is read into this change of t
In amount, the variable may be configured as global variable.If file reads successfully read (key_fd ,s &t, sizeof (t)) and will returned greatly
In the value equal to 0, if the value for being less than 0 will be returned to by reading failure read (key_fd ,s &t, sizeof (t)).
If reading have failed, it is necessary to printf (" read/dev/input/event device error!\n")
Mode carrys out print error message.
It is accomplished by taking out the content in variable t into the content judged in t is how many if read successfully.If t's
Value is 0 to mean that button is pressed, if t value is 1 to mean that button is lifted.
Complete every time after a read cycle, it is necessary to call a delay function sleep to transmit the detection of coming in simultaneously
Cycle delt_time is delivered in sleep functions, that is, calls sleep (delt_time) functions to realize delay, delay
Afterwards enter next time call the cycle.Such benefit is saving system of being tried one's best in the case of ensure that user's accuracy of detection
Expense.
Just the event being pressed is reported by the form of function pointer after button is pressed when detecting.
Benefit analysis:
A) in poll detection, equipment is opened and reading has been done verification and judged, if opening could successfully read, opens and loses
Lose meeting print prompt information and inform caller.
B) detection key-press event precision is adjustable, and we can set poll frequency by this parameter of delt_time, this
Sample ensures that caller can also reach the purpose for saving system resource while accuracy requirement is reached.
C) detect after key-press event and to be reported by function pointer ((void*)) key_fun (int fun_type),
Listener can timely get button situation of change.
3rd, the data readjustment logic of button is detected
When being pressed by detecting button in step 2, call back function (void*) key_fun will be passed through
(int fun_type) reports away key-press event.Implement is if by read (key_fd ,s &t, sizeof (t))
The value for the t that function is read is greater than being shown to be equal to 0, and a button is pressed, now needs call function pointer key_
Fun (KEY_DOWN) reports away key-press event, and what wherein KEY_DOWN was represented is a customized constant, the constant
Value be 1.
Why have a fun_type type adjust back away be for convenience other compatible key-press events of later stage carry out it is pre-
Work is stayed, the autgmentability of the function is improved.
By the call method of above-mentioned function pointer, we just inform the trigger event of button to outside, so outside
Portion can just get the information that button is pressed in real time.
Benefit analysis:A categorical variable is devised in function pointer (void*) key_fun (int fun_type), this
Sample I various key-press events can just can be reported away.It is this to design the autgmentability for substantially increasing the function,
Extension for other key-press events of later stage serves extraordinary compatible effect.
In order to realize above-described embodiment, present invention also offers the button monitoring system based on Linux inner core, such as Fig. 3
Shown, convering system includes:
Monitoring file setup module, for specified button virtually to be turned into device node by linux kernel, the equipment section
Point shows as button monitoring file, and the button monitoring file includes a SQL for being used to monitor the specified button, should
The polling cycle of detection button is provided with SQL and the event functions of key-press status are reported;Button monitoring file can
It is pre-stored in the device file of linux system.
Read module, text is monitored for reading the button according to the polling cycle of setting with polling mode by operating system
Part, and the content in the button monitoring file is read in design variables;
Module is monitored, for whether when read module is read successfully, it to be preset value to judge the content in the design variables,
The state value that preset value correspondence specified button is pressed or lifted, if so, then being reported key-press status according to event functions.
In one embodiment of the present of invention, if the content in the button monitoring file is read successfully, return and be more than or equal to 0
Value, if read failure if return less than 0 value.Further, the monitoring module can specifically be incited somebody to action by the form of function pointer
Key-press status is reported.
As shown in figure 4, the system also includes time delay module, monitored for reading the button in operating system with polling mode
During file, a polling cycle is often completed, then passes to a delay function to realize delay by the polling cycle for detecting button, prolongs
When terminate after enter back into polling cycle next time.
As shown in figure 5, the system may also include print module, failure is read for the content in the button monitoring file
When, call default printf print error message.
To sum up, the present invention passes through wheel by the way that button to be invented to a device node, operating system in Linux inner core
The mode of inquiry reads the value of the device node file to judge whether button is pressed or lifts, and the present invention can be examined effectively
Physical button presses or lifts situation in examining system.
It should be appreciated that for those of ordinary skills, can according to the above description be improved or converted,
And all these modifications and variations should all belong to the protection domain of appended claims of the present invention.
Claims (10)
1. a kind of button monitor method based on Linux inner core, it is characterised in that comprise the following steps:
Operating system opens the button monitoring file under preset path, and button monitoring file correspondence is virtual by linux kernel
The specified button of device node is turned to, the button monitoring file includes a SQL for being used to monitor the specified button,
The polling cycle of detection button is provided with the SQL and the event functions of key-press status are reported;
Operating system reads the button monitoring file according to the polling cycle of the setting with polling mode, and the button is monitored
Content in file is read in design variables;
Whether if reading successfully, it is preset value to judge the content in the design variables, the preset value correspondence specified button by by
State value that is lower or lifting, if so, then being reported key-press status according to the event functions.
2. the button monitor method according to claim 1 based on Linux inner core, it is characterised in that the button prison
File is listened to be pre-stored in the device file of linux system.
3. the button monitor method according to claim 1 based on Linux inner core, it is characterised in that if the button is supervised
Listen the content in file to read successfully, then return to the value more than or equal to 0, the value less than 0 is returned if failure is read.
4. the button monitor method according to claim 1 based on Linux inner core, it is characterised in that if the button is supervised
Listen the content in file to read failure, then call default printf print error message.
5. the button monitor method according to claim 1 based on Linux inner core, it is characterised in that operating system with
When polling mode reads the button monitoring file, a polling cycle is often completed, then is passed the polling cycle of the detection button
A delay function is passed to realize that delay, delay enter back into polling cycle next time after terminating.
6. the button monitor method according to claim 1 based on Linux inner core, it is characterised in that especially by letter
The form of number pointer reports key-press status.
7. a kind of button monitoring system based on Linux inner core, it is characterised in that including:
Monitoring file setup module, for specified button virtually to be turned into device node by linux kernel, the device node table
It is now button monitoring file, the button monitoring file includes a SQL for being used to monitor the specified button, and this is made by oneself
The polling cycle of detection button is provided with adopted function and the event functions of key-press status are reported;
Read module, text is monitored for reading the button according to the polling cycle of the setting with polling mode by operating system
Part, and the content in the button monitoring file is read in design variables;
Module is monitored, for when read module is read successfully, whether to be preset value, this is pre- if judging the content in the design variables
If the state value that value correspondence specified button is pressed or lifted, if so, then being reported key-press status according to the event functions.
8. the button monitoring system according to claim 7 based on Linux inner core, it is characterised in that the button prison
File is listened to be pre-stored in the device file of linux system.
9. the button monitoring system according to claim 7 based on Linux inner core, it is characterised in that the system is also wrapped
Time delay module is included, for when operating system reads the button monitoring file with polling mode, often completing a polling cycle, then
The polling cycle of the detection button is passed into a delay function to realize that delay, delay enter back into wheel next time after terminating
The inquiry cycle.
10. the button monitoring system according to claim 7 based on Linux inner core, it is characterised in that the monitoring mould
Block reports key-press status especially by the form of function pointer.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710168451.XA CN107015803A (en) | 2017-03-21 | 2017-03-21 | Button monitor method and system based on Linux inner core |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710168451.XA CN107015803A (en) | 2017-03-21 | 2017-03-21 | Button monitor method and system based on Linux inner core |
Publications (1)
Publication Number | Publication Date |
---|---|
CN107015803A true CN107015803A (en) | 2017-08-04 |
Family
ID=59440665
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710168451.XA Pending CN107015803A (en) | 2017-03-21 | 2017-03-21 | Button monitor method and system based on Linux inner core |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107015803A (en) |
Cited By (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108039945A (en) * | 2017-12-11 | 2018-05-15 | 北京奇虎科技有限公司 | A kind of endorsement method of service packs, method of calibration and device |
CN109951591A (en) * | 2019-03-12 | 2019-06-28 | 上海龙旗科技股份有限公司 | Mobile phone device abnormality monitoring method and equipment |
CN114371978A (en) * | 2022-01-07 | 2022-04-19 | 北京仁光科技有限公司 | Method, device, apparatus and system for android to acquire data |
CN116483294A (en) * | 2023-06-25 | 2023-07-25 | 闪捷信息科技有限公司 | Printer watermark adding method and device based on Linux kernel management and control |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2009296320A (en) * | 2008-06-05 | 2009-12-17 | Nec Corp | Monitoring control integrating device, transmission device, and monitoring control method, and program |
CN104378682A (en) * | 2014-11-14 | 2015-02-25 | 乐视致新电子科技(天津)有限公司 | Key counting method based on android system and smart television based on android system |
CN104506941A (en) * | 2014-12-11 | 2015-04-08 | 中国科学院声学研究所 | Key event processing method and device in smart television |
CN105681878A (en) * | 2016-01-15 | 2016-06-15 | 南京熊猫电子股份有限公司 | Device and method for controlling smart set top box through smart phone |
-
2017
- 2017-03-21 CN CN201710168451.XA patent/CN107015803A/en active Pending
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
JP2009296320A (en) * | 2008-06-05 | 2009-12-17 | Nec Corp | Monitoring control integrating device, transmission device, and monitoring control method, and program |
CN104378682A (en) * | 2014-11-14 | 2015-02-25 | 乐视致新电子科技(天津)有限公司 | Key counting method based on android system and smart television based on android system |
CN104506941A (en) * | 2014-12-11 | 2015-04-08 | 中国科学院声学研究所 | Key event processing method and device in smart television |
CN105681878A (en) * | 2016-01-15 | 2016-06-15 | 南京熊猫电子股份有限公司 | Device and method for controlling smart set top box through smart phone |
Non-Patent Citations (1)
Title |
---|
MFCAI: ""linux下获取按键响应事件"", 《WWW.ITEYE.COM/BLOG/STARATSKY-1734631》 * |
Cited By (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108039945A (en) * | 2017-12-11 | 2018-05-15 | 北京奇虎科技有限公司 | A kind of endorsement method of service packs, method of calibration and device |
CN109951591A (en) * | 2019-03-12 | 2019-06-28 | 上海龙旗科技股份有限公司 | Mobile phone device abnormality monitoring method and equipment |
CN114371978A (en) * | 2022-01-07 | 2022-04-19 | 北京仁光科技有限公司 | Method, device, apparatus and system for android to acquire data |
CN116483294A (en) * | 2023-06-25 | 2023-07-25 | 闪捷信息科技有限公司 | Printer watermark adding method and device based on Linux kernel management and control |
CN116483294B (en) * | 2023-06-25 | 2023-09-01 | 闪捷信息科技有限公司 | Printer watermark adding method and device based on Linux kernel management and control |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107015803A (en) | Button monitor method and system based on Linux inner core | |
CN108364645A (en) | A kind of method and device for realizing page interaction based on phonetic order | |
CN103870260B (en) | The method and system of business interface exploitation | |
CN105721660B (en) | Harassing call recognition methods and system | |
CN107357580A (en) | A kind of method that guiding terminal user opens the miscellaneous function authority of application | |
CN109067597A (en) | A kind of distributed system dynamic and intelligent service administering method | |
CN107168850A (en) | A kind of URL pages monitoring method and device | |
CN109684155A (en) | Monitor configuration method, device, equipment and readable storage medium storing program for executing | |
CN103605575B (en) | A kind of Cloud Foundry platform applications dispatch system and method | |
CN107861797A (en) | A kind of method for early warning and device based on JVM | |
CN104063303B (en) | A method of obtaining and discharge root authority | |
CN108345527A (en) | A kind of interface enters the analysis monitoring method and system of ginseng | |
CN109753419A (en) | A kind of method and device of the abnormal log information of all applications of non-invasive monitoring Android system | |
CN109614164A (en) | Realize plug-in unit configurable method, apparatus, equipment and readable storage medium storing program for executing | |
CN115794313A (en) | Virtual machine debugging method, system, electronic equipment and storage medium | |
CN108039956A (en) | Using monitoring method, system and computer-readable recording medium | |
CN105635231A (en) | Calling method and apparatus of distributed system | |
CN107368326A (en) | Course control method and device | |
CN109669785A (en) | Page sharing method, device, server and the storage medium of terminal applies | |
CN107612755A (en) | The management method and its device of a kind of cloud resource | |
CN106933681B (en) | It is a kind of multipair as blocking method and its system | |
CN106775861A (en) | Self monitor method and its system of application program unloading | |
CN116302989A (en) | Pressure testing method and system, storage medium and computer equipment | |
CN106940647B (en) | Code management method and device | |
CN110069922A (en) | A kind of system interface kidnaps detection method, device and terminal |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20170804 |
|
RJ01 | Rejection of invention patent application after publication |