0.1.8 PinInGroup

This commit is contained in:
rob tillaart 2022-11-22 12:37:06 +01:00
parent 1241b83a82
commit 27c7ab6520
9 changed files with 157 additions and 61 deletions

View File

@ -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:
# Choosing to run compilation tests on 2 different Arduino platforms
# selected only those that work
platforms:
- uno
# - due
@ -7,5 +23,7 @@ compile:
# - leonardo
- m4
- esp32
# - esp8266
- esp8266
# - mega2560
- rpipico

View File

@ -0,0 +1,50 @@
# Change Log PinInGroup
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.8] - 2022-11-22
- add changelog.md
- add RP2040 in build
- obsolete getIdx() ==> getIndex()
- update documentation / comments
- update unit test
- add PININGROUP_ERROR_PIN
## [0.1.7] - 2022-08-04
- fix getIdx() to fix build-CI.
## [0.1.6] - 2021-12-23
- update library.json
- update license
- minor edits.
## [0.1.5] - 2021-11-12
- update build-CI
- update readme, badges
- rename variables for readability,
- add getIndex() to replace getIdx()
- add getMaxSize()
- fix version number and history
## [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
- refactor
- add clear()
- add param for INPUT or INPUT_PULLUP
## [0.1.0] - 2017-08-20
- initial version (based upon pinGroup)

View File

@ -1,31 +1,14 @@
//
// FILE: PinInGroup.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.7
// VERSION: 0.1.8
// DATE: 2017-04-26
// PURPOSE: PinInGroup library for Arduino
// goal is to easily read a group of pins that logically
// belong to each other.
// The pins can be in any order.
// The pins can be in any order, even duplicates are allowed.
// URL: https://github.com/RobTillaart/PinInGroup
// http://forum.arduino.cc/index.php?topic=469599.0
//
// HISTORY
// 0.1.0 2017-08-20 initial version (based upon pinGroup)
// 0.1.1 2020-05-19 refactor; added clear();
// added param for INPUT or INPUT_PULLUP
// 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-12 update build-CI
// update readme, badges
// rename variables for readability,
// add getIndex() to replace getIdx(),
// add getMaxSize(),
// fix version number and history.
// 0.1.6 2021-12-23 update library.json, license, minor edits.
// 0.1.7 2022-08-04 fix getIdx() to fix build-CI.
#include "PinInGroup.h"

View File

@ -1,10 +1,9 @@
#pragma once
// FILE: PinInGroup.h
// AUTHOR: Rob dot Tillaart at gmail dot com
// VERSION: 0.1.7
// VERSION: 0.1.8
// DATE: 2017-04-26
// PURPOSE: PinInGroup library for Arduino
// HISTORY: See PinInGroup.cpp
//
// Note: ESP32 has some dedicated IO pins that cannot be used in a group.
// FLASH: pin 6 - 11 (maybe more)
@ -13,14 +12,16 @@
#include "Arduino.h"
#define PININGROUP_LIB_VERSION (F("0.1.7"))
#define PININGROUP_LIB_VERSION (F("0.1.8"))
// smaller MAXSIZE will reduce memory footprint with ditto bytes.
#ifndef PININGROUP_MAXSIZE
#define PININGROUP_MAXSIZE 16
#define PININGROUP_MAXSIZE 16
#endif
#define PININGROUP_ERROR_PIN 0xFF
class PinInGroup
{
@ -53,11 +54,11 @@ public:
uint8_t getPin(uint8_t index);
uint8_t getIndex(uint8_t pin);
uint8_t getIndex(uint8_t pin); // returns first occurrence!
// OBSOLETE in next release
uint8_t getIdx(uint8_t pin) { return getIndex(pin); };
// uint8_t getIdx(uint8_t pin) { return getIndex(pin); };
private:
uint8_t _pins[PININGROUP_MAXSIZE];

View File

@ -51,9 +51,12 @@ Returns the number of pins added.
- **uint8_t add(uint8_t pin, uint8_t mode)** adds a single pin to the group.
Returns the number of pins added (1 or 0).
Mode can be **INPUT**(default) or **INPUT_PULLUP**.
- **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 isInGroup(uint8_t pin)** returns how often a pin is added to a group. Can be more than once.
- **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.
Returns 255 (0xFF) if not found.
- **uint8_t isInGroup(uint8_t pin)** returns how often a pin is added to a group.
Can be larger than one, max size of course.
- **uint8_t size()** how many slots are used.
- **uint8_t getMaxSize()** how many slots are there in total.
- **uint8_t available()** how many slots are free.
@ -61,34 +64,53 @@ Mode can be **INPUT**(default) or **INPUT_PULLUP**.
### Read
- **uint16_t read()** reads a 16 bits unsigned int from max 16 pins. Every bit represents an input value.
- **uint16_t read()** reads a 16 bits unsigned int from max 16 pins.
Every bit represents an input value.
Note that the bits are in LSB order of the adding.
- **uint16_t read(uint8_t index)** index = 0 .. size - 1.
Reads the single pin at index from the group.
Returns 0 or 1 if OK and 0xFFFF when index >= size.
# Operation
#### Error codes
PININGROUP_ERROR_PIN = 0xFF = 255.
## Operation
See examples.
## Future
- Optimize the low level reading e.g. reading registers only once.
- Hold register and bit info per pin.
- Especially for AVR this could be interesting performance wise.
- Create an analogPinGroup and a PWMGroup
- extend to 32 bits / pins. class hierarchy. 8, 24 ?
These ideas will be explored when time permits or needs arise.
#### must
- improve documentation
- move code from .h to .cpp
#### should
- add real live examples
- Allocate dynamic memory (0.2.0)
- fragmentation?
- would be memory efficient.
- clear() => reset() or clearGroup() ???
#### could
- Optimize the low level reading e.g. reading registers only once.
- Hold register and bit info per pin.
- Especially for AVR this could be interesting performance wise.
- Create a PWMGroup
- Create an analogPinGroup
- new class
- extend to 32 bits / pins. class hierarchy. 8, 24 ?
- clear() => reset() or clearGroup() ?
- do we need yield() somewhere?
- extend unit tests
- getIndex()
- getPin()
These ideas will be explored when time permits or needs arise.

View File

@ -20,6 +20,7 @@ getIndex KEYWORD2
# Constants (LITERAL1)
PININGROUP_LIB_VERSION LITERAL1
PININGROUP_MAXSIZE LITERAL1
PININGROUP_ERROR_PIN LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/PinInGroup.git"
},
"version": "0.1.7",
"version": "0.1.8",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,5 +1,5 @@
name=PinInGroup
version=0.1.7
version=0.1.8
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=A class that groups input pins so they can be read in one logical step.

