Subversion Repositories HomeAutomation

Rev

Rev 2058 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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