M5Unit-KEYBOARD 0.0.1 git rev:a483db1
Loading...
Searching...
No Matches
m5::unit::UnitKeyboardBitwise Class Reference

Class supporting keyboard state acquisition by key press bits. More...

#include <unit_Keyboard.hpp>

Inheritance diagram for m5::unit::UnitKeyboardBitwise:
m5::unit::UnitKeyboard m5::unit::UnitCardKB m5::unit::UnitCardKB2UART m5::unit::UnitFacesQWERTY

Public Member Functions

 UnitKeyboardBitwise (const uint8_t addr=DEFAULT_ADDRESS)
 
virtual void update (const bool force=false) override
 
Measurement data by periodic
virtual char getchar () const override
 Gets the input character.
 
uint8_t pressed () const
 Get the oldest pressed key.
 
virtual uint8_t released () const override
 Get the oldest released key.
 
Periodic measurement
bool startPeriodicMeasurement (const uint32_t interval)
 Start periodic measurement.
 
bool startPeriodicMeasurement ()
 Start periodic measurement using current settings.
 
bool stopPeriodicMeasurement ()
 Stop periodic measurement.
 
Key status bits if updated
Warning
API valid only if using M5Unit-KEYBOARD firmware
Note
Which bits represent what depends on the target unit
keyboard::key_status_bits_t nowBits () const
 Get the bits of the key being pressed.
 
keyboard::key_status_bits_t previousBits () const
 Get the bits of the previous key pressed.
 
keyboard::key_status_bits_t pressedBits () const
 Get the key bits at the moment they are pressed.
 
keyboard::key_status_bits_t releasedBits () const
 Get the key bits at the moment they are released.
 
keyboard::key_status_bits_t holdingBits () const
 Get the bits of the held key.
 
keyboard::key_status_bits_t wasHoldBits () const
 Get the bits of the key at the moment of hold.
 
keyboard::key_status_bits_t repeatingBits () const
 Get the bits of the key that the software is repeatedly pressing.
 
keyboard::key_status_bits_t modifierBits () const
 Get the bits of the modifier key being pressed.
 
Modifier
Warning
API valid only if using M5Unit-KEYBOARD firmware
Note
Some keys do not exist depending on the target Unit
bool isModifier () const
 Is any modifier keys pressed?
 
bool isShift () const
 Is the shift key pressed?
 
bool isSymbol () const
 Is the symbol key pressed?
 
bool isFunction () const
 Is the function key pressed?
 
bool isAlt () const
 Is the alt key pressed?
 
bool isControl () const
 Is the control key pressed?
 
bool isOption () const
 Is the option key pressed?
 
bool isShiftEqual () const
 Is only shift pressed among the modifier keys?
 
bool isSymbolEqual () const
 Is only symbol pressed among the modifier keys?
 
bool isFunctionEqual () const
 Is only function pressed among the modifier keys?
 
bool isAltEqual () const
 Is only alt pressed among the modifier keys?
 
bool isControlEqual () const
 Is only control pressed among the modifier keys?
 
bool isOptionEqual () const
 Is only option pressed among the modifier keys?
 
Any key
Warning
API valid only if using M5Unit-KEYBOARD firmware
bool isPressed () const
 Is any key press?
 
bool isReleased () const
 Is all key release?
 
bool wasPressed () const
 Was any key pressed?
 
bool wasReleased () const
 Was any key released?
 
bool isHolding () const
 Is any key holding?
 
bool wasHold () const
 Was any key hold?
 
bool isRepeating () const
 Is any key repeating?
 
Specified key (Key index)
Warning
API valid only if using M5Unit-KEYBOARD firmware
bool isPressed (const keyboard::key_index_t kidx) const
 Is the specified key pressed?
 
bool isReleased (const keyboard::key_index_t kidx) const
 Is the specified key released?
 
bool wasPressed (const keyboard::key_index_t kidx) const
 Was the specified key pressed?
 
bool wasReleased (const keyboard::key_index_t kidx) const
 Was the specified key released?
 
bool isHolding (const keyboard::key_index_t kidx) const
 Is the specified key holding?
 
bool wasHold (const keyboard::key_index_t kidx) const
 Was the specified key hold?
 
bool isRepeating (const keyboard::key_index_t kidx) const
 Is the specified key repeating?
 
Specified Character
Warning
API valid only if using M5Unit-KEYBOARD firmware. For CardKB2 UART mode, character-based state queries (isPressed(ch), wasPressed(ch), etc.) may return inaccurate results because press and release events can arrive in the same update cycle, causing the key state to be cleared before the buffered character is read. Use key-index-based queries (isPressed(kidx)) instead. This limitation may be improved in a future firmware update.
virtual keyboard::key_index_t toKeyIndex (const char) const
 Obtains the key index corresponding to the specified character.
 
bool isPressed (const char ch) const
 Is the specified character pressed?
 
bool isReleased (const char ch) const
 Is the specified character released?
 
