Difference between revisions of "Wallboardphpcode"

From Randomdata wiki
Jump to: navigation, search
(Created page with "This is a php webinterface to programm the Wallboards we have thru a moxa <pre> <?php // *************************************************************** // Author: Kahits ...")
 
m
 
Line 1: Line 1:
This is a php webinterface to programm the [[Wallboards]] we have thru a moxa
+
This is a php webinterface to programm the [[Wallboard]]s we have thru a moxa
 
<pre>
 
<pre>
 
<?php
 
<?php

Latest revision as of 19:30, 24 April 2013

This is a php webinterface to programm the Wallboards we have thru a moxa

<?php
// ***************************************************************
// Author: Kahits (kahits@randomdata.nl) - JfL 20130421
// What..: QUAD piece of code to show given text on the wallboard.
//         Like I said it's QUick And Dirty!
//         More enhancements? Remove CR/LF from strings.
//         Give effect per line.
//         How to set date/ time?
//         Optimize array and code.
//
// ***************************************************************
$DEBUG=0;

$address= "192.168.199.20";
$port= "4001";  //local port


function transValue( $char ) {
  $trantab = array(
    128 => 'a',
    129 => 'b',
// No use for 130 and 131 discovered....strange.
    132 => 'c',
    133 => 'd',
    134 => 'e',
    135 => 'f',
    136 => 'g',
    137 => 'h',
    138 => 'i',
    139 => 'j',
    140 => 'k',
    141 => 'l',
    142 => 'm',
    143 => 'n',
    144 => 'o',
    145 => 'p',
    146 => 'q',
    147 => 'r',
    148 => 's',
    149 => 't',
    150 => 'u',
    151 => 'v',
    152 => 'w',
    153 => 'x',
    154 => 'y',
    155 => 'z',
    
    156 => "JUMP_T",
    157 => "RESET",
    158 => "TIME",
    159 => "DATE",

    160 => ' ',
    161 => '!',
    162 => '"', 
    163 => '#',
    164 => '$',
    165 => '%',
    166 => '&',
    167 => "'",
    168 => '(',
    169 => ')',
    170 => '*',
    171 => '+',
    172 => ',',
    173 => '-',
    174 => '.',
    175 => '/',
  // 176 is seen as null string terminator.
    177 => '1',
    178 => '2',
    179 => '3',
    180 => '4',
    181 => '5',
    182 => '6',
    183 => '7',
    184 => '8',
    185 => '9',
    186 => ':',
    187 => ';',
    188 => '<',
    189 => '=',
    190 => '>',
    191 => '?',
    192 => '@',
    193 => 'A',
    194 => 'B',
    195 => 'C',
    196 => 'D',
    197 => 'E',
    198 => 'F',
    199 => 'G',
    200 => 'H',
    201 => 'I',
    202 => 'J',
    203 => 'K',
    204 => 'L',
    205 => 'M',
    206 => 'N',
    207 => 'O',
    208 => 'P',
    209 => 'Q',
    210 => 'R',
    211 => 'S',
    212 => 'T',
    213 => 'U',
    214 => 'V',
    215 => 'W',
    216 => 'X',
    217 => 'Y',
    218 => 'Z',
    219 => 'é',
    220 => 'î',
    221 => 'ö',
    222 => 'ú',
    223 => '•',
    224 => 'Ä',
    226 => 'ë',
    227 => '®',
// effects    
    228 => "DIM",
    229 => "M_SYNC",
    239 => "WIDE",
    240 => "SHOOT",
    241 => "CLOSE",
    242 => "OPEN",
    243 => "WIPE",
    244 => "FREEZE",
    245 => "SYNC",
    246 => "JUMP",
    247 => "VERT",
    248 => "REV",
    249 => "SCRIPT",
    250 => "NORMAL",
    251 => "FAT",
    252 => "FLASH",
    253 => "PAUSE",
    254 => "END_BL",
    255 => "RED_BL",
    176 => '0',
    256 => "STOP"
  );

    if ($char == '0' )
        return( chr(176) );  // special treatment. '0' is seen as a string/ array terminator :(

    while ($charact = current($trantab)) {
        if ($charact == $char) {
            return( chr(key($trantab)) );
        }
        next($trantab);
    }
    return(chr(170)); // character not found so return an asterisk as placeholder
} 


// ****** Main functionality
$wbtext= $_POST['wbtext'];
if( $wbtext == "" )
    $msg= "empty";
else
    $msg= $wbtext;

$wbeffect= $_POST['wbeffect'];
if( $wbeffect == "" )
    $effect= "";
else
    $effect= $wbeffect;

$tmsg= trans( $msg );

?>
<html><title>Walldisplay editor - Kahits</title><body>

<form action="index.php" method="post">
Text to display<br>
<textarea rows=4 cols=100 name="wbtext"><? echo $msg ?></textarea><br />
Effects:<br>
<input type="radio" name="wdeffect" value="228">DIM<br>
<input type="radio" name="wbeffect" value="229">M_SYNC<br>
<input type="radio" name="wbeffect" value="230">WIDE<br>
<input type="radio" name="wbeffect" value="240">SHOOT<br>
<input type="radio" name="wbeffect" value="241">CLOSE<br>
<input type="radio" name="wbeffect" value="242">OPEN<br>
<input type="radio" name="wbeffect" value="243">WIPE<br>
<input type="radio" name="wbeffect" value="244">FREEZE<br>
<input type="radio" name="wbeffect" value="245">SYNC<br>
<input type="radio" name="wbeffect" value="246">JUMP<br>
<input type="radio" name="wbeffect" value="247">VERT<br>
<input type="radio" name="wbeffect" value="248">REV<br>
<input type="radio" name="wbeffect" value="249">SCRIPT Font<br>
<input type="radio" name="wbeffect" value="250">NORMAL Font<br>
<input type="radio" name="wbeffect" value="251">FAT Font<br>
<input type="radio" name="wbeffect" value="252">FLASH<br>
<input type="radio" name="wbeffect" value="253">PAUSE<br>
<input type="radio" name="wbeffect" value="254">END_BL<br>
<input type="radio" name="wbeffect" value="255">RED_BL<br>

<input type="submit" name="submit" value="submit" />
</form>

</body></html>

<?php
$tmsg= chr(2).chr($effect).$tmsg.chr(126).chr(3);

if( $msg != "empty" ) {
  if(!$DEBUG) {
    if (($socket=socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) and (socket_connect($socket, $address, $port)))
      {
        socket_write($socket, $tmsg);
        socket_close($socket);
      }
    else
      echo "Unable to connect to $address on port $port!\n";
  }
}

function trans( $str_msg ) {
    $len= strlen($str_msg);
    $trans_msg= "";

    for($idx= 0; $idx< $len; $idx++){
        $trans_msg.= transValue($str_msg[$idx]);
    }
    return($trans_msg);
}

?>