Skip to content

Commit 359769c

Browse files
committed
Add C++ and command line disable UART options
1 parent 3716ca0 commit 359769c

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

pico_project.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
isWindows = False
203203

204204
class Parameters():
205-
def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, features, projects, configs, runFromRAM, examples, uart, usb):
205+
def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, features, projects, configs, runFromRAM, examples, uart, usb, cpp):
206206
self.sdkPath = sdkPath
207207
self.projectRoot = projectRoot
208208
self.projectName = projectName
@@ -216,6 +216,7 @@ def __init__(self, sdkPath, projectRoot, projectName, gui, overwrite, build, fea
216216
self.wantExamples = examples
217217
self.wantUART = uart
218218
self.wantUSB = usb
219+
self.wantCPP = cpp
219220

220221
def GetBackground():
221222
return 'white'
@@ -652,6 +653,10 @@ def init_window(self, args):
652653
self.wantRunFromRAM.set(args.runFromRAM)
653654
ttk.Checkbutton(coptionsSubframe, text="Run from RAM", variable=self.wantRunFromRAM).grid(row=0, column=1, padx=4, sticky=tk.W)
654655

656+
self.wantCPP = tk.IntVar()
657+
self.wantCPP.set(args.cpp)
658+
ttk.Checkbutton(coptionsSubframe, text="Generate C++", variable=self.wantCPP).grid(row=0, column=3, padx=4, sticky=tk.W)
659+
655660
ttk.Button(coptionsSubframe, text="Advanced...", command=self.config).grid(row=0, column=4, sticky=tk.E)
656661

657662
optionsRow += 2
@@ -712,7 +717,7 @@ def OK(self):
712717
p = Parameters(sdkPath=self.sdkpath, projectRoot=Path(projectPath), projectName=self.projectName.get(),
713718
gui=True, overwrite=self.wantOverwrite.get(), build=self.wantBuild.get(),
714719
features=features, projects=projects, configs=self.configs, runFromRAM=self.wantRunFromRAM.get(),
715-
examples=self.wantExamples.get(), uart=self.wantUART.get(), usb=self.wantUSB.get())
720+
examples=self.wantExamples.get(), uart=self.wantUART.get(), usb=self.wantUSB.get(), cpp=self.wantCPP.get())
716721

717722
DoEverything(self, p)
718723

@@ -773,14 +778,19 @@ def ParseCommandLine():
773778
parser.add_argument("-p", "--project", action='append', help="Generate projects files for IDE. Options are: vscode")
774779
parser.add_argument("-r", "--runFromRAM", action='store_true', help="Run the program from RAM rather than flash")
775780
parser.add_argument("-uart", "--uart", action='store_true', default=1, help="Console output to UART (default)")
781+
parser.add_argument("-nouart", "--nouart", action='store_true', default=0, help="Disable console output to UART")
776782
parser.add_argument("-usb", "--usb", action='store_true', help="Console output to USB (disables other USB functionality")
783+
parser.add_argument("-cpp", "--cpp", action='store_true', default=0, help="Generate C++ code")
777784

778785
return parser.parse_args()
779786

780787

781-
def GenerateMain(folder, projectName, features):
788+
def GenerateMain(folder, projectName, features, cpp):
782789

783-
filename = Path(folder) / (projectName + '.c')
790+
if cpp:
791+
filename = Path(folder) / (projectName + '.cpp')
792+
else:
793+
filename = Path(folder) / (projectName + '.c')
784794

785795
file = open(filename, 'w')
786796

@@ -885,7 +895,11 @@ def GenerateCMake(folder, params):
885895
# No GUI/command line to set a different executable name at this stage
886896
executableName = params.projectName
887897

888-
file.write('add_executable(' + params.projectName + ' ' + params.projectName + '.c )\n\n')
898+
if params.wantCPP:
899+
file.write('add_executable(' + params.projectName + ' ' + params.projectName + '.cpp )\n\n')
900+
else:
901+
file.write('add_executable(' + params.projectName + ' ' + params.projectName + '.c )\n\n')
902+
889903
file.write('pico_set_program_name(' + params.projectName + ' "' + executableName + '")\n')
890904
file.write('pico_set_program_version(' + params.projectName + ' "0.1")\n\n')
891905

@@ -1077,7 +1091,7 @@ def DoEverything(parent, params):
10771091
if params.wantExamples:
10781092
features_and_examples = list(stdlib_examples_list.keys()) + features_and_examples
10791093

1080-
GenerateMain('.', params.projectName, features_and_examples)
1094+
GenerateMain('.', params.projectName, features_and_examples, params.wantCPP)
10811095

10821096
GenerateCMake('.', params)
10831097

@@ -1121,6 +1135,8 @@ def DoEverything(parent, params):
11211135

11221136
args = ParseCommandLine()
11231137

1138+
if args.nouart:
1139+
args.uart = False
11241140

11251141
# Check we have everything we need to compile etc
11261142
c = CheckPrerequisites()
@@ -1175,7 +1191,7 @@ def DoEverything(parent, params):
11751191
p = Parameters(sdkPath=sdkPath, projectRoot=projectRoot, projectName=args.name,
11761192
gui=False, overwrite=args.overwrite, build=args.build, features=args.feature,
11771193
projects=args.project, configs=(), runFromRAM=args.runFromRAM,
1178-
examples=args.examples, uart=args.uart, usb=args.usb)
1194+
examples=args.examples, uart=args.uart, usb=args.usb, cpp=args.cpp)
11791195

11801196
DoEverything(None, p)
11811197

0 commit comments

Comments
 (0)