src/joystick/android/SDL_sysjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 26 Nov 2012 22:09:34 -0800
changeset 6696 73e2ad636f6e
parent 6695 ec21e81c62aa
child 6707 70eeb7e3ec2f
permissions -rw-r--r--
Return an error if the joystick index isn't 0 on Android
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     2
  Simple DirectMedia Layer
6138
4c64952a58fb Happy New Year!
Sam Lantinga <slouken@libsdl.org>
parents: 5535
diff changeset
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     7
  arising from the use of this software.
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    11
  freely, subject to the following restrictions:
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    20
*/
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    21
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    22
#include "SDL_config.h"
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    23
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    24
#ifdef SDL_JOYSTICK_ANDROID
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    25
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    26
/* This is the system specific header for the SDL joystick API */
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    27
#include <stdio.h>              /* For the definition of NULL */
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    28
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    29
#include "SDL_error.h"
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    30
#include "SDL_events.h"
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    31
#include "SDL_joystick.h"
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    32
#include "../SDL_sysjoystick.h"
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    33
#include "../SDL_joystick_c.h"
5090
327f181542f1 Include windows.h in a single point in the source, so we can be consistent about the definition of UNICODE and have core utility functions for Windows that all modules can share.
Sam Lantinga <slouken@libsdl.org>
parents: 5000
diff changeset
    34
#include "../../core/android/SDL_android.h"
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    35
5000
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    36
static const char *accelerometerName = "Android accelerometer";
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    37
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    38
/* Function to scan the system for joysticks.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    39
 * This function should set SDL_numjoysticks to the number of available
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    40
 * joysticks.  Joystick 0 should be the system default joystick.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    41
 * It should return 0, or -1 on an unrecoverable fatal error.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    42
 */
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    43
int
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    44
SDL_SYS_JoystickInit(void)
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    45
{
5000
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    46
    return (1);
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    47
}
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    48
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    49
/* Function to get the device-dependent name of a joystick */
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    50
const char *
6695
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
    51
SDL_SYS_JoystickNameForIndex(int index)
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    52
{
5000
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    53
    if (index == 0) {
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    54
        return accelerometerName;
5000
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    55
    } else {
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    56
        SDL_SetError("No joystick available with that index");
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    57
        return (NULL);
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    58
    }
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    59
}
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    60
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    61
/* Function to open a joystick for use.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    62
   The joystick to open is specified by the index field of the joystick.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    63
   This should fill the nbuttons and naxes fields of the joystick structure.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    64
   It returns 0, or -1 if there is an error.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    65
 */
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    66
int
6696
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    67
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    68
{
6696
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    69
    if (device_index == 0) {
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    70
        joystick->nbuttons = 0;
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    71
        joystick->nhats = 0;
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    72
        joystick->nballs = 0;
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    73
        joystick->naxes = 3;
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    74
        return 0;
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    75
	} else {
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    76
		SDL_SetError("No joystick available with that index");
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    77
		return (-1);
73e2ad636f6e Return an error if the joystick index isn't 0 on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6695
diff changeset
    78
	}
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    79
}
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    80
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    81
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    82
/* Function to update the state of a joystick - called as a device poll.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    83
 * This function shouldn't update the joystick structure directly,
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    84
 * but instead should call SDL_PrivateJoystick*() to deliver events
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    85
 * and update joystick device state.
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    86
 */
5000
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    87
void
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    88
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    89
{
5000
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    90
    int i;
6212
78d854de3a66 Fixed bug 1368 - Enabling joystick subsystem cause an infinite loop
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    91
    Sint16 value;
5000
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    92
    float values[3];
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
    93
6212
78d854de3a66 Fixed bug 1368 - Enabling joystick subsystem cause an infinite loop
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    94
    if (Android_JNI_GetAccelerometerValues(values)) {
78d854de3a66 Fixed bug 1368 - Enabling joystick subsystem cause an infinite loop
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    95
        for ( i = 0; i < 3; i++ ) {
78d854de3a66 Fixed bug 1368 - Enabling joystick subsystem cause an infinite loop
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    96
            value = (Sint16)(values[i] * 32767.0f);
78d854de3a66 Fixed bug 1368 - Enabling joystick subsystem cause an infinite loop
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    97
            SDL_PrivateJoystickAxis(joystick, i, value);
78d854de3a66 Fixed bug 1368 - Enabling joystick subsystem cause an infinite loop
Sam Lantinga <slouken@libsdl.org>
parents: 6138
diff changeset
    98
        }
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
    99
    }
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   100
}
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   101
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   102
/* Function to close a joystick after use */
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   103
void
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   104
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   105
{
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   106
}
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   107
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   108
/* Function to perform any system-specific joystick related cleanup */
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   109
void
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   110
SDL_SYS_JoystickQuit(void)
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   111
{
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   112
}
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   113
6695
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   114
/* Function to perform the mapping from device index to the instance id for this index */
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   115
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int index)
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   116
{
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   117
    return index;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   118
}
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   119
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   120
/* Function to determine is this joystick is attached to the system right now */
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   121
int SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   122
{
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   123
    return 1;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   124
}
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   125
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   126
int SDL_SYS_NumJoysticks()
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   127
{
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   128
    return 1;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   129
}
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   130
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   131
int SDL_SYS_JoystickNeedsPolling()
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   132
{
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   133
    return 0;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   134
}
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   135
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   136
void SDL_SYS_JoystickDetect()
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   137
{
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   138
}
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   139
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   140
JoystickGUID SDL_SYS_PrivateJoystickGetDeviceGUID( int device_index )
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   141
{
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   142
    JoystickGUID guid;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   143
    // the GUID is just the first 16 chars of the name for now
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   144
    const char *name = SDL_SYS_JoystickNameForIndex( device_index );
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   145
    SDL_zero( guid );
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   146
    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   147
    return guid;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   148
}
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   149
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   150
JoystickGUID SDL_SYS_PrivateJoystickGetGUID(SDL_Joystick * joystick)
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   151
{
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   152
    JoystickGUID guid;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   153
    // the GUID is just the first 16 chars of the name for now
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   154
    const char *name = joystick->name;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   155
    SDL_zero( guid );
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   156
    SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   157
    return guid;
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   158
}
ec21e81c62aa Fixed building joystick code on Android
Sam Lantinga <slouken@libsdl.org>
parents: 6212
diff changeset
   159
4721
7bb9d3a3f257 Added accelerometer 'joystick'
Paul Hunkin <paul@bieh.net>
parents:
diff changeset
   160
#endif /* SDL_JOYSTICK_NDS */
5000
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
   161
6a10693e66c3 Cleaned up internal accelerometer interface
Sam Lantinga <slouken@libsdl.org>
parents: 4721
diff changeset
   162
/* vi: set ts=4 sw=4 expandtab: */