Morph review first wave

This commit is contained in:
german77 2021-10-22 23:04:06 -05:00 committed by Narr the Reg
parent e2e5f1beaf
commit b564f024f0
23 changed files with 117 additions and 136 deletions

View file

@ -35,8 +35,8 @@ public:
private:
struct SevenSixAxisState {
INSERT_PADDING_WORDS(4); // unused
s64_le sampling_number{};
s64_le sampling_number2{};
s64 sampling_number{};
s64 sampling_number2{};
u64 unknown{};
Common::Vec3f accel{};
Common::Vec3f gyro{};
@ -45,10 +45,10 @@ private:
static_assert(sizeof(SevenSixAxisState) == 0x50, "SevenSixAxisState is an invalid size");
struct CommonHeader {
s64_le timestamp;
s64_le total_entry_count;
s64_le last_entry_index;
s64_le entry_count;
s64 timestamp;
s64 total_entry_count;
s64 last_entry_index;
s64 entry_count;
};
static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size");
@ -61,7 +61,7 @@ private:
// This is nn::hid::detail::ConsoleSixAxisSensorSharedMemoryFormat
struct ConsoleSharedMemory {
u64_le sampling_number{};
u64 sampling_number{};
bool is_seven_six_axis_sensor_at_rest{};
f32 verticalization_error{};
Common::Vec3f gyro_bias{};

View file

@ -38,7 +38,7 @@ private:
// This is nn::hid::DebugPadAttribute
struct DebugPadAttribute {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, u32> connected;
};
};
@ -46,7 +46,7 @@ private:
// This is nn::hid::DebugPadState
struct DebugPadState {
s64_le sampling_number;
s64 sampling_number;
DebugPadAttribute attribute;
Core::HID::DebugPadButton pad_state;
Core::HID::AnalogStickState r_stick;

View file

@ -65,10 +65,7 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u
void Controller_Gesture::ReadTouchInput() {
const auto touch_status = console->GetTouch();
for (std::size_t id = 0; id < fingers.size(); ++id) {
const Core::HID::TouchFinger& status = touch_status[id];
Finger& finger = fingers[id];
finger.pos = status.position;
finger.pressed = status.pressed;
fingers[id] = touch_status[id];
}
}
@ -315,14 +312,14 @@ const Controller_Gesture::GestureState& Controller_Gesture::GetLastGestureEntry(
Controller_Gesture::GestureProperties Controller_Gesture::GetGestureProperties() {
GestureProperties gesture;
std::array<Finger, MAX_POINTS> active_fingers;
std::array<Core::HID::TouchFinger, MAX_POINTS> active_fingers;
const auto end_iter = std::copy_if(fingers.begin(), fingers.end(), active_fingers.begin(),
[](const auto& finger) { return finger.pressed; });
gesture.active_points =
static_cast<std::size_t>(std::distance(active_fingers.begin(), end_iter));
for (size_t id = 0; id < gesture.active_points; ++id) {
const auto& [active_x, active_y] = active_fingers[id].pos;
const auto& [active_x, active_y] = active_fingers[id].position;
gesture.points[id] = {
.x = static_cast<s32>(active_x * Layout::ScreenUndocked::Width),
.y = static_cast<s32>(active_y * Layout::ScreenUndocked::Height),

View file

@ -60,7 +60,7 @@ private:
// This is nn::hid::GestureAttribute
struct GestureAttribute {
union {
u32_le raw{};
u32 raw{};
BitField<4, 1, u32> is_new_touch;
BitField<8, 1, u32> is_double_tap;
@ -70,33 +70,28 @@ private:
// This is nn::hid::GestureState
struct GestureState {
s64_le sampling_number;
s64_le detection_count;
s64 sampling_number;
s64 detection_count;
GestureType type;
GestureDirection direction;
Common::Point<s32_le> pos;
Common::Point<s32_le> delta;
Common::Point<s32> pos;
Common::Point<s32> delta;
f32 vel_x;
f32 vel_y;
GestureAttribute attributes;
f32 scale;
f32 rotation_angle;
s32_le point_count;
std::array<Common::Point<s32_le>, 4> points;
s32 point_count;
std::array<Common::Point<s32>, 4> points;
};
static_assert(sizeof(GestureState) == 0x60, "GestureState is an invalid size");
struct Finger {
Common::Point<f32> pos{};
bool pressed{};
};
struct GestureProperties {
std::array<Common::Point<s32_le>, MAX_POINTS> points{};
std::array<Common::Point<s32>, MAX_POINTS> points{};
std::size_t active_points{};
Common::Point<s32_le> mid_point{};
s64_le detection_count{};
u64_le delta_time{};
Common::Point<s32> mid_point{};
s64 detection_count{};
u64 delta_time{};
f32 average_distance{};
f32 angle{};
};
@ -150,10 +145,10 @@ private:
Core::HID::EmulatedConsole* console;
std::array<Finger, MAX_POINTS> fingers{};
std::array<Core::HID::TouchFinger, MAX_POINTS> fingers{};
GestureProperties last_gesture{};
s64_le last_update_timestamp{};
s64_le last_tap_timestamp{};
s64 last_update_timestamp{};
s64 last_tap_timestamp{};
f32 last_pan_time_difference{};
bool force_update{false};
bool enable_press_and_tap{false};

View file

@ -37,7 +37,7 @@ public:
private:
// This is nn::hid::detail::KeyboardState
struct KeyboardState {
s64_le sampling_number;
s64 sampling_number;
Core::HID::KeyboardModifier modifier;
Core::HID::KeyboardKey key;
};

View file

@ -106,7 +106,7 @@ Controller_NPad::Controller_NPad(Core::System& system_,
Core::HID::ControllerUpdateCallback engine_callback{
.on_change = [this,
i](Core::HID::ControllerTriggerType type) { ControllerUpdate(type, i); },
.is_service = true,
.is_npad_service = true,
};
controller.callback_key = controller.device->SetCallback(engine_callback);
}
@ -157,7 +157,6 @@ void Controller_NPad::ControllerUpdate(Core::HID::ControllerTriggerType type,
void Controller_NPad::InitNewlyAddedController(std::size_t controller_idx) {
auto& controller = controller_data[controller_idx];
LOG_WARNING(Service_HID, "Connect {} {}", controller_idx, controller.is_connected);
const auto controller_type = controller.device->GetNpadType();
auto& shared_memory = controller.shared_memory_entry;
if (controller_type == Core::HID::NpadType::None) {
@ -892,7 +891,6 @@ void Controller_NPad::DisconnectNpad(u32 npad_id) {
void Controller_NPad::DisconnectNpadAtIndex(std::size_t npad_index) {
auto& controller = controller_data[npad_index];
LOG_WARNING(Service_HID, "Disconnect {} {}", npad_index, controller.is_connected);
for (std::size_t device_idx = 0; device_idx < controller.vibration.size(); ++device_idx) {
// Send an empty vibration to stop any vibrations.
VibrateControllerAtIndex(npad_index, device_idx, {});

View file

@ -195,7 +195,7 @@ public:
private:
// This is nn::hid::detail::ColorAttribute
enum class ColorAttribute : u32_le {
enum class ColorAttribute : u32 {
Ok = 0,
ReadError = 1,
NoController = 2,
@ -220,7 +220,7 @@ private:
// This is nn::hid::NpadAttribute
struct NpadAttribute {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, u32> is_connected;
BitField<1, 1, u32> is_wired;
BitField<2, 1, u32> is_left_connected;
@ -251,7 +251,7 @@ private:
// This is nn::hid::SixAxisSensorAttribute
struct SixAxisSensorAttribute {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, u32> is_connected;
BitField<1, 1, u32> is_interpolated;
};
@ -260,8 +260,8 @@ private:
// This is nn::hid::SixAxisSensorState
struct SixAxisSensorState {
s64_le delta_time{};
s64_le sampling_number{};
s64 delta_time{};
s64 sampling_number{};
Common::Vec3f accel{};
Common::Vec3f gyro{};
Common::Vec3f rotation{};
@ -273,16 +273,16 @@ private:
// This is nn::hid::server::NpadGcTriggerState
struct NpadGcTriggerState {
s64_le sampling_number{};
s32_le l_analog{};
s32_le r_analog{};
s64 sampling_number{};
s32 l_analog{};
s32 r_analog{};
};
static_assert(sizeof(NpadGcTriggerState) == 0x10, "NpadGcTriggerState is an invalid size");
// This is nn::hid::NpadSystemProperties
struct NPadSystemProperties {
union {
s64_le raw{};
s64 raw{};
BitField<0, 1, s64> is_charging_joy_dual;
BitField<1, 1, s64> is_charging_joy_left;
BitField<2, 1, s64> is_charging_joy_right;
@ -303,7 +303,7 @@ private:
// This is nn::hid::NpadSystemButtonProperties
struct NpadSystemButtonProperties {
union {
s32_le raw{};
s32 raw{};
BitField<0, 1, s32> is_home_button_protection_enabled;
};
};
@ -313,7 +313,7 @@ private:
// This is nn::hid::system::DeviceType
struct DeviceType {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, s32> fullkey;
BitField<1, 1, s32> debug_pad;
BitField<2, 1, s32> handheld_left;

View file

@ -26,10 +26,10 @@ public:
private:
struct CommonHeader {
s64_le timestamp;
s64_le total_entry_count;
s64_le last_entry_index;
s64_le entry_count;
s64 timestamp;
s64 total_entry_count;
s64 last_entry_index;
s64 entry_count;
};
static_assert(sizeof(CommonHeader) == 0x20, "CommonHeader is an invalid size");

View file

@ -66,7 +66,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
}
}
std::array<Finger, MAX_FINGERS> active_fingers;
std::array<Core::HID::TouchFinger, MAX_FINGERS> active_fingers;
const auto end_iter = std::copy_if(fingers.begin(), fingers.end(), active_fingers.begin(),
[](const auto& finger) { return finger.pressed; });
const auto active_fingers_count =
@ -76,7 +76,7 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
const auto& last_entry = touch_screen_lifo.ReadCurrentEntry().state;
next_state.sampling_number = last_entry.sampling_number + 1;
next_state.entry_count = static_cast<s32_le>(active_fingers_count);
next_state.entry_count = static_cast<s32>(active_fingers_count);
for (std::size_t id = 0; id < MAX_FINGERS; ++id) {
auto& touch_entry = next_state.states[id];

View file

@ -50,27 +50,19 @@ private:
// This is nn::hid::TouchScreenState
struct TouchScreenState {
s64_le sampling_number;
s32_le entry_count;
s64 sampling_number;
s32 entry_count;
INSERT_PADDING_BYTES(4); // Reserved
std::array<Core::HID::TouchState, MAX_FINGERS> states;
};
static_assert(sizeof(TouchScreenState) == 0x290, "TouchScreenState is an invalid size");
struct Finger {
u64_le last_touch{};
Common::Point<float> position;
u32_le id{};
bool pressed{};
Core::HID::TouchAttribute attribute;
};
// This is nn::hid::detail::TouchScreenLifo
Lifo<TouchScreenState> touch_screen_lifo{};
static_assert(sizeof(touch_screen_lifo) == 0x2C38, "touch_screen_lifo is an invalid size");
TouchScreenState next_state{};
std::array<Finger, MAX_FINGERS> fingers;
std::array<Core::HID::TouchFinger, MAX_FINGERS> fingers;
Core::HID::EmulatedConsole* console;
};
} // namespace Service::HID

View file

@ -31,7 +31,7 @@ private:
// This is nn::hid::BasicXpadAttributeSet
struct BasicXpadAttributeSet {
union {
u32_le raw{};
u32 raw{};
BitField<0, 1, u32> is_connected;
BitField<1, 1, u32> is_wired;
BitField<2, 1, u32> is_left_connected;
@ -45,7 +45,7 @@ private:
// This is nn::hid::BasicXpadButtonSet
struct BasicXpadButtonSet {
union {
u32_le raw{};
u32 raw{};
// Button states
BitField<0, 1, u32> a;
BitField<1, 1, u32> b;
@ -93,7 +93,7 @@ private:
// This is nn::hid::detail::BasicXpadState
struct BasicXpadState {
s64_le sampling_number;
s64 sampling_number;
BasicXpadAttributeSet attributes;
BasicXpadButtonSet pad_states;
Core::HID::AnalogStickState l_stick;

View file

@ -12,16 +12,16 @@ constexpr std::size_t max_entry_size = 17;
template <typename State>
struct AtomicStorage {
s64_le sampling_number;
s64 sampling_number;
State state;
};
template <typename State>
struct Lifo {
s64_le timestamp{};
s64_le total_entry_count = max_entry_size;
s64_le last_entry_index{};
s64_le entry_count{};
s64 timestamp{};
s64 total_entry_count = max_entry_size;
s64 last_entry_index{};
s64 entry_count{};
std::array<AtomicStorage<State>, max_entry_size> entries{};
const AtomicStorage<State>& ReadCurrentEntry() const {