first of all u'll need a phidgetservo offcoure

i have a 4 servo board, and the phidget framework installed (wich is pretty simple to use)
consider that i use linux ( fedora 8 ) and i did this in the vdrift-2007-12-26 src release
i did everything in vamosworld.cpp modified like this:
add the includes to make phidgets code work, and some printf commands that i used for debugging:
Code:
#include <phidget21>
#include <stdio>
then i added this code before the VAMOSWORLD::VAMOSWORLD() line 40 of original vamosworld.cpp:
Code:
CPhidgetServoHandle mhcservo;
void initMhcServo()
{
int result;
const char *err;
//object
CPhidgetServo_create (&mhcservo);
//apro
CPhidget_open((CPhidgetHandle)mhcservo, -1);
//aspetto connessione
if((result = CPhidget_waitForAttachment((CPhidgetHandle)mhcservo, 5000)))
{
CPhidget_getErrorDescription(result, &err);
printf("Problem waiting for attachment: %s\n", err);
}
}
void deinitMhcServo()
{
CPhidget_close((CPhidgetHandle)mhcservo);
CPhidget_delete((CPhidgetHandle)mhcservo);
printf("Chiudo\n");
}
i copied the float rpm at line 1988 of original file like this to define my float for servo data (explained before), and function to make the servo move (this is all in the VAMOSWORLD:

rawHUD() functon):
Code:
float mhc_r = Vamos_Geometry::rad_s_to_rpm (current_focus->car->engine ()->rotational_speed () / 50);
CPhidgetServo_setMotorPosition (mhcservo, 0, mhc_r);
and at the end of the void VAMOSWORLD::LoadHUD() function at line 2526 of original file i added the my function to init the servo:
to make scons compile with this hack u need to modify line 71 of SConscript under ./src folder to add libs:
Code:
common_libs = ['SDL_image', 'SDL_net', 'SDL_gfx', 'libbulletcollision', 'libbulletmath', 'vorbisfile', 'phidget21', 'm']
and.. that's it! simple
what's bad about all this:
the servo init function should be placed somewhere where it's called only once.. maybe when the game load or something like that.. otherwise u need to exit the game every time u finish a race or change track or car the have the servo working.. maybe someone can tell me where is the best place to do so and i can do some testing, and i should do some more practice to understand when to deinit the servo too
i should think about some more code to use the entire 200 degree servo movement considering the max rpm for each car.. and btw i'll like a light to indicate the rpm peak like in racing tachometers it would be nice to put it as default part of the game..
i should also write some code fore the speedo, i did a couple of test to indicate max 300 khm whit the servo, and for imput graph too since i have a 4 servo board i can make a complete external gauge display
have fun! :lol: