Profile progress is visible in the web interface

Wed, 03 Sep 2014 15:02:09 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 03 Sep 2014 15:02:09 +0200
changeset 284
9e6fb5aed618
parent 283
affe4d2adc94
child 285
bbe73c2ecacf

Profile progress is visible in the web interface

thermferm/rdconfig.c file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
www-thermferm/getstate.php file | annotate | diff | comparison | revisions
www-thermferm/liveview.php file | annotate | diff | comparison | revisions
--- a/thermferm/rdconfig.c	Tue Sep 02 16:54:18 2014 +0200
+++ b/thermferm/rdconfig.c	Wed Sep 03 15:02:09 2014 +0200
@@ -856,6 +856,7 @@
     unit->idle_rangeH = 1.0;
     unit->idle_rangeL = -1.0;
     unit->prof_started = unit->prof_paused = (time_t)0;
+    unit->prof_percent = 0;
     unit->PID_err_old = unit->PID_I_err = 0.0;
 
     cur = cur->xmlChildrenNode;
--- a/thermferm/server.c	Tue Sep 02 16:54:18 2014 +0200
+++ b/thermferm/server.c	Wed Sep 03 15:02:09 2014 +0200
@@ -1458,6 +1458,7 @@
 	unit->idle_rangeH = 1.0;
 	unit->idle_rangeL = -1.0;
 	unit->prof_started = unit->prof_paused = (time_t)0;
+	unit->prof_percent = 0;
 	unit->PID_err_old = unit->PID_I_err = 0.0;
 
 	/*
@@ -1546,7 +1547,11 @@
 		srv_send((char *)"BEER_SET,%.1f", unit->beer_set);
 		srv_send((char *)"PROFILE,%s", unit->profile);
 		srv_send((char *)"PROF_STARTED,%d", (int)unit->prof_started);
-		srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]);
+		if (unit->prof_state == PROFILE_RUN) {
+		    srv_send((char *)"PROF_STATE,%s %d%%", PROFSTATE[unit->prof_state], unit->prof_percent);
+		} else {
+		    srv_send((char *)"PROF_STATE,%s", PROFSTATE[unit->prof_state]);
+		}
 		srv_send((char *)"PROF_TARGET,%.3f", unit->prof_target);
 		srv_send((char *)"TEMP_SET_MIN,%.1f", unit->temp_set_min);
 		srv_send((char *)"TEMP_SET_MAX,%.1f", unit->temp_set_max);
--- a/thermferm/thermferm.c	Tue Sep 02 16:54:18 2014 +0200
+++ b/thermferm/thermferm.c	Wed Sep 03 15:02:09 2014 +0200
@@ -1112,6 +1112,7 @@
 			    switch (unit->prof_state) {
 				case PROFILE_OFF:
 						unit->prof_target = profile->inittemp;
+						unit->prof_percent = 0;
 						break;
 				case PROFILE_PAUSE:
 						/*
@@ -1176,16 +1177,18 @@
 						    fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds);
 
 						if (valid_step == TRUE) {
+						    unit->prof_percent = (100 * run_minutes) / tot_minutes;
 						    if (((minutes == 10) || (minutes == 40)) && (seconds == 1)) {
 						    	syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, target %.3f degrees", 
 								profile->name, run_hours / 24, run_hours % 24, run_minutes % 60, current_step, 
-								(100 * run_minutes) / tot_minutes, unit->prof_target);
+								unit->prof_percent, unit->prof_target);
 						    }
 						} else {
 						    /*
 						     * No more steps to do
 						     */
 						    unit->prof_state = PROFILE_DONE;
+						    unit->prof_percent = 100;
 						    syslog(LOG_NOTICE, "Profile `%s' is done", profile->name);
 						}
 						break;
@@ -1201,6 +1204,7 @@
 						    previous_target = step->target;
 						}
 						unit->prof_target = previous_target;
+						unit->prof_percent = 100;
 						break;
 			    } /* switch */
 			}
--- a/thermferm/thermferm.h	Tue Sep 02 16:54:18 2014 +0200
+++ b/thermferm/thermferm.h	Wed Sep 03 15:02:09 2014 +0200
@@ -138,6 +138,7 @@
     int			prof_state;		/* Profile OFF|PAUSE|RUN|DONE	*/
     float		prof_target;		/* Profile current target temp	*/
     time_t		prof_paused;		/* Profile total pause time	*/
