Skip to content

Commit a27a91e

Browse files
Geoffroy ArenouCopilot
andcommitted
Review every print to do it in 1 line instead of 2
Co-authored-by: Copilot <copilot@github.com>
1 parent 53913ea commit a27a91e

7 files changed

Lines changed: 95 additions & 66 deletions

File tree

include/ESP32_Helper.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@
3838

3939
namespace ESP32_Helper
4040
{
41-
// Type definition for command handler function
42-
// Returns true if the command was handled, false otherwise
43-
typedef bool (*CommandHandlerFunc)(Command);
44-
// Type definition for command help print function
45-
typedef void (*CommandHelpFunc)();
46-
4741
/**
4842
* Initialize serial/wifi for PC communication
4943
*/

include/Structure_Helper.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,20 @@ struct Command
396396
}
397397
};
398398

399+
// Type definition for command handler function
400+
// Returns true if the command was handled, false otherwise
401+
typedef bool (*CommandHandlerFunc)(Command);
402+
// Type definition for command help print function
403+
typedef void (*CommandHelpFunc)();
404+
405+
// Used to store all custom command
406+
struct CommandHandler
407+
{
408+
String prefix;
409+
CommandHandlerFunc func;
410+
CommandHelpFunc helpFunc;
411+
};
412+
399413
// Use Start to specify the timeOut in ms,
400414
// Use IsTimeOut to check if the timer has passed the timeOut value
401415
struct Timeout

src/Debugger.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ namespace Debugger
3232

3333
void Initialisation()
3434
{
35-
Printer::print("Preparing queueSteps : ");
3635
queueSteps = QueueThread<int16_t>(100);
3736
if (!queueSteps.IsInit())
3837
{
39-
Printer::println("Error creating the queueSteps !");
38+
Printer::println("Preparing queueSteps : Error creating the queueSteps !");
39+
return;
4040
}
41-
Printer::println("done.");
41+
Printer::println("Preparing queueSteps : done.");
4242
}
4343

4444
bool HandleCommand(Command cmdTmp)

src/ESP32_Helper.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,6 @@ namespace ESP32_Helper
77
{
88
namespace // anonymous nested namespace, cannot access outside this file
99
{
10-
struct CommandHandler
11-
{
12-
String prefix;
13-
CommandHandlerFunc func;
14-
CommandHelpFunc helpFunc;
15-
};
16-
1710
const int8_t readBufferMax = 64;
1811
std::vector<char> readBuffer;
1912
std::vector<CommandHandler> customHandlers;
@@ -74,9 +67,7 @@ namespace ESP32_Helper
7467
println("¦ M E C A P I ¦");
7568
println("+---------------+");
7669
println();
77-
print(__DATE__);
78-
print(" at ");
79-
println(__TIME__);
70+
println("%s at %s", __DATE__, __TIME__);
8071
println();
8172

8273
println("-- Starting Debugger Initialisation --");
@@ -129,8 +120,8 @@ namespace ESP32_Helper
129120
{
130121
if (readBuffer.size() > 1)
131122
{
132-
Printer::print("Received %u : ", static_cast<unsigned int>(readBuffer.size()));
133-
Printer::println(String(readBuffer.data(), readBuffer.size() - 1));
123+
String receivedCmd(readBuffer.data(), readBuffer.size() - 1);
124+
Printer::println("Received %u : %s", static_cast<unsigned int>(readBuffer.size()), receivedCmd.c_str());
134125
ESP32_Helper::BufferReadCommand(readBuffer);
135126
}
136127
readBuffer.clear();

src/FileSystem_Helper.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ namespace FileSystem_Helper
3131

3232
void ListFiles(const String &filter)
3333
{
34-
print("Listing files ");
35-
filter != "" ? println(" with filter : <%s>", filter.c_str()) : println(" :");
34+
if (filter != "")
35+
println("Listing files with filter : <%s>", filter.c_str());
36+
else
37+
println("Listing files :");
3638

3739
File root = SPIFFS.open("/");
3840
if (!root)
@@ -47,8 +49,7 @@ namespace FileSystem_Helper
4749
{
4850
if (filter == "" || (filter != "" && String(file.name()).indexOf(filter) != -1))
4951
{
50-
print(" " + String(file.name()));
51-
print(" \t " + String((int)file.size()) + "\n");
52+
println(" %s \t %i", file.name(), (int)file.size());
5253
}
5354
file = root.openNextFile();
5455
}
@@ -166,8 +167,7 @@ namespace FileSystem_Helper
166167

167168
void RenameFile(const String &path1, const String &path2)
168169
{
169-
print("Renaming file ", path1);
170-
println(" to file ", path2);
170+
println("Renaming file %s to file %s", path1.c_str(), path2.c_str());
171171

172172
if(!SPIFFS.exists("/" + path1))
173173
{
@@ -191,7 +191,7 @@ namespace FileSystem_Helper
191191

192192
void DeleteFile(const String &fileName)
193193
{
194-
println("Deleting file: ", fileName);
194+
println("Deleting file: %s", fileName.c_str());
195195

196196
if(!SPIFFS.exists("/" + fileName))
197197
{

src/Printer.cpp

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,60 @@ namespace Printer
88
Enable teleplotUDPEnable = Enable::ENABLE_FALSE;
99
namespace
1010
{
11-
Level printLevel = Level::LEVEL_VERBOSE;
12-
Enable printEnable = Enable::ENABLE_TRUE;
11+
Level printLevel = Level::LEVEL_NONE;
12+
Enable printEnable = Enable::ENABLE_NONE;
1313
}
1414

1515
void SetLevel(Level level)
1616
{
1717
printLevel = level;
18-
print("Printer Level : ");
18+
const char *levelName = "LEVEL_UNKNOWN";
1919
switch (level)
2020
{
21-
ENUM_PRINT(Level::LEVEL_VERBOSE);
22-
ENUM_PRINT(Level::LEVEL_INFO);
23-
ENUM_PRINT(Level::LEVEL_WARN);
24-
ENUM_PRINT(Level::LEVEL_ERROR);
25-
ENUM_PRINT(Level::LEVEL_NONE);
21+
case Level::LEVEL_VERBOSE:
22+
levelName = "LEVEL_VERBOSE";
23+
break;
24+
case Level::LEVEL_INFO:
25+
levelName = "LEVEL_INFO";
26+
break;
27+
case Level::LEVEL_WARN:
28+
levelName = "LEVEL_WARN";
29+
break;
30+
case Level::LEVEL_ERROR:
31+
levelName = "LEVEL_ERROR";
32+
break;
33+
case Level::LEVEL_NONE:
34+
levelName = "LEVEL_NONE";
35+
break;
36+
default:
37+
break;
2638
}
39+
println("Printer Level : %s", levelName);
2740
}
2841

2942
void EnablePrinter(Enable enable)
3043
{
3144
if (enable != Enable::ENABLE_NONE)
3245
{
33-
print("Printer : ");
46+
const char *status = "unknown";
3447

3548
if (printEnable == enable && enable == Enable::ENABLE_TRUE)
3649
{
37-
print("already Enable");
50+
status = "already Enable";
3851
}
3952
if (printEnable == enable && enable == Enable::ENABLE_FALSE)
4053
{
41-
print("already Disable");
54+
status = "already Disable";
4255
}
4356
if (printEnable != enable && enable == Enable::ENABLE_TRUE)
4457
{
45-
print(" Enable");
58+
status = "Enable";
4659
}
4760
if (printEnable != enable && enable == Enable::ENABLE_FALSE)
4861
{
49-
print(" Disable");
62+
status = "Disable";
5063
}
51-
println();
64+
println("Printer : %s", status);
5265
printEnable = enable;
5366
}
5467
}
@@ -136,28 +149,50 @@ namespace Printer
136149
void PrintLevel(Level level)
137150
{
138151
printLevel = level;
139-
print("PrintLevel : ");
152+
const char *levelName = "LEVEL_UNKNOWN";
140153
switch (level)
141154
{
142-
ENUM_PRINT(Level::LEVEL_VERBOSE);
143-
ENUM_PRINT(Level::LEVEL_INFO);
144-
ENUM_PRINT(Level::LEVEL_WARN);
145-
ENUM_PRINT(Level::LEVEL_ERROR);
146-
ENUM_PRINT(Level::LEVEL_NONE);
155+
case Level::LEVEL_VERBOSE:
156+
levelName = "LEVEL_VERBOSE";
157+
break;
158+
case Level::LEVEL_INFO:
159+
levelName = "LEVEL_INFO";
160+
break;
161+
case Level::LEVEL_WARN:
162+
levelName = "LEVEL_WARN";
163+
break;
164+
case Level::LEVEL_ERROR:
165+
levelName = "LEVEL_ERROR";
166+
break;
167+
case Level::LEVEL_NONE:
168+
levelName = "LEVEL_NONE";
169+
break;
170+
default:
171+
break;
147172
}
173+
println("PrintLevel : %s", levelName);
148174
}
149175

150176
Enable PrintEnable() { return printEnable; }
151177
void PrintEnable(Enable enable)
152178
{
153179
printEnable = enable;
154-
print("PrintEnable : ");
180+
const char *enableName = "ENABLE_UNKNOWN";
155181
switch (enable)
156182
{
157-
ENUM_PRINT(Enable::ENABLE_FALSE);
158-
ENUM_PRINT(Enable::ENABLE_TRUE);
159-
ENUM_PRINT(Enable::ENABLE_NONE);
183+
case Enable::ENABLE_FALSE:
184+
enableName = "ENABLE_FALSE";
185+
break;
186+
case Enable::ENABLE_TRUE:
187+
enableName = "ENABLE_TRUE";
188+
break;
189+
case Enable::ENABLE_NONE:
190+
enableName = "ENABLE_NONE";
191+
break;
192+
default:
193+
break;
160194
}
195+
println("PrintEnable : %s", enableName);
161196
}
162197

163198
/**
@@ -242,12 +277,9 @@ Format Specifier
242277
{
243278
if(Chrono::print)
244279
{
245-
String name = "Chrono["+chrono.name+"]";
246280
int time = (int)(chrono.elapsedTime/chrono.loopNbr);
247-
print("Chrono [%s]: %d µs", chrono.name.c_str(), time);
248-
249281
uint stackSize = uxTaskGetStackHighWaterMark(nullptr);
250-
println(" -- Stack Size: %u", stackSize);
282+
println("Chrono [%s]: %d µs -- Stack Size: %u", chrono.name.c_str(), time, stackSize);
251283
}
252284
//if(Chrono::teleplot)
253285
// teleplot(name,time);

src/Wifi_Helper.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,29 +46,29 @@ namespace Wifi_Helper
4646
{
4747
if (enable != Enable::ENABLE_NONE)
4848
{
49-
Printer::print("Wifi : ");
49+
const char *status = "unknown";
5050

5151
if (wifiEnable == enable && enable == Enable::ENABLE_TRUE)
5252
{
53-
Printer::print("already Enable");
53+
status = "already Enable";
5454
}
5555
if (wifiEnable == enable && enable == Enable::ENABLE_FALSE)
5656
{
57-
Printer::print("already Disable");
57+
status = "already Disable";
5858
wifiClient.stop();
5959
WiFi.disconnect();
6060
}
6161
if (wifiEnable != enable && enable == Enable::ENABLE_TRUE)
6262
{
63-
Printer::print(" Enable");
63+
status = "Enable";
6464
}
6565
if (wifiEnable != enable && enable == Enable::ENABLE_FALSE)
6666
{
67-
Printer::print(" Disable");
67+
status = "Disable";
6868
wifiClient.stop();
6969
WiFi.disconnect();
7070
}
71-
Printer::println();
71+
Printer::println("Wifi : %s", status);
7272
wifiEnable = enable;
7373
}
7474
}
@@ -89,10 +89,8 @@ namespace Wifi_Helper
8989

9090
WiFi.mode(WIFI_STA);
9191

92-
print("AP MAC : ");
93-
println(WiFi.softAPmacAddress());
94-
print("Wifi MAC : ");
95-
println(WiFi.macAddress());
92+
println("AP MAC : %s", WiFi.softAPmacAddress().c_str());
93+
println("Wifi MAC : %s", WiFi.macAddress().c_str());
9694

9795
// Get the Local Static IP saved
9896
String saved_wifi_local_ip = Preferences_Helper::LoadFromPreference("wifi_local_ip", "");

0 commit comments

Comments
 (0)