IP-Symcon Module Library  v1.0
IPSEDIP.class.php
gehe zur Dokumentation dieser Datei
00001 <?
00033    include_once "IPSLogger.ips.php";
00034    include_once "IPSEDIP_Constants.ips.php";
00035    include_once "IPSEDIP_Configuration.ips.php";
00036 
00037    // Manuelles Testen eines Displays
00038    if ($IPS_SENDER=='Execute') {
00039       $edip = new edip43(24234);
00040       $edip->RefreshDisplay();
00041       $edip = new edip43(37774);
00042       $edip->RefreshDisplay();
00043    }
00044 
00053    abstract class EDIP{
00054       private $sendDelay=5;
00055 
00056       protected $instanceId=0;
00057       protected $rootId=0;
00058       protected $currentId=0;
00059       private   $registerId=0;
00060 
00061       protected $objectIdsId=0;
00062       protected $objectValuesId=0;
00063       protected $objectCmdsId=0;
00064       protected $objectEditId=0;
00065 
00066       protected $messageArray=array();
00067       protected $objectList=array();//Types,Names,...
00068 
00076       public function __construct($instanceId){
00077          $this->instanceId     = $instanceId;
00078          $this->rootId         = GetValue(IPS_GetObjectIDbyIdent(EDIP_VAR_ROOT, $instanceId));
00079          $this->currentId      = GetValue(IPS_GetObjectIDbyIdent(EDIP_VAR_CURRENT, $instanceId));
00080          $this->registerId     = GetValue(IPS_GetObjectIDbyIdent(EDIP_VAR_REGISTER, $instanceId));
00081          $this->objectIdsId    = IPS_GetObjectIDbyIdent(EDIP_VAR_OBJECTIDS, $instanceId);
00082          $this->objectValuesId = IPS_GetObjectIDbyIdent(EDIP_VAR_OBJECTVALUES, $instanceId);
00083          $this->objectCmdsId   = IPS_GetObjectIDbyIdent(EDIP_VAR_OBJECTCMDS, $instanceId);
00084          $this->objectEditId   = IPS_GetObjectIDbyIdent(EDIP_VAR_OBJECTEDIT, $instanceId);
00085       }
00086 
00087       abstract protected function AddMessageHeader();
00088       abstract protected function AddMessageCategories();
00089       abstract protected function AddMessageVariables();
00090       abstract protected function AddMessageValueEdit();
00091 
00092       private function GenerateEvents() {
00093          $objectIds = explode(',',GetValue($this->objectIdsId));
00094          $edipName  = IPS_GetName($this->instanceId);
00095          foreach ($objectIds as $objectId) {
00096             $objectId   = (int)$objectId;
00097             $objectData = IPS_GetObject($objectId);
00098             if ($objectData['ObjectType']==2) {
00099                $eventName = $edipName.'_'.IPS_GetName($objectId);
00100                $eventId   = @IPS_GetEventIdByName($eventName ,EDIP_ID_EVENTSCRIPT);
00101                if ($eventId===false) {
00102                   $eventId = IPS_CreateEvent(0);
00103                   IPSLogger_Dbg(__file__, "Create Event=$eventName, ID=$eventId, Parent=".EDIP_ID_EVENTSCRIPT);
00104                   IPS_SetName($eventId, $eventName);
00105                   IPS_SetEventTrigger($eventId, 1, $objectId);
00106                   IPS_SetParent($eventId, EDIP_ID_EVENTSCRIPT);
00107                   IPS_SetEventActive($eventId, true);
00108                }
00109             }
00110          }
00111       }
00112 
00113       private function DropEvents() {
00114          $objectIds = explode(',',GetValue($this->objectIdsId));
00115          $edipName  = IPS_GetName($this->instanceId);
00116          foreach ($objectIds as $objectId) {
00117             $objectId = (int)$objectId;
00118             $eventName = $edipName.'_'.IPS_GetName($objectId);
00119             $eventId   = @IPS_GetEventIdByName($eventName ,EDIP_ID_EVENTSCRIPT);
00120             if ($eventId!==false) {
00121                IPSLogger_Dbg(__file__, "Drop Event=$eventName, ID=$eventId");
00122                IPS_DeleteEvent($eventId);
00123             }
00124          }
00125       }
00126 
00127       private function StoreObjectData() {
00128          $objectIds    = array();
00129          $objectValues = array();
00130          $objectCmds   = array();
00131          foreach ($this->objectList as $object) {
00132             if ($object['ObjectType']=='Category') {
00133                $objectIds[]    = $object['Link'];
00134             } else {
00135                $objectIds[]    = $object['Id'];
00136             }
00137             if ($object['DisplayType']=='Text') {
00138                $objectValues[] = "";
00139             } elseif (array_key_exists('Value', $object)) {
00140                $objectValues[] = $object['Value'];
00141             } else {
00142                $objectValues[] = "";
00143             }
00144             $objectCmds[]   = $object['Cmd'];
00145          }
00146          SetValue($this->objectIdsId,    implode(',',$objectIds));
00147          SetValue($this->objectValuesId, implode(',',$objectValues));
00148          SetValue($this->objectCmdsId,   implode(',',$objectCmds));
00149       }
00150       
00151       private function GetObjectDataByCmd($cmd) {
00152          $objectIds    = explode(',',GetValue($this->objectIdsId));
00153          $objectValues = explode(',',GetValue($this->objectValuesId));
00154          $objectCmds   = explode(',',GetValue($this->objectCmdsId));
00155          foreach ($objectCmds as $idx=>$objectCmd) {
00156             if ($objectCmd==$cmd) {
00157                $object['Cmd']   = $cmd;
00158                $object['Id']    = $objectIds[$idx];
00159                $object['Value'] = $objectValues[$idx];
00160                return $object;
00161             }
00162          }
00163          return false;
00164       }
00165       
00166       private function GetDisplayAttributte($id, $attribute, $default) {
00167          $result     = $default;
00168          $object     = IPS_GetObject($id);
00169          $objectInfo = $object['ObjectInfo'];
00170          if (substr($objectInfo,0,2)=='##') {
00171             $attributeList = explode(',',substr($objectInfo,2));
00172             foreach ($attributeList as $keyValue) {
00173                $keyValue = explode('=', $keyValue);
00174                if ($keyValue[0]==$attribute) {
00175                   $result = $keyValue[1];
00176                }
00177             }
00178          }
00179          return $result;
00180       }
00181       
00182       private function AddObjectCategory($link, $id, $name, $position) {
00183          $object = array();
00184          $object['Id']             = $id;
00185          $object['Link']           = $link;
00186          $object['Name']           = $name;
00187          $object['Position']       = $position;
00188          $object['DisplayType']    = 'Category';
00189          $object['ObjectType']     = 'Category';
00190          $this->objectList[] = $object;
00191       }
00192 
00193       private function AddObjectScript($link, $id, $name, $position) {
00194          $object = array();
00195          $object['Id']             = $id;
00196          $object['Link']           = $link;
00197          $object['Name']           = $name;
00198          $object['BlockBegin']     = true;
00199          $object['BlockEnd']       = true;
00200          $object['Position']       = $position;
00201          $object['DisplayType']    = 'Button';
00202          $object['ObjectType']     = 'Script';
00203          $object['ValueFormatted'] = 'Execute';
00204          $object['Width']          = 100;
00205          $object['LineIdx']        = 0;
00206          $color = 150*256*256+150*256+150;
00207          $red    = floor($color/256/256);
00208          $green  = floor(($color-$red*256*256)/256);
00209          $blue   = floor(($color-$red*256*256-$green*256));
00210          $object['Color']  =  $color;
00211          $object['Red']    =  $red;
00212          $object['Green']  =  $green;
00213          $object['Blue']   =  $blue;
00214          $this->objectList[] = $object;
00215       }
00216       
00217       private function AddObjectVariableValues($object, $associations, $valueCurrent, $objectType) {
00218          $lineIdx    = 0;
00219          $widthTotal = 0;
00220          foreach ($associations as $idx=>$association) {
00221             $object['BlockBegin']     = false;
00222             $object['BlockEnd']       = false;
00223             if ($idx==0)                        $object['BlockBegin']     = true;
00224             if ($idx == count($associations)-1) $object['BlockEnd']       = true;
00225             $object['Idx']            = $idx;
00226             $object['Value']          = $association['Value'];
00227             $object['ValueFormatted'] = $object['Prefix'].$association['Name'].$object['Suffix'];
00228             $object['ObjectType']     = $objectType;
00229 
00230             $width = $this->GetDisplayAttributte($object['Link'], 'Width'.$association['Value'], '100');
00231             $object['Width']    = $width;
00232             $object['LineIdx']  = $lineIdx;
00233             $widthTotal = $widthTotal + $width;
00234             if ($widthTotal >= 100) {
00235                $widthTotal = 0;
00236                $lineIdx    = 0;
00237             } else {
00238                $lineIdx = $lineIdx + 1;
00239             }
00240 
00241             if ($object['Value']==$valueCurrent) {
00242                $color = $association['Color'];
00243                if ($color==-1) {
00244                   $color = 150*256*256+150*256+150;
00245                }
00246             } else {
00247                $color = 60*256*256+60*256+60;
00248             }
00249             $red    = floor($color/256/256);
00250             $green  = floor(($color-$red*256*256)/256);
00251             $blue   = floor(($color-$red*256*256-$green*256));
00252             $object['Color']  =  $color;
00253             $object['Red']    =  $red;
00254             $object['Green']  =  $green;
00255             $object['Blue']   =  $blue;
00256 
00257             $this->objectList[] = $object;
00258 
00259          }
00260       }
00261       
00262       private function AddObjectVariable($link, $id, $name, $position) {
00263          $value        = GetValue($id);
00264          $variable     = IPS_GetVariable($id);
00265          $action       = $variable['VariableCustomAction'] ;
00266          $type         = $variable['VariableValue']['ValueType'];
00267          $profile      = $variable['VariableCustomProfile'];
00268          if ($profile=='') return;
00269          $profileData  = IPS_GetVariableProfile($profile);
00270          $associations = $profileData['Associations'];
00271          $color        = -1;
00272 
00273          $object = array();
00274          $object['Id']             = $id;
00275          $object['Link']           = $link;
00276          $object['Name']           = $name;
00277          $object['Position']       = $position;
00278          $object['ValueFormatted'] = GetValueFormatted($id);
00279          $object['ObjectType']     = 'Variable';
00280          $object['DisplayType']    = 'Text';
00281          $object['BlockBegin']     = true;
00282          $object['BlockEnd']       = true;
00283          $object['Width']          = 100;
00284          $object['LineIdx']        = 0;
00285          $object['Suffix']         = $profileData['Suffix'];
00286          $object['Prefix']         = $profileData['Prefix'];
00287          $object['MaxValue']       = $profileData['MaxValue'];
00288          $object['MinValue']       = $profileData['MinValue'];
00289          $object['StepSize']       = $profileData['StepSize'];
00290 
00291          switch($type) {
00292             case 0: // Boolean
00293                $object['DisplayType'] = 'Switch';
00294                $value = $value ? 1 : 0;
00295                $object['Value'] = $value;
00296                if (array_key_exists($value, $associations)) $color = $associations[$value]['Color'];
00297                break;
00298             case 1: // Integer
00299                $object['Value']          = $value;
00300                if ($object['Suffix'] == '%') {
00301                   $object['DisplayType']    =  'BarGraph';
00302                } else if (count($profileData['Associations']) > 0) {
00303                   $object['DisplayType'] = $this->GetDisplayAttributte($link, 'DisplayType', 'Switch');
00304                   $object['Value']       = ""; // Call Edit Mode
00305                   if ($object['DisplayType']=='Inline' or $object['DisplayType']=='Block') {
00306                      $this->AddObjectVariableValues($object, $associations, $value, 'Variable');
00307                      return;
00308                   }
00309                } else {
00310                }
00311                if (array_key_exists($value, $associations)) $color = $associations[$value]['Color'];
00312                break;
00313             case 2: // Float
00314                $object['Value']          = floatval($value);
00315                break;
00316             case 3: // String
00317                $object['Value']          = $value;
00318                if ($profile=='~HTMLBox') return; // Text
00319                break;
00320             default: // Unsupported Datatype
00321          }
00322          
00323          $object['DisplayType'] = $this->GetDisplayAttributte($link, 'DisplayType', $object['DisplayType']);
00324          if ($action==0 and $object['DisplayType']<>'Text' and $object['DisplayType']<>'BigText') {
00325             $object['DisplayType'] = 'Text';
00326          }
00327 
00328          if ($color==-1) $color = 150*256*256+150*256+150;
00329          $red    = floor($color/256/256);
00330          $green  = floor(($color-$red*256*256)/256);
00331          $blue   = floor(($color-$red*256*256-$green*256));
00332          $object['Color']  =  $color;
00333          $object['Red']    =  $red;
00334          $object['Green']  =  $green;
00335          $object['Blue']   =  $blue;
00336          $this->objectList[] = $object;
00337 
00338          if (GetValue($this->objectEditId)==$id) {
00339             $this->AddObjectVariableValues($object, $associations, $value, 'Edit');
00340          }
00341       }
00342 
00343       private function AddObjects() {
00344          $childrenIds = IPS_GetChildrenIDs($this->currentId);
00345          foreach ($childrenIds as $idx=>$childrenId) {
00346             $object     = IPS_GetObject($childrenId);
00347             $name       = IPS_GetName($childrenId);
00348             $position   = $object['ObjectPosition'];
00349             $linkId     = $childrenId;
00350             if ($object['ObjectType']==6) { // Link
00351                $link = IPS_GetLink($childrenId);
00352                $childrenId = $link['LinkChildID'];
00353                $object     = IPS_GetObject($childrenId);
00354             }
00355             switch($object['ObjectType']) {
00356                case 0: // Category
00357                case 1: // Instance
00358                   echo 'Found Category '.$name."\n";
00359                   $this->AddObjectCategory($linkId, $childrenId, $name, $position);
00360                   break;
00361                case 2: // Variable
00362                   echo 'Found Variable '.$name."\n";
00363                   $this->AddObjectVariable($linkId, $childrenId, $name, $position);
00364                   break;
00365                case 3: // Script
00366                   echo 'Found Script '.$name."\n";
00367                   $this->AddObjectScript($linkId, $childrenId, $name, $position);
00368                   break;
00369                default:
00370                   // Unsupported Object ...
00371             }
00372          }
00373       }
00374 
00375       private function OrderObjects() {
00376          usort($this->objectList, 'IPSEDIP_CompareObjects');
00377          $cmd   = 30;
00378          $graph = 2;
00379          foreach ($this->objectList as $idx=>$object) {
00380             if ($object['DisplayType'] == 'BarGraph') {
00381                $this->objectList[$idx]['Cmd'] = $graph;
00382                $graph++;
00383             } else {
00384                $this->objectList[$idx]['Cmd'] = $cmd;
00385                $cmd++;
00386             }
00387          }
00388       }
00389 
00396       public function RefreshDisplay() {
00397          IPSLogger_Dbg(__file__, 'Refresh EDIP Display '.IPS_GetName($this->instanceId));
00398          $this->AddObjects();
00399          $this->OrderObjects();
00400          $this->StoreObjectData();
00401 
00402          $this->messageArray = array();
00403          $this->AddMessageHeader();
00404          $this->AddMessageCategories();
00405          $this->AddMessageVariables();
00406          $this->AddMessageValueEdit();
00407          $this->sendArray($this->messageArray);
00408       }
00409 
00410 
00411       private function ReceiveCodeSpecial($code) {
00412          IPSLogger_Dbg(__file__, 'Received SpecialCode='.$code.' from EDIP');
00413          switch ($code) {
00414             case 1: // Navigate Back
00415                if (GetValue($this->objectEditId)<>0) {
00416                   SetValue($this->objectEditId,0);
00417                } elseif ($this->currentId <> $this->rootId) {
00418                   $this->currentId = IPS_GetParent($this->currentId);
00419                   SetValue(IPS_GetObjectIDbyIdent(EDIP_VAR_CURRENT, $this->instanceId), $this->currentId);
00420                } else {
00421                }
00422                break;
00423          }
00424       }
00425 
00426       private function ReceiveCodeCategory($object) {
00427          IPSLogger_Dbg(__file__, 'Received CategoryCode='.$object['Cmd'].' for CategoryId='.$object['Id'].' from EDIP');
00428          $this->currentId = (int)$object['Id'];
00429          SetValue(IPS_GetObjectIDbyIdent(EDIP_VAR_CURRENT, $this->instanceId), $this->currentId);
00430       }
00431 
00432       private function ReceiveCodeScript($object) {
00433          IPSLogger_Dbg(__file__, 'Received CategoryCode='.$object['Cmd'].' for ScriptId='.$object['Id'].' from EDIP');
00434          IPS_RunScriptWaitEx((int)$object['Id'], array( 'IPS_SENDER'=>'WebFront', 'IPS_VALUE'=>null, 'IPS_VARIABLE'=>null, 'REMOTE_ADDR'=>null));
00435       }
00436 
00437       private function ReceiveCodeVariable($object) {
00438          $variableId   = (int)$object['Id'];
00439          $variable     = IPS_GetVariable($variableId);
00440          $value        = GetValue($variableId);
00441          $action       = $variable['VariableCustomAction'] ;
00442          $type         = $variable['VariableValue']['ValueType'];
00443          $profile      = $variable['VariableCustomProfile'];
00444          $profileData  = IPS_GetVariableProfile($profile);
00445          $associations = $profileData['Associations'];
00446 
00447          if ($profile=='' or $action==0) return;
00448 
00449          if (GetValue($this->objectEditId)<>0) {
00450             SetValue($this->objectEditId, 0);
00451          }
00452 
00453          switch($type) {
00454             case 0: // Boolean
00455                IPSLogger_Inf(__file__, 'Execute Action '.$action);
00456                IPS_RunScriptWaitEx($action, array( 'SENDER'=>'WebFront', 'VALUE'=>!$value, 'VARIABLE'=>$variableId, 'REMOTE_ADDR'=>'localhost'));
00457                break;
00458             case 1: // Integer
00459                if ($object['Value']=="") {
00460                   SetValue($this->objectEditId, $variableId);
00461                } else {
00462                   IPS_RunScriptWaitEx($action, array( 'SENDER'=>'WebFront', 'VALUE'=>(int)$object['Value'], 'VARIABLE'=>$variableId, 'REMOTE_ADDR'=>'localhost'));
00463                }
00464                break;
00465             case 2: // Float
00466                break;
00467             case 3: // String
00468                break;
00469             default: // Unsupported Datatype
00470          }
00471       }
00472 
00481       public function ReceiveText($string, $useEvents=true) {
00482          if ($useEvents) {
00483             $this->DropEvents();
00484          }
00485          if (substr($string,0,1)==chr(27)) {
00486             switch(substr($string,1,1)) {
00487                case 'A': // Button Code received
00488                   $cmd = ord(substr($string,3));
00489                   $object = $this->GetObjectDataByCmd($cmd);
00490                   if ($object===false) {
00491                      $this->ReceiveCodeSpecial($cmd);
00492                      break;
00493                   }
00494 
00495                   $objectData = IPS_GetObject((int)$object['Id']);
00496                   switch($objectData['ObjectType']) {
00497                      case 0: // Category
00498                      case 1: // Instance
00499                         $this->ReceiveCodeCategory($object);
00500                         break;
00501                      case 2: // Variable
00502                         $this->ReceiveCodeVariable($object);
00503                         break;
00504                      case 3: // Script
00505                         $this->ReceiveCodeScript($object);
00506                         break;
00507                      default:
00508                         // Unsupported Object ...
00509                   }
00510                   break;
00511 
00512                case 'B': // Bargraph Value received
00513                   $graph = ord(substr($string,3,1));
00514                   $value = ord(substr($string,4));
00515                   $object = $this->GetObjectDataByCmd($graph);
00516                   $object['Value'] = (int)$value-10; // Correct Value (BarGraph 0..100 doesnt work, 10..110 works???)
00517                   $this->ReceiveCodeVariable($object);
00518                   break;
00519                default:
00520                   // Unsupported Message Type
00521             }
00522          }
00523 
00524          $this->RefreshDisplay();
00525 
00526          if ($useEvents) {
00527             $this->GenerateEvents();
00528          }
00529       }
00530       
00531       
00532       private function SendArray($messageArray) {
00533          $messagePackage = '';
00534          foreach ($messageArray as $idx=>$message) {
00535             $messagePackage .='#'.$message.chr(13);
00536             if (strlen($messagePackage) >= 100) {
00537                $this->SendText($messagePackage);
00538                $messagePackage = '';
00539             }
00540          }
00541          if (strlen($messagePackage) > 0) {
00542             $this->SendText($messagePackage);
00543          }
00544       }
00545       
00553       public function SendText($string){
00554 
00555          // Translate special Characters
00556          $string = str_replace("Ä", "\x8E", $string);
00557          $string = str_replace("ä", "\x84", $string);
00558          $string = str_replace("Ö", "\x99", $string);
00559          $string = str_replace("ö", "\x94", $string);
00560          $string = str_replace("ü", "\x81", $string);
00561          $string = str_replace("Ü", "\x9A", $string);
00562          $string = str_replace("ß", "\xE1", $string);
00563          //$string = str_replace(",", "\xFB", $string);
00564          $string = str_replace("°", "\xF8", $string);
00565 
00566          // Build Message
00567          $string = chr(17).chr(strlen($string)).$string; //Build Message <DC1><Len><DataBytes> 
00568          $checkSum = 0; // Calc Checksum
00569          for($i = 0; $i < strlen($string); $i++) {
00570             $checkSum = $checkSum + ord(substr($string, $i, 1));
00571          }
00572          $string .= chr($checkSum % 256);
00573 
00574          //IPSLogger_Com(__file__,'Send Msg to EDIP: '.$string);
00575          RegVar_SendText($this->registerId, $string);
00576          ips_sleep($this->sendDelay);
00577       }
00578    }
00579 
00587    class EDIP43 extends EDIP {
00588       protected function AddMessageHeader() {
00589          // Common Settings
00590          $this->messageArray[] = 'TA';     // Terminal aus
00591          $this->messageArray[] = 'AL,0,1'; // Touch löschen
00592          $this->messageArray[] = 'DL';     // Display leeren
00593          $this->messageArray[] = 'AS,0';   // Summer aus
00594          $this->messageArray[] = 'YH,30';  // Helligkeit auf 30
00595          // Top Line
00596          $this->messageArray[] = "FP,19,130,130,130"; // Define Color
00597          $this->messageArray[] = "FE,8,1,19,8,1,7"; // Button Color
00598          if ($this->rootId <> $this->currentId) $this->messageArray[] = 'AT,1,1,75,25,1,0,C<<';   // Touch Button
00599          $this->messageArray[] = 'ZF,5'; // Schriftart
00600          $this->messageArray[] = 'ZZ,1,1'; // SchriftZoom
00601          $this->messageArray[] = 'ZC,220,5,'.IPS_GetName($this->currentId); // Current Category
00602          $this->messageArray[] = "FG,8,1,1"; // Line Color
00603          $this->messageArray[] = 'GR,1,30,480,30'; // Line
00604          $this->messageArray[] = 'GR,160,30,160,272'; // Line
00605       }
00606 
00607       protected function AddMessageCategories() {
00608          $categoryList = array();
00609          foreach ($this->objectList as $idx=>$object) {
00610             if ($object['ObjectType']=='Category') {
00611                $categoryList[] = $object;
00612             }
00613          }
00614          $this->GetObjectDisplayAttributes(count($categoryList), $buttonHeight, $buttonSpace, 30, 10);
00615          $this->messageArray[] = "FP,18,150,150,150"; // Define Color
00616          $this->messageArray[] = "FE,8,1,18,8,1,7"; // Button Color
00617          $yPos1 = 40;
00618          foreach ($categoryList as $idx=>$category) {
00619             $yPos2 = $yPos1+$buttonHeight;
00620             $cmd   = $category['Cmd'];
00621             $name  = $category['Name'];
00622             $this->messageArray[] = "AT(1,$yPos1,150,$yPos2,$cmd,0,C$name"; // Touch Button
00623             $yPos1 = $yPos1 + $buttonHeight + $buttonSpace;
00624          }
00625       }
00626 
00627       protected function AddMessageVariables() {
00628          $varList = array();
00629          $count     = 0;
00630          foreach ($this->objectList as $idx=>$object) {
00631             if ($object['ObjectType']=='Variable' or $object['ObjectType']=='Script') {
00632                $varList[] = $object;
00633                if ($object['LineIdx']==0) $count++;
00634             }
00635          }
00636 
00637          $this->GetObjectDisplayAttributes($count, $height, $space, 40, 0);
00638          $yPosR1  = 40;    // Start of Variable Section
00639          foreach ($varList as $idx=>$variable) {
00640             $cmd         = $variable['Cmd'];
00641             $name        = $variable['Name'];
00642             $displayType = $variable['DisplayType'];
00643             $yPosR2      = $yPosR1+$height;
00644             $this->GetObjectButtonAttributes($count, $displayType, $yPosR1, $yPosR2, $yPosG1, $yPosG2, $yPosB1, $yPosB2, $yPosT);
00645 
00646             if ($variable['BlockBegin']) {
00647                $yPosBR1              = $yPosR1;
00648                $this->messageArray[] = 'ZF,5'; // Schriftart
00649                $this->messageArray[] = 'ZZ,1,1'; // SchriftZoom
00650                $this->messageArray[] = "FR,16,1,1"; // Frame Color
00651                $this->messageArray[] = "ZL,180,$yPosT,$name"; // Text
00652             }
00653 
00654             switch($displayType) {
00655                case 'Text':
00656                case 'BigText':
00657                   $valueFormatted  = $variable['ValueFormatted'];
00658                   if ($displayType=='BigText') {
00659                      $this->messageArray[] = 'ZF,5'; // Schriftart
00660                      $this->messageArray[] = 'ZZ,2,2'; // SchriftZoom
00661                      $yPosT=$yPosT-5;
00662                   }
00663                   $this->messageArray[] = "ZR,470,$yPosT,$valueFormatted"; // Text
00664                   break;
00665 
00666                case 'Switch':
00667                case 'Button':
00668                case 'Inline':
00669                case 'Block':
00670                   $valueFormatted  = $variable['ValueFormatted'];
00671                   $red             = $variable['Red'];
00672                   $green           = $variable['Green'];
00673                   $blue            = $variable['Blue'];
00674                   $this->messageArray[] = "FP,17,$red,$green,$blue"; // Define Color
00675                   $this->messageArray[] = "FE,8,1,17,8,1,7"; // Button Color
00676 
00677                   if ($displayType=='Inline') {
00678                      //echo "Width=".$variable['Width'].", LineIdx=".$variable['LineIdx']."\n";
00679                      if ($variable['Width']==50 and ($variable['LineIdx']==0)) {
00680                        $this->messageArray[] = "AT,320,$yPosB1,392,$yPosB2,$cmd,0,C$valueFormatted"; // Button Text
00681                      } elseif ($variable['Width']==50 and ($variable['LineIdx']==1)) {
00682                        $this->messageArray[] = "AT,398,$yPosB1,470,$yPosB2,$cmd,0,C$valueFormatted"; // Button Text
00683                      } else {
00684                        $this->messageArray[] = "AT,320,$yPosB1,470,$yPosB2,$cmd,0,C$valueFormatted"; // Button Text
00685                      }
00686 
00687                   } elseif ($displayType=='Block') {
00688                      if ($variable['Width']==50 and ($variable['LineIdx']==0)) {
00689                         $valueFormatted = substr($valueFormatted,0,17);
00690                         $this->messageArray[] = "AT,180,$yPosB1,320,$yPosB2,$cmd,0,C$valueFormatted"; // Button Text
00691                      } elseif ($variable['Width']==50 and ($variable['LineIdx']==1)) {
00692                         $valueFormatted = substr($valueFormatted,0,17);
00693                         $this->messageArray[] = "AT,330,$yPosB1,470,$yPosB2,$cmd,0,C$valueFormatted"; // Button Text
00694                      } else {
00695                         $valueFormatted = substr($valueFormatted,0,35);
00696                         $this->messageArray[] = "AT,180,$yPosB1,470,$yPosB2,$cmd,0,C$valueFormatted"; // Button Text
00697                      }
00698                      
00699                   } else {
00700                      $this->messageArray[] = "AT,320,$yPosB1,470,$yPosB2,$cmd,0,C$valueFormatted"; // Button Text
00701                   }
00702                   break;
00703                case 'Script':
00704                   $this->messageArray[] = "FE,8,1,18,8,1,7"; // Button Color
00705                   $this->messageArray[] = "AT,320,$yPosB1,470,$yPosB2,$cmd,0,C>> "; // Button Text
00706                   break;
00707                case 'BarGraph':
00708                   $maxValue        = $variable['MaxValue']+10; // Correct +10 (0..100 doesnt work, 10..110 works ???)
00709                   $minValue        = $variable['MinValue']+10;
00710                   $stepSize        = $variable['StepSize'];
00711                   $value           = $variable['Value'];
00712                   $this->messageArray[] = "BR,$cmd,280,$yPosG1,470,$yPosG2,$minValue,$maxValue,$stepSize";
00713                   $this->messageArray[] = "BA,$cmd,".($value+10);
00714                   $this->messageArray[] = "AB,$cmd";
00715                   break;
00716                default: // Unsupported Datatype
00717             }
00718             if ($variable['BlockEnd']) {
00719                $yPosBR2              = $yPosR2;
00720                $this->messageArray[] = "FG,16,1,1"; // Frame Color
00721                $this->messageArray[] = "GR,170,$yPosBR1,480,$yPosBR1"; // Line
00722                $this->messageArray[] = "GR,170,$yPosBR2,480,$yPosBR2"; // Line
00723                $this->messageArray[] = "GR,170,$yPosBR1,170,$yPosBR2"; // Line
00724                $this->messageArray[] = "GR,480,$yPosBR1,480,$yPosBR2"; // Line
00725             }
00726             // NewLine or EndOfList
00727             if ($idx==count($varList)-1 or ($idx<count($varList)-1) and $varList[$idx+1]['LineIdx']==0) {
00728                $yPosR1  = $yPosR1 + $height + $space; // Calc Next Position
00729             }
00730          }
00731       }
00732 
00733       protected function AddMessageValueEdit() {
00734          if (GetValue($this->objectEditId)==0) return;
00735 
00736          $editList = array();
00737          foreach ($this->objectList as $idx=>$object) {
00738             if ($object['ObjectType']=='Edit') {
00739                $editList[] = $object;
00740             }
00741          }
00742          $yPos1 = max(80 - count($editList)*4, 45);
00743          $value = GetValue(GetValue($this->objectEditId));
00744          $this->messageArray[] = "FP,19,130,130,130"; // Define Color
00745          $this->messageArray[] = "FP,20,130,130,180"; // Define Color
00746          $this->GetObjectDisplayAttributes(count($editList), $height, $space, 35, 0);
00747          foreach ($editList as $idx=>$object) {
00748             $valueFormatted = $object['ValueFormatted'];
00749             $cmd            = $object['Cmd'];
00750             $yPos2          = $yPos1 + $height;
00751             if ($object['Value']==$value) {
00752                $this->messageArray[] = "FE,8,1,20,8,1,7"; // Button Color
00753                $this->messageArray[] = "AK,250,$yPos1,465,$yPos2,$cmd,0,L * $valueFormatted"; // Button Text
00754             } else {
00755                $this->messageArray[] = "FE,8,1,19,8,1,7"; // Button Color
00756                $this->messageArray[] = "AK,250,$yPos1,465,$yPos2,$cmd,0,L   $valueFormatted"; // Button Text
00757             }
00758             $yPos1 = $yPos1 + $height + $space;
00759          }
00760       }
00761 
00762       private function GetObjectDisplayAttributes($objectCount, &$height, &$space, $defaultHeight=30, $defaultSpace=10, $startPos=40, $endPos=272) {
00763          if ($objectCount==0) return;
00764          $height = $defaultHeight;
00765          $space  = $defaultSpace;
00766 
00767          $totalHeight  = $endPos - $startPos;
00768          $segment      = floor($totalHeight / $objectCount);
00769          //echo "Total=$totalHeight, Segment=$segment, Count=$objectCount\n";
00770          $segmentSpace = 0;
00771          if ($space > 0) {
00772             $segmentSpace = $space + 9 - $objectCount*2;
00773             if ($space < 0) $space = 3;
00774          }
00775          $segmentHeight = $segment - $segmentSpace;
00776          //echo "$segmentHeight < $height\n";
00777          if ($segmentHeight < $height) {
00778             $height = $segmentHeight;
00779             $space  = $segmentSpace;
00780          }
00781          
00782       }
00783 
00784       private function GetObjectButtonAttributes($count, $displayType, $yPosR1, $yPosR2, &$yPosG1, &$yPosG2, &$yPosB1, &$yPosB2, &$yPosT) {
00785          $yPosT  = $yPosR1 + round(($yPosR2-$yPosR1)/2) - 6;
00786          $yPosG1 = $yPosR1+14-$count;
00787          $yPosG2 = $yPosR2-14+$count;
00788          $yPosB1 = $yPosR1+7-max(round($count/3),2);
00789          $yPosB2 = $yPosR2-7+max(round($count/3),2);
00790       }
00791 
00792    } // class edip43
00793 
00801    class EDIP240 extends EDIP {
00802       protected function AddMessageHeader() {
00803          // to be implented...
00804       }
00805 
00806       protected function AddMessageCategories() {
00807          // to be implented...
00808       }
00809 
00810       protected function AddMessageVariables() {
00811          // to be implented...
00812       }
00813 
00814       protected function AddMessageValueEdit() {
00815          // to be implented...
00816       }
00817    } // class edip240
00818 
00819 
00820    function IPSEDIP_CompareObjects($object1, $object2) {
00821       if ($object1['Position'] == $object2['Position']) {
00822          if (array_key_exists('Idx',$object1) and array_key_exists('Idx',$object2)) {
00823             if ($object1['Idx'] == $object2['Idx']) {
00824                return 0;
00825             } else {
00826                return ($object1['Idx'] < $object2['Idx']) ? -1 : 1;
00827             }
00828          }
00829          return 0;
00830       } else {
00831          return ($object1['Position'] < $object2['Position']) ? -1 : 1;
00832       }
00833    }
00834 
00836 ?>