3 // Copyright (c) 2007 The Dasher Team
5 // This file is part of Dasher.
7 // Dasher is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // Dasher is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with Dasher; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #include "DasherInterfaceBase.h"
22 #include "DynamicButtons.h"
24 using namespace Dasher
;
26 CDynamicButtons::CDynamicButtons(CSettingsUser
*pCreator
, CDasherInterfaceBase
*pInterface
, CFrameRate
*pFramerate
, ModuleID_t iID
, const char *szName
)
27 : CDynamicFilter(pCreator
, pInterface
, pFramerate
, iID
, szName
), m_pModel(NULL
) {
28 m_bDecorationChanged
= true;
33 void CDynamicButtons::Timer(unsigned long iTime
, CDasherView
*pDasherView
, CDasherInput
*pInput
, CDasherModel
*pModel
, CExpansionPolicy
**pol
) {
34 if (isPaused()) return;
36 OneStepTowards(pModel
, 41943,2048, iTime
, FrameSpeedMul(pModel
, iTime
));
38 //moving forwards. Check auto speed control...
39 if (GetBoolParameter(BP_AUTO_SPEEDCONTROL
) && m_uSpeedControlTime
< iTime
) {
40 if (m_uSpeedControlTime
> 0) //has actually been set?
41 SetLongParameter(LP_MAX_BITRATE
, GetLongParameter(LP_MAX_BITRATE
) * (1.0 + GetLongParameter(LP_DYNAMIC_SPEED_INC
)/100.0));
42 m_uSpeedControlTime
= iTime
+ 1000*GetLongParameter(LP_DYNAMIC_SPEED_FREQ
);
44 TimerImpl(iTime
, pDasherView
, pModel
, pol
);
48 void CDynamicButtons::KeyDown(unsigned long iTime
, int iId
, CDasherView
*pView
, CDasherInput
*pInput
, CDasherModel
*pModel
) {
50 if(((iId
== 0) || (iId
== 1) || (iId
== 100)) && !GetBoolParameter(BP_BACKOFF_BUTTON
))
56 // Pass the basic key down event to the handler
57 ButtonEvent(iTime
, iId
, 0, pModel
);
63 void CDynamicButtons::KeyUp(unsigned long iTime
, int iId
, CDasherView
*pView
, CDasherInput
*pInput
, CDasherModel
*pModel
) {
64 if (iId
== m_iHeldId
) m_bKeyDown
= false;
67 void CDynamicButtons::ButtonEvent(unsigned long iTime
, int iButton
, int iType
, CDasherModel
*pModel
) {
69 // TODO: Check that state diagram implemented here is what we
72 // What happens next depends on the state:
74 //Any button causes a restart
75 if(CUserLogBase
*pUserLog
=m_pInterface
->GetUserLogPtr())
76 pUserLog
->KeyDown(iButton
, iType
, 1);
78 } else if (isReversing()) {
80 if(CUserLogBase
*pUserLog
=m_pInterface
->GetUserLogPtr())
81 pUserLog
->KeyDown(iButton
, iType
, 2);
85 //running; examine event/button-press type
87 case 0: //single press
88 if((iButton
== 0) || (iButton
== 100)) {
89 //dedicated pause button
90 if(CUserLogBase
*pUserLog
=m_pInterface
->GetUserLogPtr())
91 pUserLog
->KeyDown(iButton
, iType
, 2);
96 else if(iButton
== 1) {
97 //dedicated reverse button
98 if(CUserLogBase
*pUserLog
=m_pInterface
->GetUserLogPtr())
99 pUserLog
->KeyDown(iButton
, iType
, 6);
103 //else - any non-special button - fall through
104 default: //or, Any special kind of event - long, double, triple, ...
105 ActionButton(iTime
, iButton
, iType
, pModel
);
110 void CDynamicButtons::pause() {
111 CDynamicFilter::pause();
112 if (m_pModel
) m_pModel
->AbortOffset();
115 void CDynamicButtons::reverse(unsigned long iTime
) {
117 if (isPaused()) CDynamicFilter::run(iTime
);
118 if (GetBoolParameter(BP_AUTO_SPEEDCONTROL
)) {
119 //treat reversing as a sign of distress --> slow down!
120 SetLongParameter(LP_MAX_BITRATE
, GetLongParameter(LP_MAX_BITRATE
) *
121 (1.0 - GetLongParameter(LP_DYNAMIC_SPEED_DEC
)/100.0));
125 void CDynamicButtons::run(unsigned long iTime
) {
127 if (isPaused()) CDynamicFilter::run(iTime
); //wasn't running previously
128 m_uSpeedControlTime
= 0; //will be set in Timer()
131 void CDynamicButtons::ApplyOffset(CDasherModel
*pModel
, int iOffset
) {
132 (m_pModel
=pModel
)->Offset(iOffset
);