[dasher] Reimplement and resurrect (now "static") "one button mode" as per manual



commit a38f97087f1376a9c05bf90ff844f27e7f3f6d71
Author: Alan Lawrence <acl33 inf phy cam ac uk>
Date:   Mon Aug 10 11:11:57 2009 +0200

    Reimplement and resurrect (now "static") "one button mode" as per manual

 ChangeLog                              |    2 +
 Src/DasherCore/DasherInterfaceBase.cpp |    3 +-
 Src/DasherCore/DasherInterfaceBase.h   |    1 -
 Src/DasherCore/OneButtonFilter.cpp     |   90 +++++++++++++++++++------------
 Src/DasherCore/OneButtonFilter.h       |    6 +--
 Src/DasherCore/Parameters.h            |    4 +-
 6 files changed, 64 insertions(+), 42 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index e15c7fb..d325f66 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,8 @@
 	* Remove a few unused variables / signedness fixes.
 	* Level-of-detail algorithm maintains LP_NODE_BUDGET extant DasherNode
 	  objects.
+	* Reimplement and resurrect "one button mode" as per manual.
+
 
 2009-08-08  Alan Lawrence <acl33 inf phy cam ac uk>
 
diff --git a/Src/DasherCore/DasherInterfaceBase.cpp b/Src/DasherCore/DasherInterfaceBase.cpp
index b5e623d..8544bc6 100644
--- a/Src/DasherCore/DasherInterfaceBase.cpp
+++ b/Src/DasherCore/DasherInterfaceBase.cpp
@@ -44,6 +44,7 @@
 #include "DefaultFilter.h"
 #include "DasherButtons.h"
 #include "EyetrackerFilter.h"
+#include "OneButtonFilter.h"
 #include "OneButtonDynamicFilter.h"
 #include "OneDimensionalFilter.h"
 #include "StylusFilter.h"
