71 lines
1.7 KiB
C
Raw Normal View History

2020-05-22 16:00:06 +02:00
#pragma once
2017-08-20 22:12:07 +02:00
// FILE: PinInGroup.h
// AUTHOR: Rob dot Tillaart at gmail dot com
2022-11-22 12:37:06 +01:00
// VERSION: 0.1.8
2020-05-22 16:00:06 +02:00
// DATE: 2017-04-26
2017-08-20 22:12:07 +02:00
// PURPOSE: PinInGroup library for Arduino
//
2020-05-22 16:00:06 +02:00
// Note: ESP32 has some dedicated IO pins that cannot be used in a group.
// FLASH: pin 6 - 11 (maybe more)
2021-01-29 12:31:58 +01:00
2020-05-22 16:00:06 +02:00
2017-08-20 22:12:07 +02:00
#include "Arduino.h"
2021-01-29 12:31:58 +01:00
2022-11-22 12:37:06 +01:00
#define PININGROUP_LIB_VERSION (F("0.1.8"))
2021-01-29 12:31:58 +01:00
2020-05-22 16:00:06 +02:00
2022-08-04 17:25:38 +02:00
// smaller MAXSIZE will reduce memory footprint with ditto bytes.
2020-05-22 16:00:06 +02:00
#ifndef PININGROUP_MAXSIZE
2022-11-22 12:37:06 +01:00
#define PININGROUP_MAXSIZE 16
2020-05-22 16:00:06 +02:00
#endif
2022-11-22 12:37:06 +01:00
#define PININGROUP_ERROR_PIN 0xFF
2017-08-20 22:12:07 +02:00
class PinInGroup
{
2021-01-29 12:31:58 +01:00
public:
PinInGroup();
2022-08-04 17:25:38 +02:00
// enables one to reset the pinGroup and repopulate it
2021-01-29 12:31:58 +01:00
void clear();
2021-11-12 15:01:35 +01:00
2022-08-04 17:25:38 +02:00
// adds a predefined array of pin numbers to the PinInGroup
// sets all to either INPUT (default) or INPUT_PULLUP.
2021-11-12 15:01:35 +01:00
uint8_t add(uint8_t size, uint8_t * pinArray, uint8_t mode = INPUT);
2022-08-04 17:25:38 +02:00
// adds a single pin to the PinInGroup
2021-11-12 15:01:35 +01:00
uint8_t add(uint8_t pin, uint8_t mode = INPUT);
2020-05-22 16:00:06 +02:00
2022-08-04 17:25:38 +02:00
// counts how often a pin is in the group
2021-11-12 15:01:35 +01:00
uint8_t isInGroup(uint8_t pin);
uint8_t size() { return _size; };
uint8_t getMaxSize() { return PININGROUP_MAXSIZE; };
2022-08-04 17:25:38 +02:00
// check how many "slots" are available
2021-11-12 15:01:35 +01:00
uint8_t available() { return PININGROUP_MAXSIZE - _size; };
2020-05-22 16:00:06 +02:00
2022-08-04 17:25:38 +02:00
// read up to 16 pins "simultaneously" in one call.
2021-01-29 12:31:58 +01:00
uint16_t read();
2022-08-04 17:25:38 +02:00
// read specific index.
2021-11-12 15:01:35 +01:00
uint16_t read(uint8_t index);
2020-05-22 16:00:06 +02:00
2021-11-12 15:01:35 +01:00
uint8_t getPin(uint8_t index);
2022-11-22 12:37:06 +01:00
uint8_t getIndex(uint8_t pin); // returns first occurrence!
2022-08-04 17:25:38 +02:00
// OBSOLETE in next release
2022-11-22 12:37:06 +01:00
// uint8_t getIdx(uint8_t pin) { return getIndex(pin); };
2020-05-22 16:00:06 +02:00
2021-01-29 12:31:58 +01:00
private:
uint8_t _pins[PININGROUP_MAXSIZE];
uint8_t _size = 0;
2017-08-20 22:12:07 +02:00
};
2020-05-22 16:00:06 +02:00
2021-12-23 17:54:57 +01:00
2022-08-04 17:25:38 +02:00
// -- END OF FILE --
2021-12-23 17:54:57 +01:00