Repository navigation
Expand file tree
/
Copy pathbusysignal.js
More file actions
123 lines (104 loc) · 1.94 KB
/
Copy pathbusysignal.js
File metadata and controls
123 lines (104 loc) · 1.94 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Copyright (c) 2014 Andrew McPherson, Andrew Rodgers, and Jake Brown. All rights reserved.
// MIT license
var lightIP = "10.0.0.180"
var lightID = "3"
var lightUser = "newdeveloper"
var lightLocation = "http://"+lightIP+"/api/"+lightUser+"/lights/"+lightID+"/state";
$(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)
$("#busy").click(function()
{
setColor(65535);
});
$("#maxBrightness").change(function()
{
brightness.max = parseInt($(this).val());
console.log(brightness.max);
busyness = 3;
setBrightness(brightness.max);
});
$("#busy").click(function()
{
setColor(65535);
});
$("#away").click(function()
{
setPowerState();
});
$("#available").click(function()
{
setColor(25500);
});
});
function setBrightness(brightness)
{
if(this.brightness != brightness)
{
jQuery.ajax({
type: "PUT",
url: lightLocation,
data: JSON.stringify({
on: true,
bri: brightness,
transitiontime: 30
}),
processData: false
})
.then(function(data)
{
console.log(JSON.stringify(data, undefined, 2));
});
this.brightness = brightness;
}
}
function setColor(color)
{
jQuery.ajax({
type: "PUT",
url: lightLocation,
data: JSON.stringify({
on: true,
hue: color,
transitiontime: 30
}),
processData: false
})
.then(function(data)
{
//console.log(JSON.stringify(data, undefined, 2));
});
}
function setPowerState()
{
jQuery.ajax({
type: "PUT",
url: lightLocation,
data: JSON.stringify({
on: false
}),
processData: false
})
.then(function(data)
{
console.log(JSON.stringify(data, undefined, 2));
});
}