forked from micropython/micropython
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrtc.py
117 lines (99 loc) · 2.57 KB
/
rtc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
'''
RTC test for the CC3200 based boards.
'''
from machine import RTC
import os
import time
mch = os.uname().machine
if not 'LaunchPad' in mch and not 'WiPy' in mch:
raise Exception('Board not supported!')
rtc = RTC()
print(rtc)
print(rtc.now()[:6])
rtc = RTC(datetime=(2015, 8, 29, 9, 0, 0, 0, None))
print(rtc.now()[:6])
rtc.deinit()
print(rtc.now()[:6])
rtc.init((2015, 8, 29, 9, 0, 0, 0, None))
print(rtc.now()[:6])
seconds = rtc.now()[5]
time.sleep_ms(1000)
print(rtc.now()[5] - seconds == 1)
seconds = rtc.now()[5]
time.sleep_ms(2000)
print(rtc.now()[5] - seconds == 2)
# initialization with shorter tuples
rtc.init((2015, 9, 19, 8, 0, 0, 0))
print(rtc.now()[5])
rtc.init((2015, 9, 19, 8, 0, 0))
print(rtc.now()[5])
rtc.init((2015, 9, 19, 8, 0))
print(rtc.now()[5])
rtc.init((2015, 9, 19, 8))
print(rtc.now()[4])
rtc.init((2015, 9, 19))
print(rtc.now()[3])
def set_and_print(datetime):
rtc.init(datetime)
print(rtc.now()[:6])
# make sure that setting works correctly
set_and_print((2000, 1, 1, 0, 0, 0, 0, None))
set_and_print((2000, 1, 31, 0, 0, 0, 0, None))
set_and_print((2000, 12, 31, 0, 0, 0, 0, None))
set_and_print((2016, 12, 31, 0, 0, 0, 0, None))
set_and_print((2016, 12, 31, 0, 0, 0, 0, None))
set_and_print((2016, 12, 31, 1, 0, 0, 0, None))
set_and_print((2016, 12, 31, 12, 0, 0, 0, None))
set_and_print((2016, 12, 31, 13, 0, 0, 0, None))
set_and_print((2016, 12, 31, 23, 0, 0, 0, None))
set_and_print((2016, 12, 31, 23, 1, 0, 0, None))
set_and_print((2016, 12, 31, 23, 59, 0, 50, None))
set_and_print((2016, 12, 31, 23, 59, 1, 900, None))
set_and_print((2016, 12, 31, 23, 59, 59, 100, None))
set_and_print((2048, 12, 31, 23, 59, 59, 99999, None))
rtc.init((2015, 8, 29, 9, 0, 0, 0, None))
rtc.alarm(0, 5000)
rtc.alarm(time=2000)
time.sleep_ms(1000)
left = rtc.alarm_left()
print(abs(left-1000) <= 10)
time.sleep_ms(1000)
print(rtc.alarm_left() == 0)
time.sleep_ms(100)
print(rtc.alarm_left(0) == 0)
rtc.alarm(time=1000, repeat=True)
time.sleep_ms(1500)
left = rtc.alarm_left()
print(abs(left-500) <= 15)
rtc.init((2015, 8, 29, 9, 0, 0, 0, None))
rtc.alarm(time=(2015, 8, 29, 9, 0, 45))
time.sleep_ms(1000)
left = rtc.alarm_left()
print(abs(left-44000) <= 90)
rtc.alarm_cancel()
rtc.deinit()
# next ones must raise
try:
rtc.alarm(5000)
except:
print('Exception')
try:
rtc.alarm_left(1)
except:
print('Exception')
try:
rtc.alarm_cancel(1)
except:
print('Exception')
try:
rtc.alarm(5000)
except:
print('Exception')
try:
rtc = RTC(200000000)
except:
print('Exception')
try:
rtc = RTC((2015, 8, 29, 9, 0, 0, 0, None))
except:
print('Exception')