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

63 lines
1.5 KiB
C
Raw Normal View History

2021-05-17 09:43:30 -04:00
#pragma once
//
// FILE: rotaryDecoderSwitch.h
// AUTHOR: Rob Tillaart
2022-11-23 09:30:52 -05:00
// VERSION: 0.1.3
2021-05-17 09:43:30 -04:00
// DATE: 2021-05-17
2022-11-23 09:30:52 -05:00
// PURPOSE: Arduino library for rotary decoder (with switch)
2021-05-17 09:43:30 -04:00
// URL: https://github.com/RobTillaart/rotaryDecoderSwitch
#include "Arduino.h"
#include "Wire.h"
2022-11-23 09:30:52 -05:00
#define ROTARY_DECODER_SWITCH_LIB_VERSION (F("0.1.3"))
2021-05-17 09:43:30 -04:00
class rotaryDecoderSwitch
{
public:
explicit rotaryDecoderSwitch(const int8_t address, TwoWire *wire = &Wire);
#if defined (ESP8266) || defined(ESP32)
2021-11-16 13:02:04 -05:00
bool begin(uint8_t sda, uint8_t scl, uint8_t count = 2);
2021-05-17 09:43:30 -04:00
#endif
2021-11-16 13:02:04 -05:00
bool begin(uint8_t count = 2);
2021-05-17 09:43:30 -04:00
bool isConnected();
void readInitialState();
2022-11-23 09:30:52 -05:00
// for polling version,
// checkChange is bit faster than a call to update
// so useful if there are only a few updates
2021-05-17 09:43:30 -04:00
bool checkChange();
2022-11-23 09:30:52 -05:00
// read and update the counters
bool update(); // assumes two directions => +1 and -1
bool updateSingle(); // assumes single direction => + ++ +++
2021-05-17 09:43:30 -04:00
int32_t getValue(uint8_t re) { return _encoder[re]; };
void setValue(uint8_t re, int32_t val = 0) { _encoder[re] = val; };
bool isKeyPressed(uint8_t re);
2022-11-23 09:30:52 -05:00
// DEBUG
2021-05-17 09:43:30 -04:00
uint8_t getLastPosition(uint8_t re) { return _lastPos[re]; };
uint8_t getRaw() { return _read8(); };
2022-11-23 09:30:52 -05:00
2021-05-17 09:43:30 -04:00
private:
2021-11-16 13:02:04 -05:00
uint8_t _count = 0;
uint8_t _lastValue = 0;
2021-05-17 09:43:30 -04:00
uint8_t _lastPos[2] = { 0,0 };
int32_t _encoder[2] = { 0,0 };
uint8_t _read8();
uint8_t _address;
TwoWire * _wire;
};
2021-11-16 13:02:04 -05:00
2022-11-23 09:30:52 -05:00
// -- END OF FILE --
2021-11-16 13:02:04 -05:00