Good portable wiimote library with sound support? - c

I'm lookin for a portable wiimote library. I want to use the wiimote for the hardware it has (but I don't need to access any data stored on it).
Required features:
access to all the buttons (as an exception, no use of the power button is OK)
make the wiimote play sound
talk to nunchuks and classic controllers
preferably: make the wiimote rumble.
interface with C. Preferably native C. Bonus points for bindings with Haskell or python.
The library should port to Linux, Windows and OS X (in order of importance) and should be agnostic with respect to CPU architecture.
Anyone got a good suggestion?

Haven't use it (I've only read about the managed Wiimote library really), but you may want to check out wiiuse. It seems like the most complete of the native libararies.
Others include:
GlovePIE
WiiYourself

You can use my WiiMouse program to do this (which is based on the wiimotelib open source project), it allows you to connect via named pipes and play PCM sounds and use all the attachments including the MotionPlus, it even calculates the MotionPLus vectors for you, you can get it here:
http://home.exetel.com.au/amurgshere/wiimouse.phtml
See the download for an example on how to connect to a wiimote via named pipes and play sounds and stuff.

Related

finite state machine compiler for C to simulate network protocols

I was looking for a good state machine compiler so as to test some custom networking protocols. I looked at a few tools already such as Yakindu, Ragel(compiler), SCXML(language) but I was not sure if any of them could be used for networking protocols.
SCXML(language) looks good but I could not find any compilers specifically for C (scxmlcc is for C++). Does anyone know a compiler for C based on SCXML?
Yakindu tool looks promising, but I am not sure if network protocols like BGP/OSPF could be tested. Can anyone please give any pointers on this?
Ragel also looks good, but again I am not sure if complex network protocol clients can be generated using this compiler.
The reason I mentioned network protocols specifically is that I also want to be able to perform custom routines such as packet_create/packet_send (with custom packet sizes) etc as part of 'actions' after an 'event' occurs.
Do I need to always generate code from the state graph or Is there a way to directly interact with the states?
I am very new to FSMs, any help/advice/suggestion/links will be greatly appreciated.
The default Yakindu SCT C code generator generates plain C code that is agnostic of the concrete execution environment. This means you get a piece of standard C code that you can integrate into you own application manually. This manual integration means mapping events, operations, and variables between your application and the state machine. Additionally you have to trigger the state machine execution properly.
You can find some information on that in the user guide. You could also customize the code generators in order to match your needs but that makes only sense if the integration into the application always look the same and you want to integrate more than one or two state machines.
So if you provide some more information about the application side API that i could provide some hints how to integrate with the state machine.
We just finished our SCXML -> ANSI C transformation. Currently, it does everything but invocations. Here is a sample of generated ANSI C code, with user-supplied callbacks and the general scaffolding here. Performance measurements for a single microstep on a late 2015 MacBook Pro#3.1GHz are here.
Note that the scaffolding is in C++98 as we had to connect to a data-model implementation to pass the SCXML IRP tests. Generated source is ANSI C though. If you want to transform a SCXML state-chart you can use uscxml-transform as:
$ uscxml-transform -tc -i FILE_OR_URL -o GENERATED_HERE
For example, to print the generated C code for test144 from the SCXML IRP suite on STDOUT:
$ uscxml-transform -tc -i https://raw.githubusercontent.com/tklab-tud/uscxml/master/test/w3c/ecma/test144.scxml
Generated ANSI-C code passes all SCXML IRP tests but those for invocations and custom I/O processors.
LOKI is a new application designed to provide an easy way for programmers and system admistrators to interact with BGP networks. Use it to test your OSPF/BGP connections as well

How Can I control another programs?

my question is general for all languages, but I'm using only C, so, I would like to get answer in this one.
My question is, How Can I control the behavior of another applications that I didn't write?
For example:
How Can I fill this entry box (in
this site) using C? Do I need to
control the browser? (I'm using
firefox.)
Still in this example, How Can I open
another tab in this browser using C?
(see, I want to control this
application such another one)
How Can I embed a program im my one?
How Can I fill a database program using your gui, doing it by c?
and so on...
Thanks a lot!
There's no concrete or single answer to your (multiple) questions because every program varies. Short of the desired application having an API, you can resort to using low level Win32 commands to identify handles of processes and windows within those processes which you want to change/read. It's by no means a straightforward or scalable process though.
You'd have to interact with that programs API.
Some programs are scriptable and publish APIs that allow other programs to send commands to them. If your "target" app does something like this, then that will typically be your best bet.
If the app doesn't have a C API, then you probably can't control it in C. That doesn't mean it's impossible, only that you might need a different language. If your app is a Windows GUI app, you can use AutoIt to interact with the GUI programmatically.
Typically you use a program's application programming interface (API) to gain access to publicly available functions that let you accomplish tasks within that program. However, not every application has an API that you can use.
You should start by looking at the documentation of the application you're intending to take control of with your program and seeing if they have an API suitable for your needs.
Most of the time application need API to work with each other.
There is another way around to automatise actions done to applications (like an user would). For example on Windows there is an "language" named AutoIt which can interact with your computer.
I'm not really sure if this is what your seeking but it can do almost all the thing you asked for.
question is, How Can I control the behavior of another applications that I didn't write
Answer: that depends on the application and platform (linux, windows, mac, ...). It generally does not depend on your language of choice.
As an example, quite a lot of gtk/ kde programs on linux can be partially controlled via the dbus messaging bus. Those apps are designed to be controlled in that way.
I think firefox has a command line option to open a new website using an already running browser.
Applescript or automator on a mac can be used to control some apps too, I believe.
In short, make a separate question on what you want to do exactly, stating both platform and app you need to control.

