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 24import time, sys, signal, atexit 25import pyupm_ds1307 as upmDs1307 26 27# load RTC clock on i2c bus 0 28myRTCClock = upmDs1307.DS1307(0) 29 30def 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 45print "Loading the current time... " 46result = myRTCClock.loadTime() 47if (not result): 48 print "myRTCClock.loadTime() failed." 49 sys.exit(0) 50 51printTime(myRTCClock); 52 53# set the year as an example 54print "setting the year to 50" 55myRTCClock.year = 50 56myRTCClock.setTime() 57 58# reload the time and print it 59myRTCClock.loadTime() 60printTime(myRTCClock) 61