Touch Class
begin
Syntax:
void begin(m5gfx::LGFX_Device* gfx);
Description:
- Initialize the Touch instance.
Parameters:
- m5gfx::LGFX_Device* gfx:
- Pointer to the screen device instance.
Return:
- bool:
- true: Initialization successful.
- false: Initialization failed.
update
Syntax:
void update(std::uint32_t msec);
Description:
Parameters:
Return:
isEnabled
Syntax:
bool isEnabled(void);
Description:
- Check if Touch is initialized.
Parameters:
Return:
- bool:
- true: Touch has been initialized.
- false: Touch is not initialized.
end
Syntax:
void end(void);
Description:
- Set the Touch screen device instance pointer to null, reverse initialization.
Parameters:
Return:
getCount
Syntax:
std::uint8_t getCount(void);
Description:
- Get the number of current screen touch points.
Parameters:
Return:
- uint8_t points:
- The number of screen touch points.
getDetail
Syntax:
const touch_detail_t& getDetail(std::size_t index = 0);
Description:
- Get detailed information about the touch point.
Parameters:
- size_t index:
- The index of the touch point to retrieve.
Return:
- touch_detail_t detail:
- Detailed information about the screen touch point, including coordinates, offsets, touch point events, etc. For details, refer to the
Touch Detail
section.
getTouchPointRaw
Syntax:
inline const m5gfx::touch_point_t& getTouchPointRaw(std::size_t index = 0) const { return _touch_raw[index < _detail_count ? index : 0]; }
Description:
- Get the raw information of the touch point.
Parameters:
- size_t index:
- The index of the touch point to retrieve.
Return:
- touch_point_t point:
- Raw information of the screen touch point, including coordinates and ID.
setHoldThresh
Syntax:
void setHoldThresh(std::uint16_t msec) { _msecHold = msec; }
Description:
- Set the touch hold trigger time threshold.
Parameters:
- uint16_t msec:
- Hold trigger threshold in milliseconds.
Return:
setFlickThresh
Syntax:
void setFlickThresh(std::uint16_t distance) { _flickThresh = distance; }
Description:
- Set the touch flick threshold.
Parameters:
- uint16_t distance:
- Touch offset flick threshold.
Return:
Touch Detail
Syntax:
struct touch_detail_t : public m5gfx::touch_point_t
{
};
deltaX
Syntax:
inline int deltaX(void) const { return x - prev_x; }
Description:
- Get the offset of the touch point's X coordinate relative to the last sampling.
Parameters:
Return:
- int deltaX:
- The offset of the touch point's X coordinate relative to the last sampling.
deltaY
Syntax:
inline int deltaY(void) const { return y - prev_y; }
Description:
- Get the offset of the touch point's Y coordinate relative to the last sampling.
Parameters:
Return:
- int deltaY:
- The offset of the touch point's Y coordinate relative to the last sampling.
distanceX
Syntax:
inline int distanceX(void) const { return x - base_x; }
Description:
- Get the offset of the touch point's X coordinate relative to the touch start sampling.
Parameters:
Return:
- int distanceX:
- The offset of the touch point's X coordinate relative to the touch start sampling.
distanceY
Syntax:
inline int distanceY(void) const { return y - base_y; }
Description:
- Get the offset of the touch point's Y coordinate relative to the touch start sampling.
Parameters:
Return:
- int distanceY:
- The offset of the touch point's Y coordinate relative to the touch start sampling.
isPressed
Syntax:
inline bool isPressed(void) const { return state & touch_state_t::mask_touch; };
Description:
- Determine if the touch point is pressed.
Parameters:
Return:
- bool:
- true: The touch point is in a pressed state.
- false: The touch point is not in a pressed state.
wasPressed
Syntax:
inline bool wasPressed(void) const { return state == touch_state_t::touch_begin; };
Description:
- Determine if the touch point has changed from a released state to a pressed state.
Parameters:
Return:
- bool:
- true: The touch point has changed from a released state to a pressed state.
- false: The touch point has not changed from a released state to a pressed state.
wasClicked
Syntax:
inline bool wasClicked(void) const { return state == touch_state_t::touch_end; };
Description:
- Determine if the touch point has been clicked.
Parameters:
Return:
- bool:
- true: The touch point has been clicked.
- false: The touch point has not been clicked.
isReleased
Syntax:
inline bool isReleased(void) const { return !(state & touch_state_t::mask_touch); };
Description:
- Determine if the touch point is in a released state.
Parameters:
Return:
- bool:
- true: The touch point is in a released state.
- false: The touch point is not in a released state.
wasReleased
Syntax:
inline bool wasReleased(void) const { return (state & (touch_state_t::mask_touch | touch_state_t::mask_change)) == touch_state_t::mask_change; };
Description:
- Determine if the touch point has changed from a pressed state to a released state.
Parameters:
Return:
- bool:
- true: The touch point has changed from a pressed state to a released state.
- false: The touch point has not changed from a pressed state to a released state.
isHolding
Syntax:
inline bool isHolding(void) const { return (state & (touch_state_t::mask_touch | touch_state_t::mask_holding)) == (touch_state_t::mask_touch | touch_state_t::mask_holding); }
Description:
- Determine if the touch point is currently being held down.
Parameters:
Return:
- bool:
- true: The touch point is currently being held down.
- false: The touch point is not currently being held down.
wasHold
Syntax:
inline bool wasHold(void) const { return state == touch_state_t::hold_begin; }
Description:
- Determine if the touch point has been held down, with a default threshold time of 500ms.
Parameters:
Return:
- bool:
- true: The touch point has been held down.
- false: The touch point has not been held down.
wasFlickStart
Syntax:
inline bool wasFlickStart(void) const { return state == touch_state_t::flick_begin; }
Description:
- Determine if the touch flick action has started.
Parameters:
Return:
- bool:
- true: The touch flick action has started.
- false: The touch flick action has not started.
isFlicking
Syntax:
inline bool isFlicking(void) const { return (state & touch_state_t::drag) == touch_state_t::flick; }
Description:
- Determine if the touch flick action is in progress.
Parameters:
Return:
- bool:
- true: The touch flick action is in progress.
- false: The touch flick action is not in progress.
wasFlicked
Syntax:
inline bool wasFlicked(void) const { return state == touch_state_t::flick_end; }
Description:
- Determine if the touch flick action has ended.
Parameters:
Return:
- bool:
- true: The touch flick action has ended.
- false: The touch flick action has not ended.
wasDragStart
Syntax:
inline bool wasDragStart(void) const { return state == touch_state_t::drag_begin; }
Description:
- Determine if the touch drag action has started, triggered after holding and moving.
Parameters:
Return:
- bool:
- true: The touch drag action has started.
- false: The touch drag action has not started.
isDragging
Syntax:
inline bool isDragging(void) const { return (state & touch_state_t::drag) == touch_state_t::drag; }
Description:
- Determine if the touch drag action is in progress.
Parameters:
Return:
- bool:
- true: The touch drag action is in progress.
- false: The touch drag action is not in progress.
wasDragged
Syntax:
inline bool wasDragged(void) const { return state == touch_state_t::drag_end; }
Description:
- Determine if the touch drag action has ended.
Parameters:
Return:
- bool:
- true: The touch drag action has ended.
- false: The touch drag action has not ended.
getClickCount
Syntax:
inline std::uint8_t getClickCount(void) const { return click_count; }
Description:
- Get the number of consecutive touch clicks.
Parameters:
Return:
- uint8_t count:
- The number of consecutive touch clicks.