python lists are crap

This commit is contained in:
Robin Clark 2022-07-17 10:28:47 +01:00
parent 567ece4ccc
commit cb95042889

85
main.py
View File

@ -1,5 +1,5 @@
# A weather station program display the date, time, temperature and humidity on the OLED screen with Air Quality and eCO2 on ZIP LEDs (Red/Green) # morse code analyser
from PicoAirQuality import KitronikBME688, KitronikButton, KitronikDataLogger, \ from PicoAirQuality import KitronikBME688, KitronikButton, KitronikDataLogger, \
KitronikOLED, KitronikRTC, KitronikZIPLEDs,\ KitronikOLED, KitronikRTC, KitronikZIPLEDs,\
KitronikBuzzer KitronikBuzzer
@ -26,27 +26,35 @@ 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
# 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.
# #
class buttonEvent: class buttonEvent:
mstimestamp = 0 #mstimestamp = 0
pinstate = 0 #pinstate = 0
def __init__(self, mststamp, pinst): def __init__(self, mststamp, pinst):
buttonEvent.mstimestamp = mststamp buttonEvent.mstimestamp = mststamp
buttonEvent.pinstate = pinst buttonEvent.pinstate = pinst
#def str(self): #def str(self):
#return "mstimestamp:",str(mstimestamp), "pinst ",str(pinstate) #return "mstimestamp:",str(mstimestamp), "pinst ",str(pinstate)
mmaxindex = 20 # this pythin list is doing my head in, why cant they just ahve arrays like normal langauages
mbuf = [] # array(buttonEvent) #
mindex = 0 # head new button events for i in range (0,30):
mindex_t = 0 # tail unprocessed button events b = buttonEvent(0,0)
mcount = 0 print (" inserting a dummy entry into the stupid list object ", i)
old_m_count = 0 mbuf.insert(i,b)
last_pv = 0 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
# buttonB = 2*60 # buttonB = 2*60
@ -55,18 +63,20 @@ last_pv = 0
def ButtonB_f_IRQHandler(pin): def ButtonB_f_IRQHandler(pin):
#now = time.now() #now = time.now()
global buttonB, last_pv global buttonB, last_pv
global mbuff, mindex, mcount, mmaxindex global mbuf, mindex, mcount, mmaxindex
pv = pin.value() pv = pin.value()
tt = time.ticks_ms()
buttonB = 2*60 # maKES leds LIGHT IN AIRq buttonB = 2*60 # maKES leds LIGHT IN AIRq
print("button B IRQ", time.ticks_ms(), pv) print("button B IRQ", tt, pv)
if last_pv == 0 and pin.value() == 0: # get get spurious 0 level ints if last_pv == pv : # get get spurious 0 level ints
print("two zero ints low level in a row") # ignore print("two ints @ same level in a row",pv) # ignore
else: else:
bollocks=buttonEvent(time.ticks_ms(),pv) b=buttonEvent(time.ticks_ms(),pv)
mbuf.insert(mindex,bollocks) # no no no!!! mbuf.insert(mindex,b)
print ("bollocks", str(bollocks.mstimestamp), str(bollocks.pinstate)) # arghhh why is it not storing thsi mbuf[mindex] = b # why cant i do this arrrgghhhnhhh all I want is a fucking array
print ("mbuf inserting ",str( time.ticks_ms()), str(pv), "@", str(mindex)) print ("b", str(b.mstimestamp), str(b.pinstate)) # arghhh why is it not storing thsi
b3 = mbuf[mindex] print ("mbuf inserting ",str( time.ticks_ms()), str(pv), "@", str(mindex), mbuf)
b3 = mbuf[mindex] # shit bag that should store it
print ("did shit bag python actually put this in the list??", b3.pinstate, b3) print ("did shit bag python actually put this in the list??", b3.pinstate, b3)
# it would appear the shitbag python did store this # it would appear the shitbag python did store this
mcount += 1 mcount += 1
@ -83,23 +93,35 @@ 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)
while True:
#global old_m_count 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():
#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 )
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 # process the list
if (mcount - old_m_count) >= 2: if (mcount - old_m_count) >= 2:
print(" old_m_count != mcount >= 2") print("(mcount - old_m_count) >= 2", mbuf, " mindex_t ", mindex_t)
b1 = mbuf[(mindex_t+mmaxindex)%mmaxindex] b1 = mbuf[(mindex_t)%mmaxindex]
b2 = mbuf[(mindex_t+1)%mmaxindex] b2 = mbuf[(mindex_t+1)%mmaxindex]
# ok shitbag python why is the pinstate in that object now zero you turd # 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("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("b2 index", str((mindex_t+mmaxindex+1)%mmaxindex), "b2 ps ", str(b2.pinstate))
print("b1", b1, b1.pinstate) print("b1", b1, b1.pinstate, "@ mbuf[", str((mindex_t+mmaxindex)%mmaxindex), "]")
print("b2", b2, b2.pinstate) print("b2", b2, b2.pinstate, "@ mbuf[", str((mindex_t+1)%mmaxindex), "]")
print(" b1 ps, b2 ps", b1.pinstate, b2.pinstate) print(" b1 ts ps ", b1.mstimestamp, b1.pinstate, "b2 ts ps", b2.mstimestamp, b2.pinstate)
if b1.pinstate == 1 and b2.pinstate == 0: if b1.pinstate == 1 and b2.pinstate == 0:
print(" high to low pinstate valid press", b1.pinstate, b2.pinstate) print(" high to low pinstate valid press", b1.pinstate, b2.pinstate)
# press and release found # press and release found
@ -119,3 +141,12 @@ while True:
oled.displayText('BAH ', 5, 33) oled.displayText('BAH ', 5, 33)
old_m_count = mcount old_m_count = mcount
oled.show() oled.show()
while True:
# maybe a function can have a global ref, yeah maybe the main cont. another wanky aspect ogf pythion
#process_morse()
process_morse2()
time.sleep(1.0)