Global mouse hook on click events in X11 [closed] - c++

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've read a lot of information about X11 graphic system and found a lot of questions about this issue without answer. So let me ask onу more time.
I need classic implementation of hook mechanism (like SetWindowsHookEx) or any other approach in UNIX-like operation systems with ONLY ONE CONDITION : ability to listen events without blocking original event (like XGrabButton and XUngrabButton do).
P.S. Ben, this is Danila. I need help! ®

I've ended up by grabbing source code from Xnee - it allows record all input events, including keyboard and mouse with non-blocking logic. The only restriction is that I have to ask if there any events in loop with 100ms interval, but it's ok for me - there is no processor loading at all.

Not possible do globally (all events/all windows) unless you read low level communication (using pcap or replacing real xserver with proxy that gives you all the data)
To get notification for particular window you change event mask of that window. Server keeps separate copy of event mask for a window per client, and notifies each client interested in events matching mask. For example, if you add PointerMotion bit to root window event mask from your connection you'll get pointer events when mouse moves over root window (given it's visible)

Related

Handle multiple events in gpio [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I'm new to embedded programming and I apologise in advance for any confusion.
I need to handle multiple events from different devices connected to a gpio. These events need to be monitored continually. This means that after one event is generated and handled, the code needs to keep monitoring the device for other events.
I understand the concept of interruptions and polling in Linux (the kernel gets an interruption and dispatch it to the handler which goes on up to the callee of an epoll which is inside an infinite loop while(1)-like).
This is fine for one-time, single-event toy models. In a embedded system with limited resources such as the AT91SAM9x5 that runs at 400mhz and has 128mb of ram what can I do ? I believe that the while(1)-like pattern isn't the best choice. I've heard good things about thread pool solution but at the heart of each thread don't we find a while(1) ?
What are my options to attack this problem ?
Thank you in advance !
For an embedded system, the AT91SAM is actually quite "resource rich" rather than resource limited. The idea is the same as if you writing it using Linux: you set up a pin interrupt, and in your interrupt handler, you do some minimal processing and maybe set up some global data so that your main loop "while (1)" can detect the situation and then process the information in the non-interrupt context. Basically you want the interrupt handler to finish as quickly as possible so that it can handle the next interrupt.
In most systems, interrupts can be pended or nested. With systems that allow nested interrupts, you have to make sure that it does not trash the context of the previous interrupt that is still being executed.
The actual communication scheme between the interrupt handler and the main code depends on your requirement. You can even use an RTOS with support for such requirements.
It depends a lot on what is your application and what are your constrains but here are some of the common methods to monitor gpio pins for event
In many of the newer controllers, all GPIO pins are capable of generating a combined interrupt. You can use this to trigger an ISR call on any change on any of the pins and then inside the ISR detect which specific pin triggered it.
If there is nothing else your controller should be doing, then there is nothing wrong is a while(1) loop continuously monitoring all port pins and triggering relevant actions
If none of the above solutions are acceptable, you can perhaps try to load a small OS like FreeRTOS on your controller and then use different tasks to monitor port pins
A lighter version of the above method is to have a configure a timer interrupt and poll for all the port pins inside it. You can then save the state of pins in global variable and use that in the main loop to take relevant actions.

System Architecture using Amazon SQS [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
I am modeling a system (A) that notifies system (B) when something changes on system (C).
So my my system (A) just make pooling on system (C), using an API and when something changes then notifies system (B).
The system (C) stores status about an order. This status can be X, Y, Z.
It can take minutes to hours for the order to transition from state X to Y. And it can take days for the order to transition from Y to Z.
If I model my system just using one queue, I think I going to have some problems.
I could have a moment that I will have much more message from state Y-->Z than state X-->Y because the Y-->Z has a update time greater than X-->Y.
So it is going to take a long time to process X-->Y. To prevent this I think I have to clone the message and re-enqueue it, to put it back to end of the queue.
Instead of one queue, I can have two queues, one for each status.
I simplify the problem. In the original problem I can have multiple status. (I think it is 5 status).
Do you guys have a suggestion?
Keeping the queue separate for each status is best option for your use case as you don't have to worry or tune one queue for handling both the status.
Queue system are not fail-safe. Queue parser must be able to handle application crash.
If required, implement process to make sure queue are not processes twice. (program might read but failed to consumed the message after processing )
Implement a failed safe house keeping process that republish works IF queue server went down and wipe all the message with it.
Amazon SQS maximum message retention period are 14 days. Even for own MQ server, it is high risk to store "long term" message.
Whether your X-->Y , or Y-->Z process that take different processing timeframe , it doesn't matter. If you publish message to queue ASAP when change is trigger(say Y--> Z changes happens after 24 days), then there should be no waiting issues. IMHO, I see no reason you raise question about "re-enqueue".

MFC application that uses Serial Ports [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
For my thesis I'm given an application written in visual c++ and using MFC that receives gps data (NMEA 183 (RMC)), the data is received from UDP and/or a Serial port (COM port) (they have to work separatly or together). The UDP part of the application is done and its working (written by another student before me), so I have to finish the Serial port part, but here comes my problem, it turns out that MFC does not support COM ports or at least doesn't have a class for serial ports, I found some serial port implementation on the internet: LINK, but I dont know how to integrate it and make it work, it turns out that the UDP part is working like an event triggering mechanism using virtual function CAsyncSocket::OnReceive. I was wondering if its posible to make anything similar to this working with Serial Ports?
Thank you for your help.
Best Regards.
If your program is a GUI then it is a good idea to run the serial port code in a separate worker thread. ReadFile can take a long time to get serial data and this would block the GUI message processing if it was done in the main thread. To provide notification events from the serial thread to the main (GUI) thread you can use PostMessage with a user-defined message. An example of doing this is at
http://vcfaq.mvps.org/mfc/12.htm

Programming a motor connected to computer through CAN communication? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a motor connected to my computer, which is connected through CAN to the motor. Basically, I have a USB-to-CAN adapter, to which I connect a USB cable from my computer. Then, from the adapter, the motor is connected through CAN.
Now, I wish to send data to the motor- I already know what sequence of bytes I need to send, but I'm not sure what commands to use to "talk" to my motor that is connected through CAN. I have been able to send data by direct USB connection from my computer to motor (using the WriteFile command in C++), but this method does not work for CAN.
Are there any libraries/functions that I can use to talk to my motor via CAN in C++?
Since you cannot connect a motor directly to a CAN bus, there must be some sort of motor controller, drive or I/O controller between the bus. Details of this device are required in order to advise on a more than fundamental level.
CAN itself does not define an application layer protocol, and several application protocols exist for CAN, such as CANopen, DeviceNet and SDS. Your device may use such a protocol or possibly something entirely proprietary. Your starting point should be the documentation for your I/O device.
For testing, most PC CAN adapter manufacturers will provide some sort of debug or development tool that allows you to construct and send individual messages and message sequences at a low-level; such a tool will allow you to verify the operation of the bus and I/O device.

Microphone Specific Signal to activate interupt [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
A heads up, i am very new to audio so please bear with me =)
I am trying to interpret audio signals into an AVR (its a classical myAVR MK2 board). Now normally, the interupt signal is always some kind of switch. So if i press this swich, go into that interupt.
My goal is to interpret audio signals via microphone into the board, and have the board react to it. My first question is, when sending the microphone signal, do i have to put it through the A/D Converter, since technically it is an anolag signal ??
My second and more complicated question is, how would i actually interpret the audio signal coming in?
For example, if i scream "GREEN" then what ever the programm was doing should be stopped, the interupt should be called and the green LED should come on. Now the mic is preatty much always on ... how do i control so that only if GREEN is said, the interupt signal is sent. I dont want him constantly going in and out of the interupts just because someone made some noise ...
Would i have to save "GREEN" as a bit-combination somewhere and compare the incoming signal with the saved bits ... or ??
Some answers:
...do i have to put it through the A/D Converter, since technically it is an anolag signal ?
Yes, digital chips may fry when exposed to analog signals.
Be aware that you may have delay some time after starting the ADC before the signals are accurate.
how would i actually interpret the audio signal coming in?
Basically you have digital values coming in at a frequency. You will need to store those values and then analyze them. You must trade memory capacity/usage for accuracy. The more samples you take, the better your data and results; but this occupies more memory.
You will also need to filter out noise from the signal and from layered sounds.
You may get some benefits from researching on FFTs.
You should compare using "fuzzy logic" because in the real world, nothing is exact; for example your voice signal could be +/- 30 counts and still be "correct".