Skip to content

Commit

Permalink
Added support of MegaD-16I-XT
Browse files Browse the repository at this point in the history
  • Loading branch information
sergejey committed Jul 5, 2020
1 parent 1e7c5c4 commit ac393a2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
15 changes: 13 additions & 2 deletions modules/megad/megad.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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 ''
Expand Down
11 changes: 9 additions & 2 deletions modules/megad/megaddevices_edit.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
Expand All @@ -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');
Expand All @@ -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);
Expand All @@ -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");
Expand Down
16 changes: 16 additions & 0 deletions modules/megad/readvalues.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
}
}
}
}
}
Expand Down
35 changes: 32 additions & 3 deletions templates/megad/megaddevices_edit_property.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@
<#LANG_PORT#>[#if I2C="1"#] SCL[#endif#]:
(*)
</label>
<div class="col-lg-4"><input type="text" class="form-control" name="num" value="[#PROPERTY_NUM#]" required></div>
<div class="col-lg-4">
[#if PROPERTY_COMMAND_INDEX!="0" && PROPERTY_COMMAND_INDEX!=""#]
[#PROPERTY_NUM#].[#PROPERTY_COMMAND_INDEX#]
<input type="hidden" name="num" value="[#PROPERTY_NUM#]">
[#else#]
<input type="text" class="form-control" name="num" value="[#PROPERTY_NUM#]" required>
[#endif#]
</div>
</div>

[#if NEED_ADD_PORT="1"#]
Expand All @@ -33,13 +40,33 @@
</div>
[#endif#]

[#if NEED_ADD_INT="1"#]
<div class="form-group">
<label class="col-lg-3 control-label">
<#LANG_PORT#> INT:
</label>
<div class="col-lg-4"><input type="text" class="form-control" name="add_int" value="[#PROPERTY_ADD_INT#]"></div>
</div>
[#endif#]

<div class="form-group">
<label class="col-lg-3 control-label">
<#LANG_NOTES#>:
</label>
<div class="col-lg-4"><input type="text" class="form-control" name="comment" value="[#PROPERTY_COMMENT#]"></div>
</div>

[#if PROPERTY_COMMAND_INDEX!="0" && PROPERTY_COMMAND_INDEX!=""#]
<div class="form-group">
<label class="col-lg-3 control-label">
<#LANG_TYPE#>:
(*)
</label>
<div class="col-lg-4">[#PROPERTY_COMMAND#]</div>
<input type="hidden" name="command" value="[#PROPERTY_COMMAND#]">
</div>
[#else PROPERTY_COMMAND_INDEX#]

[#if NEW_PROPERTY!="1"#]
<div class="form-group">
<label class="col-lg-3 control-label">
Expand Down Expand Up @@ -82,8 +109,9 @@
<option value="humidity"[#if PROPERTY_COMMAND="humidity"#] selected[#endif#]>Humidity</option>
<option value="wiegand"[#if PROPERTY_COMMAND="wiegand"#] selected[#endif#]>Wiegand</option>
<option value="ibutton"[#if PROPERTY_COMMAND="ibutton"#] selected[#endif#]>IButton</option>
<option value="i2c"[#if PROPERTY_COMMAND="i2c"#] selected[#endif#]>I2C</option>
<option value="i2c_htu21d"[#if PROPERTY_COMMAND="i2c_htu21d"#] selected[#endif#]>I2C htu21d</option>
<option value="i2c"[#if PROPERTY_COMMAND="i2c"#] selected[#endif#]>I2C (SCL)</option>
<option value="i2c_htu21d"[#if PROPERTY_COMMAND="i2c_htu21d"#] selected[#endif#]>I2C htu21d (SCL)</option>
<option value="i2c_16i_xt"[#if PROPERTY_COMMAND="i2c_16i_xt"#] selected[#endif#]>I2C MegaD-16I-XT (SCL)</option>
<option value="i2c_bmp180"[#if PROPERTY_COMMAND="i2c_bmp180"#] selected[#endif#]>I2C bmp180 (coming soon)</option>
<option value="i2c_tsl2591"[#if PROPERTY_COMMAND="i2c_tsl2591"#] selected[#endif#]>I2C tsl2591 (coming soon)</option>
<option value="i2c_ssd1306"[#if PROPERTY_COMMAND="i2c_ssd1306"#] selected[#endif#]>I2C ssd1306 (coming soon)</option>
Expand All @@ -93,6 +121,7 @@
</select>
</div>
</div>
[#endif PROPERTY_COMMAND_INDEX#]
<div class="form-group">
<label class="col-lg-3 control-label">
<#LANG_VALUE#>:
Expand Down

0 comments on commit ac393a2

Please sign in to comment.