OS independent clipboard copy/paste text in C

I'm working on a project that's supposed to work on both Windows and Linux (with an unofficial Mac port as well) that emulates a true colour system console.
My problem is that recently there appeared a request for textfield support (yes, console-based) and it would be cool to add the possibility of copying text to clipboard and pasting from it. Is there a way of achieving this that will:
be done in C (not C++),
work in both Windows and in Linux (preprocessor macros are an option if there's no platform-independent code),
require no extra libraries to link to?
Thanks in advance for your help.
If you're not using a cross platform UI library (like wx or something), then it sounds like you're just going to have to write native clipboard code for each platform you want to support.
Remember, on Macintoshes, you copy with Command-C, not Ctrl+C :)
The clipboard is inherently an operating system defined concept. The C language itself has no knowledge of what a clipboard is or how to operate on it. You must either interface directly with the OS, or use a portability library that does this on your behalf. There is no way around this.
Personally I would define my your own function
getClipboardText();
That is defined in two different header files (linux_clipboard.h, windows_clipboard.h, etc) and then do pre-proccessor stuff to load the appropriate one accordingly. I don't really code in C/C++ so I'm sorry if that didn't make any sense or is bad practice but that's how I'd go about doing this.
#if WIN32
#include windows_clipboard.h
#endif
That sort of thing
Remember:
For linux you have to deal with different window managers (Gnome, KDE) all with different ways of managing the clipboard. Keep this in mind when designing your app.
You may be able to communicate to the clipboard by using xclip. You can use this python script here to do this job via communicating with 'dcop' and 'klipper' here. That is for KDE, I do not know how it would be done under GNOME... You may also be able to do this independantly of either GNOME/KDE by using DBUS, although I cannot say 100% confidently on that either...
Just be aware, that for a truly cross-platform job, you have to take into account of the different GUI's such as under Linux, X is the main window manager interface and either GNOME/KDE sits on top of it..I am not singling out other GUI's such as FluxBox, WindowMaker to name but a few, and that there will be a lot of platform dependant code, and also in conjunction, you will be dealing with Windows clipboard as well..all in all, a big integrated code...
Have you not considered looking at the raw X programming API for clipboard support? Maybe that might be better as I would imagine, GNOME/KDE etc are using the X's API to do the clipboard work...if that is confirmed, then the work would be cut out and be independant of the major GUI interfaces...(I hope that would be the case as it would make life easier for your project!)
Perhaps using compile-time switches, for each platform...WIN, KDE, GNOME, MAC or use the one that is already pre-defined..
Hope this helps,
Best regards,
Tom.

Serial Port Communications

I am trying to create a GUI for a c code written in LINUX.
This code basically connects two systems, opens the serial port, writes data from one system to the other via the port.how do I go about this?
The development tools present with me are Qt designer version 3.3.5 and K Develop, which one should I use.and how to go about it?
In Linux, every hardware device is mapped to the file-system using standard file-system permissions.
If you're just using a simple serial port protocol under Linux, you can treat any serial port device as a file. Meaning, they can be opened, read, written and handled just using standard files.
The 'filename' for a serial port is typically /dev/ttyS0 or /dev/ttyUSB0 depending on the type of serial port. It is often symlinked to /dev/modem on regular distributions.
I think you may be looking in the wrong place. You should probably search the web for a tutorial on C++ programming, or get a book on it (there are plenty out there). Once you're comfortable with C++ (it'll take a while if you're not already), you can start to read about writing KDE applications. There are probably some introductory things to read on the KDE website, and don't forget that Google is your friend throughout the process ;-)
By the way, Qt Designer is just a program for doing GUI layouts, while KDevelop is a full featured IDE that combines Qt Designer, a text editor, and a bunch of other stuff. You can use KDevelop for writing anything from very simple "Hello World" C++ programs up to, well, something as complex as KDevelop itself.
If you've actually got to write the serial port part (I'm not clear on this from your question), the other system calls you'll need to know about are 'ioctl' and 'termios', to set various serial port parameters.
Seems your using QT. You should try QextSerialPort which is a serial port class for QT.
The doc.trolltech.com site has a huge amount of documentation. You should go definitely take a look.
I would use the latest available Qt library for your distro, since it is a new developpment.
Regarding the serial port C code, I would keep it and call it from your C++ code. Beware of time consuming operations that can ruin the interactive feeling of your app.

Is FindFirstChangeNotification the best API to use for file system change notification on windows?

I'm new to windows programming and I'm trying to get notified of all changes to the file system (similar to the information that FileMon from SysInternals displays, but via an API). Is a FindFirstChangeNotification for each (non-network, non-substed) drive my best bet or are there other more suitable C/C++ APIs?
FindFirstChangeNotification is fine, but for slightly more ultimate power you should be using ReadDirectoryChangesW. (In fact, it's even recommended in the documentation!)
It doesn't require a function pointer, it does require you to manually decode a raw buffer, it uses Unicode file names, but it is generally better and more flexible.
On the other hand, if you want to do what FileMon does, you should probably do what FileMon does and use IFS to create and install a file system filter.
There are other ways to do it, but most of them involve effort on your part (or take performance from your app, or you have to block a thread to use them, etc). FindFirstChangeNotification is a bit complicated if you're not used to dealing with function pointers, etc, but it has the virtue of getting the OS to do the bulk of the work for you.
Actually FileSystemWatcher works perfectly with shared network drives. I am using it right now in an application which, among other things, monitors the file system for changes. (www.tabbles.net).
You can use FileSystemWatcher class. Very efficient but cannot work with Network shared drives.

Resources