Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

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