@@ -34,6 +34,12 @@ SOFTWARE.
34
34
35
35
#include " Commander-API.hpp"
36
36
37
+ #if defined(ARDUINO) && defined(__AVR__)
38
+ #define FF (s ) F(s)
39
+ #else
40
+ #define FF (s ) (s)
41
+ #endif
42
+
37
43
const char *Commander::version = COMMANDER_API_VERSION;
38
44
39
45
void Commander::attachTreeFunction ( API_t *API_tree_p, uint32_t API_tree_size_p ){
@@ -42,27 +48,16 @@ void Commander::attachTreeFunction( API_t *API_tree_p, uint32_t API_tree_size_p
42
48
API_tree = API_tree_p;
43
49
API_tree_size = API_tree_size_p;
44
50
45
- #if defined( ARDUINO ) && defined( __AVR__ )
46
-
47
- dbgResponse -> print ( F ( " API tree attached with " ) );
48
- dbgResponse -> print ( API_tree_size );
49
- dbgResponse -> println ( F ( " commands." ) );
50
-
51
- #else
52
-
53
- dbgResponse -> print ( (const char *)" API tree attached with " );
51
+ dbgResponse -> print ( FF ( " API tree attached with " ) );
54
52
dbgResponse -> print ( API_tree_size );
55
- dbgResponse -> println ( " commands." );
56
-
57
- #endif
58
-
53
+ dbgResponse -> println ( FF ( " commands." ) );
59
54
}
60
55
61
56
void Commander::init (){
62
57
63
58
// Generic conter variables.
64
59
uint32_t i;
65
- uint32_t j;
60
+ uint32_t j;
66
61
67
62
// Temporary variable, used to flip elements.
68
63
API_t temp;
@@ -82,26 +77,10 @@ void Commander::init(){
82
77
83
78
#endif
84
79
85
- #if defined( ARDUINO ) && defined( __AVR__ )
86
-
87
- dbgResponse -> println ( F ( " Commander init start" ) );
88
-
89
- #else
90
-
91
- dbgResponse -> println ( (const char *)" Commander init start" );
92
-
93
- #endif
80
+ dbgResponse -> println ( FF ( " Commander init start" ) );
94
81
95
82
// Make the tree ordered by alphabet.
96
- #if defined( ARDUINO ) && defined( __AVR__ )
97
-
98
- dbgResponse -> print ( F ( " Creating alphabetical order... " ) );
99
-
100
- #else
101
-
102
- dbgResponse -> print ( (const char *)" Creating alphabetical order... " );
103
-
104
- #endif
83
+ dbgResponse -> print ( FF ( " Creating alphabetical order... " ) );
105
84
106
85
// Bubble sort. We need to sort the commands into an alphabetical order.
107
86
for ( i = 0 ; i < API_tree_size; i++ ){
@@ -128,42 +107,16 @@ void Commander::init(){
128
107
129
108
}
130
109
131
- #if defined( ARDUINO ) && defined( __AVR__ )
132
-
133
- dbgResponse -> println ( F ( " [ OK ]" ) );
134
-
135
- #else
136
-
137
- dbgResponse -> println ( (const char *)" [ OK ]" );
138
-
139
- #endif
140
-
110
+ dbgResponse -> println ( FF ( " [ OK ]" ) );
141
111
142
112
// Optimize the tree to make it balanced.
143
113
// It is necessary to speed up the command
144
114
// search phase.
145
- #if defined( ARDUINO ) && defined( __AVR__ )
146
-
147
- dbgResponse -> print ( F ( " Create balanced binary structure... " ) );
148
-
149
- #else
150
-
151
- dbgResponse -> print ( (const char *)" Create balanced binary structure... " );
152
-
153
- #endif
115
+ dbgResponse -> print ( FF ( " Create balanced binary structure... " ) );
154
116
optimize_api_tree ();
155
117
156
- #if defined( ARDUINO ) && defined( __AVR__ )
157
-
158
- dbgResponse -> println ( F ( " [ OK ]" ) );
159
- dbgResponse -> println ( F ( " Commander init finished!" ) );
160
-
161
- #else
162
-
163
- dbgResponse -> println ( (const char *)" [ OK ]" );
164
- dbgResponse -> println ( (const char *)" Commander init finished!" );
165
-
166
- #endif
118
+ dbgResponse -> println ( FF ( " [ OK ]" ) );
119
+ dbgResponse -> println ( FF ( " Commander init finished!" ) );
167
120
168
121
}
169
122
@@ -492,19 +445,9 @@ void Commander::executeCommand( char *cmd, void* parent ){
492
445
493
446
// If we went through the whole tree and we did not found the command in it,
494
447
// we have to notice the user abut the problem. Maybe a Type-O
495
- #if defined( ARDUINO ) && defined( __AVR__ )
496
-
497
- response -> print ( F ( " Command \' " ) );
448
+ response -> print ( FF ( " Command \' " ) );
498
449
response -> print ( tempBuff );
499
- response -> println ( F ( " \' not found!" ) );
500
-
501
- #else
502
-
503
- response -> print ( (const char *)" Command \' " );
504
- response -> print ( tempBuff );
505
- response -> println ( (const char *)" \' not found!" );
506
-
507
- #endif
450
+ response -> println ( FF ( " \' not found!" ) );
508
451
509
452
#ifdef COMMANDER_ENABLE_PIPE_MODULE
510
453
@@ -668,31 +611,10 @@ void Commander::printHelp( Stream* out, bool description, bool style ){
668
611
uint32_t i;
669
612
670
613
if ( style ){
671
-
672
- #if defined( ARDUINO ) && defined( __AVR__ )
673
-
674
- out -> println ( F ( " \033 [1;31m----\033 [1;32m Available commands \033 [1;31m----\033 [0;37m\r\n " ) );
675
-
676
- #else
677
-
678
- out -> println ( (const char *)" \033 [1;31m----\033 [1;32m Available commands \033 [1;31m----\033 [0;37m\r\n " );
679
-
680
- #endif
681
-
614
+ out -> println ( FF ( " \033 [1;31m----\033 [1;32m Available commands \033 [1;31m----\033 [0;37m\r\n " ) );
682
615
}
683
-
684
616
else {
685
-
686
- #if defined( ARDUINO ) && defined( __AVR__ )
687
-
688
- out -> println ( F ( " ---- Available commands ----\r\n " ) );
689
-
690
- #else
691
-
692
- out -> println ( (const char *)" ---- Available commands ----\r\n " );
693
-
694
- #endif
695
-
617
+ out -> println ( FF ( " ---- Available commands ----\r\n " ) );
696
618
}
697
619
698
620
for ( i = 0 ; i < API_tree_size; i++ ){
@@ -719,9 +641,9 @@ void Commander::printHelp( Stream* out, bool description, bool style ){
719
641
720
642
else if ( memoryType == MEMORY_PROGMEM ){
721
643
722
- out -> print ( F ( " \033 [1;32m" ) );
644
+ out -> print ( FF ( " \033 [1;32m" ) );
723
645
out -> print ( API_tree[ find_api_index_by_place ( i ) ].name_P );
724
- out -> print ( F ( " \033 [0;37m" ) );
646
+ out -> print ( FF ( " \033 [0;37m" ) );
725
647
out -> print ( ' :' );
726
648
out -> print ( ' ' );
727
649
out -> print ( API_tree[ find_api_index_by_place ( i ) ].desc_P );
@@ -844,4 +766,4 @@ void Commander::enableFormatting(){
844
766
}
845
767
void Commander::disableFormatting (){
846
768
formatting = false ;
847
- }
769
+ }
0 commit comments