Selaa lähdekoodia

changed the time measurement at heating time from clock() to calendartime time()

Sebastian 7 vuotta sitten
vanhempi
commit
c2af5090c6
2 muutettua tiedostoa jossa 9 lisäystä ja 12 poistoa
  1. 8 11
      CoffeeCode/hal.cpp
  2. 1 1
      CoffeeCode/hal.h

+ 8 - 11
CoffeeCode/hal.cpp

@@ -29,7 +29,7 @@ timer Int0Timer(&halInt0TimerHandler);
 timer Int1Timer(&halInt1TimerHandler);
 timer idleTimer(&halIdleTimerHandler);
 
-clock_t heatingCycle[2] = {0, 0};
+time_t heatingCycle[2] = {0, 0};
 
 //delay of the debounce in milliseconds
 #define DELAY_DEBOUNCE	50
@@ -262,10 +262,10 @@ void halIntFlow(void) {
 void halIntPressure(void) {
 	logger(V_HAL, "IntPressure Control triggered\n");
 	if (halIsHeating()) {
-		heatingCycle[0] = clock();
+		time(&heatingCycle[0]);
 		halSendSignal(SigPressCls);
 	} else {
-		heatingCycle[1] = clock();
+		time(&heatingCycle[1]);
 		halSendSignal(SigPressOpn);
 	}
 }
@@ -275,17 +275,14 @@ void halIntPressure(void) {
  * If called during a heating process, it returns the time elapsed since the heating started
  * If called after a heating process, it returns the total time elapsed during the heating cycle
  */
-float halgetHeatingTime(void){
-	//TODO clock is the improper function for this purpose due to overflow etc
-	//maybe clock_gettime() or use time() and localtime()
-	//stackoverflow: clock() is defined to tell you how much CPU time is used; using more threads uses more CPU time, sleeping threads use less time.
+double halgetHeatingTime(void){
 	if (halIsHeating()) {
-		logger(V_HAL, "Hot Heating Time: %f\n", (float)(clock() - heatingCycle[0]) / CLOCKS_PER_SEC);
-		return (float)(clock() - heatingCycle[0]) / CLOCKS_PER_SEC;
+		logger(V_HAL, "Hot Heating Time: %f\n", difftime(time(0), heatingCycle[0]));
+		return difftime(time(0), heatingCycle[0]);
 	}
 	else {
-		logger(V_HAL, "Heating Time: %f\n", (float)(heatingCycle[1] - heatingCycle[0]) / CLOCKS_PER_SEC);
-		return (float)(heatingCycle[1] - heatingCycle[0]) / CLOCKS_PER_SEC;
+		logger(V_HAL, "Heating Time: %f\n", difftime(heatingCycle[1], heatingCycle[0]));
+		return difftime(heatingCycle[1], heatingCycle[0]);
 	}
 }
 

+ 1 - 1
CoffeeCode/hal.h

@@ -68,7 +68,7 @@ void halInt0(void);
 void halInt1(void);
 void halIntFlow(void);
 void halIntPressure(void);
-float halgetHeatingTime(void);
+double halgetHeatingTime(void);
 void halIntProximity(void);
 float halGetFlow(void);
 void halResetFlow(void);