@@ -59,17 +59,40 @@ def pack_wrgb(input: wrgb | rgb) -> int:
5959 with SyncCrazyflie (URI , cf = Crazyflie (rw_cache = './cache' )) as scf :
6060 cf = scf .cf
6161
62+ # Detect which color LED deck is present (bottom or top)
63+ # We check for whichever deck is attached and use the first one found
64+ # Check for bottom-facing deck first
65+ if str (cf .param .get_value ('deck.bcColorLedBot' )) == '1' :
66+ deck_params = {
67+ 'color' : 'colorLedBot.wrgb8888' ,
68+ 'brightness' : 'colorLedBot.brightCorr' ,
69+ 'throttle' : 'colorLedBot.throttlePct' ,
70+ 'temp' : 'colorLedBot.deckTemp'
71+ }
72+ print ('Detected bottom-facing color LED deck' )
73+ # Check for top-facing deck
74+ elif str (cf .param .get_value ('deck.bcColorLedTop' )) == '1' :
75+ deck_params = {
76+ 'color' : 'colorLedTop.wrgb8888' ,
77+ 'brightness' : 'colorLedTop.brightCorr' ,
78+ 'throttle' : 'colorLedTop.throttlePct' ,
79+ 'temp' : 'colorLedTop.deckTemp'
80+ }
81+ print ('Detected top-facing color LED deck' )
82+ else :
83+ raise RuntimeError ('No color LED deck detected!' )
84+
6285 # Thermal status callback
6386 def thermal_status_callback (timestamp , data , logconf ):
64- throttle_pct = data ['colorled.throttlePct' ]
87+ throttle_pct = data [deck_params [ 'throttle' ] ]
6588 if throttle_pct > 0 :
66- temp = data ['colorled.deckTemp' ]
89+ temp = data [deck_params [ 'temp' ] ]
6790 print (f'WARNING: Thermal throttling active! Temp: { temp } °C, Throttle: { throttle_pct } %' )
6891
6992 # Setup log configuration for thermal monitoring
7093 log_conf = LogConfig (name = 'ThermalStatus' , period_in_ms = 100 )
71- log_conf .add_variable ('colorled.deckTemp' , 'uint8_t' )
72- log_conf .add_variable ('colorled.throttlePct' , 'uint8_t' )
94+ log_conf .add_variable (deck_params [ 'temp' ] , 'uint8_t' )
95+ log_conf .add_variable (deck_params [ 'throttle' ] , 'uint8_t' )
7396
7497 cf .log .add_config (log_conf )
7598 log_conf .data_received_cb .add_callback (thermal_status_callback )
@@ -78,7 +101,7 @@ def thermal_status_callback(timestamp, data, logconf):
78101 # Brightness correction: balances luminance across R/G/B/W channels
79102 # Set to 1 (enabled, default) for perceptually uniform colors
80103 # Set to 0 (disabled) for maximum brightness per channel
81- cf .param .set_value ('colorled.brightnessCorr' , 1 )
104+ cf .param .set_value (deck_params [ 'brightness' ] , 1 )
82105 time .sleep (0.1 )
83106
84107 try :
@@ -97,13 +120,13 @@ def thermal_status_callback(timestamp, data, logconf):
97120 # ========================================
98121
99122 color_uint32 = pack_wrgb (color )
100- cf .param .set_value ('colorled.wrgb8888' , color_uint32 )
123+ cf .param .set_value (deck_params [ 'color' ] , color_uint32 )
101124 time .sleep (0.01 )
102125 print (f'Setting LED to R={ color .r } , G={ color .g } , B={ color .b } , W={ color .w } ' )
103126 print ('Press Ctrl-C to turn off LED and exit.' )
104127 while True :
105128 time .sleep (0.1 )
106129 except KeyboardInterrupt :
107130 print ('\n Stopping and turning off LED...' )
108- cf .param .set_value ('colorled.wrgb8888' , 0 )
131+ cf .param .set_value (deck_params [ 'color' ] , 0 )
109132 time .sleep (0.1 )
0 commit comments