63 lines
1.2 KiB
C
Raw Normal View History

2020-11-27 11:28:57 +01:00
#pragma once
2017-12-09 19:52:49 +01:00
//
// FILE: PrintSize.h
// AUTHOR: Rob Tillaart
2021-12-24 13:42:31 +01:00
// VERSION: 0.3.2
2017-12-09 19:52:49 +01:00
// PURPOSE: Class that determines printSize
// DATE: 2017-12-09
2020-11-27 11:28:57 +01:00
// URL: https://github.com/RobTillaart/PrintSize
2017-12-09 19:52:49 +01:00
//
2021-01-29 12:31:58 +01:00
// HISTORY:
// 0.1.0 2017-12-09 initial version
// 0.2.0 2020-04-30 add total counter to sum multiple print statements
// 0.2.1 2020-05-26 fix #1 - URLS + centering example
// 0.2.2 2020-06-19 fix library.json
2021-11-13 22:52:33 +01:00
// 0.3.0 2021-01-06 Arduino-CI + unit test
// 0.3.1 2021-11-13 update Arduino-CI, readme.md, badges
// add write(str, length) for Print interface.
2021-12-24 13:42:31 +01:00
// 0.3.2 2021-12-24 update library.json, license, minor edits
2021-11-13 22:52:33 +01:00
2017-12-09 19:52:49 +01:00
#include "Print.h"
2021-12-24 13:42:31 +01:00
#define PRINTSIZE_VERSION (F("0.3.2"))
2021-11-13 22:52:33 +01:00
2017-12-09 19:52:49 +01:00
class PrintSize: public Print
{
public:
2020-11-27 11:28:57 +01:00
PrintSize()
{
reset();
};
2021-11-13 22:52:33 +01:00
size_t write(uint8_t c) // note: warning unused parameter
2020-11-27 11:28:57 +01:00
{
_total++;
return 1;
}
2017-12-09 19:52:49 +01:00
2021-11-13 22:52:33 +01:00
size_t write(uint8_t * str, uint8_t length) // note: warning unused parameter
{
_total += length;
return length;
}
2021-01-29 12:31:58 +01:00
void reset() { _total = 0; }
2020-11-27 11:28:57 +01:00
2021-11-13 22:52:33 +01:00
2020-11-27 11:28:57 +01:00
uint32_t total() { return _total; };
2021-11-13 22:52:33 +01:00
2020-11-27 11:28:57 +01:00
private:
uint32_t _total = 0;
2021-11-13 22:52:33 +01:00
2017-12-09 19:52:49 +01:00
};
2020-11-27 11:28:57 +01:00
2021-12-24 13:42:31 +01:00
2017-12-09 19:52:49 +01:00
// -- END OF FILE --
2021-12-24 13:42:31 +01:00