50 lines
990 B
C
Raw Normal View History

2020-11-27 11:28:57 +01:00
#pragma once
2016-12-17 20:59:03 +01:00
//
// FILE: nibbleArray.h
// AUTHOR: Rob Tillaart
2022-11-18 15:35:51 +01:00
// VERSION: 0.2.4
2020-11-27 11:28:57 +01:00
// PURPOSE: Arduino library for a compact array of nibbles (4 bits)
// URL: https://github.com/RobTillaart/nibbleArray
2016-12-17 20:59:03 +01:00
//
2021-11-10 19:53:12 +01:00
2021-01-29 12:31:58 +01:00
#include "Arduino.h"
2020-11-27 11:28:57 +01:00
2022-11-18 15:35:51 +01:00
#define NIBBLEARRAY_LIB_VERSION (F("0.2.4"))
2020-11-27 11:28:57 +01:00
#ifndef NIBBLEARRAY_MAXSIZE
2021-11-10 19:53:12 +01:00
// UNO BASED MAXSIZE?
#define NIBBLEARRAY_MAXSIZE 510
2016-12-17 20:59:03 +01:00
#endif
2021-11-10 19:53:12 +01:00
#define NIBBLEARRAY_OK 0x00
#define NIBBLEARRAY_ERROR_INDEX 0xFF
2016-12-17 20:59:03 +01:00
class nibbleArray
{
public:
2021-11-10 19:53:12 +01:00
nibbleArray(const uint16_t size);
2020-11-27 11:28:57 +01:00
~nibbleArray();
2021-11-10 19:53:12 +01:00
// return 0..F if ok
// returns 0xFF for index error.
uint8_t get(const uint16_t index);
// returns 0xFF for index error.
uint8_t set(const uint16_t index, uint8_t value);
uint16_t size() { return _size; };
uint16_t memory() { return _bytes; };
2016-12-17 20:59:03 +01:00
2020-11-27 11:28:57 +01:00
void clear();
2021-11-10 19:53:12 +01:00
void setAll(uint8_t value);
2016-12-17 20:59:03 +01:00
private:
2021-11-10 19:53:12 +01:00
uint8_t * _arr;
2020-11-27 11:28:57 +01:00
uint16_t _size;
2021-11-10 19:53:12 +01:00
uint8_t _bytes = 0;
2016-12-17 20:59:03 +01:00
};
2020-11-27 11:28:57 +01:00
2021-11-10 19:53:12 +01:00
2020-11-27 11:28:57 +01:00
// -- END OF FILE --