Richard Parker / EALCD
Revision:
4:f8f7f4f9c58d
Parent:
1:f04bcaea1d60
Child:
7:6cf21b018420
diff -r 24fbf4dbd7e5 -r f8f7f4f9c58d manager/EATouchManager.cpp
--- a/manager/EATouchManager.cpp	Wed Mar 31 22:22:21 2010 +0000
+++ b/manager/EATouchManager.cpp	Mon Apr 26 21:37:54 2010 +0000
@@ -2,11 +2,15 @@
 #include "EATouchManager.h"
 
 #include "../screen/EATouch.h"
+#include "../screen/EALCD.h"
 #include "EAHitBox.h"
 
-EATouchManager::EATouchManager(EATouch& touch)
+EATouchManager::EATouchManager(EALCD& lcd, EATouch& touch)
 :   _touch(touch),
-    _head(NULL)
+    _lcd(lcd),
+    _head(NULL),
+    _count(0),
+    _timeout(200)
 {
 }
 
@@ -29,6 +33,50 @@
     if (p == true)
     {
         _doHits(x, y);
+        
+        // Reset the timeout count.
+        _watchReset();
+    }
+    
+    // Check the timeout. If reached then turn off the screen.
+    _watchCheck();
+}
+
+void EATouchManager::_watchReset()
+{
+    _count = 0;
+    
+    // If the lcd is off then turn it back on as the count has been reset.
+    if (_lcd.brightness() < 0.01)
+    {
+        float step = (_lcd.maxBrightness() - _lcd.brightness())/10;
+    
+        for(int i = 0; i < 10; i++)
+        {
+            _lcd.setBrightness(_lcd.brightness() + step);
+            wait(0.2);
+        }
+    }
+}
+
+void EATouchManager::_watchCheck()
+{  
+    // If the count has passed the timeout then turn the lcd off if it is on.
+    // Otherwise increment the count.
+    if (_count > _timeout)
+    {
+        if (_lcd.brightness() >= 0.01)
+        {
+            float step = _lcd.brightness()/10;
+        
+            for(int i = 0; i < 10; i++)
+            {
+                _lcd.setBrightness(_lcd.brightness() - step);
+                wait(0.2);
+            }            
+        }
+    } else {
+        _count++;
     }
 }