persistent settings

This commit is contained in:
Nils Schulte 2020-03-19 23:05:35 +01:00
parent ca058725e8
commit 54589b743d
3 changed files with 29 additions and 2 deletions

View File

@ -52,7 +52,7 @@ class Buzzer():
else:
self._pwm.duty(0)
await asyncio.sleep_ms(s[0])
if self.newSound:
if self.newSound or self.sound == None:
break
if (not self.newSound):
self.sound = None

View File

@ -63,6 +63,8 @@ class SettingsScreen():
self.stepperhour.rotateTo(direction=-1)
def onButtonReleased(self,button):
if not self.running:
return
self.leds[button].off(overwriteFlashing=False)
if button == 0:#left
if self.mode == 0 or self.mode == 1:
@ -118,4 +120,6 @@ class SettingsScreen():
self.housingLEDs.clear()
self.stepperhour.reset()
self.stepperminu.reset()
self.buzzer.stop()
Settings.save()
__iter__ = __await__ # https://github.com/micropython/micropython/issues/2678

View File

@ -1,2 +1,25 @@
selectedSound=0
alarmTime=((1,2,3,4),(8,),(0,))
def printState():
print("selectedSound=",selectedSound)
print("alarmTime=",alarmTime)
def save():
global selectedSound
lines = []
with open("Settings.py",'r') as rf:
for l in rf:
lines.append(l)
with open("Settings.py",'w') as wf:
for l in lines:
if l.startswith("selectedSound"):
wf.write("selectedSound="+str(selectedSound)+"\n")
elif l.startswith("alarmTime"):
wf.write("alarmTime="+str(alarmTime)+"\n")
else:
wf.write(l)
#printState()
#printState()