54 lines
1.2 KiB
C
Raw Normal View History

2020-11-27 11:10:47 +01:00
#pragma once
2015-12-07 19:56:21 +01:00
//
// FILE: BoolArray.h
2020-11-27 11:10:47 +01:00
// AUTHOR: Rob Tillaart
2022-10-29 17:05:43 +02:00
// VERSION: 0.2.6
2015-12-07 19:56:21 +01:00
// PURPOSE: BoolArray library for Arduino
2020-11-27 11:10:47 +01:00
// URL: https://github.com/RobTillaart/BoolArray.git
2022-10-29 17:05:43 +02:00
// 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
2015-12-07 19:56:21 +01:00
2021-01-29 12:31:58 +01:00
2015-12-07 19:56:21 +01:00
#include "Arduino.h"
2021-01-29 12:31:58 +01:00
2022-10-29 17:05:43 +02:00
#define BOOLARRAY_LIB_VERSION (F("0.2.6"))
2021-01-29 12:31:58 +01:00
2021-10-19 14:40:20 +02:00
#define BOOLARRAY_MAXSIZE (250 * 8) // 2000
2021-01-29 12:31:58 +01:00
#define BOOLARRAY_OK 0x00
#define BOOLARRAY_ERROR 0xFF
#define BOOLARRAY_SIZE_ERROR 0xFE
#define BOOLARRAY_INIT_ERROR 0xFD
2015-12-07 19:56:21 +01:00
class BoolArray
{
public:
2021-01-29 12:31:58 +01:00
BoolArray();
~BoolArray();
uint8_t begin(const uint16_t size);
2015-12-07 19:56:21 +01:00
2021-01-29 12:31:58 +01:00
uint16_t size() { return _size; };
2021-10-19 14:40:20 +02:00
uint8_t memory() { return _bytes; };
2020-11-27 11:10:47 +01:00
2021-01-29 12:31:58 +01:00
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);
2015-12-07 19:56:21 +01:00
private:
2021-12-14 14:48:42 +01:00
uint8_t _masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
uint8_t * _array;
2021-10-19 14:40:20 +02:00
uint16_t _size = 0;
uint8_t _bytes = 0;
2015-12-07 19:56:21 +01:00
};
2022-10-29 17:05:43 +02:00
2020-11-27 11:10:47 +01:00
// -- END OF FILE --
2022-10-29 17:05:43 +02:00