diff options
Diffstat (limited to 'java/client/src/Test.java')
| -rw-r--r-- | java/client/src/Test.java | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/java/client/src/Test.java b/java/client/src/Test.java new file mode 100644 index 0000000..7165b17 --- /dev/null +++ b/java/client/src/Test.java | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | import com.trouch.webiopi.client.PiClient; | ||
| 2 | import com.trouch.webiopi.client.PiCoapClient; | ||
| 3 | import com.trouch.webiopi.client.PiHttpClient; | ||
| 4 | import com.trouch.webiopi.client.PiMixedClient; | ||
| 5 | import com.trouch.webiopi.client.PiMulticastClient; | ||
| 6 | import com.trouch.webiopi.client.devices.analog.ADC; | ||
| 7 | import com.trouch.webiopi.client.devices.analog.DAC; | ||
| 8 | import com.trouch.webiopi.client.devices.analog.PWM; | ||
| 9 | import com.trouch.webiopi.client.devices.digital.GPIO; | ||
| 10 | import com.trouch.webiopi.client.devices.digital.NativeGPIO; | ||
| 11 | import com.trouch.webiopi.client.devices.sensor.Temperature; | ||
| 12 | |||
| 13 | public class Test { | ||
| 14 | |||
| 15 | public static void main(String[] args) { | ||
| 16 | String host = "192.168.1.234"; | ||
| 17 | PiClient client = new PiHttpClient(host, PiHttpClient.DEFAULT_PORT); | ||
| 18 | // PiClient client = new PiCoapClient(host, PiCoapClient.DEFAULT_PORT); | ||
| 19 | // PiClient client = new PiMixedClient(host, PiHttpClient.DEFAULT_PORT, PiCoapClient.DEFAULT_PORT); | ||
| 20 | // PiClient client = new PiMulticastClient(PiMulticastClient.DEFAULT_PORT); | ||
| 21 | |||
| 22 | client.setCredentials("webiopi", "raspberry"); | ||
| 23 | |||
| 24 | Temperature temp0 = new Temperature(client, "temp0"); | ||
| 25 | System.out.println(temp0.getCelsius() + "°C"); | ||
| 26 | |||
| 27 | NativeGPIO gpio = new NativeGPIO(client); | ||
| 28 | GPIO gpio0 = new GPIO(client, "gpio0"); | ||
| 29 | GPIO gpio2 = new GPIO(client, "gpio2"); | ||
| 30 | |||
| 31 | gpio.setFunction(25, GPIO.OUT); | ||
| 32 | gpio0.setFunction(0, GPIO.OUT); | ||
| 33 | gpio2.setFunction(12, GPIO.OUT); | ||
| 34 | |||
| 35 | DAC dac = new DAC(client, "dac1"); | ||
| 36 | ADC adc = new ADC(client, "adc0"); | ||
| 37 | PWM pwm = new PWM(client, "pwm0"); | ||
| 38 | |||
| 39 | boolean value = true; | ||
| 40 | for (int i = 0; i <= 100; i++) { | ||
| 41 | gpio.digitalWrite(25, value); | ||
| 42 | gpio0.digitalWrite(0, value); | ||
| 43 | gpio2.digitalWrite(12, value); | ||
| 44 | |||
| 45 | dac.writeFloat(0, (float) (i / 100.0)); | ||
| 46 | System.out.println("" + (adc.readFloat(1) * 3.3) + "V"); | ||
| 47 | pwm.writeAngle(7, i - 50); | ||
| 48 | value = !value; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | } | ||
