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

88 lines
2.1 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: SHEX.h
// AUTHOR: Rob Tillaart
2022-11-24 06:47:19 -05:00
// VERSION: 0.3.1
2021-01-29 06:31:58 -05:00
// PURPOSE: Arduino library to generate hex dump over Serial
// DATE: 2020-05-24
// URL: https://github.com/RobTillaart/SHEX
#include "Arduino.h"
#include "Print.h"
2022-05-31 11:39:54 -04:00
#define SHEX_LIB_VERSION (F("0.3.0"))
2022-05-27 04:43:49 -04:00
#define SHEX_DEFAULT_LENGTH 16
#define SHEX_MAX_LENGTH 32
2022-05-28 05:28:52 -04:00
#define SHEX_MIN_LENGTH 4
2022-05-31 11:39:54 -04:00
#define SHEX_COUNTER_DIGITS 4
2022-05-28 05:28:52 -04:00
#define SHEX_DEFAULT_VTAB 8
2021-01-29 06:31:58 -05:00
class SHEX: public Print
{
public:
2022-05-27 04:43:49 -04:00
SHEX(Print* stream = &Serial, uint8_t length = SHEX_DEFAULT_LENGTH);
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
void reset();
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
size_t write(uint8_t c);
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
void setHEX(bool hexOutput = true);
bool getHEX() { return _hexOutput; };
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
void setBytesPerLine(const uint8_t length = SHEX_DEFAULT_LENGTH);
uint8_t getBytesPerLine() { return _length; };
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
void setSeparator(char c = ' ') { _separator = c; };
char getSeparator() { return _separator; };
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
// must be 0, 4, 6 or 8
void setCountDigits(uint8_t digits = SHEX_COUNTER_DIGITS);
uint8_t getCountDigits() { return _digits; }
// restarts the output - use with care
void restartOutput();
uint32_t getCounter() { return _charCount; };
2021-01-29 06:31:58 -05:00
2022-05-31 11:39:54 -04:00
void setVTAB(uint8_t vtab = SHEX_DEFAULT_VTAB);
uint8_t getVTAB() { return _vtab; };
2022-05-28 05:28:52 -04:00
2021-12-28 05:19:54 -05:00
2022-05-31 11:39:54 -04:00
protected:
Print * _stream = &Serial;
bool _hexOutput = true;
2022-05-27 04:43:49 -04:00
uint8_t _length = SHEX_DEFAULT_LENGTH;
2022-05-28 05:28:52 -04:00
uint8_t _vtab = SHEX_DEFAULT_VTAB;
2021-01-29 06:31:58 -05:00
char _separator = ' ';
2022-05-31 11:39:54 -04:00
uint32_t _charCount = 0;
uint32_t _digits = SHEX_COUNTER_DIGITS;
};
///////////////////////////////////////////////////
//
// SHEXA shows also ASCII dump
// derived class as it takes extra RAM
//
class SHEXA : public SHEX
{
public:
SHEXA(Print* stream = &Serial, uint8_t length = SHEX_DEFAULT_LENGTH);
size_t write(uint8_t c);
// flushes the ASCII column to output; not ideal but workable for now.
// use with care
void flushASCII();
protected:
uint8_t _txtbuf[SHEX_MAX_LENGTH];
bool _showtxt = true;
2021-01-29 06:31:58 -05:00
};
2021-12-28 05:19:54 -05:00
2022-11-24 06:47:19 -05:00
// -- END OF FILE --
2021-12-28 05:19:54 -05:00