+    int			prof_percent;		/* Profile percentage done	*/
     float		PID_I_err;		/* PID Intergal error		*/
     float		PID_err_old;		/* PID old error value		*/
 } units_list;
--- a/www-thermferm/getstate.php	Tue Sep 02 16:54:18 2014 +0200
+++ b/www-thermferm/getstate.php	Wed Sep 03 15:02:09 2014 +0200
@@ -26,7 +26,7 @@
 if (isset($_GET["uuid"]))
 	$uuid = $_GET["uuid"];
 else
-	$uuid = "0e261929-486d-4117-897a-2b23509157c6";
+	$uuid = "48c9ae27-3f58-41c9-ae4b-1d57b249c45a";
 
 $answer = send_cmd('UNIT GET '.$uuid);
 $arr = explode("\r\n", $answer);
@@ -40,6 +40,7 @@
 $fridge_set = "NA";
 $beer_set = "NA";
 $heater = $cooler = $fan = "no";
+$prof_state = "OFF";
 
 
 if (startsWith($arr[0], "213")) {
@@ -83,6 +84,8 @@
 		$target_temperature = $f[1];
 	if (($f[0] == "PROF_TARGET") && ($mode == "PROFILE"))
 		$target_temperature = $f[1];
+	if (($f[0] == "PROF_STATE") && ($mode == "PROFILE"))
+		$prof_state = $f[1];
 	$j++;
     }
 }
@@ -137,7 +140,8 @@
     'led3'                => $led3,
     'sw1'                 => $sw1,
     'sw2'                 => $sw2,
-    'sw3'                 => $sw3
+    'sw3'                 => $sw3,
+    'profile_state'       => $prof_state
 );
 
 
--- a/www-thermferm/liveview.php	Tue Sep 02 16:54:18 2014 +0200
+++ b/www-thermferm/liveview.php	Wed Sep 03 15:02:09 2014 +0200
@@ -194,6 +194,8 @@
 	$outstr .= '           $("#load_sw1_'.$unr.'").html(data.sw1);'.PHP_EOL;
 	$outstr .= '           $("#load_sw2_'.$unr.'").html(data.sw2);'.PHP_EOL;
 	$outstr .= '           $("#load_sw3_'.$unr.'").html(data.sw3);'.PHP_EOL;
+	if ($mode == "PROFILE")
+	    $outstr .= '           $("#prof_state_'.$unr.'").html(data.profile_state);'.PHP_EOL;
         $outstr .= '         });'.PHP_EOL;
 	$outstr .= '       }, 10000);'.PHP_EOL;
 	$outstr .= '     });'.PHP_EOL;
@@ -268,7 +270,7 @@
 		}
 	    }
 	    $outstr .= '       <div style="color: blue; width: 148px; height: 23px; overflow: hidden;">Profile: '.$prof_name.'</div>'.PHP_EOL;
-	    $outstr .= '       <div style="color: blue; width: 148px; height: 23px; overflow: hidden;">State: '.$prof_state.'</div>'.PHP_EOL;
+	    $outstr .= '       <div id="prof_state_'.$unr.'" style="color: blue; width: 148px; height: 23px; overflow: hidden;">State: '.$prof_state.'</div>'.PHP_EOL;
 
 	    $outstr .= '       <form id="set_profile_'.$unr.'" action="index.php" method="post">'.PHP_EOL;
 	    if ($prof_state == "OFF") {
@@ -292,7 +294,7 @@
 		if ($profile != "(null)")
 		    $outstr .= '        <input type="submit" value="Start" name="key">'.PHP_EOL;
 
-	    } else if ($prof_state == "RUN") {
+	    } else if (startsWith($prof_state, "RUN")) {
 		$outstr .= '        <input type="hidden" value="'.$profile.'" name="SetProfile">'.PHP_EOL;
 		$outstr .= '        <input type="submit" value="Pause" name="key">'.PHP_EOL;
 		$outstr .= '        <input type="submit" value="Abort" name="key">'.PHP_EOL;
@@ -304,7 +306,6 @@
 		$outstr .= '        <input type="hidden" value="'.$profile.'" name="SetProfile">'.PHP_EOL;
 		$outstr .= '        <input type="submit" value="Off" name="key">'.PHP_EOL;
 	    }
-	    //$outstr .= '        <input type="text" name="Beer" size="5" value="'.$set_temperature.'">'.PHP_EOL;
 	    $outstr .= '        <input type="hidden" value="'.$unit.'" name="UUID">'.PHP_EOL;
 	    $outstr .= '       </form>'.PHP_EOL;
 	}

mercurial