Skip to content

Commit

Permalink
added layout and auto interval
Browse files Browse the repository at this point in the history
  • Loading branch information
markyharris committed Mar 31, 2022
1 parent 6e59b11 commit a43940c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
4 changes: 2 additions & 2 deletions data.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kflg
KSPI
-2
1800
0
1
7 changes: 2 additions & 5 deletions metar_layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ def layout6(display, metar, remarks, print_table, use_remarks):
# layout7 #
############
# Circles theme
def layout7(display, metar, remarks, print_table, use_remarks):
def layout7(display, metar, remarks, print_table, use_remarks):
def circle_points(r, n):
circles = []
for r, n in zip(r, n):
Expand Down Expand Up @@ -1677,15 +1677,14 @@ def layout8(display, metar, remarks, print_table, use_remarks):
RADIUS = 10
MARGIN = 10
SPACING = (2*RADIUS)+MARGIN
ICON_OFFSET = COL1-COL0-60
ICON_OFFSET = COL1-COL0-65
NUM_AIRPORTS = 15

# Display box with airport and flight category. The box must be drawn first than the text
# To create rounded corner box provide the following variables in this order
# up_left_x, up_left_y, box_width, box_height, radius, box_color
def print_box(flight_cat, airport, pos1_x, pos1_y, pos2_x, pos2_y):
metar = Metar(airport)
# flightcategory, icon = flight_category(metar)
flightcategory = flight_cat
output = airport+":"+flightcategory+" "
w, h = display.draw_black.textsize(output, font=font36b)
Expand Down Expand Up @@ -1741,8 +1740,6 @@ def print_box(flight_cat, airport, pos1_x, pos1_y, pos2_x, pos2_y):

fc_ap_dict = dict(list(fc_ap_dict.items())[:NUM_AIRPORTS]) # Trim dict

# print(len(fc_ap_dict)) # debug
# print(fc_ap_dict) # debug
keys_ap = list(fc_ap_dict.keys())
values_ap = list(fc_ap_dict.values())

Expand Down
31 changes: 26 additions & 5 deletions metar_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@ def main():
epd = epd7in5b_V2.EPD() # Instantiate instance for display.

while True:
# try:
try:
# error = 1/0 #debug # forces error to test the try-except statements
if True: # used instead of the try-except statements for debug purposes.
# if True: # used instead of the try-except statements for debug purposes.
current_time = time.strftime("%m/%d/%Y %H:%M", time.localtime())

metar = Metar(airport)
remarks, print_table = decode_remarks(metar.data["properties"]["rawMessage"]) # debug
flightcategory, icon = flight_category(metar)

if len(metar.data["properties"]["rawMessage"]) > 0:
print(metar.data["properties"]["rawMessage"]+"\n")
Expand All @@ -142,12 +143,32 @@ def main():
print("Metar Updated")

main() # Build METAR data to display using specific layout

time.sleep(interval) # Sets interval of updates. 3600 = 1 hour

# Setup update interval
# The update interval can be selected via cmd line or web iterface
# If Auto Interval is selected, then Flight Category dictates update
# So the worse the weather, the more often it updates.
if interval != 0: # if not auto interval selected
print("sleep ",interval) # debug
time.sleep(interval) # Sets interval of updates. 3600 = 1 hour
else:
if flightcategory == "VFR":
print("Sleep 3600") # debug
time.sleep(3600) # 1 hour if weather is good
elif flightcategory == "MVFR":
print("Sleep 1800") # debug
time.sleep(1800) # 30 mins if marginal
elif flightcategory == "IFR":
print("Sleep 1200") # debug
time.sleep(1200) # 20 mins if stormy
elif flightcategory == "LIFR":
print("Sleep 600") # debug
time.sleep(600) # 10 mins if stormy and low visibility

epd.init()
epd.sleep()

# except Exception as e:
except Exception as e:
time.sleep(2)
print("Error Occurred in Main While Loop")
exception_type, exception_object, exception_traceback = sys.exc_info()
Expand Down
5 changes: 4 additions & 1 deletion templates/metar.html
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ <h2>METAR E-Paper Display Selector</h2>

<label for="fname"><b>Choose Update Interval:</b></label><br>
<select name="data_field3" id="data_field3">
<option value="0" {% if data_field3=="0" %} selected="selected" {% endif %}>Auto Interval</option>
<option value="60" {% if data_field3=="60" %} selected="selected" {% endif %}>1 Minute</option>
<option value="600" {% if data_field3=="600" %} selected="selected" {% endif %}>10 Minutes</option>
<option value="1200" {% if data_field3=="1200" %} selected="selected" {% endif %}>20 Minutes</option>
Expand All @@ -122,7 +123,9 @@ <h2>METAR E-Paper Display Selector</h2>
<option value="7200" {% if data_field3=="7200" %} selected="selected" {% endif %}>2 Hours</option>

</select>
<br><p>
<br>
<i><b>Note:</b> Auto Interval changes the update based on Flight Category.<br>
VFR=1 hour, MVFR=30 mins, IFR=20 mins and LIFR=10 mins</i><p>

<button class="btn btn-primary" type="submit">Submit</button>
</div>
Expand Down

0 comments on commit a43940c

Please sign in to comment.