From ac393a2825dec18f1ec6fcbd3be3519a8f6d93c3 Mon Sep 17 00:00:00 2001 From: SergeJey Date: Sun, 5 Jul 2020 23:37:46 +0300 Subject: [PATCH] Added support of MegaD-16I-XT --- modules/megad/megad.class.php | 15 ++++++-- modules/megad/megaddevices_edit.inc.php | 11 ++++-- modules/megad/readvalues.inc.php | 16 +++++++++ .../megad/megaddevices_edit_property.html | 35 +++++++++++++++++-- 4 files changed, 70 insertions(+), 7 deletions(-) diff --git a/modules/megad/megad.class.php b/modules/megad/megad.class.php index 25a3386..a7d2941 100644 --- a/modules/megad/megad.class.php +++ b/modules/megad/megad.class.php @@ -505,15 +505,25 @@ function processRequest() return; } + $commands = array(); //input data changed - if (isset($pt)) { + if (isset($pt) && preg_match('/ext(\d+)=(\d+)/',$_SERVER['REQUEST_URI'],$m)) { + // extender port input + $ext_prop = SQLSelectOne("SELECT * FROM megadproperties WHERE DEVICE_ID=" . $rec['ID'] . " AND ADD_INT='" . (int)$pt . "'"); + if ($ext_prop['ID']) { + $idx = (int)$m[1]; + $value = $m[2]; + $cmd = array('NUM' => $ext_prop['NUM'], 'INDEX' => $idx + 1, 'VALUE' => $value, 'COMMAND' => 'input'); + $commands[] = $cmd; + } + $ecmd = 'd'; + } elseif (isset($pt)) { $prop = SQLSelectOne("SELECT * FROM megadproperties WHERE DEVICE_ID=" . $rec['ID'] . " AND NUM='" . DBSafe($pt) . "' AND COMMAND='input'"); if (!$prop['ID']) { $prop = SQLSelectOne("SELECT * FROM megadproperties WHERE DEVICE_ID=" . $rec['ID'] . " AND NUM='" . DBSafe($pt) . "' AND COMMAND!='counter'"); } if ($prop['ID']) { - if ($prop['ECMD'] && !($prop['SKIP_DEFAULT'])) { if ($rec['DEFAULT_BEHAVIOR']==0) { $ecmd = $prop['ECMD']; @@ -987,6 +997,7 @@ function dbInstall($data) megadproperties: COMMAND_INDEX int(3) NOT NULL DEFAULT '0' megadproperties: NUM int(3) NOT NULL DEFAULT '0' megadproperties: ADD_NUM int(3) NOT NULL DEFAULT '0' + megadproperties: ADD_INT int(3) NOT NULL DEFAULT '0' megadproperties: CURRENT_VALUE int(10) NOT NULL DEFAULT '0' megadproperties: CURRENT_VALUE_STRING varchar(255) NOT NULL DEFAULT '' megadproperties: CURRENT_VALUE_STRING2 varchar(255) NOT NULL DEFAULT '' diff --git a/modules/megad/megaddevices_edit.inc.php b/modules/megad/megaddevices_edit.inc.php index b96aab4..e9f9c93 100644 --- a/modules/megad/megaddevices_edit.inc.php +++ b/modules/megad/megaddevices_edit.inc.php @@ -207,6 +207,9 @@ if ($property_id) { $property = SQLSelectOne("SELECT * FROM megadproperties WHERE ID=" . (int)$property_id); if ($this->mode == 'delete') { + if ($property['INDEX']==0) { + SQLExec("DELETE FROM megadproperties WHERE NUM=".$property['NUM']); + } SQLExec("DELETE FROM megadproperties WHERE ID=".$property['ID']); $this->redirect("?view_mode=" . $this->view_mode . "&tab=" . $this->tab . "&id=" . $rec['ID']); } @@ -221,6 +224,7 @@ $property['NUM'] = gr('num','int'); $property['ADD_NUM'] = gr('add_num', 'int'); } + $property['ADD_INT'] = gr('add_int', 'int'); $property['REVERSE'] = gr('reverse','int'); $property['SKIP_DEFAULT'] = gr('skip_default', 'int'); $property['COMMENT'] = gr('comment'); @@ -245,6 +249,9 @@ $out['NEED_ADD_PORT']=1; $out['I2C']=1; } + if ($property['COMMAND']=='i2c_16i_xt') { + $out['NEED_ADD_INT']=1; + } // if ($property['LINKED_OBJECT']) { addLinkedProperty($property['LINKED_OBJECT'], $property['LINKED_PROPERTY'], $this->name); @@ -257,8 +264,8 @@ $out['NEW_PROPERTY']=1; } $out['PROPERTY_ID']=$property_id; - if ($this->mode == 'update') { - //$this->readValues($rec['ID']); + if ($this->mode == 'update' && $out['I2C'] && $property['ADD_NUM']) { + $this->readValues($rec['ID']); } } $properties = SQLSelect("SELECT * FROM megadproperties WHERE DEVICE_ID='" . $rec['ID'] . "' ORDER BY NUM, COMMAND_INDEX, COMMAND"); diff --git a/modules/megad/readvalues.inc.php b/modules/megad/readvalues.inc.php index fbd29c7..1f689ca 100644 --- a/modules/megad/readvalues.inc.php +++ b/modules/megad/readvalues.inc.php @@ -113,6 +113,7 @@ foreach ($i2c_properties as $property) { $scl = $property['NUM']; $sda = $property['ADD_NUM']; + if (!$scl || !$sda) continue; $i2c_com = new i2c_com('http://' . $record['IP'] . '/' . $record['PASSWORD'] . '/?', $scl, $sda, $record['I2C_VERSION']); if ($property['COMMAND'] == 'i2c_htu21d') { include_once(DIR_MODULES . $this->name . '/libs/i2c_htu21d.inc.php'); @@ -125,6 +126,21 @@ $commands[] = array('NUM' => $property['NUM'], 'COMMAND' => 'humidity', 'INDEX' => 1, 'VALUE' => $hum_compensated); } } + } elseif ($property['COMMAND'] == 'i2c_16i_xt') { + $url = 'http://' . $record['IP'] . '/' . $record['PASSWORD'] . '/?pt='.$sda.'&cmd=get'; + $data = getURL($url); + $ar = explode(';',$data); + $totalc = count($ar); + if ($totalc==16) { + for($ic=0;$ic<$totalc;$ic++) { + if ($ar[$ic]=='ON') { + $v=1; + } else { + $v=0; + } + $commands[] = array('NUM' => $property['NUM'], 'COMMAND' => 'input', 'INDEX' => ($ic+1), 'VALUE' => $v); + } + } } } } diff --git a/templates/megad/megaddevices_edit_property.html b/templates/megad/megaddevices_edit_property.html index b6bef0b..704868f 100644 --- a/templates/megad/megaddevices_edit_property.html +++ b/templates/megad/megaddevices_edit_property.html @@ -21,7 +21,14 @@ <#LANG_PORT#>[#if I2C="1"#] SCL[#endif#]: (*) -
+
+ [#if PROPERTY_COMMAND_INDEX!="0" && PROPERTY_COMMAND_INDEX!=""#] + [#PROPERTY_NUM#].[#PROPERTY_COMMAND_INDEX#] + + [#else#] + + [#endif#] +
[#if NEED_ADD_PORT="1"#] @@ -33,6 +40,15 @@ [#endif#] + [#if NEED_ADD_INT="1"#] +
+ +
+
+ [#endif#] +
+ [#if PROPERTY_COMMAND_INDEX!="0" && PROPERTY_COMMAND_INDEX!=""#] +
+ +
[#PROPERTY_COMMAND#]
+ +
+ [#else PROPERTY_COMMAND_INDEX#] + [#if NEW_PROPERTY!="1"#]
+ [#endif PROPERTY_COMMAND_INDEX#]