Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem ds3231 eeprom_Nikita mbed testUniGraphic_150217
Fork of merged_code2_3rd_nov_2017 by
Diff: touch_modules.cpp
- Revision:
- 37:92fcbf22bf91
- Parent:
- 35:43133f017ed4
- Child:
- 38:7238f3531ce9
diff -r 00d96aa14658 -r 92fcbf22bf91 touch_modules.cpp
--- a/touch_modules.cpp Sat Jul 29 11:23:19 2017 +0000
+++ b/touch_modules.cpp Sat Jul 29 12:12:28 2017 +0000
@@ -9,7 +9,7 @@
unsigned int xt=0;
unsigned int yt=0;
Serial kc(USBTX, USBRX);
-
+Timer t1;
void touch1() //determining the touch co-ordinates
{
@@ -20,13 +20,32 @@
}
-void detect_touch() // detect the touch //debounce
+void detect_touch(unsigned char display_state) // detect the touch //debounce
{
-
-while(i==1)
-{
- while(Touch_D)//touch detection
+kc.printf("display state=%d\n",display_state);
+uint32_t time_ms=0;
+switch (display_state)
+
+ {
+
+ case 3: time_ms= 3000000; // timer for 5 min
+ touch_func_with_timer(time_ms);
+ break;
+ case 6: time_ms= 60000; // timer for 1 min
+ touch_func_with_timer(time_ms);
+ break;
+ default : touch_func_without_timer();
+ break;
+
+ }
+}
+
+ void touch_func_without_timer()
+ {
+ while(i==1)
{
+ while(Touch_D)//touch detection
+ {
wait_ms(200); ///wait for debounce check
if (Touch_D)
{
@@ -39,11 +58,14 @@
//kc.printf("touch");
}
- }
- EnableTouch();
+ }
+}
+
+void no_touch()
+{
+ xt=0;yt=0;
- }
-
+ }
unsigned char touch_main() //determining the touch for home screen
@@ -129,10 +151,14 @@
state=1;
}
-
+ else if (xt==0 && yt==0)
+ {
+ state=1;
+ }
else
+ {
state=10; // default - goes to wait for a valid touch
-
+ }
return state;
}
@@ -182,6 +208,10 @@
state=8;
else if (type==2)
state=9;
+ }
+ else if (xt==0 && yt==0)
+ {
+ state=3;
}
else
state=10;
@@ -449,4 +479,48 @@
DigitalOut XL(PTC13);
DigitalOut YU(PTC0);
DigitalOut XR(PTB0);
- }
\ No newline at end of file
+ }
+
+uint32_t get_timer()
+{
+ kc.printf("time=%d",t1.read_ms());
+ return t1.read_ms();
+ }
+
+
+
+void touch_func_with_timer(uint32_t time_ms)
+ {
+ t1.reset();
+ while(i==1)
+ {
+ t1.start();
+ if (get_timer()<time_ms)
+ {
+ while(Touch_D)//touch detection
+ {
+ wait_ms(200); ///wait for debounce check
+ if (Touch_D)
+ {
+ Touch_D.fall(&touch1);
+
+ //determine the touch co-ordinates
+ break;
+ }
+ DisableTouch();
+ //kc.printf("touch");
+
+ }
+ }
+ else
+ {
+ t1.stop();
+ t1.reset();
+ DisableTouch();
+ no_touch();
+ break;
+
+ }
+
+ }
+}
\ No newline at end of file
