Merge branches 'dawit' and 'master' of https://github.com/reti2vc-2018/SeniorAssistant into dawit

# Conflicts:
#	.gradle/4.4/fileHashes/fileHashes.bin
#	.gradle/4.4/fileHashes/fileHashes.lock
#	.idea/gradle.xml
#	.idea/workspace.xml
#	build.gradle
#	src/test/java/TestLights.java

#MaybeThisTimeIsCorrect
This commit is contained in:
2018-06-01 21:33:50 +02:00
7 changed files with 81 additions and 89 deletions

View File

@@ -1,38 +1,38 @@
plugins { plugins {
id 'java' id 'java'
} }
group 'SeniorAssistant' group 'SeniorAssistant'
version '1.0-SNAPSHOT' version '1.0-SNAPSHOT'
sourceCompatibility = 1.8 sourceCompatibility = 1.8
repositories { repositories {
mavenCentral() mavenCentral()
} }
dependencies { dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'junit', name: 'junit', version: '4.12'
// compile "com.sparkjava:spark-core:2.5.5" // compile "com.sparkjava:spark-core:2.5.5"
// compile "org.slf4j:slf4j-simple:1.7.21" // compile "org.slf4j:slf4j-simple:1.7.21"
compile "com.google.code.gson:gson:2.8.0" compile "com.google.code.gson:gson:2.8.0"
// compile "org.xerial:sqlite-jdbc:3.15.1" // compile "org.xerial:sqlite-jdbc:3.15.1"
compile 'org.apache.httpcomponents:httpclient:4.5.3' compile 'org.apache.httpcomponents:httpclient:4.5.3'
compile 'com.google.api-client:google-api-client:1.23.0' compile 'com.google.api-client:google-api-client:1.23.0'
compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta' compile group: 'com.google.oauth-client', name: 'google-oauth-client-jetty', version: '1.11.0-beta'
// z-way-lib and all its dependencies (from https://github.com/pathec/ZWay-library-for-Java) // z-way-lib and all its dependencies (from https://github.com/pathec/ZWay-library-for-Java)
compile files('lib/zway-lib-0.2.9-SNAPSHOT.jar') compile files('lib/zway-lib-0.2.9-SNAPSHOT.jar')
// compile 'com.google.code.gson:gson:2.4' //already up there // compile 'com.google.code.gson:gson:2.4' //already up there
compile 'org.apache.commons:commons-lang3:3.4' compile 'org.apache.commons:commons-lang3:3.4'
compile 'org.eclipse.jetty:jetty-client:9.3.11.v20160721' compile 'org.eclipse.jetty:jetty-client:9.3.11.v20160721'
compile 'org.eclipse.jetty:jetty-http:9.3.11.v20160721' compile 'org.eclipse.jetty:jetty-http:9.3.11.v20160721'
compile 'org.eclipse.jetty:jetty-io:9.3.11.v20160721' compile 'org.eclipse.jetty:jetty-io:9.3.11.v20160721'
compile 'org.eclipse.jetty:jetty-util:9.3.11.v20160721' compile 'org.eclipse.jetty:jetty-util:9.3.11.v20160721'
compile 'org.eclipse.jetty.websocket:websocket-api:9.3.12.v20160915' compile 'org.eclipse.jetty.websocket:websocket-api:9.3.12.v20160915'
compile 'org.eclipse.jetty.websocket:websocket-client:9.3.12.v20160915' compile 'org.eclipse.jetty.websocket:websocket-client:9.3.12.v20160915'
compile 'org.eclipse.jetty.websocket:websocket-common:9.3.12.v20160915' compile 'org.eclipse.jetty.websocket:websocket-common:9.3.12.v20160915'
compile 'org.slf4j:slf4j-simple:1.7.21' compile 'org.slf4j:slf4j-simple:1.7.21'
} }

View File

