#include "Precompiled.h" #include "OrbisInput.h" namespace raki { OrbisJoy::OrbisJoy() { m_portHandle = ORBIS_INPUT_INVALID_PORT; } OrbisJoy::~OrbisJoy() { } void OrbisJoy::init( i32 _userId ) { m_portHandle = scePadOpen( _userId, 0, 0, NULL ); if( m_portHandle < 0 ) return; memset( &m_controllerState, 0, sizeof( m_controllerState ) ); } void OrbisJoy::done() { if( m_portHandle < 0 ) return; scePadClose( m_portHandle ); } void OrbisJoy::update() { if( m_portHandle < 0 ) return; if( SCE_OK != scePadReadState( m_portHandle, &m_controllerState ) ) return; if(m_controllerState.connected == false) return; int ret = scePadRead( m_portHandle, &m_controllerState, 16 ); /* printf("port: %d - %x\n", m_portHandle, ret); if(ret >= 0) { printf("buttons = %d\n", m_controllerState.buttons); }*/ } bool OrbisJoy::isConnected() { return m_controllerState.connected; } bool OrbisJoy::isButtonPressed( u32 _button ) { if( ( m_portHandle < 0 ) || !m_controllerState.connected ) return false; return m_controllerState.buttons & _button; } bool OrbisJoy::getLStickVal( u8 _axe, u8& _val ) { RAKI_ASSERT( _axe < 2 ); _val = 0.f; if( ( m_portHandle < 0 ) || !m_controllerState.connected ) return false; _val = ( _axe == 0 ) ? m_controllerState.leftStick.x : m_controllerState.leftStick.y; return true; } bool OrbisJoy::getRStickVal( u8 _axe, u8& _val ) { RAKI_ASSERT( _axe < 2 ); _val = 0.f; if( ( m_portHandle < 0 ) || !m_controllerState.connected ) return false; _val = ( _axe == 0 ) ? m_controllerState.rightStick.x : m_controllerState.rightStick.y; return true; } bool OrbisJoy::getL2Val( u8& _val ) { _val = 0.f; if( ( m_portHandle < 0 ) || !m_controllerState.connected ) return false; _val = m_controllerState.analogButtons.l2; return true; } bool OrbisJoy::gerR2Val( u8& _val ) { _val = 0.f; if( ( m_portHandle < 0 ) || !m_controllerState.connected ) return false; _val = m_controllerState.analogButtons.r2; return true; } OrbisInput::OrbisInput() { } OrbisInput::~OrbisInput() { } void OrbisInput::init() { scePadInit(); // init joys SceUserServiceLoginUserIdList usersIds; int errorId = sceUserServiceGetLoginUserIdList( &usersIds ); if( errorId < 0 ) goto Error; int i; for(i = 0; i < SCE_USER_SERVICE_MAX_LOGIN_USERS; i++) { m_joys[i].init(usersIds.userId[i]); } return; Error: done(); } void OrbisInput::done() { int i; for(i = 0; i < SCE_USER_SERVICE_MAX_LOGIN_USERS; i++) { m_joys[i].done(); } } void OrbisInput::update() { int i; for(i = 0; i < SCE_USER_SERVICE_MAX_LOGIN_USERS; i++) { m_joys[i].update(); } } bool OrbisInput::isButtonPressed( u8 _controllerId, u32 _button ) { RAKI_ASSERT( _controllerId <= SCE_USER_SERVICE_MAX_LOGIN_USERS ); return m_joys[_controllerId].isButtonPressed( _button ); } bool OrbisInput::getLStickVal( u8 _controllerId, u8 _axe, u8& _val ) { RAKI_ASSERT( _controllerId <= SCE_USER_SERVICE_MAX_LOGIN_USERS ); return m_joys[ _controllerId].getLStickVal( _axe, _val ); } bool OrbisInput::getRStickVal( u8 _controllerId, u8 _axe, u8& _val ) { RAKI_ASSERT( _controllerId <= SCE_USER_SERVICE_MAX_LOGIN_USERS ); return m_joys[_controllerId].getRStickVal( _axe, _val ); } bool OrbisInput::getL2Val( u8 _controllerId, u8& _val ) { RAKI_ASSERT( _controllerId <= SCE_USER_SERVICE_MAX_LOGIN_USERS ); return m_joys[_controllerId].getL2Val( _val ); } bool OrbisInput::getR2Val( u8 _controllerId, u8& _val ) { RAKI_ASSERT( _controllerId <= SCE_USER_SERVICE_MAX_LOGIN_USERS ); return m_joys[_controllerId].gerR2Val( _val ); } }