GY-63_MS5611/libraries/PinInGroup/PinInGroup.h

71 lines
1.7 KiB
C
Raw Normal View History

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