@@ -101,7 +102,6 @@ CDasherInterfaceBase::CDasherInterfaceBase() {
   
   m_iCurrentState = ST_START;
   
-  m_iLockCount = 0;
   //  m_bGlobalLock = false;
 
   // TODO: Are these actually needed?
@@ -945,6 +945,7 @@ void CDasherInterfaceBase::CreateModules() {
     RegisterModule(new CClickFilter(m_pEventHandler, m_pSettingsStore, this));
   );
 #endif
+  RegisterModule(new COneButtonFilter(m_pEventHandler, m_pSettingsStore, this));
   RegisterModule(new COneButtonDynamicFilter(m_pEventHandler, m_pSettingsStore, this));
   RegisterModule(new CTwoButtonDynamicFilter(m_pEventHandler, m_pSettingsStore, this));
   RegisterModule(new CTwoPushDynamicFilter(m_pEventHandler, m_pSettingsStore, this));
diff --git a/Src/DasherCore/DasherInterfaceBase.h b/Src/DasherCore/DasherInterfaceBase.h
index 1566ebd..f587a73 100644
--- a/Src/DasherCore/DasherInterfaceBase.h
+++ b/Src/DasherCore/DasherInterfaceBase.h
@@ -595,7 +595,6 @@ protected:
   /// @{
   //  bool m_bGlobalLock; // The big lock
   bool m_bRedrawScheduled;
-  int m_iLockCount;
   EState m_iCurrentState;
   bool m_bOldVisible;
 
diff --git a/Src/DasherCore/OneButtonFilter.cpp b/Src/DasherCore/OneButtonFilter.cpp
index d0db4b1..d413373 100644
--- a/Src/DasherCore/OneButtonFilter.cpp
+++ b/Src/DasherCore/OneButtonFilter.cpp
@@ -7,8 +7,14 @@
 
 using namespace Dasher;
 
+static SModuleSettings sSettings[] = {
+  {LP_STATIC1B_TIME, T_LONG, 100, 5000, 100, 1, _("Scan time (each direction), in ms")},
+  {LP_STATIC1B_ZOOM, T_LONG, 1, 16, 1, 1, _("Factor by which to zoom in")},
+  {LP_DYNAMIC_BUTTON_LAG, T_LONG, 0, 1000, 1, 25, _("Lag before user actually pushes button (ms)")},
+};
+
 COneButtonFilter::COneButtonFilter(Dasher::CEventHandler * pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface)
-  : CInputFilter(pEventHandler, pSettingsStore, pInterface, 9, 1, "One Button Mode") {
+  : CInputFilter(pEventHandler, pSettingsStore, pInterface, 9, 1, "Static One Button Mode") {
 
   bStarted = 0;
   iLocation = 0;
@@ -19,52 +25,66 @@ COneButtonFilter::~COneButtonFilter() {
 }
 
 bool COneButtonFilter::DecorateView(CDasherView *pView) {
+    
   CDasherScreen *pScreen(pView->Screen());
-  CDasherScreen::point p[2];
- 
-  myint iDasherX;
-  myint iDasherY;
-  
-  iDasherX = -100;
-  iDasherY = iLocation;
-  
-  pView->Dasher2Screen(iDasherX, iDasherY, p[0].x, p[0].y);
   
-  iDasherX = -1000;
-  iDasherY = iLocation;
+  if (iLocation == 0) {
+    if (!bStarted) return false;
+    //reverse!
+    CDasherScreen::point p[4];
+    pView->Dasher2Screen(2048, 0, p[0].x, p[0].y);
+    pView->Dasher2Screen(4096, 0, p[1].x, p[1].y);
+    pView->Dasher2Screen(4096, 4096, p[2].x, p[2].y);
+    pView->Dasher2Screen(2048, 4096, p[3].x, p[3].y);
+    pScreen->Polyline(p, 4, 1, 1);
+  } else {
+    CDasherScreen::point p[2];
   
-  pView->Dasher2Screen(iDasherX, iDasherY, p[1].x, p[1].y);
-  
-  pScreen->Polyline(p, 2, 1, 1);
-
+    pView->Dasher2Screen(-100, iLocation, p[0].x, p[0].y);
+    pView->Dasher2Screen(-1000, iLocation, p[1].x, p[1].y);
+    pScreen->Polyline(p, 2, 1, 1);
+  }
   return true;
 }
 
 bool COneButtonFilter::Timer(int Time, CDasherView *m_pDasherView, CDasherModel *m_pDasherModel, Dasher::VECTOR_SYMBOL_PROB *pAdded, int *pNumDeleted) {
 
-  if(bStarted)
-    iLocation = (Time - iStartTime) * 4096 / 1000;
-
-  if(iLocation > 4096) {
-    iLocation = 0;
-    iStartTime = Time;
+  if(bStarted) {
+    iLocation = (Time - iStartTime) * 4096 / GetLongParameter(LP_STATIC1B_TIME);
+    if (iLocation > 8192) {
+      //travelled down and back.
+      if (iLocation > 12288) bStarted = false; //wait for a button push then scan again
+      //else, leave bStarted = true -> "reverse"
+      iLocation = 0;
+    } else if (iLocation > 4096) {
+      //reached bottom, scan back up
+      iLocation = 8192-iLocation;
+    }
   }
     
-  return false;
-}
-
-void COneButtonFilter::KeyDown(int iTime, int iId, CDasherModel *pModel) {
-  bStarted = true;
-  iStartTime = iTime;
+  return m_pDasherModel->NextScheduledStep(Time, pAdded, pNumDeleted);
 }
 
-void COneButtonFilter::HandleEvent(Dasher::CEvent * pEvent) {
-  if(pEvent->m_iEventType == 1) {
-    Dasher::CParameterNotificationEvent * pEvt(static_cast < Dasher::CParameterNotificationEvent * >(pEvent));
-    
-    switch (pEvt->m_iParameter) {
-    default:
-      break;
+void COneButtonFilter::KeyDown(int iTime, int iId, CDasherView *pView, CDasherModel *pModel, CUserLogBase *pUserLog) {
+  if (bStarted) {
+    if (iLocation == 0) {
+      //back up by one zoom step.
+      pModel->ScheduleZoom(GetLongParameter(LP_STATIC1B_ZOOM) * 2048, 2048, 0);
+    } else {
+      iLocation -= (GetLongParameter(LP_DYNAMIC_BUTTON_LAG)*4096) / GetLongParameter(LP_STATIC1B_TIME);
+      if (iLocation < 0) iLocation +=4096;
+      pModel->ScheduleZoom(2048/GetLongParameter(LP_STATIC1B_ZOOM), iLocation, 0);
     }
+    bStarted = false;
+  } else {
+    bStarted = true;
+    iStartTime = iTime;
   }
 }
+
+bool COneButtonFilter::GetSettings(SModuleSettings **pSettings, int *iCount) {
+  *pSettings = sSettings;
+  *iCount = sizeof(sSettings) / sizeof(SModuleSettings);
+  
+  return true;
+};
diff --git a/Src/DasherCore/OneButtonFilter.h b/Src/DasherCore/OneButtonFilter.h
index 0cdc9d2..45c6f02 100644
--- a/Src/DasherCore/OneButtonFilter.h
+++ b/Src/DasherCore/OneButtonFilter.h
@@ -11,12 +11,10 @@ class COneButtonFilter : public CInputFilter {
   COneButtonFilter(Dasher::CEventHandler * pEventHandler, CSettingsStore *pSettingsStore, CDasherInterfaceBase *pInterface);
   ~COneButtonFilter();
 
-  virtual void HandleEvent(Dasher::CEvent * pEvent);
-
   virtual bool DecorateView(CDasherView *pView);
   virtual bool Timer(int Time, CDasherView *m_pDasherView, CDasherModel *m_pDasherModel, Dasher::VECTOR_SYMBOL_PROB *pAdded, int *pNumDeleted);
-  virtual void KeyDown(int iTime, int iId, CDasherModel *pModel);
-  
+  virtual void KeyDown(int iTime, int iId, CDasherView *pView, CDasherModel *pModel, CUserLogBase *pUserLog);
+  bool GetSettings(SModuleSettings **pSettings, int *iCount);
  private:
 
   bool bStarted;
diff --git a/Src/DasherCore/Parameters.h b/Src/DasherCore/Parameters.h
index c111d14..90446b9 100644
--- a/Src/DasherCore/Parameters.h
+++ b/Src/DasherCore/Parameters.h
@@ -62,7 +62,7 @@ enum {
   LP_CIRCLE_PERCENT, LP_TWO_BUTTON_OFFSET, LP_HOLD_TIME, LP_MULTIPRESS_TIME,
   LP_SLOW_START_TIME, LP_CONVERSION_ORDER, LP_CONVERSION_TYPE,
   LP_TWO_PUSH_OUTER, LP_TWO_PUSH_UP, LP_TWO_PUSH_DOWN, LP_TWO_PUSH_TOLERANCE,
-  LP_DYNAMIC_BUTTON_LAG,
+  LP_DYNAMIC_BUTTON_LAG, LP_STATIC1B_TIME, LP_STATIC1B_ZOOM,
   LP_DEMO_SPRING, LP_DEMO_NOISE_MEM, LP_DEMO_NOISE_MAG, LP_MAXZOOM, 
   LP_DYNAMIC_SPEED_INC, LP_DYNAMIC_SPEED_FREQ, LP_DYNAMIC_SPEED_DEC, END_OF_LPS
 };
@@ -222,6 +222,8 @@ static lp_table longparamtable[] = {
   {LP_TWO_PUSH_DOWN, "TwoPushDown", PERS, 1280, "Offset to down marker in one button dynamic"},
   {LP_TWO_PUSH_TOLERANCE, "TwoPushTolerance", PERS, 100, "Tolerance of two-push-mode pushes, in ms"},
   {LP_DYNAMIC_BUTTON_LAG, "DynamicButtonLag", PERS, 50, "Lag of pushes in dynamic button mode (ms)"},
+  {LP_STATIC1B_TIME, "Static1BTime", PERS, 2000, "Time for static-1B mode to scan from top to bottom (ms)"},
+  {LP_STATIC1B_ZOOM, "Static1BZoom", PERS, 8, "Zoom factor for static-1B mode"},
   {LP_DEMO_SPRING, "DemoSpring", PERS, 100, "Springyness in Demo-mode"},
   {LP_DEMO_NOISE_MEM, "DemoNoiseMem", PERS, 100, "Memory parameter for noise in Demo-mode"},
   {LP_DEMO_NOISE_MAG, "DemoNoiseMag", PERS, 325, "Magnitude of noise in Demo-mode"},



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]