Alain
Joined: 18 Apr 2006 Posts: 3 Location: France
|
How autocalibrate a Joystick (PIC 18f2550) |
Posted: Tue Apr 18, 2006 10:18 pm |
|
|
Hi,
I design a basic controler USB for a Joystick with a PIC 18f2550.
It works fine , but i hope that the joystick was autocalibrate when the controler is plugged.
I think that i need to know Vcenter , Vmax et Vmin but i haven't any idea for use this.
if anyone might offer some assistance?
Thinks
here my HID Descriptor
Code: |
const char USB_CLASS_SPECIFIC_DESC[] = {
0x05, 0x01, // Usage Page = Generic Desktop
0x09, 0x04, // Usage = Joystick
0xa1, 0x01, // Collection = Application
0x05, 0x02, // Usage Page (Simulation Controls)
0x09, 0xBB, // Usage (Throttle)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xFF,0x00 // Logical Maximum (255)
0x35, 0x00, // Physical Minimum (0)
0x46, 0xFF,0x00, // Physical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x81, 0x02, // Input (Data,Var,Abs)
0x05, 0x01, // Usage Page = Generic Desktop
0x09, 0x01, // Usage (Pointer)
0xA1, 0x00, // Collection (Physical)
0x09, 0x30, // Usage (X)
0x09, 0x31, // Usage (Y)
0x15, 0x81, // Logical Minimum (-127)
0x25, 0x7F, // Logical Maximum (+127)
0x95, 0x02, // Report Count (2)
0x81, 0x02, // Input (Data,Var,Abs)
0xC0, // End_Collection
0x05, 0x09, // Usage Page (Button)
0x19, 0x01, // Usage Minimum (Button1)
0x29, 0x08, // Usage Maximum (Button8)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x35, 0x00, // Physical Minimum (0)
0x45, 0x01, // Physical Maximum (1)
0x95, 0x08, // Report Count (8)
0x75, 0x01, // Report Size (1)
0x65, 0x00, // Unit (None)
0x81, 0x02, // Input (Data,Var,Abs)
0xC0 // End Collection
};
|
Here the main code
Code: |
#define Throttle TxUSB[0]
#define X TxUSB[1]
#define Y TxUSB[2]
#define Boutons TxUSB[3]
int8 Trim[2];
int8 TxUSB[5];
int8 Buffer;
while (TRUE)
{
if(usb_enumerated()) //si le PicUSB a été configuré
{
// Lecture des entrées analogiques
set_adc_channel( 0 ); // Selection Voie 0
delay_us(40);
Buffer = Read_ADC(); // Lecture du Canal 0 : X
X = Buffer -128 ; // Centrage de l'axe à 2.5V
set_adc_channel( 1 ); // Selection Voie 1
delay_us(40);
Buffer = Read_ADC(); // Lecture du Canal 1 : Y
Y = Buffer -128 ;
set_adc_channel( 2 ); // Selection Voie 2
delay_us(40);
Throttle = Read_ADC(); // Lecture du Canal 2 : Throttle
set_adc_channel( 3 ); // Selection Voie 3
delay_us(40);
Buffer = Read_ADC(); // Lecture du Canal 3 : Rudder
Rudder = Buffer - 128 ;
set_adc_channel( 4 ); // Selection Voie 4
delay_us(40);
Buffer = Read_ADC(); // Lecture du Canal 4 : Axe ?
Trim[1] = Buffer - 128 ;
delay_us(40);
// Lecture des entrées numériques
Boutons = input_b();
// Envoie des entrées sur le port USB
usb_put_packet(1, TxUSB, 4, USB_DTS_TOGGLE); //envoie d'un paquet de 4 octets sur EP1 vers le PC
delay_ms(10);
}
}
|
|
|