Fixing
- final version of build.gradle - fixed colors - removed Todos
This commit is contained in:
@@ -25,6 +25,7 @@ dependencies {
|
||||
|
||||
// Z-way
|
||||
compile files('lib/zway-lib-0.2.9-SNAPSHOT.jar')
|
||||
compile 'org.apache.commons:commons-lang3:3.8'
|
||||
|
||||
// Logger
|
||||
compile 'org.slf4j:slf4j-simple:1.7.25'
|
||||
@@ -33,7 +34,6 @@ dependencies {
|
||||
compile "com.sparkjava:spark-core:2.7.2"
|
||||
|
||||
// Oauth
|
||||
// compile group: 'org.pac4j', name: 'spark-pac4j', version: '2.3.0' //todo use this insted?
|
||||
compile ( group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.23.0') {
|
||||
// don't pull in an old ancient jetty version
|
||||
exclude group: 'org.mortbay.jetty', module: 'jetty'
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DialogFlowWebHook {
|
||||
/**
|
||||
* Un logger per vedere le cose piu' easy
|
||||
*/
|
||||
private static final Logger LOG = LoggerFactory.getLogger(DialogFlowWebHook.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger("WebHook");
|
||||
|
||||
/**
|
||||
* Stringa che viene usata se l'azione esiste ma lancia un qualche tipo di errore
|
||||
|
||||
@@ -47,17 +47,17 @@ public class Hue {
|
||||
/**
|
||||
* Riempimento della mappa con i vari colori
|
||||
*/
|
||||
static { // todo set right colors (in the simulation they are off, maybe in reality are ok)
|
||||
COLORS.put("giall[oae]", new Double[]{0.475, 0.475}); //wrong
|
||||
static {
|
||||
COLORS.put("giall[oae]", new Double[]{0.45, 0.45});
|
||||
COLORS.put("ross[oae]", new Double[]{0.7, 0.25});
|
||||
COLORS.put("verd[ei]", new Double[]{0.1, 0.55});
|
||||
COLORS.put("blu", new Double[]{0.15, 0.175}); //wrong
|
||||
COLORS.put("blu", new Double[]{0.12, 0.125});
|
||||
COLORS.put("rosa", new Double[]{0.45, 0.275});
|
||||
COLORS.put("viola", new Double[]{0.25, 0.1});
|
||||
COLORS.put("azzurr[oae]", new Double[]{0.15, 0.25});
|
||||
COLORS.put("arancio(ne|ni)?", new Double[]{0.6, 0.35}); //wrong
|
||||
COLORS.put("arancio(ne|ni)?", new Double[]{0.55, 0.4});
|
||||
//COLORS.put("nero", new Double[]{1.0, 1.0});
|
||||
COLORS.put("bianc(o|a|he)", new Double[]{0.3, 0.25}); //wrong
|
||||
COLORS.put("bianc(o|a|he)", new Double[]{0.275, 0.3});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,24 +81,22 @@ public class Hue {
|
||||
if(allLights.isEmpty())
|
||||
throw new NullPointerException("Non e' stato possibile connettersi alle luci");
|
||||
|
||||
if(allLights.size() != 0) {
|
||||
double bri = 0;
|
||||
double hue = 0;
|
||||
for (String name: allLights.keySet()) {
|
||||
Map<String, Object> state = (Map<String, Object>)allLights.get(name).get("state");
|
||||
bri += (Double) state.get("bri");
|
||||
hue += (Double) state.get("hue");
|
||||
}
|
||||
bri = bri/allLights.size();
|
||||
hue = hue/allLights.size();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("bri", (int)bri);
|
||||
map.put("hue", (int)hue);
|
||||
setState(map);
|
||||
|
||||
brightness = (bri*MAX_BRIGHTNESS)/100;
|
||||
double bri = 0;
|
||||
double hue = 0;
|
||||
for (String name: allLights.keySet()) {
|
||||
Map<String, Object> state = (Map<String, Object>)allLights.get(name).get("state");
|
||||
bri += (Double) state.get("bri");
|
||||
hue += (Double) state.get("hue");
|
||||
}
|
||||
bri = bri/allLights.size();
|
||||
hue = hue/allLights.size();
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("bri", (int)bri);
|
||||
map.put("hue", (int)hue);
|
||||
setState(map);
|
||||
|
||||
brightness = (bri*MAX_BRIGHTNESS)/100;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -220,7 +218,7 @@ public class Hue {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put(attribute, value);
|
||||
if(transition)
|
||||
map.put("transition", 20);
|
||||
map.put("transition", 200);
|
||||
setState(map);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import support.Database;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
@@ -25,7 +26,16 @@ public class Main {
|
||||
private static Sensor sensor = null;
|
||||
|
||||
/**
|
||||
* Funzione principale, qui si creano tutte le classi che verranno utilizzate.
|
||||
* Funzione principale, qui si creano tutte le classi che verranno utilizzate.<br>
|
||||
* Si possono passare dei parametri usando -(nome parametro)::(valore parametro)<br>
|
||||
* Ogni parametro deve esser separato da uno o piu spazi<br>
|
||||
* Parametri possibili:<br>
|
||||
* <ul>
|
||||
* <li>hueAddress</li>
|
||||
* <li>hueUser</li>
|
||||
* <li>sensorNode</li>
|
||||
* <li>sensorLog</li>
|
||||
* </ul>
|
||||
* @param args per ora nulla, ma forse in futuro si potrebbe mettere roba
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
@@ -46,7 +56,8 @@ public class Main {
|
||||
sensor = new Sensor(sensorNode);
|
||||
|
||||
if(sensorLog>0)
|
||||
startSensorLog(sensorLog);
|
||||
startSensorLog(sensorLog);
|
||||
startHueAutoBrightness();
|
||||
} catch (Exception e) {
|
||||
LOG.warn(e.getMessage());
|
||||
}
|
||||
@@ -64,7 +75,6 @@ public class Main {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
startHueAutoBrightness();
|
||||
startWebhook();
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage());
|
||||
@@ -132,7 +142,7 @@ public class Main {
|
||||
while(notInterrupted) {
|
||||
try {
|
||||
sensor.update((seconds/2) * 1000);
|
||||
LOG.info("Luminosità rilevata: " + sensor.getBrightnessLevel());
|
||||
LOG.info("Luminosita' rilevata: " + sensor.getBrightnessLevel());
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
notInterrupted = false;
|
||||
@@ -151,6 +161,51 @@ public class Main {
|
||||
// se troppo bassa alzare la luci di poco
|
||||
// se troppo alta abbassare le luci
|
||||
// se l'utente modifica la luminosita' delle luci allora non fare nulla per almeno 20/30 minuti o di piu
|
||||
/*
|
||||
Thread thread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
boolean notInterrupted = true;
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
while(notInterrupted) {
|
||||
calendar.setTimeInMillis(System.currentTimeMillis());
|
||||
int bright = sensor.getBrightnessLevel();
|
||||
int hour = calendar.get(Calendar.HOUR_OF_DAY);
|
||||
|
||||
if(hour >= 21 && hour<7) {
|
||||
lights.setBrightness(5);
|
||||
}
|
||||
else if(hour >= 19 && hour<21) {
|
||||
lights.setBrightness(99);
|
||||
}
|
||||
else if(hour >= 7 && hour<19) {
|
||||
lights.setBrightness(0);
|
||||
}
|
||||
|
||||
try {
|
||||
wait(120000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
notInterrupted = false;
|
||||
}
|
||||
|
||||
if(hour >= 21 && hour<7)
|
||||
lights.setBrightness(5);
|
||||
else if(bright >= 0 && bright <= 20)
|
||||
lights.setBrightness(90);
|
||||
else if(bright >= 21 && bright <= 40)
|
||||
lights.setBrightness(60);
|
||||
else if(bright >= 41 && bright <= 60)
|
||||
lights.setBrightness(40);
|
||||
else
|
||||
lights.turnOff();
|
||||
|
||||
}
|
||||
}
|
||||
}, "auto-brightness");
|
||||
|
||||
thread.start();
|
||||
*/
|
||||
}
|
||||
|
||||
// TODO AUTO:{C} Gestione luci a seconda del battito cardiaco
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
* the License.
|
||||
*/
|
||||
|
||||
// todo test if fitbit request still works with this class
|
||||
|
||||
package oauth;
|
||||
|
||||
import com.google.api.client.extensions.java6.auth.oauth2.VerificationCodeReceiver;
|
||||
|
||||
@@ -40,7 +40,7 @@ public class TestLights {
|
||||
}
|
||||
|
||||
lights.setBrightness(Hue.MAX_BRIGHTNESS);
|
||||
lights.colorLoop(); // todo not working in simulator
|
||||
lights.colorLoop();
|
||||
this.wait(TIMEOUT*10);
|
||||
|
||||
// change colors
|
||||
|
||||
Reference in New Issue
Block a user