Skip to content

Commit

Permalink
Fix issues with analog sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
salbahra committed Nov 27, 2023
1 parent a356d1b commit a7349c0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 40 deletions.
1 change: 0 additions & 1 deletion .vscode/extensions.json
@@ -1,6 +1,5 @@
{
"recommendations": [
"EditorConfig.EditorConfig",
"msjsdiag.debugger-for-chrome"
]
}
99 changes: 60 additions & 39 deletions www/js/analog.js
Expand Up @@ -11,8 +11,10 @@
*/

var analogSensors = {},
progAdjusts = {},
CHARTS = 11;
progAdjusts = {};
const CHARTS = 11;
const USERDEF_SENSOR = 49;
const USERDEF_UNIT = 99;

function checkAnalogSensorAvail() {
return controller.options && controller.options.feature === "ASB";
Expand Down Expand Up @@ -68,7 +70,7 @@ function updateSensorShowArea( page ) {
var sensor = analogSensors[ i ];
if ( sensor.show ) {
html += "<div id='sensor-show-" + sensor.nr + "' class='ui-body ui-body-a center'>";
html += "<label>" + sensor.name + ": " + Math.round( sensor.data ) + sensor.unit + "</label>";
html += "<label>" + sensor.name + ": " + ( Math.round( sensor.data + "e+2" ) + "e-2" ) + sensor.unit + "</label>";
html += "</div>";
}
}
Expand Down Expand Up @@ -331,6 +333,23 @@ function showSensorEditor( sensor, callback ) {
"</label>" +
"<input class='id' type='number' min='0' max='65535' value='" + sensor.id + "'>" +

((sensor.type === USERDEF_SENSOR) ?
("<label>" +
_( "Factor" ) +
"</label>" +
"<input class='fac' type='number' min='-32768' max='32767' value='" + sensor.fac + "'>" +

"<label>" +
_( "Divider" ) +
"</label>" +
"<input class='div' type='number' min='-32768' max='32767' value='" + sensor.div + "'>" +

"<label>" +
_( "Unit" ) +
"</label>" +
"<input class='unit' type='text' value='" + sensor.unit + "'>"
):"") +

"<label>" +
_( "Read Interval (s)" ) +
"</label>" +
Expand All @@ -344,15 +363,15 @@ function showSensorEditor( sensor, callback ) {
_( "Enable Data Logging" ) +
"</label>" +

"<label for='log'><input data-mini='true' id='show' type='checkbox' " + ( ( sensor.show === 1 ) ? "checked='checked'" : "" ) + ">" +
_( "Show on Main Page" ) +
"<label for='show'><input data-mini='true' id='show' type='checkbox' " + ( ( sensor.show === 1 ) ? "checked='checked'" : "" ) + ">" +
_( "Show on Mainpage" ) +
"</label>" +

"</div>" +

"<button class='submit' data-theme='b'>" + _( "Submit" ) + "</button>" +
"</div>" +
"</div>";
"</div>";

var popup = $( list ),

Expand Down Expand Up @@ -405,6 +424,9 @@ function showSensorEditor( sensor, callback ) {
port: parseInt( popup.find( ".port" ).val() ),
id: parseInt( popup.find( ".id" ).val() ),
ri: parseInt( popup.find( ".ri" ).val() ),
fac: parseInt( popup.find( ".fac" ).val() ),
div: parseInt( popup.find( ".div" ).val() ),
unit: popup.find( ".unit" ).val(),
enable: popup.find( "#enable" ).is( ":checked" ) ? 1 : 0,
log: popup.find( "#log" ).is( ":checked" ) ? 1 : 0,
show: popup.find( "#show" ).is( ":checked" ) ? 1 : 0
Expand Down Expand Up @@ -499,6 +521,11 @@ var showAnalogSensorConfig = ( function() {
"&port=" + sensorOut.port +
"&id=" + sensorOut.id +
"&ri=" + sensorOut.ri +
((sensorOut.type === USERDEF_SENSOR) ?
("&fac="+sensorOut.fac +
"&div="+sensorOut.div +
"&unit="+sensorOut.unit
):"") +
"&enable=" + sensorOut.enable +
"&log=" + sensorOut.log +
"&show=" + sensorOut.show
Expand Down Expand Up @@ -528,6 +555,11 @@ var showAnalogSensorConfig = ( function() {
"&port=" + sensorOut.port +
"&id=" + sensorOut.id +
"&ri=" + sensorOut.ri +
((sensorOut.type === USERDEF_SENSOR) ?
("&fac="+sensorOut.fac +
"&div="+sensorOut.div +
"&unit="+sensorOut.unit
):"") +
"&enable=" + sensorOut.enable +
"&log=" + sensorOut.log +
"&show=" + sensorOut.show
Expand Down Expand Up @@ -755,40 +787,25 @@ function buildSensorConfig() {
// Show Sensor Charts with apexcharts
var showAnalogSensorCharts = ( function() {

var max = CHARTS;
for ( var j = 0; j < analogSensors.length; j++ ) {
if (!analogSensors[j].log)
continue;
var unitid = analogSensors[j].unitid;
if (unitid === USERDEF_UNIT) max++;
}

var last = "", week = "", month = "";
for ( var j = 1; j <= max; j++ ) {
last += "<div id='myChart"+j+"'></div>";
week += "<div id='myChartW"+j+"'></div>";
month += "<div id='myChartM"+j+"'></div>";
}

var page = $( "<div data-role='page' id='analogsensorchart'>" +
"<div class='ui-content' role='main' style='width: 95%'>" +
"<div id='myChart1'></div>" +
"<div id='myChart2'></div>" +
"<div id='myChart3'></div>" +
"<div id='myChart4'></div>" +
"<div id='myChart5'></div>" +
"<div id='myChart6'></div>" +
"<div id='myChart7'></div>" +
"<div id='myChart8'></div>" +
"<div id='myChart9'></div>" +
"<div id='myChart10'></div>" +
"<div id='myChartW1'></div>" +
"<div id='myChartW2'></div>" +
"<div id='myChartW3'></div>" +
"<div id='myChartW4'></div>" +
"<div id='myChartW5'></div>" +
"<div id='myChartW6'></div>" +
"<div id='myChartW7'></div>" +
"<div id='myChartW8'></div>" +
"<div id='myChartW9'></div>" +
"<div id='myChartW10'></div>" +
"<div id='myChartM1'></div>" +
"<div id='myChartM2'></div>" +
"<div id='myChartM3'></div>" +
"<div id='myChartM4'></div>" +
"<div id='myChartM5'></div>" +
"<div id='myChartM6'></div>" +
"<div id='myChartM7'></div>" +
"<div id='myChartM8'></div>" +
"<div id='myChartM9'></div>" +
"<div id='myChartM10'></div>" +
"</div>" +
"</div>" );
last + week + month +
"</div></div>" );

function begin() {
$.mobile.loading( "show" );
Expand Down Expand Up @@ -851,7 +868,11 @@ function buildGraph( prefix, chart, csv, titleAdd, timestr ) {
}
var series = { name: analogSensors[ j ].name, data: logdata };

if ( unitid >= CHARTS ) {
// User defined sensor:
if (unitid === USERDEF_UNIT) {
unitid = chart.length;
chart.push(undefined);
} else if (unitid >= CHARTS) {
unitid = 0;
}

Expand Down

0 comments on commit a7349c0

Please sign in to comment.