Yet Another WebIOPi+
 All Classes Namespaces Files Functions Variables Macros Pages
GPIO.java
Go to the documentation of this file.
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 
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 }
String sendRequest(String method, String subPath)
Definition: Device.java:34
String setFunction(int channel, String function)
Definition: GPIO.java:33
boolean digitalWrite(int channel, boolean value)
Definition: GPIO.java:45
GPIO(PiClient client, String deviceName)
Definition: GPIO.java:25