2022-07-16 19:01:18 +00:00
|
|
|
|
2022-07-17 09:28:47 +00:00
|
|
|
# morse code analyser
|
2022-07-16 19:01:18 +00:00
|
|
|
from PicoAirQuality import KitronikBME688, KitronikButton, KitronikDataLogger, \
|
|
|
|
KitronikOLED, KitronikRTC, KitronikZIPLEDs,\
|
|
|
|
KitronikBuzzer
|
|
|
|
import time
|
2022-07-17 10:41:12 +00:00
|
|
|
|
2022-07-16 19:01:18 +00:00
|
|
|
#from datetime import datetime
|
|
|
|
|
|
|
|
logFileName = "atmosphere_log.txt"
|
2022-07-17 10:41:12 +00:00
|
|
|
mindex=0
|
|
|
|
morse = []
|
2022-07-16 19:01:18 +00:00
|
|
|
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()
|
2022-07-17 09:28:47 +00:00
|
|
|
last_pv = 0
|
2022-07-17 09:58:04 +00:00
|
|
|
last_tt = 0
|
2022-07-17 10:41:12 +00:00
|
|
|
spurious = 0 # interrupts are often repeated for the low level
|
|
|
|
|
2022-07-16 20:55:29 +00:00
|
|
|
# make this array size 20. A morse char of 5 dots|dashes
|
|
|
|
# would take up 10 slots max.
|
|
|
|
#
|
|
|
|
|
2022-07-17 09:28:47 +00:00
|
|
|
|
2022-07-16 20:55:29 +00:00
|
|
|
class buttonEvent:
|
2022-07-17 09:28:47 +00:00
|
|
|
#mstimestamp = 0
|
|
|
|
#pinstate = 0
|
2022-07-16 20:55:29 +00:00
|
|
|
def __init__(self, mststamp, pinst):
|
|
|
|
buttonEvent.mstimestamp = mststamp
|
|
|
|
buttonEvent.pinstate = pinst
|
|
|
|
#def str(self):
|
|
|
|
#return "mstimestamp:",str(mstimestamp), "pinst ",str(pinstate)
|
|
|
|
|
2022-07-17 09:58:04 +00:00
|
|
|
|
2022-07-16 20:55:29 +00:00
|
|
|
#def ButtonB_r_IRQHandler(pin):
|
|
|
|
# global buttonB
|
|
|
|
# buttonB = 2*60
|
|
|
|
# print("button B pressed", buttonB)
|
2022-07-16 19:01:18 +00:00
|
|
|
|
|
|
|
def ButtonB_f_IRQHandler(pin):
|
2022-07-17 10:41:12 +00:00
|
|
|
global last_pv, last_tt, spurious, mindex
|
2022-07-16 20:55:29 +00:00
|
|
|
pv = pin.value()
|
2022-07-17 09:28:47 +00:00
|
|
|
tt = time.ticks_ms()
|
2022-07-17 10:41:12 +00:00
|
|
|
#print("button B IRQ", tt, pv)
|
2022-07-17 09:28:47 +00:00
|
|
|
if last_pv == pv : # get get spurious 0 level ints
|
2022-07-17 10:41:12 +00:00
|
|
|
#print("two ints @ same level in a row",pv) # ignore
|
|
|
|
spurious += 1
|
2022-07-16 20:55:29 +00:00
|
|
|
else:
|
2022-07-17 10:41:12 +00:00
|
|
|
#b=buttonEvent(time.ticks_ms(),pv)
|
2022-07-17 09:58:04 +00:00
|
|
|
d = tt - last_tt
|
|
|
|
if pv:
|
2022-07-17 10:41:12 +00:00
|
|
|
#print(" duration of inter-m space ", d)
|
|
|
|
if d < 600:
|
|
|
|
print (" ")
|
|
|
|
else:
|
|
|
|
print (" interval ")
|
|
|
|
mindex += 1;
|
2022-07-17 09:58:04 +00:00
|
|
|
beeper.playTone(600)
|
|
|
|
else:
|
2022-07-17 10:41:12 +00:00
|
|
|
#print(" duration of press ", d)
|
2022-07-17 09:58:04 +00:00
|
|
|
if d > 300:
|
2022-07-17 10:41:12 +00:00
|
|
|
morse.append("-");
|
2022-07-17 09:58:04 +00:00
|
|
|
print ("DAH")
|
|
|
|
else:
|
2022-07-17 10:41:12 +00:00
|
|
|
morse.append(".");
|
2022-07-17 09:58:04 +00:00
|
|
|
print ("DIT")
|
|
|
|
beeper.stopTone()
|
2022-07-16 20:55:29 +00:00
|
|
|
last_pv = pv
|
2022-07-17 09:58:04 +00:00
|
|
|
last_tt = tt
|
2022-07-16 19:01:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
2022-07-17 10:41:12 +00:00
|
|
|
def decode_morse():
|
|
|
|
global morse
|
|
|
|
dm_a = [".","-"]
|
|
|
|
dm_b = ["-",".",".","."]
|
|
|
|
dm_e = ["."]
|
|
|
|
dm_i = [".","."]
|
|
|
|
dm_s = [".",".","."]
|
|
|
|
if morse == dm_e:
|
|
|
|
print ("E")
|
|
|
|
if morse == dm_a:
|
|
|
|
print ("A")
|
|
|
|
if morse == dm_i:
|
|
|
|
print ("I")
|
|
|
|
if morse == dm_s:
|
|
|
|
print ("S")
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-07-17 09:28:47 +00:00
|
|
|
def process_morse():
|
2022-07-17 10:41:12 +00:00
|
|
|
global last_tt, morse
|
|
|
|
tt = time.ticks_ms()
|
|
|
|
if (tt - last_tt) > 600:
|
|
|
|
# morse chacter complete
|
|
|
|
if (len(morse) > 0):
|
|
|
|
print(morse)
|
|
|
|
decode_morse()
|
|
|
|
morse = []
|
2022-07-16 19:01:18 +00:00
|
|
|
oled.clear()
|
|
|
|
oled.displayText(rtc.readDateString(), 1, 25)
|
|
|
|
oled.displayText(rtc.readTimeString(), 2, 33)
|
2022-07-17 09:58:04 +00:00
|
|
|
#oled.displayText(str(mcount), 4, 33)
|
2022-07-17 09:28:47 +00:00
|
|
|
oled.show()
|
2022-07-17 10:41:12 +00:00
|
|
|
|
2022-07-17 09:28:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
while True:
|
|
|
|
# maybe a function can have a global ref, yeah maybe the main cont. another wanky aspect ogf pythion
|
2022-07-17 09:58:04 +00:00
|
|
|
process_morse()
|
|
|
|
##process_morse2()
|
|
|
|
#time.sleep(1.0)
|
2022-07-17 09:28:47 +00:00
|
|
|
|