fixed buzzer

This commit is contained in:
Nils Schulte 2020-03-23 13:58:57 +01:00
parent 0b219d1236
commit d1cf3487c0
2 changed files with 13 additions and 9 deletions

View File

@ -20,14 +20,14 @@ BEEPBEEP = ((700,1000),(100,None),(600,1000))
# 0: BEEEEP BEEEEP BEEEEEP
# 1: Alle Meine Entchen
ALARMTONES = (((300,1200),(100,None),(200,1200),(300,None),(None,10)),
((400,c),(100,None),(400,d),(100,None),(400,e),(100,None),(400,f),(100,None),\
(900,g),(100,None),(900,g),(100,None),(400,a),(100,None),(400,a),(100,None),\
(400,a),(100,None),(400,a),(100,None),(1900,g),(100,None),(400,a),(100,None),\
(400,a),(100,None),(400,a),(100,None),(400,a),(100,None),(1600,g),(100,None),\
(400,f),(100,None),(400,f),(100,None),(400,f),(100,None),(400,f),(100,None),\
(900,e),(100,None),(900,e),(100,None),(400,d),(100,None),(400,d),(100,None),\
(400,d),(100,None),(400,d),(100,None),(1600,c)),)
ALARMTONES = (((300,1200),(80,None),(200,1200),(300,None),(None,10)),
((400,c),(80,None),(400,d),(80,None),(400,e),(80,None),(400,f),(80,None),\
(900,g),(80,None),(900,g),(80,None),(400,a),(80,None),(400,a),(80,None),\
(400,a),(80,None),(400,a),(80,None),(1900,g),(80,None),(400,a),(80,None),\
(400,a),(80,None),(400,a),(80,None),(400,a),(80,None),(1600,g),(80,None),\
(400,f),(80,None),(400,f),(80,None),(400,f),(80,None),(400,f),(80,None),\
(900,e),(80,None),(900,e),(80,None),(400,d),(80,None),(400,d),(80,None),\
(400,d),(80,None),(400,d),(80,None),(1600,c)),)
class Buzzer():
def __init__(self,pin,duty = 1000):
@ -47,7 +47,8 @@ class Buzzer():
self.newSound = False
timesPlayed = 0
#print("Play sound!")
for i in range(len(self.sound)):
i = 0
while i < len(self.sound):
s = self.sound[i]
if s[0] == None:
if s[1]-timesPlayed == 0:
@ -55,6 +56,7 @@ class Buzzer():
else:
i = 0
timesPlayed += 1
continue
if (s[1] != None):
self._pwm.freq(s[1])
self._pwm.duty(self.duty)
@ -64,6 +66,7 @@ class Buzzer():
await asyncio.sleep_ms(s[0])
if self.newSound or self.sound == None:
break
i+=1
if (not self.newSound):
self.sound = None
self.newSound = False

View File

@ -98,6 +98,7 @@ class RingtoneSettingsScreen():
onNumberChange=self.playAndSetSound,\
onPicked=lambda _:Settings.save())
await numberScreen
HW.buzzer.stop()
class ShowIpScreen():
def __init__(self):