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,\
|
KitronikOLED, KitronikRTC, KitronikZIPLEDs,\
|
||||||
KitronikBuzzer
|
KitronikBuzzer
|
||||||
import time
|
import time
|
||||||
from array import array
|
|
||||||
#from datetime import datetime
|
#from datetime import datetime
|
||||||
|
|
||||||
logFileName = "atmosphere_log.txt"
|
logFileName = "atmosphere_log.txt"
|
||||||
|
mindex=0
|
||||||
|
morse = []
|
||||||
bme688 = KitronikBME688()
|
bme688 = KitronikBME688()
|
||||||
oled = KitronikOLED()
|
oled = KitronikOLED()
|
||||||
rtc = KitronikRTC()
|
rtc = KitronikRTC()
|
||||||
@ -28,6 +28,8 @@ beeper = KitronikBuzzer()
|
|||||||
buttons = KitronikButton()
|
buttons = KitronikButton()
|
||||||
last_pv = 0
|
last_pv = 0
|
||||||
last_tt = 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
|
# make this array size 20. A morse char of 5 dots|dashes
|
||||||
# would take up 10 slots max.
|
# would take up 10 slots max.
|
||||||
#
|
#
|
||||||
@ -49,23 +51,31 @@ class buttonEvent:
|
|||||||
# print("button B pressed", buttonB)
|
# print("button B pressed", buttonB)
|
||||||
|
|
||||||
def ButtonB_f_IRQHandler(pin):
|
def ButtonB_f_IRQHandler(pin):
|
||||||
global last_pv, last_tt
|
global last_pv, last_tt, spurious, mindex
|
||||||
pv = pin.value()
|
pv = pin.value()
|
||||||
tt = time.ticks_ms()
|
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
|
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:
|
else:
|
||||||
b=buttonEvent(time.ticks_ms(),pv)
|
#b=buttonEvent(time.ticks_ms(),pv)
|
||||||
d = tt - last_tt
|
d = tt - last_tt
|
||||||
if pv:
|
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)
|
beeper.playTone(600)
|
||||||
else:
|
else:
|
||||||
print(" duration of press ", d)
|
#print(" duration of press ", d)
|
||||||
if d > 300:
|
if d > 300:
|
||||||
|
morse.append("-");
|
||||||
print ("DAH")
|
print ("DAH")
|
||||||
else:
|
else:
|
||||||
|
morse.append(".");
|
||||||
print ("DIT")
|
print ("DIT")
|
||||||
beeper.stopTone()
|
beeper.stopTone()
|
||||||
last_pv = pv
|
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_FALLING|machine.Pin.IRQ_RISING, handler=ButtonB_f_IRQHandler)
|
||||||
#buttons.buttonB.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonB_r_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():
|
def process_morse():
|
||||||
#global mbuf # : why python WHY: why muck everyone about with local fucking copies your sxdjhklazsedfbokhjlfvbegrhjk
|
global last_tt, morse
|
||||||
#global mbuf, mindex, mindex_t, mcount, mmaxindex, oled, old_m_count
|
tt = time.ticks_ms()
|
||||||
#for i in range (0,mmaxindex-1):
|
if (tt - last_tt) > 600:
|
||||||
#be = mbuf[i]
|
# morse chacter complete
|
||||||
#print ("be ", be.timestampms, be.pinstate )
|
if (len(morse) > 0):
|
||||||
|
print(morse)
|
||||||
|
decode_morse()
|
||||||
|
morse = []
|
||||||
oled.clear()
|
oled.clear()
|
||||||
oled.displayText(rtc.readDateString(), 1, 25)
|
oled.displayText(rtc.readDateString(), 1, 25)
|
||||||
oled.displayText(rtc.readTimeString(), 2, 33)
|
oled.displayText(rtc.readTimeString(), 2, 33)
|
||||||
|
Loading…
Reference in New Issue
Block a user