-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault.js
204 lines (133 loc) · 5.24 KB
/
default.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
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//module.exports.repl.ignoreUndefined = true;
//exports.bArrayLightOn = bArrayLightOn = [];
//Load all default Paths
require('./config/var/src/db.paths');
//Load all console require
exec = require('child_process').exec;
fs = require('fs');
net = require('net');
http = require('http');
https = require("https");
path = require('path');
request = require('request');
url = require('url');
get = require('simple-get')
//SDK1
//SDK2
hue = require('hue-sdk'); //hue = require( pathresources + './hue-sdk/lib/hue.js'),
client = new hue.Hue(require( pathconfig + './.credentials.json' ));
//Load and set default variables
require('./config/var/db.var.builder.js');
require('./config/var/db.var');
//Load default modules
bridge = require( pathhuebridge + 'bridge.js' );
sensor = require( pathhuesensor + 'sensor.js' );
light = require( pathhuelight + 'light.js' );
avr = require( pathavrhk171s + 'avr.js');
smarttv = require( pathsmarttv + 'tv.js' );
server = require( pathserver + 'server.js' );
//
//httpRequests = require( pathlib + 'httpRequests.js' );
//httpPost = require( pathlib + 'httpPost.js' );
//httpGet = require( pathlib + 'httpGet.js' );
// Variables for Colored messages
const colors = {
//General
Reset: "\x1b[0m", Bright: "\x1b[1m",
Dim: "\x1b[2m",
Underscore: "\x1b[4m",
Blink: "\x1b[5m",
Reverse: "\x1b[7m",
Hidden: "\x1b[8m",
//Font Color
Black: "\x1b[30m", fgBlack: "\x1b[30m", fgDarkGray: "\x1b[39m",
Red: "\x1b[31m", fgRed: "\x1b[31m", fgLightRed: "\x1b[91m",
Green: "\x1b[32m", fgGreen: "\x1b[32m", fgLightGreen: "\x1b[92m",
Yellow: "\x1b[33m", fgYellow: "\x1b[33m", fgLightYellow: "\x1b[93m",
Blue: "\x1b[34m", fgBlue: "\x1b[34m", fgLightBlue: "\x1b[94m",
Magenta: "\x1b[35m", fgMagenta: "\x1b[35m", fgLightMagenta: "\x1b[95m",
Cyan: "\x1b[36m", fgCyan: "\x1b[36m", fgLightCyan: "\x1b[96m",
LightGray: "\x1b[37m", fgLightGray: "\x1b[37m", fgWhite: "\x1b[97m",
Crimson: "\x1b[38m", fgCrimson: "\x1b[38m",
fgDefault: "\x1b[39m",
//Background Color
bgBlack: "\x1b[40m", bgDarkGray: "\x1b[100m",
bgRed: "\x1b[41m", bgLightRed: "\x1b[101m",
bgGreen: "\x1b[42m", bgLightGreen: "\x1b[102m",
bgYellow: "\x1b[43m", bgLightYellow: "\x1b[103m",
bgBlue: "\x1b[44m", bgLightBlue: "\x1b[104m",
bgMagenta: "\x1b[45m", bgLightMagenta: "\x1b[105m",
bgCyan: "\x1b[46m", bgLightCyan: "\x1b[106m",
bgWhite: "\x1b[47m",
bgCrimson: "\x1b[48m",
bgDefault: "\x1b[49m",
};
const colorName = [colors.Red, colors.Green, colors.Blue];
var cLogSTDout = function(msg) { process.stdout.write(msg); };
function cLogSTDColor(color = colors.Reset, msg) {
//cLogSTDout(color + msg + colors.Reset);
};
/*******\
| Start |###############################################################################################################################################################################
\*******/
//Start server at http://127.0.0.1:80
require('./server');
var myInit = function() {
//new method
bridge.statusBridgeGetState();
//keep the old method till new html is created
if ( ( iCounter % 2 ) == 0 ){
sensor.getInfoAll();
} else {
light.getInfoAll();
}
//counter start here when the object contain items
if ( Object.values(oHueStateCur).filter(a=> typeof(a) == 'object').length > 7 ){
oHueStateCur.iCounter = iCounter++;
console.log('counter:' + oHueStateCur.iCounter + ' TickRate:' + iTickrate + ' iTickRateDefault:' + iTickRateDefault + ' iTickRateMin:' + iTickRateMin + ' iTickRateMax:' + iTickRateMax + ' Objects Found:' + (Object.values(oHueStateCur).filter(a=> typeof(a) == 'object').length));
}
setTimeout(myInit, iTickrate);
};
setTimeout(myInit, iTickrate); //myInit();
function tickrateIncrease(iValue = 10){
function tickrateDefaultIncrease(iValue){
if ( iTickRateDefault < ( iTickRateMax - ( iValue / 10 ) ) ){
iTickRateDefault += Math.round( iValue / 10 );
}
}
tickrateDefaultIncrease(iValue);
while ( iValue != 0 ){
if ( iTickrate < iTickRateMax ){
iTickrate++;
}
iValue--;
}
};
function tickrateDecrease(iValue = 10){
function tickrateDefaultDecrease(iValue){
if ( iTickRateDefault > ( iTickRateMin + ( iValue / 10 ) ) ){
iTickRateDefault -= Math.round( iValue / 10 );
}
}
tickrateDefaultDecrease(iValue);
while ( iValue != 0 ){
if ( iTickrate > iTickRateMin ){
iTickrate--;
}
iValue--;
}
}
//function isEmptyObject(obj) {
// for (var key in obj) {
// if (Object.prototype.hasOwnProperty.call(obj, key)) {
// return false;
// }
// }
// return true;
//}
//console.log(isEmptyObject(cache));
//console.log(typeof cache.property == "undefined")
//cache.hasOwnProperty('lights'));
//Object.values(cache).filter(a=> typeof(a) == 'object').length > 0)
//if (Object.keys(cache).length > 4){
// console.log('counter:' + iCounter++ + ' TickRate:' + iTickrate + ' iTickRateDefault:' + iTickRateDefault + ' iTickRateMin:' + iTickRateMin + ' iTickRateMax:' + iTickRateMax + ' lightstate1:' + JSON.stringify(cache));