Better management of data to display

This commit is contained in:
Pierrick C 2018-08-19 00:02:45 +02:00
parent 4b9885d7a7
commit c62ad455ba

View File

@ -76,13 +76,6 @@ def on_message(client, userdata, msg):
payload = msg.payload.decode() payload = msg.payload.decode()
val = json.loads(payload) val = json.loads(payload)
#Is value consistent ?
try:
val['value'] = float(val['value'] )
except:
print("Value error: {}".format(val['value']))
val['value'] = float('nan')
#Manage special character "degree" #Manage special character "degree"
val['unit'] = val['unit'].replace('deg', '°') val['unit'] = val['unit'].replace('deg', '°')
@ -92,8 +85,19 @@ def on_message(client, userdata, msg):
'AP' : (1, data2_line), 'AP' : (1, data2_line),
'VBAT' : (inkyphat.WIDTH / 2 + 12, data2_line), 'VBAT' : (inkyphat.WIDTH / 2 + 12, data2_line),
} }
print(val) print(val)
if val['type'] in coord_type: if val['type'] in coord_type:
#Manage special character "degree"
val['unit'] = val['unit'].replace('deg', '°')
#Is value consistent ?
try:
val['value'] = float(val['value'] )
except:
print("Value error: {}".format(val['value']))
val['value'] = float('nan')
#Erase old data #Erase old data
inkyphat.rectangle(coord_type[val['type']] + (coord_type[val['type']][0] + inkyphat.WIDTH / 2 - 2, inkyphat.rectangle(coord_type[val['type']] + (coord_type[val['type']][0] + inkyphat.WIDTH / 2 - 2,
coord_type[val['type']][1] + 16), coord_type[val['type']][1] + 16),
@ -104,13 +108,9 @@ def on_message(client, userdata, msg):
font=data_font, font=data_font,
fill=black) fill=black)
new_data_flag = True new_data_flag = True
update_display()
# Print feather's date and time on epaper display # Print feather's date and time on epaper display
elif subtopics[0] == "SYS": elif val['type'] == "TIME":
payload = msg.payload.decode()
val = json.loads(payload)
if val['type'] == "TIME":
try: try:
#Check the date and time and offset to the right timezone #Check the date and time and offset to the right timezone
dt_texte = datetime.strftime(datetime.strptime(val['value'], "%Y/%m/%d_%H:%M:%S") + TimeZone.utcoffset(None), dt_texte = datetime.strftime(datetime.strptime(val['value'], "%Y/%m/%d_%H:%M:%S") + TimeZone.utcoffset(None),
@ -123,7 +123,7 @@ def on_message(client, userdata, msg):
# and draw the new date # and draw the new date
inkyphat.text((0, 31), dt_texte, font=font12, fill=black) inkyphat.text((0, 31), dt_texte, font=font12, fill=black)
new_data_flag = True new_data_flag = True
update_display()
def on_message_camera(client, userdata, msg): def on_message_camera(client, userdata, msg):
"""Update display with info from camera (camera shooting new picture or name """Update display with info from camera (camera shooting new picture or name