went more context sensitive and it seem to be working better
This commit is contained in:
parent
ce1ea4d0e8
commit
17950325f3
57
main.py
57
main.py
@ -4,12 +4,12 @@ from PicoAirQuality import KitronikBME688, KitronikButton, KitronikDataLogger,
|
||||
KitronikOLED, KitronikRTC, KitronikZIPLEDs,\
|
||||
KitronikBuzzer
|
||||
import time
|
||||
from array import array
|
||||
|
||||
#from datetime import datetime
|
||||
|
||||
logFileName = "atmosphere_log.txt"
|
||||
|
||||
|
||||
mindex=0
|
||||
morse = []
|
||||
bme688 = KitronikBME688()
|
||||
oled = KitronikOLED()
|
||||
rtc = KitronikRTC()
|
||||
@ -28,6 +28,8 @@ beeper = KitronikBuzzer()
|
||||
buttons = KitronikButton()
|
||||
last_pv = 0
|
||||
last_tt = 0
|
||||
spurious = 0 # interrupts are often repeated for the low level
|
||||
|
||||
# make this array size 20. A morse char of 5 dots|dashes
|
||||
# would take up 10 slots max.
|
||||
#
|
||||
@ -49,23 +51,31 @@ class buttonEvent:
|
||||
# print("button B pressed", buttonB)
|
||||
|
||||
def ButtonB_f_IRQHandler(pin):
|
||||
global last_pv, last_tt
|
||||
global last_pv, last_tt, spurious, mindex
|
||||
pv = pin.value()
|
||||
tt = time.ticks_ms()
|
||||
print("button B IRQ", tt, pv)
|
||||
#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
|
||||
#print("two ints @ same level in a row",pv) # ignore
|
||||
spurious += 1
|
||||
else:
|
||||
b=buttonEvent(time.ticks_ms(),pv)
|
||||
#b=buttonEvent(time.ticks_ms(),pv)
|
||||
d = tt - last_tt
|
||||
if pv:
|
||||
print(" duration of inter-m space ", d)
|
||||
#print(" duration of inter-m space ", d)
|
||||
if d < 600:
|
||||
print (" ")
|
||||
else:
|
||||
print (" interval ")
|
||||
mindex += 1;
|
||||
beeper.playTone(600)
|
||||
else:
|
||||
print(" duration of press ", d)
|
||||
#print(" duration of press ", d)
|
||||
if d > 300:
|
||||
morse.append("-");
|
||||
print ("DAH")
|
||||
else:
|
||||
morse.append(".");
|
||||
print ("DIT")
|
||||
beeper.stopTone()
|
||||
last_pv = pv
|
||||
@ -76,14 +86,33 @@ def ButtonB_f_IRQHandler(pin):
|
||||
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 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")
|
||||
|
||||
|
||||
|
||||
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 )
|
||||
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 = []
|
||||
oled.clear()
|
||||
oled.displayText(rtc.readDateString(), 1, 25)
|
||||
oled.displayText(rtc.readTimeString(), 2, 33)
|
||||
|
Loading…
Reference in New Issue
Block a user