Skip to content

Commit

Permalink
Работа с дополнительным IR кодами
Browse files Browse the repository at this point in the history
  • Loading branch information
fandaymon committed Feb 28, 2021
1 parent c1ac4a3 commit 73633d0
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/tuyaFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ function TuyaIR($dev_id, $command) {

if ($gw_info) {
$code = SQLSelectOne("SELECT * FROM tuircommand WHERE DEVICE_ID=" . $dev_info['ID'] . " AND TITLE='" . $command ."';");
$dps='{"1":"send_ir","13":0,"3":"'.$code['EXTS'].'","4":"'. $code['COMPRESSPULSE'] . '","10":300}';
if ($code['CPULSE_ALT_FLAG']) {
$dps='{"1":"study_key","13":3,"3":"","7":"'. $code['CPULSE_ALT'] . '","10":300}';
} else {
$dps='{"1":"send_ir","13":0,"3":"'.$code['EXTS'].'","4":"'. $code['COMPRESSPULSE'] . '","10":300}';
}

if ($gw_info['DEV_IP'] !='' and $gw_info['LOCAL_KEY'] !='') {
$tuya_module->TuyaLocalMsg('SET', $gw_info['DEV_ID'], $gw_info['LOCAL_KEY'], $gw_info['DEV_IP'], $dps);
Expand Down
18 changes: 15 additions & 3 deletions modules/tuya/tuya.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,10 @@ function edit_tudevices(&$out, $id)
function delete_tudevices($id)
{
$rec = SQLSelectOne("SELECT * FROM tudevices WHERE ID='$id'");

if ($rec['IR_FLAG'] ) {
SQLExec("DELETE FROM tuircommand WHERE DEVICE_ID='" . $rec['ID'] . "'");
}

SQLExec("DELETE FROM tucommands WHERE DEVICE_ID='" . $rec['ID'] . "'");
SQLExec("DELETE FROM tudevices WHERE ID='" . $rec['ID'] . "'");
Expand Down Expand Up @@ -568,7 +572,13 @@ function TuyaLocalMsg($command,$dev_id,$local_key,$local_ip,$data='',$cid='',$ve
$postfix_payload = hex2bin(bin2hex($json_payload) . $suffix);
$postfix_payload_hex_len = dechex(strlen($postfix_payload));

$buffer = hex2bin($prefix . $hexByte . '000000' . $postfix_payload_hex_len ) . $postfix_payload;

if (strlen($postfix_payload_hex_len)>2) {
$buffer = hex2bin($prefix . $hexByte . '00000' . $postfix_payload_hex_len ) . $postfix_payload;

} else {
$buffer = hex2bin($prefix . $hexByte . '000000' . $postfix_payload_hex_len ) . $postfix_payload;
}
$buffer=bin2hex($buffer);
$buffer1=strtoupper(substr($buffer,0,-16));

Expand Down Expand Up @@ -1599,8 +1609,10 @@ function dbInstall($data = '')
tuircommand: ID int(10) unsigned NOT NULL auto_increment
tuircommand: DEVICE_ID int(10) unsigned NOT NULL
tuircommand: TITLE varchar(20) NOT NULL DEFAULT ''
tuircommand: COMPRESSPULSE varchar(50) NOT NULL DEFAULT ''
tuircommand: EXTS varchar(100) NOT NULL DEFAULT ''
tuircommand: COMPRESSPULSE varchar(150) NOT NULL DEFAULT ''
tuircommand: EXTS varchar(150) NOT NULL DEFAULT ''
tuircommand: CPULSE_ALT varchar(300) NOT NULL DEFAULT ''
tuircommand: CPULSE_ALT_FLAG boolean DEFAULT 0
EOD;
Expand Down
32 changes: 32 additions & 0 deletions modules/tuya/tuya_search.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,38 @@
$exts = str_replace("\\","",$exts);
$exts = json_decode($exts , true);
$new_code['EXTS'] = $exts['99999'];
$new_code['CPULSE_ALT_FLAG'] = false;

SQLInsert('tuircommand', $new_code);
$new_code['DEV_ID'] = $pult['DEV_ID'];
array_push($codes, $new_code);
unset($new_code['DEV_ID']);
}

}

$action = "tuya.m.infrared.learn.get";

$apiResult = $this->TuyaWebRequest(['action'=>$action,
'gid'=>$gid,
'data'=> ['devId'=> $gw_id,
'gwId'=> $gw_id,
'subDevId'=> $device_id,
'vender'=>'3',
],
'requiresSID'=> 1]);

$result=json_decode($apiResult , true);

$codes = array();

if ($result['result']) {

foreach ($result['result'] as $code) {
$new_code['DEVICE_ID'] = $pult['ID'];
$new_code['TITLE'] = $code['keyName'];
$new_code['CPULSE_ALT'] = base64_encode(hex2bin($code['compressPulse']));
$new_code['CPULSE_ALT_FLAG'] = true;

SQLInsert('tuircommand', $new_code);
$new_code['DEV_ID'] = $pult['DEV_ID'];
Expand Down
18 changes: 16 additions & 2 deletions templates/tuya/tudevices_search_admin_ir.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
margin: 20px;
padding: 20px;
}

.ir_command {
margin: 10px;
text-valign: center;
}

.ir_command_text {
vertical-align: middle;
}
</style>

<div style="margin-top: 10px;"></div>
Expand All @@ -15,8 +24,13 @@
<div class="row">
<div class="col-md-2 ir_device">[#TITLE#]</div>
</div>
<div class="row">
<div class="col-md-6 ">Команда на выполнение: TuyaIR('[#DEV_ID#]', 'Название клавиши');</div>
<div class="row ir_command">
<div class="col-md-5 ir_command_text">Команда на выполнение: TuyaIR('[#DEV_ID#]', 'Название клавиши');</div>
<div class="col=md-2 ir_command_text">
<a href="?id=[#ID#]&view_mode=delete_tudevices" onClick="return confirm('<#LANG_ARE_YOU_SURE#>');" class="btn btn-default" title="Удалить">
<i class="glyphicon glyphicon-remove"></i></a>
</div>

</div>
<div class="row">
<div class="col-md-12">
Expand Down

0 comments on commit 73633d0

Please sign in to comment.