Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
* Usability and optimization updates
  • Loading branch information
sergejey committed Jan 31, 2019
1 parent ecbd69c commit fe0e1b4
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 24 deletions.
22 changes: 8 additions & 14 deletions modules/megad/megad.class.php
Expand Up @@ -217,7 +217,7 @@ function usual(&$out)

if ($device && $command) {
$result = $this->sendCommand($device, $command);
$this->readValues($device);
$this->readValues($device,'',1);
if ($result) {
echo "OK: ".$result;
} else {
Expand All @@ -243,7 +243,7 @@ function readConfig($id)
require(DIR_MODULES . $this->name . '/readconfig.inc.php');
}

function readValues($id, $all = '')
function readValues($id, $all = '', $quick = 0)
{
require(DIR_MODULES . $this->name . '/readvalues.inc.php');
}
Expand Down Expand Up @@ -376,6 +376,7 @@ function processRequest()

if (isset($_GET['all'])) {
$this->readValues($rec['ID'], $_GET['all']);
return;
}

$commands=array();
Expand Down Expand Up @@ -429,7 +430,7 @@ function processRequest()
$commands[] = array('NUM' => 0, 'COMMAND' => 'inttemp', 'VALUE' => $at);
}
foreach($commands as $command) {
$this->processCommand($rec['ID'],$command);
$this->processCommand($rec['ID'],$command,1);
}
}

Expand All @@ -447,13 +448,6 @@ function processRequest()
}
}
$mega_id = $rec['ID'];
/*
$code = '';
$code .= 'include_once(DIR_MODULES."megad/megad.class.php");';
$code .= '$mega=new megad();';
$code .= '$mega->readValues(' . (int)$mega_id . ');';
setTimeOut('mega_refresh_' . $mega_id, $code, 1);
*/
$url=BASE_URL.'/ajax/megad.html?op=readvalues&device='.$mega_id;
$code='getURL("'.$url.'",0);';
setTimeOut('mega_refresh_' . $mega_id, $code, 1);
Expand All @@ -480,7 +474,7 @@ function updateDevices()
}


