From a657dc248bac38611d566c243c28f93890c8ce65 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 29 Aug 1997 18:03:19 +0000 Subject: [PATCH] Initial revision. --- Cockpit/Makefile | 71 ++++ Cockpit/cockpit.c | 93 +++++ Cockpit/cockpit.h | 49 +++ Cockpit/depend | 6 + Cockpit/hud.c | 805 ++++++++++++++++++++++++++++++++++++++++++++ Cockpit/hud.h | 232 +++++++++++++ Joystick/Makefile | 68 ++++ Joystick/depend | 1 + Joystick/joystick.c | 241 +++++++++++++ Joystick/joystick.h | 35 ++ 10 files changed, 1601 insertions(+) create mode 100644 Cockpit/Makefile create mode 100644 Cockpit/cockpit.c create mode 100644 Cockpit/cockpit.h create mode 100644 Cockpit/depend create mode 100644 Cockpit/hud.c create mode 100644 Cockpit/hud.h create mode 100644 Joystick/Makefile create mode 100644 Joystick/depend create mode 100644 Joystick/joystick.c create mode 100644 Joystick/joystick.h diff --git a/Cockpit/Makefile b/Cockpit/Makefile new file mode 100644 index 000000000..dc02e1f4e --- /dev/null +++ b/Cockpit/Makefile @@ -0,0 +1,71 @@ +#--------------------------------------------------------------------------- +# Makefile +# +# Written by Curtis Olson, started July 1997. +# +# Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# $Id$ +# (Log is kept at end of this file) +#--------------------------------------------------------------------------- + + +TARGET = libCockpit.a + +CFILES = cockpit.c hud.c +HFILES = cockpit.h hud.h +OFILES = $(CFILES:.c=.o) + + +include ../make.inc + + +CFLAGS = $(FG_CFLAGS) + + +#--------------------------------------------------------------------------- +# Primary Targets +#--------------------------------------------------------------------------- + +$(TARGET): $(OFILES) + $(AR) rv $(TARGET) $(OFILES) + $(RANLIB) $(TARGET) + +all: $(TARGET) + +clean: + rm -f *.o $(TARGET) lib*.a *.os2 *~ core + + +#--------------------------------------------------------------------------- +# Secondary Targets +#--------------------------------------------------------------------------- + +include depend + +cockpit.o: + $(CC) $(CFLAGS) -c cockpit.c -o $@ + +hud.o: + $(CC) $(CFLAGS) -c hud.c -o $@ + + +#--------------------------------------------------------------------------- +# $Log$ +# Revision 1.1 1997/08/29 18:03:19 curt +# Initial revision. +# diff --git a/Cockpit/cockpit.c b/Cockpit/cockpit.c new file mode 100644 index 000000000..bc5e6c565 --- /dev/null +++ b/Cockpit/cockpit.c @@ -0,0 +1,93 @@ +/************************************************************************** + * cockpit.c -- routines to draw a cockpit (initial draft) + * + * Written by Michele America, started September 1997. + * + * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#include + +#include +#include "cockpit.h" + +#include "../constants.h" + +#include "../Aircraft/aircraft.h" +#include "../Scenery/mesh.h" +#include "../Scenery/scenery.h" +#include "../Math/mat3.h" +#include "../Math/polar.h" +#include "../Time/fg_timer.h" +#include "../Math/fg_random.h" +#include "../Weather/weather.h" + +// #define DEBUG + +/* This is a structure that contains all data related to cockpit/panel/hud system */ +static struct COCKPIT *aircraft_cockpit; + +struct COCKPIT *fgCockpitInit( struct AIRCRAFT cur_aircraft ) +{ + struct COCKPIT *cockpit; + Hptr hud; + + cockpit = (struct COCKPIT *)calloc(sizeof(struct COCKPIT),1); + if( cockpit == NULL ) + return( NULL ); + + cockpit->code = 1234; + cockpit->status = 0; + + /* If aircraft has HUD */ + hud = fgHUDInit( cur_aircraft, 3 ); + if( hud == NULL ) + return( NULL ); + + cockpit->hud = hud; + + aircraft_cockpit = cockpit; + + printf( "Code %d Status %d\n", cockpit->hud->code, cockpit->hud->status ); + + return( cockpit ); +} + +struct COCKPIT *fgCockpitAddHUD( struct COCKPIT *cockpit, struct HUD *hud ) +{ + cockpit->hud = hud; +} + +void fgCockpitUpdate() +{ + + printf( "Cockpit: code %d status %d\n", aircraft_cockpit->code, aircraft_cockpit->status ); + if( aircraft_cockpit->hud != NULL ) // That is, if the aircraft has a HUD, + fgUpdateHUD( aircraft_cockpit->hud ); // then draw it. + +} + + +/* $Log$ +/* Revision 1.1 1997/08/29 18:03:20 curt +/* Initial revision. +/* + */ diff --git a/Cockpit/cockpit.h b/Cockpit/cockpit.h new file mode 100644 index 000000000..90d992f4a --- /dev/null +++ b/Cockpit/cockpit.h @@ -0,0 +1,49 @@ +/************************************************************************** + * cockpit.h -- cockpit defines and prototypes (initial draft) + * + * Written by Michele America, started September 1997. + * + * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#include "hud.h" + + +// And in the future (near future i hope). +// #include "panel.h" + +struct COCKPIT { + int code; + Hptr hud; + // As above. + // PANEL *panel; + int status; +}; + +struct COCKPIT *fgCockpitInit( struct AIRCRAFT cur_aircraft ); +void fgCockpitUpdate(); + + +/* $Log$ +/* Revision 1.1 1997/08/29 18:03:21 curt +/* Initial revision. +/* + */ diff --git a/Cockpit/depend b/Cockpit/depend new file mode 100644 index 000000000..2d0d3ec52 --- /dev/null +++ b/Cockpit/depend @@ -0,0 +1,6 @@ +hud.o: cockpit.c cockpit.h hud.c hud.h ../Aircraft/aircraft.h \ + ../Aircraft/../Flight/flight.h ../Aircraft/../Flight/Slew/slew.h \ + ../Aircraft/../Flight/LaRCsim/ls_interface.h \ + ../Aircraft/../Flight/LaRCsim/../flight.h \ + ../Aircraft/../Controls/controls.h \ + ../Aircraft/../Controls/../limits.h ../Math/fg_random.h diff --git a/Cockpit/hud.c b/Cockpit/hud.c new file mode 100644 index 000000000..453a8dd84 --- /dev/null +++ b/Cockpit/hud.c @@ -0,0 +1,805 @@ +/************************************************************************** + * hud.c -- hud defines and prototypes + * + * Written by Michele America, started September 1997. + * + * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#include + +#include +#include "hud.h" + +#include "../constants.h" + +#include "../Aircraft/aircraft.h" +#include "../Scenery/mesh.h" +#include "../Scenery/scenery.h" +#include "../Math/mat3.h" +#include "../Math/polar.h" +#include "../Time/fg_timer.h" +#include "../Math/fg_random.h" +#include "../Weather/weather.h" + +// #define DEBUG + +#define drawOneLine(x1,y1,x2,y2) glBegin(GL_LINES); \ + glVertex2f ((x1),(y1)); glVertex2f ((x2),(y2)); glEnd(); + +/* textString - Bitmap font string */ + +static void textString(int x, int y, char *msg, void *font) +{ + glRasterPos2f(x, y); + while (*msg) { + glutBitmapCharacter(font, *msg); + msg++; + } +} + +/* strokeString - Stroke font string */ + +static void strokeString(int x, int y, char *msg, void *font) +{ + glPushMatrix(); + glTranslatef(x, y, 0); + glScalef(.04, .04, .04); + while (*msg) { + glutStrokeCharacter(font, *msg); + msg++; + } + glPopMatrix(); +} + +/* + + Draws a measuring scale anywhere on the HUD + + + Needs: HUD_scale struct + +*/ +static void drawscale( int type, int sub_type, int min_value, int orientation, int scr_pos, \ + int scr_min, int scr_max, double total_amount, int min_div, int max_div, \ + double cur_value ) +{ + double vmin, vmax; + int marker_x, marker_y; + int mid_scr; + // int scale_min, scale_max; + register i; + double factor; + char TextScale[80]; + int condition; + + vmin = cur_value-total_amount/2; + vmax = cur_value+total_amount/2; + + mid_scr = scr_min+(scr_max-scr_min)/2; + + if( type == VERTICAL ) // Vertical scale + { + if( orientation == LEFT ) + marker_x = scr_pos-6; + else if( orientation == RIGHT ) + marker_x = scr_pos; + drawOneLine( scr_pos, scr_min, scr_pos, scr_max ); + if( orientation == LEFT ) + { + drawOneLine( scr_pos-3, scr_min, scr_pos, scr_min ); + drawOneLine( scr_pos-3, scr_max, scr_pos, scr_max ); + drawOneLine( scr_pos, mid_scr, scr_pos+6, mid_scr ); + } else if( orientation == RIGHT ) + { + drawOneLine( scr_pos, scr_min, scr_pos+3, scr_min ); + drawOneLine( scr_pos, scr_max, scr_pos+3, scr_max ); + drawOneLine( scr_pos, mid_scr, scr_pos-6, mid_scr ); + } + + factor = (scr_max-scr_min)/total_amount; + + for( i=vmin; i<=vmax; i+=1 ) + { + if( sub_type == LIMIT ) + condition = i>= min_value; + else if( sub_type == NOLIMIT ) + condition = 1; + + if( condition ) + { + marker_y = scr_min+(i-vmin)*factor; + if( i%min_div==0 ) + if( orientation == LEFT ) + { + drawOneLine( marker_x+3, marker_y, marker_x+6, marker_y ); + } + else if( orientation == RIGHT ) + { + drawOneLine( marker_x, marker_y, marker_x+3, marker_y ); + } + if( i%max_div==0 ) + { + drawOneLine( marker_x, marker_y, marker_x+6, marker_y ); + sprintf( TextScale, "%d", i ); + if( orientation == LEFT ) + { + textString( marker_x-8*strlen(TextScale)-2, marker_y-4, TextScale, GLUT_BITMAP_8_BY_13 ); + } + else if( orientation == RIGHT ) + { + textString( marker_x+10, marker_y-4, TextScale, GLUT_BITMAP_8_BY_13 ); + } + } + } + } + } + if( type == HORIZONTAL ) // Horizontal scale + { + if( orientation == TOP ) + marker_y = scr_pos; + else if( orientation == BOTTOM ) + marker_y = scr_pos-6; + drawOneLine( scr_min, scr_pos, scr_max, scr_pos ); + if( orientation == TOP ) + { + drawOneLine( scr_min, scr_pos, scr_min, scr_pos-3 ); + drawOneLine( scr_max, scr_pos, scr_max, scr_pos-3 ); + drawOneLine( mid_scr, scr_pos, mid_scr, scr_pos-6 ); + } else if( orientation == BOTTOM ) + { + drawOneLine( scr_min, scr_pos, scr_min, scr_pos+3 ); + drawOneLine( scr_max, scr_pos, scr_max, scr_pos+3 ); + drawOneLine( mid_scr, scr_pos, mid_scr, scr_pos+6 ); + } + + factor = (scr_max-scr_min)/total_amount; + + for( i=vmin; i<=vmax; i+=1 ) + { + if( sub_type == LIMIT ) + condition = i>= min_value; + else if( sub_type == NOLIMIT ) + condition = 1; + + if( condition ) + { + marker_x = scr_min+(i-vmin)*factor; + if( i%min_div==0 ) + if( orientation == TOP ) + { + drawOneLine( marker_x, marker_y, marker_x, marker_y+3 ); + } + else if( orientation == BOTTOM ) + { + drawOneLine( marker_x, marker_y+3, marker_x, marker_y+6 ); + } + if( i%max_div==0 ) + { + sprintf( TextScale, "%d", i ); + if( orientation == TOP ) + { + drawOneLine( marker_x, marker_y, marker_x, marker_y+6 ); + textString( marker_x-4*strlen(TextScale), marker_y+14, TextScale, GLUT_BITMAP_8_BY_13 ); + } + else if( orientation == BOTTOM ) + { + drawOneLine( marker_x, marker_y, marker_x, marker_y+6 ); + textString( marker_x+10, marker_y-4, TextScale, GLUT_BITMAP_8_BY_13 ); + } + } + } + } + } + +} + +/* + + Draws a climb ladder in the center of the HUD + + + Needs: HUD_ladder struct + +*/ +static void drawladder( struct HUD_ladder ladder ) +{ + double vmin, vmax; + double roll_value, pitch_value; + double cos_roll, sin_roll; + int marker_x, marker_y; + int mid_scr; + int scr_min, scr_max; + int x_ini, x_end; + int y_ini, y_end; + int new_x_ini, new_x_end; + int new_y_ini, new_y_end; + register i; + double factor; + char TextLadder[80]; + int condition; + + roll_value = (*ladder.load_roll)(); + pitch_value = (*ladder.load_pitch)()*RAD_TO_DEG; + + vmin = pitch_value-ladder.width_units/2; + vmax = pitch_value+ladder.width_units/2; + + scr_min = ladder.y_pos-(ladder.scr_height/2); + scr_max = scr_min+ladder.scr_height; + + mid_scr = scr_min+(scr_max-scr_min)/2; + + marker_x = ladder.x_pos-ladder.scr_width/2; + + factor = (scr_max-scr_min)/ladder.width_units; + + for( i=vmin; i<=vmax; i+=1 ) + { + condition = 1; + if( condition ) + { + marker_y = scr_min+(i-vmin)*factor; + if( i%ladder.div_units==0 ) + { + sprintf( TextLadder, "%d", i ); + if( ladder.scr_hole == 0 ) + { + if( i != 0 ) + x_ini = ladder.x_pos-ladder.scr_width/2; + else + x_ini = ladder.x_pos-ladder.scr_width/2-10; + y_ini = marker_y; + x_end = ladder.x_pos+ladder.scr_width/2; + y_end = marker_y; + new_x_ini = ladder.x_pos+(x_ini-ladder.x_pos)*cos(roll_value)-\ + (y_ini-ladder.y_pos)*sin(roll_value); + new_y_ini = ladder.y_pos+(x_ini-ladder.x_pos)*sin(roll_value)+\ + (y_ini-ladder.y_pos)*cos(roll_value); + new_x_end = ladder.x_pos+(x_end-ladder.x_pos)*cos(roll_value)-\ + (y_end-ladder.y_pos)*sin(roll_value); + new_y_end = ladder.y_pos+(x_end-ladder.x_pos)*sin(roll_value)+\ + (y_end-ladder.y_pos)*cos(roll_value); + + if( i >= 0 ) + { + drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end ); + } + else + { + glEnable(GL_LINE_STIPPLE); + glLineStipple( 1, 0x00FF ); + drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end ); + glDisable(GL_LINE_STIPPLE); + } + textString( new_x_ini-8*strlen(TextLadder)-8, new_y_ini-4, TextLadder, GLUT_BITMAP_8_BY_13 ); + textString( new_x_end+10, new_y_end-4, TextLadder, GLUT_BITMAP_8_BY_13 ); + } + else + { + if( i != 0 ) + x_ini = ladder.x_pos-ladder.scr_width/2; + else + x_ini = ladder.x_pos-ladder.scr_width/2-10; + y_ini = marker_y; + x_end = ladder.x_pos-ladder.scr_width/2+ladder.scr_hole/2; + y_end = marker_y; + new_x_ini = ladder.x_pos+(x_ini-ladder.x_pos)*cos(roll_value)-\ + (y_ini-ladder.y_pos)*sin(roll_value); + new_y_ini = ladder.y_pos+(x_ini-ladder.x_pos)*sin(roll_value)+\ + (y_ini-ladder.y_pos)*cos(roll_value); + new_x_end = ladder.x_pos+(x_end-ladder.x_pos)*cos(roll_value)-\ + (y_end-ladder.y_pos)*sin(roll_value); + new_y_end = ladder.y_pos+(x_end-ladder.x_pos)*sin(roll_value)+\ + (y_end-ladder.y_pos)*cos(roll_value); + + if( i >= 0 ) + { + drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end ); + } + else + { + glEnable(GL_LINE_STIPPLE); + glLineStipple( 1, 0x00FF ); + drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end ); + glDisable(GL_LINE_STIPPLE); + } + textString( new_x_ini-8*strlen(TextLadder)-8, new_y_ini-4, TextLadder, GLUT_BITMAP_8_BY_13 ); + + x_ini = ladder.x_pos+ladder.scr_width/2-ladder.scr_hole/2; + y_ini = marker_y; + if( i != 0 ) + x_end = ladder.x_pos+ladder.scr_width/2; + else + x_end = ladder.x_pos+ladder.scr_width/2+10; + y_end = marker_y; + new_x_ini = ladder.x_pos+(x_ini-ladder.x_pos)*cos(roll_value)-\ + (y_ini-ladder.y_pos)*sin(roll_value); + new_y_ini = ladder.y_pos+(x_ini-ladder.x_pos)*sin(roll_value)+\ + (y_ini-ladder.y_pos)*cos(roll_value); + new_x_end = ladder.x_pos+(x_end-ladder.x_pos)*cos(roll_value)-\ + (y_end-ladder.y_pos)*sin(roll_value); + new_y_end = ladder.y_pos+(x_end-ladder.x_pos)*sin(roll_value)+\ + (y_end-ladder.y_pos)*cos(roll_value); + + if( i >= 0 ) + { + drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end ); + } + else + { + glEnable(GL_LINE_STIPPLE); + glLineStipple( 1, 0x00FF ); + drawOneLine( new_x_ini, new_y_ini, new_x_end, new_y_end ); + glDisable(GL_LINE_STIPPLE); + } + textString( new_x_end+10, new_y_end-4, TextLadder, GLUT_BITMAP_8_BY_13 ); + } + } + /* if( i%max_div==0 ) + { + drawOneLine( marker_x, marker_y, marker_x+6, marker_y ); + sprintf( TextScale, "%d", i ); + if( orientation == LEFT ) + { + textString( marker_x-8*strlen(TextScale)-2, marker_y-4, TextScale, GLUT_BITMAP_8_BY_13 ); + } + else if( orientation == RIGHT ) + { + textString( marker_x+10, marker_y-4, TextScale, GLUT_BITMAP_8_BY_13 ); + } + } */ + } + } + +} + +/* + + Draws an artificial horizon line in the center of the HUD + (with or without a center hole) + + Needs: x_center, y_center, length, hole + +*/ +static void drawhorizon( struct HUD_horizon horizon ) +{ + int x_inc1, y_inc1; + int x_inc2, y_inc2; + struct FLIGHT *f; + double sin_bank, cos_bank; + double bank_angle; + + // f = ¤t_aircraft.flight; + + bank_angle = (*horizon.load_value)(); + + // sin_bank = sin( 2*PI-FG_Phi ); + // cos_bank = cos( 2*PI-FG_Phi ); + sin_bank = sin(2*PI-bank_angle); + cos_bank = cos(2*PI-bank_angle); + x_inc1 = (int)(horizon.scr_width*cos_bank); + y_inc1 = (int)(horizon.scr_width*sin_bank); + x_inc2 = (int)(horizon.scr_hole*cos_bank); + y_inc2 = (int)(horizon.scr_hole*sin_bank); + + if( horizon.scr_hole == 0 ) + { + drawOneLine( horizon.x_pos-x_inc1, horizon.y_pos-y_inc1, \ + horizon.x_pos+x_inc1, horizon.y_pos+y_inc1 ); + } + else + { + drawOneLine( horizon.x_pos-x_inc1, horizon.y_pos-y_inc1, \ + horizon.x_pos-x_inc2, horizon.y_pos-y_inc2 ); + drawOneLine( horizon.x_pos+x_inc2, horizon.y_pos+y_inc2, \ + horizon.x_pos+x_inc1, horizon.y_pos+y_inc1 ); + } +} + +/* + + Draws a label anywhere in the HUD + + Needs: HUD_label struct + +*/ +static void drawlabel( struct HUD_label label ) +{ + char buffer[80]; + char string[80]; + int posincr; + int lenstr; + + if( label.pre_str != NULL && label.post_str != NULL ) + sprintf( buffer, "%s%s%s", label.pre_str, label.format, label.post_str ); + else if( label.pre_str == NULL && label.post_str != NULL ) + sprintf( buffer, "%s%s", label.format, label.post_str ); + else if( label.pre_str != NULL && label.post_str == NULL ) + sprintf( buffer, "%s%s", label.pre_str, label.format ); + + sprintf( string, buffer, (*label.load_value)() ); + +#ifdef DEBUG + printf( buffer ); + printf( "\n" ); + printf( string ); + printf( "\n" ); +#endif + + lenstr = strlen( string ); + if( label.justify == LEFT_JUST ) + posincr = -lenstr*8; + else if( label.justify == CENTER_JUST ) + posincr = -lenstr*4; + else if( label.justify == RIGHT_JUST ) + posincr = 0; + + if( label.size == SMALL ) + textString( label.x_pos+posincr, label.y_pos, string, GLUT_BITMAP_8_BY_13); + else if( label.size == LARGE ) + textString( label.x_pos+posincr, label.y_pos, string, GLUT_BITMAP_9_BY_15); + +} + +double get_speed() +{ + struct FLIGHT *f; + + f = ¤t_aircraft.flight; + return( FG_V_true_kts ); +} + +double get_aoa() +{ + struct FLIGHT *f; + + f = ¤t_aircraft.flight; + return( FG_Gamma_vert_rad*RAD_TO_DEG ); +} + +double get_roll() +{ + struct FLIGHT *f; + + f = ¤t_aircraft.flight; + return( FG_Phi ); +} + +double get_pitch() +{ + struct FLIGHT *f; + + f = ¤t_aircraft.flight; + return( FG_Theta ); +} + +double get_heading() +{ + struct FLIGHT *f; + + f = ¤t_aircraft.flight; + return( FG_Gamma_horiz_rad*RAD_TO_DEG ); +} + +double get_altitude() +{ + struct FLIGHT *f; + double rough_elev; + + f = ¤t_aircraft.flight; + rough_elev = mesh_altitude(FG_Longitude * RAD_TO_ARCSEC, + FG_Latitude * RAD_TO_ARCSEC); + + return( FG_Altitude*FEET_TO_METER-rough_elev ); +} + +void add_instrument( Hptr hud, HIptr instrument ) +{ + HIptr instruments; + + instruments = hud->instruments; + // while( ++instruments +} + +Hptr fgHUDInit( struct AIRCRAFT current_aircraft, int color ) +{ + Hptr hud; + + hud = (Hptr)calloc(sizeof(struct HUD),1); + if( hud == NULL ) + return( NULL ); + + hud->code = 123; + hud->status = 0; + + // For now let's just hardcode a hud here . + // In the future, hud information has to come from the same place + // aircraft information came + + fgHUDAddHorizon( hud, 590, 50, 40, 20, get_roll ); + fgHUDAddScale( hud, VERTICAL, 220, 100, 280, 5, 10, LEFT, LEFT, 0, 100, get_speed ); + fgHUDAddScale( hud, VERTICAL, 440, 100, 280, 1, 5, RIGHT, RIGHT, -MAXINT, 25, get_aoa ); + fgHUDAddScale( hud, HORIZONTAL, 280, 220, 440, 5, 10, TOP, TOP, 0, 50, get_heading ); + fgHUDAddLabel( hud, 180, 85, SMALL, NOBLINK, RIGHT_JUST, NULL, " Kts", "%5.0f", get_speed ); + fgHUDAddLabel( hud, 180, 73, SMALL, NOBLINK, RIGHT_JUST, NULL, " m", "%5.0f", get_altitude ); + fgHUDAddLadder( hud, 330, 190, 90, 180, 70, 10, NONE, 45, get_roll, get_pitch ); + + return( hud ); +} + + +Hptr fgHUDAddHorizon( Hptr hud, int x_pos, int y_pos, int length, \ + int hole_len, double (*load_value)() ) +{ + struct HUD_horizon *horizon; + struct HUD_instr *instrument; + HIptr tmp_first, tmp_next; + + tmp_first = hud->instruments; + if( tmp_first != NULL ) + tmp_next = tmp_first->next; + else + tmp_next = NULL; + + instrument = (HIptr)calloc(sizeof(struct HUD_instr),1); + if( instrument == NULL ) + return( NULL ); + + horizon = (struct HUD_horizon *)calloc(sizeof(struct HUD_horizon),1); + if( horizon == NULL ) + return( NULL ); + + instrument->type = ARTIFICIAL_HORIZON; + instrument->instr = *horizon; + instrument->instr.horizon.x_pos = x_pos; + instrument->instr.horizon.y_pos = y_pos; + instrument->instr.horizon.scr_width = length; + instrument->instr.horizon.scr_hole = hole_len; + instrument->instr.horizon.load_value = load_value; + instrument->next = tmp_first; + + hud->instruments = instrument; + + return( hud ); +} + +Hptr fgHUDAddScale( Hptr hud, int type, int scr_pos, int scr_min, int scr_max, int div_min, int div_max, \ + int orientation, int with_min, int min_value, int width_units, double (*load_value)() ) +{ + struct HUD_scale *scale; + struct HUD_instr *instrument; + HIptr tmp_first, tmp_next; + + tmp_first = hud->instruments; + if( tmp_first != NULL ) + tmp_next = tmp_first->next; + else + tmp_next = NULL; + + instrument = (HIptr)calloc(sizeof(struct HUD_instr),1); + if( instrument == NULL ) + return( NULL ); + + scale = (struct HUD_scale *)calloc(sizeof(struct HUD_scale),1); + if( scale == NULL ) + return( NULL ); + + instrument->type = SCALE; + instrument->instr = *scale; + instrument->instr.scale.type = type; + instrument->instr.scale.scr_pos = scr_pos; + instrument->instr.scale.scr_min = scr_min; + instrument->instr.scale.scr_max = scr_max; + instrument->instr.scale.div_min = div_min; + instrument->instr.scale.div_max = div_max; + instrument->instr.scale.orientation = orientation; + instrument->instr.scale.with_minimum = with_min; + instrument->instr.scale.minimum_value = min_value; + instrument->instr.scale.width_units = width_units; + instrument->instr.scale.load_value = load_value; + instrument->next = tmp_first; + + hud->instruments = instrument; + + return( hud ); +} + +Hptr fgHUDAddLabel( Hptr hud, int x_pos, int y_pos, int size, int blink, int justify, \ + char *pre_str, char *post_str, char *format, double (*load_value)() ) +{ + struct HUD_label *label; + struct HUD_instr *instrument; + HIptr tmp_first, tmp_next; + + tmp_first = hud->instruments; + if( tmp_first != NULL ) + tmp_next = tmp_first->next; + else + tmp_next = NULL; + + instrument = (HIptr)calloc(sizeof(struct HUD_instr),1); + if( instrument == NULL ) + return( NULL ); + + label = (struct HUD_label *)calloc(sizeof(struct HUD_label),1); + if( label == NULL ) + return( NULL ); + + instrument->type = LABEL; + instrument->instr = *label; + instrument->instr.label.x_pos = x_pos; + instrument->instr.label.y_pos = y_pos; + instrument->instr.label.size = size; + instrument->instr.label.blink = blink; + instrument->instr.label.justify = justify; + instrument->instr.label.pre_str = pre_str; + instrument->instr.label.post_str = post_str; + instrument->instr.label.format = format; + instrument->instr.label.load_value = load_value; + instrument->next = tmp_first; + + hud->instruments = instrument; + + return( hud ); +} + +Hptr fgHUDAddLadder( Hptr hud, int x_pos, int y_pos, int scr_width, int scr_height, \ + int hole_len, int div_units, int label_pos, int width_units, \ + double (*load_roll)(), double (*load_pitch)() ) +{ + struct HUD_ladder *ladder; + struct HUD_instr *instrument; + HIptr tmp_first, tmp_next; + + tmp_first = hud->instruments; + if( tmp_first != NULL ) + tmp_next = tmp_first->next; + else + tmp_next = NULL; + + instrument = (HIptr)calloc(sizeof(struct HUD_instr),1); + if( instrument == NULL ) + return( NULL ); + + ladder = (struct HUD_ladder *)calloc(sizeof(struct HUD_ladder),1); + if( ladder == NULL ) + return( NULL ); + + instrument->type = LADDER; + instrument->instr = *ladder; + instrument->instr.ladder.type = 0; // Not used. + instrument->instr.ladder.x_pos = x_pos; + instrument->instr.ladder.y_pos = y_pos; + instrument->instr.ladder.scr_width = scr_width; + instrument->instr.ladder.scr_height = scr_height; + instrument->instr.ladder.scr_hole = hole_len; + instrument->instr.ladder.div_units = div_units; + instrument->instr.ladder.label_position = label_pos; + instrument->instr.ladder.width_units = width_units; + instrument->instr.ladder.load_roll = load_roll; + instrument->instr.ladder.load_pitch = load_pitch; + instrument->next = tmp_first; + + hud->instruments = instrument; + + return( hud ); + +} + +/* +Hptr fgHUDAddMovingHorizon( Hptr hud, int x_pos, int y_pos, int length, int hole_len, \ + int color ) +{ + +} + +Hptr fgHUDAddCircularLadder( Hptr hud, int scr_min, int scr_max, int div_min, int div_max, \ + int max_value ) +{ + +} + +Hptr fgHUDAddNumDisp( Hptr hud, int x_pos, int y_pos, int size, int color, int blink, \ + char *pre_str, char *post_str ) +{ + +} +*/ + +void fgUpdateHUD( Hptr hud ) +{ + HIptr hud_instr; + union HUD_instr_data instr_data; + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + gluOrtho2D(0, 640, 0, 480); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glColor3f(1.0, 1.0, 1.0); + glIndexi(7); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glLineWidth(1); + glColor3f (0.1, 0.9, 0.1); + +#ifdef DEBUG + printf( "HUD Code %d Status %d\n", hud->code, hud->status ); +#endif + hud_instr = hud->instruments; + while( hud_instr != NULL ) + { + instr_data = hud_instr->instr; +#ifdef DEBUG + printf("Instr Type %d SubType %d Orient %d\n", hud_instr->type, hud_instr->sub_type, hud_instr->orientation ); +#endif + if( hud_instr->type == ARTIFICIAL_HORIZON ) + { + drawhorizon( instr_data.horizon ); + /* drawhorizon( instr_data.horizon.x_pos, instr_data.horizon.y_pos, \ + instr_data.horizon.scr_width, instr_data.horizon.scr_hole ); */ + } + else if( hud_instr->type == SCALE ) + { + drawscale( instr_data.scale.type, instr_data.scale.with_minimum, \ + instr_data.scale.minimum_value, instr_data.scale.orientation, \ + instr_data.scale.scr_pos, instr_data.scale.scr_min, \ + instr_data.scale.scr_max, instr_data.scale.width_units, \ + instr_data.scale.div_min, instr_data.scale.div_max, \ + (*instr_data.scale.load_value)() ); + } + else if( hud_instr->type == LABEL ) + { + drawlabel( instr_data.label ); + /* drawlabel( instr_data.label.x_pos, instr_data.label.y_pos, instr_data.label.size, \ + instr_data.label.blink, instr_data.label.pre_str, instr_data.label.post_str, \ + instr_data.label.format, (*instr_data.label.load_value)() ); */ + } + else if( hud_instr->type == LADDER ) + { + drawladder( instr_data.ladder ); + } + hud_instr = hud_instr->next; + } + + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + +} + + +/* $Log$ +/* Revision 1.1 1997/08/29 18:03:22 curt +/* Initial revision. +/* + */ diff --git a/Cockpit/hud.h b/Cockpit/hud.h new file mode 100644 index 000000000..696cdd49b --- /dev/null +++ b/Cockpit/hud.h @@ -0,0 +1,232 @@ +/************************************************************************** + * hud.h -- hud defines and prototypes (initial draft) + * + * Written by Michele America, started September 1997. + * + * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#include "../Aircraft/aircraft.h" +#include "../Flight/flight.h" +#include "../Controls/controls.h" + + +/* Instrument types */ +#define ARTIFICIAL_HORIZON 1 +#define SCALE 2 +#define LADDER 3 +#define LABEL 4 + +/* Scale constants */ +#define HORIZONTAL 1 +#define TOP 2 +#define BOTTOM 3 +#define VERTICAL 4 +#define LEFT 5 +#define RIGHT 6 +#define LIMIT 7 +#define NOLIMIT 8 + +/* Label constants */ +#define SMALL 1 +#define LARGE 2 +#define BLINK 3 +#define NOBLINK 4 +#define LEFT_JUST 5 +#define CENTER_JUST 6 +#define RIGHT_JUST 7 + +/* Ladder constants */ +#define NONE 1 +#define UPPER_LEFT 2 +#define UPPER_CENTER 3 +#define UPPER_RIGHT 4 +#define CENTER_RIGHT 5 +#define LOWER_RIGHT 6 +#define LOWER_CENTER 7 +#define LOWER_LEFT 8 +#define CENTER_LEFT 9 +#define SOLID_LINES 10 +#define DASHED_LINES 11 +#define DASHED_NEG_LINES 12 + +/* Ladder orientaion */ +// #define HUD_VERTICAL 1 +// #define HUD_HORIZONTAL 2 +// #define HUD_FREEFLOAT 3 + +/* Ladder orientation modes */ +// #define HUD_LEFT 1 +// #define HUD_RIGHT 2 +// #define HUD_TOP 1 +// #define HUD_BOTTOM 2 +// #define HUD_V_LEFT 1 +// #define HUD_V_RIGHT 2 +// #define HUD_H_TOP 1 +// #define HUD_H_BOTTOM 2 + + +/* Ladder sub-types */ +// #define HUD_LIM 1 +// #define HUD_NOLIM 2 +// #define HUD_CIRC 3 + +// #define HUD_INSTR_LADDER 1 +// #define HUD_INSTR_CLADDER 2 +// #define HUD_INSTR_HORIZON 3 +// #define HUD_INSTR_LABEL 4 + +struct HUD_scale { + int type; + int scr_pos; + int scr_min; + int scr_max; + int div_min; + int div_max; + int orientation; + int with_minimum; + int minimum_value; + int width_units; + double (*load_value)(); +}; + +struct HUD_circular_scale { + int type; + int scr_pos; + int scr_min; + int scr_max; + int div_min; + int div_max; + int orientation; + int label_position; + int width_units; + double (*load_value)(); +}; + +struct HUD_ladder { + int type; + int x_pos; + int y_pos; + int scr_width; + int scr_height; + int scr_hole; + int div_units; + int label_position; + int width_units; + double (*load_roll)(); + double (*load_pitch)(); +}; + +struct HUD_circular_ladder { + int scr_min; + int scr_max; + int div_min; + int div_max; + int orientation; + int label_position; + int width_units; + double (*load_value)(); +}; + +#define HORIZON_FIXED 1 +#define HORIZON_MOVING 2 + +struct HUD_horizon { + int type; + int x_pos; + int y_pos; + int scr_width; + int scr_hole; + double (*load_value)(); +}; + +#define LABEL_COUNTER 1 +#define LABEL_WARNING 2 + +struct HUD_label { + int type; + int x_pos; + int y_pos; + int size; + int blink; + int justify; + char *pre_str; + char *post_str; + char *format; + double (*load_value)(); +}; + +union HUD_instr_data { + struct HUD_scale scale; + struct HUD_circular_scale circ_scale; + struct HUD_ladder ladder; + struct HUD_circular_ladder circ_ladder; + struct HUD_horizon horizon; + struct HUD_label label; +}; + +typedef struct HUD_instr *HIptr; + +struct HUD_instr { + int type; + int sub_type; + int orientation; + union HUD_instr_data instr; + int color; + HIptr next; +}; + +struct HUD { + int code; + // struct HUD_instr *instruments; + HIptr instruments; + int status; +}; + +typedef struct HUD *Hptr; + +Hptr fgHUDInit( struct AIRCRAFT cur_aircraft, int color ); +Hptr fgHUDAddHorizon( Hptr hud, int x_pos, int y_pos, int length, int hole_len, double (*load_value)() ); +Hptr fgHUDAddScale( Hptr hud, int type, int scr_pos, int scr_min, int scr_max, int div_min, int div_max, \ + int orientation, int with_min, int min_value, int width_units, double (*load_value)() ); +Hptr fgHUDAddLabel( Hptr hud, int x_pos, int y_pos, int size, int blink, int justify, \ + char *pre_str, char *post_str, char *format, double (*load_value)() ); +Hptr fgHUDAddLadder( Hptr hud, int x_pos, int y_pos, int scr_width, int scr_height, \ + int hole_len, int div_units, int label_pos, int max_value, \ + double (*load_roll)(), double (*load_pitch)() ); + + + +/* struct HUD *fgHUDAddLadder( Hptr hud, int scr_min, int scr_max, int div_min, int div_max, \ + int orientation, int max_value, double *(load_value); +struct HUD *fgHUDAddCircularLadder( Hptr hud, int scr_min, int scr_max, int div_min, int div_max, \ + int max_value, double *(load_value) ); +struct HUD *fgHUDAddNumDisp( Hptr hud, int x_pos, int y_pos, int size, int blink, \ + char *pre_str, char *post_str, double *(load_value) ); */ +void fgUpdateHUD(); +void fgUpdateHUD2( struct HUD *hud ); + + +/* $Log$ +/* Revision 1.1 1997/08/29 18:03:22 curt +/* Initial revision. +/* + */ diff --git a/Joystick/Makefile b/Joystick/Makefile new file mode 100644 index 000000000..eb29b39e0 --- /dev/null +++ b/Joystick/Makefile @@ -0,0 +1,68 @@ +#--------------------------------------------------------------------------- +# Makefile +# +# Written by Curtis Olson, started July 1997. +# +# Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +# +# 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., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# $Id$ +# (Log is kept at end of this file) +#--------------------------------------------------------------------------- + + +TARGET = libJoystick.a + +CFILES = joystick.c +HFILES = joystick.h +OFILES = $(CFILES:.c=.o) + + +include ../make.inc + + +CFLAGS = $(FG_CFLAGS) + + +#--------------------------------------------------------------------------- +# Primary Targets +#--------------------------------------------------------------------------- + +$(TARGET): $(OFILES) + $(AR) rv $(TARGET) $(OFILES) + $(RANLIB) $(TARGET) + +all: $(TARGET) + +clean: + rm -f *.o $(TARGET) lib*.a *.os2 *~ core + + +#--------------------------------------------------------------------------- +# Secondary Targets +#--------------------------------------------------------------------------- + +include depend + +joystick.o: + $(CC) $(CFLAGS) -c joystick.c -o $@ + + +#--------------------------------------------------------------------------- +# $Log$ +# Revision 1.1 1997/08/29 18:06:53 curt +# Initial revision. +# diff --git a/Joystick/depend b/Joystick/depend new file mode 100644 index 000000000..1e3c61f9b --- /dev/null +++ b/Joystick/depend @@ -0,0 +1 @@ +joystick.o: joystick.c diff --git a/Joystick/joystick.c b/Joystick/joystick.c new file mode 100644 index 000000000..6de1d98b6 --- /dev/null +++ b/Joystick/joystick.c @@ -0,0 +1,241 @@ +/************************************************************************** + * joystick.h -- joystick support + * + * Written by Michele America, started September 1997. + * + * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#ifdef HAVE_JOYSTICK + +#include +#include +#include +#include + +#endif + +static joy_x_min=0, joy_x_ctr=0, joy_x_max=0; +static joy_y_min=0, joy_y_ctr=0, joy_y_max=0; +static joy_x_dead_min=1000, joy_x_dead_max=-1000; +static joy_y_dead_min=1000, joy_y_dead_max=-1000; + + +static int joystick_fd; + +int fgJoystickInit( int joy_num ) +{ +#ifdef HAVE_JOYSTICK + int status; + char *fname; + struct JS_DATA_TYPE js; + int button; + + /* argument should be 0 or 1 */ + if( joy_num != 1 && joy_num != 0 ) { + perror( "js" ); + return( 1 ); + } + + /* pick appropriate device file */ + if (joy_num == 0) + fname = "/dev/js0"; + if (joy_num == 1) + fname = "/dev/js1"; + + /* open device file */ + joystick_fd = open(fname, O_RDONLY); + if (joystick_fd < 0) { + perror ("js"); + return( 1 ); + } + + printf( "\nMove joystick around dead spot and press any joystick button.\n" ); + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + button = js.buttons & 1 || js.buttons & 2; + while(button == 0 ) { + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + button = js.buttons & 1 || js.buttons & 2; + if( js.x > joy_x_dead_max ) + joy_x_dead_max = js.x; + if( js.x < joy_x_dead_min ) + joy_x_dead_min = js.x; + if( js.y > joy_y_dead_max ) + joy_y_dead_max = js.y; + if( js.y < joy_y_dead_min ) + joy_y_dead_min = js.y; + + // printf( "Xmin %d Xmax %d Ymin %d Ymax %d", joy_x_dead_min, joy_x_dead_max, \ + // joy_y_dead_min, joy_y_dead_max ); + } + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + + printf("\nJoystick calibration: X_dead_min = %d, X_dead_max = %d\n", joy_x_dead_min, joy_x_dead_max ); + printf(" Y_dead_min = %d, Y_dead_max = %d\n", joy_y_dead_min, joy_y_dead_max ); + + sleep( 1 ); + + printf( "\nCenter joystick and press any joystick button.\n" ); + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + button = js.buttons & 1 || js.buttons & 2; + while(button == 0 ) { + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + button = js.buttons & 1 || js.buttons & 2; + } + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + joy_x_ctr = js.x; + joy_y_ctr = js.y; + + printf("Joystick calibration: X_ctr = %d, Y_ctr = %d\n", joy_x_ctr, joy_y_ctr ); + + sleep( 1 ); + + printf( "\nMove joystick to upper left and press any joystick button.\n" ); + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + button = js.buttons & 1 || js.buttons & 2; + while(button == 0 ) { + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + button = js.buttons & 1 || js.buttons & 2; + } + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + joy_x_min = js.x; + joy_y_min = js.y; + printf("Joystick calibration: X_min = %d, Y_min = %d\n", joy_x_min, joy_y_min ); + + sleep( 1 ); + + printf( "\nMove joystick to lower right and press any joystick button.\n" ); + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + button = js.buttons & 1 || js.buttons & 2; + while(button == 0 ) { + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + button = js.buttons & 1 || js.buttons & 2; + } + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + joy_x_max = js.x; + joy_y_max = js.y; + + printf("Joystick calibration: X_max = %d, Y_max = %d\n", joy_x_max, joy_y_max ); + + // joy_x_ctr = (joy_x_max-joy_x_min)/2; + // joy_y_ctr = (joy_y_max-joy_y_min)/2; + // printf("Joystick calibration: X_ctr = %d, Y_ctr = %d\n", joy_x_ctr, joy_y_ctr ); + + return( joystick_fd ); +#endif +} + +/* void fgJoystickCalibrate( int joy_fd ) +{ + +} */ + +int fgJoystickRead( double *joy_x, double *joy_y, int *joy_b1, int *joy_b2 ) +{ +#ifdef HAVE_JOYSTICK + struct JS_DATA_TYPE js; + int status; + + status = read(joystick_fd, &js, JS_RETURN); + if (status != JS_RETURN) { + perror("js"); + return( 1 ); + } + + /* printf("\n button 0: %s button 1: %s X position: %4d Y position: %4d\n", + (js.buttons & 1) ? "on " : "off", + (js.buttons & 2) ? "on " : "off", + js.x, + js.y ); */ + + if( js.x >= joy_x_dead_min && js.x <= joy_x_dead_max ) + *joy_x = 0.5; + else + *joy_x = (double)js.x/(double)(joy_x_max-joy_x_min); + *joy_x = *joy_x*2-1; + + if( js.y >= joy_y_dead_min && js.y <= joy_y_dead_max ) + *joy_y = 0.5; + else + *joy_y = (double)js.y/(double)(joy_y_max-joy_y_min); + *joy_y = *joy_y*2-1; + + *joy_b1 = js.buttons & 1; + *joy_b2 = js.buttons & 2; + + return( 0 ); +#endif +} + + +/* $Log$ +/* Revision 1.1 1997/08/29 18:06:54 curt +/* Initial revision. +/* + */ diff --git a/Joystick/joystick.h b/Joystick/joystick.h new file mode 100644 index 000000000..f363ead6b --- /dev/null +++ b/Joystick/joystick.h @@ -0,0 +1,35 @@ +/************************************************************************** + * joystick.h -- joystick support + * + * Written by Michele America, started September 1997. + * + * Copyright (C) 1997 Michele F. America - nomimarketing@mail.telepac.pt + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +int fgJoystickInit( int joy_num ); +int fgJoystickRead( double *joy_x, double *joy_y, int *joy_b1, int *joy_b2 ); + + +/* $Log$ +/* Revision 1.1 1997/08/29 18:06:55 curt +/* Initial revision. +/* + */ -- 2.39.2