No Description

MAXds3231mExample.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Author: Abhishek Malik <abhishek.malik@intel.com>
  3. * Copyright (c) 2016 Intel Corporation.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be
  14. * included in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  19. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  20. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  21. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  22. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. import upm_maxds3231m.MAXDS3231M;
  25. import upm_maxds3231m.Time3231;
  26. public class MAXds3231mExample {
  27. static {
  28. try {
  29. System.loadLibrary("javaupm_maxds3231m");
  30. System.loadLibrary("mraajava");
  31. } catch (UnsatisfiedLinkError e) {
  32. System.err.println(
  33. "Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" +
  34. e);
  35. System.exit(1);
  36. }
  37. }
  38. public static void main(String[] args) {
  39. // TODO Auto-generated method stub
  40. //! [Interesting]
  41. MAXDS3231M sensor = new MAXDS3231M(upm_maxds3231m.javaupm_maxds3231mConstants.ADDR);
  42. Time3231 t = new Time3231();
  43. t.setSecond((short)1);
  44. t.setMinute((short)3);
  45. t.setHour((short)3);
  46. t.setDay((short)3);
  47. t.setMonth((short)3);
  48. t.setYear((short)3);
  49. t.setWeekDay((short)3);
  50. sensor.setDate(t);
  51. try {
  52. Thread.sleep(500);
  53. } catch (InterruptedException e) {
  54. // TODO Auto-generated catch block
  55. System.out.println("The following exception occured: "+e.getMessage());
  56. }
  57. while(true){
  58. if(sensor.getDate(t)){
  59. System.out.println(t.getHour()+":"+t.getMinute()+":"+t.getSecond());
  60. }
  61. System.out.println("Temperature: "+sensor.getTemperature());
  62. try {
  63. Thread.sleep(1000);
  64. } catch (InterruptedException e) {
  65. // TODO Auto-generated catch block
  66. System.out.println("The following exception occcured: "+e.getMessage());
  67. }
  68. }
  69. //! [Interesting]
  70. }
  71. }