Permalink
Browse files

added experimental OrangePi examples (untested)

  • Loading branch information...
1 parent 6654b20 commit 80f3b6447d6996c9f7ab2b6b56f619b2fdf14eed @savageautomate savageautomate committed Dec 6, 2016
@@ -5,7 +5,7 @@
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: Java Library (Core)
- * FILENAME : I2CFactoryProviderBananaPi.java
+ * FILENAME : I2CFactoryProviderOrangePi.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: http://www.pi4j.com/
@@ -5,7 +5,7 @@
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: Java Library (Core)
- * FILENAME : BananaProSerial.java
+ * FILENAME : OrangePiSerial.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: http://www.pi4j.com/
@@ -5,7 +5,7 @@
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: Java Library (Core)
- * FILENAME : BananaProSystemInfoProvider.java
+ * FILENAME : OrangePiSystemInfoProvider.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: http://www.pi4j.com/
@@ -0,0 +1,129 @@
+package orangepi.bananapro;
+/*
+ * #%L
+ * **********************************************************************
+ * ORGANIZATION : Pi4J
+ * PROJECT : Pi4J :: Java Examples
+ * FILENAME : GpioInputAllExample.java
+ *
+ * This file is part of the Pi4J project. More information about
+ * this project can be found here: http://www.pi4j.com/
+ * **********************************************************************
+ * %%
+ * Copyright (C) 2012 - 2016 Pi4J
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import com.pi4j.io.gpio.*;
+import com.pi4j.platform.Platform;
+import com.pi4j.platform.PlatformAlreadyAssignedException;
+import com.pi4j.platform.PlatformManager;
+import com.pi4j.util.CommandArgumentParser;
+import com.pi4j.util.Console;
+import com.pi4j.util.ConsoleColor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * This example code demonstrates how to perform simple GPIO
+ * pin state reading on the OrangePi platform fro all pins.
+ *
+ * @author Robert Savage
+ */
+public class GpioInputAllExample {
+
+ /**
+ * [ARGUMENT/OPTION "--pull (up|down|off)" | "-l (up|down|off)" | "--up" | "--down" ]
+ * This example program accepts an optional argument for specifying pin pull resistance.
+ * Supported values: "up|down" (or simply "1|0"). If no value is specified in the command
+ * argument, then the pin pull resistance will be set to PULL_UP by default.
+ * -- EXAMPLES: "--pull up", "-pull down", "--pull off", "--up", "--down", "-pull 0", "--pull 1", "-l up", "-l down".
+ *
+ * @param args
+ * @throws InterruptedException
+ * @throws PlatformAlreadyAssignedException
+ */
+ public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException {
+
+ // ####################################################################
+ //
+ // since we are not using the default Raspberry Pi platform, we should
+ // explicitly assign the platform as the OrangePi platform.
+ //
+ // ####################################################################
+ PlatformManager.setPlatform(Platform.ORANGEPI);
+
+ // create Pi4J console wrapper/helper
+ // (This is a utility class to abstract some of the boilerplate code)
+ final Console console = new Console();
+
+ // print program title/header
+ console.title("<-- The Pi4J Project -->", "GPIO Input (ALL PINS) Example");
+
+ // allow for user to exit program using CTRL-C
+ console.promptForExit();
+
+ // create gpio controller
+ final GpioController gpio = GpioFactory.getInstance();
+
+ // by default we will use gpio pin PULL-UP; however, if an argument
+ // has been provided, then use the specified pull resistance
+ PinPullResistance pull = CommandArgumentParser.getPinPullResistance(
+ PinPullResistance.PULL_UP, // default pin pull resistance if no pull argument found
+ args); // argument array to search in
+
+ // ####################################################################
+ //
+ // When provisioning a pin, use the OrangePiPin class.
+ //
+ // ####################################################################
+
+ List<GpioPinDigitalInput> provisionedPins = new ArrayList<>();
+
+ // provision GPIO input pins
+ for (Pin pin : OrangePiPin.allPins()) {
+ try {
+ GpioPinDigitalInput provisionedPin = gpio.provisionDigitalInputPin(pin, pull);
+ provisionedPin.setShutdownOptions(true); // unexport pin on program shutdown
+ provisionedPins.add(provisionedPin); // add provisioned pin to collection
+ }
+ catch (Exception ex){
+ System.err.println(ex.getMessage());
+ }
+ }
+
+ // prompt user that we are ready
+ console.println(" ... Successfully provisioned all GPIO input pins");
+ console.emptyLine();
+ console.box("The GPIO input pins states will be displayed below.");
+ console.emptyLine();
+
+ // display pin states for all pins
+ for(GpioPinDigitalInput input : provisionedPins) {
+ console.println(" [" + input.toString() + "] digital state is: " + ConsoleColor.conditional(
+ input.getState().isHigh(), // conditional expression
+ ConsoleColor.GREEN, // positive conditional color
+ ConsoleColor.RED, // negative conditional color
+ input.getState()));
+ }
+
+ // stop all GPIO activity/threads by shutting down the GPIO controller
+ // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
+ gpio.shutdown();
+ }
+}
@@ -0,0 +1,130 @@
+package orangepi.bananapro;
+/*
+ * #%L
+ * **********************************************************************
+ * ORGANIZATION : Pi4J
+ * PROJECT : Pi4J :: Java Examples
+ * FILENAME : GpioInputExample.java
+ *
+ * This file is part of the Pi4J project. More information about
+ * this project can be found here: http://www.pi4j.com/
+ * **********************************************************************
+ * %%
+ * Copyright (C) 2012 - 2016 Pi4J
+ * %%
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Lesser Public License for more details.
+ *
+ * You should have received a copy of the GNU General Lesser Public
+ * License along with this program. If not, see
+ * <http://www.gnu.org/licenses/lgpl-3.0.html>.
+ * #L%
+ */
+
+import com.pi4j.io.gpio.*;
+import com.pi4j.platform.Platform;
+import com.pi4j.platform.PlatformAlreadyAssignedException;
+import com.pi4j.platform.PlatformManager;
+import com.pi4j.util.CommandArgumentParser;
+import com.pi4j.util.Console;
+import com.pi4j.util.ConsoleColor;
+
+/**
+ * This example code demonstrates how to perform simple GPIO
+ * pin state reading on the OrangePi platform.
+ *
+ * @author Robert Savage
+ */
+public class GpioInputExample {
+
+ /**
+ * [ARGUMENT/OPTION "--pin (#)" | "-p (#)" ]
+ * This example program accepts an optional argument for specifying the GPIO pin (by number)
+ * to use with this GPIO listener example. If no argument is provided, then GPIO #1 will be used.
+ * -- EXAMPLE: "--pin 4" or "-p 0".
+ *
+ * [ARGUMENT/OPTION "--pull (up|down|off)" | "-l (up|down|off)" | "--up" | "--down" ]
+ * This example program accepts an optional argument for specifying pin pull resistance.
+ * Supported values: "up|down" (or simply "1|0"). If no value is specified in the command
+ * argument, then the pin pull resistance will be set to PULL_UP by default.
+ * -- EXAMPLES: "--pull up", "-pull down", "--pull off", "--up", "--down", "-pull 0", "--pull 1", "-l up", "-l down".
+ *
+ * @param args
+ * @throws InterruptedException
+ * @throws PlatformAlreadyAssignedException
+ */
+ public static void main(String[] args) throws InterruptedException, PlatformAlreadyAssignedException {
+
+ // ####################################################################
+ //
+ // since we are not using the default Raspberry Pi platform, we should
+ // explicitly assign the platform as the OrangePi platform.
+ //
+ // ####################################################################
+ PlatformManager.setPlatform(Platform.ORANGEPI);
+
+ // create Pi4J console wrapper/helper
+ // (This is a utility class to abstract some of the boilerplate code)
+ final Console console = new Console();
+
+ // print program title/header
+ console.title("<-- The Pi4J Project -->", "GPIO Input Example");
+
+ // allow for user to exit program using CTRL-C
+ console.promptForExit();
+
+ // create gpio controller
+ final GpioController gpio = GpioFactory.getInstance();
+
+ // ####################################################################
+ //
+ // When provisioning a pin, use the OrangePiPin class.
+ //
+ // ####################################################################
+
+ // by default we will use gpio pin #01; however, if an argument
+ // has been provided, then lookup the pin by address
+ Pin pin = CommandArgumentParser.getPin(
+ OrangePiPin.class, // pin provider class to obtain pin instance from
+ OrangePiPin.GPIO_01, // default pin if no pin argument found
+ args); // argument array to search in
+
+ // by default we will use gpio pin PULL-UP; however, if an argument
+ // has been provided, then use the specified pull resistance
+ PinPullResistance pull = CommandArgumentParser.getPinPullResistance(
+ PinPullResistance.PULL_UP, // default pin pull resistance if no pull argument found
+ args); // argument array to search in
+
+ // provision gpio pin as an input pin
+ final GpioPinDigitalInput input = gpio.provisionDigitalInputPin(pin, "MyInput", pull);
+
+ // set shutdown state for this pin: unexport the pin
+ input.setShutdownOptions(true);
+
+ // prompt user that we are ready
+ console.println("Successfully provisioned [" + pin + "] with PULL resistance = [" + pull + "]");
+ console.emptyLine();
+ console.box("The GPIO input pin states will be displayed below.");
+ console.emptyLine();
+
+ // display pin state
+ console.emptyLine();
+ console.println(" [" + input.toString() + "] digital state is: " + ConsoleColor.conditional(
+ input.getState().isHigh(), // conditional expression
+ ConsoleColor.GREEN, // positive conditional color
+ ConsoleColor.RED, // negative conditional color
+ input.getState()));
+ console.emptyLine();
+
+ // stop all GPIO activity/threads by shutting down the GPIO controller
+ // (this method will forcefully shutdown all GPIO monitoring threads and scheduled tasks)
+ gpio.shutdown();
+ }
+}
Oops, something went wrong.

0 comments on commit 80f3b64

Please sign in to comment.