|
|
|
@ -172,88 +172,34 @@ void JoyconDriver::InputThread(std::stop_token stop_token) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void JoyconDriver::OnNewData(std::span<u8> buffer) {
|
|
|
|
|
const u8 report_mode_byte = buffer[0];
|
|
|
|
|
const auto report_mode = static_cast<ReportMode>(buffer[0]);
|
|
|
|
|
|
|
|
|
|
// Packages can be a little bit inconsistent. Average the delta time to provide a smoother
|
|
|
|
|
// motion experience
|
|
|
|
|
switch (report_mode) {
|
|
|
|
|
case ReportMode::STANDARD_FULL_60HZ:
|
|
|
|
|
case ReportMode::NFC_IR_MODE_60HZ:
|
|
|
|
|
case ReportMode::SIMPLE_HID_MODE: {
|
|
|
|
|
if (report_mode_byte > 0x33 || ((1L << report_mode_byte) & 0xf000a00000000U) == 0) {
|
|
|
|
|
// ParceUSBMode();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
u8 motion_samples = 0;
|
|
|
|
|
if (motion_enabled) {
|
|
|
|
|
// Packages can be a little bit inconsistent. Average the delta time to provide a smoother
|
|
|
|
|
// motion experience
|
|
|
|
|
const auto now = std::chrono::steady_clock::now();
|
|
|
|
|
const auto new_delta_time = static_cast<u64>(
|
|
|
|
|
std::chrono::duration_cast<std::chrono::microseconds>(now - last_update).count());
|
|
|
|
|
delta_time = ((delta_time * 8) + (new_delta_time * 2)) / 10;
|
|
|
|
|
last_update = now;
|
|
|
|
|
joycon_poller->UpdateColor(color);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
motion_samples = 3;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const MotionStatus motion_status{
|
|
|
|
|
.is_enabled = motion_enabled,
|
|
|
|
|
.delta_time = delta_time,
|
|
|
|
|
.gyro_sensitivity = gyro_sensitivity,
|
|
|
|
|
.accelerometer_sensitivity = accelerometer_sensitivity,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// TODO: Remove this when calibration is properly loaded and not calculated
|
|
|
|
|
if (ring_connected && report_mode == ReportMode::STANDARD_FULL_60HZ) {
|
|
|
|
|
InputReportActive data{};
|
|
|
|
|
memcpy(&data, buffer.data(), sizeof(InputReportActive));
|
|
|
|
|
calibration_protocol->GetRingCalibration(ring_calibration, data.ring_input);
|
|
|
|
|
if (irs_enabled) {
|
|
|
|
|
motion_samples = 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const RingStatus ring_status{
|
|
|
|
|
.is_enabled = ring_connected,
|
|
|
|
|
.default_value = ring_calibration.default_value,
|
|
|
|
|
.max_value = ring_calibration.max_value,
|
|
|
|
|
.min_value = ring_calibration.min_value,
|
|
|
|
|
};
|
|
|
|
|
const bool is_not_reply_or_state =
|
|
|
|
|
report_mode != ReportMode::SUBCMD_REPLY && report_mode != ReportMode::MCU_UPDATE_STATE;
|
|
|
|
|
|
|
|
|
|
if (irs_protocol->IsEnabled()) {
|
|
|
|
|
irs_protocol->RequestImage(buffer);
|
|
|
|
|
joycon_poller->UpdateCamera(irs_protocol->GetImage(), irs_protocol->GetIrsFormat());
|
|
|
|
|
}
|
|
|
|
|
joycon_poller->ReadActiveMode(buffer, motion);
|
|
|
|
|
|
|
|
|
|
if (nfc_protocol->IsPolling()) {
|
|
|
|
|
if (amiibo_detected) {
|
|
|
|
|
if (!nfc_protocol->HasAmiibo()) {
|
|
|
|
|
joycon_poller->UpdateAmiibo({});
|
|
|
|
|
amiibo_detected = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!amiibo_detected) {
|
|
|
|
|
Joycon::TagInfo tag_info;
|
|
|
|
|
const auto result = nfc_protocol->GetTagInfo(tag_info);
|
|
|
|
|
if (result == Common::Input::DriverResult::Success) {
|
|
|
|
|
joycon_poller->UpdateAmiibo(tag_info);
|
|
|
|
|
amiibo_detected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (report_mode) {
|
|
|
|
|
case ReportMode::STANDARD_FULL_60HZ:
|
|
|
|
|
joycon_poller->ReadActiveMode(buffer, motion_status, ring_status);
|
|
|
|
|
break;
|
|
|
|
|
case ReportMode::NFC_IR_MODE_60HZ:
|
|
|
|
|
joycon_poller->ReadNfcIRMode(buffer, motion_status);
|
|
|
|
|
break;
|
|
|
|
|
case ReportMode::SIMPLE_HID_MODE:
|
|
|
|
|
joycon_poller->ReadPassiveMode(buffer);
|
|
|
|
|
break;
|
|
|
|
|
case ReportMode::SUBCMD_REPLY:
|
|
|
|
|
LOG_DEBUG(Input, "Unhandled command reply");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
LOG_ERROR(Input, "Report mode not Implemented {}", report_mode);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Common::Input::DriverResult JoyconDriver::SetPollingMode() {
|
|
|
|
|