function processCommand($device_id, $command)
function processCommand($device_id, $command, $force = 0)
{
if (!isset($command['INDEX'])) {
$command['INDEX'] = 0;
Expand All @@ -505,11 +499,11 @@ function processCommand($device_id, $command)
}
SQLUpdate('megadproperties', $prop);
if ($prop['LINKED_OBJECT'] && $prop['LINKED_PROPERTY']) {
if ($old_value != $prop['CURRENT_VALUE_STRING'] || $prop['CURRENT_VALUE_STRING'] != gg($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_PROPERTY'])) {
if ($force || $old_value != $prop['CURRENT_VALUE_STRING'] || $prop['CURRENT_VALUE_STRING'] != gg($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_PROPERTY'])) {
setGlobal($prop['LINKED_OBJECT'] . '.' . $prop['LINKED_PROPERTY'], $prop['CURRENT_VALUE_STRING'], array($this->name => '0'));
}
}
if ($prop['LINKED_OBJECT'] && $prop['LINKED_METHOD'] && ($old_value != $prop['CURRENT_VALUE_STRING'])) {
if ($force || $prop['LINKED_OBJECT'] && $prop['LINKED_METHOD'] && ($old_value != $prop['CURRENT_VALUE_STRING'])) {
$params = array();
$params['TITLE'] = $record['TITLE'];
$params['VALUE'] = $prop['CURRENT_VALUE_STRING'];
Expand Down Expand Up @@ -567,7 +561,7 @@ function setProperty($property_id, $value)
} elseif ($prop['COMMAND'] == 'raw') { // raw command
$this->sendCommand($prop['DEVICE_ID'], $value);
}
$this->readValues($prop['DEVICE_ID']);
$this->readValues($prop['DEVICE_ID'],'',1);
}

function restoreDeviceStatus($device_id)
Expand Down
17 changes: 15 additions & 2 deletions modules/megad/megaddevices_edit.inc.php
Expand Up @@ -187,8 +187,16 @@
$this->redirect("?view_mode=" . $this->view_mode . "&tab=" . $this->tab . "&id=" . $rec['ID']);
}
if ($this->mode == 'update') {
$property['NUM'] = gr('num', 'int');
$property['ADD_NUM'] = gr('add_num', 'int');
if (preg_match('/,/',gr('num'))) {
$tmp=explode(',',gr('num'));
$num1=(int)trim($tmp[0]);
$num2=(int)trim($tmp[1]);
$property['NUM'] = $num1;
$property['ADD_NUM'] = $num2;
} else {
$property['NUM'] = gr('num','int');
$property['ADD_NUM'] = gr('add_num', 'int');
}
$property['SKIP_DEFAULT'] = gr('skip_default', 'int');
$property['COMMENT'] = gr('comment');
$property['COMMAND'] = gr('command');
Expand All @@ -202,6 +210,11 @@
$property['LINKED_METHOD'] = gr('linked_method');
SQLUpdate('megadproperties', $property);
}

if ($property['ADD_NUM']!='') {
SQLExec("UPDATE megadproperties SET COMMAND='i2c' WHERE DEVICE_ID=".$rec['ID']." AND NUM=".$property['ADD_NUM']);
}

}
if (preg_match('/i2c/',$property['COMMAND'])) {
$out['NEED_ADD_PORT']=1;
Expand Down
4 changes: 4 additions & 0 deletions modules/megad/megaddevices_search.inc.php
Expand Up @@ -45,6 +45,10 @@
$total=count($res);
for($i=0;$i<$total;$i++) {
// some action for every record if required
$latest_update=SQLSelectOne("SELECT UPDATED FROM megadproperties WHERE DEVICE_ID=".$res[$i]['ID']." ORDER BY UPDATED DESC LIMIT 1");
if ($latest_update['UPDATED']) {
$res[$i]['UPDATED']=$latest_update['UPDATED'];
}
}
$out['RESULT']=$res;
}
14 changes: 11 additions & 3 deletions modules/megad/readvalues.inc.php
@@ -1,5 +1,6 @@
<?php


$record = SQLSelectOne("SELECT * FROM megaddevices WHERE ID='" . (int)$id . "'");


Expand All @@ -10,6 +11,12 @@
$stateData = getURL($url, 0);
}

if ($_GET['debug']) {
dprint($url."\n".$stateData,false);
}

if ($stateData=='') return;

//echo $stateData;exit;
$commands = array();
$states = explode(';', $stateData);
Expand All @@ -23,6 +30,8 @@
$cmd=(int)$prop['COMMAND'];
*/
$current_prop=SQLSelectOne("SELECT * FROM megadproperties WHERE DEVICE_ID='".$record['ID']."' AND NUM='".$i."' AND COMMAND_INDEX=0");
if (preg_match('/^i2c/',$current_prop['COMMAND'])) continue;

if ($states[$i] == 'ON') {
$cmd = array('NUM' => $i, 'VALUE' => 1, 'COMMAND' => 'output');
$commands[] = $cmd;
Expand Down Expand Up @@ -72,15 +81,15 @@

//internal temp sensor data
$prop = SQLSelectOne("SELECT * FROM megadproperties WHERE DEVICE_ID='" . $record['ID'] . "' AND COMMAND='inttemp'");
if ($prop['ID']) {
if (!$quick && $prop['ID']) {
$stateData = getURL('http://' . $record['IP'] . '/' . $record['PASSWORD'] . '/?tget=1', 0);
if ($stateData != '') {
$commands[] = array('NUM' => 0, 'COMMAND' => 'inttemp', 'VALUE' => $stateData);
}
}

$i2c_properties=SQLSelect("SELECT * FROM megadproperties WHERE DEVICE_ID='".$record['ID']."' AND COMMAND LIKE 'i2c%' ORDER BY NUM");
if ($stateData!='' && $i2c_properties[0]['ID']) {
if (!$quick && $stateData!='' && $i2c_properties[0]['ID']) {
include_once(DIR_MODULES.$this->name.'/libs/i2c_com.class.php');
include_once(DIR_MODULES.$this->name.'/libs/i2c_functions.inc.php');
foreach($i2c_properties as $property) {
Expand All @@ -103,7 +112,6 @@
}

if ($_GET['debug']) {
dprint($url."\n".$stateData,false);
dprint($commands);
}

Expand Down
2 changes: 1 addition & 1 deletion templates/megad/action_admin.html
Expand Up @@ -28,7 +28,7 @@


<p><a href="?">&lt;&lt;&lt; <#LANG_BACK#></a></p>
[#if TITLE!=""#]<h4>[#TITLE#]</h4>[#endif TITLE#]
[#if TITLE!=""#]<h4>[#TITLE#][#if COMMENT!=""#] - [#COMMENT#][#endif#]</h4>[#endif TITLE#]
<ul class="nav nav-tabs">
<li[#if TAB=""#] class="active"[#endif#]>
<a href="?data_source=<#DATA_SOURCE#>&view_mode=<#VIEW_MODE#>&id=<#ID#>&tab="><#LANG_GENERAL#></a>
Expand Down
4 changes: 3 additions & 1 deletion templates/megad/megaddevices_edit_data.html
Expand Up @@ -54,7 +54,9 @@
</td>
<td valign="top">[#LINKED_OBJECT#]</td>
<td valign="top">[#COMMENT#]</td>
<td valign="top"><div class="dynamic_content" id="updated[#ID#]">[#UPDATED#]<!--/dynamic_content--></div></td>
<td valign="top"><div class="dynamic_content" id="updated[#ID#]">[#UPDATED#]
<!--/dynamic_content--></div>
</td>
<td>
<a href="?view_mode=<#VIEW_MODE#>&id=<#ID#>&tab=<#TAB#>&property_id=[#ID#]" class="btn btn-default"><i class="glyphicon glyphicon-edit"></i></a>
<a href="http://<#IP#>/<#PASSWORD#>/?pt=[#NUM#]" class="btn btn-default" target="_blank"><i class="glyphicon glyphicon-wrench"></i></a>
Expand Down
9 changes: 6 additions & 3 deletions templates/megad/megaddevices_edit_property.html
Expand Up @@ -2,7 +2,7 @@
<div class="row">


<div class="col-md-8">
<div class="col-md-6">
<!-- Table 'megaddevices' edit -->
<form action="?" method="post" enctype="multipart/form-data" name="frmEdit" class="form-horizontal">
[#if OK#]
Expand Down Expand Up @@ -164,14 +164,17 @@
</form>
</div>

<div class="col-md-4">
<div class="col-md-6">
<table class="table">
[#begin PROPERTIES#]
<tr>
<td[#if SELECTED#] style="background-color:lightgreen"[#endif#]>
<td[#if SELECTED#] style="background-color:lightgreen"[#endif#] nowrap>
<a href="?view_mode=<#VIEW_MODE#>&id=<#ID#>&tab=<#TAB#>&property_id=[#ID#]">P [#NUM#].[#COMMAND_INDEX#]</a>
</td>
<td[#if SELECTED#] style="background-color:lightgreen"[#endif#]>[#COMMAND#]</td>
<td[#if SELECTED#] style="background-color:lightgreen"[#endif#]>[#CURRENT_VALUE_STRING#]</td>
<td[#if SELECTED#] style="background-color:lightgreen"[#endif#]>[#COMMENT#]</td>
<td[#if SELECTED#] style="background-color:lightgreen"[#endif#]>[#LINKED_OBJECT#]</td>
</tr>
[#end PROPERTIES#]
</table>
Expand Down
2 changes: 2 additions & 0 deletions templates/megad/megaddevices_search_admin.html
Expand Up @@ -61,6 +61,7 @@
IP
</th>
<th><#LANG_NOTES#></th>
<th><#LANG_UPDATED#></th>
<th>&nbsp;</th>
</tr>
</thead>
Expand All @@ -85,6 +86,7 @@
[#IP#]&nbsp;
</td>
<td>[#COMMENT#]</td>
<td>[#UPDATED#]</td>
<td style="vertical-align:middle" nowrap>

[#if "<#ACTION#>"=="admin"#]
Expand Down

0 comments on commit fe0e1b4

Please sign in to comment.