Subversion Repositories HomeAutomation

Rev

Rev 2058 | Blame | Last modification | View Log | SVN | RSS feed

  1. <?php
  2. $aliasesDimmer = array("bardisk_tv", "TakSovrum");
  3. $aliasesOther = array("Power", "PowerBRF", "PID");
  4.  
  5. require 'atom_interface.php';
  6. require 'getSetData.php';
  7.  
  8. $response = array();
  9.  
  10. if (isset($_GET["DimmerStrength"]))
  11. {
  12.   if (intval($_GET["DimmerStrength"]) < 10)
  13.   {
  14.     $_GET["DimmerStrength"] = 0;
  15.   }
  16.   SetDimmerValue($_GET["alias"], $_GET["DimmerStrength"]);
  17.   echo json_encode($response);
  18.   exit(0);
  19. }
  20. else if (isset($_GET["getdata"]))
  21. {
  22.   foreach ($_GET["alias"] as $alias)
  23.   {
  24.     $responseData = GetLastData($alias);
  25.  
  26.     foreach ($responseData as $name => $value)
  27.     {
  28.       $response[$name] = $value;
  29.     }
  30.   }
  31.  
  32.   echo json_encode($response);
  33.   exit(0);
  34. }
  35. ?>
  36.  
  37.  
  38. <!DOCTYPE html>
  39. <html>
  40. <head>
  41.   <meta charset="utf-8">
  42.   <meta name="viewport" content="width=device-width, initial-scale=1">
  43.   <title>Light switch</title>
  44. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />
  45.     <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  46.     <script src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>
  47. <?php
  48. //  <link rel="stylesheet"  href="jquery.mobile-1.0b1.css" />
  49. //  <script src="jquery-1.6.1.min.js"></script>
  50. //  <script src="jquery.mobile-1.0b1.min.js"></script>
  51. ?>
  52.   <script>
  53.  
  54.     $(document).bind("pagecreate", function(event, ui)
  55.     {
  56.       <?php
  57.       foreach ($aliasesDimmer as $alias)
  58.       {
  59.       ?>
  60.         $('#slider<?php  echo $alias?>' ).bind('change', function(event, ui){ makeAjaxChange("<?php  echo $alias?>"); });
  61.       <?php
  62.       }
  63.       ?>
  64.       delayed_start_of_poll();
  65.     });
  66.  
  67.     var current_value = {};
  68.     var next_value = {};
  69.    
  70.     <?php
  71.     foreach ($aliasesDimmer as $alias)
  72.     {
  73.     ?>
  74.       current_value['<?php echo $alias?>'] = 0;
  75.       next_value['<?php echo $alias?>'] = -1;
  76.     <?php
  77.     }
  78.     ?>
  79.     var updating_current = false;
  80.     var timer = null;
  81.  
  82.     function checkCurrentValue()
  83.     {
  84.       updating_current = true;
  85.       jQuery.getJSON("?getdata=1", "<?php echo "alias[]=" . implode("&alias[]=", $aliasesDimmer)?>", function(data)
  86.       {
  87.        
  88.        
  89.         jQuery.each(data, function(alias, value)
  90.         {
  91.           current_value[alias] = value.Level.value;
  92.           $('#slider' + alias).val(value.Level.value).slider("refresh");
  93.         });
  94.        
  95.         updating_current = false;
  96.       });
  97.       jQuery.getJSON("?getdata=1", "<?php echo "alias[]=" . implode("&alias[]=", $aliasesOther)?>", function(data)
  98.       {
  99.       var element = $("#current-information");
  100.  
  101.       element.empty();
  102.  
  103.       var text = "";
  104.  
  105.       jQuery.each(data, function(alias, aliasData)
  106.       {
  107.         text += "<b>" + alias + "</b><br/>";
  108.  
  109.         jQuery.each(aliasData, function(name, value)
  110.         {
  111.           if (typeof value.value == "string")
  112.           {
  113.         text += name + "=" + value.value + "<br/>";
  114.           }
  115.           else
  116.           {
  117.         text += name + "<br/>";
  118.         jQuery.each(value.value, function(name2, value2)
  119.         {
  120.           text += "&nbsp;&nbsp;" + name2 + "=" + value2 + "<br/>";
  121.         });
  122.           }
  123.         });
  124.  
  125.         text += "<br/>";
  126.       });
  127.  
  128.       element.html(text);
  129.  
  130.  
  131.       });
  132.       timer = setTimeout(checkCurrentValue, 5000);
  133.     }
  134.  
  135.     function makeAjaxChange(alias)
  136.     {
  137.       if (updating_current)
  138.       {
  139.         return;
  140.       }
  141.    
  142.       if ($('#slider' + alias).val() == current_value)
  143.       {
  144.         return;
  145.       }
  146.      
  147.       if (next_value[alias] == -1) // Nothing in progress, do a call
  148.       {
  149.         do_call(alias, $('#slider' + alias).val());
  150.       }
  151.       else
  152.       {
  153.         next_value[alias] = $('#slider' + alias).val();
  154.       }
  155.       // console.log($('#slider').val());
  156.     }
  157.    
  158.     function do_call(alias, strength)
  159.     {
  160.       next_value[alias] = strength;
  161.      
  162.       clearInterval(timer);
  163.       timer = null;
  164.      
  165.       jQuery.get("?alias=" + alias + "&DimmerStrength=" + strength, "", function()
  166.       {
  167.         current_value[alias] = strength;
  168.        
  169.         if (next_value[alias] != current_value[alias])
  170.         {
  171.           do_call(alias, next_value[alias]);
  172.         }
  173.         else
  174.         {
  175.           timer = setTimeout(delayed_start_of_poll, 3000);
  176.           next_value[alias] = -1;
  177.         }
  178.       });
  179.     }
  180.    
  181.     function delayed_start_of_poll()
  182.     {
  183.       timer = setTimeout(checkCurrentValue, 1000);
  184.     }
  185.  
  186.   </script>
  187.  
  188. </head>
  189. <body>
  190.   <div data-role="page" id="jqm-home" class="type-home" data-theme="a">
  191.     <div data-role="header" data-position="inline">
  192.         <a href="index.html" data-icon="delete">Cancel</a>
  193.         <h1>Testar</h1>
  194.         <a href="index.html" data-icon="check">Save</a>
  195.     </div>
  196.     <div data-role="content">
  197.       <div data-role="collapsible-set" data-theme="" data-content-theme="">
  198.     <div data-role="collapsible" data-collapsed="true">
  199.       <h3>
  200.         Dimmers
  201.       </h3>
  202.       <?php
  203.       foreach ($aliasesDimmer as $alias)
  204.       {
  205.       ?>
  206.       <div data-role="fieldcontain" id="slider-container">
  207.         <label for="slider<?php echo $alias?>"><?php echo ucfirst($alias)?>:</label>
  208.         <input type="range" name="slider<?php echo $alias?>" id="slider<?php echo $alias?>" value="<?php echo intval($level)?>" min="0" max="255"  />
  209.       </div>
  210.  
  211.       <div style="">
  212.  
  213.       </div>
  214.       <?php
  215.       }
  216.       ?>
  217.     </div>
  218.       </div>
  219.       <div data-role="collapsible-set" data-theme="" data-content-theme="">
  220.     <div data-role="collapsible" data-collapsed="true">
  221.       <h3>
  222.         Power
  223.       </h3>
  224.       <?php
  225.       foreach ($aliasesPower as $alias)
  226.       {
  227.       ?>
  228.       <div data-role="fieldcontain" id="slider-container">
  229.         <label for="slider<?php echo $alias?>"><?php echo ucfirst($alias)?>:</label>
  230.       </div>
  231.  
  232.       <div style="">
  233.  
  234.       </div>
  235.       <?php
  236.       }
  237.       ?>
  238.     </div>
  239.       </div>
  240.       <div data-role="collapsible-set" data-theme="" data-content-theme="">
  241.     <div data-role="collapsible" data-collapsed="true">
  242.       <h3>
  243.         Ute temperatur
  244.       </h3>
  245.       <div id="current-information">None</div>
  246. <?php
  247. //    <div style="width: 997px; height: 519px; position: relative; background-color: #fbfbfb; border: 1px solid #b8b8b8;">
  248. //      <img style=" top: 50%; left: 50%; " src="http://linuxz-home.mine.nu/CANgraph/outside_day.png" />
  249. //    </div>
  250. ?>
  251.     </div>
  252.       </div>
  253.     </div>
  254.   </div>
  255. </body>
  256. </html>
  257.