From f32ef700f277704a8eb89aebf7099d19853364f1 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Sat, 17 Jul 2010 17:28:40 +0200 Subject: tools: add RTC control script --- tools/rtc.py | 139 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 tools/rtc.py (limited to 'tools') diff --git a/tools/rtc.py b/tools/rtc.py new file mode 100644 index 0000000..7fcacb1 --- /dev/null +++ b/tools/rtc.py @@ -0,0 +1,139 @@ +# binwatch - Tiny binary wristwatch. {{{ +# +# Copyright (C) 2010 Nicolas Schodet +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +# Contact : +# Web: http://ni.fr.eu.org/ +# Email: +# }}} */ +"""RTC control.""" +import struct +import dev2.twi + +class ProtocolError (RuntimeError): + pass + +class RTC: + + REGS = [ + ('control1', 0xff), + ('control2', 0xbf), + ('second', 0xff), + ('minute', 0x7f), + ('hour', 0x3f), + ('day', 0x3f), + ('weekday', 0x07), + ('month_century', 0x9f), + ('year', 0xff), + ('alarm_minute', 0xff), + ('alarm_hour', 0xbf), + ('alarm_day', 0xbf), + ('alarm_weekday', 0x87), + ('clkout', 0x83), + ('timer_control', 0x83), + ('timer', 0xff), + ] + + def __init__ (self, address, serial): + """Initialise and set address and serial object to use.""" + self.address = address + self.twi = dev2.twi.Twi (serial) + + def init (self): + s = struct.pack ('> sys.stderr, e.message + sys.exit (1) + +if __name__ == '__main__': + command () -- cgit v1.2.3