In my autohotkey script, I remap key A to key B:
a::b
So now I have two buttons that act as B: A and B.
The problem I have is that each button independently produces KEYUP and KEYDOWN signals. For example, consider this sequence of events:
I press and hold B. The OS generates a KEYDOWN signal for B.
I additionally press and hold A. The OS generates another KEYDOWN signal for B.
I release A or B, but leave the other one pressed. The OS generates a KEYUP signal for B.
The app received a KEYUP signal for B, and thus thinks I stopped pressing B. Even though I'm still holding down a button that maps to B.
How can I suppress this extraneous KEYUP event? A KEYUP should only be generated when the last button is released.
Related
So im using gtkmm specifically here.
What I'm working on:
I'm implementing a feature in which when I press in a certain window a parameter is increased/decreased depending on if the mouse moves left/right.
What needs to be done:
To be able to somehow loop in the button press callback method -(doing so as each iteration would store the new value of the cursor position and compare it to the inital position to determine wheter increase value or decrease)- until the button is released.However the event which is sent remains the same so I cant just for example check to see if the events type becomes GTK_BUTTON_RELEASE. I have also tried to use a flag which is set to false in the button release call back, however the release callback isnt even called as the execution is stuck in the now infinite loop.
Thoughts
Im thinking maybe the solution could be a certain something to do with signals.
Update:
Gtk has two functions for doing what I was saying here exactly which are , gtk_events_pending(), and gtk_main_iteration(). Hever turns out having a limitless loop inside an event is considered a bad practise and its better to use other methods like here for example using GdkEventMotion, or other types.
I'm currently reading values from a PS/2 mouse, which is working perfectly! - I'm trying only to read from the mouse, when the mouse sends a clock signal (falling edge), so i'm trying to use a interrupt. This is some of my code so far:
Interrupt handler:
extern struct mouse mouseData;
CY_ISR(PS2_interrupt) {
ISR_getMouseData(&mouseData);
}
This interrupt is giving me the follwing result, which is perfect:
I'm moving the mouse to the right, and it's outputting the right thing, i can't however do anything in the main for loop. If i for instance print something on the display in the main loop, nothing happends, but it can still read data from the mouse, whenever the mouse is sending..
I found out that you should clear the interrupt using this function:
isr_PS2_clock_ClearPending()
When i write this function in the interrupt handler i'll get this:
This is the same movement at before, but as you can see, the data i corrupted. I can however execute things in the main loop, whenever the intterrupt is not called.
What am i doing wrong in terms of handling the interrupts?
Try to use isr_PS2_clock_ClearInterrupt() to clear the Flag
In the design of UML state charts it appears that I can chose to use either triggers or guard logic to achieve transitions between states.
So which is better to use? Given the same logic for transition, does a trigger behave any differently than a guard? What are the benefits/drawbacks of one over the other?
Are there perhaps differences depending on the particular tool, or does the UML standard strictly define the behaviors of either method of transition?
I'm presently using Simulink Stateflow to design a state machine.
Those two are different concepts.
Trigger is an event occurrence which enables the transition,
while guard is a condition that must be evaluated to true in order for the transition to proceed.
So you cannot use them interchangeably — they have different roles.
Also note that the default guard (if none is specified) is [true], so the trigger is often sufficient to move from one state to another.
Update:
Summary:
Trigger (event) is some new data (of any data type) that was received by the object.
Guard is boolean expression on some data that is alrady present in the object.
Trigger (event) is an outside event that some other actor fired - user has pressed a button, browser requested a page load, etc. So in the image above, every time user presses a digit on a digital lock it fires "pressed digit" event.
If the pin (sequence of digits) is valid, then the transition to unlocked state will be enabled.
Yet another way to look at it:
If you press a keyboard key the system fires a keypress event, that would be a trigger whose value is the pressed key. Then you can make a guard [pressedKey = enter] (guard is always a boolean expression).
However having just the guard is not enough here, because there would be nothing to compare against.
Strictly speaking, guards cannot be used without triggers.
UML 2.5.1 specification (Section 14.2.4.8, page 331) defines State Machine's transitions by the following BNF expression:
[<trigger> [‘,’ <trigger>]* [‘[‘ <guard>’]’] [‘/’ <behavior-expression>]]
While UML 2.0 defined them as:
<transition> ::= <trigger> [‘,’ <trigger>]* [‘[‘ <guard-constraint>’]’] [‘/’ <activity-expression>]
Triggers are defined as:
<trigger> ::= <call-event> | <signal-event> | <any-receive-event> | <time-event> | <change-event>
So, in both cases, there cannot be a transition with a guard that doesn't have any trigger.
The only exception, according to UML 2.5.1, are internal transitions, which are specified by:
{<trigger>}* ['[' <guard>']'] [/<behavior-expression>]
I am maintaining a project for a PLC written in ST. To implement a new feature I need to let cyclic program A know when an event happened in cyclic program B.
How is this generally done in ST? Do I simply use global variables or is there a different method? If I use global variables, how are these then protected from concurrent modification?
I use the X20 PLCs from B&R Automation.
Asynchronous communication is tricky.
So imagine a global A_DONE initialized to false, with B inspecting it occasionally. A runs, and sets A_DONE. B can react to this event... but what does it do if it needs to handle another event?
If you believe that the event that tells A to signal A_DONE occurs only long after B sees A_DONE, B can simply reset A_DONE to false (assuming this always happens before the next A_DONE event) and the cycle can repeat.
If A_DONE can occur "again" while B is handling the results of seeing A_DONE, B cannot just reset A_DONE: you might get a timing splinter in which B reads A_DONE, A sets A_DONE again and B then clears A_DONE; now you've lost an event. If that event is controlling your reactor emergency rods, this could be pretty bad because poof, B missed it.
In this case you will likely need a handshake from A to B and back. We add a signal from B back to A, call it A_DONE_SEEN, to let B tell A that it has processed the event. Then A sets A_DONE, waits for A_DONE_SEEN; A clears A_DONE, waits for A_DONE_SEEN to go false, and continues its business. If A_DONE needs to be set while A_DONE is already set, or A_DONE_SEEN is set, we know we missed an event and some disaster recovery procedure can be run. B watches for A_DONE, handles the A_DONE action, sets A_DONE_SEEN, watches for A_DONE going false, and sets A_DONE_SEEN_FALSE.
I don't know about your specific PLCs, but in many systems there are atomic operations that increment counts, etc. You could use this instead of the handshake.
Yes, you need to declare a variable that has a shared scope to both cyclic programs.
You can do this by using the existing global.var file or you can create a new variable file, and limit what programs can read or write to it by placing it within a "package" (folder in your project).
To create a new var declaration file...
-right click within the logical view
-add object
-select "file" category, and choose new file
-name, and change to "save as *.var" in the drop down
By default, the new variable declaration visibility will be limited to the package it is contained within. To verify this, right click the file and go to properties. Select the details tab.
There is no way to protect from concurrent modification, but you can use the cross reference tool to see where a selected variable is being written and read within your project. First build a cross reference, and then use the tab at the bottom.
Good luck!
I am trying to catch the enter/return key in a GtkEntry widget. Should I make a signal hander for key-press-event or key-release event?
Alternatively you could look at connecting to the "activate" signal which gets fired when the user hits enter or activates it through some other method.
It depends when you want to act on the event as either signal will do. If you handle key-press-event and the user holds down the key, then you'll keep getting signals. If you handle key-release-event then you'll only get one signal when the user releases the key.
I think most commonly you'll want to use key-release-event.