-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
942 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="src" path="resources"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>AVR-Remote</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
encoding/<project>=UTF-8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
eclipse.preferences.version=1 | ||
line.separator=\r\n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
package de.marcovogt.avrremote; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Properties; | ||
|
||
public class Config { | ||
|
||
private static String avr = ""; | ||
private static int maximumVolume = 80; | ||
private static String favoriteSource = "AUX2"; | ||
private static String favoriteSourceLabel = "PC"; | ||
|
||
private static final String CONFIG_FILE_PATH = System.getProperty("user.home") + File.separator + "avr-remote.properties"; | ||
|
||
public static String getAVR() { | ||
return avr; | ||
} | ||
|
||
public static void setAVR(String pAVR) { | ||
avr = pAVR; | ||
writeConfigFile(); | ||
} | ||
|
||
|
||
public static int getMaximumVolume() { | ||
return maximumVolume; | ||
} | ||
|
||
public static void setMaximumVolume(int pMaximumVolume) { | ||
maximumVolume = pMaximumVolume; | ||
writeConfigFile(); | ||
} | ||
|
||
|
||
public static String getFavoriteSource() { | ||
return favoriteSource; | ||
} | ||
|
||
public static void setFavoriteSource(String pFavoriteSource) { | ||
favoriteSource = pFavoriteSource; | ||
writeConfigFile(); | ||
} | ||
|
||
|
||
public static String getFavoriteSourceLabel() { | ||
return favoriteSourceLabel; | ||
} | ||
|
||
public static void setFavoriteSourceLabel(String pFavoriteSourceLabel) { | ||
favoriteSourceLabel = pFavoriteSourceLabel; | ||
writeConfigFile(); | ||
} | ||
|
||
|
||
private static void writeConfigFile() { | ||
Properties prop = new Properties(); | ||
OutputStream output = null; | ||
|
||
try { | ||
output = new FileOutputStream(CONFIG_FILE_PATH); | ||
|
||
// set the properties value | ||
prop.setProperty("avr", avr); | ||
prop.setProperty("maximumVolume", maximumVolume + ""); | ||
prop.setProperty("favoriteSource", favoriteSource); | ||
prop.setProperty("favoriteSourceLabel", favoriteSourceLabel); | ||
|
||
// save properties to project root folder | ||
prop.store(output, null); | ||
|
||
} catch (IOException io) { | ||
io.printStackTrace(); | ||
} finally { | ||
if (output != null) { | ||
try { | ||
output.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
public static void readConfigFile() { | ||
Properties prop = new Properties(); | ||
InputStream input = null; | ||
|
||
try { | ||
File f = new File(CONFIG_FILE_PATH); | ||
if(f.exists()) { | ||
input = new FileInputStream(f); | ||
|
||
// load a properties file | ||
prop.load(input); | ||
|
||
// get the property values | ||
avr = prop.getProperty("avr"); | ||
maximumVolume = Integer.parseInt(prop.getProperty("maximumVolume")); | ||
favoriteSource = prop.getProperty("favoriteSource"); | ||
favoriteSourceLabel = prop.getProperty("favoriteSourceLabel"); | ||
} | ||
} catch (IOException ex) { | ||
ex.printStackTrace(); | ||
} finally { | ||
if (input != null) { | ||
try { | ||
input.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
package de.marcovogt.avrremote; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
|
||
import javax.xml.parsers.DocumentBuilder; | ||
import javax.xml.parsers.DocumentBuilderFactory; | ||
import javax.xml.parsers.ParserConfigurationException; | ||
|
||
import org.w3c.dom.Document; | ||
import org.w3c.dom.Element; | ||
import org.w3c.dom.Node; | ||
import org.w3c.dom.NodeList; | ||
import org.xml.sax.SAXException; | ||
|
||
public class Controller { | ||
|
||
public static boolean isConnected() { | ||
try { | ||
new URL("http://" + Config.getAVR() + "/goform/formMainZone_MainZoneXmlStatus.xml").openStream(); | ||
return true; | ||
} catch(Exception e) { | ||
return false; | ||
} | ||
} | ||
|
||
public static void setVolume(int vol) { | ||
sendRequest("http://" + Config.getAVR() + "/goform/formiPhoneAppDirect.xml?MV" + vol); | ||
} | ||
|
||
public static void volumeUp() { | ||
sendRequest("http://" + Config.getAVR() + "/goform/formiPhoneAppDirect.xml?MVUP"); | ||
} | ||
|
||
public static void volumeDown() { | ||
sendRequest("http://" + Config.getAVR() + "/goform/formiPhoneAppDirect.xml?MVDOWN"); | ||
} | ||
|
||
public static void setMute(boolean state) { | ||
if(state) { | ||
sendRequest("http://" + Config.getAVR() + "/goform/formiPhoneAppMute.xml?1+MuteOn"); | ||
} else { | ||
sendRequest("http://" + Config.getAVR() + "/goform/formiPhoneAppMute.xml?1+MuteOff"); | ||
} | ||
} | ||
|
||
public static void setPower(boolean state) { | ||
if(state) { | ||
sendRequest("http://" + Config.getAVR() + "/goform/formiPhoneAppPower.xml?1+PowerOn"); | ||
} else { | ||
sendRequest("http://" + Config.getAVR() + "/goform/formiPhoneAppPower.xml?1+PowerStandby"); | ||
} | ||
} | ||
|
||
public static void setFavoriteSource() { | ||
sendRequest("http://" + Config.getAVR() + "/goform/formiPhoneAppDirect.xml?SI" + Config.getFavoriteSource()); | ||
} | ||
|
||
public static ArrayList<Input> getInputList() { | ||
Document res = parseRequest("http://" + Config.getAVR() + "/goform/formMainZone_MainZoneXmlStatus.xml"); | ||
Element docEle = res.getDocumentElement(); | ||
|
||
ArrayList<Input> inputList = new ArrayList<Input>(); | ||
|
||
NodeList inputs = docEle.getElementsByTagName("InputFuncList").item(0).getChildNodes(); | ||
if (inputs != null && inputs.getLength() > 0) { | ||
for (int i = 0; i < inputs.getLength(); i++) { | ||
if (inputs.item(i).getNodeType() == Node.ELEMENT_NODE) { | ||
Element input = (Element) inputs.item(i); | ||
Input in = new Input(); | ||
in.name = input.getFirstChild().getNodeValue(); | ||
inputList.add(in); | ||
} | ||
} | ||
} | ||
|
||
inputs = docEle.getElementsByTagName("RenameSource").item(0).getChildNodes(); | ||
if (inputs != null && inputs.getLength() > 0) { | ||
for (int i = 0; i < inputs.getLength(); i++) { | ||
if (inputs.item(i).getNodeType() == Node.ELEMENT_NODE) { | ||
Element input = (Element) inputs.item(i).getFirstChild(); | ||
Input in = inputList.get(i/2); | ||
in.customName = input.getFirstChild().getNodeValue(); | ||
} | ||
} | ||
} | ||
|
||
return inputList; | ||
} | ||
|
||
public static class Input { | ||
public String name; | ||
public String customName; | ||
|
||
@Override | ||
public String toString() { | ||
return customName; | ||
} | ||
} | ||
|
||
public static String getSelectedInput() { | ||
Document res = parseRequest("http://" + Config.getAVR() + "/goform/formMainZone_MainZoneXmlStatus.xml"); | ||
Element docEle = res.getDocumentElement(); | ||
return docEle.getElementsByTagName("InputFuncSelect").item(0).getFirstChild().getFirstChild().getNodeValue(); | ||
} | ||
|
||
public static Status getStatus() { | ||
Document res = parseRequest("http://" + Config.getAVR() + "/goform/formMainZone_MainZoneXmlStatus.xml"); | ||
Element docEle = res.getDocumentElement(); | ||
|
||
Status status = new Status(); | ||
|
||
// Power | ||
if(docEle.getElementsByTagName("Power").item(0).getFirstChild().getFirstChild().getNodeValue().equals("ON")) { | ||
status.power = true; | ||
} else { | ||
status.power = false; | ||
} | ||
|
||
// Mute | ||
if(docEle.getElementsByTagName("Mute").item(0).getFirstChild().getFirstChild().getNodeValue().equals("on")) { | ||
status.mute = true; | ||
} else { | ||
status.mute = false; | ||
} | ||
|
||
// Favorite Source | ||
if(docEle.getElementsByTagName("InputFuncSelect").item(0).getFirstChild().getFirstChild().getNodeValue().equals(Config.getFavoriteSource())) { | ||
status.favoriteSourceSelected = true; | ||
} else { | ||
status.favoriteSourceSelected = false; | ||
} | ||
|
||
// Volume | ||
String str = docEle.getElementsByTagName("MasterVolume").item(0).getFirstChild().getFirstChild().getNodeValue(); | ||
Integer val; | ||
if(str.equals("--")) { | ||
val = 80; | ||
} else { | ||
val = (int) Double.parseDouble(str); | ||
} | ||
status.volume = 80-Math.abs(val); | ||
|
||
return status; | ||
} | ||
|
||
public static Document parseRequest(String urlStr) { | ||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); | ||
|
||
try ( | ||
InputStream res = new URL(urlStr).openStream() | ||
) { | ||
//Using factory get an instance of document builder | ||
DocumentBuilder db = dbf.newDocumentBuilder(); | ||
|
||
//parse using builder to get DOM representation of the XML file | ||
Document dom = db.parse(res); | ||
|
||
return dom; | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} catch (ParserConfigurationException e) { | ||
e.printStackTrace(); | ||
} catch (SAXException e) { | ||
e.printStackTrace(); | ||
} | ||
return null; | ||
} | ||
|
||
public static void sendRequest(String urlStr) { | ||
try ( | ||
InputStream res = new URL(urlStr).openStream() | ||
) { | ||
// send request | ||
} catch (MalformedURLException e) { | ||
e.printStackTrace(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
|
||
public static class Status { | ||
public boolean power; | ||
public boolean mute; | ||
public boolean favoriteSourceSelected; | ||
public int volume; | ||
} | ||
|
||
} |
Oops, something went wrong.