Pārlūkot izejas kodu

Display now shows time in bottom line

Philipp Hinz 8 gadi atpakaļ
vecāks
revīzija
2545943990
2 mainītis faili ar 22 papildinājumiem un 3 dzēšanām
  1. 1 0
      CoffeeCode/global.h
  2. 21 3
      CoffeeCode/main.cpp

+ 1 - 0
CoffeeCode/global.h

@@ -28,6 +28,7 @@
 extern int verbose, optPoll;
 extern bool optEcho, optInc, optLom, optTerm, optAdd, optDate, optSuppress;
 extern pthread_mutex_t mutex;
+extern int lcd;
 
 // CAN Filter - Should Incoming messages be filtered in Hardware?
 // #defining FILTER_USAGE means yes, otherwise no filtering applies

+ 21 - 3
CoffeeCode/main.cpp

@@ -15,6 +15,7 @@
 #include <unistd.h>
 #include <iostream>
 #include <csignal>
+#include <time.h>
 #include "global.h"
 #include "led.h"
 #include "timer.h"
@@ -27,6 +28,7 @@ const int buildno = (1+(int)(
 #include "buildno"
 		));
 
+int lcd = 0;
 int verbose = 0;
 int optPoll = 0;
 int optRes = 0;
@@ -39,10 +41,13 @@ bool optAdd = false;
 bool optDate = false;
 bool optSuppress = false;
 
+
 void *mainLoop(void *threadid);
 void terminationHandler(int signum);
 void usr1Handler(int signum);
 void hupHandler(int signum);
+void timeHandler(void);
+timer timeTimer(&timeHandler);
 pthread_t thread[3];
 pthread_mutex_t mutex;
 
@@ -205,7 +210,7 @@ int main(int argc, char *argv[]) {
 	pthread_attr_destroy(&attr);
 
 	// Insert main stuff here.
-	int lcd = lcdInit();
+	lcd = lcdInit();
 	if (lcd < 0) logger_error("Error: unable to init LCD (%d)\n", lcd);
 	lcdClear(lcd);
 	lcdHome(lcd);
@@ -284,10 +289,13 @@ void *mainLoop(void *threadid) {
 	 sqlInsertNode((uint8_t*)"3525   2", false, false);
 	 sqlInsertNode((uint8_t*)"sbw452 3", false, false);
 	 sqlInsertNode((uint8_t*)"s4t4   4", true, true);
-	 sqlInsertNode((uint8_t*)"te456  5", true, false);*/
-	sqlSetup();
+	 sqlInsertNode((uint8_t*)"te456  5", true, false);
+	sqlSetup();*/
 
 	// Do more stuff here
+	timeTimer.setDivider(1);
+	timeTimer.start();
+	lcdClear(lcd);
 
 	logger(V_BASIC, "Thread goes Sleeping..\n");
 	while (1) {
@@ -296,3 +304,13 @@ void *mainLoop(void *threadid) {
 	}
 	pthread_exit(NULL);
 }
+
+void timeHandler(void) {
+    time_t rawtime;
+    struct tm * timeinfo;
+
+    time ( &rawtime );
+    timeinfo = localtime ( &rawtime );
+	lcdPosition(lcd, 0, 1);
+	lcdPrintf(lcd, "%.2d:%.2d:%.2d   ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
+}