Added Main
This commit is contained in:
@@ -8,7 +8,9 @@ version '1.0-SNAPSHOT'
|
|||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
maven {
|
||||||
|
url("https://plugins.gradle.org/m2/")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import support.Rest;
|
|||||||
* Classe che permette di controllare le luci Philips Hue
|
* Classe che permette di controllare le luci Philips Hue
|
||||||
*/
|
*/
|
||||||
public class Hue {
|
public class Hue {
|
||||||
|
public static final int MAX_BRIGHTNESS = 255;
|
||||||
//private String baseURL = "192.168.0.2";
|
//private String baseURL = "192.168.0.2";
|
||||||
//private String username = "C0vPwqjJZo5Jt9Oe5HgO6sBFFMxgoR532IxFoGmx";
|
//private String username = "C0vPwqjJZo5Jt9Oe5HgO6sBFFMxgoR532IxFoGmx";
|
||||||
/**
|
/**
|
||||||
@@ -21,6 +22,8 @@ public class Hue {
|
|||||||
*/
|
*/
|
||||||
private Map<String, ?> allLights;
|
private Map<String, ?> allLights;
|
||||||
|
|
||||||
|
private int brightness = 0;
|
||||||
|
|
||||||
public Hue () {
|
public Hue () {
|
||||||
this("http://172.30.1.138/api/C0vPwqjJZo5Jt9Oe5HgO6sBFFMxgoR532IxFoGmx/lights/");
|
this("http://172.30.1.138/api/C0vPwqjJZo5Jt9Oe5HgO6sBFFMxgoR532IxFoGmx/lights/");
|
||||||
}
|
}
|
||||||
@@ -33,6 +36,7 @@ public class Hue {
|
|||||||
public Hue (String url) {
|
public Hue (String url) {
|
||||||
lightsURL = url;
|
lightsURL = url;
|
||||||
allLights = Rest.get(lightsURL);
|
allLights = Rest.get(lightsURL);
|
||||||
|
// Todo brightness initial
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -81,7 +85,7 @@ public class Hue {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int getCurrentBrightness() {
|
public int getCurrentBrightness() {
|
||||||
return 0;
|
return brightness;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,6 +100,45 @@ public class Hue {
|
|||||||
String body = "{ \"bri\" : "+num+" }";
|
String body = "{ \"bri\" : "+num+" }";
|
||||||
Rest.put(callURL, body, "application/json");
|
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);
|
devices.addDevice(devi);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int luminiscenceLevel() {
|
public int getBrightnessLevel() {
|
||||||
for (Device device : devices.getAllDevices())
|
for (Device device : devices.getAllDevices())
|
||||||
if (device.getMetrics().getProbeTitle().equalsIgnoreCase("luminiscence"))
|
if (device.getMetrics().getProbeTitle().equalsIgnoreCase("luminiscence"))
|
||||||
return Integer.parseInt(device.getMetrics().getLevel());
|
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 device.Fitbit;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TestFitbit {
|
public class TestFitbit {
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.Set;
|
|||||||
@Test
|
@Test
|
||||||
synchronized public void firstTestSensor() throws InterruptedException {
|
synchronized public void firstTestSensor() throws InterruptedException {
|
||||||
sensor.update(2);
|
sensor.update(2);
|
||||||
System.out.println(sensor.luminiscenceLevel());
|
System.out.println(sensor.getBrightnessLevel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -28,15 +28,15 @@ import java.util.Set;
|
|||||||
lights.turnOn();
|
lights.turnOn();
|
||||||
|
|
||||||
while(i<999999) {
|
while(i<999999) {
|
||||||
if (sensor.luminiscenceLevel() < 200) {
|
if (sensor.getBrightnessLevel() < 200) {
|
||||||
lights.getCurrentBrightness();
|
lights.getCurrentBrightness();
|
||||||
lights.setBrightness(200);
|
lights.setBrightness(200);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sensor.luminiscenceLevel() > 600) {
|
if (sensor.getBrightnessLevel() > 600) {
|
||||||
lights.setBrightness(0);
|
lights.setBrightness(0);
|
||||||
}
|
}
|
||||||
System.out.println(i+"-"+sensor.luminiscenceLevel());
|
System.out.println(i+"-"+sensor.getBrightnessLevel());
|
||||||
sensor.update(100);
|
sensor.update(100);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user