Added Main
This commit is contained in:
@@ -8,7 +8,9 @@ version '1.0-SNAPSHOT'
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url("https://plugins.gradle.org/m2/")
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -9,6 +9,7 @@ import support.Rest;
|
||||
* Classe che permette di controllare le luci Philips Hue
|
||||
*/
|
||||
public class Hue {
|
||||
public static final int MAX_BRIGHTNESS = 255;
|
||||
//private String baseURL = "192.168.0.2";
|
||||
//private String username = "C0vPwqjJZo5Jt9Oe5HgO6sBFFMxgoR532IxFoGmx";
|
||||
/**
|
||||
@@ -21,6 +22,8 @@ public class Hue {
|
||||
*/
|
||||
private Map<String, ?> allLights;
|
||||
|
||||
private int brightness = 0;
|
||||
|
||||
public Hue () {
|
||||
this("http://172.30.1.138/api/C0vPwqjJZo5Jt9Oe5HgO6sBFFMxgoR532IxFoGmx/lights/");
|
||||
}
|
||||
@@ -33,6 +36,7 @@ public class Hue {
|
||||
public Hue (String url) {
|
||||
lightsURL = url;
|
||||
allLights = Rest.get(lightsURL);
|
||||
// Todo brightness initial
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +85,7 @@ public class Hue {
|
||||
* @return
|
||||
*/
|
||||
public int getCurrentBrightness() {
|
||||
return 0;
|
||||
return brightness;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,6 +100,45 @@ public class Hue {
|
||||
String body = "{ \"bri\" : "+num+" }";
|
||||
Rest.put(callURL, body, "application/json");
|
||||
}
|
||||
brightness = num;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dinuisce la luminosita' delle luci controllate della percentuale che viene passata
|
||||
* @param percentage la percentuale di diminuzione
|
||||
*/
|
||||
public void increaseBrightness(int percentage) {
|
||||
if (percentage<0)
|
||||
percentage = 0;
|
||||
else if (percentage>100)
|
||||
percentage = 100;
|
||||
setBrightness(brightness + (percentage*MAX_BRIGHTNESS)/100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Aumenta la luminosita' delle luci controllate del 10%
|
||||
*/
|
||||
public void increaseBrightness() {
|
||||
increaseBrightness(10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dinuisce la luminosita' delle luci controllate della percentuale che viene passata
|
||||
* @param percentage la percentuale di diminuzione
|
||||
*/
|
||||
public void decreaseBrightness(int percentage) {
|
||||
if (percentage<0)
|
||||
percentage = 0;
|
||||
else if (percentage>100)
|
||||
percentage = 100;
|
||||
setBrightness(brightness - (percentage*MAX_BRIGHTNESS)/100);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dinuisce la luminosita' delle luci controllate del 10%
|
||||
*/
|
||||
public void decreaseBrightness() {
|
||||
decreaseBrightness(10);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,7 +57,7 @@ public class Sensor {
|
||||
devices.addDevice(devi);
|
||||
}
|
||||
|
||||
public int luminiscenceLevel() {
|
||||
public int getBrightnessLevel() {
|
||||
for (Device device : devices.getAllDevices())
|
||||
if (device.getMetrics().getProbeTitle().equalsIgnoreCase("luminiscence"))
|
||||
return Integer.parseInt(device.getMetrics().getLevel());
|
||||
|
||||
34
src/main/java/main/Main.java
Normal file
34
src/main/java/main/Main.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package main;
|
||||
|
||||
import device.*;
|
||||
|
||||
/**
|
||||
* Created by 20015159 on 28/08/2018.
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Fitbit fitbit = new Fitbit();
|
||||
Sensor sensor = new Sensor();
|
||||
Hue hue = new Hue();
|
||||
|
||||
while(true) {
|
||||
double heart = fitbit.getHeartRate();
|
||||
int brightness = sensor.getBrightnessLevel();
|
||||
|
||||
// AUTOMATIC
|
||||
// Inserire ui dati nel DB ogni ora
|
||||
// Gestione luci in modo che la luminosità sia sempre la stessa
|
||||
// Gestione luci a seconda del battito cardiaco
|
||||
// Ad una certa ora guarda i passi e se sono pochi dillo
|
||||
// Se i battiti sono troppo bassi/alti avvisare il tizio
|
||||
|
||||
// USER-INTERACTION
|
||||
// Dati del sonno/battito/passi che l'utente puo' richiedere
|
||||
// Gestione luci secondo le esigenze dell'utente
|
||||
// EXTRA Gestione musica tramite comando vocale
|
||||
|
||||
// Randomly at night heavy metal start
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import org.junit.Test;
|
||||
|
||||
import device.Fitbit;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestFitbit {
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.util.Set;
|
||||
@Test
|
||||
synchronized public void firstTestSensor() throws InterruptedException {
|
||||
sensor.update(2);
|
||||
System.out.println(sensor.luminiscenceLevel());
|
||||
System.out.println(sensor.getBrightnessLevel());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -28,15 +28,15 @@ import java.util.Set;
|
||||
lights.turnOn();
|
||||
|
||||
while(i<999999) {
|
||||
if (sensor.luminiscenceLevel() < 200) {
|
||||
if (sensor.getBrightnessLevel() < 200) {
|
||||
lights.getCurrentBrightness();
|
||||
lights.setBrightness(200);
|
||||
}
|
||||
|
||||
if (sensor.luminiscenceLevel() > 600) {
|
||||
if (sensor.getBrightnessLevel() > 600) {
|
||||
lights.setBrightness(0);
|
||||
}
|
||||
System.out.println(i+"-"+sensor.luminiscenceLevel());
|
||||
System.out.println(i+"-"+sensor.getBrightnessLevel());
|
||||
sensor.update(100);
|
||||
i++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user