* Snake! * Add spiLock to snake score saving * Check fixes * More careful locking * WIP: Big Display Node * Update src/graphics/HUB75Display.cpp Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * Add HUB75 Native * Add Tetris game module with core logic and UI integration - Implement TetrisGame class for game logic, including piece movement, rotation, and line clearing. - Create TetrisModule class to manage game state, input handling, and rendering on OLED display. - Introduce high score tracking with persistence and optional mesh broadcasting. - Define UI states for title, playing, paused, game over, and high scores. - Implement input handling for game controls and state transitions. - Add rendering functions for the game board, high scores, and title screen. * feat(snake): add snake graphics and update display logic in SnakeModule * Prompt for Initials for Tetris, too * refactor games module * Games refactor * hub75 native double buffer * Games tuning * Make joystick repeat events on held button * Add clouds and colors * Fix breakout and more color * difficulty tuning * trunk * refactor game announcements, etc * Scale chirpy gravity as game speed increases * Portduino, check for hub75 display before reading in hub75 options * Final(?) games tuning * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Properly ignore input when games screen not shown * Fail gracefully when HUB75 is selected but not supported. --------- Co-authored-by: Thomas Göttgens <tgoettgens@gmail.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Ixitxachitl <kramerfm@gmail.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
66 lines
2.4 KiB
C++
66 lines
2.4 KiB
C++
#pragma once
|
|
// Linux evdev gamepad/joystick input. Only compiled on Linux portduino targets;
|
|
// macOS / non-Linux builds have no <linux/input.h> or epoll. Unlike LinuxInput
|
|
// (keyboard, EV_KEY only) this decodes the D-pad from EV_ABS axes as well.
|
|
#if ARCH_PORTDUINO && defined(__linux__)
|
|
#include "InputBroker.h"
|
|
#include "concurrency/OSThread.h"
|
|
#include <linux/input.h>
|
|
#include <map>
|
|
#include <stdint.h>
|
|
#include <sys/epoll.h>
|
|
|
|
#define JOY_MAX_EVENTS 10
|
|
|
|
// Default button map when config.yaml has no [Input] JoystickButtons override.
|
|
// Codes confirmed by evdev capture on a 0079:0011 "USB Gamepad".
|
|
#define JOY_BTN_A BTN_THUMB // 0x121 -> INPUT_BROKER_SELECT
|
|
#define JOY_BTN_B BTN_THUMB2 // 0x122 -> INPUT_BROKER_CANCEL
|
|
#define JOY_AXIS_CENTER 127 // D-pad resting value
|
|
#define JOY_AXIS_LOW 64 // below this -> "min" edge (0)
|
|
#define JOY_AXIS_HIGH 192 // above this -> "max" edge (255)
|
|
|
|
// D-pad auto-repeat while a direction is held (typematic).
|
|
#define JOY_REPEAT_DELAY_MS 400 // hold this long before repeats start
|
|
#define JOY_REPEAT_INTERVAL_MS 150 // then repeat this often
|
|
|
|
class LinuxJoystick : public Observable<const InputEvent *>, public concurrency::OSThread
|
|
{
|
|
public:
|
|
explicit LinuxJoystick(const char *name);
|
|
void init(); // Registers this source with the InputBroker
|
|
void deInit(); // Strictly for cleanly "rebooting" the binary on native
|
|
|
|
// Current held D-pad zone, updated the instant the axis moves (independent of the typematic
|
|
// auto-repeat). -1 = left/up edge, 0 = centered, +1 = right/down edge. Lets a game poll for
|
|
// smooth continuous control instead of waiting for the slow repeat events.
|
|
int heldXZone() const { return heldX; }
|
|
int heldYZone() const { return heldY; }
|
|
|
|
protected:
|
|
virtual int32_t runOnce() override;
|
|
|
|
private:
|
|
void emitEvent(input_broker_event event);
|
|
|
|
const char *_originName;
|
|
bool firstTime = true;
|
|
|
|
// evdev button code -> broker event, built from config (or defaults) in init().
|
|
std::map<int, input_broker_event> buttonMap;
|
|
|
|
struct epoll_event events[JOY_MAX_EVENTS];
|
|
struct epoll_event ev;
|
|
int fd = -1;
|
|
int epollfd = -1;
|
|
|
|
// D-pad auto-repeat state: currently held zone per axis (-1 / 0 / +1) and the
|
|
// next millis() timestamp at which to re-emit while the direction is held.
|
|
int heldX = 0;
|
|
int heldY = 0;
|
|
uint32_t nextRepeatX = 0;
|
|
uint32_t nextRepeatY = 0;
|
|
};
|
|
extern LinuxJoystick *aLinuxJoystick;
|
|
#endif
|