2022-12-22 22:09:57 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2023-12-17 14:52:08 +00:00
|
|
|
// Copyright (C) 2022-present JELOS (https://github.com/JustEnoughLinuxOS)
|
2022-12-22 22:09:57 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <SDL.h>
|
2022-12-25 00:54:59 +00:00
|
|
|
#include <cstdlib>
|
2022-12-22 22:09:57 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2024-02-08 12:54:50 +00:00
|
|
|
|
|
|
|
SDL_GameControllerAddMappingsFromFile("/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt");
|
|
|
|
SDL_Init(SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER);
|
2022-12-22 22:09:57 +00:00
|
|
|
atexit(SDL_Quit);
|
2022-12-25 00:54:59 +00:00
|
|
|
|
2022-12-22 22:09:57 +00:00
|
|
|
int num_joysticks = SDL_NumJoysticks();
|
|
|
|
int i;
|
|
|
|
for(i = 0; i < num_joysticks; ++i)
|
|
|
|
{
|
|
|
|
SDL_Joystick* js = SDL_JoystickOpen(i);
|
|
|
|
if (js)
|
|
|
|
{
|
|
|
|
SDL_JoystickGUID guid = SDL_JoystickGetGUID(js);
|
2024-02-08 12:54:50 +00:00
|
|
|
bool is_controller = SDL_IsGameController(i);
|
|
|
|
|
2022-12-22 22:09:57 +00:00
|
|
|
char guid_str[1024];
|
|
|
|
SDL_JoystickGetGUIDString(guid, guid_str, sizeof(guid_str));
|
2024-02-08 12:54:50 +00:00
|
|
|
if (is_controller)
|
|
|
|
{
|
|
|
|
const char* name = SDL_JoystickName(js);
|
2022-12-25 00:54:59 +00:00
|
|
|
|
2024-02-08 12:54:50 +00:00
|
|
|
printf("controlfolder=\"/storage/.config/gptokeyb\"\nESUDO=\"sudo\"\nESUDOKILL=\"-sudokill\"\nexport SDL_GAMECONTROLLERCONFIG_FILE=\"$controlfolder/gamecontrollerdb.txt\"\nSDLDBFILE=\"${SDL_GAMECONTROLLERCONFIG_FILE}\"\n[ -z \"${SDLDBFILE}\" ] && SDLDBFILE=\"${controlfolder}/gamecontrollerdb.txt\"\nSDLDBUSERFILE=\"/storage/.config/SDL-GameControllerDB/gamecontrollerdb.txt\"\nget_controls() {\nANALOGSTICKS=\"2\"\nDEVICE=\"%s\"\nparam_device=\"%s\"\n}\nGPTOKEYB=\"$controlfolder/gptokeyb $ESUDOKILL\"",
|
|
|
|
guid_str, name);
|
|
|
|
}
|
2022-12-22 22:09:57 +00:00
|
|
|
SDL_JoystickClose(js);
|
|
|
|
}
|
|
|
|
}
|
2022-12-25 00:54:59 +00:00
|
|
|
|
2022-12-22 22:09:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|