3535
3636# font = bitmap_font.load_font("/tom-thumb.pcf")
3737font = terminalio .FONT
38- text_color = 0xFC6900 # e.g., Retro Orange
39- colors = [0xFC6900 , 0xDD8000 ]
38+ text_color = 0x01F9C6 # e.g., Retro Orange
39+ colors = [0x01F9C6 , 0x01F9C6 ]
4040
4141# --- Wi-Fi setup ---
4242wifi .radio .connect (
5454requests = adafruit_requests .Session (pool , context )
5555
5656# --- Matrix setup ---
57- DISPLAY_WIDTH = 192
58- DISPLAY_HEIGHT = 64
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
5963matrix = rgbmatrix .RGBMatrix (
6064 width = DISPLAY_WIDTH ,
61- height = DISPLAY_HEIGHT ,
62- bit_depth = 2 ,
65+ height = DISPLAY_HEIGHT , # Fixed: Changed from 'width' to 'height'
66+ bit_depth = 1 ,
6367 rgb_pins = [
6468 board .MTX_R1 ,
6569 board .MTX_G1 ,
7882 clock_pin = board .MTX_CLK ,
7983 latch_pin = board .MTX_LAT ,
8084 output_enable_pin = board .MTX_OE ,
81- tile = 1 ,
82- serpentine = True ,
85+
86+ serpentine = False ,
8387 doublebuffer = False ,
8488)
8589
8690# --- Drawing setup ---
8791#font = bitmap_font.load_font("/tom-thumb.pcf")
8892font = terminalio .FONT
89- text_color = 0xFC6900 # e.g., Retro Orange
93+ text_color = 0x22ff00 # e.g., Retro Orange
9094colors = [0xFC6900 , 0xDD8000 ]
9195
9296group = Group ()
9599
96100# --- Icon Positioning ---
97101ICON_HEIGHT = 26 # Height of the icon
98- GAP_BETWEEN_ICONS = 12 # Gap between the icons
102+ GAP_BETWEEN_ICONS = 15 # Gap between the icons
99103NUMBER_OF_ICONS = 2 # Number of icons to display
100104total_icons_height = (ICON_HEIGHT * NUMBER_OF_ICONS ) + (GAP_BETWEEN_ICONS * (NUMBER_OF_ICONS - 1 ))
101105
107111icon_group = Group ()
108112
109113
110- gap_between_lines = 12
114+ gap_between_lines = 32
111115
112116display .show (icon_group )
113117
@@ -117,10 +121,6 @@ def scroll_icons(icon_tile):
117121 icon_tile .x = 128 # Reset position to the rightmost
118122
119123
120-
121-
122-
123-
124124# Function to scroll the icons
125125TEXT_RESET_X = 170
126126
@@ -133,19 +133,21 @@ def scroll_text_labels(text_labels):
133133 label .x = TEXT_RESET_X
134134
135135
136+ kbounding_box = {
137+ "min_latitude" : 40.671859 , # Southernmost latitude
138+ "max_latitude" : 40.696278 , # Northernmost latitude
139+ "min_longitude" : - 73.932734 , # Westernmost longitude
140+ "max_longitude" : - 73.788054 , # Easternmost longitude
141+ }
136142
137- seen_flight_numbers = set () # To keep track of processed flight numbers
138143
139144bounding_box = {
140- "min_latitude" : 40.962321 , # Southernmost latitude
145+ "min_latitude" : 40.633013 , # Southernmost latitude
141146 "max_latitude" : 44.953469 , # Northernmost latitude
142147 "min_longitude" : - 111.045360 , # Westernmost longitude
143148 "max_longitude" : - 104.046570 , # Easternmost longitude
144149}
145150
146- # curl -X GET "https://aeroapi.flightaware.com/aeroapi/flights/search?query=-latlong+%2244.953469+-111.045360+40.962321+-104.046577%22&max_pages=1" \
147- # -H "Accept: application/json; charset=UTF-8" \
148- # -H "x-apikey: -AN API KEY-"
149151
150152def degrees_to_cardinal (d ):
151153 dirs = ["N" , "NE" , "E" , "SE" , "S" , "SW" , "W" , "NW" ]
@@ -164,7 +166,6 @@ def update_flight_labels(flights_data):
164166# Call this function with fetched flight data
165167
166168
167- #anA5AXJkYlfC2SNgWghB27mkNO9RRaTI
168169
169170def fetch_flight_data ():
170171 print ("Running fetch_flight_data" )
@@ -175,7 +176,7 @@ def fetch_flight_data():
175176 }
176177 headers = {
177178 "Accept" : "application/json; charset=UTF-8" ,
178- "x-apikey" : "anA5AXJkYlfC2SNgWghB27mkNO9RRaTI " # Replace with your actual API key
179+ "x-apikey" : "" # Replace with your actual API key
179180 }
180181 full_url = f"{ base_url } ?{ construct_query_string (params )} "
181182 response = requests .get (full_url , headers = headers )
@@ -189,6 +190,8 @@ def fetch_flight_data():
189190 print (f"Response content: { response .content } " )
190191 return [] # Return an empty list if the request failed
191192
193+
194+
192195def process_flight_data (json_data ):
193196 # Initialize an empty list to hold processed flight data
194197 processed_flights = []
@@ -201,12 +204,12 @@ def process_flight_data(json_data):
201204 'fa_flight_id' : flight .get ('fa_flight_id' , 'N/A' ),
202205 'actual_off' : flight .get ('actual_off' , 'N/A' ),
203206 'actual_on' : flight .get ('actual_on' , 'N/A' ),
204- 'origin_code' : flight .get ('origin' , {}).get ('code' , 'Unknown ' ),
205- 'origin_city' : flight .get ('origin' , {}).get ('city' , 'Unknown ' ),
206- 'origin_country' : flight .get ('origin' , {}).get ('country' , 'Unknown ' ),
207- 'destination_code' : flight .get ('destination' , {}).get ('code' , 'Unknown ' ) if flight .get ('destination' ) else 'Unknown ' ,
208- 'destination_city' : flight .get ('destination' , {}).get ('city' , 'Unknown ' ) if flight .get ('destination' ) else 'Unknown ' ,
209- 'destination_country' : flight .get ('destination' , {}).get ('country' , 'Unknown ' ) if flight .get ('destination' ) else 'Unknown ' ,
207+ 'origin_code' : flight .get ('origin' , {}).get ('code' , 'UnknownA ' ),
208+ 'origin_city' : flight .get ('origin' , {}).get ('city' , 'UnknownB ' ),
209+ 'origin_country' : flight .get ('origin' , {}).get ('country' , 'UnknownC ' ),
210+ '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 ' ,
212+ 'destination_country' : flight .get ('destination' , {}).get ('country' , 'UnknownZ ' ) if flight .get ('destination' ) else 'UnknownG ' ,
210213 'altitude' : flight .get ('last_position' , {}).get ('altitude' , 'N/A' ),
211214 'groundspeed' : flight .get ('last_position' , {}).get ('groundspeed' , 'N/A' ),
212215 'heading' : flight .get ('last_position' , {}).get ('heading' , 'N/A' ),
@@ -222,28 +225,18 @@ def process_flight_data(json_data):
222225 return processed_flights
223226
224227
225-
226-
227-
228- def create_text_labels (flight_data , display_group ):
228+
229+ def create_text_labels (flight_data , y_positions ):
229230 text_labels = []
230231 for i , flight in enumerate (flight_data ):
231- y_position = i * gap_between_lines + 15
232+ y_position = y_positions [ i ] + GAP_BETWEEN_ICONS
232233
233- # Since 'country' is not present, we'll use 'origin_city' and 'destination_code' instead
234- # Construct the display text for each flight without 'country'
235-
234+ # Since 'country' is not present, use 'origin_city' and 'destination_city' instead
236235 origin_city = flight .get ('origin_city' , 'Unknown City' )
237- origin_country = flight .get ('origin_country' , 'Unknown Country' )
238236 destination_city = flight .get ('destination_city' , 'Unknown City' )
239- destination_country = flight .get ('destination_country' , 'Unknown Country' )
240-
241- # Format from and to locations with city and country
242- from_location = f"{ origin_city } , { origin_country } "
243- to_location = f"{ destination_city } , { destination_country } "
244237
245238 # Construct the display text for each flight
246- single_line_text = f"{ flight ['ident' ]} | From: { from_location } To: { to_location } "
239+ single_line_text = f"{ flight ['ident' ]} | From: { origin_city } To: { destination_city } "
247240
248241 text_label = adafruit_display_text .label .Label (
249242 font ,
@@ -252,65 +245,97 @@ def create_text_labels(flight_data, display_group):
252245 y = y_position ,
253246 text = single_line_text
254247 )
255- display_group .append (text_label )
256248 text_labels .append (text_label )
257249 return text_labels
258250
259251
252+
260253def create_icon_tilegrid (ident ):
261254 airline_code = ident [:3 ].upper () # Use the first three characters of 'ident'
262255 icon_path = f"/airline_logos/{ airline_code } .bmp"
263256 try :
264257 icon_bitmap = OnDiskBitmap (open (icon_path , "rb" ))
265- icon_tilegrid = TileGrid (icon_bitmap , pixel_shader = icon_bitmap .pixel_shader , x = 0 , y = 0 )
266- return icon_tilegrid
267258 except OSError :
268- print (f"Icon for { airline_code } not found." )
269- return None
259+ print (f"Icon for { airline_code } not found. Using placeholder." )
260+ icon_path = "/airline_logos/placeholder.bmp" # Path to the placeholder image
261+ icon_bitmap = OnDiskBitmap (open (icon_path , "rb" )) # Open the placeholder image
262+
263+ icon_tilegrid = TileGrid (icon_bitmap , pixel_shader = icon_bitmap .pixel_shader , x = 0 , y = 0 )
264+ return icon_tilegrid
265+
266+
267+
268+
269+
270+
271+ DISPLAY_HEIGHT = 64 # Total display height in pixels
272+ ICON_HEIGHT = 26 # Height of each icon in pixels
273+ NUM_ICONS = 3 # Adjusted number of icons to display without overlap
274+
275+ # Calculate the space needed for all icons
276+ total_icon_height = ICON_HEIGHT * NUM_ICONS
277+
278+ # Calculate the remaining space after placing all icons
279+ remaining_space = DISPLAY_HEIGHT - total_icon_height
280+
281+ # Calculate the gap between icons, assuming even spacing above the first icon and below the last icon
282+ gap_between_icons = remaining_space // (NUM_ICONS + 1 )
283+
284+ # Calculate the y position for each icon
285+ y_positions = [gap_between_icons + (ICON_HEIGHT + gap_between_icons ) * i for i in range (NUM_ICONS )]
286+
287+
270288
271- # Update your display update function to include icon creation and text label setup
272289def update_display_with_flight_data (flight_data , icon_group , display_group ):
273290 # Clear previous display items
274291 while len (display_group ):
275292 display_group .pop ()
293+
294+ # Clear previous icon items
295+ while len (icon_group ):
296+ icon_group .pop ()
276297
298+ # Limit flight data to the adjusted number of icons
299+ flight_data = flight_data [:NUM_ICONS ]
277300
301+ # Create text labels for up to NUM_ICONS flights
302+ text_labels = create_text_labels (flight_data , y_positions )
278303
279- # Limit flight data to only 4 flights
280- flight_data = flight_data [:4 ]
304+ # Add text labels to the display group first so they are behind icons
305+ for label in text_labels :
306+ display_group .append (label )
281307
282- # Load icons and create text labels for up to 4 flights
308+ # Load icons and create icon tilegrids for up to NUM_ICONS flights
283309 for i , flight in enumerate (flight_data ):
284- y_position = i * gap_between_lines + 10
310+ # Calculate the y position for each icon
311+ y_position = y_positions [i ]
285312
286313 # Load the icon dynamically
287314 icon_tilegrid = create_icon_tilegrid (flight ['ident' ])
288315 if icon_tilegrid :
289316 icon_tilegrid .y = y_position
290317 icon_group .append (icon_tilegrid )
291-
292- # Append the icon group to the main display group
318+
319+ # Add the icon group to the main display group after text labels
293320 display_group .append (icon_group )
294321
295- # Create and append text labels next to the icons
296- text_labels = create_text_labels (flight_data , display_group )
297-
298322 # Show the updated group on the display
299323 display .show (display_group )
300324 return text_labels
301325
302326
327+
303328# Initialize the main display group
304329main_group = Group ()
305330
306331# Initialize the icon group (this remains static on the display)
307332static_icon_group = Group ()
308-
309-
310- text_label = adafruit_display_text .label .Label (font , text = "Label 1" , color = 0xFFFFFF , x = DISPLAY_WIDTH , y = 1 )
311- text_label2 = adafruit_display_text .label .Label (font , text = "Label 2" , color = 0xFFFFFF , x = DISPLAY_WIDTH , y = 3 )
312- text_label3 = adafruit_display_text .label .Label (font , text = "Label 3" , color = 0xFFFFFF , x = DISPLAY_WIDTH , y = 6 )
313- text_label4 = adafruit_display_text .label .Label (font , text = "Label 4" , color = 0xFFFFFF , x = DISPLAY_WIDTH , y = 15 )
333+
334+
335+ text_label = adafruit_display_text .label .Label (font , text = "Label 1" , color = 0x617C58 , x = DISPLAY_WIDTH , y = 1 )
336+ text_label2 = adafruit_display_text .label .Label (font , text = "Label 2" , color = 0x617C58 , x = DISPLAY_WIDTH , y = 3 )
337+ text_label3 = adafruit_display_text .label .Label (font , text = "Label 3" , color = 0x617C58 , x = DISPLAY_WIDTH , y = 6 )
338+ text_label4 = adafruit_display_text .label .Label (font , text = "Label 4" , color = 0x617C58 , x = DISPLAY_WIDTH , y = 15 )
314339
315340# Add labels to a display group
316341group = displayio .Group ()
@@ -321,7 +346,7 @@ def update_display_with_flight_data(flight_data, icon_group, display_group):
321346
322347# Show the group
323348display .show (group )
324-
349+
325350flight_data = fetch_flight_data ()
326351
327352# Initialize text labels list
@@ -330,12 +355,12 @@ def update_display_with_flight_data(flight_data, icon_group, display_group):
330355# Check if we received any flight data
331356if flight_data :
332357 text_labels = update_display_with_flight_data (flight_data , static_icon_group , main_group )
333-
334-
358+
359+
335360while True :
336361 scroll_text_labels (text_labels )
337362
338363 # Refresh the display
339364 display .refresh (minimum_frames_per_second = 0 )
340-
341- time .sleep (120000 )
365+
366+ time .sleep (1200 )
0 commit comments