本文整理汇总了C++中Print::printf方法的典型用法代码示例。如果您正苦于以下问题:C++ Print::printf方法的具体用法?C++ Print::printf怎么用?C++ Print::printf使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Print
的用法示例。
在下文中一共展示了Print::printf方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: printTo
size_t IPAddress::printTo(Print& p) const {
size_t n = 0;
if (!isSet())
return p.print(F("(IP unset)"));
#if LWIP_IPV6
if (isV6()) {
int count0 = 0;
for (int i = 0; i < 8; i++) {
uint16_t bit = PP_NTOHS(raw6()[i]);
if (bit || count0 < 0) {
n += p.printf("%x", bit);
if (count0 > 0)
// no more hiding 0
count0 = -8;
} else
count0++;
if ((i != 7 && count0 < 2) || count0 == 7)
n += p.print(':');
}
return n;
}
#endif
for(int i = 0; i < 4; i++) {
n += p.print((*this)[i], DEC);
if (i != 3)
n += p.print('.');
}
return n;
}
示例2: print
/**
* Print out crash information that has been previusly saved in EEPROM
* @param outputDev Print& Optional. Where to print: Serial, Serial, WiFiClient, etc.
*/
void EspSaveCrash::print(Print& outputDev)
{
// Note that 'EEPROM.begin' method is reserving a RAM buffer
// The buffer size is SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_SPACE_SIZE
EEPROM.begin(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_SPACE_SIZE);
byte crashCounter = EEPROM.read(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_COUNTER);
if (crashCounter == 0)
{
outputDev.println("No any crashes saved");
return;
}
outputDev.println("Crash information recovered from EEPROM");
int16_t readFrom = SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_DATA_SETS;
for (byte k = 0; k < crashCounter; k++)
{
uint32_t crashTime;
EEPROM.get(readFrom + SAVE_CRASH_CRASH_TIME, crashTime);
outputDev.printf("Crash # %d at %ld ms\n", k + 1, crashTime);
outputDev.printf("Reason of restart: %d\n", EEPROM.read(readFrom + SAVE_CRASH_RESTART_REASON));
outputDev.printf("Exception cause: %d\n", EEPROM.read(readFrom + SAVE_CRASH_EXCEPTION_CAUSE));
uint32_t epc1, epc2, epc3, excvaddr, depc;
EEPROM.get(readFrom + SAVE_CRASH_EPC1, epc1);
EEPROM.get(readFrom + SAVE_CRASH_EPC2, epc2);
EEPROM.get(readFrom + SAVE_CRASH_EPC3, epc3);
EEPROM.get(readFrom + SAVE_CRASH_EXCVADDR, excvaddr);
EEPROM.get(readFrom + SAVE_CRASH_DEPC, depc);
outputDev.printf("epc1=0x%08x epc2=0x%08x epc3=0x%08x excvaddr=0x%08x depc=0x%08x\n", epc1, epc2, epc3, excvaddr, depc);
uint32_t stackStart, stackEnd;
EEPROM.get(readFrom + SAVE_CRASH_STACK_START, stackStart);
EEPROM.get(readFrom + SAVE_CRASH_STACK_END, stackEnd);
outputDev.println(">>>stack>>>");
int16_t currentAddress = readFrom + SAVE_CRASH_STACK_TRACE;
int16_t stackLength = stackEnd - stackStart;
uint32_t stackTrace;
for (int16_t i = 0; i < stackLength; i += 0x10)
{
outputDev.printf("%08x: ", stackStart + i);
for (byte j = 0; j < 4; j++)
{
EEPROM.get(currentAddress, stackTrace);
outputDev.printf("%08x ", stackTrace);
currentAddress += 4;
if (currentAddress - SAVE_CRASH_EEPROM_OFFSET > SAVE_CRASH_SPACE_SIZE)
{
outputDev.println("\nIncomplete stack trace saved!");
goto eepromSpaceEnd;
}
}
outputDev.println();
}
eepromSpaceEnd:
outputDev.println("<<<stack<<<");
readFrom = readFrom + SAVE_CRASH_STACK_TRACE + stackLength;
}
int16_t writeFrom;
EEPROM.get(SAVE_CRASH_EEPROM_OFFSET + SAVE_CRASH_WRITE_FROM, writeFrom);
EEPROM.end();
// is there free EEPROM space avialable to save data for next crash?
if (writeFrom + SAVE_CRASH_STACK_TRACE > SAVE_CRASH_SPACE_SIZE)
{
outputDev.println("No more EEPROM space available to save crash information!");
}
else
{
outputDev.printf("EEPROM space available: 0x%04x bytes\n", SAVE_CRASH_SPACE_SIZE - writeFrom);
}
}