MissionControl/mc_mitm/source/controllers/emulated_switch_controller.hpp

83 lines
3.5 KiB
C++
Raw Normal View History

2020-08-26 18:52:47 +00:00
/*
2021-01-26 03:03:26 +00:00
* Copyright (c) 2020-2021 ndeadly
2020-08-26 18:52:47 +00:00
*
2020-08-26 22:50:34 +00:00
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
2020-08-26 18:52:47 +00:00
*
2020-08-26 22:50:34 +00:00
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
2020-08-26 18:52:47 +00:00
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "switch_controller.hpp"
namespace ams::controller {
inline uint8_t ScaleRumbleAmplitude(float amp, uint8_t lower, uint8_t upper) {
return amp > 0.0 ? static_cast<uint8_t>(amp * (upper - lower) + lower) : 0;
}
2020-08-26 18:52:47 +00:00
class EmulatedSwitchController : public SwitchController {
public:
EmulatedSwitchController(const bluetooth::Address *address);
bool IsOfficialController(void) { return false; };
2020-08-26 18:52:47 +00:00
Result HandleIncomingReport(const bluetooth::HidReport *report);
Result HandleOutgoingReport(const bluetooth::HidReport *report);
protected:
void ClearControllerState(void);
virtual void UpdateControllerState(const bluetooth::HidReport *report) {};
2020-08-26 18:52:47 +00:00
virtual Result SetVibration(const SwitchRumbleData *left, const SwitchRumbleData *right) { return ams::ResultSuccess(); };
virtual Result CancelVibration(void) { return ams::ResultSuccess(); };
2020-08-26 18:52:47 +00:00
virtual Result SetPlayerLed(uint8_t led_mask) { return ams::ResultSuccess(); };
constexpr SwitchStickData PackStickData(uint16_t x, uint16_t y) {
return {
static_cast<uint8_t>(x & 0xff),
static_cast<uint8_t>((x >> 8) | ((y & 0xff) << 4)),
static_cast<uint8_t>((y >> 4) & 0xff)
};
}
2020-08-26 18:52:47 +00:00
Result HandleSubCmdReport(const bluetooth::HidReport *report);
Result HandleRumbleReport(const bluetooth::HidReport *report);
2020-08-26 18:52:47 +00:00
Result SubCmdRequestDeviceInfo(const bluetooth::HidReport *report);
Result SubCmdSpiFlashRead(const bluetooth::HidReport *report);
Result SubCmdSpiFlashWrite(const bluetooth::HidReport *report);
Result SubCmdSpiSectorErase(const bluetooth::HidReport *report);
Result SubCmdSetInputReportMode(const bluetooth::HidReport *report);
Result SubCmdTriggersElapsedTime(const bluetooth::HidReport *report);
Result SubCmdSetShipPowerState(const bluetooth::HidReport *report);
Result SubCmdSetMcuConfig(const bluetooth::HidReport *report);
Result SubCmdSetMcuState(const bluetooth::HidReport *report);
Result SubCmdSetPlayerLeds(const bluetooth::HidReport *report);
Result SubCmdSetHomeLed(const bluetooth::HidReport *report);
2020-08-26 18:52:47 +00:00
Result SubCmdEnableImu(const bluetooth::HidReport *report);
Result SubCmdEnableVibration(const bluetooth::HidReport *report);
Result FakeSubCmdResponse(const SwitchSubcommandResponse *response);
2020-08-26 18:52:47 +00:00
bool m_charging;
uint8_t m_battery;
SwitchButtonData m_buttons;
SwitchStickData m_left_stick;
SwitchStickData m_right_stick;
Switch6AxisData m_motion_data[3];
2020-08-26 18:52:47 +00:00
ProControllerColours m_colours;
bool m_enable_rumble;
2020-08-26 18:52:47 +00:00
};
}