-
Notifications
You must be signed in to change notification settings - Fork 1
/
iambic_keyer_rp2040.py
860 lines (638 loc) · 28.2 KB
/
iambic_keyer_rp2040.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
# Iambic keyer rp2040 include simple transceiver on 40m
#
# Copyright (C) 2022 dl2dbg
# update 6.1.2024
# update 12.3.2023
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from machine import Pin, Timer, PWM
from rp2 import PIO, StateMachine, asm_pio
import utime # utime is the micropython brother of time
import time
import ujson
#xiaoKey - a computer connected iambic keyer
# Copyright 2022 Mark Woodworth (AC9YW)
#https://github.com/MarkWoodworth/xiaokey/blob/master/code/code.py
# setup encode and decode
encodings = {}
def encode(char):
global encodings
if char in encodings:
return encodings[char]
elif char.lower() in encodings:
return encodings[char.lower()]
else:
return ''
decodings = {}
def decode(char):
global decodings
if char in decodings:
return decodings[char]
else:
return '('+char+'?)'
def MAP(pattern,letter):
decodings[pattern] = letter
encodings[letter ] = pattern
MAP('.-' ,'a') ; MAP('-...' ,'b') ; MAP('-.-.' ,'c') ; MAP('-..' ,'d') ; MAP('.' ,'e')
MAP('..-.' ,'f') ; MAP('--.' ,'g') ; MAP('....' ,'h') ; MAP('..' ,'i') ; MAP('.---' ,'j')
MAP('-.-' ,'k') ; MAP('.-..' ,'l') ; MAP('--' ,'m') ; MAP('-.' ,'n') ; MAP('---' ,'o')
MAP('.--.' ,'p') ; MAP('--.-' ,'q') ; MAP('.-.' ,'r') ; MAP('...' ,'s') ; MAP('-' ,'t')
MAP('..-' ,'u') ; MAP('...-' ,'v') ; MAP('.--' ,'w') ; MAP('-..-' ,'x') ; MAP('-.--' ,'y')
MAP('--..' ,'z')
MAP('.----','1') ; MAP('..---','2') ; MAP('...--','3') ; MAP('....-','4') ; MAP('.....','5')
MAP('-....','6') ; MAP('--...','7') ; MAP('---..','8') ; MAP('----.','9') ; MAP('-----','0')
MAP('.-.-.-','.') # period
MAP('--..--',',') # comma
MAP('..--..','?') # question mark
MAP('-...-', '=') # equals, also /BT separator
MAP('-....-','-') # hyphen
MAP('-..-.', '/') # forward slash
MAP('.--.-.','@') # at sign
class transceiver():
'''
dl2dbg 3.3.2022
# StateMachine ....to trasmit cw with rp2040 pin
#
# doku
# Cornell University ECE4760
# RP2040 testing
# ttp:https://people.ece.cornell.edu/land/courses/ece4760/RP2040/index_rp2040_testing.html
'''
def __init__(self):
#self.tx_opt_pin = Pin(tx_pin,Pin.OUT)
# Pin(2)) is HF out
self.freq = 7005250 # auf 40m fangen wir an
self.on_off = 1
self.osc()
def set_freq(self,frq):
self.freq = frq
self.osc()
#print(frq)
def on(self):
self.on_off = 1
def off(self):
self.on_off = 0
self.sm3.active(0)
@asm_pio(set_init=PIO.OUT_LOW)
def tx_toggle():
wrap_target()
set(pins, 1) [1]
set(pins, 0) [1]
wrap()
def osc(self):
self.sm3 = StateMachine(3, self.tx_toggle, freq= self.freq*4, set_base=Pin(2))
# self.sm3 = StateMachine(3, self.tx_toggle, freq= self.freq*4, set_base=Pin(2), jmp_pin=self.tx_opt_pin)
self.sm3.active(0)
self.sm3.active(1)
def send(self,state):
if self.on_off == 1:
self.sm3.active(state)
class tx_opt():
'''
3.3.2022
simple pin on/off for tx optocopler
#
'''
def __init__(self,tx_pin):
self.tx_opt_pin = Pin(tx_pin,Pin.OUT)
self.on_off = 1
#self._pin = Pin(10, Pin.OUT)
def on(self):
self.on_off = 1
def off(self):
self.on_off = 0
def send(self,state):
if self.on_off == 1:
self.tx_opt_pin.value(state)
#print(".") #dl2dbg
#print(tx_pin)
class command_button():
'''
6.3.2020 button for Command request
'''
def __init__(self,pin_button,led1,led2):
#GPIO welcher als PWM Pin benutzt werden soll
self.button = Pin(pin_button,Pin.IN,Pin.PULL_UP)
self.led1 = Pin(led1, Pin.OUT)
self.led2 = Pin(led2, Pin.OUT)
self.button_save = 0
self.btimer = 0 # timer for debounce
self.command_state = 1 # im keyer mode
#
# self.save_tfreq = cwt.tonfreq()
# self.ton_freq_command = cwt.tonfreq_command()
def button_press(self):
return(self.button.value())
def button_command_off(self):
#print("command off")
self.command_state = 0
self.led1(self.command_state)
self.led2(self.command_state)
iambic.char = ""
iambic.word = ""
text2cw("e")
def button_state(self):
if self.button.value() == 0 and self.button_save == 1: # 1 0 ->button is press
utime.ticks_ms()
self.btimer = utime.ticks_ms()
self.button_save = 0
elif self.button.value() == 1 and self.button_save == 0 and utime.ticks_ms() > self.btimer + 10 : #0 0 ->button IS press
self.button_save = 1
self.led1(not self.command_state)
self.led2(not self.command_state)
self.command_state = not self.command_state
if self.command_state:
#print("command ",self.command_state)
# in command mode immer ton on
cwt.set2cton()
cwt.onoff(True)
else :
#print("command ",self.command_state)
cwt.set2ton()
cwt.onoff(iambic.sidetone_enable)
cb.button_command_off()
text2cw("e")
return(self.button_save)
class cw_sound():
'''
6.3.2020 simple sound with pwm
'''
def __init__(self,pin=22):
#GPIO welcher als PWM Pin benutzt werden soll
self.pwm_ton = PWM(Pin(pin))
#eine Frequenz von 1000hz also 1kHz
self.freq = 600
self.Ton_freq_command = 1500
self.pwm_ton.freq(self.freq)
self.cwvolum = 2000 #30000 laut
self.on_off = 1
def set_tonfreq(self,freq):
self.freq = freq
self.pwm_ton.freq(self.freq)##
def set2ton(self):
self.pwm_ton.freq(self.freq)
def set2cton(self):
self.pwm_ton.freq(self.Ton_freq_command)
def tonfreq(self):
return self.freq
def tonfreq_command(self):
return self.Ton_freq_command
def volume(self,volume):
self.cwvolum = volume
def tone(self,on):
if self.on_off == 1:
if on:
self.pwm_ton.duty_u16(self.cwvolum)
else:
self.pwm_ton.duty_u16(1)
def onoff(self,state):
self.on_off = state
def cw(state):
cwt.tone(state)
tx.send(state)
txopt.send(state)
class cw_timing():
def __init__(self,wpm=18):
self.wpm = wpm
# timing
def dit_time(self):
self.PARIS = 50
return 60.0 / self.wpm / self.PARIS *1000 ## mili sekunden
def set_wpm(self, wpm):
self.wpm = wpm
# decode iambic b paddles
class Iambic:
"""
Command
a -> Iambic Mode A
b -> Iambic Mode B
m -> request Iambic Mode A/B
? -> request value of ...
i -> TX_opt enable(on) disable(off)
j -> TX_transceiver HF enable(on) disable(off)
o -> Sidetone toggle (on) (off)
f -> adjust sidetone frequenz
v -> adjust sidetone volume 1-100
q -> adjust qrg of tx
w -> adjust WPM (Word per minute)
t -> tune mode, end with command mode
s -> save parameter to file
x -> exit Command mode
tranceiver is toggle pin of rp2040
def tx_toggle():
wrap_target()
set(pins, 1) [1]
set(pins, 0) [1]
wrap()
qrg:
.... 7029870
.... 7023700
.... 7017540
.... 7011390
.... 7005250
"""
def __init__(self,dit_key,dah_key):
self.dit_key = Pin(dit_key,Pin.IN,Pin.PULL_UP)
self.dah_key = Pin(dah_key,Pin.IN,Pin.PULL_UP)
self.dit = False ; self.dah = False
self.ktimer = 0
self.ktimer_end = 0
self.in_char = True
self.in_word = True
self.char = ""
self.IDLE=0; self.CHK_DIT=1; self.CHK_DAH=2; self.KEYED_PREP=3; self.KEYED=4; self.INTER_ELEMENT=5
self.keyerState = self.IDLE
self.keyerControl = 0 #keyerControl = IAMBICB; // Or 0 for IAMBICA
# keyerControl bit definitions
self.DIT_L = 0x01 # Dit latch
self.DAH_L = 0x02 #Dah latch
self.DIT_PROC = 0x04 # Dit is being processed
self.PDLSWAP = 0x08 # 0 for normal, 1 for swap
#self.iambic_mode = 0x10 # 0 for Iambic A, 1 for Iambic B
self.LOW = 0
self.HIGH = 1
self.tune = 0 # transmit
self.transmit_tune= 0
self.adj_sidetone = 0
self.adj_wpm = 0
self.adj_qrg = 0
self.adj_sidetone_volume = 0
# this variable are default an will be overwrite with the json file
#
self.iambic_mode = 0x10 # 0 for Iambic A, 1 for Iambic B
self.wpm = 18
self.tx_enable = 0 # tx des OPTO Copler
self.txt_enable = 0 # "HF" tx transceiver des PIOC
self.sidetone_enable = 1
self.sidetone_freq = 700 #
self.sidetone_volume = 10 # range 1,100 * 200 -> 2000 #30000 laut
#
self.f_liste =[7017540,7005250,7011390,7036050,7029870,7023700]
self.f_liste.sort()
self.qrg_marke = 0
self.qrg = self.f_liste[self.qrg_marke]
self.request = 0 # request of parameters
#--------------
self.iambic_data = {} # create date store
if cb.button_press() == 1: # not press "0" -> json date read,and init, if "0" use factory setting
self.read_jsondata()
self.init_iambic_data()
def set_data(self,key,value):
#self.iambic_data
self.key=key
self.value= value
self.iambic_data[self.key]=self.value
# print ('setting',menu_data)
def write_data2file(self):
#self.iambic_data
self.json_string = ujson.dumps(self.iambic_data)
with open('json_iambic.json', 'w') as outfile:
ujson.dump(self.json_string, outfile)
def read_jsondata(self):
#print("read json data")
with open('json_iambic.json') as json_file:
self.data = ujson.load(json_file)
self.iambic_data = ujson.loads(self.data)
def write_jsondata(self): # write new json file
#print("write_jsondata")
self.set_data("iambic_mode",self.iambic_mode) # transmit
self.set_data("wpm",self.wpm)
self.set_data("sidetone_enable",self.sidetone_enable)
self.set_data("sidetone_freq",self.sidetone_freq)
self.set_data("sidetone_volume",self.sidetone_volume)
self.set_data("tx_enable",self.tx_enable)
self.set_data("txt_enable",self.txt_enable)
#print(self.iambic_data)
self.write_data2file()
def init_iambic_data(self): # is only use at the begin to create new json file
self.iambic_mode = self.iambic_data["iambic_mode"]
self.wpm = self.iambic_data["wpm"]
self.sidetone_enable = self.iambic_data["sidetone_enable"]
self.sidetone_freq = self.iambic_data["sidetone_freq"]
self.sidetone_volume = self.iambic_data["sidetone_volume"]
self.tx_enable = self.iambic_data["tx_enable"]
self.txt_enable = self.iambic_data["txt_enable"]
# set extern Parameter
cw_time.set_wpm(self.wpm)
cwt.set_tonfreq(self.sidetone_freq)
cwt.volume(self.sidetone_volume*200)
cwt.onoff(self.sidetone_enable)
if self.tx_enable == 1:
txopt.on()
else:
txopt.off()
#---------------
def update_PaddleLatch(self):
if (self.dit_key.value() == self.LOW):
self.keyerControl |= self.DIT_L
if (self.dah_key.value() == self.LOW):
self.keyerControl |= self.DAH_L
def cycle(self):
#utime.sleep(0.3)
cb.button_state() ## Comand button abfragen
if cb.command_state == 1 : # "1" ->comand mode
if self.tune == 1: # begin tune
self.keyerSate = self.IDLE
if self.dah_key.value() == self.LOW: # transmit on
self.transmit_tune= 1
cw(1)
elif self.dit_key.value() == self.LOW: #transmit off
self.transmit_tune= 0
cw(0)
return
elif self.adj_sidetone == 1: # begin tune
self.keyerSate = self.IDLE
if self.dah_key.value() == self.LOW: # transmit on
if self.sidetone_freq > 2000:
text2cw("max")
else:
self.sidetone_freq =self.sidetone_freq +10
cwt.set_tonfreq(self.sidetone_freq) # change the Freq
play("-")
elif self.dit_key.value() == self.LOW: #transmit off
if self.sidetone_freq < 50:
text2cw("min")
else:
self.sidetone_freq = self.sidetone_freq -10
cwt.set_tonfreq(self.sidetone_freq)
play(".")
return
elif self.adj_sidetone_volume == 1: # adjust sidetone volume
self.keyerSate = self.IDLE
if self.dah_key.value() == self.LOW: # transmit on
if self.sidetone_volume >= 100:
text2cw("max")
else:
self.sidetone_volume = self.sidetone_volume + 1
cwt.volume(self.sidetone_volume*200)
#print(self.sidetone_volume)
play("-")
elif self.dit_key.value() == self.LOW: #transmit off
if self.sidetone_volume <= 0:
text2cw("min")
else:
self.sidetone_volume = self.sidetone_volume - 1
cwt.volume(self.sidetone_volume*200)
#print(self.sidetone_volume)
play(".")
return
elif self.adj_wpm == 1: # begin tune
self.keyerSate = self.IDLE
if self.dah_key.value() == self.LOW: # transmit on
self.wpm = self.wpm+1
cw_time.set_wpm(self.wpm)
print("wpm:",self.wpm)
play("-")
elif self.dit_key.value() == self.LOW: #transmit off
self.wpm = self.wpm-1
cw_time.set_wpm(self.wpm)
#print("wpm:",self.wpm)
play(".")
return
elif self.adj_qrg == 1: # begin tune
self.keyerSate = self.IDLE
if self.dah_key.value() == self.LOW: # transmit on
if self.qrg_marke >= len(self.f_liste)-1:
text2cw("max")
else:
self.qrg_marke = self.qrg_marke + 1
tx.set_freq(self.f_liste[self.qrg_marke])
#print("....",self.f_liste[self.qrg_marke])
play("-")
elif self.dit_key.value() == self.LOW: #transmit off
if self.qrg_marke <= 0:
text2cw("min")
else:
self.qrg_marke = self.qrg_marke - 1
tx.set_freq(self.f_liste[self.qrg_marke])
#print("....",self.f_liste[self.qrg_marke])
play(".")
return
else: # wenn commad mode ende dann auch tune :-)
self.tune = 0
self.adj_qrg = 0
self.adj_sidetone = 0
self.adj_wpm = 0
self.adj_sidetone_volume = 0
self.request = 0
if self.keyerState == self.IDLE:
# Wait for direct or latched paddle press
if utime.ticks_ms() > (self.ktimer_end + cw_time.dit_time()*2):
if self.in_char:
self.in_char = False
#print(utime.ticks_ms(),self.ktimer_end)
#print("char",self.char)
if cb.command_state == 1: # "1" ->comand mode
Char = decode(self.char)
# comand mode ----------------
if Char == "i" : # TX enable(on) disable(off)
if self.request == 1: # ? -> request value of ...
if self.tx_enable == 1:
text2cw("on")
else:
text2cw("off")
else: # set / change mode
self.tx_enable = 1 - self.tx_enable
if self.tx_enable == 1:
txopt.on()
text2cw("on")
else:
text2cw("off")
txopt.off()
#print("Transmit", self.tx_enable)
cb.button_command_off()
elif Char == "j" : # HF TX opt enable(on) disable(off)
if self.request == 1:
if self.txt_enable :
text2cw("on")
else:
text2cw("off")
else:
self.txt_enable = not self.txt_enable
if self.txt_enable:
tx.on()
text2cw("on")
else:
text2cw("off")
tx.off()
#print("Transmit", self.txt_enable)
cb.button_command_off()
elif Char == "o" : # sidetone enable(on) disable(off)
if self.request == 1:
#print("CMD-TX:",self.sidetone)
if self.sidetone_enable :
text2cw("on")
else:
text2cw("off")
else:
self.sidetone_enable = not self.sidetone_enable
if self.sidetone_enable:
cwt.onoff(1)
text2cw("on")
else:
text2cw("off")
cwt.onoff(0)
cb.button_command_off()
#print("sidetone", self.tx_enable)
elif Char == "t" : # tune mode
#print("CMD-tune:",self.tune)
self.tune = 1
if self.tune:
text2cw("on")
elif Char == "w" : # WPM Change Speed )
if self.request == 1:
#print("CMD-wpm:",self.wpm)
text2cw(str(self.wpm))
else:
self.adj_wpm = 1
if self.tune:
text2cw("on")
elif Char == "v" : # sidetone volume controll
if self.request == 1:
text2cw(str(self.sidetone_volume))
else:
self.adj_sidetone_volume = 1
elif Char == "?" : # request of parameters
self.request = 1
elif Char == "x" : # command exit
cb.button_command_off()
elif Char == "f" : # adjust sidetone frequenz
if self.request == 1:
text2cw(str(self.sidetone_freq))
else:
self.adj_sidetone = 1
elif Char == "q" : # adjust qrg
if self.request == 1:
text2cw(str(self.f_liste[self.qrg_marke]))
else:
self.adj_qrg = 1
elif Char == "m" : # Iambic mode a/b
if self.request == 1:
if self.iambic_mode== 16 : text2cw("b")
else : text2cw("a")
elif Char == "a" : # adjust sidetone frequenz
self.iambic_mode = 0 # 0x10 # 0 for Iambic A, 1 for Iambic B
cb.button_command_off()
elif Char == "s" : # save parameter afer change
self.write_jsondata()
text2cw("save")
cb.button_command_off()
elif Char == "b" : # adjust sidetone frequenz
self.iambic_mode = 0x10 # 0x10 # 0 for Iambic A, 1 for Iambic B
cb.button_command_off()
else :
print(decode(self.char))
self.char = ""
# #send(decode(self.char))
# self.char = ""
if ((self.dit_key.value() == self.LOW) or (self.dah_key.value() == self.LOW) or (self.keyerControl & 0x03)):
self.update_PaddleLatch()
self.keyerState = self.CHK_DIT
elif self.keyerState == self.CHK_DIT:
#See if the dit paddle was pressed
if (self.keyerControl & self.DIT_L):
self.keyerControl |= self.DIT_PROC
self.ktimer = cw_time.dit_time()
self.keyerState = self.KEYED_PREP
self.in_char = True
self.in_word = True
self.char += "."
else:
self.keyerState = self.CHK_DAH;
elif self.keyerState == self.CHK_DAH:
#See if dah paddle was pressed
if (self.keyerControl & self.DAH_L):
self.ktimer = cw_time.dit_time()*3
self.keyerState = self.KEYED_PREP
self.in_char = True
self.in_word = True
self.char += "-"
else:
self.keyerState = self.IDLE;
elif self.keyerState == self.KEYED_PREP:
#print("Prep")
#Assert key down, start timing, state shared for dit or dah
#digitalWrite(ledPin, HIGH); // turn the LED on
self.Key_state = self.HIGH
cw(True)
self.ktimer += utime.ticks_ms() # set ktimer to interval end time
self.keyerControl &= ~(self.DIT_L + self.DAH_L) # clear both paddle latch bits
self.keyerState = self.KEYED # next state
elif self.keyerState == self.KEYED:
if (utime.ticks_ms() > self.ktimer): #are we at end of key down?
self.Key_sate = 0
cw(False)
self.ktimer = utime.ticks_ms()+ cw_time.dit_time() #inter-elemet time
self.keyerState = self.INTER_ELEMENT #next state
else:
if (self.keyerControl & self.iambic_mode):
self.update_PaddleLatch() # early paddle latch in Iambic B mode
elif self.keyerState == self.INTER_ELEMENT:
self.update_PaddleLatch() #latch paddle state
if (utime.ticks_ms() > self.ktimer): #are we at end of inter-space ?
self.ktimer_end = utime.ticks_ms()
if (self.keyerControl & self.DIT_PROC): # was it a dir or dah?
self.keyerControl &= ~(self.DIT_L + self.DIT_PROC) #clear two bits
self.keyerState = self.CHK_DAH #dit done, check for dah
#print(utime.ticks_ms(),self.ktimer_end)
else:
self.keyerControl &= ~(self.DAH_L) #clear dah latch
self.keyerState = self.IDLE #go idle
# transmit pattern
def play(pattern):
#print("play")
for sound in pattern:
if sound == '.':
cw(True)
#print(uutime.ticks_ms()())
utime.sleep(cw_time.dit_time()/1000)
#print(uutime.ticks_ms())
cw(False)
utime.sleep(cw_time.dit_time()/1000)
elif sound == '-':
cw(True)
utime.sleep(3*cw_time.dit_time()/1000)
cw(False)
utime.sleep(cw_time.dit_time()/1000)
elif sound == ' ':
utime.sleep(4*cw_time.dit_time()/1000)
utime.sleep(2*cw_time.dit_time()/1000)
def text2cw(str):
for c in str:
play(encode(c))
#----------------------------------------
# Setup Hardware pin on rp2040
comand_button = 15
onboard_led = 25
extern_led = 11 # is in snc with interne led_onboard
tx_opt_pin = 10
#tx_pin = 18
cw_sound_pin = 22
paddle_left_pin = 17
paddle_right_pin = 18
#----------------------------------------
#paddle instance
print("keyer")
# user class
tx = transceiver()
tx.off()
txopt = tx_opt(tx_opt_pin)
cwt = cw_sound(cw_sound_pin)
cw_time = cw_timing(18)
cb = command_button(comand_button,onboard_led,extern_led)
iambic = Iambic(paddle_left_pin,paddle_right_pin)
text2cw("r")
#--------
while True:
iambic.cycle()