Skip to content

Commit ab3f015

Browse files
committed
0.2.4 BoolArray
1 parent 7a0ece2 commit ab3f015

File tree

13 files changed

+156
-78
lines changed

13 files changed

+156
-78
lines changed

libraries/BoolArray/.arduino-ci.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ compile:
22
# Choosing to run compilation tests on 2 different Arduino platforms
33
platforms:
44
- uno
5-
- leonardo
6-
- due
7-
- zero
5+
# - due
6+
# - zero
7+
# - leonardo
8+
- m4
9+
- esp32
10+
# - esp8266
11+
# - mega2560

libraries/BoolArray/.github/workflows/arduino_test_runner.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ name: Arduino CI
44
on: [push, pull_request]
55

66
jobs:
7-
arduino_ci:
7+
runTest:
88
runs-on: ubuntu-latest
99

1010
steps:
1111
- uses: actions/checkout@v2
12-
- uses: Arduino-CI/action@master
13-
# Arduino-CI/[email protected]
12+
- uses: ruby/setup-ruby@v1
13+
with:
14+
ruby-version: 2.6
15+
- run: |
16+
gem install arduino_ci
17+
arduino_ci.rb

libraries/BoolArray/BoolArray.cpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
//
22
// FILE: BoolArray.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.2.3
4+
// VERSION: 0.2.4
55
// PURPOSE: BoolArray library for Arduino
66
// URL: https://github.com/RobTillaart/BoolArray.git
77
// http://forum.arduino.cc/index.php?topic=361167
8-
9-
10-
// 0.2.3 2021-01-19 update readme
11-
// 0.2.2 2020-12-15 add arduino-CI + unit tests
12-
// 0.2.1 2020-06-05 Fix library.json
13-
// 0.2.0 2020-03-29 #pragma, readme.md,
14-
15-
// 0.1.4 2017-07-16 added masks for performance
16-
// 0.1.3 added toggle
17-
// 0.1.02 added errorhandling
18-
// 0.1.01 fixed constructor - Thanks WPD64 + error handling
8+
//
9+
// HISTORY
1910
// 0.1.00 initial version
11+
// 0.1.01 fixed constructor - Thanks WPD64 + error handling
12+
// 0.1.02 added errorhandling
13+
// 0.1.3 added toggle
14+
// 0.1.4 2017-07-16 added masks for performance
15+
// 0.2.0 2020-03-29 #pragma, readme.md,
16+
// 0.2.1 2020-06-05 Fix library.json
17+
// 0.2.2 2020-12-15 add arduino-CI + unit tests
18+
// 0.2.3 2021-01-19 update readme
19+
// 0.2.4 2021-10-19 update build-CI + badges
2020
//
2121

2222

@@ -39,9 +39,10 @@ BoolArray::~BoolArray()
3939
uint8_t BoolArray::begin(const uint16_t size)
4040
{
4141
if (size > BOOLARRAY_MAXSIZE) return BOOLARRAY_SIZE_ERROR;
42-
_size = size;
42+
_size = size;
43+
_bytes = (_size + 7) / 8;
4344
if (_ar) free(_ar);
44-
_ar = (byte*) malloc((_size + 7) / 8);
45+
_ar = (byte*) malloc(_bytes);
4546
return BOOLARRAY_OK;
4647
}
4748

@@ -79,20 +80,19 @@ uint8_t BoolArray::toggle(const uint16_t index)
7980
}
8081

8182

82-
// 32 bit is even faster,
8383
uint8_t BoolArray::setAll(const uint8_t value)
8484
{
8585
if (_ar == NULL) return BOOLARRAY_INIT_ERROR;
8686
uint8_t *p = _ar;
87-
uint8_t t = (_size + 7) / 8;
87+
uint8_t t = _bytes;
8888
if (value == 0)
8989
{
9090
while(t--) *p++ = 0;
9191
}
9292
else
9393
{
94-
while(t--) *p++ = 0xFF; // set 16 bits at once
95-
}
94+
while(t--) *p++ = 0xFF;
95+
}
9696
return BOOLARRAY_OK;
9797
}
9898

libraries/BoolArray/BoolArray.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// FILE: BoolArray.h
44
// AUTHOR: Rob Tillaart
5-
// VERSION: 0.2.3
5+
// VERSION: 0.2.4
66
// PURPOSE: BoolArray library for Arduino
77
// URL: https://github.com/RobTillaart/BoolArray.git
88

@@ -14,9 +14,9 @@
1414
#include "Arduino.h"
1515

1616

17-
#define BOOLARRAY_LIB_VERSION (F("0.2.3"))
17+
#define BOOLARRAY_LIB_VERSION (F("0.2.4"))
1818

19-
#define BOOLARRAY_MAXSIZE (250 * 8)
19+
#define BOOLARRAY_MAXSIZE (250 * 8) // 2000
2020

2121
#define BOOLARRAY_OK 0x00
2222
#define BOOLARRAY_ERROR 0xFF
@@ -33,7 +33,7 @@ class BoolArray
3333
uint8_t begin(const uint16_t size);
3434

3535
uint16_t size() { return _size; };
36-
uint16_t memory() { return (_size + 7) / 8; };
36+
uint8_t memory() { return _bytes; };
3737

3838
uint8_t setAll(const uint8_t value);
3939
uint8_t clear() { return setAll(0); };
@@ -42,9 +42,10 @@ class BoolArray
4242
uint8_t toggle(const uint16_t index);
4343

4444
private:
45-
uint8_t masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
45+
uint8_t masks[8] = {1, 2, 4, 8, 16, 32, 64, 128};
4646
uint8_t * _ar;
47-
uint16_t _size;
47+
uint16_t _size = 0;
48+
uint8_t _bytes = 0;
4849
};
4950

5051
// -- END OF FILE --

libraries/BoolArray/README.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

22
[![Arduino CI](https://github.com/RobTillaart/BoolArray/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
3+
[![Arduino-lint](https://github.com/RobTillaart/BoolArray/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/BoolArray/actions/workflows/arduino-lint.yml)
4+
[![JSON check](https://github.com/RobTillaart/BoolArray/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/BoolArray/actions/workflows/jsoncheck.yml)
35
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/BoolArray/blob/master/LICENSE)
46
[![GitHub release](https://img.shields.io/github/release/RobTillaart/BoolArray.svg?maxAge=3600)](https://github.com/RobTillaart/BoolArray/releases)
57

@@ -19,9 +21,9 @@ The class is optimized for storage by packing 8 elements of the array in one byt
1921
You need to check if your application needs more performance than this library can deliver.
2022

2123
The BoolArray library is one from a set of three:
22-
- BitArray for elements of user defined size in bits (values 0 .. 2^n-1)
23-
- BoolArray for elements of 1 bit (values 0 .. 1)
24-
- nybbleArray for elements of 4 bits (values 0 .. 15)
24+
- **BitArray** for elements of user defined size in bits (values 0 .. 2^n-1)
25+
- **BoolArray** for elements of 1 bit (values 0 .. 1)
26+
- **nybbleArray** for elements of 4 bits (values 0 .. 15)
2527

2628
BoolArray is faster than BitArray as it only supports single bits and does not need to merge parts
2729
of different bytes to read/write a value. However BoolArray currently only supports 2000 bits while
@@ -30,16 +32,16 @@ BitArray can support more.
3032

3133
## Interface
3234

33-
- ** BoolArray()** Constructor
35+
- **BoolArray()** Constructor
3436
- **~BoolArray()** Destructor
35-
- **uint8_t begin(size)** dynamically allocates size elements. Returns **BOOLARRAY_OK** on success.
37+
- **uint8_t begin(uint16_t size)** dynamically allocates size elements (8 bools in one byte). Returns **BOOLARRAY_OK** on success.
3638
- **uint16_t size()** returns number of bool elements.
37-
- **uint16_t memory()** returns # bytes used
38-
- **uint8_t setAll(value)** Sets all elements to false (0) or true (all other values).
39-
- **uint8_t set(index, value)** Set the element to false (0) or true (all other values).
40-
- **uint8_t get(index)** Return 0 or 1 OR an error value which can be interpreted as true.
39+
- **uint16_t memory()** returns number of bytes used.
40+
- **uint8_t setAll(uint8_t value)** Sets all elements to false (0) or true (all other values).
41+
- **uint8_t set(uint16_t index, uint8_t value)** Set the element to false (0) or true (all other values).
42+
- **uint8_t get(uint16_t index)** Return 0 or 1 OR an error value which can be interpreted as true.
4143
So one need to check these carefully.
42-
- **uint8_t toggle(index)** Toggles element at index. Returns **BOOLARRAY_OK** on success.
44+
- **uint8_t toggle(uint16_t index)** Toggles element at index. Returns **BOOLARRAY_OK** on success.
4345
- **uint8_t clear()** Sets all elements to false.
4446

4547

@@ -50,8 +52,16 @@ Check out the examples.
5052

5153
## Notes
5254

53-
The BoolArray class dynamicly allocates memory.
55+
The BoolArray class allocates dynamic memory.
5456
The **BOOLARRAY_MAXSIZE** is set to 2000, this was chosen as **malloc()** can only allocate 255 bytes
55-
in one call on an UNO. This is not checked with the recent versions of the IDE anymore.
57+
in one call on an UNO. This is not checked with the recent versions of the IDE any more.
5658

5759
The library is tested on AVR architecture only.
60+
61+
62+
## Future
63+
64+
- performance test on ESP32
65+
- performance for **clear()** dedicated loop vs **setAll(0)** call
66+
- update examples.
67+

libraries/BoolArray/examples/boolArrayDemo0/boolArrayDemo0.ino

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
//
2-
// FILE: boolArrayDemo2.ino
2+
// FILE: boolArrayDemo0.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.2.0
4+
// VERSION: 0.2.4
55
// PURPOSE: demo performance reading boolean array
66
// DATE: 2015-12-06
77
// URL: https://forum.arduino.cc/index.php?topic=361167.0
88
//
9-
// Released to the public domain
10-
//
119

1210

1311
#include "BoolArray.h"
@@ -57,7 +55,7 @@ void loop()
5755
void test0()
5856
{
5957
Serial.println();
60-
Serial.println("SET TEST0");
58+
Serial.println("TEST SET(1)");
6159

6260
start = micros();
6361
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
@@ -77,17 +75,17 @@ void test0()
7775
duration2 = micros() - start;
7876
Serial.print("DURATION:\t");
7977
Serial.println(duration2);
80-
Serial.print("\t\t\t");
81-
Serial.println(duration2 - duration1);
82-
Serial.print(" X:\t");
83-
Serial.println(x);
78+
Serial.print("\t\t");
79+
Serial.print(duration2 - duration1);
80+
Serial.print("\t");
81+
Serial.println((duration2 - duration1) / (1.0 * b.size()));
8482
}
8583

8684

8785
void test1()
8886
{
8987
Serial.println();
90-
Serial.println("SET TEST0");
88+
Serial.println("TEST SET(0)");
9189

9290
start = micros();
9391
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
@@ -107,17 +105,17 @@ void test1()
107105
duration2 = micros() - start;
108106
Serial.print("DURATION:\t");
109107
Serial.println(duration2);
110-
Serial.print("\t\t\t");
111-
Serial.println(duration2 - duration1);
112-
Serial.print(" X:\t");
113-
Serial.println(x);
108+
Serial.print("\t\t");
109+
Serial.print(duration2 - duration1);
110+
Serial.print("\t");
111+
Serial.println((duration2 - duration1) / (1.0 * b.size()));
114112
}
115113

116114

117115
void test2()
118116
{
119117
Serial.println();
120-
Serial.println("GET TEST");
118+
Serial.println("TEST GET(i)");
121119

122120
start = micros();
123121
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
@@ -137,40 +135,54 @@ void test2()
137135
duration2 = micros() - start;
138136
Serial.print("DURATION:\t");
139137
Serial.println(duration2);
140-
Serial.print("\t\t\t");
141-
Serial.println(duration2 - duration1);
142-
Serial.print(" X:\t");
143-
Serial.println(x);
138+
Serial.print("\t\t");
139+
Serial.print(duration2 - duration1);
140+
Serial.print("\t");
141+
Serial.println((duration2 - duration1) / (1.0 * b.size()));
144142
}
145143

146144

147145
void test3()
148146
{
149147
Serial.println();
150-
Serial.println("SET TEST");
151148

152149
start = micros();
153150
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
154151
{
155152
b.set(i, 0);
156153
}
157-
duration1 = micros();
158-
Serial.print("DURATION:\t");
154+
duration1 = micros() - start;
155+
Serial.print("TEST SET(0):\t");
159156
Serial.println(duration1);
157+
delay(10);
158+
159+
start = micros();
160+
b.setAll(0);
161+
duration2 = micros() - start;
162+
Serial.print("TEST SETALL(0):\t");
163+
Serial.println(duration2);
164+
Serial.print("FACTOR:\t\t");
165+
Serial.println(1.0 * duration1 / duration2);
166+
Serial.println();
167+
delay(10);
160168

161169
start = micros();
162170
for (int i = 0; i < BOOLARRAY_MAXSIZE; i++)
163171
{
164-
b.set(i, 0);
165-
b.set(i, 0);
172+
b.set(i, 1);
166173
}
167-
duration2 = micros();
168-
Serial.print("DURATION:\t");
174+
duration1 = micros() - start;
175+
Serial.print("TEST SET(1):\t");
176+
Serial.println(duration1);
177+
delay(10);
178+
179+
start = micros();
180+
b.setAll(1);
181+
duration2 = micros() - start;
182+
Serial.print("TEST SETALL(1):\t");
169183
Serial.println(duration2);
170-
Serial.print("\t\t\t");
171-
Serial.println(duration2 - duration1);
172-
Serial.print(" X:\t");
173-
Serial.println(x);
184+
Serial.print("FACTOR:\t\t");
185+
Serial.println(1.0 * duration1 / duration2);
174186
}
175187

176188
// -- END OF FILE --

libraries/BoolArray/examples/boolArrayDemo2/boolArrayDemo2.ino

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
// DATE: 2015-12-12
77
// URL: https://forum.arduino.cc/index.php?topic=361167.0
88
//
9-
// Released to the public domain
10-
//
119
// 0.1.1 - added performance for toggle
1210
//
1311

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
BOOLARRAY_LIB_VERSION: 0.2.3
2+
Bool array size: 1000
3+
4+
get
5+
DURATION: 5648
6+
DURATION: 9964
7+
X: 0
8+
9+
set
10+
DURATION: 4176
11+
DURATION: 7568
12+
13+
clear
14+
DURATION: 42396
15+
DURATION: 84352
16+
17+
setAll
18+
DURATION: 50332
19+
DURATION: 100100
20+
21+
toggle
22+
DURATION: 3996
23+
DURATION: 7320
24+
Done...

0 commit comments

Comments
 (0)