Subversion Repositories HomeAutomation

Rev

Rev 2056 | Go to most recent revision | Blame | Last modification | View Log | SVN | RSS feed

  1. <?php
  2. $aliasesDimmer = array("bardisk_tv", "TakSovrum");
  3. $aliasesOther = 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 ($_GET["alias"] 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 ($_GET["alias"] 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. <?php
  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.       <?php
  69.       foreach ($aliasesDimmer as $alias)
  70.       {
  71.       ?>
  72.         $('#slider<?php  echo $alias?>' ).bind('change', function(event, ui){ makeAjaxChange("<?php  echo $alias?>"); });
  73.       <?php
  74.       }
  75.       ?>
  76.       delayed_start_of_poll();
  77.     });
  78.  
  79.     var current_value = {};
  80.     var next_value = {};
  81.    
  82.     <?php
  83.     foreach ($aliasesDimmer as $alias)
  84.     {
  85.     ?>
  86.       current_value['<?php echo $alias?>'] = 0;
  87.       next_value['<?php echo $alias?>'] = -1;
  88.     <?php
  89.     }
  90.     ?>
  91.     var updating_current = false;
  92.     var timer = null;
  93.  
  94.     function checkCurrentValue()
  95.     {
  96.       updating_current = true;
  97.       jQuery.getJSON("?getvalue=1", "<? echo "alias[]=" . implode("&alias[]=", $aliasesDimmer)?>", function(data)
  98.       {
  99.        
  100.        
  101.         jQuery.each(data, function(alias, value)
  102.         {
  103.           current_value[alias] = value;
  104.           $('#slider' + alias).val(value).slider("refresh");
  105.         });
  106.        
  107.         updating_current = false;
  108.       });
  109.       jQuery.getJSON("?getdata=1", "<? echo "alias[]=" . implode("&alias[]=", $aliasesOther)?>", function(data)
  110.       {
  111.       var element = $("#current-information");
  112.  
  113.       element.empty();
  114.  
  115.       var text = "";
  116.  
  117.       jQuery.each(data, function(alias, aliasData)
  118.       {
  119.         text += "<b>" + alias + "</b><br/>";
  120.  
  121.         jQuery.each(aliasData, function(name, value)
  122.         {
  123.           text += name + "=" + value.value + "<br/>";
  124.         });
  125.  
  126.         text += "<br/>";
  127.       });
  128.  
  129.       element.html(text);
  130.  
  131.  
  132.       });
  133.       timer = setTimeout(checkCurrentValue, 5000);
  134.     }
  135.  
  136.     function makeAjaxChange(alias)
  137.     {
  138.       if (updating_current)
  139.       {
  140.         return;
  141.       }
  142.    
  143.       if ($('#slider' + alias).val() == current_value)
  144.       {
  145.         return;
  146.       }
  147.      
  148.       if (next_value[alias] == -1) // Nothing in progress, do a call
  149.       {
  150.         do_call(alias, $('#slider' + alias).val());
  151.       }
  152.       else
  153.       {
  154.         next_value[alias] = $('#slider' + alias).val();
  155.       }
  156.       // console.log($('#slider').val());
  157.     }
  158.    
  159.     function do_call(alias, strength)
  160.     {
  161.       next_value[alias] = strength;
  162.      
  163.       clearInterval(timer);
  164.       timer = null;
  165.      
  166.       jQuery.get("?alias=" + alias + "&DimmerStrength=" + strength, "", function()
  167.       {
  168.         current_value[alias] = strength;
  169.        
  170.         if (next_value[alias] != current_value[alias])
  171.         {
  172.           do_call(alias, next_value[alias]);
  173.         }
  174.         else
  175.         {
  176.           timer = setTimeout(delayed_start_of_poll, 3000);
  177.           next_value[alias] = -1;
  178.         }
  179.       });
  180.     }
  181.    
  182.     function delayed_start_of_poll()
  183.     {
  184.       timer = setTimeout(checkCurrentValue, 1000);
  185.     }
  186.  
  187.   </script>
  188.  
  189. </head>
  190. <body>
  191.   <div data-role="page" id="jqm-home" class="type-home" data-theme="a">
  192.     <div data-role="header" data-position="inline">
  193.         <a href="index.html" data-icon="delete">Cancel</a>
  194.         <h1>Testar</h1>
  195.         <a href="index.html" data-icon="check">Save</a>
  196.     </div>
  197.     <div data-role="content">
  198.       <div data-role="collapsible-set" data-theme="" data-content-theme="">
  199.     <div data-role="collapsible" data-collapsed="true">
  200.       <h3>
  201.         Dimmers
  202.       </h3>
  203.       <?php
  204.       foreach ($aliasesDimmer as $alias)
  205.       {
  206.       ?>
  207.       <div data-role="fieldcontain" id="slider-container">
  208.         <label for="slider<?php echo $alias?>"><?php echo ucfirst($alias)?>:</label>
  209.         <input type="range" name="slider<?php echo $alias?>" id="slider<?php echo $alias?>" value="<?php echo intval($level)?>" min="0" max="255"  />
  210.       </div>
  211.  
  212.       <div style="">
  213.  
  214.       </div>
  215.       <?php
  216.       }
  217.       ?>
  218.     </div>
  219.       </div>
  220.       <div data-role="collapsible-set" data-theme="" data-content-theme="">
  221.     <div data-role="collapsible" data-collapsed="true">
  222.       <h3>
  223.         Power
  224.       </h3>
  225.       <?php
  226.       foreach ($aliasesPower as $alias)
  227.       {
  228.       ?>
  229.       <div data-role="fieldcontain" id="slider-container">
  230.         <label for="slider<?php echo $alias?>"><?php echo ucfirst($alias)?>:</label>
  231.       </div>
  232.  
  233.       <div style="">
  234.  
  235.       </div>
  236.       <?php
  237.       }
  238.       ?>
  239.     </div>
  240.       </div>
  241.       <div data-role="collapsible-set" data-theme="" data-content-theme="">
  242.     <div data-role="collapsible" data-collapsed="true">
  243.       <h3>
  244.         Ute temperatur
  245.       </h3>
  246.       <div id="current-information">None</div>
  247. <?php
  248. //    <div style="width: 997px; height: 519px; position: relative; background-color: #fbfbfb; border: 1px solid #b8b8b8;">
  249. //      <img style=" top: 50%; left: 50%; " src="http://linuxz-home.mine.nu/CANgraph/outside_day.png" />
  250. //    </div>
  251. ?>
  252.     </div>
  253.       </div>
  254.     </div>
  255.   </div>
  256. </body>
  257. </html>
  258.