hallo,
1)
bau meines JoyWarrior24F8-Sensor mit USB-Kabel
z.z. keine Buttons eingebaut.OK.
bin ich froh.
2)
erkennung des sensors unter linux 10.1. (64bit)
mit GeraeteManager:
3 Achsen werden erkannt = OK
4)
Frage: da der GeraeteManager eine
Kalibrierung anbietet, frage ginge das?
in meinen Fall koennte ich auf einer
Kalibrierung verzichten, wird softwaremaessig
bei der initialisierung geloest.
4)
SoftwareTest OK
Untenstehend ein kleines test-programm in c und mit
SDL- unterstuetzung.
weitere infos ueber SDL ss. www.sdl.org (vermutlich)
das programm hat
1) consolen-output: -> x,y,z-werte
2) sdl_windows :
-> ball koennte in x,y,direction bewegt werden
muss noch erstellt werden als ball.bmp
das ganze programm ist unter GPL und freiverfuegbar.
bitte nicht boese sein, dass ich den code so einfach poste,
vielen dank fuer die superhardware.
gruss
nomad
Code: Select all
// joyWarriorStickTest1.c
// ----------------------
// compile : cc joyWarriorStickTest1.c -o joyWarriorStickTest1 `sdl-config --cflags --libs` -lm
// run : ./joyWarriorStickTest1
//***************************************************************************************************/
// THIS PROGRAMM IS UNDER THE GNU-LICENCE
/****************************************************************************************************
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.
*****************************************************************************************************
01.05. - da beim Sensor keine Buttons verschaltet sind tauchen sie hier auch nicht auf
- ball.bmp koennte man mit x,y bewegen, nicht realisiert
- erkennen durch OS Linux 10.1. 64 bit == OK
- durch geraeteManager == OK
- Geraet:
-> Code Mercenaries JoyWarrior24 Force 8 OK
****************************************************************************************/
#include <math.h>
#include <stdlib.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>
#include "SDL_endian.h"
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <termios.h>
#include <unistd.h>
#include <sys/signal.h>
#include <sys/types.h>
#include <errno.h>
#include <ctype.h>
#include <sys/io.h>
// vars
unsigned char letsexit = 0;
// sprite-bewegung
Uint16 xvel = 0, yvel = 0;
// xyPos sprite
SDL_Rect spritepos;
#define SDL_VIDEO_FLAGS (SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_ANYFORMAT)
SDL_Surface * screen;
SDL_Surface * sprite, * tmp;
int nbjoysticks;
int i;
/***************************************************************************/
void gotoxy(int x, int y) { printf("\033[%d;%dH", y, x); fflush(stdout); }
void clrscr(void) { printf("\033[H\033[J"); fflush(stdout); }
/*******************************************************************************************************/
void process_events()
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
// the program quits if someone
// press the x simbol of the window with the mouse
case SDL_QUIT:
printf("Exit and bye...\n");
letsexit = 1;
break;
// keys
case SDL_KEYDOWN:
printf("KeyPressed ASCCI-Code: %d with Character: %c)\n",event.key.keysym.sym,event.key.keysym.unicode);
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
letsexit = 1;
break;
case SDLK_LEFT:
//printf("Left ArrowKey\n"); // yxvel = -1;
break;
case SDLK_RIGHT:
//printf("Right ArrowKey\n"); // xvel = 1;
break;
case SDLK_UP:
//printf("Up ArrowKey\n"); // yvel = -1;
break;
case SDLK_DOWN:
//printf("Down ArrowKey\n"); // yvel = 1;
break;
default:
break;
}
break;
// release key
case SDL_KEYUP:
//printf("Key release: %d\n", event.key.keysym.sym);
switch (event.key.keysym.sym)
{
case SDLK_LEFT:
case SDLK_RIGHT:
//printf("Left or Right ArrowKey released\n"); // xvel =0;
break;
case SDLK_UP:
case SDLK_DOWN:
//printf("Up or Down ArrowKey released\n"); // yvel = 0;
break;
default:
break;
}
break;
// sprite movements with mouse
case SDL_MOUSEMOTION:
//spritepos.x += event.motion.xrel;
//spritepos.y += event.motion.yrel;
//printf("SpritePosition: X: %d, Y: %d\n", event.motion.x,event.motion.y);
break;
// mouse clicks pressed
case SDL_MOUSEBUTTONDOWN:
//printf("MouseButton Click No.%d\n", event.button.button);
break;
// mouse clicks release
case SDL_MOUSEBUTTONUP:
//printf("MouseButton Released No. %d\n", event.button.button);
break;
// Joystick Axes JOYWARRIOR 24F8
case SDL_JOYAXISMOTION:
//printf("StickAxis No. %d\n",event.jaxis.axis, event.jaxis.which, event.jaxis.value);
if(event.jaxis.axis == 0)
{
gotoxy(2,10);
printf("Axis No: 0 (Turns) X-Axis: %d\n",event.jaxis.value);
}
if(event.jaxis.axis == 1)
{
gotoxy(2,11);
printf("Axis No: 1 (For/Back) y-Axis: %d\n",event.jaxis.value);
}
if(event.jaxis.axis == 2)
{
gotoxy(2,12);
printf("SchubRegler No: 2 (Speed)Z-Axis: %d\n",event.jaxis.value);
}
break;
// Joystick TrackBall = wird nicht von diesem Joystick unterstuetzt
case SDL_JOYBALLMOTION:
spritepos.x += event.jball.xrel;
spritepos.y += event.jball.yrel;
printf("Trackball %d\n",event.jball.ball, event.jball.which,event.jball.xrel, event.jball.yrel);
break;
// Joystick Buttons
case SDL_JOYBUTTONDOWN:
printf("Button No. %d clicked\n",event.jbutton.button, event.jbutton.which);
break;
// Joystick Button released
case SDL_JOYBUTTONUP:
printf("Button No. %d released\n",event.jbutton.button, event.jbutton.which);
break;
default:
break;
} // end switch(event.type)
} // end while
}
/***********************************************************************************************************/
int main(int argc, char * argv[])
{
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) == -1)
{
fprintf(stderr, "Error at Initialitions of SDL: %s\n",SDL_GetError());
return 1;
}
screen = SDL_SetVideoMode(640, 480, 24, SDL_VIDEO_FLAGS);
printf("Video-Mode: dx%d\n", screen->w, screen->h,screen->format->BitsPerPixel);
// Activations of UNICODE-support
SDL_EnableUNICODE(1);
clrscr();
gotoxy(2,1);
printf("JoyWarrior24 Force 8 Software-Test mit SDL\n");
nbjoysticks = SDL_NumJoysticks();
gotoxy(2,2);
printf("Nos of attached Joysticks: %d\n", nbjoysticks);
for(i = 0; i < nbjoysticks; i++)
{
SDL_Joystick * joy = SDL_JoystickOpen(i);
gotoxy(2,i+3);
printf("Axes : %d\n", SDL_JoystickNumAxes(joy));
gotoxy(2,i+4);
printf("Buttons : %d\n", SDL_JoystickNumButtons(joy));
// nur zu spaeteren test-zwecken
gotoxy(2,i+5);
printf("Trackballs: %d\n", SDL_JoystickNumBalls(joy));
gotoxy(2,i+6);
printf("NumHats: %d\n\n", SDL_JoystickNumHats(joy));
}
// Sprite image
tmp = SDL_LoadBMP("ball.bmp");
sprite = SDL_DisplayFormat(tmp);
SDL_FreeSurface(tmp);
SDL_SetColorKey(sprite, SDL_SRCCOLORKEY, SDL_MapRGB(sprite->format, 0xff, 0x00, 0xff));
// InitialPosition of sprite
spritepos.x = (screen->w - sprite->w) / 2;
spritepos.y = (screen->h - sprite->h) / 2;
//printf("Initial SpritePos: X = %d, Y = %d\n",spritepos.x,spritepos.y);
spritepos.w = 0;
spritepos.h = 0;
// new program-headline
SDL_WM_SetCaption("sdl-JoyWarrior24 F8 Stick Version 0.1.", "JoyWarrior");
// Event-Handling
while(!letsexit)
{
// event process
process_events();
// position & velocite
spritepos.x += xvel;
spritepos.y += yvel;
// if sprite Pos out of sight (outside window)
if (spritepos.x > screen->w - sprite->w) spritepos.x = screen->w - sprite->w;
if (spritepos.y < 0) spritepos.y = 0;
if (spritepos.y > screen->h - sprite->h) spritepos.y = screen->h - sprite->h;
// window-background (black)
SDL_FillRect(screen, NULL, 0);
// blitting & flip
SDL_BlitSurface(sprite, NULL, screen, &spritepos);
SDL_Flip(screen);
}
SDL_Quit();
return 0;
}