CHGame 0.3.0
Libraries for the CHGame handheld
Loading...
Searching...
No Matches
CHGame Class Reference

The board's buttons and frame clock. There is one, chgame. More...

#include <chgame/Input.h>

Public Member Functions

void boot ()
 Set up the button pins (inputs with pull-ups) and take a first reading.
 
void setFrameRate (uint8_t fps)
 Set the frame rate nextFrame() paces to.
 
bool nextFrame ()
 Whether it is time for the next frame.
 
void pollButtons ()
 Take this frame's snapshot of the buttons.
 
uint8_t buttons () const
 The buttons held in this frame's snapshot.
 
bool pressed (uint8_t b) const
 Whether all the buttons in a mask are held.
 
bool anyPressed (uint8_t b) const
 Whether any of the buttons in a mask is held.
 
bool justPressed (uint8_t b) const
 Whether a button went down this frame.
 
bool justReleased (uint8_t b) const
 Whether a button was let go this frame.
 
uint8_t justPressedMask () const
 Every button that went down this frame.
 
bool repeat (uint8_t b, uint8_t delay=18, uint8_t rate=5) const
 Press edge, then auto-repeat while held: for menus and adjusting a bet.
 
void clearButtonState ()
 Forget this frame's presses: justPressed() and justReleased() are false until the buttons change again.
 
bool everyXFrames (uint16_t n) const
 Whether frameCount is a multiple of n: something to do every n frames.
 
void exitToMenu ()
 Leave the game for the SD game menu.
 

Public Attributes

uint32_t frameCount = 0
 Frames since boot, counted by nextFrame().
 
uint8_t injected = 0
 Buttons ORed into the physical ones (the debug protocol's K).
 
bool startExits = true
 START held 3 s calls exitToMenu(); a game that needs a long START hold clears it in setup().
 
int32_t lockstep = -1
 Lockstep: < 0 free-running, else the frames nextFrame() may still run (set by the debug protocol's L and N).
 

Detailed Description

The board's buttons and frame clock. There is one, chgame.

Member Function Documentation

◆ boot()

void CHGame::boot ( )

Set up the button pins (inputs with pull-ups) and take a first reading.

Call once at the top of setup(). A button held at boot does not count as a press on the first frame.

◆ setFrameRate()

void CHGame::setFrameRate ( uint8_t  fps)

Set the frame rate nextFrame() paces to.

Parameters
fpsFrames per second (1-255). The default is 60.

◆ nextFrame()

bool CHGame::nextFrame ( )

Whether it is time for the next frame.

Returns
true once per frame period (and counts the frame in frameCount); false otherwise, so loop() returns at once.

A game that falls more than three frames behind (a debug pause, a save) starts afresh instead of sprinting to catch up. In lockstep (the debug protocol's L1) it returns true only for the frames the tool asked for.

◆ pollButtons()

void CHGame::pollButtons ( )

Take this frame's snapshot of the buttons.

Call once per frame, after nextFrame(). Every query below reads this snapshot, so a frame sees one consistent state. It ORs in injected (the debug protocol's K), counts how long each button has been held (for repeat()), and calls exitToMenu() when START has been held 3 s and startExits is set.

◆ buttons()

uint8_t CHGame::buttons ( ) const
inline

The buttons held in this frame's snapshot.

Returns
A mask of A_BUTTON ... SELECT_BUTTON.

◆ pressed()

bool CHGame::pressed ( uint8_t  b) const
inline

Whether all the buttons in a mask are held.

Parameters
bOne button or several ORed together.
Returns
true if every one of them is held.

◆ anyPressed()

bool CHGame::anyPressed ( uint8_t  b) const
inline

Whether any of the buttons in a mask is held.

Parameters
bOne button or several ORed together.
Returns
true if at least one of them is held.

◆ justPressed()

bool CHGame::justPressed ( uint8_t  b) const
inline

Whether a button went down this frame.

Parameters
bOne button or several ORed together.
Returns
true if any of them is held now and was not in the previous frame.

◆ justReleased()

bool CHGame::justReleased ( uint8_t  b) const
inline

Whether a button was let go this frame.

Parameters
bOne button or several ORed together.
Returns
true if any of them was held in the previous frame and is not now.

◆ justPressedMask()

uint8_t CHGame::justPressedMask ( ) const
inline

Every button that went down this frame.

Returns
A mask of the buttons pressed now and not in the previous frame.

◆ repeat()

bool CHGame::repeat ( uint8_t  b,
uint8_t  delay = 18,
uint8_t  rate = 5 
) const

Press edge, then auto-repeat while held: for menus and adjusting a bet.

Parameters
bOne button or several ORed together.
delayFrames held before the repeat starts (default 18, 0.3 s at 60 fps).
rateFrames between repeats after that (default 5).
Returns
true on the frame a button went down, then every rate frames once it has been held longer than delay.

◆ clearButtonState()

void CHGame::clearButtonState ( )
inline

Forget this frame's presses: justPressed() and justReleased() are false until the buttons change again.

Use it when a screen changes, so the press that changed it does not also act on the new one.

◆ everyXFrames()

bool CHGame::everyXFrames ( uint16_t  n) const
inline

Whether frameCount is a multiple of n: something to do every n frames.

Parameters
nThe period in frames (not 0).
Returns
true on every nth frame.

◆ exitToMenu()

void CHGame::exitToMenu ( )
inline

Leave the game for the SD game menu.

Never returns.

See also
chgame_exitToMenu()

Member Data Documentation

◆ frameCount

uint32_t CHGame::frameCount = 0

Frames since boot, counted by nextFrame().

◆ injected

uint8_t CHGame::injected = 0

Buttons ORed into the physical ones (the debug protocol's K).

◆ startExits

bool CHGame::startExits = true

START held 3 s calls exitToMenu(); a game that needs a long START hold clears it in setup().

◆ lockstep

int32_t CHGame::lockstep = -1

Lockstep: < 0 free-running, else the frames nextFrame() may still run (set by the debug protocol's L and N).


The documentation for this class was generated from the following file: