fixed some chars displayed as ?
allowed a RATE CHANGE ON BUTTON a Ms FOR DIT
This commit is contained in:
parent
a920e282e5
commit
77430c7d92
93
main.py
93
main.py
@ -5,22 +5,16 @@ from PicoAirQuality import KitronikBME688, KitronikButton, KitronikDataLogger,
|
|||||||
KitronikBuzzer
|
KitronikBuzzer
|
||||||
import time
|
import time
|
||||||
|
|
||||||
#from datetime import datetime
|
|
||||||
|
|
||||||
logFileName = "atmosphere_log.txt"
|
|
||||||
mindex=0
|
mindex=0
|
||||||
morse = []
|
morse = []
|
||||||
#bme688 = KitronikBME688()
|
|
||||||
oled = KitronikOLED()
|
oled = KitronikOLED()
|
||||||
rtc = KitronikRTC()
|
rtc = KitronikRTC()
|
||||||
zipleds = KitronikZIPLEDs(3)
|
zipleds = KitronikZIPLEDs(3)
|
||||||
# Python u arse hole sec = Integer()
|
|
||||||
rtc.setDate(16, 7, 2022)
|
rtc.setDate(16, 7, 2022)
|
||||||
rtc.setTime(12, 10, 0)
|
rtc.setTime(12, 10, 0)
|
||||||
rate = 60 # 20 wpm
|
rate = 50 # 20 wpm
|
||||||
#bme688.setupGasSensor()
|
|
||||||
#bme688.calcBaselines()
|
#sec = 0
|
||||||
sec = 0
|
|
||||||
#f = open(logFileName, 'a')
|
#f = open(logFileName, 'a')
|
||||||
#f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
|
#f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
|
||||||
|
|
||||||
@ -29,26 +23,22 @@ buttons = KitronikButton()
|
|||||||
last_pv = 0
|
last_pv = 0
|
||||||
last_tt = 0
|
last_tt = 0
|
||||||
spurious = 0 # interrupts are often repeated for the low level
|
spurious = 0 # interrupts are often repeated for the low level
|
||||||
|
button_state = 0 # on==1 off==0
|
||||||
# make this array size 20. A morse char of 5 dots|dashes
|
|
||||||
# would take up 10 slots max.
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
class buttonEvent:
|
def header():
|
||||||
#mstimestamp = 0
|
global rate, oled
|
||||||
#pinstate = 0
|
s = "Morse rate " + str(rate) + " mS"
|
||||||
def __init__(self, mststamp, pinst):
|
oled.displayText(s,1,0)
|
||||||
buttonEvent.mstimestamp = mststamp
|
|
||||||
buttonEvent.pinstate = pinst
|
|
||||||
#def str(self):
|
|
||||||
#return "mstimestamp:",str(mstimestamp), "pinst ",str(pinstate)
|
|
||||||
|
|
||||||
|
def ButtonA_f_IRQHandler(pin):
|
||||||
#def ButtonB_r_IRQHandler(pin):
|
global rate, oled
|
||||||
# global buttonB
|
rate += 10
|
||||||
# buttonB = 2*60
|
if rate > 100:
|
||||||
# print("button B pressed", buttonB)
|
rate = 40
|
||||||
|
oled.clear()
|
||||||
|
header()
|
||||||
|
print (" IRQ button A" + str(rate))
|
||||||
|
|
||||||
def ButtonB_f_IRQHandler(pin):
|
def ButtonB_f_IRQHandler(pin):
|
||||||
global last_pv, last_tt, spurious, mindex
|
global last_pv, last_tt, spurious, mindex
|
||||||
@ -66,9 +56,10 @@ def ButtonB_f_IRQHandler(pin):
|
|||||||
if d < rate*3:
|
if d < rate*3:
|
||||||
print (" ")
|
print (" ")
|
||||||
else:
|
else:
|
||||||
print (" interval ")
|
print (" ipi ")
|
||||||
mindex += 1;
|
mindex += 1;
|
||||||
beeper.playTone(600)
|
beeper.playTone(600)
|
||||||
|
button_state = 1
|
||||||
else:
|
else:
|
||||||
#print(" duration of press ", d)
|
#print(" duration of press ", d)
|
||||||
if d > rate*3:
|
if d > rate*3:
|
||||||
@ -78,13 +69,14 @@ def ButtonB_f_IRQHandler(pin):
|
|||||||
morse.append(".");
|
morse.append(".");
|
||||||
print ("DIT")
|
print ("DIT")
|
||||||
beeper.stopTone()
|
beeper.stopTone()
|
||||||
|
button_state = 0
|
||||||
last_pv = pv
|
last_pv = pv
|
||||||
last_tt = tt
|
last_tt = tt
|
||||||
|
|
||||||
|
buttons.buttonB.irq(trigger=machine.Pin.IRQ_FALLING|machine.Pin.IRQ_RISING, \
|
||||||
|
handler=ButtonB_f_IRQHandler)
|
||||||
|
|
||||||
# FALLING DOES NOT WORK AND IRQ_LOW_LEVEL not recognised
|
buttons.buttonA.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonA_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)
|
|
||||||
|
|
||||||
charbuf = []
|
charbuf = []
|
||||||
hpm=10
|
hpm=10
|
||||||
@ -94,7 +86,7 @@ def printm(mchar):
|
|||||||
charbuf.append(mchar)
|
charbuf.append(mchar)
|
||||||
chcnt = 0
|
chcnt = 0
|
||||||
oled.clear()
|
oled.clear()
|
||||||
oled.displayText("Morse rxd",1,2)
|
header()
|
||||||
while len(charbuf) > (4*20):
|
while len(charbuf) > (4*20):
|
||||||
charbuf.pop(0) # get rid of old morse
|
charbuf.pop(0) # get rid of old morse
|
||||||
for i in range(2,6):
|
for i in range(2,6):
|
||||||
@ -160,7 +152,7 @@ def decode_morse():
|
|||||||
if morse == dm_f:
|
if morse == dm_f:
|
||||||
return ("F")
|
return ("F")
|
||||||
if morse == dm_g:
|
if morse == dm_g:
|
||||||
print ("G")
|
return ("G")
|
||||||
if morse == dm_h:
|
if morse == dm_h:
|
||||||
return ("H")
|
return ("H")
|
||||||
if morse == dm_i:
|
if morse == dm_i:
|
||||||
@ -168,7 +160,7 @@ def decode_morse():
|
|||||||
if morse == dm_j:
|
if morse == dm_j:
|
||||||
return ("J")
|
return ("J")
|
||||||
if morse == dm_k:
|
if morse == dm_k:
|
||||||
print ("K")
|
return ("K")
|
||||||
if morse == dm_l:
|
if morse == dm_l:
|
||||||
return ("L")
|
return ("L")
|
||||||
if morse == dm_m:
|
if morse == dm_m:
|
||||||
@ -227,31 +219,26 @@ last_sp = 0
|
|||||||
def process_morse():
|
def process_morse():
|
||||||
global last_tt, morse, last_was_space, last_sp
|
global last_tt, morse, last_was_space, last_sp
|
||||||
tt = time.ticks_ms()
|
tt = time.ticks_ms()
|
||||||
if (tt - last_tt) > rate*6:
|
if (button_state == 0):
|
||||||
# morse chacter complete
|
if (tt - last_tt) > rate*6:
|
||||||
if (len(morse) > 0):
|
# morse chacter complete
|
||||||
#print(morse)
|
if (len(morse) > 0):
|
||||||
printm(decode_morse())
|
#print(morse)
|
||||||
morse = []
|
printm(decode_morse())
|
||||||
last_was_space = 0
|
morse = []
|
||||||
last_sp = last_tt
|
last_was_space = 0
|
||||||
#oled.clear()
|
last_sp = last_tt
|
||||||
#oled.displayText(rtc.readDateString(), 1, 25)
|
|
||||||
#oled.displayText(rtc.readTimeString(), 2, 33)
|
|
||||||
#oled.displayText(str(mcount), 4, 33)
|
|
||||||
#oled.show()
|
|
||||||
if (tt - last_sp) > rate*22 : # and last_not_space == 0:
|
|
||||||
if last_was_space == 0:
|
|
||||||
printm(" ");
|
|
||||||
last_was_space = 1 # dont keep repeating inter word spaces
|
|
||||||
|
|
||||||
|
if (tt - last_sp) > rate*22 : # and last_not_space == 0:
|
||||||
|
if last_was_space == 0:
|
||||||
|
printm(" ");
|
||||||
|
last_was_space = 1 # dont keep repeating inter word spaces
|
||||||
|
last_sp = last_tt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
# maybe a function can have a global ref, yeah maybe the main cont. another wanky aspect ogf pythion
|
|
||||||
process_morse()
|
process_morse()
|
||||||
##process_morse2()
|
|
||||||
#time.sleep(1.0)
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user