persistent settings
This commit is contained in:
		
							parent
							
								
									ca058725e8
								
							
						
					
					
						commit
						54589b743d
					
				@ -52,7 +52,7 @@ class Buzzer():
 | 
				
			|||||||
                    else: 
 | 
					                    else: 
 | 
				
			||||||
                        self._pwm.duty(0)
 | 
					                        self._pwm.duty(0)
 | 
				
			||||||
                    await asyncio.sleep_ms(s[0])
 | 
					                    await asyncio.sleep_ms(s[0])
 | 
				
			||||||
                    if self.newSound:
 | 
					                    if self.newSound or self.sound == None:
 | 
				
			||||||
                        break
 | 
					                        break
 | 
				
			||||||
                if (not self.newSound):
 | 
					                if (not self.newSound):
 | 
				
			||||||
                    self.sound = None
 | 
					                    self.sound = None
 | 
				
			||||||
 | 
				
			|||||||
@ -63,6 +63,8 @@ class SettingsScreen():
 | 
				
			|||||||
                    self.stepperhour.rotateTo(direction=-1)
 | 
					                    self.stepperhour.rotateTo(direction=-1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def onButtonReleased(self,button):
 | 
					    def onButtonReleased(self,button):
 | 
				
			||||||
 | 
					        if not self.running:
 | 
				
			||||||
 | 
					            return
 | 
				
			||||||
        self.leds[button].off(overwriteFlashing=False)
 | 
					        self.leds[button].off(overwriteFlashing=False)
 | 
				
			||||||
        if button == 0:#left
 | 
					        if button == 0:#left
 | 
				
			||||||
            if self.mode == 0 or self.mode == 1:
 | 
					            if self.mode == 0 or self.mode == 1:
 | 
				
			||||||
@ -118,4 +120,6 @@ class SettingsScreen():
 | 
				
			|||||||
        self.housingLEDs.clear()
 | 
					        self.housingLEDs.clear()
 | 
				
			||||||
        self.stepperhour.reset()
 | 
					        self.stepperhour.reset()
 | 
				
			||||||
        self.stepperminu.reset()
 | 
					        self.stepperminu.reset()
 | 
				
			||||||
 | 
					        self.buzzer.stop()
 | 
				
			||||||
 | 
					        Settings.save()
 | 
				
			||||||
    __iter__ = __await__  # https://github.com/micropython/micropython/issues/2678
 | 
					    __iter__ = __await__  # https://github.com/micropython/micropython/issues/2678
 | 
				
			||||||
							
								
								
									
										25
									
								
								Settings.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								Settings.py
									
									
									
									
									
								
							@ -1,2 +1,25 @@
 | 
				
			|||||||
 | 
					 | 
				
			||||||
selectedSound=0
 | 
					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()
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user