Subversion Repositories HomeAutomation

Rev

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

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