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
2057 linlun 2
$aliasesDimmer = array("bardisk_tv", "TakSovrum");
3
$aliasesOther = array("Power", "PowerBRF");
1872 runge 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
{
2051 linlun 12
  if (intval($_GET["strength"]) < 10)
1872 runge 13
  {
2051 linlun 14
    $_GET["strength"] = 0;
1872 runge 15
  }
16
 
2051 linlun 17
  SetDimmerValue($_GET["alias"], $_GET["strength"]);
1872 runge 18
 
2051 linlun 19
  echo json_encode($response);
20
  exit(0);
1872 runge 21
}
2051 linlun 22
else if (isset($_GET["getvalue"]))
1872 runge 23
{
2057 linlun 24
  foreach ($_GET["alias"] as $alias)
1872 runge 25
  {
2051 linlun 26
    $response[$alias] = GetLastValue($alias);
1872 runge 27
  }
28
 
29
  echo json_encode($response);
30
  exit(0);
31
}
2051 linlun 32
else if (isset($_GET["getdata"]))
1872 runge 33
{
2057 linlun 34
  foreach ($_GET["alias"] as $alias)
1872 runge 35
  {
2054 linlun 36
    $responseData = GetLastData($alias);
37
 
38
    foreach ($responseData as $name => $value)
39
    {
40
      $response[$name] = $value;
41
    }
1872 runge 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> 
2051 linlun 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>
2056 arune 59
<?php
2051 linlun 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
?>
1872 runge 64
  <script>
65
 
66
    $(document).bind("pagecreate", function(event, ui)
67
    {
2056 arune 68
      <?php
2051 linlun 69
      foreach ($aliasesDimmer as $alias)
1872 runge 70
      {
71
      ?>
2057 linlun 72
        $('#slider<?php  echo $alias?>' ).bind('change', function(event, ui){ makeAjaxChange("<?php  echo $alias?>"); });
2056 arune 73
      <?php
1872 runge 74
      }
75
      ?>
76
      delayed_start_of_poll();
77
    });
78
 
79
    var current_value = {};
80
    var next_value = {};
81
 
2056 arune 82
    <?php
2051 linlun 83
    foreach ($aliasesDimmer as $alias)
1872 runge 84
    {
85
    ?>
2057 linlun 86
      current_value['<?php echo $alias?>'] = 0;
87
      next_value['<?php echo $alias?>'] = -1;
2056 arune 88
    <?php
1872 runge 89
    }
90
    ?>
91
    var updating_current = false;
92
    var timer = null;
93
 
94
    function checkCurrentValue()
95
    {
96
      updating_current = true;
2057 linlun 97
      jQuery.getJSON("?getvalue=1", "<? echo "alias[]=" . implode("&alias[]=", $aliasesDimmer)?>", function(data)
1872 runge 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;
2057 linlun 108
      });
109
      jQuery.getJSON("?getdata=1", "<? echo "alias[]=" . implode("&alias[]=", $aliasesOther)?>", function(data)
2054 linlun 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
 
1872 runge 132
      });
2054 linlun 133
      timer = setTimeout(checkCurrentValue, 5000);
1872 runge 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
 
2051 linlun 163
      clearInterval(timer);
1872 runge 164
      timer = null;
165
 
2051 linlun 166
      jQuery.get("?alias=" + alias + "&DimmerStrength=" + strength, "", function()
1872 runge 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
        {
2051 linlun 176
          timer = setTimeout(delayed_start_of_poll, 3000);
1872 runge 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> 
2051 linlun 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>
2056 arune 203
	  <?php
2051 linlun 204
	  foreach ($aliasesDimmer as $alias)
205
	  {
206
	  ?>
207
	  <div data-role="fieldcontain" id="slider-container">
2057 linlun 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"  />
2051 linlun 210
	  </div>
211
 
212
	  <div style="">
213
 
214
	  </div>
2056 arune 215
	  <?php
2051 linlun 216
	  }
217
	  ?>
218
	</div>
1872 runge 219
      </div>
2051 linlun 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>
2056 arune 225
	  <?php
2051 linlun 226
	  foreach ($aliasesPower as $alias)
227
	  {
228
	  ?>
229
	  <div data-role="fieldcontain" id="slider-container">
2057 linlun 230
	    <label for="slider<?php echo $alias?>"><?php echo ucfirst($alias)?>:</label>
2051 linlun 231
	  </div>
232
 
233
	  <div style="">
234
 
235
	  </div>
2056 arune 236
	  <?php
2051 linlun 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>
2054 linlun 246
	  <div id="current-information">None</div>
2056 arune 247
<?php
2051 linlun 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> 
1872 runge 255
  </div> 
256
</body> 
2056 arune 257
</html>