While I was thinking about logging sensor values, I noticed that I have not got clock for this board. Blowsing the mbed API, I found that the ticker could be used. So this is my first trial of implementing a clock using the ticker. Meantime I added getPoint in my SPI_STMPE610 lib so that the x and y coordinate can be directly read.

Dependencies:   SPI_STMPE610 SPI_TFT_ILI9341 TFT_fonts mbed

Tokei means a clock or a watch in Japanese. To log values of sensor(s) I needed a way to trace the time. At first, knowing that the RTC is not connected in FRDM-KL25Z I thought it must be difficult to implement a clock, but finding the "ticker" in mbed lib, at least I could give a try.

センサの値をログするのに時計機能が欲しいかなと思っていたのですが、FRDM-KL25ZではRTCに32KHzが接続されていないのでちょっと難しいかなと mbed の API を見ていたら ticker というのがありました(笑)

/media/uploads/Rhyme/tokei.jpg

Since it must be painful to set the time each time powering the board, I implemented the minimum functions to set the time (hour, min, sec) using the Adafruit 2.8" TFT and Touch Sensor.

流石に起動毎にシリアルから時間を設定するのは厳しそうだったので とりあえず時、分、秒を設定できる最低限のUIも付けて見ました。

/media/uploads/Rhyme/set_hour.jpg /media/uploads/Rhyme/set_min.jpg /media/uploads/Rhyme/set_sec.jpg

Files at this revision

API Documentation at this revision

Comitter:
Rhyme
Date:
Sat Dec 13 09:07:54 2014 +0000
Parent:
0:94d52137914c
Commit message:
some clean up is done

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 94d52137914c -r a3749e465942 main.cpp
--- a/main.cpp	Sat Dec 13 08:48:34 2014 +0000
+++ b/main.cpp	Sat Dec 13 09:07:54 2014 +0000
@@ -34,9 +34,6 @@
 
 Ticker timer ;
 bool ticked = false ;
-int year = 2014 ;
-int month = 12 ;
-int day = 13 ;
 int hour = 14 ;
 int min = 40 ;
 int sec = 0 ;
@@ -68,6 +65,16 @@
     TFT.printf("OK") ;
 }
 
+void draw_tmp_value(uint16_t value)
+{
+    char str[8] ;
+    TFT.foreground(White) ;
+    TFT.set_font((unsigned char*) Arial28x28);
+    sprintf(str, " %02d ", value) ;
+    TFT.locate(80, 120) ;
+    TFT.printf(str) ;
+}
+
 int getAdjustMenu(void)
 {
     uint16_t x, y, z ;
@@ -90,7 +97,6 @@
 {
     bool selected = false ;
     int16_t tmp_hour, prev_value = -1 ;
-    char str[4] ;
     tmp_hour = hour ;
     TFT.cls() ;
     TFT.foreground(White) ;
@@ -100,12 +106,7 @@
      
     while(!selected) {
         if (tmp_hour != prev_value) {
-            TFT.foreground(White) ;
-            TFT.set_font((unsigned char*) Arial28x28);
-            sprintf(str, " %02d ", tmp_hour) ;
-            TFT.locate(80, 120) ;
-            TFT.printf(str) ;
-    
+            draw_tmp_value(tmp_hour) ;   
             drawAdjustMenu() ;   
             prev_value = tmp_hour ;    
         }
@@ -141,7 +142,6 @@
 {
     bool selected = false ;
     int16_t tmp_min, prev_value = -1 ;
-    char str[4] ;
     tmp_min = min ;
     TFT.cls() ;
     TFT.set_font((unsigned char*) Arial28x28);
@@ -151,12 +151,7 @@
 
     while(!selected) {
         if (tmp_min != prev_value) {
-            TFT.set_font((unsigned char*) Arial28x28);
-            TFT.foreground(White) ;
-            sprintf(str, " %02d ", tmp_min) ;
-            TFT.locate(80, 120) ;
-            TFT.printf(str) ;
-    
+            draw_tmp_value(tmp_min) ;
             drawAdjustMenu() ;   
             prev_value = tmp_min ;   
         }
@@ -192,7 +187,6 @@
 {
     bool selected = false ;
     int16_t tmp_sec, prev_value = -1 ;
-    char str[4] ;
     tmp_sec = sec ;
     TFT.cls() ;
     TFT.foreground(White) ;
@@ -202,12 +196,7 @@
 
     while(!selected) {
         if (tmp_sec != prev_value) {
-            TFT.set_font((unsigned char*) Arial28x28);
-            TFT.foreground(White) ;
-            sprintf(str, " %02d ", tmp_sec) ;
-            TFT.locate(80, 120) ;
-            TFT.printf(str) ;
-    
+            draw_tmp_value(tmp_sec) ; 
             drawAdjustMenu() ;    
             prev_value = tmp_sec ;
         }
@@ -269,7 +258,6 @@
         min = min % 60 ;
     }
     if (hour > 23) {
-        day++ ;
         hour = hour % 24 ;
     }
     ticked = true ;
@@ -289,9 +277,10 @@
     
     initTFT() ;
     timer.attach(&tick_time, 1) ;
+    backlight = 1 ;
+    set_time() ;
     draw_adjust_str() ;
-    backlight = 1 ;
-    
+ 
     for(;;) {
         if (ticked) {
             display_time() ;