+ if mode == 7:
+ # variable = "pm1"
+ unit = "ug/m3"
+ try:
+ data = pms5003.read()
+ except pmsReadTimeoutError:
+ logging.warn("Failed to read PMS5003")
+ else:
+ data = float(data.pm_ug_per_m3(1.0))
+ display_text(variables[mode], data, unit)
+
+ if mode == 8:
+ # variable = "pm25"
+ unit = "ug/m3"
+ try:
+ data = pms5003.read()
+ except pmsReadTimeoutError:
+ logging.warn("Failed to read PMS5003")
+ else:
+ data = float(data.pm_ug_per_m3(2.5))
+ display_text(variables[mode], data, unit)
+
+ if mode == 9:
+ # variable = "pm10"
+ unit = "ug/m3"
+ try:
+ data = pms5003.read()
+ except pmsReadTimeoutError:
+ logging.warn("Failed to read PMS5003")
+ else:
+ data = float(data.pm_ug_per_m3(10))
+ display_text(variables[mode], data, unit)
+ if mode == 10:
+ # Everything on one screen
+ cpu_temp = get_cpu_temperature()
+ # Smooth out with some averaging to decrease jitter
+ cpu_temps = cpu_temps[1:] + [cpu_temp]
+ avg_cpu_temp = sum(cpu_temps) / float(len(cpu_temps))
+ raw_temp = bme280.get_temperature()
+ raw_data = raw_temp - ((avg_cpu_temp - raw_temp) / factor)
+ save_data(0, raw_data)
+ display_everything()
+ raw_data = bme280.get_pressure()
+ save_data(1, raw_data)
+ display_everything()
+ raw_data = bme280.get_humidity()
+ save_data(2, raw_data)
+ if proximity < 10:
+ raw_data = ltr559.get_lux()
+ else:
+ raw_data = 1
+ save_data(3, raw_data)
+ display_everything()
+ gas_data = gas.read_all()
+ save_data(4, gas_data.oxidising / 1000)
+ save_data(5, gas_data.reducing / 1000)
+ save_data(6, gas_data.nh3 / 1000)
+ display_everything()
+ pms_data = None
+ try:
+ pms_data = pms5003.read()
+ except pmsReadTimeoutError:
+ logging.warn("Failed to read PMS5003")
+ else:
+ save_data(7, float(pms_data.pm_ug_per_m3(1.0)))
+ save_data(8, float(pms_data.pm_ug_per_m3(2.5)))
+ save_data(9, float(pms_data.pm_ug_per_m3(10)))
+ display_everything()
+
+ # Exit cleanly
+ except KeyboardInterrupt:
+ sys.exit(0)
+
+
+if __name__ == "__main__":
+ main()