attempt idle timeout fix
This commit is contained in:
		
							parent
							
								
									76715d1dc2
								
							
						
					
					
						commit
						3217cf177d
					
				
					 1 changed files with 31 additions and 13 deletions
				
			
		
							
								
								
									
										42
									
								
								leds.py
									
										
									
									
									
								
							
							
						
						
									
										42
									
								
								leds.py
									
										
									
									
									
								
							|  | @ -239,23 +239,33 @@ class Adafruit_CharLCD: | ||||||
|                 self.write4bits(ord(char), True) |                 self.write4bits(ord(char), True) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | debug_statements = True | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | def debug(msg): | ||||||
|  |     if debug_statements: | ||||||
|  |         print(msg) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| def lightlevel(lcd, level): | def lightlevel(lcd, level): | ||||||
|     print("display level") |     debug("display level") | ||||||
|     lcd.clear() |     lcd.clear() | ||||||
|     lcd.message("Light Level:\n]" + "-"*level + "[") |     lcd.message("Light Level:\n]" + "-"*level + "[") | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def querylightlevel(): | def querylightlevel(): | ||||||
|   print("NYI") |     debug("NYI") | ||||||
|     return 7 |     return 7 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def color(lcd, col): | def color(lcd, col): | ||||||
|     lcd.clear() |     lcd.clear() | ||||||
|     lcd.message("new color:\n#" + col) |     lcd.message("new color:\n#{}".format(col)) | ||||||
|     print("NYI") |     debug("NYI") | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def querycolor(): | def querycolor(): | ||||||
|     print("NYI") |     debug("NYI") | ||||||
|     return "ffffff" |     return "ffffff" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -267,22 +277,30 @@ def loop(): | ||||||
|         idle = 0 |         idle = 0 | ||||||
|         idle_max = 15 |         idle_max = 15 | ||||||
|         cur_color = "ffffff" |         cur_color = "ffffff" | ||||||
|         print("loop") |         debug("loop") | ||||||
|         query_color = querycolor() |         query_color = querycolor() | ||||||
|         level = querylightlevel() |         query_level = querylightlevel() | ||||||
|         idle = idle + 1 |         idle = idle + 1 | ||||||
|         if idle >= idle_max: |         debug("idle value: {}".format(idle)) | ||||||
|             idle = idle_max | 
 | ||||||
|             lcd.noDisplay() |         if query_color != cur_color: | ||||||
|         elif query_color != cur_color: |  | ||||||
|             if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol: |             if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol: | ||||||
|                 lcd.display() |                 lcd.display() | ||||||
|             ccolor = query_color |             ccolor = query_color | ||||||
|  |             idle = 0 | ||||||
|             color(lcd, cur_color) |             color(lcd, cur_color) | ||||||
|         else: |         elif query_level != level: | ||||||
|  |             level = query_level | ||||||
|  |             idle = 0 | ||||||
|             if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol: |             if lcd.displaycontrol & lcd.LCD_DISPLAYON != lcd.displaycontrol: | ||||||
|                 lcd.display() |                 lcd.display() | ||||||
|             lightlevel(lcd, level) |             lightlevel(lcd, level) | ||||||
|  |         elif idle >= idle_max: | ||||||
|  |             debug("hit idle threshold") | ||||||
|  |             idle = idle_max | ||||||
|  |             lcd.noDisplay() | ||||||
|  |         else: | ||||||
|  |             lightlevel(lcd, level) | ||||||
|         sleep(1) |         sleep(1) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue