0.1.3 rotaryDecoderSwitch

This commit is contained in:
rob tillaart 2022-11-23 15:30:52 +01:00
parent f2bf989d84
commit b25fa79612
8 changed files with 95 additions and 42 deletions

View File

@ -1,11 +1,29 @@
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
- zero
- leonardo
# - due
# - zero
# - leonardo
- m4
- esp32
- esp8266
- mega2560
# - mega2560
- rpipico

View File

@ -0,0 +1,27 @@
# Change Log rotaryDecoderSwitch
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.3] - 2022-11-23
- add changelog.md
- add RP2040 to build-CI
- fix version number .cpp
- minor edits
## [0.1.2] - 2021-12-27
- update library.json
- update readme.md
- update license
- minor edits
## [0.1.1] - 2021-11-16
- update build-CI, readme.md, badges
- improve readability of code
## [0.1.0] - 2021-05-17
- initial version

View File

@ -78,7 +78,8 @@ assumes that the rotary encoder only goes into a single direction.
- **uint32_t getValue(uint8_r re)** returns the RE counter. (re = 0 or 1).
- **void setValue(uint8_r re, uint32_t val = 0)** (re)set the internal counter to val, default 0
- **bool isKeyPressed(uint8_t re)** returns true is the switch is pressed of the RE selected (re = 0 or 1). Note one needs to call **update()** first!
- **bool isKeyPressed(uint8_t re)** returns true is the switch is pressed of the RE selected (re = 0 or 1).
Note one needs to call **update()** first!
## Debugging
@ -126,6 +127,14 @@ See examples..
## Future
- think of what to do with the two "idle lines"
#### must
- update documentation
- add schematic.
- add schema
- keep in sync with rotaryDecoder library
#### should
- think of what to do with the two "idle lines"
#### could

View File

@ -1,4 +1,4 @@
# Syntax Colouring Map For rotaryDecoder
# Syntax Colouring Map For rotaryDecoderSwitch
# Data types (KEYWORD1)

View File

@ -1,7 +1,7 @@
{
"name": "rotaryDecoderSwitch",
"keywords": "rotary,encoder,PCF8574",
"description": "Arduino library to rotary decoder with a PCF8574\nSupports up to 2 RE's with switch",
"description": "Arduino library for rotary decoder+switch with a PCF8574\nSupports up to 2 RE's with switch",
"authors":
[
{
@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/rotaryDecoderSwitch.git"
},
"version": "0.1.2",
"version": "0.1.3",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",

View File

@ -1,8 +1,8 @@
name=rotaryDecoderSwitch
version=0.1.2
version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library to rotary decoder with a PCF8574
sentence=Arduino library for rotary decoder+switch with a PCF8574
paragraph=Supports up to 2 RE's with a switch
category=Data Processing
url=https://github.com/RobTillaart/rotaryDecoderSwitch

View File

@ -1,16 +1,10 @@
//
// FILE: rotaryDecoderSwitch.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.1
// VERSION: 0.1.3
// DATE: 2021-05-17
// PURPOSE: rotary decoder library for Arduino
// PURPOSE: Arduino library for rotary decoder (with switch)
// URL: https://github.com/RobTillaart/rotaryDecoderSwitch
//
// HISTORY:
// 0.1.0 2021-05-17 initial version
// 0.1.1 2021-11-16 update build-CI, readnme.md, badges
// improve readability of code
// 0.1.2 2021-12-27 update library.json, readme, license, minor edits
#include "rotaryDecoderSwitch.h"
@ -18,7 +12,7 @@
/////////////////////////////////////////////////////
//
// CONSTRUCTORS
// CONSTRUCTORS
//
rotaryDecoderSwitch::rotaryDecoderSwitch(const int8_t address, TwoWire *wire)
{
@ -61,7 +55,7 @@ void rotaryDecoderSwitch::readInitialState()
{
uint8_t value = _read8();
_lastValue = value;
// pin 0,1 and 4,5
// pin 0,1 and 4,5
for (uint8_t i = 0; i < _count; i++)
{
_lastPos[i] = value & 0x03;
@ -91,7 +85,7 @@ bool rotaryDecoderSwitch::update()
uint8_t change = (_lastPos[i] << 2) | currentpos;
switch (change)
{
case 0b0001: // fall through..
case 0b0001: // fall through..
case 0b0111:
case 0b1110:
case 0b1000:
@ -125,7 +119,7 @@ bool rotaryDecoderSwitch::updateSingle()
uint8_t change = (_lastPos[i] << 2) | currentpos;
switch (change)
{
case 0b0001: // fall through..
case 0b0001: // fall through..
case 0b0111:
case 0b1110:
case 0b1000:
@ -150,13 +144,6 @@ bool rotaryDecoderSwitch::updateSingle()
}
uint8_t rotaryDecoderSwitch::_read8()
{
_wire->requestFrom(_address, (uint8_t)1);
return _wire->read();
}
bool rotaryDecoderSwitch::isKeyPressed(uint8_t re)
{
uint8_t mask = 0x04;
@ -165,5 +152,16 @@ bool rotaryDecoderSwitch::isKeyPressed(uint8_t re)
}
/////////////////////////////////////////////////////
//
// PRIVATE
//
uint8_t rotaryDecoderSwitch::_read8()
{
_wire->requestFrom(_address, (uint8_t)1);
return _wire->read();
}
// -- END OF FILE --

View File

@ -2,16 +2,16 @@
//
// FILE: rotaryDecoderSwitch.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.1.3
// DATE: 2021-05-17
// PURPOSE: rotary decoder library for Arduino
// PURPOSE: Arduino library for rotary decoder (with switch)
// URL: https://github.com/RobTillaart/rotaryDecoderSwitch
#include "Arduino.h"
#include "Wire.h"
#define ROTARY_DECODER_SWITCH_LIB_VERSION (F("0.1.2"))
#define ROTARY_DECODER_SWITCH_LIB_VERSION (F("0.1.3"))
class rotaryDecoderSwitch
@ -28,23 +28,24 @@ public:
void readInitialState();
// for polling version,
// checkChange is bit faster than a call to update
// so useful if there are only a few updates
// for polling version,
// checkChange is bit faster than a call to update
// so useful if there are only a few updates
bool checkChange();
// read and update the counters
bool update(); // assumes two directions => +1 and -1
bool updateSingle(); // assumes single direction => + ++ +++
// read and update the counters
bool update(); // assumes two directions => +1 and -1
bool updateSingle(); // assumes single direction => + ++ +++
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);
// DEBUG
// DEBUG
uint8_t getLastPosition(uint8_t re) { return _lastPos[re]; };
uint8_t getRaw() { return _read8(); };
private:
uint8_t _count = 0;
uint8_t _lastValue = 0;
@ -57,5 +58,5 @@ private:
};
// -- END OF FILE --
// -- END OF FILE --