bool wasPressed (const char ch) const
 Was the specified character pressed?
 
bool wasReleased (const char ch) const
 Was the specified character released?
 
bool isHolding (const char ch) const
 Is the specified character holding?
 
bool wasHold (const char ch) const
 Was the specified character hold?
 
bool isRepeating (const char ch) const
 Is the specified character repeating?
 
Firmware
Warning
API valid only if using M5Unit-KEYBOARD firmware
uint8_t firmwareVersion () const
 Gets the firmware version.
 
virtual bool readFirmwareVersion (uint8_t &ver)
 Read the firmware version.
 
Repeat/Hold threshold
Warning
API valid only if using M5Unit-KEYBOARD firmware
uint32_t holdingThreshold () const
 Gets the holding threshold (ms)
 
uint32_t repeatingThreshold () const
 Gets the repeating threshold (ms)
 
void setHoldingThreshold (const uint32_t ms)
 Sets the holding threshold.
 
void setRepeatingThreshold (const uint32_t ms)
 Sets the repeating threshold.
 
Mode
Warning
API valid only if using M5Unit-KEYBOARD firmware (CardKB, FacesQWERTY). CardKB2 does not support software mode switching; readMode()/writeMode() always return false.
virtual bool readMode (keyboard::Mode &mode)
 Read the mode.
 
virtual bool writeMode (const keyboard::Mode mode)
 Write the mode.
 
- Public Member Functions inherited from m5::unit::UnitKeyboard
 UnitKeyboard (const uint8_t addr=DEFAULT_ADDRESS)
 
virtual bool begin () override
 

Protected Member Functions

bool start_periodic_measurement ()
 
bool start_periodic_measurement (const uint32_t interval)
 
bool stop_periodic_measurement ()
 
bool update_new_firmware (const types::elapsed_time_t at)
 
void push_back (m5::container::CircularBuffer< uint8_t > *container, const uint8_t kidx, const uint8_t alt)
 
keyboard::key_status_bits_t modifier_bits () const
 
virtual uint8_t to_mode_bits (const char) const
 
virtual uint8_t scan_reg_addr () const
 
virtual uint8_t mode_reg_addr () const
 
virtual uint8_t firmware_version_reg_addr () const
 
bool permitted_mode (const uint8_t mbits) const
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitKeyboardBitwise, uint8_t)
 

Protected Attributes

std::unique_ptr< m5::container::CircularBuffer< uint8_t > > _data {}
 
keyboard::key_status_bits_t _now {}
 
keyboard::key_status_bits_t _prev {}
 
keyboard::key_status_bits_t _wasPressed {}
 
keyboard::key_status_bits_t _wasReleased {}
 
keyboard::key_status_bits_t _wasHold {}
 
keyboard::key_status_bits_t _holding {}
 
keyboard::key_status_bits_t _repeating {}
 
std::vector< types::elapsed_time_t > _repeat_start_at {}
 
std::vector< types::elapsed_time_t > _hold_start_at {}
 
uint32_t _repeating_threshold {400}
 
uint32_t _holding_threshold {800}
 
uint8_t _firmware_version {}
 
keyboard::Mode _mode {keyboard::Mode::Conventional}
 

Detailed Description

Class supporting keyboard state acquisition by key press bits.

Warning
To make it work, M5Unit-KEYBOARD firmware must be written to the target (CardKB, FacesQWERTY...)

Member Function Documentation

◆ firmwareVersion()

uint8_t m5::unit::UnitKeyboardBitwise::firmwareVersion ( ) const
inline

Gets the firmware version.

Return values
==0 Conventional firmware
!=0 M5UnitUnified firmware version
Warning
Valid after begin

◆ getchar()

virtual char m5::unit::UnitKeyboardBitwise::getchar ( ) const
inlineoverridevirtual

Gets the input character.

Return values
!=0 Character
==0 Not input or invalid character

Reimplemented from m5::unit::UnitKeyboard.

◆ isHolding() [1/2]

bool m5::unit::UnitKeyboardBitwise::isHolding ( const char ch) const
inline

Is the specified character holding?

Parameters
chCharacter
Returns
If so,true

◆ isHolding() [2/2]

bool m5::unit::UnitKeyboardBitwise::isHolding ( const keyboard::key_index_t kidx) const
inline

Is the specified key holding?

Parameters
kidxKey index code
Returns
If so,true

◆ isPressed() [1/2]

bool m5::unit::UnitKeyboardBitwise::isPressed ( const char ch) const
inline

Is the specified character pressed?

Parameters
chCharacter
Returns
If so,true

◆ isPressed() [2/2]

bool m5::unit::UnitKeyboardBitwise::isPressed ( const keyboard::key_index_t kidx) const
inline

Is the specified key pressed?

Parameters
kidxKey index code
Returns
If so,true

◆ isReleased() [1/2]

bool m5::unit::UnitKeyboardBitwise::isReleased ( const char ch) const
inline

Is the specified character released?