@@ -34,8 +34,8 @@ public class AuthFITBIT {
private static FileDataStoreFactory DATA_STORE_FACTORY; private static FileDataStoreFactory DATA_STORE_FACTORY;
/** OAuth 2 scope. */ /** OAuth 2 scope. */
private static final String SCOPE = "read"; private static final String SCOPE = "activity";
//private static final String SCOPE[] = new String[]{"activity","heartrate","location","sleep"};
/** Global instance of the HTTP transport. */ /** Global instance of the HTTP transport. */
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport(); private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
@@ -63,7 +63,8 @@ public class AuthFITBIT {
// authorize // authorize
LocalServerReceiver receiver = new LocalServerReceiver.Builder().setHost( LocalServerReceiver receiver = new LocalServerReceiver.Builder().setHost(
OAuth2ClientCredentials.DOMAIN).setPort(OAuth2ClientCredentials.PORT).build(); OAuth2ClientCredentials.DOMAIN).setPort(OAuth2ClientCredentials.PORT).build();
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user" );
} }
private static void run(HttpRequestFactory requestFactory) throws IOException { private static void run(HttpRequestFactory requestFactory) throws IOException {
@@ -74,19 +75,19 @@ public class AuthFITBIT {
UserData data = request.execute().parseAs(UserData.class); UserData data = request.execute().parseAs(UserData.class);
if (data.list.isEmpty()) { if (data.list.isEmpty()) {
System.out.println("Error in retrieve user data"); System.out.println("Error in retrieve user data");
} /*else { } else/* {
if (data.hasMore) { if (data.hasMore) {
System.out.print("First "); System.out.print("First ");
}*/ //i don't think is necessary }*/ //i don't think is necessary
/* System.out.println(data.list.size() + " favorite videos found:"); /* System.out.println(data.list.size() + " favorite videos found:");
for (Data datas: data.list) { */for (FITIBITData datas: data.list) {
System.out.println(); System.out.println(datas.toString());/*
System.out.println("-----------------------------------------------"); System.out.println("-----------------------------------------------");
System.out.println("ID: " + datas.id); System.out.println("ID: " + datas.id);
System.out.println("Title: " + datas.title); System.out.println("Title: " + datas.title);
System.out.println("Tags: " + datas.tags); System.out.println("Tags: " + datas.tags);
System.out.println("URL: " + datas.url); System.out.println("URL: " + datas.url);
} */ }/*
}*/ //neither this }*/ //neither this
} }

View File

@@ -1,22 +0,0 @@
package manage;
import com.google.api.client.util.Key;
import java.util.List;
//da modificare inserendo gli attributi del json (activity, heartrate, sleep, location)
public class Data {
@Key
public String id;
@Key
public List<String> tags;
@Key
public String title;
@Key
public String url;
}

View File

@@ -0,0 +1,21 @@
package manage;
import com.google.api.client.util.Key;
import java.util.List;
public class FITIBITData {
@Key
public String activity;
@Key
public String heartrate;
@Key
public String sleep;
@Key
public String location;
}

View File

@@ -3,16 +3,16 @@ package manage;
public class OAuth2ClientCredentials { public class OAuth2ClientCredentials {
/** Value of the "API Key". */ /** Value of the "API Key". */
public static final String API_KEY = "22CSTL"; public static final String API_KEY = "22CSTL"; //maybe togliere le virgolette
/** Value of the "API Secret". */ /** Value of the "API Secret". */
public static final String API_SECRET = "ea2452013abd35609940ce5601960a08"; public static final String API_SECRET = "ea2452013abd35609940ce5601960a08"; //maybe togliere le virgolette
/** Port in the "Callback URL". */ /** Port in the "Callback URL". */
public static final int PORT = 8080; public static final int PORT = 8080;
/** Domain name in the "Callback URL". */ /** Domain name in the "Callback URL". */
public static final String DOMAIN = "http://127.0.0.1:8080/"; public static final String DOMAIN = "127.0.0.1";
public static void errorIfNotSpecified() { public static void errorIfNotSpecified() {
if (API_KEY.startsWith("Enter ") || API_SECRET.startsWith("Enter ")) { if (API_KEY.startsWith("Enter ") || API_SECRET.startsWith("Enter ")) {

View File

@@ -7,7 +7,7 @@ import java.util.List;
public class UserData { public class UserData {
@Key @Key
public List<Data> list; public List<FITIBITData> list;
/* /*
@Key @Key
public int limit; public int limit;

View File

@@ -1,38 +1,30 @@
import device.Hue; import device.Hue;
import org.junit.Test; import org.junit.Test;
import java.util.HashSet;
import java.util.Set;
public class TestLights { public class TestLights {
@Test @Test
synchronized public void firstTestLights() throws InterruptedException { synchronized public void firstTestLights() throws InterruptedException {
//Hue lights = new Hue("http://localhost/api/newdeveloper/"); Hue lights = new Hue("http://localhost/api/newdeveloper/");
Hue lights = new Hue();
Set<String> toRemove = new HashSet<>();
for(String str: lights.getNameLights())
if(!str.equals("4"))
toRemove.add(str);
lights.removeLights(toRemove);
for(int i=0; i<10; i++) { for(int i=0; i<10; i++) {
lights.turnOn(); lights.turnOn();
this.wait(0b1111101000); // 1000 this.wait(0b11001000); // 200
lights.turnOff(); lights.turnOff();
this.wait(0b1111101000); // 1000 this.wait(0b11001000); // 200
} }
lights.turnOn(); lights.turnOn();
for(int i=0; i<256; i++) { for(int i=0; i<256; i++) {
lights.setBrightness(i); lights.setBrightness(i);
this.wait(2); this.wait(50);
}
for(int i=256; i>=0; i--) {
lights.setBrightness(i);
this.wait(50);
} }
lights.colorLoop();
this.wait(20);
lights.turnOff();
} }
} }