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-16 20:55:29 +00:00
|
|
|
from array import array
|
2022-07-16 19:01:18 +00:00
|
|
|
#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()
|
2022-07-17 09:28:47 +00:00
|
|
|
last_pv = 0
|
2022-07-17 09:58:04 +00:00
|
|
|
last_tt = 0
|
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 09:58:04 +00:00
|
|
|
global last_pv, last_tt
|
2022-07-16 20:55:29 +00:00
|
|
|
pv = pin.value()
|
2022-07-17 09:28:47 +00:00
|
|
|
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
|
2022-07-16 20:55:29 +00:00
|
|
|
else:
|
2022-07-17 09:28:47 +00:00
|
|
|
b=buttonEvent(time.ticks_ms(),pv)
|
2022-07-17 09:58:04 +00:00
|
|
|
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()
|
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 09:58:04 +00:00
|
|
|
|
2022-07-17 09:28:47 +00:00
|
|
|
|
|
|
|
def process_morse():
|
|
|
|
#global mbuf # : why python WHY: why muck everyone about with local fucking copies your sxdjhklazsedfbokhjlfvbegrhjk
|
2022-07-17 09:58:04 +00:00
|
|
|
#global mbuf, mindex, mindex_t, mcount, mmaxindex, oled, old_m_count
|
2022-07-17 09:28:47 +00:00
|
|
|
#for i in range (0,mmaxindex-1):
|
|
|
|
#be = mbuf[i]
|
|
|
|
#print ("be ", be.timestampms, be.pinstate )
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|