Respect the controller setting when returning data from cellPadGetData.

This commit is contained in:
jjsat 2017-09-24 20:39:56 +02:00 committed by Ivan
parent 9650218bb8
commit 632c8872cd
2 changed files with 77 additions and 33 deletions

View File

@ -235,21 +235,47 @@ s32 cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
btnChanged = true;
}
//not sure if this should officially change with capabilities/portsettings :(
data->len = 24;
if (pad->m_buffer_cleared)
// the real hardware only fills the buffer up to "len" elements (16 bit each)
if (pad->m_port_setting & CELL_PAD_SETTING_SENSOR_ON)
{
// report back new data every ~10 ms even if the input doesn't change
// this is observed behaviour when using a Dualshock 3 controller
static std::chrono::time_point<steady_clock> last_update[CELL_PAD_MAX_PORT_NUM] = { };
const std::chrono::time_point<steady_clock> now = steady_clock::now();
if (btnChanged || pad->m_buffer_cleared || (std::chrono::duration_cast<std::chrono::milliseconds>(now - last_update[port_no]).count() >= 10))
{
data->len = CELL_PAD_LEN_CHANGE_SENSOR_ON;
last_update[port_no] = now;
}
else
{
data->len = CELL_PAD_LEN_NO_CHANGE;
}
}
else if (btnChanged || pad->m_buffer_cleared)
{
// only give back valid data if a controller state changed
data->len = (pad->m_port_setting & CELL_PAD_SETTING_PRESS_ON) ? CELL_PAD_LEN_CHANGE_PRESS_ON : CELL_PAD_LEN_CHANGE_DEFAULT;
}
else
{
// report no state changes
data->len = CELL_PAD_LEN_NO_CHANGE;
}
pad->m_buffer_cleared = false;
}
else if (!btnChanged)
// only update parts of the output struct depending on the controller setting
if (data->len > CELL_PAD_LEN_NO_CHANGE)
{
data->len = 0;
}
memset(data->button, 0, sizeof(data->button));
data->button[0] = 0x0; // always 0
// bits 15-8 reserved, 7-4 = 0x7, 3-0: data->len/2;
data->button[1] = (0x7 << 4) | std::min(data->len / 2, 15);
//lets still send new data anyway, not sure whats expected still
data->button[CELL_PAD_BTN_OFFSET_DIGITAL1] = pad->m_digital_1;
data->button[CELL_PAD_BTN_OFFSET_DIGITAL2] = pad->m_digital_2;
data->button[CELL_PAD_BTN_OFFSET_ANALOG_RIGHT_X] = pad->m_analog_right_x;
@ -260,6 +286,10 @@ s32 cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
data->button[CELL_PAD_BTN_OFFSET_PRESS_LEFT] = pad->m_press_left;
data->button[CELL_PAD_BTN_OFFSET_PRESS_UP] = pad->m_press_up;
data->button[CELL_PAD_BTN_OFFSET_PRESS_DOWN] = pad->m_press_down;
}
if (data->len >= CELL_PAD_LEN_CHANGE_PRESS_ON)
{
data->button[CELL_PAD_BTN_OFFSET_PRESS_TRIANGLE] = pad->m_press_triangle;
data->button[CELL_PAD_BTN_OFFSET_PRESS_CIRCLE] = pad->m_press_circle;
data->button[CELL_PAD_BTN_OFFSET_PRESS_CROSS] = pad->m_press_cross;
@ -268,10 +298,15 @@ s32 cellPadGetData(u32 port_no, vm::ptr<CellPadData> data)
data->button[CELL_PAD_BTN_OFFSET_PRESS_L2] = pad->m_press_L2;
data->button[CELL_PAD_BTN_OFFSET_PRESS_R1] = pad->m_press_R1;
data->button[CELL_PAD_BTN_OFFSET_PRESS_R2] = pad->m_press_R2;
}
if (data->len == CELL_PAD_LEN_CHANGE_SENSOR_ON)
{
data->button[CELL_PAD_BTN_OFFSET_SENSOR_X] = pad->m_sensor_x;
data->button[CELL_PAD_BTN_OFFSET_SENSOR_Y] = pad->m_sensor_y;
data->button[CELL_PAD_BTN_OFFSET_SENSOR_Z] = pad->m_sensor_z;
data->button[CELL_PAD_BTN_OFFSET_SENSOR_G] = pad->m_sensor_g;
}
return CELL_OK;
}

View File

@ -27,6 +27,15 @@ enum
CELL_PAD_PCLASS_TYPE_NAVIGATION = 0x05,
};
// Length returned in CellPadData struct
enum
{
CELL_PAD_LEN_NO_CHANGE = 0,
CELL_PAD_LEN_CHANGE_DEFAULT = 8,
CELL_PAD_LEN_CHANGE_PRESS_ON = 20,
CELL_PAD_LEN_CHANGE_SENSOR_ON = 24,
};
struct CellPadData
{
be_t<s32> len;