2020-11-27 05:28:57 -05:00
|
|
|
#pragma once
|
2017-12-09 13:52:49 -05:00
|
|
|
//
|
|
|
|
// FILE: PrintSize.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2024-04-11 07:23:26 -04:00
|
|
|
// VERSION: 0.3.5
|
2022-11-22 11:00:39 -05:00
|
|
|
// PURPOSE: Library to determine size of a printed variable.
|
2017-12-09 13:52:49 -05:00
|
|
|
// DATE: 2017-12-09
|
2020-11-27 05:28:57 -05:00
|
|
|
// URL: https://github.com/RobTillaart/PrintSize
|
2021-11-13 16:52:33 -05:00
|
|
|
|
2017-12-09 13:52:49 -05:00
|
|
|
|
2022-11-22 11:00:39 -05:00
|
|
|
#include "Arduino.h"
|
2017-12-09 13:52:49 -05:00
|
|
|
#include "Print.h"
|
|
|
|
|
2024-04-11 07:23:26 -04:00
|
|
|
#define PRINTSIZE_VERSION (F("0.3.5"))
|
2021-11-13 16:52:33 -05:00
|
|
|
|
2017-12-09 13:52:49 -05:00
|
|
|
|
|
|
|
class PrintSize: public Print
|
|
|
|
{
|
|
|
|
public:
|
2020-11-27 05:28:57 -05:00
|
|
|
PrintSize()
|
|
|
|
{
|
|
|
|
reset();
|
|
|
|
};
|
|
|
|
|
2021-11-13 16:52:33 -05:00
|
|
|
|
2022-11-22 11:00:39 -05:00
|
|
|
size_t write(uint8_t c) // note: warning unused parameter
|
2020-11-27 05:28:57 -05:00
|
|
|
{
|
|
|
|
_total++;
|
2024-04-11 07:23:26 -04:00
|
|
|
return sizeof(c);
|
2020-11-27 05:28:57 -05:00
|
|
|
}
|
2017-12-09 13:52:49 -05:00
|
|
|
|
2021-11-13 16:52:33 -05:00
|
|
|
|
2022-11-22 11:00:39 -05:00
|
|
|
size_t write(uint8_t * str, uint8_t length) // note: warning unused parameter
|
2021-11-13 16:52:33 -05:00
|
|
|
{
|
|
|
|
_total += length;
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-04-11 07:23:26 -04:00
|
|
|
void reset()
|
|
|
|
{
|
|
|
|
_total = 0;
|
|
|
|
}
|
2020-11-27 05:28:57 -05:00
|
|
|
|
2021-11-13 16:52:33 -05:00
|
|
|
|
2024-04-11 07:23:26 -04:00
|
|
|
uint32_t total()
|
|
|
|
{
|
|
|
|
return _total;
|
|
|
|
}
|
2020-11-27 05:28:57 -05:00
|
|
|
|
2021-11-13 16:52:33 -05:00
|
|
|
|
2020-11-27 05:28:57 -05:00
|
|
|
private:
|
|
|
|
uint32_t _total = 0;
|
2021-11-13 16:52:33 -05:00
|
|
|
|
2017-12-09 13:52:49 -05:00
|
|
|
};
|
2020-11-27 05:28:57 -05:00
|
|
|
|
2021-12-24 07:42:31 -05:00
|
|
|
|
2023-11-16 04:38:25 -05:00
|
|
|
// -- END OF FILE --
|
2021-12-24 07:42:31 -05:00
|
|
|
|