Subversion Repositories HomeAutomation

Rev

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

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