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