MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ adopt_device()

bool MayaFlux::Core::TabletBackend::adopt_device ( const std::string &  path,
uint16_t  vid,
uint16_t  pid,
std::string  name 
)
private

Definition at line 604 of file TabletBackend.cpp.

606{
607 hid_device* handle = hid_open_path(path.c_str());
608 if (!handle) {
610 "Could not open HID device {} ({}): {}",
611 name, path, hid_failure_reason(nullptr));
612 return false;
613 }
614
615 std::vector<uint8_t> descriptor(4096);
616 const int written = hid_get_report_descriptor(handle,
617 descriptor.data(), descriptor.size());
618
619 if (written <= 0) {
621 "Could not read report descriptor of {} ({}): {}",
622 name, path, hid_failure_reason(handle));
623 hid_close(handle);
624 return false;
625 }
626 descriptor.resize(static_cast<size_t>(written));
627
628 TabletLayout layout = parse_descriptor(descriptor);
629 if (layout.fields.empty()) {
630 hid_close(handle);
631 return false;
632 }
633
634 hid_set_nonblocking(handle, 0);
635
636 auto device = std::make_shared<TabletDevice>();
637 device->handle = handle;
638 device->path = path;
639 device->name = std::move(name);
640 device->vendor_id = vid;
641 device->product_id = pid;
642 device->layout = std::move(layout);
643 device->read_buffer.resize(m_config.read_buffer_size);
644 device->active.store(true);
645
646 std::vector<TabletToolInfo> announced;
647
648 {
649 std::lock_guard lock(m_devices_mutex);
650
651 TabletToolInfo pen;
652 pen.id = m_next_device_id++;
653 pen.backend_type = InputType::TABLET;
654 pen.is_connected = true;
655 pen.is_input = true;
656 pen.vendor_id = vid;
657 pen.product_id = pid;
658 pen.tablet_name = device->name;
659 pen.name = device->name + " Pen";
660 pen.tool_type = TabletToolType::PEN;
661 pen.axes = device->layout.axes;
662
663 device->pen_id = pen.id;
664 m_tools[pen.id] = pen;
665 m_tool_paths[pen.id] = path;
666 announced.push_back(pen);
667
668 if (m_config.split_eraser && device->layout.has_invert) {
669 TabletToolInfo eraser = pen;
670 eraser.id = m_next_device_id++;
671 eraser.name = device->name + " Eraser";
672 eraser.tool_type = TabletToolType::ERASER;
673
674 device->eraser_id = eraser.id;
675 m_tools[eraser.id] = eraser;
676 m_tool_paths[eraser.id] = path;
677 announced.push_back(eraser);
678 } else {
679 device->eraser_id = device->pen_id;
680 }
681
682 m_devices[path] = device;
683 }
684
686 "Tablet adopted: {} (VID:{:04X} PID:{:04X}, {} field(s))",
687 device->name, vid, pid, device->layout.fields.size());
688
689 for (const auto& info : announced) {
690 notify_device_change(info, true);
691 }
692
693 return true;
694}
#define MF_INFO(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
hid_device_ hid_device
Definition HIDBackend.hpp:5
vk::PhysicalDevice device
Definition VKDevice.cpp:121
std::string name
Definition VKDevice.cpp:123
void notify_device_change(const InputDeviceInfo &info, bool connected)
static TabletLayout parse_descriptor(std::span< const uint8_t > descriptor)
Parse a HID report descriptor into a tablet layout.
std::unordered_map< uint32_t, std::string > m_tool_paths
std::unordered_map< std::string, std::shared_ptr< TabletDevice > > m_devices
std::unordered_map< uint32_t, TabletToolInfo > m_tools
@ TABLET
Digitizers and styluses (pressure, tilt, rotation)
@ InputBackend
Input device backend (HID, MIDI, OSC)
@ Core
Core engine, backend, subsystems.
bool split_eraser
Report the eraser end as its own tool.
size_t read_buffer_size
Per-device read buffer.

References MayaFlux::Core::TabletToolInfo::axes, MayaFlux::Core::InputDeviceInfo::backend_type, MayaFlux::Journal::Core, device, MayaFlux::Core::ERASER, MayaFlux::Core::TabletLayout::fields, MayaFlux::Core::InputDeviceInfo::id, MayaFlux::Journal::InputBackend, MayaFlux::Core::InputDeviceInfo::is_connected, MayaFlux::Core::InputDeviceInfo::is_input, m_config, m_devices, m_devices_mutex, m_next_device_id, m_tool_paths, m_tools, MF_DEBUG, MF_INFO, name, MayaFlux::Core::InputDeviceInfo::name, notify_device_change(), parse_descriptor(), MayaFlux::Core::PEN, MayaFlux::Core::InputDeviceInfo::product_id, MayaFlux::Core::TabletBackend::Config::read_buffer_size, MayaFlux::Core::TabletBackend::Config::split_eraser, MayaFlux::Core::TABLET, MayaFlux::Core::TabletToolInfo::tablet_name, MayaFlux::Core::TabletToolInfo::tool_type, and MayaFlux::Core::InputDeviceInfo::vendor_id.

Referenced by refresh_devices().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: