6
6
This is a simple application to configure the static libraries for the ESP32 Arduino core.
7
7
It allows the user to select the targets to compile, change the configuration options and compile the libraries.
8
8
9
- The application is built using the ' textual' library, which is a Python library for building text-based user interfaces.
9
+ The application is built using the " textual" library, which is a Python library for building text-based user interfaces.
10
10
11
11
The first argument to the script is the path to the Arduino core. If no argument is provided, it is assumed that the
12
12
Arduino core is located in the default path `/arduino-esp32` (docker image default).
13
13
14
14
"""
15
15
16
+ import argparse
16
17
import os
18
+ import platform
19
+
20
+ from pathlib import Path
17
21
18
22
try :
19
23
from textual .app import App , ComposeResult
20
24
from textual .containers import Container
21
25
from textual .widgets import Button , Header , Label
22
26
except ImportError :
23
- print ("Please install the ' textual-dev' package before running this script." )
27
+ print ("Please install the \" textual-dev\" package before running this script." )
24
28
quit ()
25
29
26
30
from targets import TargetsScreen
@@ -32,11 +36,16 @@ class ConfigEditorApp(App):
32
36
33
37
# Change to the root directory of the app to the root of the project
34
38
script_path = os .path .abspath (os .path .dirname (__file__ ))
35
- root_path = os .path .abspath (os .path .join (script_path , '..' , '..' ))
39
+ root_path = os .path .abspath (os .path .join (script_path , ".." , ".." ))
36
40
os .chdir (root_path )
37
41
38
- # Target is set to "all" by default
39
- target_str = "all"
42
+ # Options
43
+ option_target = None
44
+ option_arduino_path = None
45
+ option_arduino_branch = None
46
+ option_idf_branch = None
47
+ option_idf_commit = None
48
+ option_debug_level = None
40
49
41
50
ENABLE_COMMAND_PALETTE = False
42
51
CSS_PATH = "style.tcss"
@@ -50,19 +59,19 @@ def update_targets(self, targets: str) -> None:
50
59
# Callback function to update the targets after returning from the targets screen
51
60
print ("Updating targets in app, received: " + targets )
52
61
if targets :
53
- self .target_str = str (targets )
62
+ self .option_target = str (targets )
54
63
55
64
def on_button_pressed (self , event : Button .Pressed ) -> None :
56
65
# Event handler called when a button is pressed
57
66
if event .button .id == "compile-button" :
58
67
print ("Compile button pressed" )
59
- self .push_screen (' compile' )
68
+ self .push_screen (" compile" )
60
69
elif event .button .id == "targets-button" :
61
70
print ("Targets button pressed" )
62
- self .push_screen (' targets' , self .update_targets )
71
+ self .push_screen (" targets" , self .update_targets )
63
72
elif event .button .id == "options-button" :
64
73
print ("Options button pressed" )
65
- self .push_screen (' editor' )
74
+ self .push_screen (" editor" )
66
75
elif event .button .id == "quit-button" :
67
76
print ("Quit button pressed" )
68
77
quit ()
@@ -81,12 +90,82 @@ def on_mount(self) -> None:
81
90
# Event handler called when the app is mounted for the first time
82
91
self .title = "Configurator"
83
92
self .sub_title = "Main Menu"
84
- print ("App started" )
85
-
93
+ print ("App started. Initial Options:" )
94
+ print ("Target: " + str (self .option_target ))
95
+ print ("Arduino Path: " + str (self .option_arduino_path ))
96
+ print ("Arduino Branch: " + str (self .option_arduino_branch ))
97
+ print ("IDF Branch: " + str (self .option_idf_branch ))
98
+ print ("IDF Commit: " + str (self .option_idf_commit ))
99
+ print ("IDF Debug Level: " + str (self .option_debug_level ))
100
+
101
+ def arduino_default_path ():
102
+ sys_name = platform .system ()
103
+ home = str (Path .home ())
104
+ if sys_name == "Linux" :
105
+ return os .path .join (home , "Arduino" , "hardware" , "espressif" , "esp32" )
106
+ else : # Windows and MacOS
107
+ return os .path .join (home , "Documents" , "Arduino" , "hardware" , "espressif" , "esp32" )
86
108
87
109
def main () -> None :
110
+ app = ConfigEditorApp ()
111
+
112
+ parser = argparse .ArgumentParser (description = "Configure and compile the ESP32 Arduino static libraries" )
113
+
114
+ target_choices = ("all" , "esp32" , "esp32s2" , "esp32s3" , "esp32c2" , "esp32c3" , "esp32c6" , "esp32h2" )
115
+ parser .add_argument ("-t" , "--target" ,
116
+ metavar = "<target>" ,
117
+ type = str ,
118
+ default = "all" ,
119
+ choices = target_choices ,
120
+ required = False ,
121
+ help = "Target to be compiled. Choose from: " + ", " .join (target_choices ))
122
+
123
+ parser .add_argument ("-c" , "--arduino-path" ,
124
+ metavar = "<arduino path>" ,
125
+ type = str ,
126
+ default = arduino_default_path (),
127
+ required = False ,
128
+ help = "Path to arduino-esp32 directory" )
129
+
130
+ parser .add_argument ("-A" , "--arduino-branch" ,
131
+ metavar = "<arduino branch>" ,
132
+ type = str ,
133
+ required = False ,
134
+ help = "Branch of the arduino-esp32 repository to be used" )
135
+
136
+ parser .add_argument ("-I" , "--idf-branch" ,
137
+ metavar = "<IDF branch>" ,
138
+ type = str ,
139
+ required = False ,
140
+ help = "Branch of the ESP-IDF repository to be used" )
141
+
142
+ parser .add_argument ("-i" , "--idf-commit" ,
143
+ metavar = "<IDF commit>" ,
144
+ type = str ,
145
+ required = False ,
146
+ help = "Commit of the ESP-IDF repository to be used" )
147
+
148
+ debug_level_choices = ("default" , "none" , "error" , "warning" , "info" , "debug" , "verbose" )
149
+ parser .add_argument ("-D" , "--debug-level" ,
150
+ metavar = "<level>" ,
151
+ type = str ,
152
+ default = "default" ,
153
+ choices = debug_level_choices ,
154
+ required = False ,
155
+ help = "Debug level to be set to ESP-IDF. Choose from: " + ", " .join (debug_level_choices ))
156
+
157
+ args = parser .parse_args ()
158
+
159
+ # Set the options in the app
160
+ app .option_target = args .target
161
+ app .option_arduino_path = args .arduino_path
162
+ app .option_arduino_branch = args .arduino_branch
163
+ app .option_idf_branch = args .idf_branch
164
+ app .option_idf_commit = args .idf_commit
165
+ app .option_debug_level = args .debug_level
166
+
88
167
# Main function to run the app
89
- ConfigEditorApp () .run ()
168
+ app .run ()
90
169
91
170
if __name__ == "__main__" :
92
171
# If this script is run directly, start the app
0 commit comments