Subversion Repositories HomeAutomation

Rev

Rev 2060 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

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