-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from lovyan03/unstable
stable
- Loading branch information
Showing
9 changed files
with
166 additions
and
17 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
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
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
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=M5Stack_OnScreenKeyboard | ||
version=0.3.2 | ||
version=0.3.4 | ||
author=lovyan03 | ||
maintainer=Lovyan <[email protected]> | ||
sentence=OnScreenKeyboard for M5Stack | ||
|
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,43 @@ | ||
#include <M5FACESEncoder.h> | ||
|
||
M5FACESEncoder FACESEncoder; | ||
|
||
bool M5FACESEncoder::update() | ||
{ | ||
if (!Wire.requestFrom(_addr, 2)) return false; | ||
_time = millis(); | ||
_oldUpDown = _upDown; | ||
_oldPress = _press; | ||
bool press = false; | ||
while (Wire.available()){ | ||
_raw = Wire.read(); | ||
_rawsum += _raw; | ||
press = (Wire.read() == 0); | ||
} | ||
_upDown = _rawsum; | ||
if (_upDown != 0) _rawsum = 0; | ||
|
||
if (press != (0 != _oldPress)) _lastChange = _time; | ||
if (press) { | ||
if (!_oldPress) { | ||
_press = 1; | ||
} else | ||
if (1 == _oldPress && (_time - _lastChange >= msecHold)) { | ||
_press = 2; | ||
} | ||
} else { | ||
_press = 0; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
void M5FACESEncoder::led(int led_index, int r, int g, int b) | ||
{ | ||
Wire.beginTransmission(_addr); | ||
Wire.write(led_index); | ||
Wire.write(r); | ||
Wire.write(g); | ||
Wire.write(b); | ||
Wire.endTransmission(); | ||
} |
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,48 @@ | ||
#ifndef _M5FACESENCODER_H_ | ||
#define _M5FACESENCODER_H_ | ||
|
||
#include <M5Stack.h> | ||
|
||
class M5FACESEncoder | ||
{ | ||
public: | ||
uint16_t msecHold = 300; | ||
|
||
void setAddr(int8_t addr) { _addr = addr; } | ||
|
||
bool update(); | ||
|
||
int8_t rawValue() const { return _raw; } | ||
bool wasUp() const { return _upDown > 0; } | ||
bool wasDown() const { return _upDown < 0; } | ||
|
||
bool wasClicked() const { return _oldPress == 1 && _press == 0; } | ||
bool wasHold() const { return _oldPress == 1 && _press == 2; } | ||
bool isHolding() const { return _oldPress == 2 && _press == 2; } | ||
|
||
bool isPressed() const { return _press; } | ||
bool isReleased() const { return !_press; } | ||
bool wasPressed() const { return !_oldPress && _press; } | ||
bool wasReleased() const { return _oldPress && !_press; } | ||
bool pressedFor(uint32_t ms) const { return (_press && _time - _lastChange >= ms); } | ||
bool releasedFor(uint32_t ms) const { return (!_press && _time - _lastChange >= ms); } | ||
|
||
void led(int led_index, int r, int g, int b); | ||
|
||
private: | ||
int8_t _ledpos = 0; | ||
int8_t _addr = 0x5E; | ||
int8_t _raw = 0; | ||
int8_t _rawsum = 0; | ||
int8_t _upDown = 0; | ||
int8_t _oldUpDown = 0; | ||
uint8_t _press = 0; // 0:release 1:click 2:holding | ||
uint8_t _oldPress = 0; | ||
uint32_t _time = 0; | ||
uint32_t _lastChange = 0; | ||
}; | ||
|
||
#endif | ||
|
||
extern M5FACESEncoder FACESEncoder; | ||
|
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
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