MCPcopy Create free account
hub / github.com/SFML/SFML / update

Method update

src/SFML/Window/NetBSD/JoystickImpl.cpp:302–349  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

300
301////////////////////////////////////////////////////////////
302JoystickState JoystickImpl::JoystickImpl::update()
303{
304 while (read(m_file, m_buffer.data(), m_length) == m_length)
305 {
306 hid_data_t data = hid_start_parse(m_desc, 1 << hid_input, m_id);
307
308 // No memory?
309 if (!data)
310 continue;
311
312 std::size_t buttonIndex = 0;
313 hid_item_t item;
314
315 while (hid_get_item(data, &item))
316 {
317 if (item.kind == hid_input)
318 {
319 int usage = HID_USAGE(item.usage);
320
321 if (usage == HUP_BUTTON)
322 {
323 m_state.buttons[buttonIndex++] = hid_get_data(m_buffer.data(), &item);
324 }
325 else if (usage == HUP_GENERIC_DESKTOP)
326 {
327 int value = hid_get_data(m_buffer.data(), &item);
328
329 if (usage == HUG_HAT_SWITCH)
330 {
331 hatValueToSfml(value, m_state);
332 }
333 else if (const std::optional<Joystick::Axis> axis = usageToAxis(usage))
334 {
335 int minimum = item.logical_minimum;
336 int maximum = item.logical_maximum;
337
338 value = (value - minimum) * 200 / (maximum - minimum) - 100;
339 m_state.axes[*axis] = value;
340 }
341 }
342 }
343 }
344
345 hid_end_parse(data);
346 }
347
348 return m_state;
349}
350
351} // namespace sf::priv

Callers

nothing calls this directly

Calls 3

hatValueToSfmlFunction · 0.70
usageToAxisFunction · 0.70
readFunction · 0.50

Tested by

no test coverage detected