From 6c7f26622e51a2e9e1a95204ad852e8568293a2a Mon Sep 17 00:00:00 2001
From: John Lee <john.lee@hardkernel.com>
Date: Mon, 27 Mar 2017 20:56:16 +0900
Subject: [PATCH] Fix the LCD display of watt hours, display volts and amps to
 three decimal places on the web interface.

---
 data/index.html     | 23 ++++++++++++++++++++++-
 src/smartpower2.ino | 20 +++++++++++---------
 2 files changed, 33 insertions(+), 10 deletions(-)

diff --git a/data/index.html b/data/index.html
index 58116c8..57d35d2 100644
--- a/data/index.html
+++ b/data/index.html
@@ -114,8 +114,29 @@
                     if (watth != dataInfo[3]) {
                         watth = dataInfo[3];
                         $("#sevenseg_watthour").sevenSeg({
-                            value: dataInfo[3]
+                            value: watth
                         });
+			if (watth < 10) {
+				$("#sevenseg_watthour").sevenSeg({
+				digits: 4,
+				decimalPlaces: 3
+				});
+			} else if (watth < 100) {
+				$("#sevenseg_watthour").sevenSeg({
+				digits: 4,
+				decimalPlaces: 2
+				});
+			} else if (watth < 1000) {
+				$("#sevenseg_watthour").sevenSeg({
+				digits: 4,
+				decimalPlaces: 1
+				});
+			} else {
+				$("#sevenseg_watthour").sevenSeg({
+				digits: 4,
+				decimalPlaces: 0
+				});
+			}
                     }
                     break;
                 case MEASUREWATTHOUR:
diff --git a/src/smartpower2.ino b/src/smartpower2.ino
index 4012ae1..8771432 100644
--- a/src/smartpower2.ino
+++ b/src/smartpower2.ino
@@ -41,7 +41,7 @@ WiFiClient logClient;
 #define MEASUREWATTHOUR		'm'
 #define FW_VERSION			'f'
 
-#define FWversion	1.1
+#define FWversion	1.2
 
 uint8_t onoff = OFF;
 unsigned char measureWh;
@@ -511,6 +511,7 @@ void lcd_status(void)
 
 void printPower_LCD(void)
 {
+	double rwatth;
 	lcd.setCursor(0, 0);
 	lcd.print(volt, 3);
 	lcd.print(" V ");
@@ -525,17 +526,18 @@ void printPower_LCD(void)
 	}
 	lcd.print(" W ");
 
-	if (watth < 10) {
-		lcd.print(watth, 3);
+	rwatth = watth/3600;
+	if (rwatth < 10) {
+		lcd.print(rwatth, 3);
 		lcd.print(" ");
-	} else if (watth < 100) {
-		lcd.print(watth, 2);
+	} else if (rwatth < 100) {
+		lcd.print(rwatth, 2);
 		lcd.print(" ");
-	} else if (watth < 1000) {
-		lcd.print(watth, 1);
+	} else if (rwatth < 1000) {
+		lcd.print(rwatth, 1);
 		lcd.print(" ");
 	} else {
-		lcd.print(watth/1000, 0);
+		lcd.print(rwatth/1000, 0);
 		lcd.print(" K");
 	}
 	lcd.print("Wh     ");
@@ -751,7 +753,7 @@ void handler(void)
 	if (connectedWeb) {
 		if (onoff == ON) {
 			String data = String(DATA_PVI);
-			data += String(watt, 3) + "," + String(volt) + "," + String(ampere);
+			data += String(watt, 3) + "," + String(volt, 3) + "," + String(ampere, 3);
 			if (measureWh) {
 				watth += watt;
 			}
-- 
GitLab