浏览代码

add battery indicator

Christian Herzog 5 年之前
父节点
当前提交
992c8d2679

+ 1 - 0
components/wifi-manager/battery-0.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 8v8h-17v-8h17zm2-2h-21v12h21v-12zm1 9h.75c.69 0 1.25-.56 1.25-1.25v-3.5c0-.69-.56-1.25-1.25-1.25h-.75v6z"/></svg>

+ 1 - 0
components/wifi-manager/battery-1.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 8v8h-17v-8h17zm2-2h-21v12h21v-12zm1 9h.75c.69 0 1.25-.56 1.25-1.25v-3.5c0-.69-.56-1.25-1.25-1.25h-.75v6zm-16-6h-3v6h3v-6z"/></svg>

+ 1 - 0
components/wifi-manager/battery-2.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 8v8h-17v-8h17zm2-2h-21v12h21v-12zm1 9h.75c.69 0 1.25-.56 1.25-1.25v-3.5c0-.69-.56-1.25-1.25-1.25h-.75v6zm-16-6h-3v6h3v-6zm4 0h-3v6h3v-6z"/></svg>

+ 1 - 0
components/wifi-manager/battery-3.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 8v8h-17v-8h17zm2-2h-21v12h21v-12zm1 9h.75c.69 0 1.25-.56 1.25-1.25v-3.5c0-.69-.56-1.25-1.25-1.25h-.75v6zm-16-6h-3v6h3v-6zm4 0h-3v6h3v-6zm4 0h-3v6h3v-6z"/></svg>

+ 1 - 0
components/wifi-manager/battery-4.svg

@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M19 8v8h-17v-8h17zm2-2h-21v12h21v-12zm1 9h.75c.69 0 1.25-.56 1.25-1.25v-3.5c0-.69-.56-1.25-1.25-1.25h-.75v6zm-16-6h-3v6h3v-6zm4 0h-3v6h3v-6zm4 0h-3v6h3v-6zm4 0h-3v6h3v-6z"/></svg>

+ 22 - 0
components/wifi-manager/code.js

@@ -706,6 +706,24 @@ function checkStatus(){
                 lastMsg = msg;
             }
         }
+        if (data.hasOwnProperty('Voltage')) {
+            var voltage = data['Voltage'];
+            var i;
+            if (voltage > 0) {
+                if (inRange(voltage, 5.8, 6.2) || inRange(voltage, 8.8, 9.2)) {
+                    i = 0;
+                } else if (inRange(voltage, 6.2, 6.8) || inRange(voltage, 9.2, 10.0)) {
+                    i = 1;
+                } else if (inRange(voltage, 6.8, 7.1) || inRange(voltage, 10.0, 10.5)) {
+                    i = 2;
+                } else if (inRange(voltage, 7.1, 7.5) || inRange(voltage, 10.5, 11.0)) {
+                    i = 3;
+                } else {
+                    i = 4;
+                }
+                $("#battery").html('<img src="battery-'+i+'.svg" />');
+            }
+        }
         blockAjax = false;
     })
     .fail(function(xhr, ajaxOptions, thrownError) {
@@ -778,3 +796,7 @@ function showMessage(message, severity) {
         });
     });
 }
+
+function inRange(x, min, max) {
+    return ((x-min)*(x-max) <= 0);
+}

+ 1 - 0
components/wifi-manager/index.html

@@ -24,6 +24,7 @@
     </head>
 
     <body>
+        <div id="battery"></div>
         <ul id="navbar" class="nav nav-tabs">
             <li class="nav-item">
                 <a class="nav-link active" data-toggle="tab" href="#tab-wifi">WiFi</a>

+ 13 - 0
components/wifi-manager/style.css

@@ -308,6 +308,19 @@ span#flash-status {
     font-size: 120%;
 }
 
+#battery {
+    padding-top: 7px;
+    float: right;
+}
+
+ul#navbar {
+    border-bottom: 0px;
+}
+
+#content {
+    border-top: 1px solid black;
+}
+
 .footer {
   position: fixed;
   left: 0;