Last active
August 29, 2015 14:10
-
-
Save pingswept/baecafa306f24638a53d to your computer and use it in GitHub Desktop.
Demo of Precision Voltage Shield on Rascal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title>Battery Voltage</title> | |
| {% include "include/rascal-head.html" %} | |
| <style> | |
| #chart1 { | |
| margin-top: 20px; | |
| margin-left: -40px; | |
| height: 400px; | |
| width: 800px; | |
| } | |
| .jqplot-title, .jqplot-axis { | |
| color: #ddd; | |
| } | |
| .jqplot-table-legend-label { | |
| color: #111; | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| {% include "include/rascal-topbar.html" %} | |
| <div class="container"> | |
| <div class="well rascal"> | |
| <h1>Battery Voltage</h1> | |
| <div id="chart1"></div> | |
| </div> | |
| </div> | |
| <script type="text/javascript"> | |
| var chartOptions = { | |
| legend: { | |
| show: true, | |
| location: "ne" | |
| }, | |
| title: "Channel 1 & 2", | |
| series: [ | |
| {label: "Channel 1 (Bench Supply)", lineWidth: 3, showMarker: false} | |
| {label: "Channel 2 (Cell Battery)", lineWidth: 3, showMarker: false} | |
| ], | |
| axes: { | |
| xaxis: { | |
| label: "Time [seconds ago]", | |
| min: 0, | |
| max: 120, | |
| pad: 0, | |
| numberTicks: 9 | |
| }, | |
| yaxis: { | |
| label: "voltage [V] DC", | |
| min: 0, | |
| max: 3.5, | |
| numberTicks: 8 | |
| } | |
| }, | |
| seriesColors: [ "#cd2820", "#cd7f20" ] | |
| }; | |
| var | |
| a0 = [], | |
| a1 = [], | |
| firstTime = true, | |
| plot1; | |
| setInterval(function () { | |
| "use strict"; | |
| $.post("pvs/read", function (response) { | |
| var | |
| data = response.toString().split(','), | |
| i; | |
| console.log(data); | |
| var i; | |
| if (a0.length > chartOptions.axes.xaxis.max) { | |
| a0.pop(); | |
| a1.pop(); | |
| } | |
| // Add new value at beginning | |
| a0.unshift([0, data[0]]); | |
| a1.unshift([0, data[1]]); | |
| // Adjust old X values | |
| for (i = 1; i < a0.length; i++) { | |
| a0[i][0] = i; | |
| a1[i][0] = i; | |
| } | |
| if (firstTime) { | |
| plot1 = $.jqplot("chart1", [a0, a1], chartOptions); | |
| firstTime = false; | |
| } else { | |
| plot1.series[0].data = a0; | |
| plot1.series[1].data = a1; | |
| plot1.replot(); | |
| } | |
| }); | |
| }, 1000); | |
| </script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment