Blender game engine events with python - blender

We're searching for a way to script events in BGE instead of using there build in GUI version where you are using your mouse to make events trigger your scripts. Isn't there a way to use events with python directly? Thanks in advance.

The only way to bypass the BGE event system is to read events with Python (which by it's nature inefficient).
You can read keyboard and mouse events or verify the scene with own algorithms.
I suggest to trigger code that depends on keyboard events with a keyboard sensor (allKeys mode) to get a better performance rather then an always sensor.

Related

Using EXTI line for software event

I'm using STM32F4 and I want to generate a pulse. the question is how do I know the pulse is generated by set certain bit of swier in exti or not? is there any way to detect the generated pulse, or any alternative way to indicate that? how should I do to achieve that way with std library?
any code to config exti for soft event mode, and how to detect or indicate generated pulse
The "pulse generator" in the diagram is merely a description of how the event generation hardware works. It is not a user accessible function.
The difference between an interrupt and an event is not clear in ST's manuals, but an interrupt signals the NVIC, and will result in the associated handler code being executed, while an event is used to directly signal a peripheral device.
So here if the configured EXTI edge occurs, and the corresponding event mask bit is set, a pulse is generated signalling some other internal on-chip peripheral.
there any way to detect the generated pulse
Not in the context of that diagram. It is probably irrelevant to whatever it is you are trying to do.
how should I do to achieve that way with std library?
Classic X-Y problem, you have fixated a solution and are asking questions about the solution. You need to ask about the problem. Unfortunately it is entirely unclear what that problem is.
Moreover what "std library"? Are you using the older "standard peripheral library" or the abysmal CubeMX library?
If you want to simply generate an output pulse in response to an edge in an input, then most of the timer peripherals support that with zero software overhead. Search your parts reference manual for "One-pulse mode" in relation to any of the available timer peripherals.

core.wait command -- am I using pyglet or not?

I've set up an experiment in the Builder to obtain rapid reaction times to audio stimuli, and I've subsequently been playing with the code to get the experiment to do exactly what I want. In particular, I'd like very accurate reaction times, so the program would ideally hog the CPU from the onset of each stimulus until a fixed point afterwards, and record keypresses of "w" and "e" during this time.
In an attempt to achieve this, I've been resetting the clock at the start of the audio stimuli, then hogging the CPU for for 2secs, as follows:
event.clearEvents(eventType='keyboard')
response.clock.reset()
core.wait(2,2)
if response.status == STARTED:
theseKeys = event.getKeys(keyList=['w', 'e'])
This seems to work fine. However, I have one concern: the documentation for the core.wait command says:
If you want to obtain key-presses during the wait, be sure to use pyglet.
How would I know if I'm using pyglet? Is it automatic, or do I need to alter the script in some way to ensure that I'm using it?
This refers to the type of window (pyglet or pygame) that you are using to display your stimuli. PsychoPy will generally use pyglet, but to be sure, you can explicitly set the window type when you create it. See the window API at http://www.psychopy.org/api/visual/window.html:
winType : None, ‘pyglet’, ‘pygame’
If None then PsychoPy will revert
to user/site preferences
More importantly, make sure you are using the pyo audio library rather than the default pygame. Set this in the PsychoPy Preferences -> General -> Audio Library dialog box field. Pygame definitely has sound latency problems: you should assume that there is a substantial lag between telling a sound to play and sound actually being produced. Pyo does better apparently, but I think you should validate this independently in some way to ensure that your reaction times to auditory stimuli are meaningful.

OS X - broadcasting HID events

I have a USB gamepad that I'm attempting to write a user-space driver for. Originally, I wrote the driver to work with Linux (using libusb), and everything seems to work fine there.
Basically, I get all the useful data (e.g. X, Y coordinates and button presses) from the device and store it in an array that is printf'd onto the screen. Now I can get this far with OS X easily.
However, I don't know how to broadcast that data so it can be used by other applications. I realize that one workaround is to call CGEventCreateKeyboardEvent, where I could basically map the device's buttons to keystrokes. However, I would rather not use emulated keystrokes because some information (for example the X, Y coordinates) is difficult to represent as keystroke events.
I'm unfamiliar with IOKit, so is there a function available there (or somewhere else buried in Apple documentation) that will help me do this? And, if so, will I have to re-write my current driver to be able to utilize the IOKit/other-Apple-library way? Or is there some, super-easy-to-use function where I can take my data and send it to any foreground application?

Is QML worth using for Embedded systems which run around 600MHz and no GPU?

Im planning to build a Embedded system which is almost like an organizer i.e. which handles contacts, games, applications & wifi/2G/3G for internet. I planned to build the UI with QML because of its easy to use and quick application building nature. And to have a linux kernel.
But after reading these articles:
http://qt-project.org/forums/viewthread/5820 &
http://en.roolz.org/Blog/Entries/2010/10/29_Qt_QML_on_embedded_devices.html
I am depressed and reconsidering my idea of using QML!
My hardware will be with these configurations : Processor around 600MHz, RAM 128MB and no GPU.
Please give comments on this and suggest me some alternatives for this.
Thanks in Advance.
inblueswithu
I have created a QML application for Nokia E63 which has 369MHz processor, 128MB RAM. I don't think it has a GPU. The application is a Stop Watch application. I have animated button click events like jumping (jumping balls). The animations are really smooth even when two button jumps at the same time. A 600MHz processor is expected to handle QML easily.
This is the link for the sis file http://store.ovi.com/content/184985. If you have a Nokia mobile you can test it.
May be you should consider building QML elements by hand instead of doing it from Photoshop or Gimp. For example using Item in the place of Rectangle will be optimal. So you can give it a try. May be by creating a rough sketch with good amount of animations to check whether you processor can handle that. Even if it don't work as expected then consider Qt to build your UI.
QML applications work fine on low-specs Nokia devices. I have made one for 5800 XPressMusic smartphone without any problems.

Is it possible to reprogram a keyboard?

I mean the real USB keyboard, not a software keyboard driver.
I know that keybords differ, but in general is it easy/possible to reprogram / rewire it?
Maybe there are models that are easier to do that?
And yes, I can use soldering iron / hardware flash reprogrammer.
In general, no. Most keyboards that you find have a small bit of brains and a switch matrix and not much else. They have just enough brains to communicate over USB while scanning their switch matrix. The entire mess is in one mask-programmed chip that you can't change the programming of.
There are a few keyboards out there that do things like key remapping or macro programming in the keyboard, but they are pretty rare and/or pretty expensive. And, in my experience, pretty damned annoying when you accidentally hit the 'program macro' key accidentally.
You could, in theory, tear akeyboard apart, remove it's existing brains, install a micro-controller and write code to send whatever codes you want to the host when a given point on the switch matrix is hit. You'll need to work out what traces are what on the switch matrix, and you'll need to write/find micro-controller code to talk USB. And don't forget that a switch matrix is susceptible to ghosting effects (one keypress masks others), so don't try to put things like shift, control, alt on keys that are subject to ghosting.
If you don't/can't do the micro-controller work yourself, you could use something like an ipac (it's the micro-controller part that I just described) to do the job, but you'll have to get something that understands a switch matrix.
For some keyboards it is possible, as a recent hack of an Apple keyboard revealed.
yes. you need to remove the manufacturer's controller and wire in a programmable keyboard controller. the better controllers contain a rom to hold the key matrix. (essential keyboard functions and raw scancodes are segregated and remain untouched). a convenient windows app is used to create the matrix, then compile to a binary, then flash the rom.
search: FlexMatrix SK5100/SK5101 i think it does macros too! =D