diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index 62fc018a..8afe7acc 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -114,6 +114,11 @@ add_example(TEX00_Example tex00) add_example(BMI160_Example bmi160) add_example(Tsl2561 tsl2561) add_example(AM2315Example am2315) +add_example(MAX31855Example max31855) +add_example(MAX5487Example max5487) +add_example(MAXds3231mExample maxds3231m) +add_example(ECS1030Example ecs1030) +add_example(SM130Example sm130) if (MODBUS_FOUND) add_example(H803X_Example h803x) endif() diff --git a/examples/java/ECS1030Example.java b/examples/java/ECS1030Example.java new file mode 100644 index 00000000..b9223496 --- /dev/null +++ b/examples/java/ECS1030Example.java @@ -0,0 +1,52 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import upm_ecs1030.ECS1030; + +public class ECS1030Example { + + static { + try { + System.loadLibrary("javaupm_ecs1030"); + System.loadLibrary("mraajava"); + } catch (UnsatisfiedLinkError e) { + System.err.println( + "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + + e); + System.exit(1); + } + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + //! [Interesting] + ECS1030 sensor = new ECS1030((short)0); + + while(true){ + System.out.println("I = "+sensor.getCurrency_A()+", Power = "+sensor.getPower_A()); + System.out.println("I = "+sensor.getCurrency_B()+", Power = "+sensor.getPower_B()); + } + //! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/MAX31855Example.java b/examples/java/MAX31855Example.java new file mode 100644 index 00000000..1b1127ed --- /dev/null +++ b/examples/java/MAX31855Example.java @@ -0,0 +1,56 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import upm_max31855.MAX31855; + +public class MAX31855Example { + + static { + try { + System.loadLibrary("javaupm_max31855"); + System.loadLibrary("mraajava"); + } catch (UnsatisfiedLinkError e) { + System.err.println( + "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + + e); + System.exit(1); + } + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + //! [Interesting] + MAX31855 sensor = new MAX31855(0, 8); + while(true){ + System.out.println("Temperature: "+sensor.getTemp()); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + System.out.println("The following exception occured: "+e.getMessage()); + } + } + //! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/MAX5487Example.java b/examples/java/MAX5487Example.java new file mode 100644 index 00000000..92b53310 --- /dev/null +++ b/examples/java/MAX5487Example.java @@ -0,0 +1,71 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import upm_max5487.MAX5487; + +public class MAX5487Example { + + static { + try { + System.loadLibrary("javaupm_max5487"); + System.loadLibrary("mraajava"); + } catch (UnsatisfiedLinkError e) { + System.err.println( + "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + + e); + System.exit(1); + } + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + //! [Interesting] + MAX5487 sensor = new MAX5487(7); + + // Power LED UP + for(int i=0; i<255; i++){ + sensor.setWiperA((short)i); + try { + Thread.sleep(5); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + System.out.println("The following Exception occured: "+e.getMessage()); + } + } + + // Power LED DOWN + for(int i=0; i<255; i++){ + sensor.setWiperA((short)(255 - i)); + try { + Thread.sleep(5); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + System.out.println("The following exception occured: "+e.getMessage()); + } + } + + System.out.println("Exiting..."); + //! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/MAXds3231mExample.java b/examples/java/MAXds3231mExample.java new file mode 100644 index 00000000..12e6dba5 --- /dev/null +++ b/examples/java/MAXds3231mExample.java @@ -0,0 +1,79 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import upm_maxds3231m.MAXDS3231M; +import upm_maxds3231m.Time3231; + +public class MAXds3231mExample { + + static { + try { + System.loadLibrary("javaupm_maxds3231m"); + System.loadLibrary("mraajava"); + } catch (UnsatisfiedLinkError e) { + System.err.println( + "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + + e); + System.exit(1); + } + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + //! [Interesting] + MAXDS3231M sensor = new MAXDS3231M(upm_maxds3231m.javaupm_maxds3231mConstants.ADDR); + Time3231 t = new Time3231(); + + t.setSecond((short)1); + t.setMinute((short)3); + t.setHour((short)3); + t.setDay((short)3); + t.setMonth((short)3); + t.setYear((short)3); + t.setWeekDay((short)3); + + sensor.setDate(t); + + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + System.out.println("The following exception occured: "+e.getMessage()); + } + + while(true){ + if(sensor.getDate(t)){ + System.out.println(t.getHour()+":"+t.getMinute()+":"+t.getSecond()); + } + System.out.println("Temperature: "+sensor.getTemperature()); + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + System.out.println("The following exception occcured: "+e.getMessage()); + } + } + //! [Interesting] + } + +} \ No newline at end of file diff --git a/examples/java/SM130Example.java b/examples/java/SM130Example.java new file mode 100644 index 00000000..16f056d7 --- /dev/null +++ b/examples/java/SM130Example.java @@ -0,0 +1,69 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2016 Intel Corporation. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ +import upm_sm130.SM130; + +public class SM130Example { + + static { + try { + System.loadLibrary("javaupm_sm130"); + System.loadLibrary("mraajava"); + } catch (UnsatisfiedLinkError e) { + System.err.println( + "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + + e); + System.exit(1); + } + } + + public static void main(String[] args) { + // TODO Auto-generated method stub + //! [Interesting] + // Instantiate a UART based SM130 RFID Module using defaults + SM130 sensor = new SM130(); + + // set the baud rate. 19200 baud is the default. + if(sensor.setBaudRate(19200) == 1){ + System.out.println("Failed to set baud rate"); + return; + } + + System.out.println("Resetting..."); + sensor.reset(); + + System.out.println("Firmware revision: "+sensor.getFirmwareVersion()); + System.out.println("Waiting up to 5 seconds for a tag..."); + + if(sensor.waitForTag(5000)){ + System.out.println("Found tag, UID: "+sensor.string2HexString(sensor.getUID())); + System.out.println("Tag Type: "+sensor.tag2String(sensor.getTagType())); + } + else{ + // error + System.out.println("waitForTag failed: "+sensor.getLastErrorString()); + } + //! [Interesting] + } + +} \ No newline at end of file