1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     PadEx.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev:$
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_SAMPLE_DEMOS_PHTSEL_PADEX_H_
17 #define NN_SAMPLE_DEMOS_PHTSEL_PADEX_H_
18 
19 #include <nn/hid.h>
20 
21 ////////////////////////////////////////////////////////////////////////////////////////////////
22 /// Expand pad
23 ///
24 ////////////////////////////////////////////////////////////////////////////////////////////////
25 class PadEx
26 {
27 public:
PadEx(nn::hid::PadStatus & ps_)28     explicit PadEx( nn::hid::PadStatus& ps_ )
29         : ps(ps_)
30         , m_repeat(0)
31         , m_repeatCount(0)
32         , m_vcount(0)
33         , m_bCheckedNoHold(false)
34     {}
35 
Tick()36     void  Tick()
37     {
38         // Input is disabled until pad holds nothing at least once
39         if( !m_bCheckedNoHold )
40         {
41             if( 0==ps.hold ) m_bCheckedNoHold = true;
42             ps.hold = 0;
43             ps.trigger = 0;
44         }
45 
46         // Repeat processing
47         const GLint  vcount = nngxCheckVSync(NN_GX_DISPLAY0);
48 
49         m_repeat = 0;
50 
51         if( ps.trigger )
52         {
53             m_repeatCount = 0;
54             m_repeat = ps.trigger;
55         }
56 
57         if( m_vcount != vcount )
58         {
59             m_vcount = vcount;
60 
61             if( !ps.trigger && ps.hold ){
62                 ++m_repeatCount;
63             }
64             else{
65                 m_repeatCount = 0;
66             }
67 
68             static const s32  cDelay  = 16;
69             static const s32  cRepeat = 2;
70             if( m_repeatCount < cDelay ){
71             }
72             else if( (m_repeatCount - cDelay) % cRepeat == 0 ){
73                 m_repeat = ps.hold;
74             }
75         }
76     }
77 
78     /// Get repeat value
GetRepeat()79     bit32  GetRepeat() const  { return m_repeat; }
80 
81     /// Reset
Reset()82     void  Reset()
83     {
84         m_bCheckedNoHold = false;
85         ps.hold = 0;
86         ps.trigger = 0;
87     }
88 
89 public:
90     nn::hid::PadStatus&  ps;
91     bit32  m_repeat;
92     s32    m_repeatCount;
93     GLint  m_vcount;
94     bool   m_bCheckedNoHold;
95     NN_PADDING3;
96 };
97 
98 /* NN_SAMPLE_DEMOS_PHTSEL_PADEX_H_ */
99 #endif
100 
101 /*---------------------------------------------------------------------------*
102   End of file
103  *---------------------------------------------------------------------------*/
104