View File

@ -41,18 +41,26 @@ unittest_setup()
fprintf(stderr, "PININGROUP_LIB_VERSION: %s\n", (char *) PININGROUP_LIB_VERSION);
}
unittest_teardown()
{
}
unittest(test_constants)
{
assertEqual(16, PININGROUP_MAXSIZE);
assertEqual(0xFF, PININGROUP_ERROR_PIN);
}
unittest(test_constructor)
{
PinInGroup PIG;
assertEqual(0, PIG.size());
assertEqual(0, PIG.size());
assertEqual(16, PIG.available());
assertEqual(16, PIG.getMaxSize());
assertEqual(0, PIG.isInGroup(2));
assertEqual(0, PIG.isInGroup(2));
}
@ -62,18 +70,18 @@ unittest(test_isInGroup)
uint8_t ar[8] = {2, 3, 4, 5, 6, 7, 4, 4};
PIG.add(8, ar, INPUT_PULLUP);
assertEqual(8, PIG.size());
assertEqual(8, PIG.available());
assertEqual(8, PIG.size());
assertEqual(8, PIG.available());
assertEqual(16, PIG.getMaxSize());
assertEqual(0, PIG.isInGroup(0));
assertEqual(1, PIG.isInGroup(2));
assertEqual(1, PIG.isInGroup(3));
assertEqual(3, PIG.isInGroup(4));
assertEqual(1, PIG.isInGroup(5));
assertEqual(1, PIG.isInGroup(6));
assertEqual(1, PIG.isInGroup(7));
assertEqual(0, PIG.isInGroup(8));
assertEqual(0, PIG.isInGroup(0));
assertEqual(1, PIG.isInGroup(2));
assertEqual(1, PIG.isInGroup(3));
assertEqual(3, PIG.isInGroup(4));
assertEqual(1, PIG.isInGroup(5));
assertEqual(1, PIG.isInGroup(6));
assertEqual(1, PIG.isInGroup(7));
assertEqual(0, PIG.isInGroup(8));
}
@ -83,9 +91,15 @@ unittest(test_getIndex)
uint8_t ar[8] = {2, 3, 4, 5, 6, 7, 4, 4};
PIG.add(8, ar, INPUT_PULLUP);
assertEqual(8, PIG.size());
assertEqual(8, PIG.available());
// TODO
assertEqual(8, PIG.size());
assertEqual(8, PIG.available());
assertEqual(0xFF, PIG.getIndex(0)); // not in group
assertEqual(0xFF, PIG.getIndex(1));
assertEqual(0, PIG.getIndex(2));
assertEqual(2, PIG.getIndex(4));
assertEqual(4, PIG.getIndex(6));
assertEqual(5, PIG.getIndex(7));
}
@ -95,9 +109,16 @@ unittest(test_getPin)
uint8_t ar[8] = {2, 3, 4, 5, 6, 7, 4, 4};
PIG.add(8, ar, INPUT_PULLUP);
assertEqual(8, PIG.size());
assertEqual(8, PIG.available());
// TODO
assertEqual(8, PIG.size());
assertEqual(8, PIG.available());
assertEqual(2, PIG.getPin(0));
assertEqual(3, PIG.getPin(1));
assertEqual(4, PIG.getPin(2));
assertEqual(6, PIG.getPin(4));
assertEqual(4, PIG.getPin(6));
assertEqual(4, PIG.getPin(7));
assertEqual(0xFF, PIG.getPin(8));
}