mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#pragma once
|
|
//
|
|
// FILE: BoolArray.h
|
|
// AUTHOR: Rob Tillaart
|
|
// VERSION: 0.2.6
|
|
// PURPOSE: BoolArray library for Arduino
|
|
// URL: https://github.com/RobTillaart/BoolArray.git
|
|
|
|
// BoolArray implement a compact array of booleans of max size 2000.
|
|
// For larger arrays one need to modify the code, or use BitArray.
|
|
// Tested on AVR only
|
|
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
|
#define BOOLARRAY_LIB_VERSION (F("0.2.6"))
|
|
|
|
#define BOOLARRAY_MAXSIZE (250 * 8) // 2000
|
|
|
|
#define BOOLARRAY_OK 0x00
|
|
#define BOOLARRAY_ERROR 0xFF
|
|
#define BOOLARRAY_SIZE_ERROR 0xFE
|
|
#define BOOLARRAY_INIT_ERROR 0xFD
|
|
|
|
|
|
class BoolArray
|
|
{
|
|
public:
|
|
BoolArray();
|
|
~BoolArray();
|
|
|
|
uint8_t begin(const uint16_t size);
|
|
|
|
uint16_t size() { return _size; };
|
|
uint8_t memory() { return _bytes; };
|
|
|
|
uint8_t setAll(const uint8_t value);
|
|
uint8_t clear() { return setAll(0); };
|
|
uint8_t get(const uint16_t index);
|
|
uint8_t set(const uint16_t index, const uint8_t value);
|
|
uint8_t toggle(const uint16_t index);
|
|
|
|
private:
|
|
uint8_t _masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
|
|
uint8_t * _array;
|
|
uint16_t _size = 0;
|
|
uint8_t _bytes = 0;
|
|
};
|
|
|
|
|
|
// -- END OF FILE --
|
|
|