71 changed files with 13887 additions and 3 deletions
-
8AUTHORS
-
340COPYING
-
11README.md
-
8doc/Notes.txt
-
BINdoc/TuxSSV2-Tuxware-Libtuxdriver.odt
-
245include/tux_driver.h
-
233include/tux_driver.pas
-
404include/tux_driver.py
-
255src/log.c
-
63src/log.h
-
37src/svnrev.tmpl.h
-
54src/threading_uniform.h
-
76src/tux_audio.c
-
37src/tux_audio.h
-
128src/tux_battery.c
-
47src/tux_battery.h
-
1434src/tux_cmd_parser.c
-
61src/tux_cmd_parser.h
-
66src/tux_descriptor.c
-
67src/tux_descriptor.h
-
568src/tux_driver.c
-
65src/tux_error.c
-
55src/tux_error.h
-
192src/tux_eyes.c
-
47src/tux_eyes.h
-
650src/tux_firmware.c
-
121src/tux_firmware.h
-
196src/tux_flippers.c
-
48src/tux_flippers.h
-
269src/tux_hid_unix.c
-
46src/tux_hid_unix.h
-
240src/tux_hid_win32.c
-
47src/tux_hid_win32.h
-
96src/tux_hw_cmd.h
-
657src/tux_hw_status.c
-
365src/tux_hw_status.h
-
89src/tux_id.c
-
37src/tux_id.h
-
619src/tux_leds.c
-
95src/tux_leds.h
-
62src/tux_light.c
-
26src/tux_light.h
-
210src/tux_misc.c
-
55src/tux_misc.h
-
193src/tux_mouth.c
-
49src/tux_mouth.h
-
411src/tux_movements.c
-
63src/tux_movements.h
-
112src/tux_pong.c
-
27src/tux_pong.h
-
778src/tux_sound_flash.c
-
53src/tux_sound_flash.h
-
232src/tux_spinning.c
-
52src/tux_spinning.h
-
672src/tux_sw_status.c
-
127src/tux_sw_status.h
-
238src/tux_types.h
-
660src/tux_usb.c
-
202src/tux_usb.h
-
341src/tux_user_inputs.c
-
87src/tux_user_inputs.h
-
39src/version.h
-
60test/Makefile.unix
-
67test/Makefile.win32
-
4test/compile.bat
-
223test/main.c
-
BINtest/tada.wav
-
9test/test_macro.txt
-
78unix/Makefile
-
82win32/Makefile
-
602win32/libtuxdriver.dev
@ -0,0 +1,8 @@ |
|||
libtuxdriver was written by: |
|||
|
|||
Remi Jocaille <remi.jocaille@c2me.be> |
|||
|
|||
Contributors: |
|||
Frans Meulenbroeks aka eFfeM |
|||
Paul Rathgeb <paul.rathgeb@c2me.be> |
|||
David Bourgeois <david@jaguarondi.com> |
@ -0,0 +1,340 @@ |
|||
GNU GENERAL PUBLIC LICENSE |
|||
Version 2, June 1991 |
|||
|
|||
Copyright (C) 1989, 1991 Free Software Foundation, Inc. |
|||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
Everyone is permitted to copy and distribute verbatim copies |
|||
of this license document, but changing it is not allowed. |
|||
|
|||
Preamble |
|||
|
|||
The licenses for most software are designed to take away your |
|||
freedom to share and change it. By contrast, the GNU General Public |
|||
License is intended to guarantee your freedom to share and change free |
|||
software--to make sure the software is free for all its users. This |
|||
General Public License applies to most of the Free Software |
|||
Foundation's software and to any other program whose authors commit to |
|||
using it. (Some other Free Software Foundation software is covered by |
|||
the GNU Library General Public License instead.) You can apply it to |
|||
your programs, too. |
|||
|
|||
When we speak of free software, we are referring to freedom, not |
|||
price. Our General Public Licenses are designed to make sure that you |
|||
have the freedom to distribute copies of free software (and charge for |
|||
this service if you wish), that you receive source code or can get it |
|||
if you want it, that you can change the software or use pieces of it |
|||
in new free programs; and that you know you can do these things. |
|||
|
|||
To protect your rights, we need to make restrictions that forbid |
|||
anyone to deny you these rights or to ask you to surrender the rights. |
|||
These restrictions translate to certain responsibilities for you if you |
|||
distribute copies of the software, or if you modify it. |
|||
|
|||
For example, if you distribute copies of such a program, whether |
|||
gratis or for a fee, you must give the recipients all the rights that |
|||
you have. You must make sure that they, too, receive or can get the |
|||
source code. And you must show them these terms so they know their |
|||
rights. |
|||
|
|||
We protect your rights with two steps: (1) copyright the software, and |
|||
(2) offer you this license which gives you legal permission to copy, |
|||
distribute and/or modify the software. |
|||
|
|||
Also, for each author's protection and ours, we want to make certain |
|||
that everyone understands that there is no warranty for this free |
|||
software. If the software is modified by someone else and passed on, we |
|||
want its recipients to know that what they have is not the original, so |
|||
that any problems introduced by others will not reflect on the original |
|||
authors' reputations. |
|||
|
|||
Finally, any free program is threatened constantly by software |
|||
patents. We wish to avoid the danger that redistributors of a free |
|||
program will individually obtain patent licenses, in effect making the |
|||
program proprietary. To prevent this, we have made it clear that any |
|||
patent must be licensed for everyone's free use or not licensed at all. |
|||
|
|||
The precise terms and conditions for copying, distribution and |
|||
modification follow. |
|||
|
|||
GNU GENERAL PUBLIC LICENSE |
|||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION |
|||
|
|||
0. This License applies to any program or other work which contains |
|||
a notice placed by the copyright holder saying it may be distributed |
|||
under the terms of this General Public License. The "Program", below, |
|||
refers to any such program or work, and a "work based on the Program" |
|||
means either the Program or any derivative work under copyright law: |
|||
that is to say, a work containing the Program or a portion of it, |
|||
either verbatim or with modifications and/or translated into another |
|||
language. (Hereinafter, translation is included without limitation in |
|||
the term "modification".) Each licensee is addressed as "you". |
|||
|
|||
Activities other than copying, distribution and modification are not |
|||
covered by this License; they are outside its scope. The act of |
|||
running the Program is not restricted, and the output from the Program |
|||
is covered only if its contents constitute a work based on the |
|||
Program (independent of having been made by running the Program). |
|||
Whether that is true depends on what the Program does. |
|||
|
|||
1. You may copy and distribute verbatim copies of the Program's |
|||
source code as you receive it, in any medium, provided that you |
|||
conspicuously and appropriately publish on each copy an appropriate |
|||
copyright notice and disclaimer of warranty; keep intact all the |
|||
notices that refer to this License and to the absence of any warranty; |
|||
and give any other recipients of the Program a copy of this License |
|||
along with the Program. |
|||
|
|||
You may charge a fee for the physical act of transferring a copy, and |
|||
you may at your option offer warranty protection in exchange for a fee. |
|||
|
|||
2. You may modify your copy or copies of the Program or any portion |
|||
of it, thus forming a work based on the Program, and copy and |
|||
distribute such modifications or work under the terms of Section 1 |
|||
above, provided that you also meet all of these conditions: |
|||
|
|||
a) You must cause the modified files to carry prominent notices |
|||
stating that you changed the files and the date of any change. |
|||
|
|||
b) You must cause any work that you distribute or publish, that in |
|||
whole or in part contains or is derived from the Program or any |
|||
part thereof, to be licensed as a whole at no charge to all third |
|||
parties under the terms of this License. |
|||
|
|||
c) If the modified program normally reads commands interactively |
|||
when run, you must cause it, when started running for such |
|||
interactive use in the most ordinary way, to print or display an |
|||
announcement including an appropriate copyright notice and a |
|||
notice that there is no warranty (or else, saying that you provide |
|||
a warranty) and that users may redistribute the program under |
|||
these conditions, and telling the user how to view a copy of this |
|||
License. (Exception: if the Program itself is interactive but |
|||
does not normally print such an announcement, your work based on |
|||
the Program is not required to print an announcement.) |
|||
|
|||
These requirements apply to the modified work as a whole. If |
|||
identifiable sections of that work are not derived from the Program, |
|||
and can be reasonably considered independent and separate works in |
|||
themselves, then this License, and its terms, do not apply to those |
|||
sections when you distribute them as separate works. But when you |
|||
distribute the same sections as part of a whole which is a work based |
|||
on the Program, the distribution of the whole must be on the terms of |
|||
this License, whose permissions for other licensees extend to the |
|||
entire whole, and thus to each and every part regardless of who wrote it. |
|||
|
|||
Thus, it is not the intent of this section to claim rights or contest |
|||
your rights to work written entirely by you; rather, the intent is to |
|||
exercise the right to control the distribution of derivative or |
|||
collective works based on the Program. |
|||
|
|||
In addition, mere aggregation of another work not based on the Program |
|||
with the Program (or with a work based on the Program) on a volume of |
|||
a storage or distribution medium does not bring the other work under |
|||
the scope of this License. |
|||
|
|||
3. You may copy and distribute the Program (or a work based on it, |
|||
under Section 2) in object code or executable form under the terms of |
|||
Sections 1 and 2 above provided that you also do one of the following: |
|||
|
|||
a) Accompany it with the complete corresponding machine-readable |
|||
source code, which must be distributed under the terms of Sections |
|||
1 and 2 above on a medium customarily used for software interchange; or, |
|||
|
|||
b) Accompany it with a written offer, valid for at least three |
|||
years, to give any third party, for a charge no more than your |
|||
cost of physically performing source distribution, a complete |
|||
machine-readable copy of the corresponding source code, to be |
|||
distributed under the terms of Sections 1 and 2 above on a medium |
|||
customarily used for software interchange; or, |
|||
|
|||
c) Accompany it with the information you received as to the offer |
|||
to distribute corresponding source code. (This alternative is |
|||
allowed only for noncommercial distribution and only if you |
|||
received the program in object code or executable form with such |
|||
an offer, in accord with Subsection b above.) |
|||
|
|||
The source code for a work means the preferred form of the work for |
|||
making modifications to it. For an executable work, complete source |
|||
code means all the source code for all modules it contains, plus any |
|||
associated interface definition files, plus the scripts used to |
|||
control compilation and installation of the executable. However, as a |
|||
special exception, the source code distributed need not include |
|||
anything that is normally distributed (in either source or binary |
|||
form) with the major components (compiler, kernel, and so on) of the |
|||
operating system on which the executable runs, unless that component |
|||
itself accompanies the executable. |
|||
|
|||
If distribution of executable or object code is made by offering |
|||
access to copy from a designated place, then offering equivalent |
|||
access to copy the source code from the same place counts as |
|||
distribution of the source code, even though third parties are not |
|||
compelled to copy the source along with the object code. |
|||
|
|||
4. You may not copy, modify, sublicense, or distribute the Program |
|||
except as expressly provided under this License. Any attempt |
|||
otherwise to copy, modify, sublicense or distribute the Program is |
|||
void, and will automatically terminate your rights under this License. |
|||
However, parties who have received copies, or rights, from you under |
|||
this License will not have their licenses terminated so long as such |
|||
parties remain in full compliance. |
|||
|
|||
5. You are not required to accept this License, since you have not |
|||
signed it. However, nothing else grants you permission to modify or |
|||
distribute the Program or its derivative works. These actions are |
|||
prohibited by law if you do not accept this License. Therefore, by |
|||
modifying or distributing the Program (or any work based on the |
|||
Program), you indicate your acceptance of this License to do so, and |
|||
all its terms and conditions for copying, distributing or modifying |
|||
the Program or works based on it. |
|||
|
|||
6. Each time you redistribute the Program (or any work based on the |
|||
Program), the recipient automatically receives a license from the |
|||
original licensor to copy, distribute or modify the Program subject to |
|||
these terms and conditions. You may not impose any further |
|||
restrictions on the recipients' exercise of the rights granted herein. |
|||
You are not responsible for enforcing compliance by third parties to |
|||
this License. |
|||
|
|||
7. If, as a consequence of a court judgment or allegation of patent |
|||
infringement or for any other reason (not limited to patent issues), |
|||
conditions are imposed on you (whether by court order, agreement or |
|||
otherwise) that contradict the conditions of this License, they do not |
|||
excuse you from the conditions of this License. If you cannot |
|||
distribute so as to satisfy simultaneously your obligations under this |
|||
License and any other pertinent obligations, then as a consequence you |
|||
may not distribute the Program at all. For example, if a patent |
|||
license would not permit royalty-free redistribution of the Program by |
|||
all those who receive copies directly or indirectly through you, then |
|||
the only way you could satisfy both it and this License would be to |
|||
refrain entirely from distribution of the Program. |
|||
|
|||
If any portion of this section is held invalid or unenforceable under |
|||
any particular circumstance, the balance of the section is intended to |
|||
apply and the section as a whole is intended to apply in other |
|||
circumstances. |
|||
|
|||
It is not the purpose of this section to induce you to infringe any |
|||
patents or other property right claims or to contest validity of any |
|||
such claims; this section has the sole purpose of protecting the |
|||
integrity of the free software distribution system, which is |
|||
implemented by public license practices. Many people have made |
|||
generous contributions to the wide range of software distributed |
|||
through that system in reliance on consistent application of that |
|||
system; it is up to the author/donor to decide if he or she is willing |
|||
to distribute software through any other system and a licensee cannot |
|||
impose that choice. |
|||
|
|||
This section is intended to make thoroughly clear what is believed to |
|||
be a consequence of the rest of this License. |
|||
|
|||
8. If the distribution and/or use of the Program is restricted in |
|||
certain countries either by patents or by copyrighted interfaces, the |
|||
original copyright holder who places the Program under this License |
|||
may add an explicit geographical distribution limitation excluding |
|||
those countries, so that distribution is permitted only in or among |
|||
countries not thus excluded. In such case, this License incorporates |
|||
the limitation as if written in the body of this License. |
|||
|
|||
9. The Free Software Foundation may publish revised and/or new versions |
|||
of the General Public License from time to time. Such new versions will |
|||
be similar in spirit to the present version, but may differ in detail to |
|||
address new problems or concerns. |
|||
|
|||
Each version is given a distinguishing version number. If the Program |
|||
specifies a version number of this License which applies to it and "any |
|||
later version", you have the option of following the terms and conditions |
|||
either of that version or of any later version published by the Free |
|||
Software Foundation. If the Program does not specify a version number of |
|||
this License, you may choose any version ever published by the Free Software |
|||
Foundation. |
|||
|
|||
10. If you wish to incorporate parts of the Program into other free |
|||
programs whose distribution conditions are different, write to the author |
|||
to ask for permission. For software which is copyrighted by the Free |
|||
Software Foundation, write to the Free Software Foundation; we sometimes |
|||
make exceptions for this. Our decision will be guided by the two goals |
|||
of preserving the free status of all derivatives of our free software and |
|||
of promoting the sharing and reuse of software generally. |
|||
|
|||
NO WARRANTY |
|||
|
|||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
|||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
|||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
|||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED |
|||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
|||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS |
|||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE |
|||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, |
|||
REPAIR OR CORRECTION. |
|||
|
|||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
|||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
|||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, |
|||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING |
|||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED |
|||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY |
|||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER |
|||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE |
|||
POSSIBILITY OF SUCH DAMAGES. |
|||
|
|||
END OF TERMS AND CONDITIONS |
|||
|
|||
How to Apply These Terms to Your New Programs |
|||
|
|||
If you develop a new program, and you want it to be of the greatest |
|||
possible use to the public, the best way to achieve this is to make it |
|||
free software which everyone can redistribute and change under these terms. |
|||
|
|||
To do so, attach the following notices to the program. It is safest |
|||
to attach them to the start of each source file to most effectively |
|||
convey the exclusion of warranty; and each file should have at least |
|||
the "copyright" line and a pointer to where the full notice is found. |
|||
|
|||
<one line to give the program's name and a brief idea of what it does.> |
|||
Copyright (C) <year> <name of author> |
|||
|
|||
This program is free software; you can redistribute it and/or modify |
|||
it under the terms of the GNU General Public License as published by |
|||
the Free Software Foundation; either version 2 of the License, or |
|||
(at your option) any later version. |
|||
|
|||
This program is distributed in the hope that it will be useful, |
|||
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
GNU General Public License for more details. |
|||
|
|||
You should have received a copy of the GNU General Public License |
|||
along with this program; if not, write to the Free Software |
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|||
|
|||
|
|||
Also add information on how to contact you by electronic and paper mail. |
|||
|
|||
If the program is interactive, make it output a short notice like this |
|||
when it starts in an interactive mode: |
|||
|
|||
Gnomovision version 69, Copyright (C) year name of author |
|||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. |
|||
This is free software, and you are welcome to redistribute it |
|||
under certain conditions; type `show c' for details. |
|||
|
|||
The hypothetical commands `show w' and `show c' should show the appropriate |
|||
parts of the General Public License. Of course, the commands you use may |
|||
be called something other than `show w' and `show c'; they could even be |
|||
mouse-clicks or menu items--whatever suits your program. |
|||
|
|||
You should also get your employer (if you work as a programmer) or your |
|||
school, if any, to sign a "copyright disclaimer" for the program, if |
|||
necessary. Here is a sample; alter the names: |
|||
|
|||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program |
|||
`Gnomovision' (which makes passes at compilers) written by James Hacker. |
|||
|
|||
<signature of Ty Coon>, 1 April 1989 |
|||
Ty Coon, President of Vice |
|||
|
|||
This General Public License does not permit incorporating your program into |
|||
proprietary programs. If your program is a subroutine library, you may |
|||
consider it more useful to permit linking proprietary applications with the |
|||
library. If this is what you want to do, use the GNU Library General |
|||
Public License instead of this License. |
@ -1,4 +1,9 @@ |
|||
tuxdriver |
|||
========= |
|||
|
|||
New driver for TuxDroid (more infos here: http://forum.tuxdroid-community.org/viewtopic.php?id=205) |
|||
libtuxdriver is a shared library to control Tuxdroid. |
|||
|
|||
For all information about Tuxdroid, please visit: |
|||
|
|||
http://tuxdroid-community.org/ |
|||
http://www.tux-droid.eu/ |
|||
|
|||
|
@ -0,0 +1,8 @@ |
|||
Defines: |
|||
======== |
|||
|
|||
USE_MUTEX |
|||
LOCK_TUX |
|||
USB_DEBUG |
|||
USB_IDFRAME |
|||
GENERATE_DOC |
@ -0,0 +1,245 @@ |
|||
/* |
|||
* Tux Droid - Driver |
|||
* Copyright (C) 2008 C2ME Sa <Acness : remi.jocaille@c2me.be> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|||
* 02111-1307, USA. |
|||
*/ |
|||
|
|||
#ifndef _TUX_DRIVER_H_ |
|||
#define _TUX_DRIVER_H_ |
|||
|
|||
#include <stdbool.h> |
|||
|
|||
/** |
|||
* Id enumeration of high level status. |
|||
*/ |
|||
typedef enum { |
|||
SW_ID_FLIPPERS_POSITION = 0, |
|||
SW_ID_FLIPPERS_REMAINING_MVM, |
|||
SW_ID_SPINNING_DIRECTION, |
|||
SW_ID_SPINNING_REMAINING_MVM, |
|||
SW_ID_LEFT_WING_BUTTON, |
|||
SW_ID_RIGHT_WING_BUTTON, |
|||
SW_ID_HEAD_BUTTON, |
|||
SW_ID_REMOTE_BUTTON, |
|||
SW_ID_MOUTH_POSITION, |
|||
SW_ID_MOUTH_REMAINING_MVM, |
|||
SW_ID_EYES_POSITION, |
|||
SW_ID_EYES_REMAINING_MVM, |
|||
SW_ID_DESCRIPTOR_COMPLETE, |
|||
SW_ID_RF_STATE, |
|||
SW_ID_DONGLE_PLUG, |
|||
SW_ID_CHARGER_STATE, |
|||
SW_ID_BATTERY_LEVEL, |
|||
SW_ID_BATTERY_STATE, |
|||
SW_ID_LIGHT_LEVEL, |
|||
SW_ID_LEFT_LED_STATE, |
|||
SW_ID_RIGHT_LED_STATE, |
|||
SW_ID_CONNECTION_QUALITY, |
|||
SW_ID_AUDIO_FLASH_PLAY, |
|||
SW_ID_AUDIO_GENERAL_PLAY, |
|||
SW_ID_FLASH_PROG_CURR_TRACK, |
|||
SW_ID_FLASH_PROG_LAST_TRACK_SIZE, |
|||
SW_ID_TUXCORE_SYMBOLIC_VERSION, |
|||
SW_ID_TUXAUDIO_SYMBOLIC_VERSION, |
|||
SW_ID_FUXUSB_SYMBOLIC_VERSION, |
|||
SW_ID_FUXRF_SYMBOLIC_VERSION, |
|||
SW_ID_TUXRF_SYMBOLIC_VERSION, |
|||
SW_ID_DRIVER_SYMBOLIC_VERSION, |
|||
SW_ID_SOUND_REFLASH_BEGIN, |
|||
SW_ID_SOUND_REFLASH_END, |
|||
SW_ID_SOUND_REFLASH_CURRENT_TRACK, |
|||
SW_ID_EYES_MOTOR_ON, |
|||
SW_ID_MOUTH_MOTOR_ON, |
|||
SW_ID_FLIPPERS_MOTOR_ON, |
|||
SW_ID_SPIN_LEFT_MOTOR_ON, |
|||
SW_ID_SPIN_RIGHT_MOTOR_ON, |
|||
SW_ID_FLASH_SOUND_COUNT, |
|||
} SW_ID_DRIVER; |
|||
|
|||
#if defined(__cplusplus) |
|||
extern "C" { |
|||
#endif |
|||
|
|||
/** |
|||
* Error codes |
|||
*/ |
|||
#define TUX_ERROR_BEGIN 256 |
|||
typedef int TuxDrvError; |
|||
typedef enum |
|||
{ |
|||
E_TUXDRV_NOERROR = 0, |
|||
E_TUXDRV_PARSERISDISABLED = TUX_ERROR_BEGIN, |
|||
E_TUXDRV_INVALIDCOMMAND, |
|||
E_TUXDRV_STACKOVERFLOW, |
|||
E_TUXDRV_FILEERROR, |
|||
E_TUXDRV_BADWAVFILE, |
|||
E_TUXDRV_INVALIDIDENTIFIER, |
|||
E_TUXDRV_INVALIDNAME, |
|||
E_TUXDRV_INVALIDPARAMETER, |
|||
E_TUXDRV_BUSY, |
|||
E_TUXDRV_WAVSIZEEXCEDED, |
|||
} tux_drv_error_t; |
|||
|
|||
/** |
|||
* CPU number enumeration. |
|||
*/ |
|||
typedef enum { |
|||
TUXCORE_CPU_NUM = 0, |
|||
TUXAUDIO_CPU_NUM = 1, |
|||
TUXRF_CPU_NUM = 2, |
|||
FUXRF_CPU_NUM = 3, |
|||
FUXUSB_CPU_NUM = 4, |
|||
INVALID_CPU_NUM = -1, |
|||
} CPU_IDENTIFIERS; |
|||
|
|||
/** |
|||
* Descriptor structure of a firmaware. |
|||
*/ |
|||
typedef struct { |
|||
CPU_IDENTIFIERS cpu_id; |
|||
unsigned int version_major; |
|||
unsigned int version_minor; |
|||
unsigned int version_update; |
|||
unsigned int revision; |
|||
bool release; |
|||
bool local_modification; |
|||
bool mixed_revisions; |
|||
unsigned int author; |
|||
unsigned int variation; |
|||
char version_string[256]; |
|||
} firmware_descriptor_t; |
|||
|
|||
/** |
|||
* Descriptor structure of sound flash. |
|||
*/ |
|||
typedef struct { |
|||
unsigned int number_of_sounds; |
|||
unsigned int flash_usage; |
|||
unsigned int available_record_time; |
|||
} sound_flash_descriptor_t; |
|||
|
|||
/** |
|||
* Descriptor structure of ID connection. |
|||
*/ |
|||
typedef struct { |
|||
unsigned int number; |
|||
} id_descriptor_t; |
|||
|
|||
/** |
|||
* Global descriptor structure of tuxdroid. |
|||
*/ |
|||
typedef struct { |
|||
struct firmwares_t { |
|||
firmware_descriptor_t *package; |
|||
firmware_descriptor_t *tuxcore; |
|||
firmware_descriptor_t *tuxaudio; |
|||
firmware_descriptor_t *tuxrf; |
|||
firmware_descriptor_t *fuxrf; |
|||
firmware_descriptor_t *fuxusb; |
|||
} firmwares; |
|||
struct driver_version_t { |
|||
unsigned int version_major; |
|||
unsigned int version_minor; |
|||
unsigned int version_update; |
|||
unsigned int version_build; |
|||
char version_state[100]; |
|||
char version_string[100]; |
|||
} driver; |
|||
sound_flash_descriptor_t *sound_flash; |
|||
id_descriptor_t *id; |
|||
} tux_descriptor_t; |
|||
|
|||
/** |
|||
* Simple callback definition. |
|||
*/ |
|||
typedef void(*drv_simple_callback_t)(void); |
|||
|
|||
/** |
|||
* Status callback definition. |
|||
*/ |
|||
typedef void(*drv_status_callback_t)(char *status); |
|||
|
|||
/** |
|||
* Tokens structure |
|||
*/ |
|||
typedef char drv_token_str_t[1024]; |
|||
typedef drv_token_str_t drv_tokens_t[256]; |
|||
|
|||
/** |
|||
* Logging target |
|||
*/ |
|||
typedef enum log_target |
|||
{ |
|||
LOG_TARGET_TUX, |
|||
LOG_TARGET_SHELL |
|||
} log_target_t; |
|||
|
|||
/** |
|||
* Logging levels, in increasing priorities |
|||
*/ |
|||
typedef enum log_level |
|||
{ |
|||
LOG_LEVEL_DEBUG, |
|||
LOG_LEVEL_INFO, |
|||
LOG_LEVEL_WARNING, |
|||
LOG_LEVEL_ERROR, |
|||
LOG_LEVEL_NONE |
|||
} log_level_t; |
|||
|
|||
extern void TuxDrv_Start(void); |
|||
extern void TuxDrv_Stop(void); |
|||
|
|||
/** |
|||
* 31/08/2012 - Joël Maatteotti <sfuser: joelmatteitti> |
|||
*/ |
|||
extern bool TuxDrv_Eyes_cmd_off(void); |
|||
extern bool TuxDrv_Mouth_cmd_off(void); |
|||
extern bool TuxDrv_Spinning_cmd_off(void); |
|||
extern bool TuxDrv_Flippers_cmd_off(void); |
|||
extern char *TuxDrv_SoundFlash_dump_descriptor(char *p); |
|||
extern void TuxDrv_LightLevel_update(void); |
|||
/** ------------------------- */ |
|||
|
|||
|
|||
extern const char *TuxDrv_StrError(TuxDrvError error_code); |
|||
extern void TuxDrv_GetDescriptor(tux_descriptor_t *tux_desc); |
|||
extern void TuxDrv_SetStatusCallback(drv_status_callback_t funct); |
|||
extern void TuxDrv_SetEndCycleCallback(drv_simple_callback_t funct); |
|||
extern void TuxDrv_SetDongleConnectedCallback(drv_simple_callback_t funct); |
|||
extern void TuxDrv_SetDongleDisconnectedCallback(drv_simple_callback_t funct); |
|||
extern TuxDrvError TuxDrv_PerformCommand(double delay, char *cmd_str); |
|||
extern void TuxDrv_ClearCommandStack(void); |
|||
extern TuxDrvError TuxDrv_PerformMacroFile(char *file_path); |
|||
extern TuxDrvError TuxDrv_PerformMacroText(char *macro); |
|||
extern TuxDrvError TuxDrv_SoundReflash(char *tracks); |
|||
extern void TuxDrv_SetLogLevel(log_level_t level); |
|||
extern void TuxDrv_SetLogTarget(log_target_t target); |
|||
extern TuxDrvError TuxDrv_GetStatusName(int id, char* name); |
|||
extern TuxDrvError TuxDrv_GetStatusId(char* name, int *id); |
|||
extern TuxDrvError TuxDrv_GetStatusState(int id, char *state); |
|||
extern TuxDrvError TuxDrv_GetStatusValue(int id, char *value); |
|||
extern void TuxDrv_GetAllStatusState(char *state); |
|||
extern int TuxDrv_TokenizeStatus(char *status, drv_tokens_t *tokens); |
|||
extern void TuxDrv_ResetPositions(void); |
|||
extern void TuxDrv_ResetDongle(void); |
|||
extern double get_time(void); |
|||
|
|||
#if defined(__cplusplus) |
|||
} |
|||
#endif |
|||
|
|||
#endif /* _TUX_DRIVER_H_ */ |
@ -0,0 +1,233 @@ |
|||
{* |
|||
* Tux Droid - Driver |
|||
* Copyright (C) 2008 C2ME Sa <Acness : remi.jocaille@c2me.be> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|||
* 02111-1307, USA. |
|||
*} |
|||
|
|||
unit tux_driver; |
|||
|
|||
interface |
|||
|
|||
uses |
|||
Windows, classes; |
|||
|
|||
const |
|||
|
|||
DLL_NAME = 'libtuxdriver.dll'; |
|||
|
|||
{** |
|||
* Error codes enumeration. |
|||
*} |
|||
E_TUXDRV_BEGIN = 256; |
|||
E_TUXDRV_NOERROR = 0; |
|||
E_TUXDRV_PARSERISDISABLED = E_TUXDRV_BEGIN; |
|||
E_TUXDRV_INVALIDCOMMAND = E_TUXDRV_BEGIN + 1; |
|||
E_TUXDRV_STACKOVERFLOW = E_TUXDRV_BEGIN + 2; |
|||
E_TUXDRV_FILEERROR = E_TUXDRV_BEGIN + 3; |
|||
E_TUXDRV_BADWAVFILE = E_TUXDRV_BEGIN + 4; |
|||
E_TUXDRV_INVALIDIDENTIFIER = E_TUXDRV_BEGIN + 5; |
|||
E_TUXDRV_INVALIDNAME = E_TUXDRV_BEGIN + 6; |
|||
E_TUXDRV_INVALIDPARAMETER = E_TUXDRV_BEGIN + 7; |
|||
E_TUXDRV_BUSY = E_TUXDRV_BEGIN + 8; |
|||
E_TUXDRV_WAVSIZEEXCEDED = E_TUXDRV_BEGIN + 9; |
|||
|
|||
{** |
|||
* Id enumeration of high level status. |
|||
*} |
|||
SW_ID_FLIPPERS_POSITION = 0; |
|||
SW_ID_FLIPPERS_REMAINING_MVM = 1; |
|||
SW_ID_SPINNING_DIRECTION = 2; |
|||
SW_ID_SPINNING_REMAINING_MVM = 3; |
|||
SW_ID_LEFT_WING_BUTTON = 4; |
|||
SW_ID_RIGHT_WING_BUTTON = 5; |
|||
SW_ID_HEAD_BUTTON = 6; |
|||
SW_ID_REMOTE_BUTTON = 7; |
|||
SW_ID_MOUTH_POSITION = 8; |
|||
SW_ID_MOUTH_REMAINING_MVM = 9; |
|||
SW_ID_EYES_POSITION = 10; |
|||
SW_ID_EYES_REMAINING_MVM = 11; |
|||
SW_ID_DESCRIPTOR_COMPLETE = 12; |
|||
SW_ID_RF_STATE = 13; |
|||
SW_ID_DONGLE_PLUG = 14; |
|||
SW_ID_CHARGER_STATE = 15; |
|||
SW_ID_BATTERY_LEVEL = 16; |
|||
SW_ID_BATTERY_STATE = 17; |
|||
SW_ID_LIGHT_LEVEL = 18; |
|||
SW_ID_LEFT_LED_STATE = 19; |
|||
SW_ID_RIGHT_LED_STATE = 20; |
|||
SW_ID_CONNECTION_QUALITY = 21; |
|||
SW_ID_AUDIO_FLASH_PLAY = 22; |
|||
SW_ID_AUDIO_GENERAL_PLAY = 23; |
|||
SW_ID_FLASH_PROG_CURR_TRACK = 24; |
|||
SW_ID_FLASH_PROG_LAST_TRACK_SIZE = 25; |
|||
SW_ID_TUXCORE_SYMBOLIC_VERSION = 26; |
|||
SW_ID_TUXAUDIO_SYMBOLIC_VERSION = 27; |
|||
SW_ID_FUXUSB_SYMBOLIC_VERSION = 28; |
|||
SW_ID_FUXRF_SYMBOLIC_VERSION = 29; |
|||
SW_ID_TUXRF_SYMBOLIC_VERSION = 30; |
|||
SW_ID_DRIVER_SYMBOLIC_VERSION = 31; |
|||
SW_ID_SOUND_REFLASH_BEGIN = 32; |
|||
SW_ID_SOUND_REFLASH_END = 33; |
|||
SW_ID_SOUND_REFLASH_CURRENT_TRACK = 34; |
|||
SW_ID_EYES_MOTOR_ON = 35; |
|||
SW_ID_MOUTH_MOTOR_ON = 36; |
|||
SW_ID_FLIPPERS_MOTOR_ON = 37; |
|||
SW_ID_SPIN_LEFT_MOTOR_ON = 38; |
|||
SW_ID_SPIN_RIGHT_MOTOR_ON = 39; |
|||
SW_ID_FLASH_SOUND_COUNT = 40; |
|||
|
|||
type |
|||
|
|||
{** |
|||
* Simple callback definition. |
|||
*} |
|||
drv_simple_callback_t = procedure; |
|||
|
|||
{** |
|||
* Status callback definition. |
|||
*} |
|||
drv_status_callback_t = procedure(status:PChar); cdecl; |
|||
|
|||
{** |
|||
* Logging target |
|||
*} |
|||
log_target_t = ( |
|||
LOG_TARGET_TUX = 0, |
|||
LOG_TARGET_SHELL |
|||
); |
|||
|
|||
{** |
|||
* Logging levels, in increasing priorities |
|||
*} |
|||
log_level_t = ( |
|||
LOG_LEVEL_DEBUG = 0, |
|||
LOG_LEVEL_INFO, |
|||
LOG_LEVEL_WARNING, |
|||
LOG_LEVEL_ERROR, |
|||
LOG_LEVEL_NONE |
|||
); |
|||
|
|||
{** |
|||
* Descriptor structure of a firmaware. |
|||
*} |
|||
p_firmware_descriptor_t = ^firmware_descriptor_t; |
|||
firmware_descriptor_t = packed record |
|||
cpu_id : integer; |
|||
version_major : cardinal; |
|||
version_minor : cardinal; |
|||
version_update : cardinal; |
|||
revision : cardinal; |
|||
rlmmr : cardinal; |
|||
author : cardinal; |
|||
variation : cardinal; |
|||
version_string : packed array[0..255] of char; |
|||
end; |
|||
|
|||
{** |
|||
* Descriptor structure of sound flash. |
|||
*} |
|||
p_sound_flash_descriptor_t = ^sound_flash_descriptor_t; |
|||
sound_flash_descriptor_t = packed record |
|||
number_of_sounds : cardinal; |
|||
flash_usage : cardinal; |
|||
available_record_time : cardinal; |
|||
end; |
|||
|
|||
{** |
|||
* Descriptor structure of ID connection. |
|||
*} |
|||
p_id_descriptor_t = ^id_descriptor_t; |
|||
id_descriptor_t = packed record |
|||
number : cardinal; |
|||
end; |
|||
|
|||
{** |
|||
* Global descriptor structure of tuxdroid. |
|||
*} |
|||
p_tux_descriptor_t = ^tux_descriptor_t; |
|||
tux_descriptor_t = packed record |
|||
firmwares : packed record |
|||
package : p_firmware_descriptor_t; |
|||
tuxcore : p_firmware_descriptor_t; |
|||
tuxaudio : p_firmware_descriptor_t; |
|||
tuxrf : p_firmware_descriptor_t; |
|||
fuxrf : p_firmware_descriptor_t; |
|||
fuxusb : p_firmware_descriptor_t; |
|||
end; |
|||
driver : packed record |
|||
version_major : cardinal; |
|||
version_minor : cardinal; |
|||
version_update : cardinal; |
|||
version_build : cardinal; |
|||
version_state : packed array[0..99] of char; |
|||
version_string : packed array[0..99] of char; |
|||
end; |
|||
sound_flash : p_sound_flash_descriptor_t; |
|||
id : p_id_descriptor_t; |
|||
end; |
|||
|
|||
{** |
|||
* DLL static linkage. |
|||
*} |
|||
procedure TuxDrv_Start; cdecl; |
|||
external DLL_NAME name 'TuxDrv_Start'; |
|||
procedure TuxDrv_Stop; cdecl; |
|||
external DLL_NAME name 'TuxDrv_Stop'; |
|||
procedure TuxDrv_SetStatusCallback(funct:drv_status_callback_t); cdecl; |
|||
external DLL_NAME name 'TuxDrv_SetStatusCallback'; |
|||
procedure TuxDrv_SetEndCycleCallback(funct:drv_simple_callback_t); cdecl; |
|||
external DLL_NAME name 'TuxDrv_SetEndCycleCallback'; |
|||
procedure TuxDrv_SetDongleConnectedCallback(funct:drv_simple_callback_t); cdecl; |
|||
external DLL_NAME name 'TuxDrv_SetDongleConnectedCallback'; |
|||
procedure TuxDrv_SetDongleDisconnectedCallback(funct:drv_simple_callback_t); cdecl; |
|||
external DLL_NAME name 'TuxDrv_SetDongleDisconnectedCallback'; |
|||
function TuxDrv_PerformCommand(delay:real; cmd_str:PChar):integer; cdecl; |
|||
external DLL_NAME name 'TuxDrv_PerformCommand'; |
|||
function TuxDrv_PerformMacroFile(file_path:PChar):integer; cdecl; |
|||
external DLL_NAME name 'TuxDrv_PerformMacroFile'; |
|||
function TuxDrv_PerformMacroText(macro:PChar):integer; cdecl; |
|||
external DLL_NAME name 'TuxDrv_PerformMacroText'; |
|||
function TuxDrv_GetStatusName(id:integer; name:PChar):integer; cdecl; |
|||
external DLL_NAME name 'TuxDrv_GetStatusName'; |
|||
function TuxDrv_GetStatusValue(id:integer; value:PChar):integer; cdecl; |
|||
external DLL_NAME name 'TuxDrv_GetStatusValue'; |
|||
function TuxDrv_GetStatusId(name:PChar; var id:integer):integer; cdecl; |
|||
external DLL_NAME name 'TuxDrv_GetStatusId'; |
|||
procedure TuxDrv_ClearCommandStack; cdecl; |
|||
external DLL_NAME name 'TuxDrv_ClearCommandStack'; |
|||
function TuxDrv_GetStatusState(id:integer; state:PChar):integer; cdecl; |
|||
external DLL_NAME name 'TuxDrv_GetStatusState'; |
|||
procedure TuxDrv_GetAllStatusState(state:PChar); cdecl; |
|||
external DLL_NAME name 'TuxDrv_GetAllStatusState'; |
|||
function TuxDrv_SoundReflash(tracks:PChar):integer; cdecl; |
|||
external DLL_NAME name 'TuxDrv_SoundReflash'; |
|||
procedure TuxDrv_ResetPositions; cdecl; |
|||
external DLL_NAME name 'TuxDrv_ResetPositions'; |
|||
procedure TuxDrv_ResetDongle; cdecl; |
|||
external DLL_NAME name 'TuxDrv_ResetDongle'; |
|||
procedure TuxDrv_SetLogLevel(level:integer); cdecl; |
|||
external DLL_NAME name 'TuxDrv_SetLogLevel'; |
|||
procedure TuxDrv_SetLogTarget(target:integer); cdecl; |
|||
external DLL_NAME name 'TuxDrv_SetLogTarget'; |
|||
procedure TuxDrv_GetDescriptor(tux_desc:p_tux_descriptor_t); cdecl; |
|||
external DLL_NAME name 'TuxDrv_GetDescriptor'; |
|||
function TuxDrv_StrError(error_code:integer):PChar; cdecl; |
|||
external DLL_NAME name 'TuxDrv_StrError'; |
|||
|
|||
implementation |
|||
|
|||
end. |
@ -0,0 +1,404 @@ |
|||
# Tux Droid - Driver |
|||
# Copyright (C) 2008 C2ME Sa <Acness : remi.jocaille@c2me.be> |
|||
# |
|||
# This program is free software; you can redistribute it and/or modify |
|||
# it under the terms of the GNU General Public License as published by |
|||
# the Free Software Foundation; either version 2, or (at your option) |
|||
# any later version. |
|||
# |
|||
# This program is distributed in the hope that it will be useful, |
|||
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
# GNU General Public License for more details. |
|||
# |
|||
# You should have received a copy of the GNU General Public License |
|||
# along with this program; if not, write to the Free Software |
|||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|||
# 02111-1307, USA. |
|||
|
|||
from ctypes import * |
|||
import os |
|||
|
|||
E_TUXDRV_BEGIN = 256 |
|||
E_TUXDRV_NOERROR = 0 |
|||
E_TUXDRV_PARSERISDISABLED = E_TUXDRV_BEGIN |
|||
E_TUXDRV_INVALIDCOMMAND = E_TUXDRV_BEGIN + 1 |
|||
E_TUXDRV_STACKOVERFLOW = E_TUXDRV_BEGIN + 2 |
|||
E_TUXDRV_FILEERROR = E_TUXDRV_BEGIN + 3 |
|||
E_TUXDRV_BADWAVFILE = E_TUXDRV_BEGIN + 4 |
|||
E_TUXDRV_INVALIDIDENTIFIER = E_TUXDRV_BEGIN + 5 |
|||
E_TUXDRV_INVALIDNAME = E_TUXDRV_BEGIN + 6 |
|||
E_TUXDRV_INVALIDPARAMETER = E_TUXDRV_BEGIN + 7 |
|||
E_TUXDRV_BUSY = E_TUXDRV_BEGIN + 8 |
|||
E_TUXDRV_WAVSIZEEXCEDED = E_TUXDRV_BEGIN + 9 |
|||
|
|||
SW_ID_FLIPPERS_POSITION = 0 |
|||
SW_ID_FLIPPERS_REMAINING_MVM = 1 |
|||
SW_ID_SPINNING_DIRECTION = 2 |
|||
SW_ID_SPINNING_REMAINING_MVM = 3 |
|||
SW_ID_LEFT_WING_BUTTON = 4 |
|||
SW_ID_RIGHT_WING_BUTTON = 5 |
|||
SW_ID_HEAD_BUTTON = 6 |
|||
SW_ID_REMOTE_BUTTON = 7 |
|||
SW_ID_MOUTH_POSITION = 8 |
|||
SW_ID_MOUTH_REMAINING_MVM = 9 |
|||
SW_ID_EYES_POSITION = 10 |
|||
SW_ID_EYES_REMAINING_MVM = 11 |
|||
SW_ID_DESCRIPTOR_COMPLETE = 12 |
|||
SW_ID_RF_STATE = 13 |
|||
SW_ID_DONGLE_PLUG = 14 |
|||
SW_ID_CHARGER_STATE = 15 |
|||
SW_ID_BATTERY_LEVEL = 16 |
|||
SW_ID_BATTERY_STATE = 17 |
|||
SW_ID_LIGHT_LEVEL = 18 |
|||
SW_ID_LEFT_LED_STATE = 19 |
|||
SW_ID_RIGHT_LED_STATE = 20 |
|||
SW_ID_CONNECTION_QUALITY = 21 |
|||
SW_ID_AUDIO_FLASH_PLAY = 22 |
|||
SW_ID_AUDIO_GENERAL_PLAY = 23 |
|||
SW_ID_FLASH_PROG_CURR_TRACK = 24 |
|||
SW_ID_FLASH_PROG_LAST_TRACK_SIZE = 25 |
|||
SW_ID_TUXCORE_SYMBOLIC_VERSION = 26 |
|||
SW_ID_TUXAUDIO_SYMBOLIC_VERSION = 27 |
|||
SW_ID_FUXUSB_SYMBOLIC_VERSION = 28 |
|||
SW_ID_FUXRF_SYMBOLIC_VERSION = 29 |
|||
SW_ID_TUXRF_SYMBOLIC_VERSION = 30 |
|||
SW_ID_DRIVER_SYMBOLIC_VERSION = 31 |
|||
SW_ID_SOUND_REFLASH_BEGIN = 32 |
|||
SW_ID_SOUND_REFLASH_END = 33 |
|||
SW_ID_SOUND_REFLASH_CURRENT_TRACK = 34 |
|||
SW_ID_EYES_MOTOR_ON = 35 |
|||
SW_ID_MOUTH_MOTOR_ON = 36 |
|||
SW_ID_FLIPPERS_MOTOR_ON = 37 |
|||
SW_ID_SPIN_LEFT_MOTOR_ON = 38 |
|||
SW_ID_SPIN_RIGHT_MOTOR_ON = 39 |
|||
SW_ID_FLASH_SOUND_COUNT = 40 |
|||
|
|||
SW_NAME_DRIVER = [ |
|||
"flippers_position", |
|||
"flippers_remaining_movements", |
|||
"spinning_direction", |
|||
"spinning_remaining_movements", |
|||
"left_wing_button", |
|||
"right_wing_button", |
|||
"head_button", |
|||
"remote_button", |
|||
"mouth_position", |
|||
"mouth_remaining_movements", |
|||
"eyes_position", |
|||
"eyes_remaining_movements", |
|||
"descriptor_complete", |
|||
"radio_state", |
|||
"dongle_plug", |
|||
"charger_state", |
|||
"battery_level", |
|||
"battery_state", |
|||
"light_level", |
|||
"left_led_state", |
|||
"right_led_state", |
|||
"connection_quality", |
|||
"audio_flash_play", |
|||
"audio_general_play", |
|||
"flash_programming_current_track", |
|||
"flash_programming_last_track_size", |
|||
"tuxcore_symbolic_version", |
|||
"tuxaudio_symbolic_version", |
|||
"fuxusb_symbolic_version", |
|||
"fuxrf_symbolic_version", |
|||
"tuxrf_symbolic_version", |
|||
"driver_symbolic_version", |
|||
"sound_reflash_begin", |
|||
"sound_reflash_end", |
|||
"sound_reflash_current_track", |
|||
"eyes_motor_on", |
|||
"mouth_motor_on", |
|||
"flippers_motor_on", |
|||
"spin_left_motor_on", |
|||
"spin_right_motor_on", |
|||
"sound_flash_count" |
|||
] |
|||
|
|||
LOG_LEVEL_DEBUG = 0 |
|||
LOG_LEVEL_INFO = 1 |
|||
LOG_LEVEL_WARNING = 2 |
|||
LOG_LEVEL_ERROR = 3 |
|||
LOG_LEVEL_NONE = 4 |
|||
|
|||
LOG_TARGET_TUX = 0 |
|||
LOG_TARGET_SHELL = 1 |
|||
|
|||
TUX_DRIVER_STATUS_CALLBACK = CFUNCTYPE(None, c_char_p) |
|||
TUX_DRIVER_SIMPLE_CALLBACK = CFUNCTYPE(None) |
|||
|
|||
class TuxDrv(object): |
|||
|
|||
def __init__(self, library_path): |
|||
self.__callback_container = [] |
|||
self.tux_driver_lib = None |
|||
if os.path.isfile(library_path): |
|||
try: |
|||
self.tux_driver_lib = CDLL(library_path) |
|||
except: |
|||
self.tux_driver_lib = None |
|||
|
|||
def SetStatusCallback(self, funct = None): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
if funct == None: |
|||
return |
|||
|
|||
cb = TUX_DRIVER_STATUS_CALLBACK(funct) |
|||
self.__callback_container.append(cb) |
|||
self.tux_driver_lib.TuxDrv_SetStatusCallback(cb) |
|||
return |
|||
|
|||
def SetEndCycleCallback(self, funct = None): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
if funct == None: |
|||
return |
|||
|
|||
cb = TUX_DRIVER_SIMPLE_CALLBACK(funct) |
|||
self.__callback_container.append(cb) |
|||
self.tux_driver_lib.TuxDrv_SetEndCycleCallback(cb) |
|||
return |
|||
|
|||
def SetDongleConnectedCallback(self, funct = None): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
if funct == None: |
|||
return |
|||
|
|||
cb = TUX_DRIVER_SIMPLE_CALLBACK(funct) |
|||
self.__callback_container.append(cb) |
|||
self.tux_driver_lib.TuxDrv_SetDongleConnectedCallback(cb) |
|||
return |
|||
|
|||
def SetDongleDisconnectedCallback(self, funct = None): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
if funct == None: |
|||
return |
|||
|
|||
cb = TUX_DRIVER_SIMPLE_CALLBACK(funct) |
|||
self.__callback_container.append(cb) |
|||
self.tux_driver_lib.TuxDrv_SetDongleDisconnectedCallback(cb) |
|||
return |
|||
|
|||
def Start(self): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
self.tux_driver_lib.TuxDrv_Start() |
|||
|
|||
def Stop(self): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
self.tux_driver_lib.TuxDrv_Stop() |
|||
|
|||
|
|||
def PerformCommand(self, delay, command): |
|||
if self.tux_driver_lib == None: |
|||
return E_TUXDRV_PARSERISDISABLED |
|||
|
|||
ret = self.tux_driver_lib.TuxDrv_PerformCommand(c_double(delay), |
|||
c_char_p(command)) |
|||
|
|||
return ret |
|||
|
|||
def PerformMacroFile(self, file_path = ""): |
|||
if self.tux_driver_lib == None: |
|||
return E_TUXDRV_PARSERISDISABLED |
|||
|
|||
ret = self.tux_driver_lib.TuxDrv_PerformMacroFile(c_char_p(file_path)) |
|||
|
|||
return ret |
|||
|
|||
def PerformMacroText(self, macro = ""): |
|||
if self.tux_driver_lib == None: |
|||
return E_TUXDRV_PARSERISDISABLED |
|||
|
|||
ret = self.tux_driver_lib.TuxDrv_PerformMacroText(c_char_p(macro)) |
|||
|
|||
return ret |
|||
|
|||
def ClearCommandStack(self): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
self.tux_driver_lib.TuxDrv_ClearCommandStack() |
|||
|
|||
return |
|||
|
|||
def SoundReflash(self, tracks = ""): |
|||
if self.tux_driver_lib == None: |
|||
return E_TUXDRV_BUSY |
|||
|
|||
ret = self.tux_driver_lib.TuxDrv_SoundReflash(c_char_p(tracks)) |
|||
|
|||
return ret |
|||
|
|||
def GetStatusId(self, name = "battery_level"): |
|||
if self.tux_driver_lib == None: |
|||
return -1 |
|||
|
|||
idc = c_int(0) |
|||
idcp = pointer(idc) |
|||
ret = self.tux_driver_lib.TuxDrv_GetStatusId(c_char_p(name), idcp) |
|||
|
|||
if ret != E_TUXDRV_NOERROR: |
|||
idc.value = -1 |
|||
|
|||
return idc.value |
|||
|
|||
def GetStatusName(self, id = 0): |
|||
if self.tux_driver_lib == None: |
|||
return "UNDEFINED" |
|||
|
|||
result = " " * 256 |
|||
ret = self.tux_driver_lib.TuxDrv_GetStatusName(c_int(id), |
|||
c_char_p(result)) |
|||
result = result.replace(" ", "") |
|||
|
|||
if ret == E_TUXDRV_NOERROR: |
|||
return result |
|||
else: |
|||
return "UNDEFINED" |
|||
|
|||
def SetLogLevel(self, level = LOG_LEVEL_INFO): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
self.tux_driver_lib.TuxDrv_SetLogLevel(c_uint8(level)) |
|||
|
|||
def SetLogTarget(self, target = LOG_TARGET_SHELL): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
self.tux_driver_lib.TuxDrv_SetLogTarget(c_uint8(target)) |
|||
|
|||
def GetStatusState(self, id = 0): |
|||
if self.tux_driver_lib == None: |
|||
return "UNDEFINED" |
|||
|
|||
result = " " * 256 |
|||
ret = self.tux_driver_lib.TuxDrv_GetStatusState(c_int(id), |
|||
c_char_p(result)) |
|||
result = result.replace(" ", "") |
|||
|
|||
if ret == E_TUXDRV_NOERROR: |
|||
return result |
|||
else: |
|||
return "UNDEFINED" |
|||
|
|||
def GetStatusValue(self, id = 0): |
|||
if self.tux_driver_lib == None: |
|||
return "UNDEFINED" |
|||
|
|||
result = " " * 256 |
|||
ret = self.tux_driver_lib.TuxDrv_GetStatusValue(c_int(id), |
|||
c_char_p(result)) |
|||
result = result.replace(" ", "") |
|||
|
|||
if ret == E_TUXDRV_NOERROR: |
|||
return result |
|||
else: |
|||
return "UNDEFINED" |
|||
|
|||
def GetAllStatusState(self): |
|||
if self.tux_driver_lib == None: |
|||
return "" |
|||
|
|||
result = " " * 8182 |
|||
self.tux_driver_lib.TuxDrv_GetAllStatusState(c_char_p(result)) |
|||
result = result.replace(" ", "") |
|||
|
|||
return result |
|||
|
|||
def TokenizeStatus(self, status = ""): |
|||
if self.tux_driver_lib == None: |
|||
return [] |
|||
|
|||
result = status.split(":") |
|||
if len(result) == 1: |
|||
if result[0] == '': |
|||
result = [] |
|||
return result |
|||
|
|||
def ResetPositions(self): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
self.tux_driver_lib.TuxDrv_ResetPositions() |
|||
|
|||
return |
|||
|
|||
def ResetDongle(self): |
|||
if self.tux_driver_lib == None: |
|||
return |
|||
|
|||
self.tux_driver_lib.TuxDrv_ResetDongle() |
|||
|
|||
return |
|||
|
|||
def GetStatusStruct(self, status = ""): |
|||
result = { |
|||
'name' : "None", |
|||
'value' : None, |
|||
'delay' : 0.0, |
|||
'type' : 'string' |
|||
} |
|||
|
|||
if self.tux_driver_lib == None: |
|||
return result |
|||
|
|||
status_s = self.TokenizeStatus(status) |
|||
if len(status_s) == 0: |
|||
return result |
|||
|
|||
result['name'] = status_s[0] |
|||
result['delay'] = status_s[3] |
|||
result['type'] = status_s[1] |
|||
|
|||
if status_s[1] in ['uint8', 'int8', 'int', 'float', 'bool']: |
|||
result['value'] = eval(status_s[2]) |
|||
elif status_s[1] == 'string': |
|||
result['value'] = status_s[2] |
|||
|
|||
return result |
|||
|
|||
def StrError(self, error_code): |
|||
if self.tux_driver_lib == None: |
|||
return "Shared library not found" |
|||
|
|||
result = self.tux_driver_lib.TuxDrv_StrError(c_int(error_code)) |
|||
|
|||
return c_char_p(result).value |
|||
|
|||
if __name__ == "__main__": |
|||
|
|||
def on_status_event(status): |
|||
status_struct = tux_drv.GetStatusStruct(status) |
|||
print status_struct |
|||
|
|||
def on_dongle_connected(): |
|||
tux_drv.ResetPositions() |
|||
print tux_drv.GetAllStatusState() |
|||
print tux_drv.GetStatusName(0) |
|||
print tux_drv.GetStatusValue(0) |
|||
print tux_drv.GetStatusState(0) |
|||
|
|||
if os.name == 'nt': |
|||
tux_drv = TuxDrv('../win32/libtuxdriver.dll') |
|||
else: |
|||
tux_drv = TuxDrv('../unix/libtuxdriver.so') |
|||
|
|||
tux_drv.SetLogLevel(LOG_LEVEL_INFO) |
|||
tux_drv.SetStatusCallback(on_status_event) |
|||
tux_drv.SetDongleConnectedCallback(on_dongle_connected) |
|||
tux_drv.Start() |
@ -0,0 +1,255 @@ |
|||
/* |
|||
* Tux Droid - Log |
|||
* Copyright (C) 2007 C2ME S.A. <tuxdroid@c2me.be> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|||
* 02111-1307, USA. |
|||
*/ |
|||
|
|||
/** |
|||
* \file log.c |
|||
* \brief Logger functions. |
|||
* \ingroup logger |
|||
*/ |
|||
|
|||
#include <assert.h> |
|||
#include <stdio.h> |
|||
#include <stdarg.h> |
|||
#include <time.h> |
|||
|
|||
#include "log.h" |
|||
|
|||
/** Name of log file for target LOG_TARGET_TUX */ |
|||
#ifdef WIN32 |
|||
# define LOG_FILE "c:\\windows\\libtuxdriver.log" |
|||
#else |
|||
# define LOG_FILE "/var/log/tuxdroid/libtuxdriver.log" |
|||
#endif |
|||
|
|||
/** All logged messages are prefixed with this text */ |
|||
#define LOG_PREFIX "libtuxdriver" |
|||
|
|||
/** Current logging level */ |
|||
static log_level_t current_level = LOG_LEVEL_INFO; |
|||
|
|||
/** Logging level names */ |
|||
static const char *level_names[] = |
|||
{ |
|||
[LOG_LEVEL_DEBUG] = "debug", |
|||
[LOG_LEVEL_INFO] = "info", |
|||
[LOG_LEVEL_WARNING] = "warning", |
|||
[LOG_LEVEL_ERROR] = "error", |
|||
[LOG_LEVEL_NONE] = "none" |
|||
}; |
|||
|
|||
/** Current logging target */ |
|||
static log_target_t log_target = LOG_TARGET_SHELL; |
|||
|
|||
/** Log file for target LOG_TARGET_TUX */ |
|||
static FILE *log_file; |
|||
|
|||
/** Whether the log has been opened */ |
|||
static bool log_opened; |
|||
|
|||
/** |
|||
* \brief Open the log. |
|||
* \param target Logging target. |
|||
* \return true if successfull, false otherwise. |
|||
*/ |
|||
bool |
|||
log_open(log_target_t target) |
|||
{ |
|||
if (log_opened) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
switch (target) |
|||
{ |
|||
case LOG_TARGET_TUX: |
|||
log_file = fopen(LOG_FILE, "w"); |
|||
if (log_file == NULL) |
|||
{ |
|||
return false; |
|||
} |
|||
fclose(log_file); |
|||
log_file = NULL; |
|||
break; |
|||
|
|||
case LOG_TARGET_SHELL: |
|||
break; |
|||
} |
|||
|
|||
log_target = target; |
|||
log_opened = true; |
|||
|
|||
return true; |
|||
} |
|||
|
|||
/** |
|||
* \brief Close the log. |
|||
*/ |
|||
void |
|||
log_close(void) |
|||
{ |
|||
if (!log_opened) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
switch (log_target) |
|||
{ |
|||
case LOG_TARGET_TUX: |
|||
break; |
|||
|
|||
case LOG_TARGET_SHELL: |
|||
break; |
|||
} |
|||
|
|||
log_opened = false; |
|||
} |
|||
|
|||
/** |
|||
* \brief Write text in the log. |
|||
* \param text Text to write. |
|||
*/ |
|||
static void |
|||
write_log_text(char *text) |
|||
{ |
|||
log_file = fopen(LOG_FILE, "a"); |
|||
if (log_file == NULL) |
|||
{ |
|||
return; |
|||
} |
|||
fprintf(log_file, "%s\n", text); |
|||
fclose(log_file); |
|||
log_file = NULL; |
|||
} |
|||
|
|||
/** |
|||
* \brief Set the logging level. |
|||
* \param new_level New logging level. |
|||
*/ |
|||
void |
|||
log_set_level(log_level_t new_level) |
|||
{ |
|||
assert(new_level >= LOG_LEVEL_DEBUG && new_level <= LOG_LEVEL_NONE); |
|||
current_level = new_level; |
|||
} |
|||
|
|||
/** |
|||
* \brief Get the logging level. |
|||
* \return The current logging level |
|||
*/ |
|||
log_level_t |
|||
log_get_level(void) |
|||
{ |
|||
return current_level; |
|||
} |
|||
|
|||
/** |
|||
* \brief Log formatted message at the specified level. |
|||
* |
|||
* \param at_level Level to log the message at. |
|||
* \param fmt Message format. |
|||
* \param ... Optional message data. |
|||
* |
|||
* If the priority of the specifed level is lower than the priority |
|||
* of the current logging level, the message is silently dropped. |
|||
* |
|||
* \return true if successful, false otherwise. |
|||
*/ |
|||
bool |
|||
log_text(log_level_t at_level, const char *fmt, ...) |
|||
{ |
|||
char text[1024], *p = text; |
|||
size_t size = sizeof(text); |
|||
time_t now; |
|||
va_list al; |
|||
int r; |
|||
|
|||
/* No need for the log to be 'opened' when logging to std{out,err} */ |
|||
if (log_target != LOG_TARGET_SHELL && !log_opened) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
/* Logging at level NONE has no sense */ |
|||
assert(at_level >= LOG_LEVEL_DEBUG && at_level < LOG_LEVEL_NONE); |
|||
|
|||
if (at_level < current_level) |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
/* Add date & time when LOG_TARGET_TUX */ |
|||
if (log_target == LOG_TARGET_TUX) |
|||
{ |
|||
now = time(NULL); |
|||
#ifdef WIN32 |
|||
r = strftime(p, size, "%y-%m-%d %H-%M-%S ", localtime(&now)); |
|||
#else |
|||
r = strftime(p, size, "%F %T ", localtime(&now)); |
|||
#endif |
|||
if (r == 0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
p += r; |
|||
size -= r; |
|||
} |
|||
|
|||
/* Only prefix non-INFO level messages */ |
|||
if (at_level != LOG_LEVEL_INFO) |
|||
{ |
|||
r = snprintf(p, size, "%s: ", level_names[at_level]); |
|||
if (r < 0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
p += r; |
|||
size -= r; |
|||
} |
|||
|
|||
va_start(al, fmt); |
|||
r = vsnprintf(p, size, fmt, al); |
|||
va_end(al); |
|||
if (r < 0) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
switch (log_target) |
|||
{ |
|||
case LOG_TARGET_TUX: |
|||
write_log_text(text); |
|||
break; |
|||
|
|||
case LOG_TARGET_SHELL: |
|||
if (at_level == LOG_LEVEL_WARNING || at_level == LOG_LEVEL_ERROR) |
|||
{ |
|||
fprintf(stderr, "%s: %s\n", LOG_PREFIX, text); |
|||
} |
|||
else |
|||
{ |
|||
fprintf(stdout, "%s: %s\n", LOG_PREFIX, text); |
|||
} |
|||
break; |
|||
} |
|||
|
|||
return true; |
|||
} |
@ -0,0 +1,63 @@ |
|||
/* |
|||
* Tux Droid - Log |
|||
* Copyright (C) 2007 C2ME S.A. <tuxdroid@c2me.be> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|||
* 02111-1307, USA. |
|||
*/ |
|||
|
|||
/** |
|||
* \file log.h |
|||
* \brief Logger header. |
|||
* \ingroup logger |
|||
*/ |
|||
|
|||
#ifndef __LOG_H__ |
|||
#define __LOG_H__ |
|||
|
|||
#include <stdbool.h> |
|||
|
|||
/** \brief Logging target. */ |
|||
typedef enum log_target |
|||
{ |
|||
LOG_TARGET_TUX, /**< Target file */ |
|||
LOG_TARGET_SHELL /**< Target shell */ |
|||
} log_target_t; |
|||
|
|||
extern bool log_open(log_target_t target); |
|||
extern void log_close(void); |
|||
|
|||
/** \brief Logging levels, in increasing priorities */ |
|||
typedef enum log_level |
|||
{ |
|||
LOG_LEVEL_DEBUG, /**< Level Debug */ |
|||
LOG_LEVEL_INFO, /**< Level Info */ |
|||
LOG_LEVEL_WARNING, /**< Level Warning */ |
|||
LOG_LEVEL_ERROR, /**< Level Error */ |
|||
LOG_LEVEL_NONE /**< Level None */ |
|||
} log_level_t; |
|||
|
|||
extern void log_set_level(log_level_t new_level); |
|||
extern log_level_t log_get_level(void); |
|||
|
|||
extern bool log_text(log_level_t at_level, const char *fmt, ...) |
|||
__attribute__((format(printf, 2, 3))); |
|||
|
|||
#define log_debug(fmt, ...) log_text(LOG_LEVEL_DEBUG, (fmt), ## __VA_ARGS__) |
|||
#define log_info(fmt, ...) log_text(LOG_LEVEL_INFO, (fmt), ## __VA_ARGS__) |
|||
#define log_warning(fmt, ...) log_text(LOG_LEVEL_WARNING, (fmt), ## __VA_ARGS__) |
|||
#define log_error(fmt, ...) log_text(LOG_LEVEL_ERROR, (fmt), ## __VA_ARGS__) |
|||
|
|||
#endif /* __LOG_H__ */ |
@ -0,0 +1,37 @@ |
|||
/* |
|||
* Tux Droid - svnrev template |
|||
* Copyright (C) 2008 C2ME Sa <Acness : remi.jocaille@c2me.be> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
|||
* 02111-1307, USA. |
|||
*/ |
|||
/* SVN : $Id$ */ |
|||
/* This file is a template to generate svnrev.h automatically. |
|||
* SubWCRev performs keyword susbstitution whith SVN information. |
|||
*/ |
|||
|
|||
#ifndef _SVNREV_H_ |
|||
#define _SVNREV_H_ |
|||
|
|||
#define SVN_REV $WCREV$ |
|||
#define SVN_REVSTR "$WCREV$" |
|||
#define SVN_REVDATE "$WCDATE$" |
|||
#define SVN_MOD $WCMODS?1:0$ |
|||
#define SVN_MIX $WCMIXED?1:0$ |
|||
#define SVN_STATUS (SVN_MOD + (SVN_MIX<<1)) |
|||
#define SVN_RANGE "$WCRANGE$" |
|||
#define SVN_URL "$WCURL$" |
|||
|
|||
#endif /* _SVNREV_H_ */ |
@ -0,0 +1,54 @@ |
|||
/* |
|||
* FICHIER .H pour la realisation de THREADS PORTABLES LINUX/WINDOWS |
|||
* |
|||
* ce code a été écrit par Smeagol(smeagol-worms4@ifrance.com) et revu par |
|||
* Jerry Kan (pilouface@gmail.com) |
|||
* pour le site |
|||
* http://www.irrlicht.fr/ communauté francaise Irrlicht |
|||
* |
|||
* retrouvez ce tutoriel et beaucoup d'autres sur notre forum, |
|||
*/ |
|||
|
|||
#ifdef USE_MUTEX |
|||
#ifndef _THREADING_UNIFORM_H_ |
|||
#define _THREADING_UNIFORM_H_ |
|||
|
|||
#ifdef WIN32 |
|||
# include <windows.h> |
|||
# define callback_t unsigned long __stdcall |
|||
# define thread_t HANDLE |
|||
# define thread_create(thrd, fct, param) thrd = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(fct),(param),0,NULL) |
|||
# define thread_delete(thrd) CloseHandle(thrd); |
|||
# define thread_wait_close(thrd) WaitForMultipleObjects(1, &thrd, TRUE, INFINITE) |
|||
# define mutex_t CRITICAL_SECTION |
|||
# define mutex_init(mutex) InitializeCriticalSection(& mutex) |
|||
# define mutex_lock(mutex) EnterCriticalSection(& mutex) |
|||
# define mutex_unlock(mutex) LeaveCriticalSection(& mutex) |
|||
# define mutex_delete(mutex) DeleteCriticalSection(& mutex) |
|||
# define semaphore_t HANDLE |
|||
# define semaphore_init(sema, max, place) ((sema) = CreateSemaphore(NULL, (max), (place), NULL)) |
|||
# define semaphore_lock(sema) WaitForSingleObject((sema), INFINITE) |
|||
# define semaphore_unlock(sema) ReleaseSemaphore((sema), 1, NULL) |
|||
# define semaphore_delete(sema) CloseHandle(sema) |
|||
#else |
|||
# include <pthread.h> |
|||
# define callback_t void * |
|||
# define thread_t pthread_t |
|||
# define thread_create(thrd, fct, param) pthread_create(&thrd, NULL, (fct), ((void *)param)); |
|||
# define thread_delete(thrd) |
|||
# define thread_wait_close(thrd) pthread_join(thrd, NULL) |
|||
# include <semaphore.h> |
|||
# define mutex_t pthread_mutex_t |
|||
# define mutex_init(mutex) pthread_mutex_init ((&mutex), NULL) |
|||
# define mutex_lock(mutex) pthread_mutex_lock((&mutex)) |
|||
# define mutex_unlock(mutex) pthread_mutex_unlock((&mutex)) |
|||
# define mutex_delete(mutex) pthread_mutex_destroy((&mutex)) |
|||
# define semaphore_t sem_t* |
|||
# define semaphore_init(sema, max, place) (sema) = new sem_t; sem_init ((sema), (max), (place)) |
|||
# define semaphore_lock(sema) sem_wait((sema)) |
|||
# define semaphore_unlock(sema) sem_post((sema)) |
|||
# define semaphore_delete(sema) sem_destroy((sema)); delete ((sema)) |
|||
#endif |
|||
|
|||
#endif |
|||
#endif |
@ -0,0 +1,76 @@ |
|||
/* |
|||
* Tux Droid - Audio |
|||
* Copyright (C) 2008 C2ME Sa <Acness : remi.jocaille@c2me.be> |
|||
* |
|||
* This program is free software; you can redistribute it and/or modify |
|||
* it under the terms of the GNU General Public License as published by |
|||
* the Free Software Foundation; either version 2, or (at your option) |
|||
* any later version. |
|||
* |
|||
* This program is distributed in the hope that it will be useful, |
|||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|||
* GNU General Public License for more details. |
|||
* |
|||
* You should have received a copy of the GNU General Public License |
|||
* along with this program; if not, write to the Free Software |
|||
* Foundation, Inc., 59 Temple Place - Suit |