Add threshold parameter to set_clock_from_gps() and update some documentation

This commit is contained in:
Pierrick C 2018-08-03 23:25:14 +02:00
parent 66abc780f8
commit 4cc41e8e9a

View File

@ -115,9 +115,10 @@ class Data:
if not self.data[source] == None: if not self.data[source] == None:
for d in self.data[source].items(): for d in self.data[source].items():
print("\t{0}: {1}".format(d[0], d[1])) print("\t{0}: {1}".format(d[0], d[1]))
@property @property
def json(self): def json(self):
"""Serialize data to json-formatted string""" """Serialized data to json-formatted string"""
output = '{' output = '{'
first_source = True first_source = True
for source in self.data.keys(): for source in self.data.keys():
@ -143,7 +144,8 @@ class Data:
@property @property
def rgb(self): def rgb(self):
"""Convert atmospheric data from BME280 sensor into NeoPixel color """Convert atmospheric data from BME280 sensor into NeoPixel color as
a tuple (RED, BLUE, GREEN):
* RED => temperature : max = 35degC, min =10degC (range 25°C) * RED => temperature : max = 35degC, min =10degC (range 25°C)
* BLUE => humidity : max= 100%, mini=0% * BLUE => humidity : max= 100%, mini=0%
* GREEN => pression : mini=960hPa, maxi = 1030hPa (range 70hPa) * GREEN => pression : mini=960hPa, maxi = 1030hPa (range 70hPa)
@ -196,7 +198,11 @@ 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 set_clock_from_GPS(): def set_clock_from_GPS(treshold=5.0):
"""Compare internal RTC and date-time from GPS (if enable and fixed) and set
the RTC date time to GPS date-time if the difference is more or equal to
threshold (in seconds)"""
if gps_enable and gps.has_fix: if gps_enable and gps.has_fix:
#Congreen 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,
@ -206,7 +212,7 @@ def set_clock_from_GPS():
gps.timestamp_utc.tm_min, gps.timestamp_utc.tm_min,
gps.timestamp_utc.tm_sec, 0, 0, 0)) gps.timestamp_utc.tm_sec, 0, 0, 0))
#Max difference between GPS and internal RTC (in seconds): #Max difference between GPS and internal RTC (in seconds):
if abs(time.mktime(gps_datetime) - time.mktime(clock.datetime)) >= 5.0: if abs(time.mktime(gps_datetime) - time.mktime(clock.datetime)) >= treshold:
print("Clock difference with GPS!") print("Clock difference with GPS!")
print("Previous date/time : " + datetime_format.format(*clock.datetime[0:6])) print("Previous date/time : " + datetime_format.format(*clock.datetime[0:6]))
clock.datetime = gps_datetime #Trust GPS if there is a bias clock.datetime = gps_datetime #Trust GPS if there is a bias