1 /*
2  * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
4  * Copyright (c) 2014 Intel Corporation.
5  * Author: Petre Eftime <petre.p.eftime@intel.com>
6  * Copyright (c) 2015 Intel Corporation.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining
9  * a copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be
17  * included in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
23  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
24  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  */
27 
28 
29 import mraa.Dir;
30 import mraa.Gpio;
31 import mraa.Result;
32 import mraa.mraa;
33 
34 public class BlinkIO {
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     }
45 
46     final static int DEFAULT_IOPIN = 8;
47 
main(String argv[])48     public static void main(String argv[]) throws InterruptedException {
49         int iopin = DEFAULT_IOPIN;
50         if (argv.length == 0) {
51             System.out.println("Provide an int arg if you want to flash on something other than " + DEFAULT_IOPIN);
52         } else {
53             iopin = Integer.valueOf(argv[0], DEFAULT_IOPIN);
54         }
55 
56         //! [Interesting]
57         Gpio gpio = new Gpio(iopin);
58         Result result = gpio.dir(Dir.DIR_OUT);
59         if (result != Result.SUCCESS) {
60             mraa.printError(result);
61             System.exit(1);
62         }
63 
64         while (true) {
65             gpio.write(1);
66             Thread.sleep(1000);
67             gpio.write(0);
68             Thread.sleep(1000);
69         }
70         //! [Interesting]
71     }
72 }