Subversion Repositories HomeAutomation

Rev

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

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