-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_wpm_timing.py
127 lines (90 loc) · 3.24 KB
/
test_wpm_timing.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
from machine import Pin, Timer, PWM, ADC, I2C
from time import sleep
import utime # utime is the micropython brother of time
# testprogram für das timing gemessen am oscilloscope
#5.12.23 dl2dbg
pin_led = Pin(4, mode=Pin.OUT)
class cw_timing(): # cw timing wird als eigene classe verwaltet, kann daher auch ohne IAMBIC class eingesetzt werden
def __init__(self, wpm=18, weighting= 50, ratio = 3):
self.wpm_t = wpm # wpmt local
self.weighting_t = weighting
self.ratio_t = ratio
# timing
def dit_time(self): #aktive
self.PARIS = 50
# return 60.0 / self.wpm_t / self.PARIS * 1000 /50*(self.weighting_t) ## mili sekunden
return 60.0 / self.wpm_t / self.PARIS * 1000 /50*(self.weighting_t) ## mili sekunden
def pdit_time(self): #pasive
self.PARIS = 50
return 60.0 / self.wpm_t / self.PARIS * 1000 /50*(100-self.weighting_t)## mili sekunden
def set_wpm(self, wpm):
self.wpm_t = wpm
def get_ratio(self):
return self.ratio_t
def set_ratio(self, ratio):
self.ratio_t = ratio
def get_weighting(self):
return self.weighting_t
def set_weighting(self, weighting):
self.weighting_t = weighting
def cw(state):
if state:
pin_led.on()
else:
pin_led.off()
class count_time():
def __init__(self):
self.time = 0
def clear(self):
self.time = 0
def add(self, delay):
self.time = self.time + delay
def get(self):
return (self.time)
class count_dit():
def __init__(self):
self.count = 0
def clear(self):
self.count = 0
def add(self, anzahl):
self.count = self.count + anzahl
def get(self):
return (self.count)
# transmit pattern
def play(pattern):
for sound in pattern:
if sound == '.':
cw(True)
utime.sleep(cw_time.dit_time() / 1000)
zeit.add(cw_time.dit_time())
dit.add(1)
cw(False)
utime.sleep(cw_time.pdit_time() / 1000)
zeit.add(cw_time.dit_time())
dit.add(1)
elif sound == '-':
cw(True)
utime.sleep(cw_time.get_ratio() * cw_time.dit_time() / 1000) # ration 2.3-3.7
zeit.add(cw_time.get_ratio() * cw_time.dit_time())
dit.add(1*cw_time.get_ratio())
cw(False)
utime.sleep(cw_time.pdit_time() / 1000)
zeit.add(cw_time.dit_time())
dit.add(1)
elif sound == ' ':
utime.sleep(4 * cw_time.pdit_time() / 1000)
zeit.add(cw_time.dit_time())
dit.add(4)
utime.sleep(2 * cw_time.pdit_time() / 1000)
#zeit.add(2*cw_time.dit_time())
zeit = count_time()
dit = count_dit()
cw_time = cw_timing(wpm=18,weighting=50,ratio=4)
print(f"weighting:{cw_time.get_weighting()} ratio:{cw_time.get_ratio()} aktive dit_time: {cw_time.dit_time()} ms pause pdit_time: {cw_time.pdit_time()} ms dat_time: {cw_time.get_ratio() * cw_time.dit_time()} ms")
zeit.clear()
dit.clear()
txt = "...-"
play(txt)
print(txt)
print(zeit.get())
print(dit.get())