2016-04-02 17:46:06 +02:00
|
|
|
|
|
|
|
// A simple wrapper for libsicksaxis, to make it resemble WPAD/PAD more closely.
|
|
|
|
// Written by daxtsu/thedax. I'm releasing this code into the public domain, so do whatever you want with it.
|
|
|
|
|
|
|
|
#include <sicksaxis.h>
|
|
|
|
#include "sicksaxis-wrapper.h"
|
|
|
|
|
2020-05-27 22:18:38 +02:00
|
|
|
static DS3 Controller1;
|
2016-04-02 17:46:06 +02:00
|
|
|
static bool psPressed = false;
|
|
|
|
|
2020-05-27 22:18:38 +02:00
|
|
|
bool DS3_Init()// does not check for and connect controller
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
|
|
|
USB_Initialize();
|
2020-05-27 22:18:38 +02:00
|
|
|
ss_init();// add controller to ios heap
|
|
|
|
ss_initialize(&Controller1);// set all values to initial states
|
2016-04-02 17:46:06 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DS3_Rumble()
|
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
//if (DS3_Connected())
|
|
|
|
if (Controller1.connected && psPressed)
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
ss_set_rumble(&Controller1, 2, 255, 2, 255);
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DS3_Cleanup()
|
|
|
|
{
|
|
|
|
psPressed = false;
|
2020-05-27 22:18:38 +02:00
|
|
|
ss_close(&Controller1);
|
2022-01-17 21:50:40 +01:00
|
|
|
//USB_Deinitialize();
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int DS3_ButtonsDown()
|
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
//if (!DS3_Connected())
|
|
|
|
if (!ss_is_connected(&Controller1) || !psPressed)
|
2016-04-02 17:46:06 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
DS3 *controller;
|
2020-05-27 22:18:38 +02:00
|
|
|
controller = &Controller1;
|
2016-04-02 17:46:06 +02:00
|
|
|
|
|
|
|
unsigned int pressed = 0;
|
|
|
|
|
|
|
|
pressed |= controller->pad.buttons.PS ? DS3_BUTTON_PS : 0;
|
|
|
|
pressed |= controller->pad.buttons.start ? DS3_BUTTON_START : 0;
|
|
|
|
pressed |= controller->pad.buttons.select ? DS3_BUTTON_SELECT : 0;
|
|
|
|
pressed |= controller->pad.buttons.triangle ? DS3_BUTTON_TRIANGLE : 0;
|
|
|
|
pressed |= controller->pad.buttons.circle ? DS3_BUTTON_CIRCLE : 0;
|
|
|
|
pressed |= controller->pad.buttons.cross ? DS3_BUTTON_CROSS : 0;
|
|
|
|
pressed |= controller->pad.buttons.square ? DS3_BUTTON_SQUARE : 0;
|
|
|
|
pressed |= controller->pad.buttons.up ? DS3_BUTTON_UP : 0;
|
|
|
|
pressed |= controller->pad.buttons.right ? DS3_BUTTON_RIGHT : 0;
|
|
|
|
pressed |= controller->pad.buttons.down ? DS3_BUTTON_DOWN : 0;
|
|
|
|
pressed |= controller->pad.buttons.left ? DS3_BUTTON_LEFT : 0;
|
|
|
|
pressed |= controller->pad.buttons.L1 ? DS3_BUTTON_L1 : 0;
|
|
|
|
pressed |= controller->pad.buttons.L2 ? DS3_BUTTON_L2 : 0;
|
|
|
|
pressed |= controller->pad.buttons.L3 ? DS3_BUTTON_L3 : 0;
|
|
|
|
pressed |= controller->pad.buttons.R1 ? DS3_BUTTON_R1 : 0;
|
|
|
|
pressed |= controller->pad.buttons.R2 ? DS3_BUTTON_R2 : 0;
|
|
|
|
pressed |= controller->pad.buttons.R3 ? DS3_BUTTON_R3 : 0;
|
|
|
|
|
|
|
|
return pressed;
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:18:38 +02:00
|
|
|
bool DS3_Connected()// not used but could be used in the functions ButtonsDown() and Rumble() above
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
return Controller1.connected > 0 && psPressed;
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 22:18:38 +02:00
|
|
|
/* does not scan pads. simply connects with the controller and starts a thread to read the controller. */
|
|
|
|
/* on later calls it simply checks if the PS button on the controller has been pressed and lights up the LED */
|
2016-04-02 17:46:06 +02:00
|
|
|
void DS3_ScanPads()
|
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
if (!ss_is_connected(&Controller1))
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
|
|
|
psPressed = false;
|
2020-05-27 22:18:38 +02:00
|
|
|
ss_initialize(&Controller1);
|
|
|
|
if (ss_open(&Controller1) > 0)
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
ss_start_reading(&Controller1);
|
|
|
|
ss_set_led(&Controller1, 0);
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-27 22:18:38 +02:00
|
|
|
else if (Controller1.pad.buttons.PS && !psPressed)
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
|
|
|
psPressed = true;
|
2020-05-27 22:18:38 +02:00
|
|
|
ss_set_led(&Controller1, 1);
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 22:18:38 +02:00
|
|
|
int DS3_LStickX()
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
return psPressed? Controller1.pad.left_analog.x - 128 : 0;
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 22:18:38 +02:00
|
|
|
int DS3_RStickX()
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
return psPressed? Controller1.pad.right_analog.x - 128 : 0;
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 22:18:38 +02:00
|
|
|
int DS3_LStickY()
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
return psPressed? Controller1.pad.left_analog.y - 128 : 0;
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 22:18:38 +02:00
|
|
|
int DS3_RStickY()
|
2016-04-02 17:46:06 +02:00
|
|
|
{
|
2020-05-27 22:18:38 +02:00
|
|
|
return psPressed? Controller1.pad.right_analog.y - 128 : 0;
|
2016-04-02 17:46:06 +02:00
|
|
|
}
|