5454requests = adafruit_requests .Session (pool , context )
5555
5656# --- Matrix setup ---
57- base_width = 64
58- base_height = 32
59- chain_across = 3 # 3 panels chained across
60- tile_down = 2 # 2 panels tiled down
61- DISPLAY_WIDTH = base_width * chain_across
62- DISPLAY_HEIGHT = base_height * tile_down
57+ DISPLAY_WIDTH = 192
58+ DISPLAY_HEIGHT = 128
59+ BIT_DEPTH = 2
60+ AUTO_REFRESH = False
6361matrix = rgbmatrix .RGBMatrix (
64- width = DISPLAY_WIDTH ,
65- height = DISPLAY_HEIGHT , # Fixed: Changed from 'width' to 'height'
66- bit_depth = 1 ,
62+ width = DISPLAY_WIDTH , height = DISPLAY_HEIGHT , bit_depth = BIT_DEPTH ,
6763 rgb_pins = [
6864 board .MTX_R1 ,
6965 board .MTX_G1 ,
8278 clock_pin = board .MTX_CLK ,
8379 latch_pin = board .MTX_LAT ,
8480 output_enable_pin = board .MTX_OE ,
85-
81+ tile = 2 ,
8682 serpentine = False ,
87- doublebuffer = False ,
88- )
83+ doublebuffer = False )
8984
9085# --- Drawing setup ---
9186#font = bitmap_font.load_font("/tom-thumb.pcf")
10095# --- Icon Positioning ---
10196ICON_HEIGHT = 26 # Height of the icon
10297GAP_BETWEEN_ICONS = 15 # Gap between the icons
103- NUMBER_OF_ICONS = 2 # Number of icons to display
98+ NUMBER_OF_ICONS = 4 # Number of icons to display
10499total_icons_height = (ICON_HEIGHT * NUMBER_OF_ICONS ) + (GAP_BETWEEN_ICONS * (NUMBER_OF_ICONS - 1 ))
105100
106101# Calculate the starting y-position for the first icon to center them vertically
118113def scroll_icons (icon_tile ):
119114 icon_tile .x -= 1
120115 if icon_tile .x < - 64 : # Assuming each icon is 64 pixels wide
121- icon_tile .x = 128 # Reset position to the rightmost
116+ icon_tile .x = 130 # Reset position to the rightmost
122117
123118
124119# Function to scroll the icons
@@ -129,7 +124,7 @@ def scroll_icons(icon_tile):
129124def scroll_text_labels (text_labels ):
130125 for label in text_labels :
131126 label .x -= 1 # Move label left.
132- if label .x < - 256 : # If label has moved off screen.
127+ if label .x < - 300 : # If label has moved off screen.
133128 label .x = TEXT_RESET_X
134129
135130
@@ -166,6 +161,7 @@ def update_flight_labels(flights_data):
166161# Call this function with fetched flight data
167162
168163
164+ #anA5AXJkYlfC2SNgWghB27mkNO9RRaTI
169165
170166def fetch_flight_data ():
171167 print ("Running fetch_flight_data" )
@@ -176,7 +172,7 @@ def fetch_flight_data():
176172 }
177173 headers = {
178174 "Accept" : "application/json; charset=UTF-8" ,
179- "x-apikey" : "" # Replace with your actual API key
175+ "x-apikey" : "anA5AXJkYlfC2SNgWghB27mkNO9RRaTI " # Replace with your actual API key
180176 }
181177 full_url = f"{ base_url } ?{ construct_query_string (params )} "
182178 response = requests .get (full_url , headers = headers )
@@ -208,7 +204,7 @@ def process_flight_data(json_data):
208204 'origin_city' : flight .get ('origin' , {}).get ('city' , 'UnknownB' ),
209205 'origin_country' : flight .get ('origin' , {}).get ('country' , 'UnknownC' ),
210206 'destination_code' : flight .get ('destination' , {}).get ('code' , 'UnknownD' ) if flight .get ('destination' ) else 'UnknownE' ,
211- 'destination_city' : flight .get ('destination' , {}).get ('city' , 'UnknownH' ) if flight .get ('destination' ) else 'UnknownF ' ,
207+ 'destination_city' : flight .get ('destination' , {}).get ('city' , 'UnknownH' ) if flight .get ('destination' ) else 'Unknown Destination ' ,
212208 'destination_country' : flight .get ('destination' , {}).get ('country' , 'UnknownZ' ) if flight .get ('destination' ) else 'UnknownG' ,
213209 'altitude' : flight .get ('last_position' , {}).get ('altitude' , 'N/A' ),
214210 'groundspeed' : flight .get ('last_position' , {}).get ('groundspeed' , 'N/A' ),
@@ -270,7 +266,7 @@ def create_icon_tilegrid(ident):
270266
271267DISPLAY_HEIGHT = 64 # Total display height in pixels
272268ICON_HEIGHT = 26 # Height of each icon in pixels
273- NUM_ICONS = 3 # Adjusted number of icons to display without overlap
269+ NUM_ICONS = 4 # Adjusted number of icons to display without overlap
274270
275271# Calculate the space needed for all icons
276272total_icon_height = ICON_HEIGHT * NUM_ICONS
@@ -290,14 +286,26 @@ def update_display_with_flight_data(flight_data, icon_group, display_group):
290286 # Clear previous display items
291287 while len (display_group ):
292288 display_group .pop ()
293-
289+
294290 # Clear previous icon items
295291 while len (icon_group ):
296292 icon_group .pop ()
297293
298294 # Limit flight data to the adjusted number of icons
299295 flight_data = flight_data [:NUM_ICONS ]
300296
297+ # Calculate the space needed for all icons
298+ total_icon_height = ICON_HEIGHT * NUM_ICONS
299+
300+ # Calculate the remaining space after placing all icons
301+ remaining_space = DISPLAY_HEIGHT - total_icon_height
302+
303+ # Calculate the gap between icons, assuming even spacing above the first icon and below the last icon
304+ gap_between_icons = 5
305+
306+ # Calculate the y position for each icon
307+ y_positions = [gap_between_icons + (ICON_HEIGHT + gap_between_icons ) * i for i in range (NUM_ICONS )]
308+
301309 # Create text labels for up to NUM_ICONS flights
302310 text_labels = create_text_labels (flight_data , y_positions )
303311
@@ -308,14 +316,15 @@ def update_display_with_flight_data(flight_data, icon_group, display_group):
308316 # Load icons and create icon tilegrids for up to NUM_ICONS flights
309317 for i , flight in enumerate (flight_data ):
310318 # Calculate the y position for each icon
319+ print (y_positions [i ])
311320 y_position = y_positions [i ]
312321
313322 # Load the icon dynamically
314323 icon_tilegrid = create_icon_tilegrid (flight ['ident' ])
315324 if icon_tilegrid :
316325 icon_tilegrid .y = y_position
317326 icon_group .append (icon_tilegrid )
318-
327+
319328 # Add the icon group to the main display group after text labels
320329 display_group .append (icon_group )
321330
@@ -356,11 +365,29 @@ def update_display_with_flight_data(flight_data, icon_group, display_group):
356365if flight_data :
357366 text_labels = update_display_with_flight_data (flight_data , static_icon_group , main_group )
358367
359-
368+
369+ start_time = time .time ()
370+ last_network_call_time = time .monotonic ()
371+
372+ NETWORK_CALL_INTERVAL = 400000 # 5 minutes
373+
374+
360375while True :
376+ # Scroll the text labels
361377 scroll_text_labels (text_labels )
362-
363378 # Refresh the display
364379 display .refresh (minimum_frames_per_second = 0 )
380+ current_time = time .monotonic ()
381+
382+ # Check if 20 minutes have passed
383+ if (current_time - last_network_call_time ) >= NETWORK_CALL_INTERVAL :
384+ # Make network call here
385+
386+ flight_data = fetch_flight_data ()
387+ last_network_call_time = current_time
388+
389+ # Reset the scroll or perform any other reset actions here
390+ # reset_scroll(text_labels) # Assuming you have a function to reset the scroll
365391
366- time .sleep (1200 )
392+ # Sleep for a short period to prevent maxing out your CPU
393+ time .sleep (1 ) # Sleep for 100 milliseconds
0 commit comments