-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c77f95
commit 3f6ab4d
Showing
16 changed files
with
621 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
compile: | ||
# Choosing to run compilation tests on 2 different Arduino platforms | ||
platforms: | ||
- uno | ||
# - due | ||
# - zero | ||
# - leonardo | ||
- m4 | ||
- esp32 | ||
# - esp8266 | ||
# - mega2560 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# These are supported funding model platforms | ||
|
||
github: RobTillaart | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
name: Arduino-lint | ||
|
||
on: [push, pull_request] | ||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: arduino/arduino-lint-action@v1 | ||
with: | ||
library-manager: update | ||
compliance: strict |
17 changes: 17 additions & 0 deletions
17
libraries/I2CKeyPad8x8/.github/workflows/arduino_test_runner.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
name: Arduino CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
runTest: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 2.6 | ||
- run: | | ||
gem install arduino_ci | ||
arduino_ci.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
name: JSON check | ||
|
||
on: | ||
push: | ||
paths: | ||
- '**.json' | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: json-syntax-check | ||
uses: limitusus/json-syntax-check@v1 | ||
with: | ||
pattern: "\\.json$" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
// | ||
// FILE: I2CKeyPad8x8.cpp | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.1.0 | ||
// PURPOSE: Arduino library for 8x8 or smaller KeyPad connected to an I2C PCF8575. | ||
// URL: https://github.com/RobTillaart/I2CKeyPad8x8 | ||
// | ||
// HISTORY: | ||
// 0.1.0 2022-09-29 initial version | ||
|
||
|
||
|
||
#include "I2CKeyPad8x8.h" | ||
|
||
|
||
I2CKeyPad8x8::I2CKeyPad8x8(const uint8_t deviceAddress, TwoWire *wire) | ||
{ | ||
_lastKey = I2C_KEYPAD8x8_NOKEY; | ||
_address = deviceAddress; | ||
_wire = wire; | ||
} | ||
|
||
|
||
#if defined(ESP8266) || defined(ESP32) | ||
bool I2CKeyPad8x8::begin(uint8_t sda, uint8_t scl) | ||
{ | ||
_wire->begin(sda, scl); | ||
// enable interrupts | ||
_read(0xFF00); | ||
return isConnected(); | ||
} | ||
#endif | ||
|
||
|
||
bool I2CKeyPad8x8::begin() | ||
{ | ||
_wire->begin(); | ||
// enable interrupts | ||
_read(0xFF00); | ||
return isConnected(); | ||
} | ||
|
||
|
||
uint8_t I2CKeyPad8x8::getKey() | ||
{ | ||
// key = row + 8 x col | ||
uint8_t key = 0; | ||
|
||
// mask = 8 rows as input pull up, 8 columns as output | ||
uint16_t rows = _read(0xFF00); | ||
|
||
// check if single line has gone low. | ||
if (rows == 0xFF00) return I2C_KEYPAD8x8_NOKEY; | ||
else if (rows == 0xFE00) key = 0; | ||
else if (rows == 0xFD00) key = 1; | ||
else if (rows == 0xFB00) key = 2; | ||
else if (rows == 0xF700) key = 3; | ||
else if (rows == 0xEF00) key = 4; | ||
else if (rows == 0xDF00) key = 5; | ||
else if (rows == 0xBF00) key = 6; | ||
else if (rows == 0x7F00) key = 7; | ||
else return I2C_KEYPAD8x8_FAIL; | ||
|
||
// 8 columns as input pull up, 8 rows as output | ||
uint16_t cols = _read(0x00FF); | ||
// check if single line has gone low. | ||
if (cols == 0x00FF) return I2C_KEYPAD8x8_NOKEY; | ||
else if (cols == 0x00FE) key += 0; | ||
else if (cols == 0x00FD) key += 8; | ||
else if (cols == 0x00FB) key += 16; | ||
else if (cols == 0x00F7) key += 24; | ||
else if (cols == 0x00EF) key += 32; | ||
else if (cols == 0x00DF) key += 40; | ||
else if (cols == 0x00BF) key += 48; | ||
else if (cols == 0x007F) key += 56; | ||
else return I2C_KEYPAD8x8_FAIL; | ||
|
||
_lastKey = key; | ||
|
||
return key; // 0..65 | ||
} | ||
|
||
|
||
uint8_t I2CKeyPad8x8::getLastKey() | ||
{ | ||
return _lastKey; | ||
}; | ||
|
||
|
||
// to check "press any key" | ||
bool I2CKeyPad8x8::isPressed() | ||
{ | ||
uint16_t a = _read(0xFF00); | ||
if (a == 0xFF00) return false; | ||
return (a != 0xFF00); | ||
} | ||
|
||
|
||
bool I2CKeyPad8x8::isConnected() | ||
{ | ||
_wire->beginTransmission(_address); | ||
return (_wire->endTransmission() == 0); | ||
} | ||
|
||
|
||
uint8_t I2CKeyPad8x8::getChar() | ||
{ | ||
return _keyMap[getKey()]; | ||
}; | ||
|
||
|
||
uint8_t I2CKeyPad8x8::getLastChar() | ||
{ | ||
return _keyMap[_lastKey]; | ||
}; | ||
|
||
|
||
void I2CKeyPad8x8::loadKeyMap(char * keyMap) | ||
{ | ||
_keyMap = keyMap; | ||
} | ||
|
||
|
||
////////////////////////////////////////////////////// | ||
// | ||
// PROTECTED | ||
// | ||
uint16_t I2CKeyPad8x8::_read(uint16_t mask) | ||
{ | ||
// improve the odds that IO will not interrupted. | ||
yield(); | ||
|
||
_wire->beginTransmission(_address); | ||
_wire->write(mask >> 8); | ||
_wire->write(mask & 0xFF); | ||
if (_wire->endTransmission() != 0) | ||
{ | ||
// set communication error | ||
return 0xFFFF; | ||
} | ||
_wire->requestFrom(_address, (uint8_t)2); | ||
uint16_t value = _wire->read() << 8; | ||
value += _wire->read(); | ||
return value; | ||
} | ||
|
||
|
||
// -- END OF FILE -- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#pragma once | ||
// | ||
// FILE: I2CKeyPad8x8.h | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.1.0 | ||
// PURPOSE: Arduino library for 8x8 or smaller KeyPad connected to an I2C PCF8575. | ||
// URL: https://github.com/RobTillaart/I2CKeyPad | ||
|
||
|
||
#include "Arduino.h" | ||
#include "Wire.h" | ||
|
||
|
||
#define I2C_KEYPAD8x8_LIB_VERSION (F("0.1.0")) | ||
|
||
#define I2C_KEYPAD8x8_NOKEY 64 | ||
#define I2C_KEYPAD8x8_FAIL 65 | ||
|
||
|
||
class I2CKeyPad8x8 | ||
{ | ||
public: | ||
I2CKeyPad8x8(const uint8_t deviceAddress, TwoWire *wire = &Wire); | ||
|
||
#if defined(ESP8266) || defined(ESP32) | ||
bool begin(uint8_t sda, uint8_t scl); | ||
#endif | ||
bool begin(); | ||
|
||
// get raw key's 0..65 | ||
uint8_t getKey(); | ||
uint8_t getLastKey(); | ||
|
||
bool isPressed(); | ||
bool isConnected(); | ||
|
||
// get 'translated' keys | ||
// user must load KeyMap, there is no check. | ||
uint8_t getChar(); | ||
uint8_t getLastChar(); | ||
void loadKeyMap(char * keyMap); // char[65] | ||
|
||
|
||
protected: | ||
uint8_t _address; | ||
uint8_t _lastKey; | ||
uint16_t _read(uint16_t mask); | ||
|
||
TwoWire* _wire; | ||
|
||
char * _keyMap = NULL; | ||
}; | ||
|
||
|
||
// -- END OF FILE -- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2022 Rob Tillaart | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
Oops, something went wrong.