Skip to content

Commit

Permalink
refactor begin() (#8)
Browse files Browse the repository at this point in the history
- simplify begin() interface - breaking change
- update readme.md
  • Loading branch information
RobTillaart committed Nov 21, 2023
1 parent 5a63607 commit ee7330f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 32 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.2.0] - 2023-11-21
- simplify begin() interface - breaking change
- update readme.md

----

## [0.1.4] - 2023-09-22
- add Wire1 support for ESP32
- moved code from .h to .cpp
- update readme.md
- minor edits


## [0.1.3] - 2022-11-23
- add changelog.md
- add RP2040 to build-CI
Expand Down
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ library assumes these are used. Furthermore it is advised to connect the free PC
pins to GND so you will not get unintended interrupts.


#### Related

- https://github.com/RobTillaart/rotaryDecoderSwitch
- https://github.com/RobTillaart/PCF8574


## Interface

```cpp
Expand All @@ -34,10 +40,6 @@ pins to GND so you will not get unintended interrupts.
#### Constructor

- **rotaryDecoder(const int8_t address, TwoWire \*wire = Wire);**
- **bool begin(uint8_t sda, uint8_t scl, uint8_t count = 4)** ESP32 ea initializes the class
by setting the I2C sda and scl pins.
count is the number of rotary encoders connected. (Max 4 per PCF8574)
Returns true if the PCF8574 is on the I2C bus.
- **bool begin(uint8_t count = 4)** UNO ea. initializes the class.
count is the number of rotary encoders connected. (Max 4 per PCF8574)
Returns true if the PCF8574 is on the I2C bus.
Expand Down Expand Up @@ -114,23 +116,19 @@ See examples..
- update documentation
- picture how to connect e.g two rotary encoders which pins to used


#### Should

- test with a high speed drill like a Dremel-tool.


#### Could

- invert flag to adjust to RE that give their pulse just the other way around?
- setInvert(bool); getInvert();
- per channel / all?


#### Wont



## Support

If you appreciate my libraries, you can support the development and maintenance.
Expand Down
3 changes: 2 additions & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
"type": "git",
"url": "https://github.com/RobTillaart/rotaryDecoder.git"
},
"version": "0.1.4",
"version": "0.2.0",
"license": "MIT",
"frameworks": "*",
"platforms": "*",
"headers": "rotaryDecoder.h"
}

2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=rotaryDecoder
version=0.1.4
version=0.2.0
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library to rotary decoder with a PCF8574
Expand Down
16 changes: 2 additions & 14 deletions rotaryDecoder.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: rotaryDecoder.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.4
// VERSION: 0.2.0
// DATE: 2021-05-08
// PURPOSE: rotary decoder library for Arduino
// URL: https://github.com/RobTillaart/rotaryDecoder
Expand All @@ -21,23 +21,11 @@ rotaryDecoder::rotaryDecoder(const int8_t address, TwoWire *wire)
}


#if defined (ESP8266) || defined(ESP32)
bool rotaryDecoder::begin(uint8_t sda, uint8_t scl, uint8_t count)
{
_count = count;
if (_count > 4) _count = 4;
_wire->begin(sda, scl);
if (! isConnected()) return false;
return true;
}
#endif


bool rotaryDecoder::begin(uint8_t count)
{
_count = count;
if (_count > 4) _count = 4;
_wire->begin();

if (! isConnected()) return false;
return true;
}
Expand Down
8 changes: 2 additions & 6 deletions rotaryDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: rotaryDecoder.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.4
// VERSION: 0.2.0
// DATE: 2021-05-08
// PURPOSE: rotary decoder library for Arduino
// URL: https://github.com/RobTillaart/rotaryDecoder
Expand All @@ -11,18 +11,14 @@
#include "Arduino.h"
#include "Wire.h"

#define ROTARY_DECODER_LIB_VERSION (F("0.1.4"))
#define ROTARY_DECODER_LIB_VERSION (F("0.2.0"))


class rotaryDecoder
{
public:
explicit rotaryDecoder(const int8_t address, TwoWire *wire = &Wire);

#if defined (ESP8266) || defined(ESP32)
bool begin(uint8_t sda, uint8_t scl, uint8_t count = 4);
#endif

bool begin(uint8_t count = 4);
bool isConnected();

Expand Down
4 changes: 3 additions & 1 deletion test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,6 @@ unittest(test_constructor)

unittest_main()

// --------

// -- END OF FILE --

0 comments on commit ee7330f

Please sign in to comment.