/*---------------------------------------------------------------------------* Project: NintendoWare File: demo_Pad.cpp Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Revision:$ *---------------------------------------------------------------------------*/ #include namespace nw { namespace demo { Pad* PadFactory::s_pPad = NULL; //-------------------------------------------------------------------------- Pad* Pad::Create(os::IAllocator* allocator) { NW_NULL_ASSERT( allocator ); void* memory = allocator->Alloc( sizeof(Pad) ); NW_ASSERT( memory != NULL ); Pad* pad = new(memory) Pad(); pad->m_Allocator = allocator; return pad; } //-------------------------------------------------------------------------- void Pad::Destroy() { os::IAllocator* allocator = this->m_Allocator; NW_ASSERT( allocator != NULL ); this->~Pad(); allocator->Free(this); } //-------------------------------------------------------------------------- void Pad::Initialize() { nn::Result result = nn::hid::CTR::Initialize(); // 下記マクロを使用すると、他所でnn::hid::CTR::Initialize()が呼ばれると // エラーを出すため、コメントアウトしています。 //NN_UTIL_PANIC_IF_FAILED( result ); Reset(); } //-------------------------------------------------------------------------- void Pad::Finalize() { // 注意:PadをFinalizeすると、hidのFinalize()を行うため、 //    これ以降でhidを使用できなくなります。 nn::hid::CTR::Finalize(); } //-------------------------------------------------------------------------- void Pad::Update() { if (m_IsTestMode) { m_PadButton.Update( m_TestPadStatus ); m_AnalogStickX = 0; m_AnalogStickY = 0; m_AnalogStick.x = 0; m_AnalogStick.y = 0; } else { nn::hid::PadReader padReader; padReader.ReadLatest( &m_PadStatus ); m_PadButton.Update( static_cast( m_PadStatus.hold ) ); m_AnalogStickX = m_PadStatus.stick.x; m_AnalogStickY = m_PadStatus.stick.y; m_AnalogStick.x = static_cast( m_PadStatus.stick.x ) / nn::hid::CTR::LIMIT_OF_STICK_CLAMP_MAX; m_AnalogStick.y = static_cast( m_PadStatus.stick.y ) / nn::hid::CTR::LIMIT_OF_STICK_CLAMP_MAX; } } //-------------------------------------------------------------------------- void Pad::Reset() { m_PadButton.Reset(); } //-------------------------------------------------------------------------- bool Pad::IsButtonPress( Button button ) const { return m_PadButton.IsButtonPress( button ); } //-------------------------------------------------------------------------- bool Pad::IsButtonDown( Button button ) const { return m_PadButton.IsButtonDown( button ); } //-------------------------------------------------------------------------- bool Pad::IsButtonUp( Button button ) const { return m_PadButton.IsButtonUp( button ); } //-------------------------------------------------------------------------- bool Pad::IsButtonRepeat( Button button ) const { return m_PadButton.IsButtonRepeat( button ); } //-------------------------------------------------------------------------- bool Pad::IsButtonRepeatFast( Button button ) const { return m_PadButton.IsButtonRepeatFast( button ); } //-------------------------------------------------------------------------- void PadFactory::Initialize(os::IAllocator* allocator) { NW_ASSERT( s_pPad == NULL ); s_pPad = Pad::Create( allocator ); s_pPad->Initialize(); } //-------------------------------------------------------------------------- void PadFactory::Finalize() { NW_NULL_ASSERT( s_pPad ); s_pPad->Finalize(); s_pPad->Destroy(); s_pPad = NULL; } //-------------------------------------------------------------------------- Pad* PadFactory::GetPad() { NW_NULL_ASSERT( s_pPad ); return s_pPad; } } // namespace nw::demo } // namespace nw