def update_led(increment): global led_index led_index += increment led_options = len(led.solid_colours) + len(led.body_animations) - 1 if led_index < 0 : led_index = led_options if led_index > led_options : led_index = 0 if led_index < len(led.solid_colours) : led.set_colour_solid(led_index) else: led.animation(led_index - len(led.solid_colours))
def speech_to_text_callback(c): if c == None: return '' if c % 2 == 1: #Odd number: start Recording led.animation(2) speech.start_recording() return (html.P("Recording audio - press again to stop")) response = speech.end_recording() led.animation(0) return (html.P("Google Response: %s" % response))
def check_battery_state(): global battery_warning_state voltage = power.read_battery_voltage() if(voltage < settings.BATTERY_SHUTDOWN_VOLTAGE and settings.BATTERY_CRITICAL_SHUTDOWN): logging.critical("BATTERY CHECK: Battery voltage critically low [%2.2f V], starting forced shutdown." % (voltage)) shutdown() if(voltage < settings.BATTERY_CRITICAL_VOLTAGE and battery_warning_state != 1): battery_warning_state = 1 led.animation(8) display.warning("BATTERY EMPTY") audio.play_audio_file(settings.AUDIO_FILEPATH + "batterycriticallylow.wav") logging.warning("BATTERY CHECK: Battery voltage critical warning [%2.2f V]" % (voltage)) elif (voltage < settings.BATTERY_LOW_VOLTAGE and battery_warning_state != 2): battery_warning_state = 2 display.warning("BATTERY LOW") audio.play_audio_file(settings.AUDIO_FILEPATH + "batterylow.wav") logging.warning("BATTERY CHECK: Battery voltage low warning [%2.2f V]" % (voltage)) #If voltage recovers to +0.3V above low state restore normal state if(battery_warning_state != 0 and voltage>(settings.BATTERY_LOW_VOLTAGE + 0.3)): battery_warning_state = 0 led.animation(0) logging.info("BATTERY CHECK: Battery voltage recovered [%2.2f V]" % (voltage)) else: logging.debug("BATTERY CHECK: Battery voltage okay [%2.2f V]" % (voltage))
def led_callback(request): #Check bounds brightness = request.brightness if(brightness > 15): print("Warning: LED brightness beyond maximum [15]: %d" % brightness) brightness = 15 led.set_brightness(brightness) index=request.index if(request.animation): if(index > len(led.body_animations)): print("Error: LED animation index outside valid range [%d]: %d" % (len(led.body_animations),index)) return "Error" name = led.body_animations[index][0] print("Setting LEDs to animation %s" % name) led.animation(index) return name else: if(index > len(led.solid_colours)): print("Error: LED colour index outside valid range [%d]: %d" % (len(led.solid_colours),index)) return "Error" name = led.solid_colours[index][0] print("Setting LEDs to colour %s" % name) led.set_colour_solid(index) return name
def check_temperature(): global temperature_warning_state pcb_temp = power.read_pcb_temperature() cpu_temp = utils.get_cpu_temp() logging.debug("TEMPERATURE CHECK: CPU=%2.2fC PCB=%2.2fC" % (cpu_temp, pcb_temp)) if((cpu_temp > settings.CPU_SHUTDOWN_TEMP or pcb_temp>settings.PCB_SHUTDOWN_TEMP) and settings.TEMPERATURE_CRITICAL_SHUTDOWN): logging.critical("Temperature too high [CPU:%2.2f C, PCB:%2.2f], starting forced shutdown." % (cpu_temp, pcb_temp)) shutdown() if((cpu_temp > settings.CPU_CRITICAL_TEMP or pcb_temp >settings.PCB_CRITICAL_TEMP) and temperature_warning_state != 1): temperature_warning_state = 1 led.animation(8) display.warning("OVERHEATING") audio.play_audio_file(settings.AUDIO_FILEPATH + "overheating.wav") logging.warning("Temperature critically high warning [CPU:%2.2f C, PCB:%2.2f]" % (cpu_temp, pcb_temp)) elif ((cpu_temp > settings.CPU_WARNING_TEMP or pcb_temp > settings.PCB_WARNING_TEMP) and temperature_warning_state != 2): temperature_warning_state = 2 display.warning("TEMP HIGH") audio.play_audio_file(settings.AUDIO_FILEPATH + "warning.wav") logging.warning("Temperature high warning [CPU:%2.2f C, PCB:%2.2f]" % (cpu_temp, pcb_temp)) #If temperatures recover to 2C below warning state restore normal state if(temperature_warning_state != 0 and cpu_temp<(settings.CPU_WARNING_TEMP - 2) and pcb_temp<(settings.PCB_WARNING_TEMP - 2)): temperature_warning_state = 0 led.animation(0) logging.info("Temperatures recovered [CPU:%2.2f C, PCB:%2.2f]" % (cpu_temp, pcb_temp))
def animation_callback(value): if value == None: return '' led.animation(int(value)) return ''