Subversion Repositories HomeAutomation

Rev

Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
2051 linlun 1
<?php
2060 linlun 2
require 'config.php';
1872 runge 3
 
2060 linlun 4
 
2051 linlun 5
require 'atom_interface.php';
6
require 'getSetData.php';
1872 runge 7
 
2051 linlun 8
$response = array();
1872 runge 9
 
2051 linlun 10
if (isset($_GET["DimmerStrength"]))
1872 runge 11
{
2059 linlun 12
  if (intval($_GET["DimmerStrength"]) < 10)
1872 runge 13
  {
2059 linlun 14
    $_GET["DimmerStrength"] = 0;
1872 runge 15
  }
2059 linlun 16
  SetDimmerValue($_GET["alias"], $_GET["DimmerStrength"]);
2051 linlun 17
  echo json_encode($response);
18
  exit(0);
1872 runge 19
}
2051 linlun 20
else if (isset($_GET["getdata"]))
1872 runge 21
{
2057 linlun 22
  foreach ($_GET["alias"] as $alias)
1872 runge 23
  {
2054 linlun 24
    $responseData = GetLastData($alias);
25
 
26
    foreach ($responseData as $name => $value)
27
    {
28
      $response[$name] = $value;
29
    }
1872 runge 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> 
2051 linlun 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>
2056 arune 47
<?php
2051 linlun 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
?>
1872 runge 52
  <script>
53
 
54
    $(document).bind("pagecreate", function(event, ui)
55
    {
2056 arune 56
      <?php
2051 linlun 57
      foreach ($aliasesDimmer as $alias)
1872 runge 58
      {
59
      ?>
2057 linlun 60
        $('#slider<?php  echo $alias?>' ).bind('change', function(event, ui){ makeAjaxChange("<?php  echo $alias?>"); });
2056 arune 61
      <?php
1872 runge 62
      }
63
      ?>
64
      delayed_start_of_poll();
65
    });
66
 
67
    var current_value = {};
68
    var next_value = {};
69
 
2056 arune 70
    <?php
2051 linlun 71
    foreach ($aliasesDimmer as $alias)
1872 runge 72
    {
73
    ?>
2057 linlun 74
      current_value['<?php echo $alias?>'] = 0;
75
      next_value['<?php echo $alias?>'] = -1;
2056 arune 76
    <?php
1872 runge 77
    }
78
    ?>
79
    var updating_current = false;
80
    var timer = null;
81
 
82
    function checkCurrentValue()
83
    {
84
      updating_current = true;
2059 linlun 85
      jQuery.getJSON("?getdata=1", "<?php echo "alias[]=" . implode("&alias[]=", $aliasesDimmer)?>", function(data)
1872 runge 86
      {
87
 
88
 
89
        jQuery.each(data, function(alias, value)
90
        {
2058 linlun 91
          current_value[alias] = value.Level.value;
92
          $('#slider' + alias).val(value.Level.value).slider("refresh");
1872 runge 93
        });
94
 
95
        updating_current = false;
2057 linlun 96
      });
2059 linlun 97
      jQuery.getJSON("?getdata=1", "<?php echo "alias[]=" . implode("&alias[]=", $aliasesOther)?>", function(data)
2054 linlun 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
	    {
2058 linlun 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
	      }
2054 linlun 123
	    });
124
 
125
	    text += "<br/>";
126
	  });
127
 
128
	  element.html(text);
129
 
130
 
1872 runge 131
      });
2054 linlun 132
      timer = setTimeout(checkCurrentValue, 5000);
1872 runge 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
 
2051 linlun 162
      clearInterval(timer);
1872 runge 163
      timer = null;
164
 
2051 linlun 165
      jQuery.get("?alias=" + alias + "&DimmerStrength=" + strength, "", function()
1872 runge 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
        {
2051 linlun 175
          timer = setTimeout(delayed_start_of_poll, 3000);
1872 runge 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> 
2051 linlun 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>
2056 arune 202
	  <?php
2051 linlun 203
	  foreach ($aliasesDimmer as $alias)
204
	  {
205
	  ?>
206
	  <div data-role="fieldcontain" id="slider-container">
2057 linlun 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"  />
2051 linlun 209
	  </div>
210
 
211
	  <div style="">
212
 
213
	  </div>
2056 arune 214
	  <?php
2051 linlun 215
	  }
216
	  ?>
217
	</div>
1872 runge 218
      </div>
2051 linlun 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>
2056 arune 224
	  <?php
2051 linlun 225
	  foreach ($aliasesPower as $alias)
226
	  {
227
	  ?>
228
	  <div data-role="fieldcontain" id="slider-container">
2057 linlun 229
	    <label for="slider<?php echo $alias?>"><?php echo ucfirst($alias)?>:</label>
2051 linlun 230
	  </div>
231
 
232
	  <div style="">
233
 
234
	  </div>
2056 arune 235
	  <?php
2051 linlun 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>
2054 linlun 245
	  <div id="current-information">None</div>
2056 arune 246
<?php
2051 linlun 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> 
1872 runge 254
  </div> 
255
</body> 
2056 arune 256
</html>