Move function "update_neopixel()" to data class method "atmo2rgb()" for consistency and french to english color variables translation
This commit is contained in:
parent
280823577c
commit
b08a56b204
@ -132,6 +132,32 @@ class Data:
|
|||||||
output = output + "}"
|
output = output + "}"
|
||||||
return 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):
|
def write_on_flash(self):
|
||||||
"""Save the current data as csv file on SPI flash"""
|
"""Save the current data as csv file on SPI flash"""
|
||||||
try:
|
try:
|
||||||
@ -160,35 +186,9 @@ def check_data_dir():
|
|||||||
elif 'daily' not in os.listdir('data'):
|
elif 'daily' not in os.listdir('data'):
|
||||||
os.mkdir('data/daily')
|
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():
|
def set_clock_from_GPS():
|
||||||
if gps_enable and gps.has_fix:
|
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_datetime = time.struct_time((gps.timestamp_utc.tm_year,
|
||||||
gps.timestamp_utc.tm_mon,
|
gps.timestamp_utc.tm_mon,
|
||||||
gps.timestamp_utc.tm_mday,
|
gps.timestamp_utc.tm_mday,
|
||||||
@ -279,7 +279,7 @@ while True:
|
|||||||
if backup_data:
|
if backup_data:
|
||||||
data.write_on_flash()
|
data.write_on_flash()
|
||||||
if data_to_neopixel:
|
if data_to_neopixel:
|
||||||
pixel[0] = update_neopixel(data.data)
|
pixel[0] = data.atmo2rgb()
|
||||||
|
|
||||||
gc.collect()
|
gc.collect()
|
||||||
# micropython.mem_info(1)
|
# micropython.mem_info(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user