Bläddra i källkod

ds1307: python example for ds1307 RTC clock

Signed-off-by: Zion Orent <zorent@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Zion Orent 9 år sedan
förälder
incheckning
de96a3d327
1 ändrade filer med 60 tillägg och 0 borttagningar
  1. 60
    0
      examples/python/ds1307.py

+ 60
- 0
examples/python/ds1307.py Visa fil

@@ -0,0 +1,60 @@
1
+#!/usr/bin/python
2
+# Author: Zion Orent <zorent@ics.com>
3
+# Copyright (c) 2015 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 time, sys, signal, atexit
25
+import pyupm_ds1307 as upmDs1307
26
+
27
+# load RTC clock on i2c bus 0
28
+myRTCClock = upmDs1307.DS1307(0)
29
+
30
+def printTime(RTCObj):
31
+	timeStr = "The time is: {0}/{1}/{2} {3}:{4}:{5}".format(
32
+	RTCObj.month, RTCObj.dayOfMonth, RTCObj.year,
33
+	RTCObj.hours, RTCObj.minutes, RTCObj.seconds)
34
+
35
+	if (RTCObj.amPmMode):
36
+		timeStr += (" PM " if RTCObj.pm else " AM ")
37
+
38
+	print timeStr
39
+
40
+	print "Clock is in", ("AM/PM mode"
41
+	if RTCObj.amPmMode else "24hr mode")
42
+
43
+
44
+# always do this first
45
+print "Loading the current time... "
46
+result = myRTCClock.loadTime()
47
+if (not result):
48
+	print "myRTCClock.loadTime() failed."
49
+	sys.exit(0)
50
+
51
+printTime(myRTCClock);
52
+
53
+# set the year as an example
54
+print "setting the year to 50"
55
+myRTCClock.year = 50
56
+myRTCClock.setTime()
57
+
58
+# reload the time and print it
59
+myRTCClock.loadTime()
60
+printTime(myRTCClock)