diff options
Diffstat (limited to 'java/client/src/com')
15 files changed, 601 insertions, 0 deletions
diff --git a/java/client/src/com/trouch/webiopi/client/PiClient.java b/java/client/src/com/trouch/webiopi/client/PiClient.java new file mode 100644 index 0000000..96a4f63 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiClient.java | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client; | ||
| 16 | |||
| 17 | import org.apache.commons.codec.binary.Base64; | ||
| 18 | |||
| 19 | public abstract class PiClient { | ||
| 20 | |||
| 21 | protected String urlBase; | ||
| 22 | protected String auth; | ||
| 23 | |||
| 24 | public static String encodeCredentials(String login, String password) { | ||
| 25 | return Base64.encodeBase64String((login + ":" + password).getBytes()); | ||
| 26 | } | ||
| 27 | |||
| 28 | public PiClient(String protocol, String host, int port) { | ||
| 29 | this.urlBase = protocol + "://" + host + ":" + port; | ||
| 30 | } | ||
| 31 | |||
| 32 | public void setCredentials(String login, String password) { | ||
| 33 | this.auth = "Basic " + encodeCredentials(login, password); | ||
| 34 | } | ||
| 35 | |||
| 36 | public abstract String sendRequest(String method, String path) throws Exception; | ||
| 37 | |||
| 38 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/PiCoapClient.java b/java/client/src/com/trouch/webiopi/client/PiCoapClient.java new file mode 100644 index 0000000..4a4f2d3 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiCoapClient.java | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client; | ||
| 16 | |||
| 17 | import com.trouch.coap.client.CoapClient; | ||
| 18 | import com.trouch.coap.messages.CoapRequest; | ||
| 19 | import com.trouch.coap.messages.CoapResponse; | ||
| 20 | import com.trouch.coap.methods.CoapGet; | ||
| 21 | import com.trouch.coap.methods.CoapPost; | ||
| 22 | |||
| 23 | |||
| 24 | public class PiCoapClient extends PiClient { | ||
| 25 | public final static int DEFAULT_PORT = 5683; | ||
| 26 | private CoapClient client; | ||
| 27 | |||
| 28 | public PiCoapClient(String host) { | ||
| 29 | super("coap", host, DEFAULT_PORT); | ||
| 30 | client = new CoapClient(); | ||
| 31 | } | ||
| 32 | |||
| 33 | public PiCoapClient(String host, int port) { | ||
| 34 | super("coap", host, port); | ||
| 35 | client = new CoapClient(); | ||
| 36 | } | ||
| 37 | |||
| 38 | @Override | ||
| 39 | public String sendRequest(String method, String path) throws Exception { | ||
| 40 | CoapRequest request; | ||
| 41 | if (method == "GET") { | ||
| 42 | request = new CoapGet(this.urlBase + path); | ||
| 43 | } | ||
| 44 | else if (method == "POST") { | ||
| 45 | request = new CoapPost(this.urlBase + path); | ||
| 46 | } | ||
| 47 | else throw new Exception("Method not supported: " + method); | ||
| 48 | |||
| 49 | CoapResponse response = client.sendRequest(request); | ||
| 50 | if (response != null) { | ||
| 51 | return response.getPayload(); | ||
| 52 | } | ||
| 53 | |||
| 54 | return null; | ||
| 55 | } | ||
| 56 | |||
| 57 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/PiHttpClient.java b/java/client/src/com/trouch/webiopi/client/PiHttpClient.java new file mode 100644 index 0000000..6562bc7 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiHttpClient.java | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client; | ||
| 16 | |||
| 17 | import java.io.BufferedReader; | ||
| 18 | import java.io.IOException; | ||
| 19 | import java.io.InputStreamReader; | ||
| 20 | import java.net.HttpURLConnection; | ||
| 21 | import java.net.URL; | ||
| 22 | |||
| 23 | public class PiHttpClient extends PiClient { | ||
| 24 | public final static int DEFAULT_PORT = 8000; | ||
| 25 | |||
| 26 | public PiHttpClient(String host) { | ||
| 27 | super("http", host, DEFAULT_PORT); | ||
| 28 | } | ||
| 29 | |||
| 30 | public PiHttpClient(String host, int port) { | ||
| 31 | super("http", host, port); | ||
| 32 | } | ||
| 33 | |||
| 34 | @Override | ||
| 35 | public String sendRequest(String method, String path) throws Exception { | ||
| 36 | BufferedReader reader = null; | ||
| 37 | try { | ||
| 38 | URL url = new URL(this.urlBase + path); | ||
| 39 | HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
| 40 | connection.setRequestMethod(method); | ||
| 41 | if (this.auth != null) { | ||
| 42 | connection.setRequestProperty("Authorization", this.auth); | ||
| 43 | } | ||
| 44 | |||
| 45 | // read the output from the server | ||
| 46 | reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); | ||
| 47 | StringBuilder stringBuilder = new StringBuilder(); | ||
| 48 | |||
| 49 | String line = null; | ||
| 50 | while ((line = reader.readLine()) != null) { | ||
| 51 | stringBuilder.append(line).append('\n'); | ||
| 52 | } | ||
| 53 | return stringBuilder.toString(); | ||
| 54 | } catch (Exception e) { | ||
| 55 | e.printStackTrace(); | ||
| 56 | throw e; | ||
| 57 | } finally { | ||
| 58 | if (reader != null) { | ||
| 59 | try { | ||
| 60 | reader.close(); | ||
| 61 | } catch (IOException ioe) { | ||
| 62 | ioe.printStackTrace(); | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/PiMixedClient.java b/java/client/src/com/trouch/webiopi/client/PiMixedClient.java new file mode 100644 index 0000000..8922f6f --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiMixedClient.java | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client; | ||
| 16 | |||
| 17 | public class PiMixedClient extends PiClient { | ||
| 18 | private PiHttpClient http; | ||
| 19 | private PiCoapClient coap; | ||
| 20 | |||
| 21 | private int tries = 0; | ||
| 22 | private int maxTries = 3; | ||
| 23 | |||
| 24 | public PiMixedClient(String host) { | ||
| 25 | super("", "", 0); | ||
| 26 | http = new PiHttpClient(host); | ||
| 27 | coap = new PiCoapClient(host); | ||
| 28 | } | ||
| 29 | |||
| 30 | public PiMixedClient(String host, int httpPort, int coapPort) { | ||
| 31 | super("", "", 0); | ||
| 32 | http = new PiHttpClient(host, httpPort); | ||
| 33 | coap = new PiCoapClient(host, coapPort); | ||
| 34 | } | ||
| 35 | |||
| 36 | @Override | ||
| 37 | public void setCredentials(String login, String password) { | ||
| 38 | http.setCredentials(login, password); | ||
| 39 | coap.setCredentials(login, password); | ||
| 40 | } | ||
| 41 | |||
| 42 | @Override | ||
| 43 | public String sendRequest(String method, String path) throws Exception { | ||
| 44 | if (tries < maxTries) { | ||
| 45 | String response = coap.sendRequest(method, path); | ||
| 46 | if (response != null) { | ||
| 47 | tries = 0; | ||
| 48 | return response; | ||
| 49 | } | ||
| 50 | tries++; | ||
| 51 | } | ||
| 52 | |||
| 53 | return http.sendRequest(method, path); | ||
| 54 | } | ||
| 55 | |||
| 56 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/PiMulticastClient.java b/java/client/src/com/trouch/webiopi/client/PiMulticastClient.java new file mode 100644 index 0000000..22b1d9e --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/PiMulticastClient.java | |||
| @@ -0,0 +1,27 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client; | ||
| 16 | |||
| 17 | public class PiMulticastClient extends PiCoapClient { | ||
| 18 | |||
| 19 | public PiMulticastClient() { | ||
| 20 | super("224.0.1.123", PiMulticastClient.DEFAULT_PORT); | ||
| 21 | } | ||
| 22 | |||
| 23 | public PiMulticastClient(int port) { | ||
| 24 | super("224.0.1.123", port); | ||
| 25 | } | ||
| 26 | |||
| 27 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/Device.java b/java/client/src/com/trouch/webiopi/client/devices/Device.java new file mode 100644 index 0000000..b12139d --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/Device.java | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | |||
| 19 | public class Device { | ||
| 20 | |||
| 21 | private PiClient client; | ||
| 22 | protected String path; | ||
| 23 | |||
| 24 | public Device(PiClient client, String deviceName, String type) { | ||
| 25 | this.client = client; | ||
| 26 | if (type != null) { | ||
| 27 | this.path = "/devices/" + deviceName + "/" + type; | ||
| 28 | } | ||
| 29 | else { | ||
| 30 | this.path = "/devices/" + deviceName; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | public String sendRequest(String method, String subPath) { | ||
| 35 | try { | ||
| 36 | return this.client.sendRequest(method, this.path + subPath); | ||
| 37 | } catch (Exception e) { | ||
| 38 | // TODO Auto-generated catch block | ||
| 39 | e.printStackTrace(); | ||
| 40 | return null; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/analog/ADC.java b/java/client/src/com/trouch/webiopi/client/devices/analog/ADC.java new file mode 100644 index 0000000..f8c349e --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/analog/ADC.java | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.analog; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | import com.trouch.webiopi.client.devices.Device; | ||
| 19 | |||
| 20 | public class ADC extends Device { | ||
| 21 | |||
| 22 | public ADC(PiClient client, String deviceName) { | ||
| 23 | super(client, deviceName, "analog"); | ||
| 24 | } | ||
| 25 | |||
| 26 | public ADC(PiClient client, String deviceName, String type) { | ||
| 27 | super(client, deviceName, type); | ||
| 28 | } | ||
| 29 | |||
| 30 | public float readFloat(int channel) { | ||
| 31 | return Float.parseFloat(this.sendRequest("GET", "/" + channel + "/float")); | ||
| 32 | } | ||
| 33 | |||
| 34 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/analog/DAC.java b/java/client/src/com/trouch/webiopi/client/devices/analog/DAC.java new file mode 100644 index 0000000..901d9c4 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/analog/DAC.java | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.analog; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | |||
| 19 | public class DAC extends ADC { | ||
| 20 | |||
| 21 | public DAC(PiClient client, String deviceName) { | ||
| 22 | super(client, deviceName); | ||
| 23 | } | ||
| 24 | |||
| 25 | public DAC(PiClient client, String deviceName, String type) { | ||
| 26 | super(client, deviceName, type); | ||
| 27 | } | ||
| 28 | |||
| 29 | public float writeFloat(int channel, float value) { | ||
| 30 | return Float.parseFloat(this.sendRequest("POST", "/" + channel + "/float/" + value)); | ||
| 31 | } | ||
| 32 | |||
| 33 | public float writeVolt(int channel, float value) { | ||
| 34 | return Float.parseFloat(this.sendRequest("POST", "/" + channel + "/volt/" + value)); | ||
| 35 | } | ||
| 36 | |||
| 37 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/analog/PWM.java b/java/client/src/com/trouch/webiopi/client/devices/analog/PWM.java new file mode 100644 index 0000000..fdc4674 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/analog/PWM.java | |||
| @@ -0,0 +1,33 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.analog; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | |||
| 19 | public class PWM extends DAC { | ||
| 20 | |||
| 21 | public PWM(PiClient client, String deviceName) { | ||
| 22 | super(client, deviceName, "pwm"); | ||
| 23 | } | ||
| 24 | |||
| 25 | public float readAngle(int channel) { | ||
| 26 | return Float.parseFloat(this.sendRequest("GET", "/" + channel + "/angle")); | ||
| 27 | } | ||
| 28 | |||
| 29 | public float writeAngle(int channel, float angle) { | ||
| 30 | return Float.parseFloat(this.sendRequest("POST", "/" + channel + "/angle/" + angle)); | ||
| 31 | } | ||
| 32 | |||
| 33 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/digital/GPIO.java b/java/client/src/com/trouch/webiopi/client/devices/digital/GPIO.java new file mode 100644 index 0000000..c08dff5 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/digital/GPIO.java | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.digital; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | import com.trouch.webiopi.client.devices.Device; | ||
| 19 | |||
| 20 | public class GPIO extends Device { | ||
| 21 | |||
| 22 | public final static String OUT = "OUT"; | ||
| 23 | public final static String IN = "IN"; | ||
| 24 | |||
| 25 | public GPIO(PiClient client, String deviceName) { | ||
| 26 | super(client, deviceName, null); | ||
| 27 | } | ||
| 28 | |||
| 29 | public String getFunction(int channel) { | ||
| 30 | return this.sendRequest("GET", "/" + channel + "/function"); | ||
| 31 | } | ||
| 32 | |||
| 33 | public String setFunction(int channel, String function) { | ||
| 34 | return this.sendRequest("POST", "/" + channel + "/function/" + function); | ||
| 35 | } | ||
| 36 | |||
| 37 | public boolean digitalRead(int channel) { | ||
| 38 | String res = this.sendRequest("GET", "/" + channel + "/value"); | ||
| 39 | if (res.equals("1")) { | ||
| 40 | return true; | ||
| 41 | } | ||
| 42 | return false; | ||
| 43 | } | ||
| 44 | |||
| 45 | public boolean digitalWrite(int channel, boolean value) { | ||
| 46 | String res = this.sendRequest("POST", "/" + channel + "/value/" + (value ? "1" : "0")); | ||
| 47 | if (res.equals("1")) { | ||
| 48 | return true; | ||
| 49 | } | ||
| 50 | return false; | ||
| 51 | } | ||
| 52 | |||
| 53 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/digital/NativeGPIO.java b/java/client/src/com/trouch/webiopi/client/devices/digital/NativeGPIO.java new file mode 100644 index 0000000..a5bc05b --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/digital/NativeGPIO.java | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.digital; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | |||
| 19 | public class NativeGPIO extends GPIO { | ||
| 20 | |||
| 21 | public NativeGPIO(PiClient client) { | ||
| 22 | super(client, ""); | ||
| 23 | this.path = "/GPIO"; | ||
| 24 | } | ||
| 25 | |||
| 26 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/sensor/Distance.java b/java/client/src/com/trouch/webiopi/client/devices/sensor/Distance.java new file mode 100644 index 0000000..63ac485 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/sensor/Distance.java | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.sensor; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | import com.trouch.webiopi.client.devices.Device; | ||
| 19 | |||
| 20 | public class Distance extends Device { | ||
| 21 | |||
| 22 | public Distance(PiClient client, String deviceName) { | ||
| 23 | super(client, deviceName, "sensor"); | ||
| 24 | } | ||
| 25 | |||
| 26 | public float getMillimeter() { | ||
| 27 | return Float.parseFloat(this.sendRequest("GET", "/distance/mm")); | ||
| 28 | } | ||
| 29 | |||
| 30 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/sensor/Luminosity.java b/java/client/src/com/trouch/webiopi/client/devices/sensor/Luminosity.java new file mode 100644 index 0000000..29eda32 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/sensor/Luminosity.java | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.sensor; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | import com.trouch.webiopi.client.devices.Device; | ||
| 19 | |||
| 20 | public class Luminosity extends Device { | ||
| 21 | |||
| 22 | public Luminosity(PiClient client, String deviceName) { | ||
| 23 | super(client, deviceName, "sensor"); | ||
| 24 | } | ||
| 25 | |||
| 26 | public float getLux() { | ||
| 27 | return Float.parseFloat(this.sendRequest("GET", "/luminosity/lx")); | ||
| 28 | } | ||
| 29 | |||
| 30 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/sensor/Pressure.java b/java/client/src/com/trouch/webiopi/client/devices/sensor/Pressure.java new file mode 100644 index 0000000..1f766a9 --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/sensor/Pressure.java | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.sensor; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | import com.trouch.webiopi.client.devices.Device; | ||
| 19 | |||
| 20 | public class Pressure extends Device { | ||
| 21 | |||
| 22 | public Pressure(PiClient client, String deviceName) { | ||
| 23 | super(client, deviceName, "sensor"); | ||
| 24 | } | ||
| 25 | |||
| 26 | public float getHectoPascal() { | ||
| 27 | return Float.parseFloat(this.sendRequest("GET", "/pressure/hpa")); | ||
| 28 | } | ||
| 29 | |||
| 30 | public float getPascal() { | ||
| 31 | return Float.parseFloat(this.sendRequest("GET", "/pressure/pa")); | ||
| 32 | } | ||
| 33 | |||
| 34 | } | ||
diff --git a/java/client/src/com/trouch/webiopi/client/devices/sensor/Temperature.java b/java/client/src/com/trouch/webiopi/client/devices/sensor/Temperature.java new file mode 100644 index 0000000..160e32f --- /dev/null +++ b/java/client/src/com/trouch/webiopi/client/devices/sensor/Temperature.java | |||
| @@ -0,0 +1,34 @@ | |||
| 1 | /* Copyright 2013 Eric Ptak - trouch.com | ||
| 2 | * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 3 | * you may not use this file except in compliance with the License. | ||
| 4 | * You may obtain a copy of the License at | ||
| 5 | * | ||
| 6 | * http://www.apache.org/licenses/LICENSE-2.0 | ||
| 7 | * | ||
| 8 | * Unless required by applicable law or agreed to in writing, software | ||
| 9 | * distributed under the License is distributed on an "AS IS" BASIS, | ||
| 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 11 | * See the License for the specific language governing permissions and | ||
| 12 | * limitations under the License. | ||
| 13 | */ | ||
| 14 | |||
| 15 | package com.trouch.webiopi.client.devices.sensor; | ||
| 16 | |||
| 17 | import com.trouch.webiopi.client.PiClient; | ||
| 18 | import com.trouch.webiopi.client.devices.Device; | ||
| 19 | |||
| 20 | public class Temperature extends Device { | ||
| 21 | |||
| 22 | public Temperature(PiClient client, String deviceName) { | ||
| 23 | super(client, deviceName, "sensor"); | ||
| 24 | } | ||
| 25 | |||
| 26 | public float getCelsius() { | ||
| 27 | return Float.parseFloat(this.sendRequest("GET", "/temperature/c")); | ||
| 28 | } | ||
| 29 | |||
| 30 | public float getFahrenheit() { | ||
| 31 | return Float.parseFloat(this.sendRequest("GET", "/temperature/f")); | ||
| 32 | } | ||
| 33 | |||
| 34 | } | ||
