modprobe sunxi_ir
cat /dev/input/event1 | hexdump
(Stop the process can be [Ctrl] + [C]) nano /etc/modules
#!/usr/bin/php5 <?php $dev="/dev/input/event1"; $f=fopen($dev, 'rb'); if($f){ while (!feof($f)){ $b=fread($f,32); // 64 , 32- , 32 - $d=bin2hex($b); // hex $d=substr($d,18,8); // $button=substr($d,0,4); // $key=substr($d,4); //0001 0000 switch($button){ case "0090": echo "POWER ".($key=="0001"?"down":"up")."\n"; } // : /*if($key=="0001"){ if($button=="0090"){ // } }else{ if($button=="0090"){ // } } */ } } ?>
chmod +x /tmp/ts
Run, check: #!/usr/bin/php5 <?php function AccessFile($file,$access){ if(file_exists($file)){ // ! if($f=@fopen($file,$access)){fclose($f);}else{exit("not have access to $file\n");} }else{ return "$file not found (may not have access to the folder)\n"; } } $dev=""; $log=0; if(count($argv)==1){ exit("Use ".dirname( __FILE__ )."/".basename($_SERVER['SCRIPT_FILENAME'])." --device=device [--log=logfile]\n"); }else{ for($i=1;$i<count($argv);$i++){ $cmd=explode("=",$argv[$i]); switch($cmd[0]){ case "--device": $dev=$cmd[1]; echo AccessFile($cmd[1],"rb"); break; case "--log": $log=$cmd[1]; echo AccessFile($cmd[1],"w"); break; } } } if($dev==""){ exit("Use ".dirname( __FILE__ )."/".basename($_SERVER['SCRIPT_FILENAME'])." --device=device [--log=logfile]\n"); } include("/etc/mylirc/buttom_avermedia.php"); if($log){exec("echo `date` > $log");} $f=fopen($dev, 'rb'); if($f){ while (!feof($f)){ $b=fread($f,32); $d=bin2hex($b); $d=substr($d,18,8); $button =substr($d,0,4); $key =substr($d,4); $l=0; for($i=0;$i<count($command);$i++){ if(trim($button)==trim($command[$i][1]) && trim($key)==trim($command[$i][2])){ $l=1; if(trim($command[$i][3])!=""){ // exec($command[$i][3]." > /dev/null 2>/dev/null &"); }else{ // , : if($log){exec("echo ".$command[$i][0]." ".$command[$i][1]." cmd=null >> $log");}// } } } if(!$l){ // , : if($log){exec("echo not buttom $button $key >> $log");}// } } } ?>
<?php $command=array(); //: //, , , $command[]=array("POWER", "00ff","0001","led green 1"); $command[]=array("POWER", "00ff","0000",""); $command[]=array("NUMB 1", "0005","0001","led green 0"); $command[]=array("NUMB 1", "0005","0000",""); // ?>
#!/bin/sh ### BEGIN INIT INFO # Provides: 01_lirc # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: # Short-Description: LIRC on PHP server ### END INIT INFO set -e # /etc/init.d/01_lirc: start and stop the "LIRC on PHP" daemon test -x /usr/sbin/mylirc || exit 0 ( /usr/sbin/mylirc -\? 2>&1 | grep -q mylirc ) 2>/dev/null || exit 0 umask 022 . /lib/lsb/init-functions run_by_init() { ([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel" = S ] } export PATH="${PATH:+$PATH:}/usr/sbin:/sbin" case "$1" in start) log_daemon_msg "Starting LIRC on PHP deamon" "mylirc" || true if start-stop-daemon --quiet --oknodo --exec /usr/sbin/mylirc --background --start -- --device=/dev/input/event1 --log=/var/log/log_lirc; then log_end_msg 0 || true else log_end_msg 1 || true fi ;; stop) log_daemon_msg "Stopping LIRC on PHP deamon" "mylirc" || true if start-stop-daemon --stop --oknodo --name mylirc --retry=KILL/1; then log_end_msg 0 || true else log_end_msg 1 || true fi ;; restart) log_daemon_msg "Restarting LIRC on PHP deamon" "mylirc" || true start-stop-daemon --stop --oknodo --name mylirc --retry=KILL/1; if start-stop-daemon --quiet --oknodo --exec /usr/sbin/mylirc --background --start -- --device=/dev/input/event1 --log=/var/log/log_lirc; then log_end_msg 0 || true else log_end_msg 1 || true fi ;; status) ID=`(lsof | grep mylirc | grep /dev/ 2>&1) 1>/dev/null || echo 0;` if [ "$ID" = "0" ]; then echo "LIRC on PHP deamon \033[37;1;41m shutdown \033[0m"; else echo "LIRC on PHP deamon \033[37;1;42m started \033[0m"; fi tput sgr0 ;; *) log_action_msg "Usage: /etc/init.d/mylirc {start|stop|restart|status}" || true exit 1 esac exit 0
/etc/init.d/01_lirc start
Stop: /etc/init.d/01_lirc stop
Status: /etc/init.d/01_lirc status
cd /etc/init.d/ update-rc.d 01_lirc defaults
cd /etc/init.d/ update-rc.d 01_lirc remove
#!/usr/bin/php5 <?php declare(ticks = 1); pcntl_signal(SIGINT, "signal_handler"); function signal_handler($signal){ global $f,$out; if($signal==SIGINT){ fclose($f); exec('echo ?\> >> '.$out); exit("\n$out create!\n"); } } function AccessFile($file,$access){ if(file_exists($file)){ // ! if($f=@fopen($file,$access)){fclose($f);}else{exit("not have access to $file\n");} }else{ return "$file not found (may not have access to the folder)\n"; } } $dev=""; $out=""; if(count($argv)==1){ exit("Use ".dirname( __FILE__ )."/".basename($_SERVER['SCRIPT_FILENAME'])." --device=device --out=config.php\n"); }else{ for($i=1;$i<count($argv);$i++){ $cmd=explode("=",$argv[$i]); switch($cmd[0]){ case "--device": $dev=$cmd[1]; echo AccessFile($cmd[1],"rb"); break; case "--out": $out=$cmd[1]; echo AccessFile($cmd[1],"w"); break; } } } if(($dev=="")||($out=="")){ exit("Use ".dirname( __FILE__ )."/".basename($_SERVER['SCRIPT_FILENAME'])." --device=device --out=config.php\n"); } echo "press [Ctrl]+[C] to stop and press any button on the remote\n"; $f=fopen($dev, 'rb'); if($f){ exec('echo \<?php > '.$out); exec('echo " \$command=array();" >> '.$out); $i=0; $j=1; while (!feof($f)){ $b=fread($f,32); $b=bin2hex($b); $b=substr($b,18,8); $button =substr($b,0,4); $key =substr($b,4); $i=$i+($j++)%2; // $but='$command[]=array("'.$i.'", "'.$button.'","'.$key.'",""); // #'.$i; exec('echo \' '.$but.'\' >> '.$out); echo $but."\n"; // , , } } ?>
Source: https://habr.com/ru/post/216615/
All Articles