Created
May 7, 2021 09:20
-
-
Save nahakiole/b506eae3313fffc46219d28f7b16f0b5 to your computer and use it in GitHub Desktop.
LIRC .conf file to Raw IR Code Convertor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$lines = file('./config.txt'); | |
$config = array(); | |
foreach ($lines as $l) { | |
$l = trim(preg_replace(["/\s+\#.*/", "/\s+/"], ["", " "], $l)); | |
preg_match("/^(?P<key>\w+)(\s|\t)+(?P<value>.*)$/", $l, $matches); | |
if (isset($matches['key'])) { | |
$config[$matches['key']] = $matches['value']; | |
} | |
} | |
$command = ""; | |
$key = str_split( str_pad(base_convert($config["KEY_POWER"], 16, 2), $config["bits"], "0",STR_PAD_LEFT)); | |
if (isset($config["plead"])) { | |
$command .= $config["plead"] . ","; | |
} | |
$command .= join(",", explode(" ", $config["header"])) . ","; | |
$a = [ | |
"0" => join(",", explode(" ", $config["zero"])), | |
"1" => join(",", explode(" ", $config["one"])), | |
]; | |
if (isset($config["pre_data"])) { | |
$pre_data = str_split(str_pad(base_convert($config["pre_data"], 16, 2), $config["pre_data_bits"], "0",STR_PAD_LEFT)); | |
foreach ($pre_data as $index => $item) { | |
$command .= $a[$item] . ","; | |
} | |
} | |
foreach ($key as $index => $item) { | |
$command .= $a[$item] . ","; | |
} | |
$command .= $config["ptrail"] . ","; | |
$command .= $config["gap"]; | |
$list = explode(",",$command) ; | |
foreach ($list as $index => $item) { | |
if ($index % 2) { | |
echo 'SLEEP '; | |
} | |
else { | |
echo 'SEND '; | |
} | |
echo $item."\n"; | |
} | |
//var_dump($command); | |
$ch = curl_init("http://192.168.1.218:8080/sendIRcmd/" . $command); // such as http://example.com/example.xml | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
$data = curl_exec($ch); | |
curl_close($ch); | |
var_dump($data); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment