- Migration of projet to github
This commit is contained in:
245
include/tux_driver.h
Normal file
245
include/tux_driver.h
Normal file
@@ -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<4A>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_ */
|
||||
233
include/tux_driver.pas
Normal file
233
include/tux_driver.pas
Normal file
@@ -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.
|
||||
404
include/tux_driver.py
Normal file
404
include/tux_driver.py
Normal file
@@ -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()
|
||||
Reference in New Issue
Block a user