From b08a56b204840265a1e829f64156375580889acc Mon Sep 17 00:00:00 2001 From: Pierrick C Date: Fri, 3 Aug 2018 15:00:28 +0200 Subject: [PATCH] Move function "update_neopixel()" to data class method "atmo2rgb()" for consistency and french to english color variables translation --- circuitpython/code/main.py | 56 +++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/circuitpython/code/main.py b/circuitpython/code/main.py index ebfd593..1fb70a6 100644 --- a/circuitpython/code/main.py +++ b/circuitpython/code/main.py @@ -132,6 +132,32 @@ class Data: output = output + "}" return output + def atmo2rgb(self): + """Congreen atmospheric data from BME280 sensor into NeoPixel color + * RED => temperature : max = 35degC, min =10degC (range 25°C) + * BLUE => humidity : max= 100%, mini=0% + * GREEN => pression : mini=960hPa, maxi = 1030hPa (range 70hPa) + """ + + red = int((self.data['BME280']['temp']['val']-10)*neopixel_max_value/25) + if red > neopixel_max_value: + red = neopixel_max_value + if red < 0: + red = 0 + + blue = int(self.data['BME280']['hum']['val']*neopixel_max_value/100) + + green = int((self.data['BME280']['press']['val']-960)*neopixel_max_value/70) + if green > neopixel_max_value: + green = neopixel_max_value + if green < 0: + green = 0 + + if print_data: + print("Col:{}".format((red, green, blue))) + + return (red, green, blue) + def write_on_flash(self): """Save the current data as csv file on SPI flash""" try: @@ -160,35 +186,9 @@ def check_data_dir(): elif 'daily' not in os.listdir('data'): os.mkdir('data/daily') -def update_neopixel(data): - """Convert atmospheric data from BME280 sensor into NeoPixel color - * RED => temperature : max = 35degC, min =10degC (range 25°C) - * BLUE => humidity : max= 100%, mini=0% - * GREEN => pression : mini=960hPa, maxi = 1030hPa (range 70hPa) - """ - - rouge = int((data['BME280']['temp']['val']-10)*neopixel_max_value/25) - if rouge > neopixel_max_value: - rouge = neopixel_max_value - if rouge < 0: - rouge = 0 - - bleu = int(data['BME280']['hum']['val']*neopixel_max_value/100) - - vert = int((data['BME280']['press']['val']-960)*neopixel_max_value/70) - if vert > neopixel_max_value: - vert = neopixel_max_value - if vert < 0: - vert = 0 - - if print_data: - print("Col:{}".format((rouge, vert, bleu))) - - return (rouge, vert, bleu) - def set_clock_from_GPS(): if gps_enable and gps.has_fix: - #Convert GPS timestamp into struct_time + #Congreen GPS timestamp into struct_time gps_datetime = time.struct_time((gps.timestamp_utc.tm_year, gps.timestamp_utc.tm_mon, gps.timestamp_utc.tm_mday, @@ -279,7 +279,7 @@ while True: if backup_data: data.write_on_flash() if data_to_neopixel: - pixel[0] = update_neopixel(data.data) + pixel[0] = data.atmo2rgb() gc.collect() # micropython.mem_info(1)