Subversion Repositories HomeAutomation

Rev

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

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