GY-63_MS5611/libraries/PrintString/PrintString.h

67 lines
1.1 KiB
C
Raw Normal View History

2020-11-27 05:28:57 -05:00
#pragma once
2017-12-09 19:35:48 -05:00
//
// FILE: PrintString.h
// AUTHOR: Rob Tillaart
2021-12-24 08:47:57 -05:00
// VERSION: 0.2.2
2017-12-09 19:35:48 -05:00
// PURPOSE: Class that captures prints into a String
// DATE: 2017-12-09
2020-11-27 05:28:57 -05:00
// URL: https://github.com/RobTillaart/PrintString
2017-12-09 19:35:48 -05:00
//
2021-01-29 06:31:58 -05:00
// 0.1.0 2017-12-09 initial version
// 0.1.1 2020-04-26 added size
// 0.1.2 2020-06-19 fix library.json
// 0.2.0 2021-01-06 add Arduino-CI + unit test
2021-11-14 11:19:48 -05:00
// 0.2.1 2021-11-14 update Arduino-CI, readme.md
// add write(char * str, uint8_t length) Print interface.
2021-12-24 08:47:57 -05:00
// 0.2.2 2021-12-24 update library.json, license, minor edits
2021-01-29 06:31:58 -05:00
2017-12-09 19:35:48 -05:00
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
2017-12-09 19:35:48 -05:00
#include "Print.h"
2021-01-29 06:31:58 -05:00
2021-12-24 08:47:57 -05:00
#define PRINTSTRING_VERSION (F("0.2.2"))
2021-01-29 06:31:58 -05:00
2017-12-09 19:35:48 -05:00
class PrintString: public Print
{
public:
PrintString() {};
2021-11-14 11:19:48 -05:00
2017-12-09 19:35:48 -05:00
size_t write(uint8_t c)
{
2020-11-27 05:28:57 -05:00
buffer.concat(char(c));
2017-12-09 19:35:48 -05:00
return 1;
}
2021-11-14 11:19:48 -05:00
size_t write(uint8_t * str, uint8_t length)
{
buffer.concat((char*)str);
return length;
}
2020-11-27 05:28:57 -05:00
size_t size()
{
return buffer.length();
}
2021-11-14 11:19:48 -05:00
2017-12-09 19:35:48 -05:00
void clear()
{
buffer = "";
}
2021-11-14 11:19:48 -05:00
2017-12-09 19:35:48 -05:00
String getString() { return buffer; }
private:
String buffer;
};
2020-11-27 05:28:57 -05:00
2021-11-14 11:19:48 -05:00
2017-12-09 19:35:48 -05:00
// -- END OF FILE --
2021-11-14 11:19:48 -05:00