MCPcopy Create free account
hub / github.com/SmingHub/Sming / testPrintf

Function testPrintf

samples/Basic_Serial/app/application.cpp:158–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

156}
157
158void testPrintf()
159{
160 Serial.println(_F("\r\n== PRINTF TEST START =="));
161
162 Serial.println(_F("\r\nFloat numbers display test:"));
163
164 Serial.printf("Pi with 2 decimals: %.2f and with 4 decimals: %.4f \r\n", PI, PI);
165 Serial.printf("Pi without specifying precision(default 9): %f\r\n", PI);
166 Serial.printf("A number with leading fraction zeroes like 1.050250=%f\r\n", 1.050250);
167
168 Serial.print(_F(
169 "\r\nTest crazy line lengths: wait for it, wait for it, wait for it, wait for it, "
170 "wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, "
171 "wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, "
172 "wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, wait for it, got "
173 "to the end :)\r\n"));
174
175 // Note that the leading '#' (as in %#x) is currently ignored
176 Serial.printf("\r\nShow a decimal %d, a hex %#x, an unsigned %u, an octal %o.\r\n", 123456, 0x00C0FFEE, 250, 06675);
177 Serial.printf("Field width is supported: [%8d], with optional zero-padding: 0x%08x\r\n", 123456, 0xC0FFEE);
178
179 Serial.print(_F("\r\nPrint pretty table\r\n"));
180
181 Serial.print(_F("LENGTH \t\tWIDTH \t\tHEIGHT \r\n"));
182 Serial.printf("%6d \t\t%5d \t\t%6d \r\n", 1, 2, 3);
183 Serial.printf("%6d \t\t%5d \t\t%6d \r\n", 10, 20, 300);
184 Serial.printf("%6.3f \t\t%5d \t\t%6.4f \r\n", 1.654, 200, 3.654);
185 Serial.printf("%6.3f \t\t%5.2f \t\t%6.4f \r\n", PI, PI, PI);
186
187 Serial.print(_F("\r\nTest crazy format specifiers on the same parameters\r\n"));
188
189 Serial.printf("Display -99:%d, \t\t-3.0104:%f, \t'abc'=%s, \t\t0.75:%f, \t\t0.888888889:%f\r\n", -99, -3.01040,
190 "abc", 3.0 / 4, 8.0 / 9);
191
192 Serial.printf("Display ' -99':%6d, \t-3.010:%.3f, \t\t'abc'=%5s, \t\t0.75000:%-+.5f, \t0.888888889:%f\r\n", -99,
193 -3.01040, "abc", 3.0 / 4, 8.0 / 9);
194
195 Serial.printf("Display -99:%3d, \t\t-3.010:%.3f, \t\t'abc'=%s, \t\t' 0.75':%5f, \t\t0.889:%.3f\r\n", -99, -3.01040,
196 "abc", 3.0 / 4, 8.0 / 9);
197
198 Serial.printf("Display -99:%.3d, \t\t-3.0104000:%.7f, \t'abc'=%s, \t\t0.750:%.3f, \t\t' 0.889':%6.3f\r\n", -99,
199 -3.01040, "abc", 3.0 / 4, 8.0 / 9);
200
201 Serial.print(_F("\r\nTest invalid specifiers and escaping of '%%': %j %w %%% %%%% % %zk \r\n"));
202
203 Serial.print(_F("\r\nShow limits:\r\n"));
204
205 Serial.printf("Int: %d .. %d \r\nUint limits 0 .. %u \r\nLong %ld .. %ld \r\n", INT_MIN + 1, INT_MAX, UINT_MAX,
206 LONG_MIN + 1, LONG_MAX);
207
208 Serial.println(_F("\r\n== TEST FINISH ==\r\n"));
209}
210
211// SerialReadingDelegateDemo calls this function when a command line has been entered
212void handleCommand(const String& command)

Callers 1

initFunction · 0.85

Calls 3

printlnMethod · 0.80
printfMethod · 0.80
printMethod · 0.45

Tested by

no test coverage detected