From 77430c7d920b84715542234f638620e49ad2cae8 Mon Sep 17 00:00:00 2001 From: Robin Clark Date: Fri, 29 Jul 2022 21:10:44 +0100 Subject: [PATCH] fixed some chars displayed as ? allowed a RATE CHANGE ON BUTTON a Ms FOR DIT --- main.py | 95 +++++++++++++++++++++++++-------------------------------- 1 file changed, 41 insertions(+), 54 deletions(-) diff --git a/main.py b/main.py index b7baf21..d48ef9f 100644 --- a/main.py +++ b/main.py @@ -5,22 +5,16 @@ from PicoAirQuality import KitronikBME688, KitronikButton, KitronikDataLogger, KitronikBuzzer import time -#from datetime import datetime - -logFileName = "atmosphere_log.txt" mindex=0 morse = [] -#bme688 = KitronikBME688() oled = KitronikOLED() rtc = KitronikRTC() zipleds = KitronikZIPLEDs(3) -# Python u arse hole sec = Integer() rtc.setDate(16, 7, 2022) rtc.setTime(12, 10, 0) -rate = 60 # 20 wpm -#bme688.setupGasSensor() -#bme688.calcBaselines() -sec = 0 +rate = 50 # 20 wpm + +#sec = 0 #f = open(logFileName, 'a') #f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n") @@ -29,26 +23,22 @@ buttons = KitronikButton() last_pv = 0 last_tt = 0 spurious = 0 # interrupts are often repeated for the low level +button_state = 0 # on==1 off==0 -# make this array size 20. A morse char of 5 dots|dashes -# would take up 10 slots max. -# +def header(): + global rate, oled + s = "Morse rate " + str(rate) + " mS" + oled.displayText(s,1,0) -class buttonEvent: - #mstimestamp = 0 - #pinstate = 0 - def __init__(self, mststamp, pinst): - buttonEvent.mstimestamp = mststamp - buttonEvent.pinstate = pinst - #def str(self): - #return "mstimestamp:",str(mstimestamp), "pinst ",str(pinstate) - - -#def ButtonB_r_IRQHandler(pin): -# global buttonB -# buttonB = 2*60 -# print("button B pressed", buttonB) +def ButtonA_f_IRQHandler(pin): + global rate, oled + rate += 10 + if rate > 100: + rate = 40 + oled.clear() + header() + print (" IRQ button A" + str(rate)) def ButtonB_f_IRQHandler(pin): global last_pv, last_tt, spurious, mindex @@ -66,9 +56,10 @@ def ButtonB_f_IRQHandler(pin): if d < rate*3: print (" ") else: - print (" interval ") + print (" ipi ") mindex += 1; beeper.playTone(600) + button_state = 1 else: #print(" duration of press ", d) if d > rate*3: @@ -78,13 +69,14 @@ def ButtonB_f_IRQHandler(pin): morse.append("."); print ("DIT") beeper.stopTone() + button_state = 0 last_pv = pv last_tt = tt - + +buttons.buttonB.irq(trigger=machine.Pin.IRQ_FALLING|machine.Pin.IRQ_RISING, \ + handler=ButtonB_f_IRQHandler) -# FALLING DOES NOT WORK AND IRQ_LOW_LEVEL not recognised -buttons.buttonB.irq(trigger=machine.Pin.IRQ_FALLING|machine.Pin.IRQ_RISING, handler=ButtonB_f_IRQHandler) -#buttons.buttonB.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonB_r_IRQHandler) +buttons.buttonA.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonA_f_IRQHandler) charbuf = [] hpm=10 @@ -94,7 +86,7 @@ def printm(mchar): charbuf.append(mchar) chcnt = 0 oled.clear() - oled.displayText("Morse rxd",1,2) + header() while len(charbuf) > (4*20): charbuf.pop(0) # get rid of old morse for i in range(2,6): @@ -160,7 +152,7 @@ def decode_morse(): if morse == dm_f: return ("F") if morse == dm_g: - print ("G") + return ("G") if morse == dm_h: return ("H") if morse == dm_i: @@ -168,7 +160,7 @@ def decode_morse(): if morse == dm_j: return ("J") if morse == dm_k: - print ("K") + return ("K") if morse == dm_l: return ("L") if morse == dm_m: @@ -227,31 +219,26 @@ last_sp = 0 def process_morse(): global last_tt, morse, last_was_space, last_sp tt = time.ticks_ms() - if (tt - last_tt) > rate*6: - # morse chacter complete - if (len(morse) > 0): - #print(morse) - printm(decode_morse()) - morse = [] - last_was_space = 0 - last_sp = last_tt - #oled.clear() - #oled.displayText(rtc.readDateString(), 1, 25) - #oled.displayText(rtc.readTimeString(), 2, 33) - #oled.displayText(str(mcount), 4, 33) - #oled.show() + if (button_state == 0): + if (tt - last_tt) > rate*6: + # morse chacter complete + if (len(morse) > 0): + #print(morse) + printm(decode_morse()) + morse = [] + last_was_space = 0 + last_sp = last_tt + if (tt - last_sp) > rate*22 : # and last_not_space == 0: - if last_was_space == 0: - printm(" "); - last_was_space = 1 # dont keep repeating inter word spaces - + if last_was_space == 0: + printm(" "); + last_was_space = 1 # dont keep repeating inter word spaces + last_sp = last_tt while True: - # maybe a function can have a global ref, yeah maybe the main cont. another wanky aspect ogf pythion process_morse() - ##process_morse2() - #time.sleep(1.0) + \ No newline at end of file