-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
138 lines (123 loc) · 5.12 KB
/
main.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from machine import Pin, RTC
from time import sleep_ms
from k155id1 import Decoder, NixieDot
SAVER_PERIOD = 2 # in minutes; default = 10
SAVER_DELAY_TIME = 300 # in ms; default = 300
SAVER_ITERATION_COUNT = 1
def state(): #TODO
if True:
return True
def main():
hour1 = Decoder({'a0': Pin(0, Pin.OUT, Pin.PULL_DOWN), 'a1': Pin(1, Pin.OUT, Pin.PULL_DOWN), 'a2': Pin(14, Pin.OUT, Pin.PULL_DOWN), 'a3': Pin(12, Pin.OUT, Pin.PULL_DOWN)})
hour2 = Decoder({'a0': Pin(16, Pin.OUT, Pin.PULL_DOWN), 'a1': Pin(17, Pin.OUT, Pin.PULL_DOWN), 'a2': Pin(26, Pin.OUT, Pin.PULL_DOWN), 'a3': Pin(27, Pin.OUT, Pin.PULL_DOWN)})
min1 = Decoder({'a0': Pin(2, Pin.OUT, Pin.PULL_DOWN), 'a1': Pin(3, Pin.OUT, Pin.PULL_DOWN), 'a2': Pin(4, Pin.OUT, Pin.PULL_DOWN), 'a3': Pin(5, Pin.OUT, Pin.PULL_DOWN)})
min2 = Decoder({'a0': Pin(6, Pin.OUT, Pin.PULL_DOWN), 'a1': Pin(7, Pin.OUT, Pin.PULL_DOWN), 'a2': Pin(8, Pin.OUT, Pin.PULL_DOWN), 'a3': Pin(9, Pin.OUT, Pin.PULL_DOWN)})
saver = NixieSaver([hour1, hour2, min1, min2])
clock = Clock(hour1, hour2, min1, min2, saver)
while True:
current_state = state()
if current_state:
clock.show_time()
print(current_state)
print(f'HOUR1 Time:{clock.ct}, current:{hour1.current}')
print(f'HOUR2 Time:{clock.ct}, current:{hour2.current}')
print(f'MIN1 Time:{clock.ct}, current:{min1.current}')
print(f'MIN2 Time:{clock.ct}, current:{min2.current}\n{"---"*3}')
sleep_ms(1000)
class Clock:
def __init__(self, hour1, hour2, minute1, minute2, saver, second1=None, second2=None):
if second1 is not None or second2 is not None:
if not isinstance(hour1, Decoder) or not isinstance(hour2, Decoder) or not isinstance(minute1, Decoder) or not isinstance(minute2, Decoder) or not isinstance(second1, Decoder) or not isinstance(second2, Decoder):
raise TypeError('Args must be Decoder')
self.saver = saver
self.rtc = RTC()
self.rtc.datetime(self.get_new_time())
self.hour1 = hour1
self.hour2 = hour2
self.minute1 = minute1
self.minute2 = minute2
self.second1 = second1
self.second2 = second2
self.old_time = -1
def get_new_time(self):
#TODO
year = 2022
month = 1
day = 3
weekday = 1
hour = 10 # fake data
minute = 20
second = 30
return (year, month, day, weekday, hour, minute, second, 0)
def show_time(self):
print(self.rtc.datetime())
current_time = self.rtc.datetime()[4:]
if current_time[1] != self.old_time and current_time[1] % SAVER_PERIOD == 0:
self.saver.run()
self.old_time = current_time[1]
print('old time:', self.old_time)
self.ct = current_time #DEBUG
# set hours
if current_time[0] < 10:
self.hour1.set_num(0)
self.hour2.set_num(current_time[0])
else:
self.hour1.set_num(current_time[0] // 10)
self.hour2.set_num(current_time[0] % 10)
# set minutes
if current_time[1] < 10:
self.minute1.set_num(0)
self.minute2.set_num(current_time[1])
else:
self.minute1.set_num(current_time[1] // 10)
self.minute2.set_num(current_time[1] % 10)
# set seconds
if self.second1 is not None or self.second2 is not None:
if current_time[2] < 10:
self.second1.set_num(0)
self.second2.set_num(current_time[2])
else:
self.second1.set_num(current_time[2] // 10)
self.second2.set_num(current_time[2] % 10)
class NixieSaver:
def __init__(self, nixies):
self.nixies = nixies
def run(self):
print('NixieSaver.run() был вызван')
for i in range(SAVER_ITERATION_COUNT):
for nixie in self.nixies:
nixie.set_num(0)
sleep_ms(SAVER_DELAY_TIME)
print(i, '0 is ok')
nixie.set_num(1)
sleep_ms(SAVER_DELAY_TIME)
print(i, '1 is ok')
nixie.set_num(2)
sleep_ms(SAVER_DELAY_TIME)
print(i, '2 is ok')
nixie.set_num(3)
sleep_ms(SAVER_DELAY_TIME)
print(i, '3 is ok')
nixie.set_num(4)
sleep_ms(SAVER_DELAY_TIME)
print(i, '4 is ok')
nixie.set_num(5)
sleep_ms(SAVER_DELAY_TIME)
print(i, '5 is ok')
nixie.set_num(6)
sleep_ms(SAVER_DELAY_TIME)
print(i, '6 is ok')
nixie.set_num(7)
sleep_ms(SAVER_DELAY_TIME)
print(i, '7 is ok')
nixie.set_num(8)
sleep_ms(SAVER_DELAY_TIME)
print(i, '8 is ok')
nixie.set_num(9)
sleep_ms(SAVER_DELAY_TIME)
print(i, '9 is ok')
current_state = None
return print('DEBUG:SAVER: RUN OK')
if __name__ == '__main__':
#main()
pass