Skip to content

Commit

Permalink
Develop (#4)
Browse files Browse the repository at this point in the history
* add changelog.md
* add RP2040 to build-CI
  • Loading branch information
RobTillaart authored Oct 27, 2022
1 parent 7320e5a commit fb7dcd8
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 43 deletions.
19 changes: 18 additions & 1 deletion .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
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
platforms:
Expand All @@ -8,4 +23,6 @@ compile:
- m4
- esp32
# - esp8266
# - mega2560
# - mega2560
- rpipico

35 changes: 12 additions & 23 deletions AnalogKeypad.cpp
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
//
// FILE: AnalogKeypad.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.2.1
// VERSION: 0.2.2
// DATE: 2019-01-31
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analog keypad
//
// HISTORY:
// 0.1.0 2019-01-31 initial version
// 0.1.1 2019-02-01 add pressed() event() last()
// 0.1.2 2019-02-01 refactored rawRead(), first stable version
// 0.1.3 2020-03-25 minor refactoring
// 0.1.4 2020-05-27 update library.json
// 0.1.5 2020-12-09 add Arduino-CI
// 0.1.6 2021-05-27 fix Arduino-lint
// 0.2.0 2021-10-17 update build-CI, readme,
// add bits as parameter in constructor.
// 0.2.1 2021-12-12 update library.json, license
// add test_constants to unit test.
// HISTORY: see changelog.md


#include "AnalogKeypad.h"


// NOTE the MAGIC NUMBERS in rawRead() are for 8 BIT ADC
// as 8 bit compares are fast
// NOTE the MAGIC NUMBERS in rawRead() are for 8 BIT ADC
// as 8 bit compares are fast
//
// The _analogShift takes care if the ADC has more
// than e.g. 10 bits.
// The _analogShift takes care if the ADC has more
// than e.g. 10 bits.
//
// Arduino UNO3 build in ==> 10 bits
// Other may have 12 or even 16 bits.
// Arduino UNO3 build in ==> 10 bits
// Other may have 12 or even 16 bits.


AnalogKeypad::AnalogKeypad(const uint8_t pin, const uint8_t bits)
Expand Down Expand Up @@ -92,16 +81,16 @@ uint8_t AnalogKeypad::read()
}


// Adjust numbers for other than 4x4 keypad
// Adjust numbers for other than 4x4 keypad
uint8_t AnalogKeypad::_rawRead()
{
// spends most time in analogRead (UNO ~110 microseconds)
// spends most time in analogRead (UNO ~110 microseconds)
uint8_t val = (analogRead(_analogPin) >> _analogShift);

// handle NOKEY first
// handle NOKEY first
if (val < 57) return 0;

// reduce average # compares by 2 (4x4 keypad)
// reduce average # compares by 2 (4x4 keypad)
if (val < 135)
{
if (val < 62) return 16;
Expand Down
28 changes: 14 additions & 14 deletions AnalogKeypad.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: AnalogKeypad.h
// AUTHOR: Rob Tillaart
// VERSION: 0.2.1
// VERSION: 0.2.2
// DATE: 2019-01-31
// PURPOSE: Class for (Robotdyn) 4x4 and 4x3 analogue keypad
// URL: https://github.com/RobTillaart/AnalogKeypad
Expand All @@ -12,31 +12,31 @@
#include "Arduino.h"


#define ANALOGKEYPAD_LIB_VERSION (F("0.2.1"))
#define ANALOGKEYPAD_LIB_VERSION (F("0.2.2"))

#define NOKEY 0x00
#define PRESSED 0x80
#define RELEASED 0x40
#define REPEATED 0x20
#define CHANGED 0x10
#define NOKEY 0x00
#define PRESSED 0x80
#define RELEASED 0x40
#define REPEATED 0x20
#define CHANGED 0x10


class AnalogKeypad
{
public:
explicit AnalogKeypad(const uint8_t pin, const uint8_t bits = 10);

// returns 0 if no key pressed
// otherwise returns key pressed first => ignoring fluctuations
// 2nd or more presses simultaneous are ignored
// returns 0 if no key pressed
// otherwise returns key pressed first => ignoring fluctuations
// 2nd or more presses simultaneous are ignored
uint8_t pressed();

// returns 0 if no key pressed
// otherwise returns key pressed (may fluctuate)
// returns 0 if no key pressed
// otherwise returns key pressed (may fluctuate)
uint8_t read();

// event alike approach
// switch(int e = event()) see examples
// event alike approach
// switch(int e = event()) see examples
uint8_t event();
uint8_t key() { return _lastKey; } ;

Expand Down
42 changes: 42 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Change Log analogKeypad

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.2.2] - 2022-10-27
- Add RP2040 support to build-CI.
- Add CHANGELOG.md

## [0.2.1] - 2021-12-12
- update library.json, license
- add test_constants to unit test.

## [0.2.0] - 2021-10-17
- update build-CI, readme,
- add bits as parameter in constructor.

----

## [0.1.6] - 2021-05-27
- fix Arduino-lint

## [0.1.5] - 2020-12-09
- add Arduino-CI

## [0.1.4] - 2020-05-27
- update library.json

## [0.1.3] - 2020-03-25
- minor refactoring

## [0.1.2] - 2019-02-01
- refactored rawRead(), first stable version

## [0.1.1] - 2019-02-01
- add pressed() event() last()

## [0.1.0] - 2019-01-31
- initial version
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ a number 1 to 16 for the keys pressed. Note the return value may
fluctuate randomly when multiple keys are pressed.

The **pressed()** function is a bit more robust.
It returns the key pressed first, so multiple key presses simultaniously
It returns the key pressed first, so multiple key presses simultaneously
are less likely to disturb your program.

See Examples
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/AnalogKeypad"
},
"version": "0.2.1",
"version": "0.2.2",
"license": "MIT",
"frameworks": "arduino",
"platforms": "*",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AnalogKeypad
version=0.2.1
version=0.2.2
author=Rob Tillaart <[email protected]>
maintainer=Rob Tillaart <[email protected]>
sentence=Arduino Library for (Robotdyn) 4x4 and 4x3 AnalogKeypad
Expand Down
3 changes: 1 addition & 2 deletions test/unit_test_001.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

unittest_setup()
{
fprintf(stderr, "ANALOGKEYPAD_LIB_VERSION: %s\n", (char *) ANALOGKEYPAD_LIB_VERSION);
}

unittest_teardown()
Expand All @@ -36,8 +37,6 @@ unittest_teardown()

unittest(test_constants)
{
fprintf(stderr, "ANALOGKEYPAD_LIB_VERSION: %s\n", (char *) ANALOGKEYPAD_LIB_VERSION);

assertEqual(0x00, NOKEY );
assertEqual(0x80, PRESSED );
assertEqual(0x40, RELEASED);
Expand Down

0 comments on commit fb7dcd8

Please sign in to comment.