Parameters
chCharacter
Returns
If so,true

◆ isReleased() [2/2]

bool m5::unit::UnitKeyboardBitwise::isReleased ( const keyboard::key_index_t kidx) const
inline

Is the specified key released?

Parameters
kidxKey index code
Returns
If so,true

◆ isRepeating() [1/2]

bool m5::unit::UnitKeyboardBitwise::isRepeating ( const char ch) const
inline

Is the specified character repeating?

Parameters
chCharacter
Returns
If so,true

◆ isRepeating() [2/2]

bool m5::unit::UnitKeyboardBitwise::isRepeating ( const keyboard::key_index_t kidx) const
inline

Is the specified key repeating?

Parameters
kidxKey index code
Returns
If so,true

◆ pressed()

uint8_t m5::unit::UnitKeyboardBitwise::pressed ( ) const
inline

Get the oldest pressed key.

Warning
API valid only if using M5Unit-KEYBOARD firmware

◆ readFirmwareVersion()

bool m5::unit::UnitKeyboardBitwise::readFirmwareVersion ( uint8_t & ver)
virtual

Read the firmware version.

Parameters
[out]verVersion high nibble:Major, low nibble:Minor
Returns
True if successful

Reimplemented in m5::unit::UnitCardKB2UART.

◆ readMode()

bool m5::unit::UnitKeyboardBitwise::readMode ( keyboard::Mode & mode)
virtual

Read the mode.

Parameters
[out]modeMode
Returns
True if successful

Reimplemented in m5::unit::UnitCardKB2UART.

◆ released()

virtual uint8_t m5::unit::UnitKeyboardBitwise::released ( ) const
inlineoverridevirtual

Get the oldest released key.

Warning
Disabled in all modes except Conventional mode

Reimplemented from m5::unit::UnitKeyboard.

Reimplemented in m5::unit::UnitFacesQWERTY.

◆ setHoldingThreshold()

void m5::unit::UnitKeyboardBitwise::setHoldingThreshold ( const uint32_t ms)
inline

Sets the holding threshold.

Parameters
msThreshold in milliseconds

◆ setRepeatingThreshold()

void m5::unit::UnitKeyboardBitwise::setRepeatingThreshold ( const uint32_t ms)
inline

Sets the repeating threshold.

Parameters
msThreshold in milliseconds

◆ startPeriodicMeasurement()

bool m5::unit::UnitKeyboardBitwise::startPeriodicMeasurement ( const uint32_t interval)
inline

Start periodic measurement.

Parameters
intervalUpdate interval time(ms)
Returns
True if successful
Warning
If config_t::trigger_irq is set to true, arguments is ignored

◆ stopPeriodicMeasurement()

bool m5::unit::UnitKeyboardBitwise::stopPeriodicMeasurement ( )
inline

Stop periodic measurement.

Returns
True if successful

◆ toKeyIndex()

virtual keyboard::key_index_t m5::unit::UnitKeyboardBitwise::toKeyIndex ( const char ) const
inlinevirtual

Obtains the key index corresponding to the specified character.

Return values
!=0xFF key index
==0xFF No corresponding key index

Reimplemented in m5::unit::UnitCardKB2UART, m5::unit::UnitCardKB, and m5::unit::UnitFacesQWERTY.

◆ update()

void m5::unit::UnitKeyboardBitwise::update ( const bool force = false)
overridevirtual

◆ wasHold() [1/2]

bool m5::unit::UnitKeyboardBitwise::wasHold ( const char ch) const
inline

Was the specified character hold?

Parameters
chCharacter
Returns
If so,true

◆ wasHold() [2/2]

bool m5::unit::UnitKeyboardBitwise::wasHold ( const keyboard::key_index_t kidx) const
inline

Was the specified key hold?

Parameters
kidxKey index code
Returns
If so,true

◆ wasPressed() [1/2]

bool m5::unit::UnitKeyboardBitwise::wasPressed ( const char ch) const
inline

Was the specified character pressed?

Parameters
chCharacter
Returns
If so,true

◆ wasPressed() [2/2]

bool m5::unit::UnitKeyboardBitwise::wasPressed ( const keyboard::key_index_t kidx) const
inline

Was the specified key pressed?

Parameters
kidxKey index code
Returns
If so,true

◆ wasReleased() [1/2]

bool m5::unit::UnitKeyboardBitwise::wasReleased ( const char ch) const
inline

Was the specified character released?

Parameters
chCharacter
Returns
If so,true

◆ wasReleased() [2/2]

bool m5::unit::UnitKeyboardBitwise::wasReleased ( const keyboard::key_index_t kidx) const
inline

Was the specified key released?

Parameters
kidxKey index code
Returns
If so,true

◆ writeMode()

bool m5::unit::UnitKeyboardBitwise::writeMode ( const keyboard::Mode mode)
virtual

Write the mode.

Parameters
modeMode
Returns
True if successful

Reimplemented in m5::unit::UnitCardKB2UART.