1 /* 2 * Author: Brendan Le Foll <brendan.le.foll@intel.com> 3 * Author: Petre Eftime <petre.p.eftime@intel.com> 4 * Copyright (c) 2015 Intel Corporation. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining 7 * a copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sublicense, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be 15 * included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26 //! [Interesting] 27 import mraa.Dir; 28 import mraa.Gpio; 29 import mraa.IntelEdison; 30 import mraa.mraa; 31 import mraa.Platform; 32 import mraa.Result; 33 34 public class HelloEdison { 35 static { 36 try { 37 System.loadLibrary("mraajava"); 38 } catch (UnsatisfiedLinkError e) { 39 System.err.println( 40 "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + 41 e); 42 System.exit(1); 43 } 44 } main(String argv[])45 public static void main(String argv[]) { 46 Platform platform = mraa.getPlatformType(); 47 48 if (platform != Platform.INTEL_EDISON_FAB_C) { 49 System.err.println("Error: This program can only be run on edison"); 50 System.exit(Result.ERROR_INVALID_PLATFORM.swigValue()); 51 } 52 53 /* 54 * MRAA_INTEL_EDISON_GP182 == 0, so this will initialise pin0 on arduino, 55 * which is hardware GPIO 130 and not 182 56 * We set the owner to false here, this makes sure that we do not close the 57 * gpio from sysfs in mraa_gpio_close meaning it will stay as an output and 58 * we will not always transition from 0->1 as gpio182 as output has the 59 * default position of '0'. Note that the value could change as a result of 60 * a mraa_gpio_dir however meaning we always go from 0->1 or 1->0 61 */ 62 Gpio gpio182 = new Gpio(IntelEdison.INTEL_EDISON_GP182.swigValue(), false); 63 gpio182.dir(Dir.DIR_OUT); 64 65 int val = gpio182.read(); 66 67 System.out.println(String.format("GPIO%d (mraa pin %d) was: %d, will set to %d\n", 182, 68 gpio182.getPin(), val, val == 0 ? 1 : 0)); 69 70 gpio182.write(val == 0 ? 1 : 0); 71 }; 72 } 73 //! [Interesting] 74