Subversion Repositories HomeAutomation

Rev

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

Rev 2054 Rev 2056
1
<?php
1
<?php
2
$aliasesDimmer = array("TakSovrum", "bardisk", "bardisk_tak", "bardisk_tv","Power", "PowerBRF");
2
$aliasesDimmer = array("powerMeter", "heatMeter");
3
$aliasesPower = array("Power", "PowerBRF");
3
//$aliasesPower = array("powerMeter", "heatMeter");
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 ($aliasesDimmer 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 ($aliasesDimmer 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
<?
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
      <?
68
      <?php
69
      foreach ($aliasesDimmer as $alias)
69
      foreach ($aliasesDimmer as $alias)
70
      {
70
      {
71
      ?>
71
      ?>
72
        $('#slider<?=$alias?>' ).bind('change', function(event, ui){ makeAjaxChange("<?=$alias?>"); });
72
        $('#slider<?php=$alias?>' ).bind('change', function(event, ui){ makeAjaxChange("<?php=$alias?>"); });
73
      <?
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
    <?
82
    <?php
83
    foreach ($aliasesDimmer as $alias)
83
    foreach ($aliasesDimmer as $alias)
84
    {
84
    {
85
    ?>
85
    ?>
86
      current_value['<?=$alias?>'] = 0;
86
      current_value['<?php=$alias?>'] = 0;
87
      next_value['<?=$alias?>'] = -1;
87
      next_value['<?php=$alias?>'] = -1;
88
    <?
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
      /*
97
      /*
98
      jQuery.getJSON("?getvalue=1", "", function(data)
98
      jQuery.getJSON("?getvalue=1", "", function(data)
99
      {
99
      {
100
       
100
       
101
       
101
       
102
        jQuery.each(data, function(alias, value)
102
        jQuery.each(data, function(alias, value)
103
        {
103
        {
104
          current_value[alias] = value;
104
          current_value[alias] = value;
105
          $('#slider' + alias).val(value).slider("refresh");
105
          $('#slider' + alias).val(value).slider("refresh");
106
        });
106
        });
107
       
107
       
108
        updating_current = false;
108
        updating_current = false;
109
      });*/
109
      });*/
110
      jQuery.getJSON("?getdata=1", "", function(data)
110
      jQuery.getJSON("?getdata=1", "", function(data)
111
      {
111
      {
112
      var element = $("#current-information");
112
      var element = $("#current-information");
113
 
113
 
114
      element.empty();
114
      element.empty();
115
 
115
 
116
      var text = "";
116
      var text = "";
117
 
117
 
118
      jQuery.each(data, function(alias, aliasData)
118
      jQuery.each(data, function(alias, aliasData)
119
      {
119
      {
120
        text += "<b>" + alias + "</b><br/>";
120
        text += "<b>" + alias + "</b><br/>";
121
 
121
 
122
        jQuery.each(aliasData, function(name, value)
122
        jQuery.each(aliasData, function(name, value)
123
        {
123
        {
124
          text += name + "=" + value.value + "<br/>";
124
          text += name + "=" + value.value + "<br/>";
125
        });
125
        });
126
 
126
 
127
        text += "<br/>";
127
        text += "<br/>";
128
      });
128
      });
129
 
129
 
130
      element.html(text);
130
      element.html(text);
131
 
131
 
132
 
132
 
133
      });
133
      });
134
      timer = setTimeout(checkCurrentValue, 5000);
134
      timer = setTimeout(checkCurrentValue, 5000);
135
    }
135
    }
136
 
136
 
137
    function makeAjaxChange(alias)
137
    function makeAjaxChange(alias)
138
    {
138
    {
139
      if (updating_current)
139
      if (updating_current)
140
      {
140
      {
141
        return;
141
        return;
142
      }
142
      }
143
   
143
   
144
      if ($('#slider' + alias).val() == current_value)
144
      if ($('#slider' + alias).val() == current_value)
145
      {
145
      {
146
        return;
146
        return;
147
      }
147
      }
148
     
148
     
149
      if (next_value[alias] == -1) // Nothing in progress, do a call
149
      if (next_value[alias] == -1) // Nothing in progress, do a call
150
      {
150
      {
151
        do_call(alias, $('#slider' + alias).val());
151
        do_call(alias, $('#slider' + alias).val());
152
      }
152
      }
153
      else
153
      else
154
      {
154
      {
155
        next_value[alias] = $('#slider' + alias).val();
155
        next_value[alias] = $('#slider' + alias).val();
156
      }
156
      }
157
      // console.log($('#slider').val());
157
      // console.log($('#slider').val());
158
    }
158
    }
159
   
159
   
160
    function do_call(alias, strength)
160
    function do_call(alias, strength)
161
    {
161
    {
162
      next_value[alias] = strength;
162
      next_value[alias] = strength;
163
     
163
     
164
      clearInterval(timer);
164
      clearInterval(timer);
165
      timer = null;
165
      timer = null;
166
     
166
     
167
      jQuery.get("?alias=" + alias + "&DimmerStrength=" + strength, "", function()
167
      jQuery.get("?alias=" + alias + "&DimmerStrength=" + strength, "", function()
168
      {
168
      {
169
        current_value[alias] = strength;
169
        current_value[alias] = strength;
170
       
170
       
171
        if (next_value[alias] != current_value[alias])
171
        if (next_value[alias] != current_value[alias])
172
        {
172
        {
173
          do_call(alias, next_value[alias]);
173
          do_call(alias, next_value[alias]);
174
        }
174
        }
175
        else
175
        else
176
        {
176
        {
177
          timer = setTimeout(delayed_start_of_poll, 3000);
177
          timer = setTimeout(delayed_start_of_poll, 3000);
178
          next_value[alias] = -1;
178
          next_value[alias] = -1;
179
        }
179
        }
180
      });
180
      });
181
    }
181
    }
182
   
182
   
183
    function delayed_start_of_poll()
183
    function delayed_start_of_poll()
184
    {
184
    {
185
      timer = setTimeout(checkCurrentValue, 1000);
185
      timer = setTimeout(checkCurrentValue, 1000);
186
    }
186
    }
187
 
187
 
188
  </script>
188
  </script>
189
 
189
 
190
</head>
190
</head>
191
<body>
191
<body>
192
  <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">
193
    <div data-role="header" data-position="inline">
193
    <div data-role="header" data-position="inline">
194
        <a href="index.html" data-icon="delete">Cancel</a>
194
        <a href="index.html" data-icon="delete">Cancel</a>
195
        <h1>Testar</h1>
195
        <h1>Testar</h1>
196
        <a href="index.html" data-icon="check">Save</a>
196
        <a href="index.html" data-icon="check">Save</a>
197
    </div>
197
    </div>
198
    <div data-role="content">
198
    <div data-role="content">
199
      <div data-role="collapsible-set" data-theme="" data-content-theme="">
199
      <div data-role="collapsible-set" data-theme="" data-content-theme="">
200
    <div data-role="collapsible" data-collapsed="true">
200
    <div data-role="collapsible" data-collapsed="true">
201
      <h3>
201
      <h3>
202
        Dimmers
202
        Dimmers
203
      </h3>
203
      </h3>
204
      <?
204
      <?php
205
      foreach ($aliasesDimmer as $alias)
205
      foreach ($aliasesDimmer as $alias)
206
      {
206
      {
207
      ?>
207
      ?>
208
      <div data-role="fieldcontain" id="slider-container">
208
      <div data-role="fieldcontain" id="slider-container">
209
        <label for="slider<?=$alias?>"><?=ucfirst($alias)?>:</label>
209
        <label for="slider<?php=$alias?>"><?php=ucfirst($alias)?>:</label>
210
        <input type="range" name="slider<?=$alias?>" id="slider<?=$alias?>" value="<?=intval($level)?>" min="0" max="255"  />
210
        <input type="range" name="slider<?php=$alias?>" id="slider<?php=$alias?>" value="<?php=intval($level)?>" min="0" max="255"  />
211
      </div>
211
      </div>
212
 
212
 
213
      <div style="">
213
      <div style="">
214
 
214
 
215
      </div>
215
      </div>
216
      <?
216
      <?php
217
      }
217
      }
218
      ?>
218
      ?>
219
    </div>
219
    </div>
220
      </div>
220
      </div>
221
      <div data-role="collapsible-set" data-theme="" data-content-theme="">
221
      <div data-role="collapsible-set" data-theme="" data-content-theme="">
222
    <div data-role="collapsible" data-collapsed="true">
222
    <div data-role="collapsible" data-collapsed="true">
223
      <h3>
223
      <h3>
224
        Power
224
        Power
225
      </h3>
225
      </h3>
226
      <?
226
      <?php
227
      foreach ($aliasesPower as $alias)
227
      foreach ($aliasesPower as $alias)
228
      {
228
      {
229
      ?>
229
      ?>
230
      <div data-role="fieldcontain" id="slider-container">
230
      <div data-role="fieldcontain" id="slider-container">
231
        <label for="slider<?=$alias?>"><?=ucfirst($alias)?>:</label>
231
        <label for="slider<?php=$alias?>"><?php=ucfirst($alias)?>:</label>
232
      </div>
232
      </div>
233
 
233
 
234
      <div style="">
234
      <div style="">
235
 
235
 
236
      </div>
236
      </div>
237
      <?
237
      <?php
238
      }
238
      }
239
      ?>
239
      ?>
240
    </div>
240
    </div>
241
      </div>
241
      </div>
242
      <div data-role="collapsible-set" data-theme="" data-content-theme="">
242
      <div data-role="collapsible-set" data-theme="" data-content-theme="">
243
    <div data-role="collapsible" data-collapsed="true">
243
    <div data-role="collapsible" data-collapsed="true">
244
      <h3>
244
      <h3>
245
        Ute temperatur
245
        Ute temperatur
246
      </h3>
246
      </h3>
247
      <div id="current-information">None</div>
247
      <div id="current-information">None</div>
248
<?
248
<?php
249
//    <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;">
250
//      <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" />
251
//    </div>
251
//    </div>
252
?>
252
?>
253
    </div>
253
    </div>
254
      </div>
254
      </div>
255
    </div>
255
    </div>
256
  </div>
256
  </div>
257
</body>
257
</body>
258
</html>
258
</html>
-
 
259