Showing posts with label logics. Show all posts
Showing posts with label logics. Show all posts

Android Input Device Events

Hi friends,

I have got task dealing with touch monitor. I have to implement multitouch in our project. In the middle, I wanted to see input events. My teammate gave me the keyword to see the input event and to manually send input event to any devices. I would like to put it here. So, Me and You can refer, when we want it...

Android getevent and sendevent 

ya, as you guess...
  • getevent is to read the input event from the device(/dev/input/device-name) and
  • sendevent is to write the input event to the device(/dev/input/device_name) manually
Before, the getevent and sendevent... Lets have a brief look into the input event...
Input Event : Basically inputs are written has (sequence of ) events in the device(/dev/input/event(device) in case of Linux). All input events comprise of three values namely,
  • Type  : type of the event like Key, Sync, Misc, LED, etc.
  • Code  : value corresponding to the key, which is pressed.
  • Value : Zero for release and One for click/press, in case of key press and mouse click event. some running number in other case( I don't have too much knowledge in it).
With these 3, OS will understand the input given by us and perform the action to the corresponding input.
 
Example : when we press key 2 in the keyboard... event sequence will be like the below

In ubuntu,  (I wrote a c program to read the input even from device and the output is below)
Event: type 4 (Misc), code 4 (ScanCode), value 458783   [Conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 1                             [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]
Event: type 4 (Misc), code 4 (ScanCode), value 458783    [conveying the event is scancode]
Event: type 1 (Key), code 3 (2), value 0                             [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]

In andriod,
Event: type 1 (Key), code 3 (2), value 1                             [key 2 pressed]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]
Event: type 1 (Key), code 3 (2), value 0                             [key 2 release]
Event: type 0 (Sync), code 0 (Sync), value 0                      [sync event]

This is for pressing the key 2 once... This will be written into the device, OS will read it and perform the actions.

ok now...

getevent : will print the event written into the device.
syntax    : getevent device
example : getevent /dev/input/event0
output    :  In android, it didn't say the scancode... but all the inputs are handled as scancodes. output is,
0001 0003 00000001
0000 0000 00000000
0001 0003 00000000
0000 0000 00000000

sendevent : will allow us to give the input in the terminal.
syntax       : sendevent device type code value.
example    : for writing key 2 into the device.
shell@android:/ # sendevent dev/input/event0 0000 0000 00000000
shell@android:/ # sendevent dev/input/event0 0001 0003 00000001
shell@android:/ # sendevent dev/input/event0 0000 0000 00000000
shell@android:/ # sendevent dev/input/event0 0000 0000 00000000


P.S. : Remember the two points below,

  1.  Run it in the android shell.
  2.  Should have root permission.


FUZZY LOGIC

Hi friends,
One of my junior asked me about FUZZY LOGIC.. so i learned about it.. i would like to share it with you all..
so it is..

FUZZY LOGIC
if you ask me for the definition.. i would say as it is given in the Wikipedia..
"Fuzzy logic is a form of many-valued logic derived from fuzzy set theory to deal with reasoning that is robust and approximate rather than brittle and exact."
but if you ask me to explain.. i would be saying as below..

if someone is asked to write coding for controlling the fan switch.. probably the algorithm would be as
=>IF temperature IS HOT, switch ON the fan.. ELSE, switch OFF the fan..
this is crisp logic.. binary logic.. the term hot is considered as TRUE(1) and the rest considered as FALSE(0)..so when the sensor gives certain value nearer to hot and more than the median.. it will be considered as TRUE(1)..

But in the case of FUZZY LOGIC.. there are many values are given between the TRUE and FALSE..
if we are writing the same program in FUZZY LOGIC.. the coding would be..
=>IF temperature IS very cold THEN stop fan
=>IF temperature IS cold THEN turn down fan
=>IF temperature IS normal THEN maintain level
=>IF temperature IS hot THEN speed up fan
Thus the TRUE (1) and the FALSE(0) as many values between them.. fuzzy works on IF... THEN.. rather than IF.. ELSE..

In case of FUZZY LOGIC, we have ranges between the TRUE and FALSE..

if you ask for another example..
consider a 100ml glass with 30ml water in it.. and someone is asking, is that glass full?..


case i:  if you are saying that glass is empty since the water is less than half of the glass... then this is crisp(binary) logic...

case ii: if  you are saying that glass is 30% full and 70% empty.. then this is FUZZY LOGIC..

the control system designed using this logic is FUZZY CONTROL SYSTEM...

hope i have explained mean for FUZZY LOGIC.. if you have any clarification.. post me.. i will clear it..

Older Posts Home

About Me

My photo
Hi everyone,myself Alagappan...electronic and communication engg. student... living in madurai... interested in everything... want to achieve something great in my lifetime...

Followers


Recent Comments