-
Notifications
You must be signed in to change notification settings - Fork 0
/
behaviors.js
51 lines (45 loc) · 944 Bytes
/
behaviors.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2014 Andrew Rodgers, Andrew McPherson, and Jake Brown. All rights reserved.
// MIT license
$(document).ready(function()
{
var busyness = 0;
var brightness = {min: 100, max: 254};
$(document).keyup(function()
{
busyness = Math.max(busyness, 5);
setBrightness(brightness.max)
});
$(document).scroll(function()
{
busyness = Math.max(busyness, 2);
setBrightness(brightness.max)
});
setInterval(function()
{
busyness -= 1;
if(busyness <= 0)
setBrightness(brightness.min);
},
0.5 * 1000)
});
function setBrightness(brightness)
{
if(this.brightness != brightness)
{
jQuery.ajax({
type: "PUT",
url: "http://10.0.0.180/api/newdeveloper/lights/3/state",
data: JSON.stringify({
on: true,
bri: brightness,
transitiontime: 30
}),
processData: false
})
.then(function(data)
{
console.log(JSON.stringify(data, undefined, 2));
});
this.brightness = brightness;
}
}