Support DualShock
This commit is contained in:
parent
572de89186
commit
6c086da65c
|
@ -29,10 +29,22 @@ void font_writer_setup() {
|
||||||
void font_writer_update() {
|
void font_writer_update() {
|
||||||
static const char*const Text[2] = {"Planschi", "Becken"};
|
static const char*const Text[2] = {"Planschi", "Becken"};
|
||||||
|
|
||||||
|
auto& controller = JabyEngine::Periphery::get_primary_controller_as<JabyEngine::Periphery::GenericController>();
|
||||||
|
auto cur_rumble = controller.get_large_rumble();
|
||||||
|
|
||||||
|
if(controller.button.is_down(JabyEngine::Periphery::GenericController::Button::R1) && cur_rumble < 0xFF) {
|
||||||
|
cur_rumble += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(controller.button.is_down(JabyEngine::Periphery::GenericController::Button::L1) && cur_rumble > 0x0) {
|
||||||
|
cur_rumble -= 1;
|
||||||
|
}
|
||||||
|
controller.set_analog_rumble(cur_rumble, controller.button.is_down(JabyEngine::Periphery::GenericController::Button::Circle));
|
||||||
|
|
||||||
auto state = JabyEngine::State::create(JabyEngine::Make::PositionI16(8, 8), wiggle_count);
|
auto state = JabyEngine::State::create(JabyEngine::Make::PositionI16(8, 8), wiggle_count);
|
||||||
new_font_writer.write(state, "012345 ABCDEFGHIJKL\nabcedfghijkl\n", JabyEngine::GPU::Color24::Blue(), &wiggle);
|
new_font_writer.write(state, "012345 ABCDEFGHIJKL\nabcedfghijkl\n", JabyEngine::GPU::Color24::Blue(), &wiggle);
|
||||||
new_font_writer.write(state, "%i (0x%p)\nWiggle (%s)\n", JabyEngine::GPU::Color24::Green(), &wiggle, wiggle_count, 0xAABBCCDD, Text[wiggle_count&0x1]);
|
new_font_writer.write(state, "%i (0x%p)\nWiggle (%s)\n", JabyEngine::GPU::Color24::Green(), &wiggle, wiggle_count, 0xAABBCCDD, Text[wiggle_count&0x1]);
|
||||||
bios_font_writer.write(state, "!!PLANSCHBECKEN!!", JabyEngine::Periphery::controller[0][0].button.is_down(JabyEngine::Periphery::GenericButton::D7) ? JabyEngine::GPU::Color24::Blue() : JabyEngine::GPU::Color24::White());
|
bios_font_writer.write(state, "!!PLANSCHBECKEN\n(%i)!!", controller.button.is_down(JabyEngine::Periphery::GenericController::Button::Square) ? JabyEngine::GPU::Color24::Blue() : JabyEngine::GPU::Color24::White(), static_cast<int>(cur_rumble));
|
||||||
|
|
||||||
if(timer.is_expired_for(50_ms)) {
|
if(timer.is_expired_for(50_ms)) {
|
||||||
timer.reset();
|
timer.reset();
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#pragma once
|
||||||
|
#include "raw_controller.hpp"
|
||||||
|
|
||||||
|
namespace JabyEngine {
|
||||||
|
namespace Periphery {
|
||||||
|
class GenericController : public RawController {
|
||||||
|
public:
|
||||||
|
struct Rumble {
|
||||||
|
static constexpr uint8_t LargeMotorThreshold = 0x60;
|
||||||
|
};
|
||||||
|
|
||||||
|
enum struct Button : uint16_t {
|
||||||
|
L2 = static_cast<uint16_t>(GenericButton::D0),
|
||||||
|
R2 = static_cast<uint16_t>(GenericButton::D1),
|
||||||
|
L1 = static_cast<uint16_t>(GenericButton::D2),
|
||||||
|
R1 = static_cast<uint16_t>(GenericButton::D3),
|
||||||
|
Triangle = static_cast<uint16_t>(GenericButton::D4),
|
||||||
|
Circle = static_cast<uint16_t>(GenericButton::D5),
|
||||||
|
Cross = static_cast<uint16_t>(GenericButton::D6),
|
||||||
|
Square = static_cast<uint16_t>(GenericButton::D7),
|
||||||
|
SEL = static_cast<uint16_t>(GenericButton::D8),
|
||||||
|
ST = static_cast<uint16_t>(GenericButton::D11),
|
||||||
|
Up = static_cast<uint16_t>(GenericButton::D12),
|
||||||
|
Right = static_cast<uint16_t>(GenericButton::D13),
|
||||||
|
Down = static_cast<uint16_t>(GenericButton::D14),
|
||||||
|
Left = static_cast<uint16_t>(GenericButton::D15)
|
||||||
|
};
|
||||||
|
|
||||||
|
void set_digital_rumble() {
|
||||||
|
RawController::header.rumble0 = 0x1;
|
||||||
|
RawController::header.rumble1 = 0x7F;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_analog_rumble(uint8_t largeMotor, bool smallMotor) {
|
||||||
|
RawController::header.rumble0 = smallMotor ? 0x1 : 0x0;
|
||||||
|
RawController::header.rumble1 = largeMotor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopRumble() {
|
||||||
|
RawController::header.rumble0 = 0x0;
|
||||||
|
RawController::header.rumble1 = 0x0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_small_rumble() const {
|
||||||
|
return static_cast<bool>(RawController::header.rumble0);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t get_large_rumble() const {
|
||||||
|
return RawController::header.rumble1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool is_useable() const {
|
||||||
|
const auto type = RawController::get_type();
|
||||||
|
return ((RawController::header.state == RawController::State::Stable) && (type == ControllerType::Controller || type == ControllerType::DualShock));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using GenericButtonState = GenericController::ButtonState;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../jabyegine_config.hpp"
|
#include "../jabyegine_config.hpp"
|
||||||
#include "raw_controller.hpp"
|
#include "controller.hpp"
|
||||||
|
|
||||||
namespace JabyEngine {
|
namespace JabyEngine {
|
||||||
namespace Periphery {
|
namespace Periphery {
|
||||||
|
@ -10,5 +10,15 @@ namespace JabyEngine {
|
||||||
extern RawController controller[PortCount][DeviceCount];
|
extern RawController controller[PortCount][DeviceCount];
|
||||||
|
|
||||||
void query_controller();
|
void query_controller();
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T& get_controller_as(size_t port, size_t device) {
|
||||||
|
return *reinterpret_cast<T*>(&controller[port][device]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
inline T& get_primary_controller_as() {
|
||||||
|
return get_controller_as<T>(0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue