Compare commits
No commits in common. "17950325f3938e3961865f04a65490b486bb52cf" and "cb9504288994daa979cc9365b56c6ecdeef0e13e" have entirely different histories.
17950325f3
...
cb95042889
139
main.py
139
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()
|
||||||
@ -26,10 +26,13 @@ sec = 0
|
|||||||
|
|
||||||
beeper = KitronikBuzzer()
|
beeper = KitronikBuzzer()
|
||||||
buttons = KitronikButton()
|
buttons = KitronikButton()
|
||||||
|
mmaxindex = 20
|
||||||
|
mbuf = [] # array/list(buttonEvent) this should be global by default RIGGHT????
|
||||||
|
mindex = 0 # head new button events
|
||||||
|
mindex_t = 0 # tail unprocessed button events
|
||||||
|
mcount = 0
|
||||||
|
old_m_count = 0
|
||||||
last_pv = 0
|
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
|
# make this array size 20. A morse char of 5 dots|dashes
|
||||||
# would take up 10 slots max.
|
# would take up 10 slots max.
|
||||||
#
|
#
|
||||||
@ -44,6 +47,13 @@ class buttonEvent:
|
|||||||
#def str(self):
|
#def str(self):
|
||||||
#return "mstimestamp:",str(mstimestamp), "pinst ",str(pinstate)
|
#return "mstimestamp:",str(mstimestamp), "pinst ",str(pinstate)
|
||||||
|
|
||||||
|
# this pythin list is doing my head in, why cant they just ahve arrays like normal langauages
|
||||||
|
#
|
||||||
|
for i in range (0,30):
|
||||||
|
b = buttonEvent(0,0)
|
||||||
|
print (" inserting a dummy entry into the stupid list object ", i)
|
||||||
|
mbuf.insert(i,b)
|
||||||
|
print (" how can it xcomplaIN NOW THE LIST IS FULL OF OBJECTS ",)
|
||||||
|
|
||||||
#def ButtonB_r_IRQHandler(pin):
|
#def ButtonB_r_IRQHandler(pin):
|
||||||
# global buttonB
|
# global buttonB
|
||||||
@ -51,79 +61,92 @@ 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, spurious, mindex
|
#now = time.now()
|
||||||
|
global buttonB, last_pv
|
||||||
|
global mbuf, mindex, mcount, mmaxindex
|
||||||
pv = pin.value()
|
pv = pin.value()
|
||||||
tt = time.ticks_ms()
|
tt = time.ticks_ms()
|
||||||
#print("button B IRQ", tt, pv)
|
buttonB = 2*60 # maKES leds LIGHT IN AIRq
|
||||||
|
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
|
# no no no!!! mbuf.insert(mindex,b)
|
||||||
if pv:
|
mbuf[mindex] = b # why cant i do this arrrgghhhnhhh all I want is a fucking array
|
||||||
#print(" duration of inter-m space ", d)
|
print ("b", str(b.mstimestamp), str(b.pinstate)) # arghhh why is it not storing thsi
|
||||||
if d < 600:
|
print ("mbuf inserting ",str( time.ticks_ms()), str(pv), "@", str(mindex), mbuf)
|
||||||
print (" ")
|
b3 = mbuf[mindex] # shit bag that should store it
|
||||||
else:
|
print ("did shit bag python actually put this in the list??", b3.pinstate, b3)
|
||||||
print (" interval ")
|
# it would appear the shitbag python did store this
|
||||||
mindex += 1;
|
mcount += 1
|
||||||
beeper.playTone(600)
|
mindex += 1
|
||||||
else:
|
mindex = mindex % mmaxindex
|
||||||
#print(" duration of press ", d)
|
if pv:
|
||||||
if d > 300:
|
beeper.playTone(600)
|
||||||
morse.append("-");
|
else:
|
||||||
print ("DAH")
|
beeper.stopTone()
|
||||||
else:
|
|
||||||
morse.append(".");
|
|
||||||
print ("DIT")
|
|
||||||
beeper.stopTone()
|
|
||||||
last_pv = pv
|
last_pv = pv
|
||||||
last_tt = tt
|
|
||||||
|
|
||||||
|
|
||||||
# FALLING DOES NOT WORK AND IRQ_LOW_LEVEL not recognised
|
# 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_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_morse2():
|
||||||
|
# ok the mbuf is driving me bonkers. keeps going local or something
|
||||||
|
global mbuf
|
||||||
|
for i in range (0,mmaxindex-1):
|
||||||
|
be = mbuf[i]
|
||||||
|
print ("be ", i, be.mstimestamp, be.pinstate )
|
||||||
|
|
||||||
def process_morse():
|
def process_morse():
|
||||||
global last_tt, morse
|
#global mbuf # : why python WHY: why muck everyone about with local fucking copies your sxdjhklazsedfbokhjlfvbegrhjk
|
||||||
tt = time.ticks_ms()
|
global mbuf, mindex, mindex_t, mcount, mmaxindex, oled, old_m_count
|
||||||
if (tt - last_tt) > 600:
|
#for i in range (0,mmaxindex-1):
|
||||||
# morse chacter complete
|
#be = mbuf[i]
|
||||||
if (len(morse) > 0):
|
#print ("be ", be.timestampms, be.pinstate )
|
||||||
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)
|
||||||
#oled.displayText(str(mcount), 4, 33)
|
oled.displayText(str(mcount), 4, 33)
|
||||||
|
# process the list
|
||||||
|
if (mcount - old_m_count) >= 2:
|
||||||
|
print("(mcount - old_m_count) >= 2", mbuf, " mindex_t ", mindex_t)
|
||||||
|
b1 = mbuf[(mindex_t)%mmaxindex]
|
||||||
|
b2 = mbuf[(mindex_t+1)%mmaxindex]
|
||||||
|
# ok shitbag python why is the pinstate in that object now zero you turd
|
||||||
|
#print("b1 index", str((mindex_t+mmaxindex)%mmaxindex), "b1 ps", str(b1.pinstate))
|
||||||
|
#print("b2 index", str((mindex_t+mmaxindex+1)%mmaxindex), "b2 ps ", str(b2.pinstate))
|
||||||
|
print("b1", b1, b1.pinstate, "@ mbuf[", str((mindex_t+mmaxindex)%mmaxindex), "]")
|
||||||
|
print("b2", b2, b2.pinstate, "@ mbuf[", str((mindex_t+1)%mmaxindex), "]")
|
||||||
|
print(" b1 ts ps ", b1.mstimestamp, b1.pinstate, "b2 ts ps", b2.mstimestamp, b2.pinstate)
|
||||||
|
if b1.pinstate == 1 and b2.pinstate == 0:
|
||||||
|
print(" high to low pinstate valid press", b1.pinstate, b2.pinstate)
|
||||||
|
# press and release found
|
||||||
|
duration = b2.mstimestamp - b1.mstimestamp
|
||||||
|
if duration < 300:
|
||||||
|
oled.displayText('dit '+str(duration), 5, 33)
|
||||||
|
else:
|
||||||
|
oled.displayText('dah '+str(duration), 5, 33)
|
||||||
|
mindex_t += 2;
|
||||||
|
mindex_t = mindex_t % mmaxindex
|
||||||
|
mcount -= 2
|
||||||
|
else:
|
||||||
|
print(" undefined pinstate order", b1.pinstate, b2.pinstate)
|
||||||
|
mindex_t += 1 # that one made no sense so move up
|
||||||
|
mindex_t = mindex_t % mmaxindex
|
||||||
|
mcount -= 1
|
||||||
|
oled.displayText('BAH ', 5, 33)
|
||||||
|
old_m_count = mcount
|
||||||
oled.show()
|
oled.show()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# maybe a function can have a global ref, yeah maybe the main cont. another wanky aspect ogf pythion
|
# maybe a function can have a global ref, yeah maybe the main cont. another wanky aspect ogf pythion
|
||||||
process_morse()
|
#process_morse()
|
||||||
##process_morse2()
|
process_morse2()
|
||||||
#time.sleep(1.0)
|
time.sleep(1.0)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user