Files
2023-10-12 19:50:10 +02:00

81 lines
1.7 KiB
C++

/**
* @file controlPad.h
* @author Alexander Klein (alex@kleiax.de)
* @brief Contains a class that gets the input data
* @version 0.1
* @date 2023-03-30
*
* @copyright Copyright (c) 2023
*
*/
#pragma once
#include <menuControl.h>
#include <controlPadInput.h>
#include <component.h>
/**
* @brief A class to manage inputs
*
* This class converts the incoming data to the buttons and
* the axis from the joystick. The converted data will be send
* to the menu.
*/
class ControlPad : public Component
{
public:
ControlPad();
/**
* @brief Insert the incoming data to convert
*
* The data is converted to the ControlPadInput struct.
*
* @param data have to be 4 byte long
*/
void insertData(const uint8_t *data);
/**
* @brief Set the MenuControl object
*
* The MenuControl object is used to control the Menu.
*
* @see Menu
* @see ControlPadInput
*
* @param menuControl
*/
void setMenuControl(MenuControl *menuControl) { this->menuControl = menuControl; }
/**
* @brief Get the Control Pad Data
*
* The pointer holds the lates data from the ControlPad
*
* @return const ControlPadInput*
*/
const ControlPadInput *getControlPadDataPtr() const { return &this->controlInput; }
bool isControlPadConnected() const { return this->connected; }
private:
void run() override;
MenuControl *menuControl = nullptr;
ControlPadInput controlInput;
bool connected = false;
bool updated = false;
bool firstButtonPress = true;
uint8_t deadZoneX = 20;
uint8_t deadZoneY = 20;
uint8_t lastButtons = 0;
uint16_t disconnectTime = 100;
uint32_t lastMessageReceive = 0;
};