mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.1.7 PinOutGroup
This commit is contained in:
parent
27c7ab6520
commit
0b320673c1
@ -1,5 +1,21 @@
|
|||||||
|
platforms:
|
||||||
|
rpipico:
|
||||||
|
board: rp2040:rp2040:rpipico
|
||||||
|
package: rp2040:rp2040
|
||||||
|
gcc:
|
||||||
|
features:
|
||||||
|
defines:
|
||||||
|
- ARDUINO_ARCH_RP2040
|
||||||
|
warnings:
|
||||||
|
flags:
|
||||||
|
|
||||||
|
packages:
|
||||||
|
rp2040:rp2040:
|
||||||
|
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||||
|
|
||||||
compile:
|
compile:
|
||||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||||
|
# selected only those that work
|
||||||
platforms:
|
platforms:
|
||||||
- uno
|
- uno
|
||||||
# - due
|
# - due
|
||||||
@ -7,5 +23,6 @@ compile:
|
|||||||
# - leonardo
|
# - leonardo
|
||||||
- m4
|
- m4
|
||||||
- esp32
|
- esp32
|
||||||
# - esp8266
|
- esp8266
|
||||||
# - mega2560
|
# - mega2560
|
||||||
|
- rpipico
|
||||||
|
49
libraries/PinOutGroup/CHANGELOG.md
Normal file
49
libraries/PinOutGroup/CHANGELOG.md
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# Change Log PinOutGroup
|
||||||
|
|
||||||
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
|
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||||
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
## [ 0.1.7] - 2022-11-22
|
||||||
|
- add changelog.md
|
||||||
|
- add RP2040 to build-CI
|
||||||
|
- add PINOUTGROUP_ERROR_PIN
|
||||||
|
- update unit test
|
||||||
|
- obsolete getIdx()
|
||||||
|
|
||||||
|
|
||||||
|
## [0.1.6] - 2021-12-23
|
||||||
|
- update library.json
|
||||||
|
- update license
|
||||||
|
- minor edits
|
||||||
|
|
||||||
|
## [0.1.5] - 2021-11-13
|
||||||
|
- update Arduino-CI
|
||||||
|
- update readme.md - badges.
|
||||||
|
- fix version numbers and history
|
||||||
|
- fix bug in allHIGH()
|
||||||
|
- renamed variables for readability
|
||||||
|
- add getIndex() to replace getIdx(),
|
||||||
|
- add getMaxSize(),
|
||||||
|
|
||||||
|
## [0.1.4] - 2021-01-22
|
||||||
|
- ?
|
||||||
|
|
||||||
|
## [0.1.3] - 2021-01-05
|
||||||
|
- add Arduino-CI + unit test
|
||||||
|
|
||||||
|
## [0.1.2] - 2020-06-19
|
||||||
|
- fix library.json
|
||||||
|
|
||||||
|
## [0.1.1] - 2020-05-19
|
||||||
|
- main refactor;
|
||||||
|
- added tests
|
||||||
|
- added clear();
|
||||||
|
- added write(idx, value)
|
||||||
|
- renamed set to write() to be in line with digitalWrite()
|
||||||
|
|
||||||
|
## [0.1.0] - 20-08-2017
|
||||||
|
- initial version (based upon experimental pinGroup)
|
||||||
|
|
@ -1,7 +1,7 @@
|
|||||||
//
|
//
|
||||||
// FILE: PinOutGroup.cpp
|
// FILE: PinOutGroup.cpp
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.6
|
// VERSION: 0.1.7
|
||||||
// DATE: 2017-04-26
|
// DATE: 2017-04-26
|
||||||
// PURPOSE: PinOutGroup library for Arduino
|
// PURPOSE: PinOutGroup library for Arduino
|
||||||
// goal is to easily change a group of pins that logically
|
// goal is to easily change a group of pins that logically
|
||||||
@ -9,23 +9,7 @@
|
|||||||
// these pins can be in any order.
|
// these pins can be in any order.
|
||||||
// URL: https://github.com/RobTillaart/PinOutGroup
|
// URL: https://github.com/RobTillaart/PinOutGroup
|
||||||
// http://forum.arduino.cc/index.php?topic=469599.0
|
// http://forum.arduino.cc/index.php?topic=469599.0
|
||||||
//
|
|
||||||
// HISTORY
|
|
||||||
//
|
|
||||||
// 0.1.0 20-08-2017 initial version (based upon experimental pinGroup)
|
|
||||||
// 0.1.1 2020-05-19 main refactor;
|
|
||||||
// added tests; added clear(); added write(idx, value)
|
|
||||||
// renamed set to write() to be in line with digitalWrite()
|
|
||||||
// 0.1.2 2020-06-19 fix library.json
|
|
||||||
// 0.1.3 2021-01-05 add Arduino-CI + unit test
|
|
||||||
// 0.1.4 2021-01-22
|
|
||||||
// 0.1.5 2021-11-13 update Arduino-CI, readme.md badges.
|
|
||||||
// fix version numbers and history
|
|
||||||
// fix bug in allHIGH()
|
|
||||||
// renamed variables for readability
|
|
||||||
// add getIndex() to replace getIdx(),
|
|
||||||
// add getMaxSize(),
|
|
||||||
// 0.1.6 2021-12-23 update library.json, license, minor edits
|
|
||||||
|
|
||||||
|
|
||||||
#include "PinOutGroup.h"
|
#include "PinOutGroup.h"
|
||||||
@ -39,7 +23,7 @@ PinOutGroup::PinOutGroup()
|
|||||||
|
|
||||||
void PinOutGroup::clear()
|
void PinOutGroup::clear()
|
||||||
{
|
{
|
||||||
// safety: set all to LOW before cleaning up.
|
// safety: set all to LOW before cleaning up.
|
||||||
allLOW();
|
allLOW();
|
||||||
_size = 0;
|
_size = 0;
|
||||||
}
|
}
|
||||||
@ -62,7 +46,7 @@ uint8_t PinOutGroup::add(uint8_t pin, uint8_t value)
|
|||||||
|
|
||||||
_pins[_size] = pin;
|
_pins[_size] = pin;
|
||||||
pinMode(pin, OUTPUT);
|
pinMode(pin, OUTPUT);
|
||||||
write(_size, value); // takes care of _lastValue
|
write(_size, value); // takes care of _lastValue
|
||||||
_size++;
|
_size++;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -81,7 +65,7 @@ uint8_t PinOutGroup::isInGroup(uint8_t pin)
|
|||||||
|
|
||||||
uint8_t PinOutGroup::write(uint16_t value)
|
uint8_t PinOutGroup::write(uint16_t value)
|
||||||
{
|
{
|
||||||
uint16_t changed = _lastValue ^ value; // detect pins that changed
|
uint16_t changed = _lastValue ^ value; // detect pins that changed
|
||||||
if (changed == 0) return 0;
|
if (changed == 0) return 0;
|
||||||
|
|
||||||
uint16_t bitMask = 1;
|
uint16_t bitMask = 1;
|
||||||
@ -107,7 +91,7 @@ uint8_t PinOutGroup::write(uint8_t index, uint8_t value)
|
|||||||
uint16_t mask = (1 << index);
|
uint16_t mask = (1 << index);
|
||||||
uint16_t lastValue = _lastValue & mask;
|
uint16_t lastValue = _lastValue & mask;
|
||||||
|
|
||||||
if ((value > 0) == (lastValue > 0)) return 0; // no change
|
if ((value > 0) == (lastValue > 0)) return 0; // no change
|
||||||
|
|
||||||
digitalWrite(_pins[index], value);
|
digitalWrite(_pins[index], value);
|
||||||
if (value == LOW) _lastValue &= ~mask;
|
if (value == LOW) _lastValue &= ~mask;
|
||||||
@ -133,7 +117,7 @@ void PinOutGroup::allHIGH()
|
|||||||
for (uint8_t i = 0; i < _size; i++)
|
for (uint8_t i = 0; i < _size; i++)
|
||||||
{
|
{
|
||||||
digitalWrite(_pins[i], HIGH);
|
digitalWrite(_pins[i], HIGH);
|
||||||
value |= (1 << i); // set flags.
|
value |= (1 << i); // set flags.
|
||||||
}
|
}
|
||||||
_lastValue = value;
|
_lastValue = value;
|
||||||
}
|
}
|
||||||
@ -156,5 +140,5 @@ uint8_t PinOutGroup::getIndex(uint8_t pin)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// --- END OF FILE ---
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
@ -1,60 +1,64 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
// FILE: PinOutGroup.h
|
// FILE: PinOutGroup.h
|
||||||
// AUTHOR: Rob Tillaart
|
// AUTHOR: Rob Tillaart
|
||||||
// VERSION: 0.1.6
|
// VERSION: 0.1.7
|
||||||
// DATE: 2017-04-26
|
// DATE: 2017-04-26
|
||||||
// PURPOSE: PinOutGroup library for Arduino
|
// PURPOSE: PinOutGroup library for Arduino
|
||||||
// URL: https://github.com/RobTillaart/PinOutGroup
|
// URL: https://github.com/RobTillaart/PinOutGroup
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
|
|
||||||
#define PINOUTGROUP_LIB_VERSION (F("0.1.6"))
|
#define PINOUTGROUP_LIB_VERSION (F("0.1.7"))
|
||||||
|
|
||||||
|
|
||||||
// smaller MAXSIZE will reduce memory footprint with ditto bytes.
|
// smaller MAXSIZE will reduce memory footprint with ditto bytes.
|
||||||
#ifndef PINOUTGROUP_MAXSIZE
|
#ifndef PINOUTGROUP_MAXSIZE
|
||||||
#define PINOUTGROUP_MAXSIZE 16
|
#define PINOUTGROUP_MAXSIZE 16
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#define PINOUTGROUP_ERROR_PIN 0xFF
|
||||||
|
|
||||||
|
|
||||||
class PinOutGroup
|
class PinOutGroup
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PinOutGroup();
|
PinOutGroup();
|
||||||
|
|
||||||
// enables one to reset at he pinGroup and repopulate it
|
// enables one to reset at he pinGroup and repopulate it
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
// adds a predefined array of pin numbers to the PinOutGroup
|
// adds a predefined array of pin numbers to the PinOutGroup
|
||||||
// sets all to (LOW, HIGH)
|
// sets all to (LOW, HIGH)
|
||||||
uint8_t add(uint8_t size, uint8_t* pinArray, uint8_t value = LOW);
|
uint8_t add(uint8_t size, uint8_t* pinArray, uint8_t value = LOW);
|
||||||
// adds a single pin to the PinOutGroup, default to LOW.
|
// adds a single pin to the PinOutGroup, default to LOW.
|
||||||
uint8_t add(uint8_t pin, uint8_t value = LOW);
|
uint8_t add(uint8_t pin, uint8_t value = LOW);
|
||||||
|
|
||||||
// returns count of pin in the group => only 0 or 1 makes sense
|
// returns count of pin in the group => only 0 or 1 makes sense
|
||||||
uint8_t isInGroup(uint8_t pin);
|
uint8_t isInGroup(uint8_t pin);
|
||||||
|
|
||||||
// set up to 16 pins "simultaneously" in one call.
|
// set up to 16 pins "simultaneously" in one call.
|
||||||
uint8_t write(uint16_t value);
|
uint8_t write(uint16_t value);
|
||||||
// write to a single pin while maintaining internal admin
|
// write to a single pin while maintaining internal admin
|
||||||
uint8_t write(uint8_t index, uint8_t value);
|
uint8_t write(uint8_t index, uint8_t value);
|
||||||
void allLOW();
|
void allLOW();
|
||||||
void allHIGH();
|
void allHIGH();
|
||||||
|
|
||||||
// retrieve the last set value
|
// retrieve the last set value
|
||||||
uint16_t read() { return _lastValue; };
|
uint16_t read() { return _lastValue; };
|
||||||
|
|
||||||
uint8_t size() { return _size; };
|
uint8_t size() { return _size; };
|
||||||
// check how many free "slots" there are...
|
// check how many free "slots" there are...
|
||||||
uint8_t available() { return PINOUTGROUP_MAXSIZE - _size; };
|
uint8_t available() { return PINOUTGROUP_MAXSIZE - _size; };
|
||||||
uint8_t getMaxSize() { return PINOUTGROUP_MAXSIZE; };
|
uint8_t getMaxSize() { return PINOUTGROUP_MAXSIZE; };
|
||||||
|
|
||||||
uint8_t getPin(uint8_t index);
|
uint8_t getPin(uint8_t index);
|
||||||
uint8_t getIndex(uint8_t pin);
|
uint8_t getIndex(uint8_t pin);
|
||||||
uint8_t getIdx(uint8_t pin) { return getIndex(pin); }; // will be obsolete in 0.2.0
|
|
||||||
|
// obsolete
|
||||||
|
// uint8_t getIdx(uint8_t pin) { return getIndex(pin); };
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -64,5 +68,5 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// -- END OF FILE --
|
// -- END OF FILE --
|
||||||
|
|
||||||
|
@ -48,10 +48,12 @@ This is platform, group size and pin state dependent.
|
|||||||
|
|
||||||
### Administration
|
### Administration
|
||||||
|
|
||||||
- **void clear()** resets all pins in the group to LOW and sets the size to zero
|
- **void clear()** resets all pins in the group to LOW and sets the size to zero.
|
||||||
so one can repopulate.
|
so one can repopulate.
|
||||||
- **uint8_t add(uint8_t size, uint8_t \* pinArray, uint8_t value = LOW)** adds a predefined array of pins to the group. Returns the number of pins added. Default the pins are set to LOW.
|
- **uint8_t add(uint8_t size, uint8_t \* pinArray, uint8_t value = LOW)** adds a predefined array of pins to the group.
|
||||||
- **uint8_t add(uint8_t pin, uint8_t mode = LOW)** adds a single pin to the group. Returns the number of pins added (1 or 0). value can be LOW (=0, default) or HIGH (1 and other values).
|
Returns the number of pins added. Default the pins are set to LOW.
|
||||||
|
- **uint8_t add(uint8_t pin, uint8_t mode = LOW)** adds a single pin to the group.
|
||||||
|
Returns the number of pins added (1 or 0). value can be LOW (=0, default) or HIGH (1 and other values).
|
||||||
- **uint8_t getPin(uint8_t index)** index = 0..15; returns the pin at slot index or 255 (0xFF) when out of range.
|
- **uint8_t getPin(uint8_t index)** index = 0..15; returns the pin at slot index or 255 (0xFF) when out of range.
|
||||||
- **uint8_t getIndex(uint8_t pin)** returns the (first) index of the slot with pin number. 255 (0xFF) if not found.
|
- **uint8_t getIndex(uint8_t pin)** returns the (first) index of the slot with pin number. 255 (0xFF) if not found.
|
||||||
- **uint8_t isInGroup(uint8_t pin)** returns how often a pin is added to a group. Can be more than once.
|
- **uint8_t isInGroup(uint8_t pin)** returns how often a pin is added to a group. Can be more than once.
|
||||||
@ -78,9 +80,19 @@ See examples
|
|||||||
|
|
||||||
## Future
|
## Future
|
||||||
|
|
||||||
|
#### must
|
||||||
|
- update documentation
|
||||||
|
|
||||||
|
#### should
|
||||||
|
- move code from .h to .cpp
|
||||||
|
- should clear() have a flag to set to LOW/HIGH/NOCHANGE when clearing?
|
||||||
|
|
||||||
|
#### could
|
||||||
- Optimize the low level writing
|
- Optimize the low level writing
|
||||||
For AVR this could be interesting (performance).
|
For AVR this could be interesting (performance).
|
||||||
- extend to 32 bits / pins. class hierarchy. 8, 24 ?
|
- extend to 32 bits / pins. class hierarchy. 8, 24 ?
|
||||||
- give **clear(skip)** a bool flag to skip setting the pins to LOW ?
|
- give **clear(skip)** a bool flag to skip setting the pins to LOW ?
|
||||||
- remove function?
|
- remove function?
|
||||||
- check PinInGroup to stay in "sync" API wise.
|
- check PinInGroup to stay in "sync" API wise.
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ allHIGH KEYWORD2
|
|||||||
|
|
||||||
# Constants (LITERAL1)
|
# Constants (LITERAL1)
|
||||||
PINOUTGROUP_LIB_VERSION LITERAL1
|
PINOUTGROUP_LIB_VERSION LITERAL1
|
||||||
|
|
||||||
PINOUTGROUP_MAXSIZE LITERAL1
|
PINOUTGROUP_MAXSIZE LITERAL1
|
||||||
|
PINOUTGROUP_ERROR_PIN LITERAL1
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/RobTillaart/PinOutGroup.git"
|
"url": "https://github.com/RobTillaart/PinOutGroup.git"
|
||||||
},
|
},
|
||||||
"version": "0.1.6",
|
"version": "0.1.7",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"frameworks": "arduino",
|
"frameworks": "arduino",
|
||||||
"platforms": "*",
|
"platforms": "*",
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
name=PinOutGroup
|
name=PinOutGroup
|
||||||
version=0.1.6
|
version=0.1.7
|
||||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||||
sentence=A class that groups output pins so they can be updated easier and slightly faster on average.
|
sentence=A class that groups output pins so they can be updated easier and slightly faster on average.
|
||||||
|
@ -47,24 +47,65 @@ unittest_teardown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unittest(test_constants)
|
||||||
|
{
|
||||||
|
assertEqual(16, PINOUTGROUP_MAXSIZE);
|
||||||
|
assertEqual(0xFF, PINOUTGROUP_ERROR_PIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
unittest(test_all)
|
unittest(test_all)
|
||||||
{
|
{
|
||||||
PinOutGroup POG;
|
PinOutGroup POG;
|
||||||
uint8_t ar[46] = {2, 3, 4, 5, 6, 7};
|
uint8_t ar[16] = {2, 3, 4, 5, 6, 7};
|
||||||
|
|
||||||
assertEqual(0, POG.size());
|
assertEqual(0, POG.size());
|
||||||
assertEqual(16, POG.available());
|
assertEqual(16, POG.available());
|
||||||
assertEqual(16, POG.getMaxSize());
|
assertEqual(16, POG.getMaxSize());
|
||||||
assertFalse(POG.isInGroup(2));
|
assertEqual(0, POG.isInGroup(2));
|
||||||
|
|
||||||
POG.add(6, ar, LOW);
|
POG.add(6, ar, LOW);
|
||||||
assertEqual(6, POG.size());
|
assertEqual(6, POG.size());
|
||||||
assertEqual(10, POG.available());
|
assertEqual(10, POG.available());
|
||||||
assertEqual(16, POG.getMaxSize());
|
assertEqual(16, POG.getMaxSize());
|
||||||
assertTrue(POG.isInGroup(2));
|
assertEqual(1, POG.isInGroup(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unittest(test_getPin)
|
||||||
|
{
|
||||||
|
PinOutGroup POG;
|
||||||
|
uint8_t ar[16] = {2, 3, 4, 5, 6, 7};
|
||||||
|
POG.add(6, ar, LOW);
|
||||||
|
|
||||||
|
assertEqual(2, POG.getPin(0));
|
||||||
|
assertEqual(3, POG.getPin(1));
|
||||||
|
assertEqual(4, POG.getPin(2));
|
||||||
|
assertEqual(5, POG.getPin(3));
|
||||||
|
assertEqual(6, POG.getPin(4));
|
||||||
|
assertEqual(7, POG.getPin(5));
|
||||||
|
assertEqual(0xFF, POG.getPin(6));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
unittest(test_getIndex)
|
||||||
|
{
|
||||||
|
PinOutGroup POG;
|
||||||
|
uint8_t ar[16] = {2, 3, 4, 5, 6, 7};
|
||||||
|
POG.add(6, ar, LOW);
|
||||||
|
|
||||||
|
assertEqual(0xFF, POG.getIndex(0)); // pin 0 is not in group
|
||||||
|
assertEqual(0xFF, POG.getIndex(1));
|
||||||
|
assertEqual(0, POG.getIndex(2));
|
||||||
|
assertEqual(1, POG.getIndex(3));
|
||||||
|
assertEqual(2, POG.getIndex(4));
|
||||||
|
assertEqual(3, POG.getIndex(5));
|
||||||
|
assertEqual(0xFF, POG.getIndex(8));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
unittest_main()
|
unittest_main()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user