morseanalyser/main.py
Robin Clark ce1ea4d0e8 k the python list out and used context sensitive
variables (times) to determine dit dah OR SPACE
2022-07-17 10:58:04 +01:00

100 lines
2.8 KiB
Python

# morse code analyser
from PicoAirQuality import KitronikBME688, KitronikButton, KitronikDataLogger, \
KitronikOLED, KitronikRTC, KitronikZIPLEDs,\
KitronikBuzzer
import time
from array import array
#from datetime import datetime
logFileName = "atmosphere_log.txt"
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)
bme688.setupGasSensor()
bme688.calcBaselines()
sec = 0
#f = open(logFileName, 'a')
#f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
beeper = KitronikBuzzer()
buttons = KitronikButton()
last_pv = 0
last_tt = 0
# make this array size 20. A morse char of 5 dots|dashes
# would take up 10 slots max.
#
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 ButtonB_f_IRQHandler(pin):
global last_pv, last_tt
pv = pin.value()
tt = time.ticks_ms()
print("button B IRQ", tt, pv)
if last_pv == pv : # get get spurious 0 level ints
print("two ints @ same level in a row",pv) # ignore
else:
b=buttonEvent(time.ticks_ms(),pv)
d = tt - last_tt
if pv:
print(" duration of inter-m space ", d)
beeper.playTone(600)
else:
print(" duration of press ", d)
if d > 300:
print ("DAH")
else:
print ("DIT")
beeper.stopTone()
last_pv = pv
last_tt = tt
# 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)
def process_morse():
#global mbuf # : why python WHY: why muck everyone about with local fucking copies your sxdjhklazsedfbokhjlfvbegrhjk
#global mbuf, mindex, mindex_t, mcount, mmaxindex, oled, old_m_count
#for i in range (0,mmaxindex-1):
#be = mbuf[i]
#print ("be ", be.timestampms, be.pinstate )
oled.clear()
oled.displayText(rtc.readDateString(), 1, 25)
oled.displayText(rtc.readTimeString(), 2, 33)
#oled.displayText(str(mcount), 4, 33)
oled.show()
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)