French -> english translation
This commit is contained in:
parent
c96f7b86ae
commit
311a36fbdf
@ -45,10 +45,12 @@ def update_epd():
|
|||||||
"""
|
"""
|
||||||
Update ePaper Display
|
Update ePaper Display
|
||||||
"""
|
"""
|
||||||
#rotation de l'image de 90° + 180° si le paramètre epd_rotate est différent de 0
|
# 90° rotation + 180° if parameter epd_rotate different of 0
|
||||||
# la translation permet de rattraper un petit décalage en cas de rotation de 90+180°
|
# The small translation corrects an offset after rotation of 270°
|
||||||
screen = image.rotate(90 + (epd_rotate * 180), expand=True, translate=(-6*epd_rotate, 0))
|
screen = image.rotate(90 + (epd_rotate * 180),
|
||||||
#Mis en memoire de l'image à afficher et affichage de l'image
|
expand=True,
|
||||||
|
translate=(-6*epd_rotate, 0))
|
||||||
|
# Put the picture to display in frame memory and display the new frame
|
||||||
epd.set_frame_memory(screen, 0, 0)
|
epd.set_frame_memory(screen, 0, 0)
|
||||||
epd.display_frame()
|
epd.display_frame()
|
||||||
|
|
||||||
@ -57,9 +59,7 @@ def update_epd():
|
|||||||
#############
|
#############
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
"""
|
"""On connection callback : topics subscription"""
|
||||||
Callback pour la connection au MQTT : souscriptions aux topics
|
|
||||||
"""
|
|
||||||
print(mqtt.connack_string(rc))
|
print(mqtt.connack_string(rc))
|
||||||
if rc == 0:
|
if rc == 0:
|
||||||
print("Subscribing to %s ..." % mqtt_topic)
|
print("Subscribing to %s ..." % mqtt_topic)
|
||||||
@ -70,28 +70,28 @@ def on_connect(client, userdata, flags, rc):
|
|||||||
|
|
||||||
|
|
||||||
def on_message(client, userdata, msg):
|
def on_message(client, userdata, msg):
|
||||||
"""
|
"""Callback for managing data sent by MQTT broker"""
|
||||||
Callback de gestion des messages arrivant au MQTT :
|
|
||||||
affichage et enregistrement en base de données
|
|
||||||
"""
|
|
||||||
top=msg.topic[len(mqtt_topic)-1:].strip()
|
top=msg.topic[len(mqtt_topic)-1:].strip()
|
||||||
|
#List of the subtopics
|
||||||
subtopics = top.split("/")
|
subtopics = top.split("/")
|
||||||
|
|
||||||
|
#Display atmospheric data from BME280 sensor
|
||||||
if subtopics[0] == "BME":
|
if subtopics[0] == "BME":
|
||||||
payload = msg.payload.decode()
|
payload = msg.payload.decode()
|
||||||
val = json.loads(payload)
|
val = json.loads(payload)
|
||||||
|
|
||||||
#Test présence et cohérence de la valeur
|
#Is value consistent ?
|
||||||
try:
|
try:
|
||||||
val['value'] = float(val['value'] )
|
val['value'] = float(val['value'] )
|
||||||
except:
|
except:
|
||||||
print("Value error: {}".format(val['value']))
|
print("Value error: {}".format(val['value']))
|
||||||
val['value'] = float('nan')
|
val['value'] = float('nan')
|
||||||
|
|
||||||
#Gestion du symbole des degrés parfois difficile pour certaines sources
|
#Manage special character "degree"
|
||||||
val['unit'] = val['unit'].replace('deg', '°')
|
val['unit'] = val['unit'].replace('deg', '°')
|
||||||
|
|
||||||
#Affichage des données
|
#List of 'displayable' data types and their coordinate on screen
|
||||||
coord_type = { 'AT' : (12, 50),
|
coord_type = { 'AT' : (12, 50),
|
||||||
'RH' : (137, 50),
|
'RH' : (137, 50),
|
||||||
'AP' : (12, 72),
|
'AP' : (12, 72),
|
||||||
@ -99,46 +99,48 @@ def on_message(client, userdata, msg):
|
|||||||
}
|
}
|
||||||
print(val)
|
print(val)
|
||||||
if val['type'] in coord_type:
|
if val['type'] in coord_type:
|
||||||
#erase former text
|
#Erase old data
|
||||||
draw.rectangle(coord_type[val['type']] + (coord_type[val['type']][0] + 112, coord_type[val['type']][1] + 20), fill=white)
|
draw.rectangle(coord_type[val['type']] + (coord_type[val['type']][0] + 112, coord_type[val['type']][1] + 20), fill=white)
|
||||||
#draw new values
|
#Draw new values
|
||||||
draw.text(coord_type[val['type']],
|
draw.text(coord_type[val['type']],
|
||||||
"{:6.1f}{} ".format(val['value'], val['unit']),
|
"{:6.1f}{} ".format(val['value'], val['unit']),
|
||||||
font=font20_bold,
|
font=font20_bold,
|
||||||
fill=black)
|
fill=black)
|
||||||
update_epd()
|
update_epd()
|
||||||
|
|
||||||
# Print feather's date and time on epaper display
|
# Print feather's date and time on epaper display
|
||||||
elif subtopics[0] == "SYS":
|
elif subtopics[0] == "SYS":
|
||||||
payload = msg.payload.decode()
|
payload = msg.payload.decode()
|
||||||
val = json.loads(payload)
|
val = json.loads(payload)
|
||||||
if val['type'] == "TIME":
|
if val['type'] == "TIME":
|
||||||
try:
|
try:
|
||||||
#Mise en forme de la date et heure reçu pour fuseau horaire configuré
|
#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),
|
||||||
"%d/%m/%Y %H:%M:%S")
|
"%d/%m/%Y %H:%M:%S")
|
||||||
except:
|
except:
|
||||||
dt_texte = payload
|
dt_texte = payload
|
||||||
print(dt_texte)
|
print(dt_texte)
|
||||||
|
# First erase old text
|
||||||
draw.rectangle((0, 34, epd2in13.EPD_HEIGHT, 48), fill=white)
|
draw.rectangle((0, 34, epd2in13.EPD_HEIGHT, 48), fill=white)
|
||||||
|
# and draw the new date
|
||||||
draw.text((0, 34), dt_texte, font=font14, fill=black)
|
draw.text((0, 34), dt_texte, font=font14, fill=black)
|
||||||
|
|
||||||
update_epd()
|
update_epd()
|
||||||
|
|
||||||
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 photo or name of the
|
of the last photo)"""
|
||||||
last photo)
|
|
||||||
"""
|
|
||||||
pl = msg.payload.decode()
|
pl = msg.payload.decode()
|
||||||
print("{} : {} ({})".format(msg.topic, pl, type(pl)))
|
print("{} : {} ({})".format(msg.topic, pl, type(pl)))
|
||||||
|
|
||||||
# Photo en cours
|
# If a picture is been taken
|
||||||
if pl == "1" and msg.topic == camera_mqtt_topic + "/shooting" :
|
if pl == "1" and msg.topic == camera_mqtt_topic + "/shooting" :
|
||||||
draw.rectangle((0, 106, epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), fill=white)
|
draw.rectangle((0, 106, epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), fill=white)
|
||||||
draw.text((0, 106), "Shooting photo... ", font=font14, fill=black)
|
draw.text((0, 106), "Shooting photo... ", font=font14, fill=black)
|
||||||
update_epd()
|
update_epd()
|
||||||
|
|
||||||
#Dernière photo prise
|
#Last picture name (with date/time)
|
||||||
if msg.topic == camera_mqtt_topic + "/last_photo":
|
if msg.topic == camera_mqtt_topic + "/last_photo":
|
||||||
draw.rectangle((0, 106, epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), fill=white)
|
draw.rectangle((0, 106, epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), fill=white)
|
||||||
draw.text((0, 106), "Last: " + pl, font=font14, fill=black)
|
draw.text((0, 106), "Last: " + pl, font=font14, fill=black)
|
||||||
@ -146,11 +148,9 @@ def on_message_camera(client, userdata, msg):
|
|||||||
|
|
||||||
|
|
||||||
def on_disconnect(client, userdata, msg):
|
def on_disconnect(client, userdata, msg):
|
||||||
"""
|
"""Disconnection callback"""
|
||||||
Callback de déconnexion au broker MQTT
|
|
||||||
"""
|
|
||||||
if msg != 0:
|
if msg != 0:
|
||||||
print("Déconnexion imprévu : %s" % msg)
|
print("Unexpected disconnection : {}".format(msg))
|
||||||
exit()
|
exit()
|
||||||
|
|
||||||
########
|
########
|
||||||
@ -179,17 +179,19 @@ font20_bold = ImageFont.truetype(epd_bold_font_file, 20)
|
|||||||
image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255)
|
image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255)
|
||||||
draw = ImageDraw.Draw(image)
|
draw = ImageDraw.Draw(image)
|
||||||
|
|
||||||
#Draw basic text and frame :
|
#Draw title in white on black
|
||||||
draw.rectangle((0, 0, epd2in13.EPD_HEIGHT, 18), fill=black)
|
draw.rectangle((0, 0, epd2in13.EPD_HEIGHT, 18), fill=black)
|
||||||
draw.text((60, 1),
|
draw.text((60, 1),
|
||||||
"Projet Camétéo",
|
"Projet Camétéo",
|
||||||
font=font16_bold,
|
font=font16_bold,
|
||||||
fill=white)
|
fill=white)
|
||||||
|
#Write hostname and IP address
|
||||||
draw.text((0, 19),
|
draw.text((0, 19),
|
||||||
"{} : IP= {}".format(socket.gethostname(),
|
"{} : IP= {}".format(socket.gethostname(),
|
||||||
netifaces.ifaddresses('wlan0')[2][0]['addr']),
|
netifaces.ifaddresses('wlan0')[2][0]['addr']),
|
||||||
font = font12,
|
font = font12,
|
||||||
fill=black )
|
fill=black )
|
||||||
|
# Draw the black lines for data table
|
||||||
draw.line((0,49,epd2in13.EPD_HEIGHT, 49), fill=black)
|
draw.line((0,49,epd2in13.EPD_HEIGHT, 49), fill=black)
|
||||||
draw.line((0,71,epd2in13.EPD_HEIGHT, 71), fill=black)
|
draw.line((0,71,epd2in13.EPD_HEIGHT, 71), fill=black)
|
||||||
draw.line((0,93,epd2in13.EPD_HEIGHT, 93), fill=black)
|
draw.line((0,93,epd2in13.EPD_HEIGHT, 93), fill=black)
|
||||||
@ -199,11 +201,6 @@ draw.line((125, 49, 125, 93), fill=black)
|
|||||||
epd.clear_frame_memory(0xFF)
|
epd.clear_frame_memory(0xFF)
|
||||||
update_epd()
|
update_epd()
|
||||||
|
|
||||||
#
|
|
||||||
#screen = image.rotate(90, expand=True)
|
|
||||||
#epd.set_frame_memory(screen, 0, 0)
|
|
||||||
#epd.display_frame()
|
|
||||||
|
|
||||||
#Toggle to partial refresh
|
#Toggle to partial refresh
|
||||||
epd.init(epd.lut_partial_update)
|
epd.init(epd.lut_partial_update)
|
||||||
|
|
||||||
@ -213,8 +210,7 @@ mqtt_client.username_pw_set(mqtt_user, mqtt_pass)
|
|||||||
mqtt_client.on_connect = on_connect
|
mqtt_client.on_connect = on_connect
|
||||||
mqtt_client.on_message = on_message
|
mqtt_client.on_message = on_message
|
||||||
mqtt_client.on_disconnect = on_disconnect
|
mqtt_client.on_disconnect = on_disconnect
|
||||||
|
#Special callback for camera
|
||||||
#mqtt_client.message_callback_add("feather0/NTP/date", on_message_date)
|
|
||||||
mqtt_client.message_callback_add(camera_mqtt_topic + "/#", on_message_camera)
|
mqtt_client.message_callback_add(camera_mqtt_topic + "/#", on_message_camera)
|
||||||
|
|
||||||
print(mqtt_host + ":" + str(mqtt_port))
|
print(mqtt_host + ":" + str(mqtt_port))
|
||||||
|
Loading…
Reference in New Issue
Block a user